~ubuntu-branches/ubuntu/vivid/muon/vivid-proposed

« back to all changes in this revision

Viewing changes to .pc/upstream_git/0020-Remove-old-kded-module-from-muon.patch/kded/MuonNotifier.cpp

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2014-04-09 11:38:49 UTC
  • Revision ID: package-import@ubuntu.com-20140409113849-e82p5u55t7ux1jrv
Tags: 2.1.70-0ubuntu4
* Import more upstream commits (no. 14-23) improving l10n and notifications
  LP: #1295423
* Update muon-notifier.install for revised notifier (missed in previous
  uploads).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright © 2009-2012 Jonathan Thomas <echidnaman@kubuntu.org>        *
 
3
 *   Copyright © 2009 Harald Sitter <apachelogger@ubuntu.com>              *
 
4
 *                                                                         *
 
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.                    *
 
12
 *                                                                         *
 
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.                          *
 
17
 *                                                                         *
 
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
 ***************************************************************************/
 
21
 
 
22
#include "MuonNotifier.h"
 
23
 
 
24
// Qt includes
 
25
#include <QtCore/QFile>
 
26
#include <QtCore/QTimer>
 
27
 
 
28
// KDE includes
 
29
#include <KAboutData>
 
30
#include <KDirWatch>
 
31
#include <KLocalizedString>
 
32
#include <KPluginFactory>
 
33
#include <KProcess>
 
34
#include <KStandardDirs>
 
35
 
 
36
// Own includes
 
37
#include "distupgradeevent/distupgradeevent.h"
 
38
#include "UpdateEvent/UpdateEvent.h"
 
39
 
 
40
#include "configwatcher.h"
 
41
 
 
42
K_PLUGIN_FACTORY(MuonNotifierFactory,
 
43
                 registerPlugin<MuonNotifier>();
 
44
                )
 
45
K_EXPORT_PLUGIN(MuonNotifierFactory("muon-notifier"))
 
46
 
 
47
 
 
48
MuonNotifier::MuonNotifier(QObject* parent, const QList<QVariant>&)
 
49
        : KDEDModule(parent)
 
50
        , m_distUpgradeEvent(nullptr)
 
51
        , m_configWatcher(nullptr)
 
52
        , m_checkerProcess(nullptr)
 
53
{
 
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");
 
60
 
 
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()));
 
67
}
 
68
 
 
69
MuonNotifier::~MuonNotifier()
 
70
{
 
71
    delete m_checkerProcess;
 
72
}
 
73
 
 
74
void MuonNotifier::init()
 
75
{
 
76
    m_configWatcher = new ConfigWatcher(this);
 
77
 
 
78
    m_distUpgradeEvent = new DistUpgradeEvent(this, "DistUpgrade");
 
79
    m_updateEvent = new UpdateEvent(this, "Update");
 
80
 
 
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()));
 
88
 
 
89
        distUpgradeEvent();
 
90
    }
 
91
 
 
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()));
 
102
 
 
103
        updateEvent();
 
104
    }
 
105
}
 
106
 
 
107
void MuonNotifier::distUpgradeEvent()
 
108
{
 
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();
 
115
}
 
116
 
 
117
void MuonNotifier::checkUpgradeFinished(int exitStatus)
 
118
{
 
119
    if (exitStatus == 0)
 
120
        m_distUpgradeEvent->show();
 
121
 
 
122
    m_checkerProcess->deleteLater();
 
123
    m_checkerProcess = nullptr;
 
124
}
 
125
 
 
126
void MuonNotifier::updateEvent()
 
127
{
 
128
    if (QFile::exists("/var/lib/update-notifier/updates-available")) {
 
129
        m_updateEvent->getUpdateInfo();
 
130
    }
 
131
}