File indexing completed on 2024-05-12 05:48:43
0001 /*************************************************************************** 0002 * Copyright © 2009-2010 Jonathan Thomas <echidnaman@kubuntu.org> * 0003 * Copyright © 2021 Harald Sitter <sitter@kde.org> * 0004 * * 0005 * This program is free software; you can redistribute it and/or * 0006 * modify it under the terms of the GNU General Public License as * 0007 * published by the Free Software Foundation; either version 2 of * 0008 * the License or (at your option) version 3 or any later version * 0009 * accepted by the membership of KDE e.V. (or its successor approved * 0010 * by the membership of KDE e.V.), which shall act as a proxy * 0011 * defined in Section 14 of version 3 of the license. * 0012 * * 0013 * This program is distributed in the hope that it will be useful, * 0014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0016 * GNU General Public License for more details. * 0017 * * 0018 * You should have received a copy of the GNU General Public License * 0019 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0020 ***************************************************************************/ 0021 0022 #include "installevent.h" 0023 0024 // Qt includes 0025 #include <QtCore/QFile> 0026 #include <QDebug> 0027 0028 // Own includes 0029 #include "installgui.h" 0030 #include "installdbuswatcher.h" 0031 0032 InstallEvent::InstallEvent(QObject *parent) 0033 : Event(parent, "Install") 0034 #warning this isn't localized and makes no sense where it is used 0035 , m_applicationName("Install") 0036 , m_installGui(0) 0037 { 0038 // this normally gets called by applications calling it through dbus when they start 0039 auto installWatcher = new InstallDBusWatcher(this); 0040 connect(installWatcher, 0041 &InstallDBusWatcher::installRestrictedCalled, 0042 this, 0043 [this](const QString &application, const QString &package) { getInfo(application, package); }); 0044 0045 m_webBrowserPackages["flashplugin-installer"] = i18nc("The name of the Adobe Flash plugin", "Flash"); 0046 0047 m_multimediaEncodingPackages["libk3b6-extracodecs"] = i18n("K3b CD Codecs"); 0048 m_multimediaEncodingPackages["libmp3lame0"] = i18n("MP3 Encoding"); 0049 0050 m_packageMapList.append(m_webBrowserPackages); 0051 m_packageMapList.append(m_multimediaEncodingPackages); 0052 } 0053 0054 InstallEvent::~InstallEvent() 0055 { 0056 } 0057 0058 void InstallEvent::show() 0059 { 0060 if (isHidden()) { 0061 return; 0062 } 0063 0064 QString icon = QString("muondiscover"); 0065 QString text(i18nc("Notification when a package wants to install extra software", 0066 "Extra packages can be installed to enhance functionality for %1", 0067 m_applicationName)); 0068 QStringList actions; 0069 actions << i18nc("Opens a dialog with more details", "Details"); 0070 actions << i18nc("Button to dismiss this notification once", "Ignore for now"); 0071 actions << i18nc("Button to make this notification never show up again", 0072 "Never show again"); 0073 0074 Event::show(icon, text, actions); 0075 } 0076 0077 void InstallEvent::addPackages(const QMap<QString, QString> &packageList) 0078 { 0079 QMap<QString, QString>::const_iterator packageIter = packageList.constBegin(); 0080 while (packageIter != packageList.constEnd()) { 0081 // check for .md5sums as .list exists even when the package is removed (but not purged) 0082 if (!QFile::exists("/var/lib/dpkg/info/" + packageIter.key() + ".md5sums") && 0083 !QFile::exists("/var/lib/dpkg/info/" + packageIter.key() + ":i386.md5sums") && 0084 !QFile::exists("/var/lib/dpkg/info/" + packageIter.key() + ":amd64.md5sums")) { 0085 m_packageList[packageIter.key()] = packageIter.value(); 0086 } 0087 ++packageIter; 0088 } 0089 } 0090 0091 void InstallEvent::getInfo(const QString &application, const QString &package) 0092 { 0093 m_applicationName = application; 0094 m_packageList.clear(); 0095 0096 QList<QMap<QString, QString> >::const_iterator packageMapIter = m_packageMapList.constBegin(); 0097 while (packageMapIter != m_packageMapList.constEnd()) { 0098 if ((*packageMapIter).contains(package)) { 0099 addPackages(*packageMapIter); 0100 break; 0101 } 0102 0103 ++packageMapIter; 0104 } 0105 0106 if (!m_packageList.isEmpty()) { 0107 show(); 0108 } 0109 } 0110 0111 void InstallEvent::run() 0112 { 0113 m_installGui = new InstallGui(this, m_applicationName, m_packageList); 0114 Event::run(); 0115 }