summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Nicoletti <dantti12@gmail.com>2012-04-22 11:17:02 -0300
committerDaniel Nicoletti <dantti12@gmail.com>2012-04-22 11:17:02 -0300
commit4b529d627b1d133b81f766296fe8ad6ce78ab380 (patch)
tree8f077ec73f3ef01ab6a3362339fd7d1490aa749a
parent8440e54ff81f2fc22df5615bf2db16c8485d2b44 (diff)
aptcc: Add a new class to show cache openning progress
-rw-r--r--backends/aptcc/AptCacheFile.cpp7
-rw-r--r--backends/aptcc/OpPackageKitProgress.cpp49
-rw-r--r--backends/aptcc/OpPackageKitProgress.h45
-rw-r--r--backends/aptcc/apt-intf.cpp3
4 files changed, 99 insertions, 5 deletions
diff --git a/backends/aptcc/AptCacheFile.cpp b/backends/aptcc/AptCacheFile.cpp
index ddba16a5..7753a99a 100644
--- a/backends/aptcc/AptCacheFile.cpp
+++ b/backends/aptcc/AptCacheFile.cpp
@@ -20,6 +20,7 @@
#include "AptCacheFile.h"
#include "apt-utils.h"
+#include "OpPackageKitProgress.h"
#include <apt-pkg/algorithms.h>
#include <sstream>
@@ -38,7 +39,8 @@ AptCacheFile::~AptCacheFile()
bool AptCacheFile::Open(bool withLock)
{
- return pkgCacheFile::Open(NULL, withLock);
+ OpPackageKitProgress progress(m_backend);
+ return pkgCacheFile::Open(&progress, withLock);
}
void AptCacheFile::Close()
@@ -56,7 +58,8 @@ void AptCacheFile::Close()
bool AptCacheFile::BuildCaches(bool withLock)
{
- return pkgCacheFile::BuildCaches(NULL, withLock);
+ OpPackageKitProgress progress(m_backend);
+ return pkgCacheFile::BuildCaches(&progress, withLock);
}
bool AptCacheFile::CheckDeps(bool FixBroken)
diff --git a/backends/aptcc/OpPackageKitProgress.cpp b/backends/aptcc/OpPackageKitProgress.cpp
new file mode 100644
index 00000000..8c64fa35
--- /dev/null
+++ b/backends/aptcc/OpPackageKitProgress.cpp
@@ -0,0 +1,49 @@
+/* OpPackageKitProgress.cpp
+ *
+ * Copyright (c) 2012 Daniel Nicoletti <dantti12@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "OpPackageKitProgress.h"
+
+OpPackageKitProgress::OpPackageKitProgress(PkBackend *backend) :
+ m_backend(backend)
+{
+ // Set PackageKit status
+ pk_backend_set_status(m_backend, PK_STATUS_ENUM_LOADING_CACHE);
+}
+
+OpPackageKitProgress::~OpPackageKitProgress()
+{
+ Done();
+}
+
+void OpPackageKitProgress::Done()
+{
+ pk_backend_set_percentage(m_backend, 100);
+}
+
+void OpPackageKitProgress::Update()
+{
+ if (CheckChange() == false) {
+ // No change has happened skip
+ return;
+ }
+
+ // Set the new percent
+ pk_backend_set_percentage(m_backend, static_cast<unsigned int>(Percent));
+}
diff --git a/backends/aptcc/OpPackageKitProgress.h b/backends/aptcc/OpPackageKitProgress.h
new file mode 100644
index 00000000..4ecf9b84
--- /dev/null
+++ b/backends/aptcc/OpPackageKitProgress.h
@@ -0,0 +1,45 @@
+/* OpPackageKitProgress.h
+ *
+ * Copyright (c) 2012 Daniel Nicoletti <dantti12@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#ifndef OP_PACKAGEKIT_PROGRESS_H
+#define OP_PACKAGEKIT_PROGRESS_H
+
+#include <apt-pkg/progress.h>
+
+#include <pk-backend.h>
+
+/**
+ * This class is maent to show Operation Progress using PackageKit
+ */
+class OpPackageKitProgress : public OpProgress
+{
+public:
+ OpPackageKitProgress(PkBackend *backend);
+ virtual ~OpPackageKitProgress();
+
+ virtual void Done();
+
+protected:
+ virtual void Update();
+
+private:
+ PkBackend *m_backend;
+};
+
+#endif // OP_PACKAGEKIT_PROGRESS_H
diff --git a/backends/aptcc/apt-intf.cpp b/backends/aptcc/apt-intf.cpp
index 4389c8cd..2b26cb95 100644
--- a/backends/aptcc/apt-intf.cpp
+++ b/backends/aptcc/apt-intf.cpp
@@ -74,9 +74,6 @@ bool AptIntf::init()
m_isMultiArch = APT::Configuration::getArchitectures(false).size() > 1;
- // Set PackageKit status
- pk_backend_set_status(m_backend, PK_STATUS_ENUM_LOADING_CACHE);
-
// set locale
if (locale = pk_backend_get_locale(m_backend)) {
setlocale(LC_ALL, locale);