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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
//
// C++ Implementation: aptactionplugin
//
// Description:
//
//
// Author: Benjamin Mesing <bensmail@gmx.net>, (C) 2005
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "aptactionplugin.h"
#include <QAction>
#include <QApplication>
#include <QClipboard>
// NApplication
#include "applicationfactory.h"
#include "runcommand.h"
// NPlugin
#include <iprovider.h>
#include "iaptmediator.h"
#include "helpers.h"
namespace NPlugin
{
const QString AptActionPlugin::PLUGIN_NAME = "AptActionPlugin";
AptActionPlugin::AptActionPlugin(IAptMediator* pMediator) :
_title("Apt-Action Plugin"),
_briefDescription("Offers the menu and toolbar entries"),
_description("This plugin offers the menu and toolbar entries for the APT plugin. "
"This includes the possibilities to install and remove packages."),
_pMediator(pMediator)
{
QAction* pQAptUpdateAction = new QAction(tr("Update Apt-Package Database"), this);
pQAptUpdateAction->setStatusTip(tr("Updates the package database"));
_pUpdateAction = new Action(pQAptUpdateAction, false, "System");
connect(pQAptUpdateAction, SIGNAL(triggered(bool)), SLOT(onUpdateAction()));
QAction* pQReloadDbAction = new QAction(QObject::tr("Reload Package Database"), this);
pQReloadDbAction->setStatusTip(tr("Reloads the package database from disk "
"(e.g. if apt-get update was performed externally)."));
_pReloadDbAction = new Action(pQReloadDbAction, false, "System");
connect(pQReloadDbAction, SIGNAL(triggered(bool)), SLOT(onReloadAction()));
QAction* pQAptGetLineAction = new QAction(tr("Copy Command Line for Installing Package to Clipboard"), this);
pQAptGetLineAction->setToolTip(tr("Creates a command line to install the selected package, and copies it to the clipboard"));
pQAptGetLineAction->setStatusTip(tr("Creates a command line to install the selected package, and copies it to the clipboard"));
connect(pQAptGetLineAction, SIGNAL(triggered(bool)), SLOT(onCreateInstallLineAction()));
_pCreateInstallLineAction = new Action(pQAptGetLineAction, true);
QAction* pQAptGetInstallAction = new QAction(tr("Install/Update Package"), this);
pQAptGetInstallAction->setToolTip(tr("Installs/updates the package"));
pQAptGetInstallAction->setStatusTip(tr("Installs/updates the package"));
connect(pQAptGetInstallAction, SIGNAL(triggered(bool)), SLOT(onInstallAction()));
_pInstallAction = new Action(pQAptGetInstallAction, true, "Packages", "Main");
QAction* pQAptGetRemoveAction = new QAction(tr("Remove Package"), this);
pQAptGetRemoveAction->setToolTip(tr("Removes the package"));
pQAptGetRemoveAction->setStatusTip(tr("Removes the package"));
connect(pQAptGetRemoveAction, SIGNAL(triggered(bool)), SLOT(onRemoveAction()));
_pRemoveAction = new Action(pQAptGetRemoveAction, true, "Packages", "Main");
QAction* pQPurgeAction = new QAction(tr("Purge Package"), this);
pQPurgeAction->setToolTip(tr("Removes package including configuration"));
pQPurgeAction->setStatusTip(tr("Removes package including configuration"));
connect(pQPurgeAction, SIGNAL(triggered(bool)), SLOT(onPurgeAction()));
_pPurgeAction = new Action(pQPurgeAction, true, "Packages");
QAction* pQSeparatorAction = new QAction(this);
pQSeparatorAction->setSeparator(true);
_pSeparatorAction = new Action(pQSeparatorAction, true, "System");
}
AptActionPlugin::~AptActionPlugin()
{
delete _pUpdateAction;
delete _pReloadDbAction;
delete _pSeparatorAction;
delete _pCreateInstallLineAction;
delete _pInstallAction;
delete _pRemoveAction;
delete _pPurgeAction;
}
/////////////////////////////////////////////////////
// Plugin Interface
/////////////////////////////////////////////////////
void AptActionPlugin::init(IProvider* pProvider)
{
_pProvider = pProvider;
QIcon installIcon(_pProvider->iconDir()+"install-package.png");
_pInstallAction->action()->setIcon(installIcon);
QIcon removeIcon(_pProvider->iconDir()+"remove-package.png");
_pRemoveAction->action()->setIcon(removeIcon);
};
/////////////////////////////////////////////////////
// ActionPlugin Interface
/////////////////////////////////////////////////////
vector<Action*> AptActionPlugin::actions() const
{
vector<Action*> actions;
actions.push_back(_pSeparatorAction);
actions.push_back(_pUpdateAction);
actions.push_back(_pReloadDbAction);
actions.push_back(_pCreateInstallLineAction);
actions.push_back(_pInstallAction);
actions.push_back(_pRemoveAction);
actions.push_back(_pPurgeAction);
return actions;
}
/////////////////////////////////////////////////////
// Other Methods
/////////////////////////////////////////////////////
void AptActionPlugin::onCreateInstallLineAction()
{
QClipboard *pCb = QApplication::clipboard();
pCb->setText(installationToolCommand() + " install "+_pProvider->currentPackage(), QClipboard::Clipboard);
pCb->setText(installationToolCommand() + " install "+_pProvider->currentPackage(), QClipboard::Selection);
}
void AptActionPlugin::onInstallAction()
{
installOrRemove(true);
}
void AptActionPlugin::onRemoveAction()
{
installOrRemove(false);
}
void AptActionPlugin::onPurgeAction()
{
installOrRemove(false, true);
}
void AptActionPlugin::onUpdateAction()
{
_pMediator->updateAptDatabase();
}
void AptActionPlugin::onReloadAction()
{
_pMediator->reloadAptDatabase();
}
void AptActionPlugin::installOrRemove(bool install, bool purge)
{
NApplication::RunCommand* pCommand = NApplication::ApplicationFactory::getInstance()->getRunCommand("");
pCommand->addArgument(installationToolCommand());
if (install)
pCommand->addArgument("install");
else
{
if (purge)
pCommand->addArgument("purge");
else
pCommand->addArgument("remove");
}
pCommand->addArgument(_pProvider->currentPackage());
try
{
pCommand->startAsRoot();
}
catch (const NException::RuntimeException& e)
{
_pProvider->reportError(tr("Unable to launch command"), toQString(e.description()) +
QString(tr("\nPlease configure to use \"apt\" as package administration tool "
"(Packagesearch->Settings->Apt Plugins)"))
);
delete pCommand;
}
}
QString AptActionPlugin::installationToolCommand()
{
return _pMediator->installationToolCommand();
}
}
|