From 3883c02097d4e8819c39d49456d5488c3319bd52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 28 Jul 2013 14:59:11 +0200 Subject: [PATCH] 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. --- src/apps/haiku-depot/MainWindow.cpp | 67 +++++++++++++++++++- src/apps/haiku-depot/MainWindow.h | 7 ++- src/apps/haiku-depot/PackageInfo.cpp | 20 +++--- src/apps/haiku-depot/PackageInfo.h | 7 ++- src/apps/haiku-depot/PackageListView.cpp | 78 +++++++++++++++++++++++- src/apps/haiku-depot/PackageListView.h | 22 +++++++ 6 files changed, 186 insertions(+), 15 deletions(-) diff --git a/src/apps/haiku-depot/MainWindow.cpp b/src/apps/haiku-depot/MainWindow.cpp index ffd288da4a..e00ca2cb45 100644 --- a/src/apps/haiku-depot/MainWindow.cpp +++ b/src/apps/haiku-depot/MainWindow.cpp @@ -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); +} diff --git a/src/apps/haiku-depot/MainWindow.h b/src/apps/haiku-depot/MainWindow.h index f148a7ad6c..f1aff79a65 100644 --- a/src/apps/haiku-depot/MainWindow.h +++ b/src/apps/haiku-depot/MainWindow.h @@ -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; diff --git a/src/apps/haiku-depot/PackageInfo.cpp b/src/apps/haiku-depot/PackageInfo.cpp index ef0fac62e8..10a6724c04 100644 --- a/src/apps/haiku-depot/PackageInfo.cpp +++ b/src/apps/haiku-depot/PackageInfo.cpp @@ -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; } diff --git a/src/apps/haiku-depot/PackageInfo.h b/src/apps/haiku-depot/PackageInfo.h index db5db3022e..10e3419ef7 100644 --- a/src/apps/haiku-depot/PackageInfo.h +++ b/src/apps/haiku-depot/PackageInfo.h @@ -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; }; diff --git a/src/apps/haiku-depot/PackageListView.cpp b/src/apps/haiku-depot/PackageListView.cpp index 2877d6f8f0..9a92470843 100644 --- a/src/apps/haiku-depot/PackageListView.cpp +++ b/src/apps/haiku-depot/PackageListView.cpp @@ -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(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; +} + diff --git a/src/apps/haiku-depot/PackageListView.h b/src/apps/haiku-depot/PackageListView.h index ac2388988e..cf588f80b8 100644 --- a/src/apps/haiku-depot/PackageListView.h +++ b/src/apps/haiku-depot/PackageListView.h @@ -9,6 +9,8 @@ #include #include +#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