[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/sysadmin/shaman
From:       Dario Freddi <drf () kde ! org>
Date:       2010-01-14 17:04:13
Message-ID: 1263488653.014248.32629.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1074735 by dafre:

API additions to let Shaman operate in Cached or Uncached mode. Also add this feature \
to Aqpm

Signed-off-by: Dario Freddi <drf@kde.org>

 M  +56 -36    libshaman/backends/aqpm/AqpmPlugin.cpp  
 M  +2 -0      libshaman/backends/aqpm/AqpmPlugin.h  
 M  +5 -0      libshaman/shamanbackend.cpp  
 M  +3 -0      libshaman/shamanbackend.h  
 M  +9 -3      libshaman/shamanbackendinterface.cpp  
 M  +13 -4     libshaman/shamanbackendinterface.h  
 M  +2 -1      libshaman/shamanbase.cpp  
 M  +11 -1     libshaman/shamanbase.h  
 M  +1 -0      libshaman/shamanbase_p.h  
 M  +1 -2      shaman/src/MainWindow.cpp  


--- trunk/playground/sysadmin/shaman/libshaman/backends/aqpm/AqpmPlugin.cpp \
#1074734:1074735 @@ -53,7 +53,9 @@
                     Shaman::BackendCapabilities::UpgradeSystemCapability,
                     /*Search capabilities*/
                     Shaman::BackendCapabilities::BasicSearchFromViewCapability | 
-                    Shaman::BackendCapabilities::ExtendedSearchFromViewCapability,
+                    Shaman::BackendCapabilities::ExtendedSearchFromViewCapability |
+                    Shaman::BackendCapabilities::BasicSearchFromBackendCapability |
+                    \
Shaman::BackendCapabilities::ExtendedSearchFromBackendCapability,  /*Package Grouping \
                capabilities*/
                     \
                Shaman::BackendCapabilities::GroupPackagesByPackageGroupsCapability |
                     \
Shaman::BackendCapabilities::GroupPackagesByRepositoryCapability, @@ -160,8 +162,9 @@
 
 bool AqpmPlugin::aboutToChangeState(Shaman::Backend::State oldstate, \
Shaman::Backend::State newstate)  {
-    if ((oldstate == Shaman::Backend::Initializing && newstate == \
                Shaman::Backend::Idling) ||
-        (oldstate == Shaman::Backend::OnTransaction && newstate == \
Shaman::Backend::Idling)) { +    if (((oldstate == Shaman::Backend::Initializing && \
newstate == Shaman::Backend::Idling) || +         (oldstate == \
Shaman::Backend::OnTransaction && newstate == Shaman::Backend::Idling)) && +        \
backend()->operationMode() == Shaman::Base::CachedMode) {  // Time to reload, guys.
         QTimer::singleShot(0, this, SLOT(reload()));
         // If we're initializing, just don't reject the state transition
@@ -202,40 +205,8 @@
         Package::List packages = db->packages();
 
         foreach (Package *package, packages) {
-            AqpmPackage *p = 0;
+            AqpmPackage *p = createShamanPackageFrom(package, upgradeable);
 
-            if (package->isInstalled()) {
-                foreach (Package *uppkg, upgradeable) {
-                    if (uppkg->name() == package->name()) {
-                        p = new AqpmPackage(uppkg, \
                Shaman::AbstractPackage::Upgradeable, this);
-                        break;
-                    }
-                }
-
-                if (!p) {
-                    p = new \
                AqpmPackage(Backend::instance()->package(package->name(), "local"),
-                                        Shaman::AbstractPackage::Installed, this);
-                }
-            } else {
-                p = new AqpmPackage(package, Shaman::AbstractPackage::NotInstalled, \
                this);
-            }
-
-            // Any providers around?
-            foreach (const QString &provider, package->providers()) {
-                QString rp;
-                if (provider.contains('=')) {
-                    rp = provider.split('=').first();
-                } else {
-                    rp = provider;
-                }
-
-                metaPackage(rp)->addPackage(p);
-                // If it's installed it's also the root item
-                if (p->state() == Shaman::AbstractPackage::Installed || p->state() \
                == Shaman::AbstractPackage::Upgradeable) {
-                    metaPackage(rp)->setRootPackage(p);
-                }
-            }
-
             r->append(p);
             pkglist[p->name()] = p;
         }
@@ -269,6 +240,45 @@
     setState(Shaman::Backend::Idling);
 }
 
+AqpmPackage* AqpmPlugin::createShamanPackageFrom(Package* package, const \
Package::List &upgradeable) +{
+    AqpmPackage *p = 0;
+
+    if (package->isInstalled()) {
+        foreach (Package *uppkg, upgradeable) {
+            if (uppkg->name() == package->name()) {
+                p = new AqpmPackage(uppkg, Shaman::AbstractPackage::Upgradeable, \
this); +                break;
+            }
+        }
+
+        if (!p) {
+            p = new AqpmPackage(Backend::instance()->package(package->name(), \
"local"), +                                Shaman::AbstractPackage::Installed, this);
+        }
+    } else {
+        p = new AqpmPackage(package, Shaman::AbstractPackage::NotInstalled, this);
+    }
+
+    // Any providers around?
+    foreach (const QString &provider, package->providers()) {
+        QString rp;
+        if (provider.contains('=')) {
+            rp = provider.split('=').first();
+        } else {
+            rp = provider;
+        }
+
+        metaPackage(rp)->addPackage(p);
+        // If it's installed it's also the root item
+        if (p->state() == Shaman::AbstractPackage::Installed || p->state() == \
Shaman::AbstractPackage::Upgradeable) { +            \
metaPackage(rp)->setRootPackage(p); +        }
+    }
+
+    return p;
+}
+
 void AqpmPlugin::updateRepositories()
 {
     kDebug() << "Update the database";
@@ -751,6 +761,16 @@
         }
     }
 
+    if (!ret && backend()->operationMode() == Shaman::Base::UncachedMode) {
+        // We probably need to add it to the cache. Find it out first.
+        Aqpm::Package *package = Aqpm::Backend::instance()->package(name, \
QString()); +        if (package) {
+            Shaman::AbstractPackage *p = createShamanPackageFrom(package, \
Aqpm::Backend::instance()->upgradeablePackages()); +            ret = p;
+            packagesRetrieved(Shaman::AbstractPackage::List() << p);
+        }
+    }
+
     return ret;
 }
 
--- trunk/playground/sysadmin/shaman/libshaman/backends/aqpm/AqpmPlugin.h \
#1074734:1074735 @@ -18,6 +18,7 @@
 #include <aqpm/QueueItem.h>
 #include <aqpm/Backend.h>
 
+class AqpmPackage;
 class KdemodDistUpgrade;
 
 
@@ -77,6 +78,7 @@
     private:
         void populateCacheForPackageName(const QString &name);
         Shaman::AbstractPackage *findPackageByName(const QString &name);
+        AqpmPackage *createShamanPackageFrom(Aqpm::Package *package, const \
Aqpm::Package::List &upgradeable);  Shaman::TransactionInterface::State \
m_cachedState;  QHash<QString, Shaman::AbstractPackage*> m_packageNameCache;
         int m_dbupdateProgress;
--- trunk/playground/sysadmin/shaman/libshaman/shamanbackend.cpp #1074734:1074735
@@ -500,7 +500,12 @@
     return d->interface->packageFromFile(path);
 }
 
+Base::OperationMode Backend::operationMode() const
+{
+    return Shaman::Base::instance()->d_func()->mode;
 }
 
+}
+
 #include "shamanbackend.moc"
 #include "shamanbackend_p.moc"
--- trunk/playground/sysadmin/shaman/libshaman/shamanbackend.h #1074734:1074735
@@ -22,6 +22,7 @@
 
 #include <KAboutData>
 #include <QtCore/quuid.h>
+#include "shamanbase.h"
 
 class KAboutData;
 class QEvent;
@@ -342,6 +343,8 @@
 
         void unmarkAdditionalTargets();
 
+        Shaman::Base::OperationMode operationMode() const;
+
     Q_SIGNALS:
         /**
          * This signal will be emitted emitted when the current State of the Backend \
                changed.
--- trunk/playground/sysadmin/shaman/libshaman/shamanbackendinterface.cpp \
#1074734:1074735 @@ -108,7 +108,7 @@
     d->backend->d->capabilities->d->informationC = informationCapabilities;
 }
 
-void BackendInterface::setPackages(Shaman::AbstractPackage::List packages)
+void BackendInterface::setPackages(const Shaman::AbstractPackage::List &packages)
 {
     // Delete the unused items
     QSet<Shaman::AbstractPackage*> toDelete = \
d->backend->d->packages.toSet().subtract(packages.toSet()); @@ -119,8 +119,14 @@
     emit d->backend->packagesChanged(packages);
 }
 
-void BackendInterface::setRepositories(Shaman::Repository::List repos)
+void BackendInterface::packagesRetrieved(const Shaman::AbstractPackage::List& \
packages)  {
+    d->backend->d->packages.append(packages);
+    emit d->backend->packagesChanged(packages);
+}
+
+void BackendInterface::setRepositories(const Shaman::Repository::List &repos)
+{
     // Delete the unused items
     QSet<Shaman::Repository*> toDelete = \
d->backend->d->repos.toSet().subtract(repos.toSet());  qDeleteAll(toDelete);
@@ -130,7 +136,7 @@
     emit d->backend->repositoriesChanged(repos);
 }
 
-void BackendInterface::setPackageGroups(Shaman::PackageGroup::List groups)
+void BackendInterface::setPackageGroups(const Shaman::PackageGroup::List &groups)
 {
     // Delete the unused items
     QSet<Shaman::PackageGroup*> toDelete = \
                d->backend->d->groups.toSet().subtract(groups.toSet());
--- trunk/playground/sysadmin/shaman/libshaman/shamanbackendinterface.h \
#1074734:1074735 @@ -343,22 +343,31 @@
         void setError(Shaman::Backend::Error error, const QString &details);
 
         /**
-         * Sets the Packages of the Backend. This is needed while initializing.
+         * Sets the Packages of the Backend. This is needed while initializing. All \
the packages previously +         * in the cache (not contained in \c packages) will \
be freed. +         *
+         * \note This has to be used \b ONLY in cached mode. Use \c \
                packagesRetrieved instead.
          * @param packages the Packages of the Backend
          */
-        void setPackages(Shaman::AbstractPackage::List packages);
+        void setPackages(const Shaman::AbstractPackage::List &packages);
 
         /**
+         * Call this function whenever the backend caches new packages. This \
function has to be used when the backend +         * is in uncached mode and \
retrieved some packages, for example through a search or while marking additional \
targets. +         */
+        void packagesRetrieved(const Shaman::AbstractPackage::List &packages);
+
+        /**
          * Sets the Repositories of the Backend. This is needed while initializing.
          * @param repos the Repositories of the Backend
          */
-        void setRepositories(Shaman::Repository::List repos);
+        void setRepositories(const Shaman::Repository::List &repos);
 
         /**
          * Sets the PackageGroups of the Backend. This is needed while initializing
          * @param groups the PackageGroups of the Backend
          */
-        void setPackageGroups(Shaman::PackageGroup::List groups);
+        void setPackageGroups(const Shaman::PackageGroup::List &groups);
 
         // Transaction setters
         /**
--- trunk/playground/sysadmin/shaman/libshaman/shamanbase.cpp #1074734:1074735
@@ -60,11 +60,12 @@
     delete d_ptr;
 }
 
-void Base::init(bool gui)
+void Base::init(OperationMode mode, bool gui)
 {
     Q_D(Base);
     //Initialize CoreInterface
     d->coreInterface = new CoreInterface(this);
+    d->mode = mode;
 
     if (gui) {
         if (!d->statusBarInterface) {
--- trunk/playground/sysadmin/shaman/libshaman/shamanbase.h #1074734:1074735
@@ -79,6 +79,16 @@
         };
         Q_DECLARE_FLAGS(PluginTypes, PluginType)
 
+        /**
+         * \enum OperationMode
+         * This enum describe the operation modes of the backend
+         */
+        enum OperationMode
+        {
+            UncachedMode = 0,
+            CachedMode = 1
+        };
+
         static Base *instance();
 
         ~Base();
@@ -150,7 +160,7 @@
          * \param gui set to true if this is a Gui program. If \c false, \
                GuiInterface won't be
          *            created
          */
-        void init(bool gui = true);
+        void init(OperationMode mode = UncachedMode, bool gui = false);
 
     Q_SIGNALS:
         /**
--- trunk/playground/sysadmin/shaman/libshaman/shamanbase_p.h #1074734:1074735
@@ -47,6 +47,7 @@
         KSharedConfig::Ptr config;
         Base::PluginTypes pluginTypes;
         QStringList plugins;
+        Base::OperationMode mode;
 
         void __k__slotBackendCreated(Backend *backend);
         void __k__slotProviderCreated(Provider *provider);
--- trunk/playground/sysadmin/shaman/shaman/src/MainWindow.cpp #1074734:1074735
@@ -76,10 +76,9 @@
     connect(m_shaman, SIGNAL(createAction(QAction *)), SLOT(slotCreateAction(QAction \
*)));  connect(m_shaman, SIGNAL(initCompleted()), SLOT(setUpGui()));
 
-    connect(this, SIGNAL(shamanReady()), m_shaman, SLOT(init()));
     connect(KApplication::instance(), SIGNAL(aboutToQuit()), this, \
SLOT(aboutToQuit()));  
-    emit shamanReady();
+    m_shaman->init(Shaman::Base::CachedMode, true);
 }
 
 MainWindow::~MainWindow()


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic