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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
|
/***************************************************************************
* Copyright © 2010 Jonathan Thomas <echidnaman@kubuntu.org> *
* *
* 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) version 3 or any later version *
* accepted by the membership of KDE e.V. (or its successor approved *
* by the membership of KDE e.V.), which shall act as a proxy *
* defined in Section 14 of version 3 of the license. *
* *
* 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. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "qapttest.h"
#include <QDir>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QStackedWidget>
#include <KDebug>
#include <KIcon>
#include <KGlobal>
#include <KLocale>
#include <KLineEdit>
#include <KProtocolManager>
#include <KStatusBar>
#include <KVBox>
#include <LibQApt/Backend>
#include <LibQApt/Transaction>
#include <DebconfGui.h>
#include "cacheupdatewidget.h"
#include "commitwidget.h"
QAptTest::QAptTest()
: KMainWindow()
, m_trans(0)
, m_stack(0)
{
setWindowIcon(KIcon("application-x-deb"));
m_backend = new QApt::Backend(this);
m_backend->init();
connect(m_backend, SIGNAL(packageChanged()), this, SLOT(updateStatusBar()));
m_stack = new QStackedWidget(this);
m_mainWidget = new QWidget(m_stack);
QVBoxLayout *layout = new QVBoxLayout(m_mainWidget);
m_stack->addWidget(m_mainWidget);
m_cacheUpdateWidget = new CacheUpdateWidget(m_stack);
m_stack->addWidget(m_cacheUpdateWidget);
m_commitWidget = new CommitWidget(m_stack);
m_stack->addWidget(m_commitWidget);
m_stack->setCurrentWidget(m_mainWidget);
KHBox *topHBox = new KHBox(m_mainWidget);
layout->addWidget(topHBox);
m_lineEdit = new KLineEdit(topHBox);
m_lineEdit->setText("muon");
m_lineEdit->setClearButtonShown(true);
connect(m_lineEdit, SIGNAL(returnPressed()), this, SLOT(updateLabels()));
QPushButton *showButton = new QPushButton(topHBox);
showButton->setText(i18n("Show"));
showButton->setIcon(KIcon("layer-visible-on"));
connect(showButton, SIGNAL(clicked()), this, SLOT(updateLabels()));
m_actionButton = new QPushButton(topHBox);
connect(m_actionButton, SIGNAL(clicked()), this, SLOT(commitAction()));
KVBox *vbox = new KVBox(m_mainWidget);
layout->addWidget(vbox);
m_nameLabel = new QLabel(vbox);
m_sectionLabel = new QLabel(vbox);
m_originLabel = new QLabel(vbox);
m_installedSizeLabel = new QLabel(vbox);
m_maintainerLabel = new QLabel(vbox);
m_sourceLabel = new QLabel(vbox);
m_versionLabel = new QLabel(vbox);
m_packageSizeLabel = new QLabel(vbox);
m_shortDescriptionLabel = new QLabel(vbox);
m_longDescriptionLabel = new QLabel(vbox);
KHBox *bottomHBox = new KHBox(m_mainWidget);
layout->addWidget(bottomHBox);
QPushButton *cacheButton = new QPushButton(bottomHBox);
cacheButton->setText(i18n("Update Cache"));
cacheButton->setIcon(KIcon("view-refresh"));
connect(cacheButton, SIGNAL(clicked()), this, SLOT(updateCache()));
QPushButton *upgradeButton = new QPushButton(bottomHBox);
upgradeButton->setText(i18n("Upgrade System"));
upgradeButton->setIcon(KIcon("system-software-update"));
connect(upgradeButton, SIGNAL(clicked()), this, SLOT(upgrade()));
// Package count labels in the statusbar
m_packageCountLabel = new QLabel(this);
m_changedPackagesLabel = new QLabel(this);
statusBar()->addWidget(m_packageCountLabel);
statusBar()->addWidget(m_changedPackagesLabel);
statusBar()->show();
updateLabels();
updateStatusBar();
setCentralWidget(m_stack);
m_debconfGui = new DebconfKde::DebconfGui("/tmp/qapt-sock");
m_debconfGui->connect(m_debconfGui, SIGNAL(activated()), m_debconfGui, SLOT(show()));
m_debconfGui->connect(m_debconfGui, SIGNAL(deactivated()), m_debconfGui, SLOT(hide()));
}
void QAptTest::updateLabels()
{
m_package = m_backend->package(m_lineEdit->text());
// Gotta be careful when getting a package directly from the user's input. We can't currently
// return empty Package containers when the package doesn't exist. And this is why most
// package managers are MVC based. ;-)
if (!m_package == 0) {
m_nameLabel->setText(i18n("<b>Package:</b> %1", m_package->name()));
m_sectionLabel->setText(i18n("<b>Section:</b> %1", m_package->section()));
m_originLabel->setText(i18n("<b>Origin:</b> %1", m_package->origin()));
QString installedSize(KFormat().formatByteSize(m_package->availableInstalledSize()));
m_installedSizeLabel->setText(i18n("<b>Installed Size:</b> %1", installedSize));
m_maintainerLabel->setText(i18n("<b>Maintainer:</b> %1", m_package->maintainer()));
m_sourceLabel->setText(i18n("<b>Source package:</b> %1", m_package->sourcePackage()));
m_versionLabel->setText(i18n("<b>Version:</b> %1", m_package->version()));
QString packageSize(KFormat().formatByteSize(m_package->downloadSize()));
m_packageSizeLabel->setText(i18n("<b>Download size:</b> %1", packageSize));
m_shortDescriptionLabel->setText(i18n("<b>Description:</b> %1", m_package->shortDescription()));
m_longDescriptionLabel->setText(m_package->longDescription());
if (!m_package->isInstalled()) {
m_actionButton->setText("Install Package");
m_actionButton->setIcon(KIcon("list-add"));
} else {
m_actionButton->setText("Remove Package");
m_actionButton->setIcon(KIcon("list-remove"));
}
if (m_package->state() & QApt::Package::Upgradeable) {
m_actionButton->setText("Upgrade Package");
m_actionButton->setIcon(KIcon("system-software-update"));
}
// kDebug() << m_package->changelogUrl();
// kDebug() << m_package->screenshotUrl(QApt::Thumbnail);
kDebug() << m_package->supportedUntil();
QApt::PackageList searchList = m_backend->search("kdelibs5");
foreach (QApt::Package *pkg, searchList) {
kDebug() << pkg->name();
}
}
// Uncomment these to see the results in Konsole; I was too lazy to make a GUI for them
// kDebug() << "============= New package Listing =============";
// QStringList requiredByList(m_package->requiredByList());
// foreach (const QString &name, requiredByList) {
// kDebug() << "reverse dependency: " << name;
// }
// A convenient way to check the install status of a package
// if (m_package->isInstalled()) {
// kDebug() << "Package is installed!!!";
// }
}
void QAptTest::updateCache()
{
if (m_trans) // Transaction running, you could queue these though
return;
m_trans = m_backend->updateCache();
// Provide proxy/locale to the transaction
if (KProtocolManager::proxyType() == KProtocolManager::ManualProxy) {
m_trans->setProxy(KProtocolManager::proxyFor("http"));
}
m_trans->setLocale(QLatin1String(setlocale(LC_MESSAGES, 0)));
// Pass the new current transaction on to our child widgets
m_cacheUpdateWidget->setTransaction(m_trans);
connect(m_trans, SIGNAL(statusChanged(QApt::TransactionStatus)),
this, SLOT(onTransactionStatusChanged(QApt::TransactionStatus)));
m_trans->run();
}
void QAptTest::upgrade()
{
if (m_trans) // Transaction running, you could queue these though
return;
m_debconfGui = new DebconfKde::DebconfGui("/tmp/qapt-sock");
m_debconfGui->connect(m_debconfGui, SIGNAL(activated()), m_debconfGui, SLOT(show()));
m_debconfGui->connect(m_debconfGui, SIGNAL(deactivated()), m_debconfGui, SLOT(hide()));
m_trans = m_backend->upgradeSystem(QApt::FullUpgrade);
// Provide proxy/locale to the transaction
if (KProtocolManager::proxyType() == KProtocolManager::ManualProxy) {
m_trans->setProxy(KProtocolManager::proxyFor("http"));
}
m_trans->setLocale(QLatin1String(setlocale(LC_MESSAGES, 0)));
// Pass the new current transaction on to our child widgets
m_cacheUpdateWidget->setTransaction(m_trans);
m_commitWidget->setTransaction(m_trans);
connect(m_trans, SIGNAL(statusChanged(QApt::TransactionStatus)),
this, SLOT(onTransactionStatusChanged(QApt::TransactionStatus)));
m_trans->run();
}
void QAptTest::commitAction()
{
if (m_trans) // Transaction running, you could queue these though
return;
if (!m_package->isInstalled()) {
m_package->setInstall();
} else {
m_package->setRemove();
}
if (m_package->state() & QApt::Package::Upgradeable) {
m_package->setInstall();
}
m_trans = m_backend->commitChanges();
// Provide proxy/locale to the transaction
if (KProtocolManager::proxyType() == KProtocolManager::ManualProxy) {
m_trans->setProxy(KProtocolManager::proxyFor("http"));
}
m_trans->setLocale(QLatin1String(setlocale(LC_MESSAGES, 0)));
// Pass the new current transaction on to our child widgets
m_cacheUpdateWidget->setTransaction(m_trans);
m_commitWidget->setTransaction(m_trans);
connect(m_trans, SIGNAL(statusChanged(QApt::TransactionStatus)),
this, SLOT(onTransactionStatusChanged(QApt::TransactionStatus)));
m_trans->run();
}
void QAptTest::onTransactionStatusChanged(QApt::TransactionStatus status)
{
QString headerText;
switch (status) {
case QApt::RunningStatus:
// For roles that start by downloading something, switch to download view
if (m_trans->role() == (QApt::UpdateCacheRole || QApt::UpgradeSystemRole ||
QApt::CommitChangesRole || QApt::DownloadArchivesRole ||
QApt::InstallFileRole)) {
m_stack->setCurrentWidget(m_cacheUpdateWidget);
}
break;
case QApt::DownloadingStatus:
m_stack->setCurrentWidget(m_cacheUpdateWidget);
break;
case QApt::CommittingStatus:
m_stack->setCurrentWidget(m_commitWidget);
break;
case QApt::FinishedStatus:
// FIXME: Determine which transactions need to reload cache on completion
m_backend->reloadCache();
m_stack->setCurrentWidget(m_mainWidget);
updateStatusBar();
// Clean up transaction object
m_trans->deleteLater();
m_trans = 0;
delete m_debconfGui;
m_debconfGui = 0;
break;
default:
break;
}
}
void QAptTest::updateStatusBar()
{
m_packageCountLabel->setText(i18n("%1 Installed, %2 upgradeable, %3 available",
m_backend->packageCount(QApt::Package::Installed),
m_backend->packageCount(QApt::Package::Upgradeable),
m_backend->packageCount()));
m_changedPackagesLabel->setText(i18n("%1 To install, %2 to upgrade, %3 to remove",
m_backend->packageCount(QApt::Package::ToInstall),
m_backend->packageCount(QApt::Package::ToUpgrade),
m_backend->packageCount(QApt::Package::ToRemove)));
}
|