File indexing completed on 2024-05-19 05:49:21
0001 /*************************************************************************** 0002 * Copyright © 2009 Jonathan Thomas <echidnaman@kubuntu.org> * 0003 * Copyright © 2009-2021 Harald Sitter <apachelogger@ubuntu.com> * 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 "hookevent.h" 0023 0024 // Qt includes 0025 #include <QDir> 0026 0027 #include <KDirWatch> 0028 0029 // Own includes 0030 #include "hook.h" 0031 #include "hookgui.h" 0032 0033 HookEvent::HookEvent(QObject* parent) 0034 : Event(parent, "Hook") 0035 , m_hooks() 0036 , m_hookGui(0) 0037 { 0038 auto hooksDirWatch = new KDirWatch(this); 0039 hooksDirWatch->addDir("/var/lib/update-notifier/user.d/"); 0040 connect(hooksDirWatch, &KDirWatch::dirty, this, &HookEvent::show); 0041 0042 // Sometimes hooks are for the first boot, so force a check 0043 show(); // noop when not applicable 0044 } 0045 0046 HookEvent::~HookEvent() 0047 { 0048 } 0049 0050 void HookEvent::show() 0051 { 0052 if (isHidden()) { 0053 return; 0054 } 0055 0056 qDeleteAll(m_hooks); 0057 m_hooks.clear(); 0058 QDir hookDir(QLatin1String("/var/lib/update-notifier/user.d/")); 0059 QStringList fileList = hookDir.entryList(QDir::Files); 0060 foreach(const QString &fileName, fileList) { 0061 Hook *hook = new Hook(this, hookDir.filePath(fileName)); 0062 if (hook->isValid() && hook->isNotificationRequired()) { 0063 m_hooks << hook; 0064 } else { 0065 hook->deleteLater(); 0066 } 0067 } 0068 0069 if (!m_hooks.isEmpty()) { 0070 QString icon = QLatin1String("help-hint"); 0071 QString text(i18nc("Notification when an upgrade requires the user to do something", 0072 "Software upgrade notifications are available")); 0073 QStringList actions; 0074 actions << i18nc("Opens a dialog with more details", "Details"); 0075 actions << i18nc("User declines an action", "Ignore"); 0076 actions << i18nc("User indicates he never wants to see this notification again", 0077 "Never show again"); 0078 Event::show(icon, text, actions); 0079 } 0080 } 0081 0082 void HookEvent::run() 0083 { 0084 if (!m_hookGui) { 0085 m_hookGui = new HookGui(this); 0086 } 0087 m_hookGui->showDialog(m_hooks); 0088 Event::run(); 0089 }