1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
#include <qcombobox.h>
#include <QMainWindow>
#include <iprovider.h>
#include <packagenotfoundexception.h>
#include "packagestatusplugin.h"
#include "installedfilterwidget.h"
#include "ipackagedb.h"
namespace NPlugin
{
const QString PackageStatusPlugin::PLUGIN_NAME = "PackageStatusPlugin";
PackageStatusPlugin::PackageStatusPlugin(NApt::IPackageDB* pPackageDB) :
_title(tr("Package Status Plugin")),
/// @todo implement descriptions here
_briefDescription(tr("")),
_description(tr("")),
_installedFilter(ALL),
_pPackageDB(pPackageDB)
{
_pInstalledFilterWidget = 0;
_stateToText[NApt::IPackage::INSTALLED] = "i";
_stateToText[NApt::IPackage::UPGRADABLE] = "u";
_stateToText[NApt::IPackage::NOT_INSTALLED] = "";
}
PackageStatusPlugin::~PackageStatusPlugin()
{
delete _pInstalledFilterWidget;
}
/////////////////////////////////////////////////////
// Plugin Interface
/////////////////////////////////////////////////////
void PackageStatusPlugin::init(IProvider* pProvider)
{
QMainWindow* pWindow = pProvider->mainWindow();
_pInstalledFilterWidget = new InstalledFilterWidget(pWindow);
_pInstalledFilterWidget->setObjectName("InstalledFilterInput");
_pInstalledFilterWidget->show();
connect(_pInstalledFilterWidget->_pInstalledFilterInput,
SIGNAL(activated(int)), SLOT(onInstalledFilterChanged(int))
);
}
/////////////////////////////////////////////////////
// SearchPlugin Interface
/////////////////////////////////////////////////////
QWidget* PackageStatusPlugin::shortInputAndFeedbackWidget() const
{
return _pInstalledFilterWidget;
}
bool PackageStatusPlugin::filterPackage(const string& package) const
{
try
{
NApt::IPackage::InstalledState state = getState(package);
if (_installedFilter == INSTALLED)
return state == NApt::IPackage::INSTALLED || state == NApt::IPackage::UPGRADABLE;
else
return _installedFilter == (InstalledState) state; // does the state of the package match the on filtered by?
}
catch (const PackageNotFoundException& e) // if the package is not in the database, it is not installed
{
return _installedFilter == NOT_INSTALLED;
}
}
void PackageStatusPlugin::clearSearch()
{
_pInstalledFilterWidget->_pInstalledFilterInput->setCurrentIndex(0);
// this should not be neccessary, because setCurrentIndex(0) should trigger
// onInstalledFilterChanged
onInstalledFilterChanged(0);
}
bool PackageStatusPlugin::isInactive() const
{
return _installedFilter == ALL;
}
/////////////////////////////////////////////////////
// ShortInformationPlugin Interface
/////////////////////////////////////////////////////
const QString PackageStatusPlugin::shortInformationText(const string& package)
{
return _stateToText[getState(package)]; // returns the text for the state of the package
}
/////////////////////////////////////////////////////
// PackageStatusPlugin functions
/////////////////////////////////////////////////////
NApt::IPackage::InstalledState PackageStatusPlugin::getState(const string& package) const
{
try
{
return _pPackageDB->getState(package);
}
catch (const PackageNotFoundException& e)
{
return NApt::IPackage::NOT_INSTALLED;
}
}
void PackageStatusPlugin::onInstalledFilterChanged(int activated)
{
switch (activated)
{
case 0:
_installedFilter = ALL;
break;
case 1:
_installedFilter = INSTALLED;
break;
case 2:
_installedFilter = UPGRADABLE;
break;
case 3:
_installedFilter = NOT_INSTALLED;
break;
}
emit searchChanged(this);
}
} // namespace NPlugin
|