19
19
***************************************************************************/
21
21
#include "kpackagekitd.h"
22
#include "../libkpackagekit/KpkEnum.h"
23
24
#include <KGenericFactory>
24
25
#include <KStandardDirs>
25
26
#include <KConfigGroup>
26
27
#include <QDateTime>
27
28
#include <limits.h>
29
#include <solid/networking.h>
30
#include <solid/acadapter.h>
31
#include <solid/powermanagement.h>
29
33
#define FIVE_MIN 360000
31
35
K_PLUGIN_FACTORY(KPackageKitFactory, registerPlugin<KPackageKitD>(); )
32
36
K_EXPORT_PLUGIN(KPackageKitFactory("kpackagekitd"))
34
KPackageKitD::KPackageKitD(QObject *parent, const QList<QVariant>&)
38
KPackageKitD::KPackageKitD(QObject *parent, const QList<QVariant> &)
35
39
: KDEDModule(parent), m_refreshCacheT(0)
37
41
m_qtimer = new QTimer(this);
38
connect( m_qtimer, SIGNAL( timeout() ), this, SLOT( init() ) ) ;
42
connect(m_qtimer, SIGNAL(timeout()), this, SLOT(init()));
40
44
// Create a new daemon
41
45
m_client = Client::instance();
42
connect(m_client, SIGNAL( transactionListChanged(const QList<PackageKit::Transaction*> &) ), this, SLOT( transactionListChanged(const QList<PackageKit::Transaction*> &) ) );
46
connect(m_client, SIGNAL(transactionListChanged(const QList<PackageKit::Transaction*> &)),
47
this, SLOT(transactionListChanged(const QList<PackageKit::Transaction*> &)));
44
49
// Start after 5 minutes, 360000 msec
45
50
// To keep the startup fast..
56
61
m_qtimer->disconnect();
57
connect( m_qtimer, SIGNAL( timeout() ), this, SLOT( read() ) );
62
connect(m_qtimer, SIGNAL(timeout()), this, SLOT(read()));
60
64
Client::Actions act = m_client->getActions();
62
66
// check to see when the next check update will happen
63
67
// if more that 15 minutes, call show updates
64
68
KConfig config("KPackageKit");
65
KConfigGroup checkUpdateGroup( &config, "CheckUpdate" );
69
KConfigGroup checkUpdateGroup(&config, "CheckUpdate");
66
70
// default to one day, 86400 sec
67
uint interval = checkUpdateGroup.readEntry( "interval", 86400 );
71
uint interval = checkUpdateGroup.readEntry("interval", KpkEnum::TimeIntervalDefault);
70
73
// 1160 -> 15 minutes
71
if ( ( (m_client->getTimeSinceAction(Client::ActionRefreshCache) - interval > 1160) && interval != 0 ) || !( act.contains(Client::ActionRefreshCache) ) )
72
QProcess::execute("kpackagekit", QStringList() << "--smart-update");
75
if ( !act.contains(Client::ActionRefreshCache) ) {
74
if (((m_client->getTimeSinceAction(Client::ActionRefreshCache) - interval > 1160) && interval != 0 )
75
|| !act.contains(Client::ActionRefreshCache)) {
76
// WE ARE NOT GOING TO REFRESH THE CACHE if it not time BUT
77
// WE can SHOW the user his system update :D
78
QProcess::execute("kpackagekit-smart-icon", QStringList() << "--update");
81
if (!act.contains(Client::ActionRefreshCache)) {
76
82
//if the backend does not suport refreshing cache let's don't do nothing
82
88
//check if any changes to the file occour
83
89
//this also prevents from reading when a checkUpdate happens
84
90
m_confWatch = new KDirWatch(this);
85
m_confWatch->addFile( KStandardDirs::locateLocal("config", "KPackageKit") );
86
connect( m_confWatch, SIGNAL( dirty(const QString &) ), this, SLOT( read() ) );
87
connect( m_confWatch, SIGNAL( created(const QString &) ), this, SLOT( read() ) );
88
connect( m_confWatch, SIGNAL( deleted(const QString &) ), this, SLOT( read() ) );
91
m_confWatch->addFile(KStandardDirs::locateLocal("config", "KPackageKit"));
92
connect(m_confWatch, SIGNAL(dirty(const QString &)), this, SLOT(read()));
93
connect(m_confWatch, SIGNAL(created(const QString &)), this, SLOT(read()));
94
connect(m_confWatch, SIGNAL(deleted(const QString &)), this, SLOT(read()));
89
95
m_confWatch->startScan();
94
100
KConfig config("KPackageKit");
95
101
KConfigGroup checkUpdateGroup( &config, "CheckUpdate" );
96
102
// default to one day, 86400 sec
97
int interval = checkUpdateGroup.readEntry( "interval", 86400 );
103
int interval = checkUpdateGroup.readEntry("interval", KpkEnum::TimeIntervalDefault);
98
104
int actRefreshCache = m_client->getTimeSinceAction(Client::ActionRefreshCache);
105
if (interval == KpkEnum::Never) {
101
if ( actRefreshCache >= interval ) {
108
if (actRefreshCache >= interval) {
106
111
//check first to see any overflow...
107
if ( ( interval - actRefreshCache ) > 4294966 )
108
m_qtimer->start( UINT_MAX );
110
m_qtimer->start( ( interval - actRefreshCache ) * 1000 );
112
if ((interval - actRefreshCache) > 4294966) {
113
m_qtimer->start(UINT_MAX);
115
m_qtimer->start((interval - actRefreshCache) * 1000);
114
120
void KPackageKitD::finished(PackageKit::Transaction::ExitStatus status, uint)
116
if ( status == Transaction::Success )
117
QProcess::execute("kpackagekit", QStringList() << "--smart-update");
122
if (status == Transaction::Success) {
123
QProcess::execute("kpackagekit-smart-icon", QStringList() << "--update");
119
125
// try again in 5 minutes
120
126
m_qtimer->start(FIVE_MIN);
130
bool KPackageKitD::systemIsReady()
132
// test whether network is connected
133
if (Solid::Networking::status() != Solid::Networking::Connected &&
134
Solid::Networking::status() != Solid::Networking::Unknown) {
138
// check how applications should behave (e.g. on battery power)
139
if (Solid::PowerManagement::appShouldConserveResources()) {
123
146
void KPackageKitD::checkUpdates()
148
// check whether system is ready for an updates check
149
if (!systemIsReady()) {
150
m_qtimer->start(FIVE_MIN);
125
154
m_refreshCacheT = m_client->refreshCache(true);
126
if ( m_refreshCacheT == 0 )
155
if (m_refreshCacheT == 0) {
127
156
// try again in 5 minutes
128
m_qtimer->start(FIVE_MIN);
130
connect( m_refreshCacheT, SIGNAL( finished(PackageKit::Transaction::ExitStatus, uint)), this, SLOT( finished(PackageKit::Transaction::ExitStatus, uint) ) );
157
m_qtimer->start(FIVE_MIN);
159
connect(m_refreshCacheT, SIGNAL(finished(PackageKit::Transaction::ExitStatus, uint)),
160
this, SLOT(finished(PackageKit::Transaction::ExitStatus, uint)));
133
164
void KPackageKitD::transactionListChanged(const QList<PackageKit::Transaction*> &tids)
136
QProcess::execute("kpackagekit-smart-icon");
167
QProcess::execute("kpackagekit-smart-icon");