From 0af0c28fbcd7e4380c49f2f4b833d13023fb3fd2 Mon Sep 17 00:00:00 2001 From: Piotr Galiszewski Date: Tue, 20 Jul 2010 22:33:29 +0200 Subject: Introduce package_pool class --- src/qt/Makefile.am | 2 + src/qt/package_pool.cc | 182 +++++++++++++++++++++++++++++++++++++++++++++++++ src/qt/package_pool.h | 79 +++++++++++++++++++++ 3 files changed, 263 insertions(+) create mode 100644 src/qt/package_pool.cc create mode 100644 src/qt/package_pool.h 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 + +// System includes +#include "vector" + +namespace aptitude +{ + namespace gui + { + namespace qt + { + class package_pool::package_pool_impl : public package_pool + { + std::vector 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 cache_closed_signal; + sigc::signal0 cache_reloaded_signal; + sigc::signal1 > 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 &slot); + + /** \brief Register a slot to be invoked when the apt cache is closed. */ + sigc::connection connect_cache_closed(const sigc::slot &slot); + + /** \brief Register a slot to be invoked when the state of packages changes. */ + sigc::connection connect_cache_state_changed(const sigc::slot > &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 &slot) + { + return cache_reloaded_signal.connect(slot); + } + + sigc::connection + package_pool::package_pool_impl::connect_cache_closed(const sigc::slot &slot) + { + return cache_closed_signal.connect(slot); + } + + sigc::connection + package_pool::package_pool_impl::connect_cache_state_changed(const sigc::slot > &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 + +#include +#include + +#include + +namespace aptitude +{ + namespace gui + { + namespace qt + { + class package; + typedef boost::shared_ptr 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 &slot) = 0; + + /** \brief Register a slot to be invoked when the apt cache is closed. */ + virtual sigc::connection connect_cache_closed(const sigc::slot &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 > &slot) = 0; + }; + } + } +} + +#endif // APTITUDE_QT_PACKAGE_POOL_H -- cgit v1.2.3