1
/***************************************************************************
2
* Copyright © 2009-2012 Jonathan Thomas <echidnaman@kubuntu.org> *
3
* Copyright © 2009 Harald Sitter <apachelogger@ubuntu.com> *
5
* This program is free software; you can redistribute it and/or *
6
* modify it under the terms of the GNU General Public License as *
7
* published by the Free Software Foundation; either version 2 of *
8
* the License or (at your option) version 3 or any later version *
9
* accepted by the membership of KDE e.V. (or its successor approved *
10
* by the membership of KDE e.V.), which shall act as a proxy *
11
* defined in Section 14 of version 3 of the license. *
13
* This program is distributed in the hope that it will be useful, *
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16
* GNU General Public License for more details. *
18
* You should have received a copy of the GNU General Public License *
19
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
20
***************************************************************************/
22
#include "MuonNotifier.h"
25
#include <QtCore/QFile>
26
#include <QtCore/QTimer>
31
#include <KLocalizedString>
32
#include <KPluginFactory>
34
#include <KStandardDirs>
37
#include "distupgradeevent/distupgradeevent.h"
38
#include "UpdateEvent/UpdateEvent.h"
40
#include "configwatcher.h"
42
K_PLUGIN_FACTORY(MuonNotifierFactory,
43
registerPlugin<MuonNotifier>();
45
K_EXPORT_PLUGIN(MuonNotifierFactory("muon-notifier"))
48
MuonNotifier::MuonNotifier(QObject* parent, const QList<QVariant>&)
50
, m_distUpgradeEvent(nullptr)
51
, m_configWatcher(nullptr)
52
, m_checkerProcess(nullptr)
54
KAboutData aboutData("muon-notifier", "muon-notifier",
55
ki18n("Muon Notification Daemon"),
56
"2.1", ki18n("A Notification Daemon for Muon"),
57
KAboutData::License_GPL,
58
ki18n("(C) 2009-2012 Jonathan Thomas, (C) 2009 Harald Sitter"),
59
KLocalizedString(), "http://kubuntu.org");
61
// Lazy init to not cause excessive load when starting kded.
62
// Also wait 2 minutes before actually starting the init as update
63
// notifications are not immediately relevant after login and there is already
64
// enough stuff going on without us. 2 minutes seems like a fair time as
65
// the system should have calmed down by then.
66
QTimer::singleShot(1000*60*2 /* 2 minutes to start */, this, SLOT(init()));
69
MuonNotifier::~MuonNotifier()
71
delete m_checkerProcess;
74
void MuonNotifier::init()
76
m_configWatcher = new ConfigWatcher(this);
78
m_distUpgradeEvent = new DistUpgradeEvent(this, "DistUpgrade");
79
m_updateEvent = new UpdateEvent(this, "Update");
81
if (!m_distUpgradeEvent->isHidden()) {
82
KDirWatch *stampDirWatch = new KDirWatch(this);
83
stampDirWatch->addFile("/var/lib/update-notifier/dpkg-run-stamp");
84
connect(stampDirWatch, SIGNAL(dirty(QString)),
85
this, SLOT(distUpgradeEvent()));
86
connect(m_configWatcher, SIGNAL(reloadConfigCalled()),
87
m_distUpgradeEvent, SLOT(reloadConfig()));
92
if (!m_updateEvent->isHidden()) {
93
KDirWatch *stampDirWatch = new KDirWatch(this);
94
stampDirWatch->addDir("/var/lib/apt/lists/");
95
stampDirWatch->addDir("/var/lib/apt/lists/partial/");
96
stampDirWatch->addFile("/var/lib/update-notifier/updates-available");
97
stampDirWatch->addFile("/var/lib/update-notifier/dpkg-run-stamp");
98
connect(stampDirWatch, SIGNAL(dirty(QString)),
99
this, SLOT(updateEvent()));
100
connect(m_configWatcher, SIGNAL(reloadConfigCalled()),
101
m_updateEvent, SLOT(reloadConfig()));
107
void MuonNotifier::distUpgradeEvent()
109
QString checkerFile = KStandardDirs::locate("data", "muon-notifier/releasechecker");
110
m_checkerProcess = new KProcess(this);
111
connect(m_checkerProcess, SIGNAL(finished(int)),
112
this, SLOT(checkUpgradeFinished(int)));
113
m_checkerProcess->setProgram(QStringList() << "/usr/bin/python3" << checkerFile);
114
m_checkerProcess->start();
117
void MuonNotifier::checkUpgradeFinished(int exitStatus)
120
m_distUpgradeEvent->show();
122
m_checkerProcess->deleteLater();
123
m_checkerProcess = nullptr;
126
void MuonNotifier::updateEvent()
128
if (QFile::exists("/var/lib/update-notifier/updates-available")) {
129
m_updateEvent->getUpdateInfo();