1
/***************************************************************************
2
* Copyright © 2009 Jonathan Thomas <echidnaman@kubuntu.org> *
4
* This program is free software; you can redistribute it and/or *
5
* modify it under the terms of the GNU General Public License as *
6
* published by the Free Software Foundation; either version 2 of *
7
* the License or (at your option) version 3 or any later version *
8
* accepted by the membership of KDE e.V. (or its successor approved *
9
* by the membership of KDE e.V.), which shall act as a proxy *
10
* defined in Section 14 of version 3 of the license. *
12
* This program is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU General Public License for more details. *
17
* You should have received a copy of the GNU General Public License *
18
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
19
***************************************************************************/
21
#include "UpdateEvent.h"
24
#include <QtCore/QProcess>
25
#include <QtCore/QStringBuilder>
29
#include <KToolInvocation>
31
UpdateEvent::UpdateEvent(QObject* parent, const QString &name)
34
, m_checkingUpdates(false)
38
UpdateEvent::~UpdateEvent()
42
void UpdateEvent::show(int updates, int securityUpdates)
44
if (!updates && !securityUpdates) {
55
if (securityUpdates) {
57
securityText = i18ncp("Notification text", "%1 security update is available",
58
"%1 security updates are available",
61
securityText = i18ncp("Notification text", "A security update is available",
62
"Security updates are available",
69
updatesText = i18ncp("Notification text", "%1 software update is available",
70
"%1 software updates are available",
73
updatesText = i18ncp("Notification text", "A software update is available",
74
"Software updates are available",
79
if (securityUpdates && updates) {
80
icon = "kpackagekit-security";
81
tTipIcon = "security-medium";
82
text = securityText % QLatin1Char('\n') % updatesText;
83
} else if (securityUpdates && !updates) {
84
icon = "kpackagekit-security";
85
tTipIcon = "security-medium";
88
icon = "kpackagekit-updates";
89
tTipIcon = "system-software-update";
94
actions << i18nc("Start the update", "Update");
95
actions << i18nc("Button to dismiss this notification once", "Ignore for now");
96
actions << i18nc("Button to make this notification never show up again",
100
Event::show(icon, text, actions, tTipIcon, "system-software-update");
102
Event::update(icon, text, tTipIcon);
106
void UpdateEvent::run()
108
KToolInvocation::kdeinitExec("/usr/bin/muon-updater");
113
void UpdateEvent::reloadConfig()
115
Event::reloadConfig();
120
void UpdateEvent::getUpdateInfo()
122
if (m_checkingUpdates) {
126
m_checkingUpdates = true;
127
m_checkerProcess = new QProcess(this);
128
connect(m_checkerProcess, SIGNAL(finished(int)), this, SLOT(parseUpdateInfo()));
129
m_checkerProcess->start("/usr/lib/update-notifier/apt-check");
132
void UpdateEvent::parseUpdateInfo()
134
// Weirdly enough, apt-check gives output on stderr
135
QByteArray line = m_checkerProcess->readAllStandardError();
136
m_checkerProcess->deleteLater();
137
m_checkerProcess = 0;
138
m_checkingUpdates = false;
140
// Format updates;security
141
int eqpos = line.indexOf(';');
144
QByteArray updatesString = line.left(eqpos);
145
QByteArray securityString = line.right(line.size() - eqpos -1);
147
int numSecurityUpdates = securityString.toInt();
148
int numUpdates = updatesString.toInt() - numSecurityUpdates;
150
show(numUpdates, numSecurityUpdates);
153
// ';' not found, apt-check broke :("