HaikuDepot: Create dummy model (2 items)
* Added methods to fill the package list view, creating PackageRows from PackageInfos, various TODOs. * Some additions in the info classes, UserRating needs language.
This commit is contained in:
@@ -39,8 +39,8 @@ MainWindow::MainWindow(BRect frame)
|
||||
|
||||
fFilterView = new FilterView();
|
||||
fPackageListView = new PackageListView();
|
||||
fPackageActionsView = new PackageActionsView();
|
||||
fPackageInfoView = new PackageInfoView();
|
||||
fPackageActionsView = new PackageActionsView();
|
||||
|
||||
fSplitView = new BSplitView(B_VERTICAL, B_USE_SMALL_SPACING);
|
||||
|
||||
@@ -59,6 +59,9 @@ MainWindow::MainWindow(BRect frame)
|
||||
;
|
||||
|
||||
fSplitView->SetCollapsible(0, false);
|
||||
|
||||
_InitDummyModel();
|
||||
_AdoptModel();
|
||||
}
|
||||
|
||||
|
||||
@@ -99,3 +102,65 @@ MainWindow::_BuildMenu(BMenuBar* menuBar)
|
||||
menuBar->AddItem(menu);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MainWindow::_AdoptModel()
|
||||
{
|
||||
PackageInfoList packages = fModel.CreatePackageList();
|
||||
|
||||
fPackageListView->Clear();
|
||||
for (int32 i = 0; i < packages.CountItems(); i++) {
|
||||
fPackageListView->AddPackage(packages.ItemAtFast(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MainWindow::_InitDummyModel()
|
||||
{
|
||||
// TODO: The Model could be filled from another thread by
|
||||
// sending messages which contain collected package information.
|
||||
// The Model could be cached on disk.
|
||||
|
||||
DepotInfo depot(B_TRANSLATE("Default"));
|
||||
|
||||
PackageInfo wonderbrush(
|
||||
"WonderBrush",
|
||||
"2.1.2",
|
||||
"A vector based graphics editor.",
|
||||
"2.1.2 - Initial Haiku release.");
|
||||
wonderbrush.AddUserRating(
|
||||
UserRating(UserInfo("humdinger"), 4.5f,
|
||||
"Awesome!", "en", "2.1.2")
|
||||
);
|
||||
wonderbrush.AddUserRating(
|
||||
UserRating(UserInfo("bonefish"), 5.0f,
|
||||
"The best!", "en", "2.1.2")
|
||||
);
|
||||
depot.AddPackage(wonderbrush);
|
||||
|
||||
PackageInfo paladin(
|
||||
"Paladin",
|
||||
"1.2.0",
|
||||
"A C/C++ IDE based on Pe.",
|
||||
"");
|
||||
paladin.AddUserRating(
|
||||
UserRating(UserInfo("stippi"), 3.5f,
|
||||
"Could be more integrated from the sounds of it.",
|
||||
"en", "1.2.0")
|
||||
);
|
||||
paladin.AddUserRating(
|
||||
UserRating(UserInfo("mmadia"), 5.0f,
|
||||
"It rocks! Give a try",
|
||||
"en", "1.1.0")
|
||||
);
|
||||
paladin.AddUserRating(
|
||||
UserRating(UserInfo("bonefish"), 2.0f,
|
||||
"It just needs to use my jam-rewrite 'ham' and it will be great.",
|
||||
"en", "1.1.0")
|
||||
);
|
||||
depot.AddPackage(paladin);
|
||||
|
||||
fModel.AddDepot(depot);
|
||||
}
|
||||
|
||||
@@ -32,12 +32,15 @@ public:
|
||||
|
||||
private:
|
||||
void _BuildMenu(BMenuBar* menuBar);
|
||||
void _AdoptModel();
|
||||
|
||||
void _InitDummyModel();
|
||||
|
||||
private:
|
||||
FilterView* fFilterView;
|
||||
PackageActionsView* fPackageActionsView;
|
||||
PackageInfoView* fPackageInfoView;
|
||||
PackageListView* fPackageListView;
|
||||
PackageInfoView* fPackageInfoView;
|
||||
PackageActionsView* fPackageActionsView;
|
||||
BSplitView* fSplitView;
|
||||
|
||||
Model fModel;
|
||||
|
||||
@@ -60,19 +60,22 @@ UserInfo::operator!=(const UserInfo& other) const
|
||||
UserRating::UserRating()
|
||||
:
|
||||
fUserInfo(),
|
||||
fComment(),
|
||||
fRating(0.0f),
|
||||
fComment(),
|
||||
fLanguage(),
|
||||
fPackageVersion()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
UserRating::UserRating(const UserInfo& userInfo, const BString& comment,
|
||||
float rating, const BString& packageVersion)
|
||||
UserRating::UserRating(const UserInfo& userInfo, float rating,
|
||||
const BString& comment, const BString& language,
|
||||
const BString& packageVersion)
|
||||
:
|
||||
fUserInfo(userInfo),
|
||||
fComment(comment),
|
||||
fRating(rating),
|
||||
fComment(comment),
|
||||
fLanguage(language),
|
||||
fPackageVersion(packageVersion)
|
||||
|
||||
{
|
||||
@@ -82,8 +85,9 @@ UserRating::UserRating(const UserInfo& userInfo, const BString& comment,
|
||||
UserRating::UserRating(const UserRating& other)
|
||||
:
|
||||
fUserInfo(other.fUserInfo),
|
||||
fComment(other.fComment),
|
||||
fRating(other.fRating),
|
||||
fComment(other.fComment),
|
||||
fLanguage(other.fLanguage),
|
||||
fPackageVersion(other.fPackageVersion)
|
||||
{
|
||||
}
|
||||
@@ -93,8 +97,9 @@ UserRating&
|
||||
UserRating::operator=(const UserRating& other)
|
||||
{
|
||||
fUserInfo = other.fUserInfo;
|
||||
fComment = other.fComment;
|
||||
fRating = other.fRating;
|
||||
fComment = other.fComment;
|
||||
fLanguage = other.fLanguage;
|
||||
fPackageVersion = other.fPackageVersion;
|
||||
return *this;
|
||||
}
|
||||
@@ -104,8 +109,9 @@ bool
|
||||
UserRating::operator==(const UserRating& other) const
|
||||
{
|
||||
return fUserInfo == other.fUserInfo
|
||||
&& fComment == other.fComment
|
||||
&& fRating == other.fRating
|
||||
&& fComment == other.fComment
|
||||
&& fLanguage == other.fLanguage
|
||||
&& fPackageVersion == other.fPackageVersion;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,9 @@ class UserRating {
|
||||
public:
|
||||
UserRating();
|
||||
UserRating(const UserInfo& userInfo,
|
||||
const BString& comment, float rating,
|
||||
float rating,
|
||||
const BString& comment,
|
||||
const BString& language,
|
||||
const BString& packageVersion);
|
||||
UserRating(const UserRating& other);
|
||||
|
||||
@@ -51,8 +53,9 @@ public:
|
||||
|
||||
private:
|
||||
UserInfo fUserInfo;
|
||||
BString fComment;
|
||||
float fRating;
|
||||
BString fComment;
|
||||
BString fLanguage;
|
||||
BString fPackageVersion;
|
||||
};
|
||||
|
||||
|
||||
@@ -171,11 +171,11 @@ PackageColumn::InitTextMargin(BView* parent)
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - PackageListView
|
||||
// #pragma mark - PackageRow
|
||||
|
||||
|
||||
enum {
|
||||
kNameColumn,
|
||||
kTitleColumn,
|
||||
kRatingColumn,
|
||||
kDescriptionColumn,
|
||||
kSizeColumn,
|
||||
@@ -183,12 +183,44 @@ enum {
|
||||
};
|
||||
|
||||
|
||||
PackageRow::PackageRow(const PackageInfo& package)
|
||||
:
|
||||
Inherited(),
|
||||
fPackage(package)
|
||||
{
|
||||
// Package icon
|
||||
|
||||
BBitmap* icon = NULL;
|
||||
// TODO: Fetch package icon
|
||||
|
||||
SetField(new BBitmapStringField(icon, package.Title()), kTitleColumn);
|
||||
|
||||
// Rating
|
||||
// TODO: Method to compute and cache rating
|
||||
SetField(new BStringField("n/a"), kRatingColumn);
|
||||
|
||||
// Description
|
||||
SetField(new BStringField(package.Description()), kDescriptionColumn);
|
||||
|
||||
// Size
|
||||
// TODO: Store package size
|
||||
SetField(new BStringField("0 KiB"), kSizeColumn);
|
||||
|
||||
// Status
|
||||
// TODO: Fetch info about installed/deactivated/unintalled/...
|
||||
SetField(new BStringField("n/a"), kStatusColumn);
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - PackageListView
|
||||
|
||||
|
||||
PackageListView::PackageListView()
|
||||
:
|
||||
BColumnListView("package list view", 0, B_FANCY_BORDER, true)
|
||||
{
|
||||
AddColumn(new PackageColumn(B_TRANSLATE("Name"), 150, 50, 500,
|
||||
B_TRUNCATE_MIDDLE), kNameColumn);
|
||||
B_TRUNCATE_MIDDLE), kTitleColumn);
|
||||
AddColumn(new PackageColumn(B_TRANSLATE("Rating"), 100, 50, 500,
|
||||
B_TRUNCATE_MIDDLE), kRatingColumn);
|
||||
AddColumn(new PackageColumn(B_TRANSLATE("Description"), 130, 50, 500,
|
||||
@@ -221,3 +253,43 @@ PackageListView::MessageReceived(BMessage* message)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageListView::AddPackage(const PackageInfo& package)
|
||||
{
|
||||
PackageRow* packageRow = _FindRow(package);
|
||||
|
||||
// forget about it if this package is already in the listview
|
||||
if (packageRow != NULL)
|
||||
return;
|
||||
|
||||
// create the row for this package
|
||||
packageRow = new PackageRow(package);
|
||||
|
||||
// add the row, parent may be NULL (add at top level)
|
||||
AddRow(packageRow);
|
||||
|
||||
// make sure the row is initially expanded
|
||||
ExpandOrCollapse(packageRow, true);
|
||||
}
|
||||
|
||||
|
||||
PackageRow*
|
||||
PackageListView::_FindRow(const PackageInfo& package, PackageRow* parent)
|
||||
{
|
||||
for (int32 i = CountRows(parent) - 1; i >= 0; i--) {
|
||||
PackageRow* row = dynamic_cast<PackageRow*>(RowAt(i, parent));
|
||||
if (row != NULL && row->Package() == package)
|
||||
return row;
|
||||
if (CountRows(row) > 0) {
|
||||
// recurse into child rows
|
||||
row = _FindRow(package, row);
|
||||
if (row != NULL)
|
||||
return row;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include <ColumnListView.h>
|
||||
#include <ColumnTypes.h>
|
||||
|
||||
#include "PackageInfo.h"
|
||||
|
||||
|
||||
// A field type displaying both a bitmap and a string so that the
|
||||
// tree display looks nicer (both text and bitmap are indented)
|
||||
@@ -55,6 +57,20 @@ private:
|
||||
};
|
||||
|
||||
|
||||
// BRow for the PartitionListView
|
||||
class PackageRow : public BRow {
|
||||
typedef BRow Inherited;
|
||||
public:
|
||||
PackageRow(const PackageInfo& package);
|
||||
|
||||
const PackageInfo& Package() const
|
||||
{ return fPackage; }
|
||||
|
||||
private:
|
||||
PackageInfo fPackage;
|
||||
};
|
||||
|
||||
|
||||
class PackageListView : public BColumnListView {
|
||||
public:
|
||||
PackageListView();
|
||||
@@ -62,6 +78,12 @@ public:
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
void AddPackage(const PackageInfo& package);
|
||||
|
||||
private:
|
||||
PackageRow* _FindRow(const PackageInfo& package,
|
||||
PackageRow* parent = NULL);
|
||||
};
|
||||
|
||||
#endif // PACKAGE_LIST_VIEW_H
|
||||
|
||||
Reference in New Issue
Block a user