diff --git a/Apper/BrowseView.cpp b/Apper/BrowseView.cpp index 6609b8a..8bff591 100644 --- a/Apper/BrowseView.cpp +++ b/Apper/BrowseView.cpp @@ -1,336 +1,336 @@ /*************************************************************************** * Copyright (C) 2009-2010 by Daniel Nicoletti * * dantti12@gmail.com * * * * 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., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "BrowseView.h" #include "PackageDetails.h" #include "CategoryModel.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace PackageKit; BrowseView::BrowseView(QWidget *parent) : QWidget(parent) { setupUi(this); connect(categoryView, &QListView::clicked, this, &BrowseView::categoryActivated); m_busySeq = new KPixmapSequenceOverlayPainter(this); - m_busySeq->setSequence(KPixmapSequence(QLatin1String("process-working"), KIconLoader::SizeSmallMedium)); + m_busySeq->setSequence(KIconLoader::global()->loadPixmapSequence(QLatin1String("process-working"), KIconLoader::SizeSmallMedium)); m_busySeq->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); m_busySeq->setWidget(packageView->viewport()); m_model = new PackageModel(this); m_proxy = new ApplicationSortFilterModel(this); m_proxy->setSourceModel(m_model); packageView->setModel(m_proxy); packageView->sortByColumn(PackageModel::NameCol, Qt::AscendingOrder); packageView->header()->setDefaultAlignment(Qt::AlignCenter); packageView->header()->setStretchLastSection(false); packageView->header()->setSectionResizeMode(PackageModel::NameCol, QHeaderView::Stretch); packageView->header()->setSectionResizeMode(PackageModel::VersionCol, QHeaderView::ResizeToContents); packageView->header()->setSectionResizeMode(PackageModel::ArchCol, QHeaderView::ResizeToContents); packageView->header()->setSectionResizeMode(PackageModel::OriginCol, QHeaderView::ResizeToContents); packageView->header()->setSectionResizeMode(PackageModel::SizeCol, QHeaderView::ResizeToContents); packageView->header()->setSectionResizeMode(PackageModel::ActionCol, QHeaderView::ResizeToContents); // Hide current Version since it's useless for us packageView->header()->setSectionHidden(PackageModel::CurrentVersionCol, true); ApplicationsDelegate *delegate = new ApplicationsDelegate(packageView); packageView->setItemDelegate(delegate); exportInstalledPB->setIcon(QIcon::fromTheme(QLatin1String("document-export"))); importInstalledPB->setIcon(QIcon::fromTheme(QLatin1String("document-import"))); KConfig config(QLatin1String("apper")); KConfigGroup viewGroup(&config, "BrowseView"); // Version packageView->header()->setSectionHidden(PackageModel::VersionCol, true); m_showPackageVersion = new QAction(i18n("Show Versions"), this); m_showPackageVersion->setCheckable(true); connect(m_showPackageVersion, &QAction::toggled, this, &BrowseView::showVersions); m_showPackageVersion->setChecked(viewGroup.readEntry("ShowApplicationVersions", true)); // Arch packageView->header()->setSectionHidden(PackageModel::ArchCol, true); m_showPackageArch = new QAction(i18n("Show Architectures"), this); m_showPackageArch->setCheckable(true); connect(m_showPackageArch, &QAction::toggled, this, &BrowseView::showArchs); m_showPackageArch->setChecked(viewGroup.readEntry("ShowApplicationArchitectures", false)); // Origin packageView->header()->setSectionHidden(PackageModel::OriginCol, true); m_showPackageOrigin = new QAction(i18n("Show Origins"), this); m_showPackageOrigin->setCheckable(true); connect(m_showPackageOrigin, &QAction::toggled, this, &BrowseView::showOrigins); m_showPackageOrigin->setChecked(viewGroup.readEntry("ShowApplicationOrigins", false)); // Sizes packageView->header()->setSectionHidden(PackageModel::SizeCol, true); m_showPackageSizes = new QAction(i18n("Show Sizes"), this); m_showPackageSizes->setCheckable(true); connect(m_showPackageSizes, &QAction::toggled, this, &BrowseView::showSizes); m_showPackageSizes->setChecked(viewGroup.readEntry("ShowPackageSizes", false)); // Ensure the index is visible when the packageDetails appears connect(packageDetails, &PackageDetails::ensureVisible, this, &BrowseView::ensureVisible); } void BrowseView::init(Transaction::Roles roles) { packageDetails->init(roles); } BrowseView::~BrowseView() { } bool BrowseView::showPageHeader() const { return false; } PackageModel* BrowseView::model() const { return m_model; } void BrowseView::showVersions(bool enabled) { KConfig config(QLatin1String("apper")); KConfigGroup viewGroup(&config, "BrowseView"); viewGroup.writeEntry("ShowApplicationVersions", enabled); packageView->header()->setSectionHidden(PackageModel::VersionCol, !enabled); packageDetails->hidePackageVersion(enabled); } void BrowseView::showArchs(bool enabled) { KConfig config(QLatin1String("apper")); KConfigGroup viewGroup(&config, "BrowseView"); viewGroup.writeEntry("ShowApplicationArchitectures", enabled); packageView->header()->setSectionHidden(PackageModel::ArchCol, !enabled); packageDetails->hidePackageArch(enabled); } void BrowseView::showOrigins(bool enabled) { KConfig config(QLatin1String("apper")); KConfigGroup viewGroup(&config, "BrowseView"); viewGroup.writeEntry("ShowApplicationOrigins", enabled); packageView->header()->setSectionHidden(PackageModel::OriginCol, !enabled); } void BrowseView::showSizes(bool enabled) { KConfig config(QLatin1String("apper")); KConfigGroup viewGroup(&config, "BrowseView"); viewGroup.writeEntry("ShowPackageSizes", enabled); packageView->header()->setSectionHidden(PackageModel::SizeCol, !enabled); packageDetails->hidePackageArch(enabled); if (enabled) { m_model->fetchSizes(); } } void BrowseView::on_packageView_customContextMenuRequested(const QPoint &pos) { auto menu = new QMenu(this); menu->addAction(m_showPackageVersion); menu->addAction(m_showPackageArch); menu->addAction(m_showPackageOrigin); menu->addAction(m_showPackageSizes); menu->exec(packageView->viewport()->mapToGlobal(pos)); menu->deleteLater(); } void BrowseView::on_packageView_clicked(const QModelIndex &index) { if (index.column() == PackageModel::ActionCol) { return; } QModelIndex origIndex = m_proxy->mapToSource(index); packageDetails->setPackage(origIndex); } void BrowseView::ensureVisible(const QModelIndex &index) { QModelIndex proxIndex = m_proxy->mapFromSource(index); packageView->scrollTo(proxIndex); } void BrowseView::showInstalledPanel(bool visible) { installedF->setVisible(visible); } ApplicationSortFilterModel* BrowseView::proxy() const { return m_proxy; } KPixmapSequenceOverlayPainter* BrowseView::busyCursor() const { return m_busySeq; } void BrowseView::setCategoryModel(QAbstractItemModel *model) { categoryView->setModel(model); } void BrowseView::setParentCategory(const QModelIndex &index) { categoryView->setRootIndex(index); // Make sure the last item is not selected categoryView->selectionModel()->clearSelection(); categoryView->horizontalScrollBar()->setValue(0); // Display the category view if the index has child items categoryF->setVisible(categoryView->model()->rowCount(index)); } bool BrowseView::goBack() { packageDetails->hide(); QModelIndex index = categoryView->rootIndex(); if (index.parent().isValid()) { index = index.parent(); // if it's valid we need to know if it wasn't a PK root category if (index.data(CategoryModel::GroupRole).type() == QVariant::String) { QString category = index.data(CategoryModel::GroupRole).toString(); if (!category.startsWith(QLatin1Char('@'))) { return true; } } setParentCategory(index); emit categoryActivated(index); return false; } return true; } void BrowseView::on_categoryMvLeft_clicked() { categoryView->horizontalScrollBar()->setValue(categoryView->horizontalScrollBar()->value() - 1); } void BrowseView::on_categoryMvRight_clicked() { categoryView->horizontalScrollBar()->setValue(categoryView->horizontalScrollBar()->value() + 1); } void BrowseView::cleanUi() { packageDetails->hide(); categoryF->setVisible(false); } bool BrowseView::isShowingSizes() const { return m_showPackageSizes->isChecked(); } void BrowseView::on_exportInstalledPB_clicked() { // We will assume the installed model // is populated since the user is seeing it. QString fileName; fileName = QFileDialog::getSaveFileName(this, i18n("Export installed packages"), QString(), QStringLiteral("*.catalog")); if (fileName.isEmpty()) { return; } QFile file(fileName); file.open(QIODevice::WriteOnly); QTextStream out(&file); out << "[PackageKit Catalog]\n\n"; out << "InstallPackages(" << Daemon::global()->distroID() << ")="; QStringList packages; for (int i = 0; i < m_model->rowCount(); i++) { packages << m_model->data(m_model->index(i, 0), PackageModel::PackageName).toString(); } out << packages.join(QLatin1Char(';')); } void BrowseView::on_importInstalledPB_clicked() { QString fileName; fileName = QFileDialog::getOpenFileName(this, i18n("Install packages from catalog"), QString(), QStringLiteral("*.catalog")); if (fileName.isEmpty()) { return; } // send a DBus message to install this catalog QDBusMessage message; message = QDBusMessage::createMethodCall(QLatin1String("org.freedesktop.PackageKit"), QLatin1String("/org/freedesktop/PackageKit"), QLatin1String("org.freedesktop.PackageKit.Modify"), QLatin1String("InstallCatalogs")); message << static_cast(effectiveWinId()); message << (QStringList() << fileName); message << QString(); // This call must block otherwise this application closes before // smarticon is activated QDBusMessage reply = QDBusConnection::sessionBus().call(message, QDBus::Block); } void BrowseView::disableExportInstalledPB() { exportInstalledPB->setEnabled(false); } void BrowseView::enableExportInstalledPB() { exportInstalledPB->setEnabled(true); } diff --git a/Apper/PackageDetails.cpp b/Apper/PackageDetails.cpp index 28de201..75a3919 100644 --- a/Apper/PackageDetails.cpp +++ b/Apper/PackageDetails.cpp @@ -1,800 +1,800 @@ /*************************************************************************** * Copyright (C) 2009-2018 by Daniel Nicoletti * * dantti12@gmail.com * * * * 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., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "PackageDetails.h" #include "ui_PackageDetails.h" #include "ScreenShotViewer.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef HAVE_APPSTREAM #include #endif #include "GraphicsOpacityDropShadowEffect.h" #define BLUR_RADIUS 15 #define FINAL_HEIGHT 210 using namespace PackageKit; Q_DECLARE_LOGGING_CATEGORY(APPER) Q_DECLARE_METATYPE(KPixmapSequenceOverlayPainter**) PackageDetails::PackageDetails(QWidget *parent) : QWidget(parent), ui(new Ui::PackageDetails), m_busySeq(0), m_display(false), m_hideVersion(false), m_hideArch(false), m_transaction(0), m_hasDetails(false), m_hasFileList(false) { ui->setupUi(this); ui->hideTB->setIcon(QIcon::fromTheme(QLatin1String("window-close"))); connect(ui->hideTB, SIGNAL(clicked()), this, SLOT(hide())); auto menu = new QMenu(i18n("Display"), this); m_actionGroup = new QActionGroup(this); // we check to see which roles are supported by the backend // if so we ask for information and create the containers descriptionAction = menu->addAction(i18n("Description")); descriptionAction->setCheckable(true); descriptionAction->setData(PackageKit::Transaction::RoleGetDetails); m_actionGroup->addAction(descriptionAction); ui->descriptionW->setWidgetResizable(true); dependsOnAction = menu->addAction(i18n("Depends On")); dependsOnAction->setCheckable(true); dependsOnAction->setData(PackageKit::Transaction::RoleDependsOn); m_actionGroup->addAction(dependsOnAction); // Sets a transparent background QWidget *dependsViewport = ui->dependsOnLV->viewport(); QPalette dependsPalette = dependsViewport->palette(); dependsPalette.setColor(dependsViewport->backgroundRole(), Qt::transparent); dependsPalette.setColor(dependsViewport->foregroundRole(), dependsPalette.color(QPalette::WindowText)); dependsViewport->setPalette(dependsPalette); m_dependsModel = new PackageModel(this); m_dependsProxy = new QSortFilterProxyModel(this); m_dependsProxy->setDynamicSortFilter(true); m_dependsProxy->setSortRole(PackageModel::SortRole); m_dependsProxy->setSourceModel(m_dependsModel); ui->dependsOnLV->setModel(m_dependsProxy); ui->dependsOnLV->sortByColumn(0, Qt::AscendingOrder); ui->dependsOnLV->header()->setDefaultAlignment(Qt::AlignCenter); ui->dependsOnLV->header()->setSectionResizeMode(PackageModel::NameCol, QHeaderView::ResizeToContents); ui->dependsOnLV->header()->setSectionResizeMode(PackageModel::VersionCol, QHeaderView::ResizeToContents); ui->dependsOnLV->header()->setSectionResizeMode(PackageModel::ArchCol, QHeaderView::Stretch); ui->dependsOnLV->header()->hideSection(PackageModel::ActionCol); ui->dependsOnLV->header()->hideSection(PackageModel::CurrentVersionCol); ui->dependsOnLV->header()->hideSection(PackageModel::OriginCol); ui->dependsOnLV->header()->hideSection(PackageModel::SizeCol); requiredByAction = menu->addAction(i18n("Required By")); requiredByAction->setCheckable(true); requiredByAction->setData(PackageKit::Transaction::RoleRequiredBy); m_actionGroup->addAction(requiredByAction); // Sets a transparent background QWidget *requiredViewport = ui->requiredByLV->viewport(); QPalette requiredPalette = requiredViewport->palette(); requiredPalette.setColor(requiredViewport->backgroundRole(), Qt::transparent); requiredPalette.setColor(requiredViewport->foregroundRole(), requiredPalette.color(QPalette::WindowText)); requiredViewport->setPalette(requiredPalette); m_requiresModel = new PackageModel(this); m_requiresProxy = new QSortFilterProxyModel(this); m_requiresProxy->setDynamicSortFilter(true); m_requiresProxy->setSortRole(PackageModel::SortRole); m_requiresProxy->setSourceModel(m_requiresModel); ui->requiredByLV->setModel(m_requiresProxy); ui->requiredByLV->sortByColumn(0, Qt::AscendingOrder); ui->requiredByLV->header()->setDefaultAlignment(Qt::AlignCenter); ui->requiredByLV->header()->setSectionResizeMode(PackageModel::NameCol, QHeaderView::ResizeToContents); ui->requiredByLV->header()->setSectionResizeMode(PackageModel::VersionCol, QHeaderView::ResizeToContents); ui->requiredByLV->header()->setSectionResizeMode(PackageModel::ArchCol, QHeaderView::Stretch); ui->requiredByLV->header()->hideSection(PackageModel::ActionCol); ui->requiredByLV->header()->hideSection(PackageModel::CurrentVersionCol); ui->requiredByLV->header()->hideSection(PackageModel::OriginCol); ui->requiredByLV->header()->hideSection(PackageModel::SizeCol); fileListAction = menu->addAction(i18n("File List")); fileListAction->setCheckable(true); fileListAction->setData(PackageKit::Transaction::RoleGetFiles); m_actionGroup->addAction(fileListAction); // Sets a transparent background QWidget *actionsViewport = ui->filesPTE->viewport(); QPalette palette = actionsViewport->palette(); palette.setColor(actionsViewport->backgroundRole(), Qt::transparent); palette.setColor(actionsViewport->foregroundRole(), palette.color(QPalette::WindowText)); actionsViewport->setPalette(palette); // Set the menu ui->menuTB->setMenu(menu); ui->menuTB->setIcon(QIcon::fromTheme(QLatin1String("help-about"))); connect(m_actionGroup, SIGNAL(triggered(QAction*)), this, SLOT(actionActivated(QAction*))); m_busySeq = new KPixmapSequenceOverlayPainter(this); - m_busySeq->setSequence(KPixmapSequence(QLatin1String("process-working"), KIconLoader::SizeSmallMedium)); + m_busySeq->setSequence(KIconLoader::global()->loadPixmapSequence(QLatin1String("process-working"), KIconLoader::SizeSmallMedium)); m_busySeq->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); m_busySeq->setWidget(ui->stackedWidget); // Setup the opacit effect that makes the descriptio transparent // after finished it checks in display() to see if it shouldn't show // up again. The property animation is always the same, the only different thing // is the Forward or Backward property QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(ui->stackedWidget); effect->setOpacity(0); ui->stackedWidget->setGraphicsEffect(effect); m_fadeStacked = new QPropertyAnimation(effect, "opacity", this); m_fadeStacked->setDuration(500); m_fadeStacked->setStartValue(qreal(0)); m_fadeStacked->setEndValue(qreal(1)); connect(m_fadeStacked, SIGNAL(finished()), this, SLOT(display())); // It's is impossible due to some limitation in Qt to set two effects on the same // Widget m_fadeScreenshot = new QPropertyAnimation(effect, "opacity", this); GraphicsOpacityDropShadowEffect *shadow = new GraphicsOpacityDropShadowEffect(ui->screenshotL); shadow->setOpacity(0); shadow->setBlurRadius(BLUR_RADIUS); shadow->setOffset(2); shadow->setColor(QApplication::palette().dark().color()); ui->screenshotL->setGraphicsEffect(shadow); m_fadeScreenshot = new QPropertyAnimation(shadow, "opacity", this); m_fadeScreenshot->setDuration(500); m_fadeScreenshot->setStartValue(qreal(0)); m_fadeScreenshot->setEndValue(qreal(1)); connect(m_fadeScreenshot, SIGNAL(finished()), this, SLOT(display())); // This pannel expanding QPropertyAnimation *anim1 = new QPropertyAnimation(this, "maximumSize", this); anim1->setDuration(500); anim1->setEasingCurve(QEasingCurve::OutQuart); anim1->setStartValue(QSize(QWIDGETSIZE_MAX, 0)); anim1->setEndValue(QSize(QWIDGETSIZE_MAX, FINAL_HEIGHT)); QPropertyAnimation *anim2 = new QPropertyAnimation(this, "minimumSize", this); anim2->setDuration(500); anim2->setEasingCurve(QEasingCurve::OutQuart); anim2->setStartValue(QSize(QWIDGETSIZE_MAX, 0)); anim2->setEndValue(QSize(QWIDGETSIZE_MAX, FINAL_HEIGHT)); m_expandPanel = new QParallelAnimationGroup(this); m_expandPanel->addAnimation(anim1); m_expandPanel->addAnimation(anim2); connect(m_expandPanel, SIGNAL(finished()), this, SLOT(display())); } void PackageDetails::init(PackageKit::Transaction::Roles roles) { // qCDebug(); bool setChecked = true; if (roles & PackageKit::Transaction::RoleGetDetails) { descriptionAction->setEnabled(true); descriptionAction->setChecked(setChecked); setChecked = false; } else { descriptionAction->setEnabled(false); descriptionAction->setChecked(false); } if (roles & PackageKit::Transaction::RoleDependsOn) { dependsOnAction->setEnabled(true); dependsOnAction->setChecked(setChecked); setChecked = false; } else { dependsOnAction->setEnabled(false); dependsOnAction->setChecked(false); } if (roles & PackageKit::Transaction::RoleRequiredBy) { requiredByAction->setEnabled(true); requiredByAction->setChecked(setChecked); setChecked = false; } else { requiredByAction->setEnabled(false); requiredByAction->setChecked(false); } if (roles & PackageKit::Transaction::RoleGetFiles) { fileListAction->setEnabled(true); fileListAction->setChecked(setChecked); setChecked = false; } else { fileListAction->setEnabled(false); fileListAction->setChecked(false); } } PackageDetails::~PackageDetails() { delete ui; } void PackageDetails::setPackage(const QModelIndex &index) { qCDebug(APPER) << index; QString appId = index.data(PackageModel::ApplicationId).toString(); QString packageID = index.data(PackageModel::IdRole).toString(); // if it's the same package and the same application, return if (packageID == m_packageID && appId == m_appId) { return; } else if (maximumSize().height() == 0) { // Expand the panel m_display = true; m_expandPanel->setDirection(QAbstractAnimation::Forward); m_expandPanel->start(); } else { // Hide the old description fadeOut(PackageDetails::FadeScreenshot | PackageDetails::FadeStacked); } m_index = index; m_appId = appId; m_packageID = packageID; m_hasDetails = false; m_hasFileList = false; m_hasRequires = false; m_hasDepends = false; qCDebug(APPER) << "appId" << appId << "m_package" << m_packageID; QString pkgIconPath = index.data(PackageModel::IconRole).toString(); m_currentIcon = PkIcons::getIcon(pkgIconPath, QString()).pixmap(64, 64); m_appName = index.data(PackageModel::NameRole).toString(); m_currentScreenshot = thumbnail(Transaction::packageName(m_packageID)); qCDebug(APPER) << "current screenshot" << m_currentScreenshot; if (!m_currentScreenshot.isNull()) { if (m_screenshotPath.contains(m_currentScreenshot)) { display(); } else { auto tempFile = new QTemporaryFile; tempFile->open(); KIO::FileCopyJob *job = KIO::file_copy(QUrl(m_currentScreenshot), QUrl(tempFile->fileName()), -1, KIO::Overwrite | KIO::HideProgressInfo); connect(job, &KIO::FileCopyJob::result, this, &PackageDetails::resultJob); } } if (m_actionGroup->checkedAction()) { actionActivated(m_actionGroup->checkedAction()); } } void PackageDetails::on_screenshotL_clicked() { const QUrl url = screenshot(Transaction::packageName(m_packageID)); if (!url.isEmpty()) { auto view = new ScreenShotViewer(url); view->setWindowTitle(m_appName); view->show(); } } void PackageDetails::hidePackageVersion(bool hide) { m_hideVersion = hide; } void PackageDetails::hidePackageArch(bool hide) { m_hideArch = hide; } void PackageDetails::actionActivated(QAction *action) { // don't fade the screenshot // if the package changed setPackage() fades both fadeOut(FadeStacked); qCDebug(APPER); // disconnect the transaction // so that we don't get old data if (m_transaction) { disconnect(m_transaction, SIGNAL(details(PackageKit::Details)), this, SLOT(description(PackageKit::Details))); disconnect(m_transaction, SIGNAL(package(PackageKit::Transaction::Info,QString,QString)), m_dependsModel, SLOT(addPackage(PackageKit::Transaction::Info,QString,QString))); disconnect(m_transaction, SIGNAL(package(PackageKit::Transaction::Info,QString,QString)), m_requiresModel, SLOT(addPackage(PackageKit::Transaction::Info,QString,QString))); disconnect(m_transaction, SIGNAL(files(QString,QStringList)), this, SLOT(files(QString,QStringList))); disconnect(m_transaction, SIGNAL(finished(PackageKit::Transaction::Exit,uint)), this, SLOT(finished())); m_transaction = 0; } // Check to see if we don't already have the required data uint role = action->data().toUInt(); switch (role) { case PackageKit::Transaction::RoleGetDetails: if (m_hasDetails) { description(m_details); display(); return; } break; case PackageKit::Transaction::RoleDependsOn: if (m_hasDepends) { display(); return; } break; case PackageKit::Transaction::RoleRequiredBy: if (m_hasRequires) { display(); return; } break; case PackageKit::Transaction::RoleGetFiles: if (m_hasFileList) { display(); return; } break; } // we don't have the data qCDebug(APPER) << "New transaction"; switch (role) { case PackageKit::Transaction::RoleGetDetails: m_transaction = Daemon::getDetails(m_packageID); connect(m_transaction, SIGNAL(details(PackageKit::Details)), SLOT(description(PackageKit::Details))); break; case PackageKit::Transaction::RoleDependsOn: m_dependsModel->clear(); m_transaction = Daemon::dependsOn(m_packageID, PackageKit::Transaction::FilterNone, false); connect(m_transaction, SIGNAL(package(PackageKit::Transaction::Info,QString,QString)), m_dependsModel, SLOT(addPackage(PackageKit::Transaction::Info,QString,QString))); connect(m_transaction, SIGNAL(finished(PackageKit::Transaction::Exit,uint)), m_dependsModel, SLOT(finished())); break; case PackageKit::Transaction::RoleRequiredBy: m_requiresModel->clear(); m_transaction = Daemon::requiredBy(m_packageID, PackageKit::Transaction::FilterNone, false); connect(m_transaction, SIGNAL(package(PackageKit::Transaction::Info,QString,QString)), m_requiresModel, SLOT(addPackage(PackageKit::Transaction::Info,QString,QString))); connect(m_transaction, SIGNAL(finished(PackageKit::Transaction::Exit,uint)), m_requiresModel, SLOT(finished())); break; case PackageKit::Transaction::RoleGetFiles: m_currentFileList.clear(); m_transaction = Daemon::getFiles(m_packageID); connect(m_transaction, SIGNAL(files(QString,QStringList)), this, SLOT(files(QString,QStringList))); break; default: qWarning() << Q_FUNC_INFO << "Oops, unhandled role, please report" << role; return; } connect(m_transaction, SIGNAL(finished(PackageKit::Transaction::Exit,uint)), this, SLOT(finished())); qCDebug(APPER) <<"transaction running"; m_busySeq->start(); } void PackageDetails::resultJob(KJob *job) { KIO::FileCopyJob *fJob = qobject_cast(job); if (!fJob->error()) { m_screenshotPath[fJob->srcUrl().url()] = fJob->destUrl().toLocalFile(); display(); } } void PackageDetails::hide() { m_display = false; // Clean the old description otherwise if the user selects the same // package the pannel won't expand m_packageID.clear(); m_appId.clear(); if (maximumSize().height() == FINAL_HEIGHT) { if (m_fadeStacked->currentValue().toReal() == 0 && m_fadeScreenshot->currentValue().toReal() == 0) { // Screen shot and description faded let's shrink the pannel m_expandPanel->setDirection(QAbstractAnimation::Backward); m_expandPanel->start(); } else { // Hide current description fadeOut(PackageDetails::FadeScreenshot | PackageDetails::FadeStacked); } } } void PackageDetails::fadeOut(FadeWidgets widgets) { // Fade out only if needed if ((widgets & FadeStacked) && m_fadeStacked->currentValue().toReal() != 0) { m_fadeStacked->setDirection(QAbstractAnimation::Backward); m_fadeStacked->start(); } // Fade out the screenshot only if needed if ((widgets & FadeScreenshot) && m_fadeScreenshot->currentValue().toReal() != 0) { ui->screenshotL->unsetCursor(); m_fadeScreenshot->setDirection(QAbstractAnimation::Backward); m_fadeScreenshot->start(); } } void PackageDetails::display() { // If we shouldn't be showing hide the pannel if (!m_display) { hide(); } else if (maximumSize().height() == FINAL_HEIGHT) { emit ensureVisible(m_index); // Check to see if the stacked widget is transparent if (m_fadeStacked->currentValue().toReal() == 0 && m_actionGroup->checkedAction()) { bool fadeIn = false; switch (m_actionGroup->checkedAction()->data().toUInt()) { case PackageKit::Transaction::RoleGetDetails: if (m_hasDetails) { setupDescription(); fadeIn = true; } break; case PackageKit::Transaction::RoleDependsOn: if (m_hasDepends) { if (ui->stackedWidget->currentWidget() != ui->pageDepends) { ui->stackedWidget->setCurrentWidget(ui->pageDepends); } fadeIn = true; } break; case PackageKit::Transaction::RoleRequiredBy: if (m_hasRequires) { if (ui->stackedWidget->currentWidget() != ui->pageRequired) { ui->stackedWidget->setCurrentWidget(ui->pageRequired); } fadeIn = true; } break; case PackageKit::Transaction::RoleGetFiles: if (m_hasFileList) { ui->filesPTE->clear(); if (m_currentFileList.isEmpty()) { ui->filesPTE->insertPlainText(i18n("No files were found.")); } else { m_currentFileList.sort(); ui->filesPTE->insertPlainText(m_currentFileList.join(QLatin1Char('\n'))); } if (ui->stackedWidget->currentWidget() != ui->pageFiles) { ui->stackedWidget->setCurrentWidget(ui->pageFiles); } ui->filesPTE->verticalScrollBar()->setValue(0); fadeIn = true; } break; } if (fadeIn) { // Fade In m_fadeStacked->setDirection(QAbstractAnimation::Forward); m_fadeStacked->start(); } } // Check to see if we have a screen shot and if we are // transparent, and make sure the details are going // to be shown if (m_fadeScreenshot->currentValue().toReal() == 0 && m_screenshotPath.contains(m_currentScreenshot) && m_fadeStacked->direction() == QAbstractAnimation::Forward) { QPixmap pixmap; pixmap = QPixmap(m_screenshotPath[m_currentScreenshot]) .scaled(160,120, Qt::KeepAspectRatio, Qt::SmoothTransformation); ui->screenshotL->setPixmap(pixmap); ui->screenshotL->setCursor(Qt::PointingHandCursor); // Fade In m_fadeScreenshot->setDirection(QAbstractAnimation::Forward); m_fadeScreenshot->start(); } } } void PackageDetails::setupDescription() { if (ui->stackedWidget->currentWidget() != ui->pageDescription) { ui->stackedWidget->setCurrentWidget(ui->pageDescription); } if (!m_hasDetails) { // Oops we don't have any details ui->descriptionL->setText(i18n("Could not fetch software details")); ui->descriptionL->show(); // Hide stuff so we don't display outdated data ui->homepageL->hide(); ui->pathL->hide(); ui->licenseL->hide(); ui->sizeL->hide(); ui->iconL->clear(); } if (!m_detailsDescription.isEmpty()) { ui->descriptionL->setText(m_detailsDescription.replace(QLatin1Char('\n'), QLatin1String("
"))); ui->descriptionL->show(); } else { ui->descriptionL->clear(); } if (!m_details.url().isEmpty()) { ui->homepageL->setText(QLatin1String("") + m_details.url() + QLatin1String("")); ui->homepageL->show(); } else { ui->homepageL->hide(); } // Let's try to find the application's path in human user // readable easiest form :D KService::Ptr service = KService::serviceByDesktopName(m_appId); QVector > ret; if (service) { ret = locateApplication(QString(), service->menuId()); } if (ret.isEmpty()) { ui->pathL->hide(); } else { QString path; path.append(QString(QLatin1String("")) .arg(KIconLoader::global()->iconPath(QLatin1String("kde"), KIconLoader::Small))); path.append(QString(QLatin1String(" %1  %3")) .arg(QString::fromUtf8("➜")) .arg(KIconLoader::global()->iconPath(QLatin1String("applications-other"), KIconLoader::Small)) .arg(i18n("Applications"))); for (int i = 0; i < ret.size(); i++) { path.append(QString(QLatin1String(" %1  %3")) .arg(QString::fromUtf8("➜")) .arg(KIconLoader::global()->iconPath(ret.at(i).second, KIconLoader::Small)) .arg(ret.at(i).first)); } ui->pathL->setText(path); ui->pathL->show(); } // if (details->group() != Package::UnknownGroup) { // // description += "" + i18nc("Group of the package", "Group") + ":" // // + PkStrings::groups(details->group()) // // + ""; // } if (!m_details.license().isEmpty() && m_details.license() != QLatin1String("unknown")) { // We have a license, check if we have and should show show package version if (!m_hideVersion && !Transaction::packageVersion(m_details.packageId()).isEmpty()) { ui->licenseL->setText(Transaction::packageVersion(m_details.packageId()) + QLatin1String(" - ") + m_details.license()); } else { ui->licenseL->setText(m_details.license()); } ui->licenseL->show(); } else if (!m_hideVersion) { ui->licenseL->setText(Transaction::packageVersion(m_details.packageId())); ui->licenseL->show(); } else { ui->licenseL->hide(); } if (m_details.size() > 0) { QString size = KFormat().formatByteSize(m_details.size()); if (!m_hideArch && !Transaction::packageArch(m_details.packageId()).isEmpty()) { ui->sizeL->setText(size % QLatin1String(" (") % Transaction::packageArch(m_details.packageId()) % QLatin1Char(')')); } else { ui->sizeL->setText(size); } ui->sizeL->show(); } else if (!m_hideArch && !Transaction::packageArch(m_details.packageId()).isEmpty()) { ui->sizeL->setText(Transaction::packageArch(m_details.packageId())); } else { ui->sizeL->hide(); } if (m_currentIcon.isNull()) { ui->iconL->clear(); } else { ui->iconL->setPixmap(m_currentIcon); } } QVector > PackageDetails::locateApplication(const QString &_relPath, const QString &menuId) const { QVector > ret; KServiceGroup::Ptr root = KServiceGroup::group(_relPath); if (!root || !root->isValid()) { return ret; } KServiceGroup::List list = root->entries(false /* sorted */, true /* exclude no display entries */, false /* allow separators */); //! TODO: Port to KF5 properly Q_UNUSED(menuId) #if 0 for (KServiceGroup::List::ConstIterator it = list.begin(); it != list.end(); it++) { KSycocaEntry::Ptr = (*it); if (p->isType(KST_KService)) { KService *service = static_cast(p.get()); if (service->noDisplay()) { continue; } // qCDebug(APPER) << menuId << service->menuId(); if (service->menuId() == menuId) { QPair pair; pair.first = service->name(); pair.second = service->icon(); ret << pair; // qCDebug(APPER) << "FOUND!"; return ret; } } else if (p->isType(KST_KServiceGroup)) { KServiceGroup *serviceGroup = static_cast(p.get()); if (serviceGroup->noDisplay() || serviceGroup->childCount() == 0) { continue; } QVector > found; found = locateApplication(serviceGroup->relPath(), menuId); if (!found.isEmpty()) { QPair pair; pair.first = serviceGroup->caption(); pair.second = serviceGroup->icon(); ret << pair; ret << found; return ret; } } else { kWarning(250) << "KServiceGroup: Unexpected object in list!"; continue; } } #endif return ret; } QString PackageDetails::thumbnail(const QString &pkgName) const { #ifndef HAVE_APPSTREAM Q_UNUSED(pkgName) return QString(); #else return QString();//AppStream::instance()->thumbnail(pkgName); #endif } QUrl PackageDetails::screenshot(const QString &pkgName) const { #ifndef HAVE_APPSTREAM Q_UNUSED(pkgName) return QUrl(); #else return AppStreamHelper::instance()->screenshot(pkgName); #endif } void PackageDetails::description(const PackageKit::Details &details) { qCDebug(APPER) << details; m_details = details; m_detailsDescription = details.description(); m_hasDetails = true; #ifdef HAVE_APPSTREAM // check if we have application details from Appstream data // FIXME: The whole AppStream handling sucks badly, since it was added later // and on to of the package-based model. So we can't respect the "multiple apps // in one package" case here. const QList apps = AppStreamHelper::instance()->applications(Transaction::packageName(m_packageID)); for (const AppStream::Component &app : apps) { if (!app.description().isEmpty()) { m_detailsDescription = app.description(); break; } } #endif } void PackageDetails::finished() { if (m_busySeq) { m_busySeq->stop(); } m_transaction = 0; auto transaction = qobject_cast(sender()); qCDebug(APPER); if (transaction) { qCDebug(APPER) << transaction->role() << PackageKit::Transaction::RoleGetDetails; if (transaction->role() == PackageKit::Transaction::RoleGetDetails) { m_hasDetails = true; } else if (transaction->role() == PackageKit::Transaction::RoleGetFiles) { m_hasFileList = true; } else if (transaction->role() == PackageKit::Transaction::RoleRequiredBy) { m_hasRequires = true; } else if (transaction->role() == PackageKit::Transaction::RoleDependsOn) { m_hasDepends = true; } else { return; } display(); } } void PackageDetails::files(const QString &packageID, const QStringList &files) { Q_UNUSED(packageID) m_currentFileList = files; } diff --git a/Apper/ScreenShotViewer.cpp b/Apper/ScreenShotViewer.cpp index ef2206b..8d7a32f 100644 --- a/Apper/ScreenShotViewer.cpp +++ b/Apper/ScreenShotViewer.cpp @@ -1,107 +1,107 @@ /*************************************************************************** * Copyright (C) 2009-2018 by Daniel Nicoletti * * dantti12@gmail.com * * * * 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., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "ScreenShotViewer.h" #include #include #include #include #include #include #include #include #include #include "ClickableLabel.h" ScreenShotViewer::ScreenShotViewer(const QUrl &url, QWidget *parent) : QScrollArea(parent) { m_screenshotL = new ClickableLabel(this); m_screenshotL->setCursor(Qt::PointingHandCursor); m_screenshotL->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); m_screenshotL->resize(250, 200); resize(250, 200); setFrameShape(NoFrame); setFrameShadow(Plain); setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); setWidget(m_screenshotL); setWindowIcon(QIcon::fromTheme(QLatin1String("layer-visible-on"))); auto tempFile = new QTemporaryFile; // tempFile->setPrefix("appgetfull"); // tempFile->setSuffix(".png"); tempFile->open(); KIO::FileCopyJob *job = KIO::file_copy(url, QUrl(tempFile->fileName()), -1, KIO::Overwrite | KIO::HideProgressInfo); connect(job, &KIO::FileCopyJob::result, this, &ScreenShotViewer::resultJob); m_busySeq = new KPixmapSequenceOverlayPainter(this); - m_busySeq->setSequence(KPixmapSequence(QLatin1String("process-working"), KIconLoader::SizeSmallMedium)); + m_busySeq->setSequence(KIconLoader::global()->loadPixmapSequence(QLatin1String("process-working"), KIconLoader::SizeSmallMedium)); m_busySeq->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); m_busySeq->setWidget(m_screenshotL); m_busySeq->start(); connect(m_screenshotL, SIGNAL(clicked()), this, SLOT(deleteLater())); } ScreenShotViewer::~ScreenShotViewer() { } void ScreenShotViewer::resultJob(KJob *job) { m_busySeq->stop(); auto fJob = qobject_cast(job); if (!fJob->error()) { m_screenshot = QPixmap(fJob->destUrl().toLocalFile()); QPropertyAnimation *anim1 = new QPropertyAnimation(this, "size"); anim1->setDuration(500); anim1->setStartValue(size()); anim1->setEndValue(m_screenshot.size()); anim1->setEasingCurve(QEasingCurve::OutCubic); connect(anim1, &QPropertyAnimation::finished, this, &ScreenShotViewer::fadeIn); anim1->start(); } else { m_screenshotL->setText(i18n("Could not find screen shot.")); } } void ScreenShotViewer::fadeIn() { auto effect = new QGraphicsOpacityEffect(m_screenshotL); effect->setOpacity(0); auto anim = new QPropertyAnimation(effect, "opacity"); anim->setDuration(500); anim->setStartValue(qreal(0)); anim->setEndValue(qreal(1)); m_screenshotL->setGraphicsEffect(effect); m_screenshotL->setPixmap(m_screenshot); m_screenshotL->adjustSize(); anim->start(); } diff --git a/Apper/Settings/Settings.cpp b/Apper/Settings/Settings.cpp index b1603b1..d06ac0c 100644 --- a/Apper/Settings/Settings.cpp +++ b/Apper/Settings/Settings.cpp @@ -1,351 +1,351 @@ /*************************************************************************** * Copyright (C) 2008-2011 by Daniel Nicoletti * * dantti12@gmail.com * * * * 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., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "Settings.h" #include "ui_Settings.h" #include "OriginModel.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include Q_DECLARE_LOGGING_CATEGORY(APPER) using namespace PackageKit; Settings::Settings(Transaction::Roles roles, QWidget *parent) : QWidget(parent), ui(new Ui::Settings), m_roles(roles) { ui->setupUi(this); auto action = new QAction(i18n("Refresh Cache"), this); connect(action, &QAction::triggered, this, &Settings::refreshCache); connect(action, &QAction::triggered, ui->messageWidget, &KMessageWidget::animatedHide); ui->messageWidget->addAction(action); ui->messageWidget->setText(i18n("A repository was changed, it's highly recommended to refresh the cache")); ui->messageWidget->hide(); if (!(m_roles & Transaction::RoleRefreshCache)) { ui->intervalL->setEnabled(false); ui->intervalCB->setEnabled(false); } if (!(m_roles & Transaction::RoleGetDistroUpgrades)) { ui->distroIntervalCB->setEnabled(false); } m_originModel = new OriginModel(this); connect(m_originModel, &OriginModel::refreshRepoList, this, &Settings::refreshRepoModel); connect(m_originModel, &OriginModel::refreshRepoList, ui->messageWidget, &KMessageWidget::animatedShow); auto proxy = new QSortFilterProxyModel(this); proxy->setDynamicSortFilter(true); proxy->setSourceModel(m_originModel); ui->originTV->setModel(proxy); ui->originTV->header()->setDefaultAlignment(Qt::AlignCenter); // This is needed to keep the oring right ui->originTV->header()->setSortIndicator(0, Qt::AscendingOrder); proxy->sort(0); if (!(m_roles & Transaction::RoleGetRepoList)) { // Disables the group box ui->originTV->setEnabled(false); ui->showOriginsCB->setEnabled(false); } ui->distroIntervalCB->addItem(i18nc("Inform about distribution upgrades", "Never"), Enum::DistroNever); ui->distroIntervalCB->addItem(i18nc("Inform about distribution upgrades", "Only stable"), Enum::DistroStable); // Ignore unstable distros upgrades for now #ifndef false ui->distroIntervalCB->addItem(i18nc("Inform about distribution upgrades", "Stable and development"), Enum::DistroDevelopment); #endif ui->intervalCB->addItem(i18nc("Hourly refresh the package cache", "Hourly"), Enum::Hourly); ui->intervalCB->addItem(i18nc("Daily refresh the package cache", "Daily"), Enum::Daily); ui->intervalCB->addItem(i18nc("Weekly refresh the package cache", "Weekly"), Enum::Weekly); ui->intervalCB->addItem(i18nc("Monthly refresh the package cache", "Monthly"), Enum::Monthly); ui->intervalCB->addItem(i18nc("Never refresh package cache", "Never"), Enum::Never); ui->autoCB->addItem(i18nc("No updates will be automatically installed", "None"), Enum::None); ui->autoCB->addItem(i18n("Download only"), Enum::DownloadOnly); ui->autoCB->addItem(i18n("Security only"), Enum::Security); ui->autoCB->addItem(i18n("All updates"), Enum::All); connect(ui->autoConfirmCB, &QCheckBox::stateChanged, this, &Settings::checkChanges); connect(ui->appLauncherCB, &QCheckBox::stateChanged, this, &Settings::checkChanges); connect(ui->distroIntervalCB, QOverload::of(&KComboBox::currentIndexChanged), this, &Settings::checkChanges); connect(ui->intervalCB, QOverload::of(&KComboBox::currentIndexChanged), this, &Settings::checkChanges); connect(ui->checkUpdatesBatteryCB, &QCheckBox::stateChanged, this, &Settings::checkChanges); connect(ui->checkUpdatesMobileCB, &QCheckBox::stateChanged, this, &Settings::checkChanges); connect(ui->autoCB, QOverload::of(&KComboBox::currentIndexChanged), this, &Settings::checkChanges); connect(ui->installUpdatesBatteryCB, &QCheckBox::stateChanged, this, &Settings::checkChanges); connect(ui->installUpdatesMobileCB, &QCheckBox::stateChanged, this, &Settings::checkChanges); // Setup buttons QPushButton *apply = ui->buttonBox->button(QDialogButtonBox::Apply); apply->setEnabled(false); connect(apply, &QPushButton::clicked, this, &Settings::save); connect(this, &Settings::changed, apply, &QPushButton::setEnabled); QPushButton *reset = ui->buttonBox->button(QDialogButtonBox::Reset); // reset->setEnabled(false); connect(reset, &QPushButton::clicked, this, &Settings::defaults); // connect(this, &Settings::changed, reset, &QPushButton::setDisabled); // Setup the busy cursor m_busySeq = new KPixmapSequenceOverlayPainter(this); - m_busySeq->setSequence(KPixmapSequence(QLatin1String("process-working"), KIconLoader::SizeSmallMedium)); + m_busySeq->setSequence(KIconLoader::global()->loadPixmapSequence(QLatin1String("process-working"), KIconLoader::SizeSmallMedium)); m_busySeq->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); m_busySeq->setWidget(ui->originTV->viewport()); #ifndef EDIT_ORIGNS_DESKTOP_NAME ui->editOriginsPB->hide(); #endif //EDIT_ORIGNS_DESKTOP_NAME } Settings::~Settings() { delete ui; } void Settings::on_editOriginsPB_clicked() { #ifdef EDIT_ORIGNS_DESKTOP_NAME KToolInvocation::startServiceByDesktopName(EDIT_ORIGNS_DESKTOP_NAME); #endif //EDIT_ORIGNS_DESKTOP_NAME } void Settings::refreshRepoModel() { on_showOriginsCB_stateChanged(ui->showOriginsCB->checkState()); } // TODO update the repo list connecting to repo changed signal void Settings::on_showOriginsCB_stateChanged(int state) { Transaction *transaction = Daemon::getRepoList(state == Qt::Checked ? Transaction::FilterNone : Transaction::FilterNotDevel); connect(transaction, &Transaction::repoDetail, m_originModel, &OriginModel::addOriginItem); connect(transaction, &Transaction::finished, m_originModel, &OriginModel::finished); connect(transaction, &Transaction::finished, m_busySeq, &KPixmapSequenceOverlayPainter::stop); connect(transaction, &Transaction::finished, this, &Settings::checkChanges); m_busySeq->start(); KConfig config(QLatin1String("apper")); KConfigGroup originsDialog(&config, "originsDialog"); bool showDevel = originsDialog.readEntry("showDevel", false); if (showDevel != ui->showOriginsCB->isChecked()) { originsDialog.writeEntry("showDevel", ui->showOriginsCB->isChecked()); } } bool Settings::hasChanges() const { KConfig config(QLatin1String("apper")); KConfigGroup requirementsDialog(&config, "requirementsDialog"); KConfigGroup transaction(&config, "Transaction"); KConfigGroup checkUpdateGroup(&config, "CheckUpdate"); if (ui->distroIntervalCB->itemData(ui->distroIntervalCB->currentIndex()).toUInt() != static_cast(checkUpdateGroup.readEntry(CFG_DISTRO_UPGRADE, Enum::DistroUpgradeDefault)) || ui->intervalCB->itemData(ui->intervalCB->currentIndex()).toUInt() != static_cast(checkUpdateGroup.readEntry(CFG_INTERVAL, Enum::TimeIntervalDefault)) || ui->checkUpdatesBatteryCB->isChecked() != checkUpdateGroup.readEntry(CFG_CHECK_UP_BATTERY, DEFAULT_CHECK_UP_BATTERY) || ui->checkUpdatesMobileCB->isChecked() != checkUpdateGroup.readEntry(CFG_CHECK_UP_MOBILE, DEFAULT_CHECK_UP_MOBILE) || ui->autoCB->itemData(ui->autoCB->currentIndex()).toUInt() != static_cast(checkUpdateGroup.readEntry(CFG_AUTO_UP, Enum::AutoUpdateDefault)) || ui->installUpdatesBatteryCB->isChecked() != checkUpdateGroup.readEntry(CFG_INSTALL_UP_BATTERY, DEFAULT_INSTALL_UP_BATTERY) || ui->installUpdatesMobileCB->isChecked() != checkUpdateGroup.readEntry(CFG_INSTALL_UP_MOBILE, DEFAULT_INSTALL_UP_MOBILE) || ui->autoConfirmCB->isChecked() != !requirementsDialog.readEntry("autoConfirm", false) || ui->appLauncherCB->isChecked() != transaction.readEntry("ShowApplicationLauncher", true)) { return true; } return false; } void Settings::checkChanges() { emit changed(hasChanges()); // Check if interval update is never bool enabled = ui->intervalCB->itemData(ui->intervalCB->currentIndex()).toUInt() != Enum::Never; ui->checkUpdatesBatteryCB->setEnabled(enabled); ui->checkUpdatesMobileCB->setEnabled(enabled); ui->autoInsL->setEnabled(enabled); ui->autoCB->setEnabled(enabled); if (enabled) { enabled = ui->autoCB->itemData(ui->autoCB->currentIndex()).toUInt() != Enum::None; } ui->installUpdatesMobileCB->setEnabled(enabled); ui->installUpdatesBatteryCB->setEnabled(enabled); } void Settings::load() { KConfig config(QLatin1String("apper")); KConfigGroup requirementsDialog(&config, "requirementsDialog"); ui->autoConfirmCB->setChecked(!requirementsDialog.readEntry("autoConfirm", false)); KConfigGroup transaction(&config, "Transaction"); ui->appLauncherCB->setChecked(transaction.readEntry("ShowApplicationLauncher", true)); KConfigGroup checkUpdateGroup(&config, "CheckUpdate"); uint distroUpgrade = checkUpdateGroup.readEntry(CFG_DISTRO_UPGRADE, Enum::DistroUpgradeDefault); int ret = ui->distroIntervalCB->findData(distroUpgrade); if (ret == -1) { ui->distroIntervalCB->setCurrentIndex(ui->distroIntervalCB->findData(Enum::DistroUpgradeDefault)); } else { ui->distroIntervalCB->setCurrentIndex(ret); } uint interval = checkUpdateGroup.readEntry(CFG_INTERVAL, Enum::TimeIntervalDefault); ret = ui->intervalCB->findData(interval); if (ret == -1) { // this is if someone change the file by hand... ui->intervalCB->addItem(KFormat().formatSpelloutDuration(interval * 1000), interval); ui->intervalCB->setCurrentIndex(ui->intervalCB->count() - 1); } else { ui->intervalCB->setCurrentIndex(ret); } ui->checkUpdatesBatteryCB->setChecked(checkUpdateGroup.readEntry(CFG_CHECK_UP_BATTERY, DEFAULT_CHECK_UP_BATTERY)); ui->checkUpdatesMobileCB->setChecked(checkUpdateGroup.readEntry(CFG_CHECK_UP_MOBILE, DEFAULT_CHECK_UP_MOBILE)); uint autoUpdate = checkUpdateGroup.readEntry(CFG_AUTO_UP, Enum::AutoUpdateDefault); ret = ui->autoCB->findData(autoUpdate); if (ret == -1) { // this is if someone change the file by hand... ui->autoCB->setCurrentIndex(ui->autoCB->findData(Enum::AutoUpdateDefault)); } else { ui->autoCB->setCurrentIndex(ret); } ui->installUpdatesBatteryCB->setChecked(checkUpdateGroup.readEntry(CFG_INSTALL_UP_BATTERY, DEFAULT_INSTALL_UP_BATTERY)); ui->installUpdatesMobileCB->setChecked(checkUpdateGroup.readEntry(CFG_INSTALL_UP_MOBILE, DEFAULT_INSTALL_UP_MOBILE)); // Load origns list if (m_roles & Transaction::RoleGetRepoList) { KConfigGroup originsDialog(&config, "originsDialog"); bool showDevel = originsDialog.readEntry("showDevel", false); ui->showOriginsCB->setChecked(showDevel); refreshRepoModel(); ui->originTV->setEnabled(true); } else { ui->originTV->setEnabled(false); } // hide battery options if we are on a desktop computer const QList listBattery = Solid::Device::listFromType(Solid::DeviceInterface::Battery, QString()); bool notFound = true; for (const Solid::Device &device : listBattery) { const Solid::Battery *battery = device.as(); if (battery && battery->type() == Solid::Battery::PrimaryBattery) { notFound = false; break; } } if (notFound) { ui->checkUpdatesBatteryCB->hide(); ui->installUpdatesBatteryCB->hide(); } } void Settings::save() { qCDebug(APPER) << "Saving settings"; KConfig config(QLatin1String("apper")); KConfigGroup requirementsDialog(&config, "requirementsDialog"); requirementsDialog.writeEntry("autoConfirm", !ui->autoConfirmCB->isChecked()); KConfigGroup transaction(&config, "Transaction"); transaction.writeEntry("ShowApplicationLauncher", ui->appLauncherCB->isChecked()); KConfigGroup checkUpdateGroup(&config, "CheckUpdate"); checkUpdateGroup.writeEntry("distroUpgrade", ui->distroIntervalCB->itemData(ui->distroIntervalCB->currentIndex()).toUInt()); checkUpdateGroup.writeEntry("interval", ui->intervalCB->itemData(ui->intervalCB->currentIndex()).toUInt()); checkUpdateGroup.writeEntry("checkUpdatesOnBattery", ui->checkUpdatesBatteryCB->isChecked()); checkUpdateGroup.writeEntry("checkUpdatesOnMobile", ui->checkUpdatesMobileCB->isChecked()); checkUpdateGroup.writeEntry("autoUpdate", ui->autoCB->itemData(ui->autoCB->currentIndex()).toUInt()); checkUpdateGroup.writeEntry("installUpdatesOnBattery", ui->installUpdatesBatteryCB->isChecked()); checkUpdateGroup.writeEntry("installUpdatesOnMobile", ui->installUpdatesMobileCB->isChecked()); emit changed(false); } void Settings::defaults() { qCDebug(APPER) << "Restoring default settings"; ui->autoConfirmCB->setChecked(true); ui->appLauncherCB->setChecked(true); ui->distroIntervalCB->setCurrentIndex(ui->distroIntervalCB->findData(Enum::DistroUpgradeDefault)); ui->intervalCB->setCurrentIndex(ui->intervalCB->findData(Enum::TimeIntervalDefault)); ui->autoCB->setCurrentIndex(ui->autoCB->findData(Enum::AutoUpdateDefault) ); checkChanges(); } void Settings::showGeneralSettings() { ui->stackedWidget->setCurrentIndex(0); } void Settings::showRepoSettings() { ui->stackedWidget->setCurrentIndex(1); } diff --git a/Apper/Updater/UpdateDetails.cpp b/Apper/Updater/UpdateDetails.cpp index 8fefe7d..f0511f5 100644 --- a/Apper/Updater/UpdateDetails.cpp +++ b/Apper/Updater/UpdateDetails.cpp @@ -1,336 +1,336 @@ /*************************************************************************** * Copyright (C) 2009-2018 by Daniel Nicoletti * * dantti12@gmail.com * * * * 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., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "UpdateDetails.h" #include #include #include #include #include #include #include #include #include #include #include #include #define FINAL_HEIGHT 160 Q_DECLARE_LOGGING_CATEGORY(APPER) UpdateDetails::UpdateDetails(QWidget *parent) : QWidget(parent) { setupUi(this); hideTB->setIcon(QIcon::fromTheme(QLatin1String("window-close"))); connect(hideTB, &QToolButton::clicked, this, &UpdateDetails::hide); m_busySeq = new KPixmapSequenceOverlayPainter(this); - m_busySeq->setSequence(KPixmapSequence(QIcon::fromTheme(QLatin1String("process-working")).pixmap(KIconLoader::SizeSmallMedium))); + m_busySeq->setSequence(KIconLoader::global()->loadPixmapSequence(QLatin1String("process-working"), KIconLoader::SizeSmallMedium)); m_busySeq->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); m_busySeq->setWidget(this); QWidget *actionsViewport = descriptionKTB->viewport(); QPalette palette = actionsViewport->palette(); palette.setColor(actionsViewport->backgroundRole(), Qt::transparent); palette.setColor(actionsViewport->foregroundRole(), palette.color(QPalette::WindowText)); actionsViewport->setPalette(palette); auto effect = new QGraphicsOpacityEffect(descriptionKTB); effect->setOpacity(0); descriptionKTB->setGraphicsEffect(effect); m_fadeDetails = new QPropertyAnimation(effect, "opacity", this); m_fadeDetails->setDuration(500); m_fadeDetails->setStartValue(qreal(0)); m_fadeDetails->setEndValue(qreal(1)); connect(m_fadeDetails, &QPropertyAnimation::finished, this, &UpdateDetails::display); auto anim1 = new QPropertyAnimation(this, "maximumSize", this); anim1->setDuration(500); anim1->setEasingCurve(QEasingCurve::OutQuart); anim1->setStartValue(QSize(QWIDGETSIZE_MAX, 0)); anim1->setEndValue(QSize(QWIDGETSIZE_MAX, FINAL_HEIGHT)); auto anim2 = new QPropertyAnimation(this, "minimumSize", this); anim2->setDuration(500); anim2->setEasingCurve(QEasingCurve::OutQuart); anim2->setStartValue(QSize(QWIDGETSIZE_MAX, 0)); anim2->setEndValue(QSize(QWIDGETSIZE_MAX, FINAL_HEIGHT)); m_expandPanel = new QParallelAnimationGroup(this); m_expandPanel->addAnimation(anim1); m_expandPanel->addAnimation(anim2); connect(m_expandPanel, &QParallelAnimationGroup::finished, this, &UpdateDetails::display); } UpdateDetails::~UpdateDetails() { } void UpdateDetails::setPackage(const QString &packageId, Transaction::Info updateInfo) { if (m_packageId == packageId) { return; } m_show = true; m_packageId = packageId; m_updateInfo = updateInfo; m_currentDescription.clear(); if (m_transaction) { disconnect(m_transaction, &Transaction::updateDetail, this, &UpdateDetails::updateDetail); disconnect(m_transaction, &Transaction::finished, this, &UpdateDetails::display); } m_transaction = Daemon::getUpdateDetail(m_packageId); connect(m_transaction, &Transaction::updateDetail, this, &UpdateDetails::updateDetail); connect(m_transaction, &Transaction::finished, this, &UpdateDetails::display); if (maximumSize().height() == 0) { // Expand the panel m_expandPanel->setDirection(QAbstractAnimation::Forward); m_expandPanel->start(); } else if (m_fadeDetails->currentValue().toReal() != 0) { // Hide the old description m_fadeDetails->setDirection(QAbstractAnimation::Backward); m_fadeDetails->start(); } m_busySeq->start(); } void UpdateDetails::hide() { m_show = false; m_packageId.clear(); if (maximumSize().height() == FINAL_HEIGHT && m_fadeDetails->currentValue().toReal() == 1) { m_fadeDetails->setDirection(QAbstractAnimation::Backward); m_fadeDetails->start(); } else if (maximumSize().height() == FINAL_HEIGHT && m_fadeDetails->currentValue().toReal() == 0) { m_expandPanel->setDirection(QAbstractAnimation::Backward); m_expandPanel->start(); } } void UpdateDetails::display() { qCDebug(APPER) << sender(); // set transaction to 0 as if PK crashes // UpdateDetails won't be emmited m_transaction = 0; if (!m_show) { hide(); return; } if (maximumSize().height() == FINAL_HEIGHT && !m_currentDescription.isEmpty() && m_fadeDetails->currentValue().toReal() == 0) { descriptionKTB->setHtml(m_currentDescription); m_fadeDetails->setDirection(QAbstractAnimation::Forward); m_fadeDetails->start(); } else if (m_currentDescription.isEmpty()) { updateDetailFinished(); } } void UpdateDetails::updateDetail(const QString &packageID, const QStringList &updates, const QStringList &obsoletes, const QStringList &vendorUrls, const QStringList &bugzillaUrls, const QStringList &cveUrls, PackageKit::Transaction::Restart restart, const QString &updateText, const QString &changelog, PackageKit::Transaction::UpdateState state, const QDateTime &issued, const QDateTime &updated) { //format and show description QString description; // update type (ie Security Update) if (m_updateInfo == Transaction::InfoEnhancement) { description += QLatin1String("

") + i18n("This update will add new features and expand functionality.") + QLatin1String("

"); } else if (m_updateInfo == Transaction::InfoBugfix) { description += QLatin1String("

") + i18n("This update will fix bugs and other non-critical problems.") + QLatin1String("

"); } else if (m_updateInfo == Transaction::InfoImportant) { description += QLatin1String("

") + i18n("This update is important as it may solve critical problems.") + QLatin1String("

"); } else if (m_updateInfo == Transaction::InfoSecurity) { description += QLatin1String("

") + i18n("This update is needed to fix a security vulnerability with this package.") + QLatin1String("

"); } else if (m_updateInfo == Transaction::InfoBlocked) { description += QLatin1String("

") + i18n("This update is blocked.") + QLatin1String("

"); } // Issued and Updated if (!issued.isNull() && !updated.isNull()) { description += QLatin1String("

") + i18n("This notification was issued on %1 and last updated on %2.", QLocale::system().toString(issued, QLocale::ShortFormat), QLocale::system().toString(updated, QLocale::ShortFormat)) + QLatin1String("

"); } else if (!issued.isNull()) { description += QLatin1String("

") + i18n("This notification was issued on %1.", QLocale::system().toString(issued, QLocale::ShortFormat)) + QLatin1String("

"); } // Description if (!updateText.isEmpty()) { QString _updateText = updateText; _updateText.replace(QLatin1Char('\n'), QLatin1String("
")); _updateText.replace(QLatin1Char(' '), QLatin1String(" ")); description += QLatin1String("

") + _updateText + QLatin1String("

"); } // links // Vendor if (!vendorUrls.isEmpty()) { description += QLatin1String("

") + i18np("For more information about this update please visit this website:", "For more information about this update please visit these websites:", vendorUrls.size()) + QLatin1String("
") + getLinkList(vendorUrls) + QLatin1String("

"); } // Bugzilla if (!bugzillaUrls.isEmpty()) { description += QLatin1String("

") + i18np("For more information about bugs fixed by this update please visit this website:", "For more information about bugs fixed by this update please visit these websites:", bugzillaUrls.size()) + QLatin1String("
") + getLinkList(bugzillaUrls) + QLatin1String("

"); } // CVE if (!cveUrls.isEmpty()) { description += QLatin1String("

") + i18np("For more information about this security update please visit this website:", "For more information about this security update please visit these websites:", cveUrls.size()) + QLatin1String("
") + getLinkList(cveUrls) + QLatin1String("

"); } // Notice (about the need for a reboot) if (restart == Transaction::RestartSystem) { description += QLatin1String("

") + i18n("The computer will have to be restarted after the update for the changes to take effect.") + QLatin1String("

"); } else if (restart == Transaction::RestartSession) { description += QLatin1String("

") + i18n("You will need to log out and back in after the update for the changes to take effect.") + QLatin1String("

"); } // State if (state == Transaction::UpdateStateUnstable) { description += QLatin1String("

") + i18n("The classification of this update is unstable which means it is not designed for production use.") + QLatin1String("

"); } else if (state == Transaction::UpdateStateTesting) { description += QLatin1String("

") + i18n("This is a test update, and is not designed for normal use. Please report any problems or regressions you encounter.") + QLatin1String("

"); } // only show changelog if we didn't have any update text if (updateText.isEmpty() && !changelog.isEmpty()) { QString _changelog = changelog; _changelog.replace(QLatin1Char('\n'), QLatin1String("
")); _changelog.replace(QLatin1Char(' '), QLatin1String(" ")); description += QLatin1String("

") + i18n("The developer logs will be shown as no description is available for this update:") + QLatin1String("
") + _changelog + QLatin1String("

"); } // Updates (lists of packages that are updated) if (!updates.isEmpty()) { description += QLatin1String("

") + i18n("Updates:") + QLatin1String("
"); QStringList _updates; for (const QString &pid : updates) { _updates += QString::fromUtf8("\xE2\x80\xA2 ") + Transaction::packageName(pid) + QLatin1String(" - ") + Transaction::packageVersion(pid); } description += _updates.join(QLatin1String("
")) + QLatin1String("

"); } // Obsoletes (lists of packages that are obsoleted) if (obsoletes.size()) { description += QLatin1String("

") + i18n("Obsoletes:") + QLatin1String("
"); QStringList _obsoletes; for (const QString &pid : obsoletes) { _obsoletes += QString::fromUtf8("\xE2\x80\xA2 ") + Transaction::packageName(pid) + QLatin1String(" - ") + Transaction::packageVersion(pid); } description += _obsoletes.join(QLatin1String("
/")) + QLatin1String("

"); } // Repository (this is the repository the package comes from) if (!Transaction::packageData(packageID).isEmpty()) { description += QLatin1String("

") + i18n("Repository: %1", Transaction::packageData(packageID)) + QLatin1String("

"); } m_currentDescription = description; m_busySeq->stop(); } QString UpdateDetails::getLinkList(const QStringList &urls) const { QString ret; for (const QString &url : urls) { if (!ret.isEmpty()) { ret += QLatin1String("
"); } ret += QString::fromUtf8(" \xE2\x80\xA2 ") % url % QLatin1String(""); } return ret; } void UpdateDetails::updateDetailFinished() { if (descriptionKTB->document()->toPlainText().isEmpty()) { descriptionKTB->setPlainText(i18n("No update description was found.")); } } diff --git a/Apper/Updater/Updater.cpp b/Apper/Updater/Updater.cpp index 82ef8ad..bb79e47 100644 --- a/Apper/Updater/Updater.cpp +++ b/Apper/Updater/Updater.cpp @@ -1,349 +1,349 @@ /*************************************************************************** * Copyright (C) 2008-2011 by Daniel Nicoletti * * dantti12@gmail.com * * * * 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., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "Updater.h" #include "ui_Updater.h" #include "UpdateDetails.h" #include "DistroUpgrade.h" #include "CheckableHeader.h" #include //#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include Q_DECLARE_LOGGING_CATEGORY(APPER) Updater::Updater(Transaction::Roles roles, QWidget *parent) : QWidget(parent), ui(new Ui::Updater), m_roles(roles) { ui->setupUi(this); updatePallete(); // connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), // this, SLOT(updatePallete())); m_updatesModel = new PackageModel(this); m_updatesModel->setCheckable(true); auto proxyModel = new ApplicationSortFilterModel(this); proxyModel->setSourceModel(m_updatesModel); ui->packageView->setModel(proxyModel); m_delegate = new ApplicationsDelegate(ui->packageView); m_delegate->setCheckable(true); ui->packageView->setItemDelegate(m_delegate); ui->packageView->sortByColumn(PackageModel::NameCol, Qt::AscendingOrder); connect(m_updatesModel, &PackageModel::changed, this, &Updater::checkEnableUpdateButton); //initialize the model, delegate, client and connect it's signals m_header = new CheckableHeader(Qt::Horizontal, this); connect(m_header, &CheckableHeader::toggled, m_updatesModel, &PackageModel::setAllChecked); m_header->setCheckBoxVisible(false); m_header->setDefaultAlignment(Qt::AlignCenter); ui->packageView->setHeaderHidden(false); ui->packageView->setHeader(m_header); // This must be set AFTER the model is set, otherwise it doesn't work m_header->setSectionResizeMode(PackageModel::NameCol, QHeaderView::Stretch); m_header->setSectionResizeMode(PackageModel::VersionCol, QHeaderView::ResizeToContents); m_header->setSectionResizeMode(PackageModel::CurrentVersionCol, QHeaderView::ResizeToContents); m_header->setSectionResizeMode(PackageModel::ArchCol, QHeaderView::ResizeToContents); m_header->setSectionResizeMode(PackageModel::OriginCol, QHeaderView::ResizeToContents); m_header->setSectionResizeMode(PackageModel::SizeCol, QHeaderView::ResizeToContents); m_header->setStretchLastSection(false); // Setup the busy cursor m_busySeq = new KPixmapSequenceOverlayPainter(this); - m_busySeq->setSequence(KPixmapSequence(QLatin1String("process-working"), KIconLoader::SizeSmallMedium)); + m_busySeq->setSequence(KIconLoader::global()->loadPixmapSequence(QLatin1String("process-working"), KIconLoader::SizeSmallMedium)); m_busySeq->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); m_busySeq->setWidget(ui->packageView->viewport()); // hide distro Upgrade container and line ui->distroUpgrade->hide(); KConfig config(QLatin1String("apper")); KConfigGroup viewGroup(&config, "UpdateView"); // versions ui->packageView->header()->setSectionHidden(PackageModel::VersionCol, true); m_showPackageVersion = new QAction(i18n("Show Versions"), this); m_showPackageVersion->setCheckable(true); connect(m_showPackageVersion, &QAction::toggled, this, &Updater::showVersions); m_showPackageVersion->setChecked(viewGroup.readEntry("ShowVersions", true)); // versions ui->packageView->header()->setSectionHidden(PackageModel::CurrentVersionCol, true); m_showPackageCurrentVersion = new QAction(i18n("Show Current Versions"), this); m_showPackageCurrentVersion->setCheckable(true); connect(m_showPackageCurrentVersion, &QAction::toggled, this, &Updater::showCurrentVersions); m_showPackageCurrentVersion->setChecked(viewGroup.readEntry("ShowCurrentVersions", false)); // Arch ui->packageView->header()->setSectionHidden(PackageModel::ArchCol, true); m_showPackageArch = new QAction(i18n("Show Architectures"), this); m_showPackageArch->setCheckable(true); connect(m_showPackageArch, &QAction::toggled, this, &Updater::showArchs); m_showPackageArch->setChecked(viewGroup.readEntry("ShowArchs", false)); // Origin ui->packageView->header()->setSectionHidden(PackageModel::OriginCol, true); m_showPackageOrigin = new QAction(i18n("Show Origins"), this); m_showPackageOrigin->setCheckable(true); connect(m_showPackageOrigin, &QAction::toggled, this, &Updater::showOrigins); m_showPackageOrigin->setChecked(viewGroup.readEntry("ShowOrigins", false)); // Sizes ui->packageView->header()->setSectionHidden(PackageModel::SizeCol, true); m_showPackageSize = new QAction(i18n("Show Sizes"), this); m_showPackageSize->setCheckable(true); connect(m_showPackageSize, &QAction::toggled, this, &Updater::showSizes); m_showPackageSize->setChecked(viewGroup.readEntry("ShowSizes", true)); } Updater::~Updater() { delete ui; } void Updater::showVersions(bool enabled) { KConfig config(QLatin1String("apper")); KConfigGroup viewGroup(&config, "UpdateView"); viewGroup.writeEntry("ShowVersions", enabled); ui->packageView->header()->setSectionHidden(PackageModel::VersionCol, !enabled); } void Updater::showCurrentVersions(bool enabled) { KConfig config(QLatin1String("apper")); KConfigGroup viewGroup(&config, "UpdateView"); viewGroup.writeEntry("ShowCurrentVersions", enabled); ui->packageView->header()->setSectionHidden(PackageModel::CurrentVersionCol, !enabled); if (enabled) { m_updatesModel->fetchCurrentVersions(); } } void Updater::showArchs(bool enabled) { KConfig config(QLatin1String("apper")); KConfigGroup viewGroup(&config, "UpdateView"); viewGroup.writeEntry("ShowArchs", enabled); ui->packageView->header()->setSectionHidden(PackageModel::ArchCol, !enabled); } void Updater::showOrigins(bool enabled) { KConfig config(QLatin1String("apper")); KConfigGroup viewGroup(&config, "UpdateView"); viewGroup.writeEntry("showOrigins", enabled); ui->packageView->header()->setSectionHidden(PackageModel::OriginCol, !enabled); } void Updater::showSizes(bool enabled) { KConfig config(QLatin1String("apper")); KConfigGroup viewGroup(&config, "UpdateView"); viewGroup.writeEntry("ShowSizes", enabled); ui->packageView->header()->setSectionHidden(PackageModel::SizeCol, !enabled); if (enabled) { m_updatesModel->fetchSizes(); } } void Updater::updatePallete() { QPalette pal; pal.setColor(QPalette::Window, pal.base().color()); pal.setColor(QPalette::WindowText, pal.text().color()); ui->backgroundFrame->setPalette(pal); } void Updater::on_packageView_clicked(const QModelIndex &index) { QString pkgId = index.data(PackageModel::IdRole).toString(); auto pkgInfo = index.data(PackageModel::InfoRole).value(); ui->updateDetails->setPackage(pkgId, pkgInfo); } //TODO: We should add some kind of configuration to let users show unstable distributions //That way, by default, users only see stable ones. void Updater::distroUpgrade(PackageKit::Transaction::DistroUpgrade type, const QString &name, const QString &description) { // TODO name should be used to do a upgrade to a different type Q_UNUSED(name) if (type != Transaction::DistroUpgradeStable) { // Ignore unstable distros upgrades for now return; } ui->distroUpgrade->setName(description); ui->distroUpgrade->animatedShow(); } bool Updater::hasChanges() const { return m_updatesModel->hasChanges(); } void Updater::checkEnableUpdateButton() { qCDebug(APPER) << "updates has changes" << hasChanges(); emit changed(hasChanges()); int selectedSize = m_updatesModel->selectedPackagesToInstall().size(); int updatesSize = m_updatesModel->rowCount(); if (selectedSize == 0) { m_header->setCheckState(Qt::Unchecked); } else if (selectedSize == updatesSize) { m_header->setCheckState(Qt::Checked); } else { m_header->setCheckState(Qt::PartiallyChecked); } unsigned long dwSize = m_updatesModel->downloadSize(); if (dwSize) { emit downloadSize(i18n("Estimated download size: %1", KFormat().formatByteSize(dwSize))); } else { emit downloadSize(QString()); } // if we don't have any upates let's disable the button m_header->setCheckBoxVisible(m_updatesModel->rowCount() != 0); ui->packageView->setHeaderHidden(m_updatesModel->rowCount() == 0); } void Updater::load() { // set focus on the updates view ui->packageView->setFocus(Qt::OtherFocusReason); emit downloadSize(QString()); // If the model already has some packages // let's just clear the selection if (m_updatesModel->rowCount()) { m_updatesModel->setAllChecked(false); } else { getUpdates(); } } void Updater::getUpdatesFinished() { m_updatesT = 0; m_updatesModel->clearSelectedNotPresent(); checkEnableUpdateButton(); if (m_updatesModel->rowCount() == 0) { // Set the info page ui->stackedWidget->setCurrentIndex(1); uint lastTime = Daemon::global()->getTimeSinceAction(Transaction::RoleRefreshCache); ui->titleL->setText(PkStrings::lastCacheRefreshTitle(lastTime)); ui->descriptionL->setText(PkStrings::lastCacheRefreshSubTitle(lastTime)); ui->iconL->setPixmap(QIcon::fromTheme(PkIcons::lastCacheRefreshIconName(lastTime)).pixmap(128, 128)); } } QStringList Updater::packagesToUpdate() const { return m_updatesModel->selectedPackagesToInstall(); } void Updater::getUpdates() { if (m_updatesT) { // There is a getUpdates running ignore this call return; } if (ui->stackedWidget->currentIndex() != 0) { ui->stackedWidget->setCurrentIndex(0); } // clears the model ui->packageView->setHeaderHidden(true); m_updatesModel->clear(); ui->updateDetails->hide(); m_updatesT = Daemon::getUpdates(); connect(m_updatesT, &Transaction::package, m_updatesModel, &PackageModel::addSelectedPackage); connect(m_updatesT, &Transaction::errorCode, this, &Updater::errorCode); connect(m_updatesT, &Transaction::finished, m_busySeq, &KPixmapSequenceOverlayPainter::stop); connect(m_updatesT, &Transaction::finished, m_updatesModel, &PackageModel::finished); // This is required to estimate download size connect(m_updatesT, &Transaction::finished, m_updatesModel, &PackageModel::fetchSizes); if (m_showPackageCurrentVersion->isChecked()) { connect(m_updatesT, &Transaction::finished, m_updatesModel, &PackageModel::fetchCurrentVersions); } connect(m_updatesT, &Transaction::finished, this, &Updater::getUpdatesFinished); m_busySeq->start(); // Hide the distribution upgrade information ui->distroUpgrade->animatedHide(); if (m_roles & Transaction::RoleGetDistroUpgrades) { // Check for distribution Upgrades Transaction *t = Daemon::getDistroUpgrades(); connect(m_updatesT, &Transaction::distroUpgrade, this, &Updater::distroUpgrade); connect(m_updatesT, &Transaction::finished, t, &Transaction::deleteLater); } } void Updater::on_packageView_customContextMenuRequested(const QPoint &pos) { auto menu = new QMenu(this); menu->addAction(m_showPackageVersion); menu->addAction(m_showPackageCurrentVersion); menu->addAction(m_showPackageArch); menu->addAction(m_showPackageOrigin); menu->addAction(m_showPackageSize); QAction *action; action = menu->addAction(i18n("Check for new updates")); action->setIcon(QIcon::fromTheme(QLatin1String("view-refresh"))); connect(action, &QAction::triggered, this, &Updater::refreshCache); menu->exec(ui->packageView->viewport()->mapToGlobal(pos)); delete menu; } void Updater::errorCode(PackageKit::Transaction::Error error, const QString &details) { KMessageBox::detailedSorry(this, PkStrings::errorMessage(error), details, PkStrings::error(error), KMessageBox::Notify); } diff --git a/CMakeLists.txt b/CMakeLists.txt index bd19999..d16cc08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,148 +1,148 @@ -project(Apper) cmake_minimum_required(VERSION 3.0) +cmake_policy(SET CMP0063 NEW) -set(APPER_VERSION 1.0.0) +project(Apper VERSION 1.0.0) find_package(ECM REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/) set(CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) include(FindPkgConfig) include(KDEInstallDirs) include(KDECompilerSettings) include(KDECMakeSettings) include(FeatureSummary) include(ECMInstallIcons) find_package(Qt5 5.7.0 CONFIG REQUIRED Core DBus Widgets Quick Sql XmlPatterns) # Load the frameworks we need find_package(KF5 REQUIRED COMPONENTS Config DocTools GuiAddons I18n KCMUtils DBusAddons KIO Notifications IconThemes ) find_package(LibKWorkspace REQUIRED) find_package(KDED REQUIRED) find_package(PackageKitQt5 1.0.0 REQUIRED) # # Options # # The various parts of Apper that can be built, or not. option(BUILD_APPER "Build the Apper application" ON) option(BUILD_APPERD "Build the Apper daemon" ON) option(BUILD_DECLARATIVE "Build the Qt Quick plugins" ON) option(BUILD_PKSESSION "Build the PkSession helper application" ON) option(BUILD_PLASMOID "Build the update notifier plasmoid" ON) # Only for Debian based systems option(DEBCONF_SUPPORT "Build Apper with debconf support" OFF) # Yum does not support this option(AUTOREMOVE "Build Apper with auto remove enabled" OFF) set(HAVE_AUTOREMOVE ${AUTOREMOVE}) message(STATUS "Building Apper with auto remove: " ${AUTOREMOVE}) # AppStream application management support option(APPSTREAM "Build Apper with AppStream support" OFF) set(HAVE_APPSTREAM ${APPSTREAM}) message(STATUS "Building Apper with AppStream support: " ${APPSTREAM}) # Enable support for Limba packages option(LIMBA "Build Apper with Limba bundle support" OFF) set(HAVE_LIMBA ${LIMBA}) message(STATUS "Building Apper with Limba support: " ${LIMBA}) option(MAINTAINER "Enable maintainer mode" OFF) if(DEBCONF_SUPPORT) # Tries to find the package, when it finds it, set HAVE_DEBCONFKDE find_package(DebconfKDE REQUIRED) message(STATUS "Building with Debconf support") set(HAVE_DEBCONF ${DEBCONF_SUPPORT}) endif(DEBCONF_SUPPORT) # command to edit the packages origins set(EDIT_ORIGNS_DESKTOP_NAME "" CACHE STRING "Edit origins desktop name") if (EDIT_ORIGNS_DESKTOP_NAME) message(STATUS "Edit origins desktop name: " ${EDIT_ORIGNS_DESKTOP_NAME}) endif(EDIT_ORIGNS_DESKTOP_NAME) # Generate config.h configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) # # Add definitions # set(MAINTAINER_CFLAGS "") if(MAINTAINER) set(MAINTAINER_CFLAGS "-Werror -Wall -Wcast-align -Wno-uninitialized -Wempty-body -Wformat-security -Winit-self -Wno-deprecated-declarations") if (CMAKE_COMPILER_IS_GNUCC) execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) if (GCC_VERSION VERSION_GREATER 4.9 OR GCC_VERSION VERSION_EQUAL 4.9) set(MAINTAINER_CFLAGS ${MAINTAINER_CFLAGS} "-fdiagnostics-color=auto") endif() endif() endif(MAINTAINER) add_definitions(${MAINTAINER_CFLAGS}) add_definitions( -DQT_USE_QSTRINGBUILDER -DQT_STRICT_ITERATORS -DQT_NO_URL_CAST_FROM_STRING -DQT_NO_CAST_FROM_BYTEARRAY -DQT_NO_SIGNALS_SLOTS_KEYWORDS -DQT_USE_FAST_OPERATOR_PLUS -DQT_NO_URL_CAST_FROM_STRING -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_DISABLE_DEPRECATED_BEFORE=0x050900 ) # # Global includes # include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${PackageKitQt5_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/libapper) # # Subcomponents # add_subdirectory(libapper) if(BUILD_APPER) add_subdirectory(Apper) endif(BUILD_APPER) if(BUILD_PKSESSION) add_subdirectory(PkSession) endif(BUILD_PKSESSION) if(BUILD_APPERD) add_subdirectory(apperd) endif(BUILD_APPERD) if(BUILD_DECLARATIVE) # add_subdirectory(declarative-plugins) endif(BUILD_DECLARATIVE) if(BUILD_PLASMOID) # add_subdirectory(plasmoid) endif(BUILD_PLASMOID) if(LIMBA) add_subdirectory(AppSetup) endif() add_subdirectory(doc) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/apperd/CMakeLists.txt b/apperd/CMakeLists.txt index 495f033..f870634 100644 --- a/apperd/CMakeLists.txt +++ b/apperd/CMakeLists.txt @@ -1,41 +1,41 @@ # CMakeLists for the kded component set(kded_apperd_SRCS DistroUpgrade.cpp DBusInterface.cpp TransactionJob.cpp TransactionWatcher.cpp RefreshCacheTask.cpp Updater.cpp RebootListener.cpp ApperdThread.cpp apperd.cpp ) qt5_add_dbus_adaptor(kded_apperd_SRCS org.kde.apperd.xml DBusInterface.h DBusInterface ) add_library(kded_apperd MODULE ${kded_apperd_SRCS}) target_link_libraries(kded_apperd KF5::WidgetsAddons KF5::KIOFileWidgets KF5::Notifications KF5::DBusAddons PW::KWorkspace PK::packagekitqt5 apper_private ) if(DEBCONF_SUPPORT) -target_link_libraries(kded_apperd DebconfKDE::Main) -endif(DEBUCONF_SUPPORT) + target_link_libraries(kded_apperd DebconfKDE::Main) +endif() set_target_properties(kded_apperd PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}/apper) install(TARGETS kded_apperd DESTINATION ${CMAKE_INSTALL_QTPLUGINDIR}) install(FILES apperd.notifyrc DESTINATION ${CMAKE_INSTALL_DATADIR}/apperd) install(FILES apperd.desktop DESTINATION ${CMAKE_INSTALL_KSERVICES5DIR}/kded) diff --git a/config.h.cmake b/config.h.cmake index 1b9ade3..4c54a29 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -1,28 +1,28 @@ #ifndef CONFIG_H #define CONFIG_H // Define if you have DebconfKDE libraries and header files. #cmakedefine HAVE_DEBCONFKDE // Define if your backend have autoremove feature. #cmakedefine HAVE_AUTOREMOVE // Define if AppStream is available. #cmakedefine HAVE_APPSTREAM // Define if Limba is available. #cmakedefine HAVE_LIMBA // Define if screenshot provider #cmakedefine SCREENSHOT_PROVIDER "@SCREENSHOT_PROVIDER@" // Define the AppStream categories path. #cmakedefine AS_CATEGORIES_PATH "@AS_CATEGORIES_PATH@" // Define the edit origins command. #cmakedefine EDIT_ORIGNS_DESKTOP_NAME "@EDIT_ORIGNS_DESKTOP_NAME@" // Define the Apper version. -#cmakedefine APPER_VERSION "@APPER_VERSION@" +#define APPER_VERSION "@PROJECT_VERSION@" #endif //CONFIG_H