summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotr Galiszewski <piotr@galiszewski.pl>2010-07-20 22:33:29 +0200
committerPiotr Galiszewski <piotr@galiszewski.pl>2010-07-21 16:20:47 +0200
commit0af0c28fbcd7e4380c49f2f4b833d13023fb3fd2 (patch)
tree6e506625fd498388104e2450315c42d18552119c
parentd5801d3fef51517e849a33a8ca9f9da5bfb179eb (diff)
downloadaptitude-0af0c28fbcd7e4380c49f2f4b833d13023fb3fd2.tar.gz
Introduce package_pool class
-rw-r--r--src/qt/Makefile.am2
-rw-r--r--src/qt/package_pool.cc182
-rw-r--r--src/qt/package_pool.h79
3 files changed, 263 insertions, 0 deletions
diff --git a/src/qt/Makefile.am b/src/qt/Makefile.am
index cca05516..d89f6e6c 100644
--- a/src/qt/Makefile.am
+++ b/src/qt/Makefile.am
@@ -39,6 +39,8 @@ libqt_a_SOURCES= \
windows/main_window.h \
package.cc \
package.h \
+ package_pool.cc \
+ package_pool.h \
qt_main.cc \
qt_main.h \
tabs_manager.cc \
diff --git a/src/qt/package_pool.cc b/src/qt/package_pool.cc
new file mode 100644
index 00000000..79a09657
--- /dev/null
+++ b/src/qt/package_pool.cc
@@ -0,0 +1,182 @@
+/** \file package_pool.cc */
+//
+// Copyright (C) 2010 Piotr Galiszewski
+//
+// 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.
+
+// Local includes
+#include "package_pool.h"
+
+#include "package.h"
+
+#include <generic/apt/apt.h>
+
+// System includes
+#include "vector"
+
+namespace aptitude
+{
+ namespace gui
+ {
+ namespace qt
+ {
+ class package_pool::package_pool_impl : public package_pool
+ {
+ std::vector<package_ptr> packages;
+
+ /** \brief Metod invoked after cache reloading.
+ *
+ * This method uses package_aware_object to inform others classes about
+ * this event
+ */
+ void handle_cache_reloaded();
+
+ /** \brief Metod invoked after cache closing.
+ *
+ * This method uses package_aware_object to inform others classes about
+ * this event
+ */
+ void handle_cache_closed();
+
+ /** \brief Metod invoked after changing cache state.
+ *
+ * This method uses package_aware_object to inform others classes about
+ * packages which state has changed
+ */
+ void cache_state_changed();
+
+ public:
+ /** \brief Create a new package_pool_impl. */
+ explicit package_pool_impl();
+
+ virtual ~package_pool_impl();
+
+ /** \brief Return the globally unique instance of the package_pool_impl. */
+ static package_pool_impl *get_instance();
+
+ /** \brief Retrieve package count. */
+ int get_packages_count();
+
+ /** \brief Retrieve a pointer to package at given index. */
+ package_ptr get_package_at_index(unsigned int index);
+
+ sigc::signal0<void> cache_closed_signal;
+ sigc::signal0<void> cache_reloaded_signal;
+ sigc::signal1<void, std::vector<package_ptr> > cache_state_changed_signal;
+
+ /** \brief Register a slot to be invoked when the apt cache is reloaded. */
+ sigc::connection connect_cache_reloaded(const sigc::slot<void> &slot);
+
+ /** \brief Register a slot to be invoked when the apt cache is closed. */
+ sigc::connection connect_cache_closed(const sigc::slot<void> &slot);
+
+ /** \brief Register a slot to be invoked when the state of packages changes. */
+ sigc::connection connect_cache_state_changed(const sigc::slot<void, std::vector<package_ptr> > &slot);
+ };
+
+ package_pool::package_pool_impl::package_pool_impl()
+ {
+ cache_closed.connect(sigc::mem_fun(*this, &package_pool::package_pool_impl::handle_cache_closed)),
+ cache_reloaded.connect(sigc::mem_fun(*this, &package_pool::package_pool_impl::handle_cache_reloaded));
+
+ handle_cache_reloaded();
+ }
+
+ package_pool::package_pool_impl::~package_pool_impl()
+ {
+ }
+
+ void package_pool::package_pool_impl::handle_cache_reloaded()
+ {
+ if(apt_cache_file == NULL)
+ return;
+
+ (*apt_cache_file)->package_state_changed.connect(sigc::mem_fun(*this, &package_pool::package_pool_impl::cache_state_changed));
+
+ packages.reserve((*apt_cache_file)->Head().PackageCount);
+
+ for(pkgCache::PkgIterator pkg = (*apt_cache_file)->PkgBegin(); !pkg.end(); ++pkg)
+ {
+ // Filter useless packages up-front.
+ if(pkg.VersionList().end() && pkg.ProvidesList().end())
+ continue;
+
+ packages.push_back(package::create(pkg));
+ }
+
+ cache_reloaded_signal();
+ }
+
+ void package_pool::package_pool_impl::handle_cache_closed()
+ {
+ cache_closed_signal();
+
+ packages.clear();
+ }
+
+ void package_pool::package_pool_impl::cache_state_changed()
+ {
+ // TODO
+ }
+
+ int package_pool::package_pool_impl::get_packages_count()
+ {
+ return packages.size();
+ }
+
+ package_ptr package_pool::package_pool_impl::get_package_at_index(unsigned int index)
+ {
+ if(index >= 0 && index < packages.size())
+ return packages.at(index);
+
+ return package_ptr();
+ }
+
+ sigc::connection
+ package_pool::package_pool_impl::connect_cache_reloaded(const sigc::slot<void> &slot)
+ {
+ return cache_reloaded_signal.connect(slot);
+ }
+
+ sigc::connection
+ package_pool::package_pool_impl::connect_cache_closed(const sigc::slot<void> &slot)
+ {
+ return cache_closed_signal.connect(slot);
+ }
+
+ sigc::connection
+ package_pool::package_pool_impl::connect_cache_state_changed(const sigc::slot<void, std::vector<package_ptr> > &slot)
+ {
+ return cache_state_changed_signal.connect(slot);
+ }
+
+ package_pool *package_pool::get_instance()
+ {
+ static package_pool_impl instance;
+
+ return &instance;
+ }
+
+ package_pool::package_pool()
+ {
+ }
+
+ package_pool::~package_pool()
+ {
+ }
+ }
+ }
+}
diff --git a/src/qt/package_pool.h b/src/qt/package_pool.h
new file mode 100644
index 00000000..284f75fa
--- /dev/null
+++ b/src/qt/package_pool.h
@@ -0,0 +1,79 @@
+/** \file package_pool.h */ // -*-c++-*-
+//
+// Copyright (C) 2010 Piotr Galiszewski
+//
+// 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 APTITUDE_QT_PACKAGE_POOL_H
+#define APTITUDE_QT_PACKAGE_POOL_H
+
+// System includes
+#include <boost/shared_ptr.hpp>
+
+#include <sigc++/connection.h>
+#include <sigc++/slot.h>
+
+#include <vector>
+
+namespace aptitude
+{
+ namespace gui
+ {
+ namespace qt
+ {
+ class package;
+ typedef boost::shared_ptr<package> package_ptr;
+
+ /** \brief Class containig pointers to all used packages from cache.
+ *
+ * This class is responsible for responsing to cache events. It creates
+ * local container containing pointers to all package class objects, which
+ * for example are later used by packages_model class.
+ *
+ * This class also propagates information about changing cache state
+ */
+ class package_pool
+ {
+ package_pool();
+ virtual ~package_pool();
+
+ class package_pool_impl;
+ friend class package_pool_impl;
+
+ public:
+ /** \brief Return the globally unique instance of package_pool. */
+ static package_pool *get_instance();
+
+ /** \brief Retrieve package count. */
+ virtual int get_packages_count() = 0;
+
+ /** \brief Retrieve a pointer to package at given index. */
+ virtual package_ptr get_package_at_index(unsigned int index) = 0;
+
+ /** \brief Register a slot to be invoked when the apt cache is reloaded. */
+ virtual sigc::connection connect_cache_reloaded(const sigc::slot<void> &slot) = 0;
+
+ /** \brief Register a slot to be invoked when the apt cache is closed. */
+ virtual sigc::connection connect_cache_closed(const sigc::slot<void> &slot) = 0;
+
+ /** \brief Register a slot to be invoked when the state of packages changes. */
+ virtual sigc::connection connect_cache_state_changed(const sigc::slot<void, std::vector<package_ptr> > &slot) = 0;
+ };
+ }
+ }
+}
+
+#endif // APTITUDE_QT_PACKAGE_POOL_H