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();
|
fFilterView = new FilterView();
|
||||||
fPackageListView = new PackageListView();
|
fPackageListView = new PackageListView();
|
||||||
fPackageActionsView = new PackageActionsView();
|
|
||||||
fPackageInfoView = new PackageInfoView();
|
fPackageInfoView = new PackageInfoView();
|
||||||
|
fPackageActionsView = new PackageActionsView();
|
||||||
|
|
||||||
fSplitView = new BSplitView(B_VERTICAL, B_USE_SMALL_SPACING);
|
fSplitView = new BSplitView(B_VERTICAL, B_USE_SMALL_SPACING);
|
||||||
|
|
||||||
@@ -59,6 +59,9 @@ MainWindow::MainWindow(BRect frame)
|
|||||||
;
|
;
|
||||||
|
|
||||||
fSplitView->SetCollapsible(0, false);
|
fSplitView->SetCollapsible(0, false);
|
||||||
|
|
||||||
|
_InitDummyModel();
|
||||||
|
_AdoptModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -99,3 +102,65 @@ MainWindow::_BuildMenu(BMenuBar* menuBar)
|
|||||||
menuBar->AddItem(menu);
|
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:
|
private:
|
||||||
void _BuildMenu(BMenuBar* menuBar);
|
void _BuildMenu(BMenuBar* menuBar);
|
||||||
|
void _AdoptModel();
|
||||||
|
|
||||||
|
void _InitDummyModel();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FilterView* fFilterView;
|
FilterView* fFilterView;
|
||||||
PackageActionsView* fPackageActionsView;
|
|
||||||
PackageInfoView* fPackageInfoView;
|
|
||||||
PackageListView* fPackageListView;
|
PackageListView* fPackageListView;
|
||||||
|
PackageInfoView* fPackageInfoView;
|
||||||
|
PackageActionsView* fPackageActionsView;
|
||||||
BSplitView* fSplitView;
|
BSplitView* fSplitView;
|
||||||
|
|
||||||
Model fModel;
|
Model fModel;
|
||||||
|
|||||||
@@ -60,19 +60,22 @@ UserInfo::operator!=(const UserInfo& other) const
|
|||||||
UserRating::UserRating()
|
UserRating::UserRating()
|
||||||
:
|
:
|
||||||
fUserInfo(),
|
fUserInfo(),
|
||||||
fComment(),
|
|
||||||
fRating(0.0f),
|
fRating(0.0f),
|
||||||
|
fComment(),
|
||||||
|
fLanguage(),
|
||||||
fPackageVersion()
|
fPackageVersion()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
UserRating::UserRating(const UserInfo& userInfo, const BString& comment,
|
UserRating::UserRating(const UserInfo& userInfo, float rating,
|
||||||
float rating, const BString& packageVersion)
|
const BString& comment, const BString& language,
|
||||||
|
const BString& packageVersion)
|
||||||
:
|
:
|
||||||
fUserInfo(userInfo),
|
fUserInfo(userInfo),
|
||||||
fComment(comment),
|
|
||||||
fRating(rating),
|
fRating(rating),
|
||||||
|
fComment(comment),
|
||||||
|
fLanguage(language),
|
||||||
fPackageVersion(packageVersion)
|
fPackageVersion(packageVersion)
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -82,8 +85,9 @@ UserRating::UserRating(const UserInfo& userInfo, const BString& comment,
|
|||||||
UserRating::UserRating(const UserRating& other)
|
UserRating::UserRating(const UserRating& other)
|
||||||
:
|
:
|
||||||
fUserInfo(other.fUserInfo),
|
fUserInfo(other.fUserInfo),
|
||||||
fComment(other.fComment),
|
|
||||||
fRating(other.fRating),
|
fRating(other.fRating),
|
||||||
|
fComment(other.fComment),
|
||||||
|
fLanguage(other.fLanguage),
|
||||||
fPackageVersion(other.fPackageVersion)
|
fPackageVersion(other.fPackageVersion)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -93,8 +97,9 @@ UserRating&
|
|||||||
UserRating::operator=(const UserRating& other)
|
UserRating::operator=(const UserRating& other)
|
||||||
{
|
{
|
||||||
fUserInfo = other.fUserInfo;
|
fUserInfo = other.fUserInfo;
|
||||||
fComment = other.fComment;
|
|
||||||
fRating = other.fRating;
|
fRating = other.fRating;
|
||||||
|
fComment = other.fComment;
|
||||||
|
fLanguage = other.fLanguage;
|
||||||
fPackageVersion = other.fPackageVersion;
|
fPackageVersion = other.fPackageVersion;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -104,8 +109,9 @@ bool
|
|||||||
UserRating::operator==(const UserRating& other) const
|
UserRating::operator==(const UserRating& other) const
|
||||||
{
|
{
|
||||||
return fUserInfo == other.fUserInfo
|
return fUserInfo == other.fUserInfo
|
||||||
&& fComment == other.fComment
|
|
||||||
&& fRating == other.fRating
|
&& fRating == other.fRating
|
||||||
|
&& fComment == other.fComment
|
||||||
|
&& fLanguage == other.fLanguage
|
||||||
&& fPackageVersion == other.fPackageVersion;
|
&& fPackageVersion == other.fPackageVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,9 @@ class UserRating {
|
|||||||
public:
|
public:
|
||||||
UserRating();
|
UserRating();
|
||||||
UserRating(const UserInfo& userInfo,
|
UserRating(const UserInfo& userInfo,
|
||||||
const BString& comment, float rating,
|
float rating,
|
||||||
|
const BString& comment,
|
||||||
|
const BString& language,
|
||||||
const BString& packageVersion);
|
const BString& packageVersion);
|
||||||
UserRating(const UserRating& other);
|
UserRating(const UserRating& other);
|
||||||
|
|
||||||
@@ -51,8 +53,9 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
UserInfo fUserInfo;
|
UserInfo fUserInfo;
|
||||||
BString fComment;
|
|
||||||
float fRating;
|
float fRating;
|
||||||
|
BString fComment;
|
||||||
|
BString fLanguage;
|
||||||
BString fPackageVersion;
|
BString fPackageVersion;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -171,11 +171,11 @@ PackageColumn::InitTextMargin(BView* parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - PackageListView
|
// #pragma mark - PackageRow
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
kNameColumn,
|
kTitleColumn,
|
||||||
kRatingColumn,
|
kRatingColumn,
|
||||||
kDescriptionColumn,
|
kDescriptionColumn,
|
||||||
kSizeColumn,
|
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()
|
PackageListView::PackageListView()
|
||||||
:
|
:
|
||||||
BColumnListView("package list view", 0, B_FANCY_BORDER, true)
|
BColumnListView("package list view", 0, B_FANCY_BORDER, true)
|
||||||
{
|
{
|
||||||
AddColumn(new PackageColumn(B_TRANSLATE("Name"), 150, 50, 500,
|
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,
|
AddColumn(new PackageColumn(B_TRANSLATE("Rating"), 100, 50, 500,
|
||||||
B_TRUNCATE_MIDDLE), kRatingColumn);
|
B_TRUNCATE_MIDDLE), kRatingColumn);
|
||||||
AddColumn(new PackageColumn(B_TRANSLATE("Description"), 130, 50, 500,
|
AddColumn(new PackageColumn(B_TRANSLATE("Description"), 130, 50, 500,
|
||||||
@@ -221,3 +253,43 @@ PackageListView::MessageReceived(BMessage* message)
|
|||||||
break;
|
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 <ColumnListView.h>
|
||||||
#include <ColumnTypes.h>
|
#include <ColumnTypes.h>
|
||||||
|
|
||||||
|
#include "PackageInfo.h"
|
||||||
|
|
||||||
|
|
||||||
// A field type displaying both a bitmap and a string so that the
|
// A field type displaying both a bitmap and a string so that the
|
||||||
// tree display looks nicer (both text and bitmap are indented)
|
// 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 {
|
class PackageListView : public BColumnListView {
|
||||||
public:
|
public:
|
||||||
PackageListView();
|
PackageListView();
|
||||||
@@ -62,6 +78,12 @@ public:
|
|||||||
|
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
|
void AddPackage(const PackageInfo& package);
|
||||||
|
|
||||||
|
private:
|
||||||
|
PackageRow* _FindRow(const PackageInfo& package,
|
||||||
|
PackageRow* parent = NULL);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PACKAGE_LIST_VIEW_H
|
#endif // PACKAGE_LIST_VIEW_H
|
||||||
|
|||||||
Reference in New Issue
Block a user