[haiku-commits] BRANCH HaikuPM-github.package-management [b4c8d2f] src/apps/haiku-depot

  • From: HaikuPM-github.package-management <community@xxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 19 Sep 2013 14:00:33 +0200 (CEST)

added 1 changeset to branch 'refs/remotes/HaikuPM-github/package-management'
old head: 50792d1199fdc9a211beb49ab282a7ce0a5c4c03
new head: b4c8d2ff49d89fa8d804bb8e58c6cf96fa01ecd0
overview: https://github.com/haiku/HaikuPM/compare/50792d1...b4c8d2f

----------------------------------------------------------------------------

b4c8d2f: HaikuDepot: Show installation state in list view.
  
  - Add package installation state to PackageInfo and update accordingly
    in Model.
  - Add package listener event for installation state change (not yet used).
  - PackageListView now fetches installation state from package and displays
    accordingly.

                                      [ Rene Gollent <anevilyak@xxxxxxxxx> ]

----------------------------------------------------------------------------

Commit:      b4c8d2ff49d89fa8d804bb8e58c6cf96fa01ecd0
Author:      Rene Gollent <anevilyak@xxxxxxxxx>
Date:        Thu Sep 19 10:47:44 2013 UTC

----------------------------------------------------------------------------

5 files changed, 57 insertions(+), 13 deletions(-)
src/apps/haiku-depot/Model.cpp             |  2 ++
src/apps/haiku-depot/PackageInfo.cpp       | 18 ++++++++++++++---
src/apps/haiku-depot/PackageInfo.h         | 21 +++++++++++--------
src/apps/haiku-depot/PackageInfoListener.h |  1 +
src/apps/haiku-depot/PackageListView.cpp   | 28 ++++++++++++++++++++++++--

----------------------------------------------------------------------------

diff --git a/src/apps/haiku-depot/Model.cpp b/src/apps/haiku-depot/Model.cpp
index c2c76e5..1ea70a2 100644
--- a/src/apps/haiku-depot/Model.cpp
+++ b/src/apps/haiku-depot/Model.cpp
@@ -323,6 +323,8 @@ Model::SetPackageState(const PackageInfoRef& package, 
PackageState state)
                        fUninstalledPackages.Add(package);
                        break;
        }
+
+       package->SetState(state);
 }
 
 
diff --git a/src/apps/haiku-depot/PackageInfo.cpp 
b/src/apps/haiku-depot/PackageInfo.cpp
index a202cc2..c200f12 100644
--- a/src/apps/haiku-depot/PackageInfo.cpp
+++ b/src/apps/haiku-depot/PackageInfo.cpp
@@ -445,7 +445,8 @@ PackageInfo::PackageInfo()
        fFullDescription(),
        fChangelog(),
        fUserRatings(),
-       fScreenshots()
+       fScreenshots(),
+       fState(NONE)
 {
 }
 
@@ -464,7 +465,8 @@ PackageInfo::PackageInfo(const BitmapRef& icon, const 
BString& title,
        fChangelog(changelog),
        fCategories(),
        fUserRatings(),
-       fScreenshots()
+       fScreenshots(),
+       fState(NONE)
 {
 }
 
@@ -480,7 +482,8 @@ PackageInfo::PackageInfo(const PackageInfo& other)
        fChangelog(other.fChangelog),
        fCategories(other.fCategories),
        fUserRatings(other.fUserRatings),
-       fScreenshots(other.fScreenshots)
+       fScreenshots(other.fScreenshots),
+       fState(other.fState)
 {
 }
 
@@ -498,6 +501,7 @@ PackageInfo::operator=(const PackageInfo& other)
        fCategories = other.fCategories;
        fUserRatings = other.fUserRatings;
        fScreenshots = other.fScreenshots;
+       fState = other.fState;
        return *this;
 }
 
@@ -532,6 +536,14 @@ PackageInfo::AddCategory(const CategoryRef& category)
 }
 
 
+void
+PackageInfo::SetState(PackageState state)
+{
+       fState = state;
+       _NotifyListeners(PKG_CHANGED_STATE);
+}
+
+
 bool
 PackageInfo::AddUserRating(const UserRating& rating)
 {
diff --git a/src/apps/haiku-depot/PackageInfo.h 
b/src/apps/haiku-depot/PackageInfo.h
index f4f74fa..485b139 100644
--- a/src/apps/haiku-depot/PackageInfo.h
+++ b/src/apps/haiku-depot/PackageInfo.h
@@ -185,6 +185,14 @@ typedef List<CategoryRef, false> CategoryList;
 typedef List<PackageInfoListenerRef, false, 2> PackageListenerList;
 
 
+enum PackageState {
+       NONE            = 0,
+       INSTALLED       = 1,
+       ACTIVATED       = 2,
+       UNINSTALLED     = 3,
+};
+
+
 class PackageInfo : public BReferenceable {
 public:
                                                                PackageInfo();
@@ -216,6 +224,10 @@ public:
                        const BString&          Changelog() const
                                                                        { 
return fChangelog; }
 
+                       PackageState            State() const
+                                                                       { 
return fState; }
+                       void                            SetState(PackageState 
state);
+
                        bool                            AddCategory(const 
CategoryRef& category);
                        const CategoryList&     Categories() const
                                                                        { 
return fCategories; }
@@ -248,6 +260,7 @@ private:
                        CategoryList            fCategories;
                        UserRatingList          fUserRatings;
                        BitmapList                      fScreenshots;
+                       PackageState            fState;
                        PackageListenerList     fListeners;
 };
 
@@ -258,14 +271,6 @@ typedef BReference<PackageInfo> PackageInfoRef;
 typedef List<PackageInfoRef, false> PackageList;
 
 
-enum PackageState {
-       NONE            = 0,
-       INSTALLED       = 1,
-       ACTIVATED       = 2,
-       UNINSTALLED     = 3,
-};
-
-
 class DepotInfo {
 public:
                                                                DepotInfo();
diff --git a/src/apps/haiku-depot/PackageInfoListener.h 
b/src/apps/haiku-depot/PackageInfoListener.h
index 323733a..88154d2 100644
--- a/src/apps/haiku-depot/PackageInfoListener.h
+++ b/src/apps/haiku-depot/PackageInfoListener.h
@@ -13,6 +13,7 @@ enum {
        PKG_CHANGED_DESCRIPTION         = 1 << 0,
        PKG_CHANGED_RATINGS                     = 1 << 1,
        PKG_CHANGED_SCREENSHOTS         = 1 << 2,
+       PKG_CHANGED_STATE                       = 1 << 3
        // ...
 };
 
diff --git a/src/apps/haiku-depot/PackageListView.cpp 
b/src/apps/haiku-depot/PackageListView.cpp
index 3e3b163..1d693a1 100644
--- a/src/apps/haiku-depot/PackageListView.cpp
+++ b/src/apps/haiku-depot/PackageListView.cpp
@@ -18,6 +18,29 @@
 #define B_TRANSLATION_CONTEXT "PackageListView"
 
 
+static const char* skPackageStateAvailable = B_TRANSLATE_MARK("Available");
+static const char* skPackageStateUninstalled = B_TRANSLATE_MARK("Uninstalled");
+static const char* skPackageStateActive = B_TRANSLATE_MARK("Active");
+static const char* skPackageStateInactive = B_TRANSLATE_MARK("Inactive");
+
+
+inline BString PackageStateToString(PackageState state)
+{
+       switch (state) {
+               case NONE:
+                       return B_TRANSLATE(skPackageStateAvailable);
+               case INSTALLED:
+                       return B_TRANSLATE(skPackageStateInactive);
+               case ACTIVATED:
+                       return B_TRANSLATE(skPackageStateActive);
+               case UNINSTALLED:
+                       return B_TRANSLATE(skPackageStateUninstalled);
+       }
+
+       return B_TRANSLATE("Unknown");
+}
+
+
 // A field type displaying both a bitmap and a string so that the
 // tree display looks nicer (both text and bitmap are indented)
 // TODO: Code-duplication with DriveSetup PartitionList.h
@@ -450,8 +473,9 @@ PackageRow::PackageRow(const PackageInfoRef& packageRef,
        SetField(new BStringField("0 KiB"), kSizeColumn);
 
        // Status
-       // TODO: Fetch info about installed/deactivated/unintalled/...
-       SetField(new BStringField("n/a"), kStatusColumn);
+       // TODO: Fetch info about installed/deactivated/uninstalled/...
+       SetField(new BStringField(PackageStateToString(package.State())),
+               kStatusColumn);
 
        package.AddListener(fPackageListener);
 }


Other related posts: