1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/*
* Copyright (C) 2007 Adrien Bustany <madcat@mymadcat.com>
*
* Licensed under the GNU General Public License Version 2
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 See MA 02111-1307, USA.
*
*/
#include "Daemon.h"
#include "constants.h"
#include "PolkitClient.h"
#include "Actions.h"
#include "Groups.h"
using namespace PackageKit;
Daemon::Daemon(QObject *parent) : QObject(parent) {
proxy = new CentralProxy(PK_NAME, PK_PATH, QDBusConnection::systemBus(), this);
connect(proxy, SIGNAL(NetworkStateChanged(const QString&)), this, SLOT(NetworkStateChanged_cb(const QString&)));
connect(proxy, SIGNAL(Locked(bool)), this, SIGNAL(Locked(bool)));
connect(proxy, SIGNAL(TransactionListChanged(const QStringList&)), this, SIGNAL(TransactionListChanged(const QStringList&)));
connect(proxy, SIGNAL(RestartSchedule()), this, SIGNAL(RestartSchedule()));
connect(proxy, SIGNAL(RepoListChanged()), this, SIGNAL(RepoListChanged()));
polkit = new PolkitClient(this);
}
Daemon::~Daemon() {
}
unsigned int Daemon::getActions() {
QStringList actions = QString(proxy->GetActions()).split(";");
unsigned int ret = 0;
for(int i = 0 ; i < actions.size() ; ++i) {
ret |= EnumFromString<Actions>(actions.at(i));
}
return ret;
}
void Daemon::getBackendDetails(QString &name, QString &author) {
name = proxy->GetBackendDetail(author);
}
QStringList Daemon::getFilters() {
return QString(proxy->GetFilters()).split(";");
}
QStringList Daemon::getGroups() {
return QString(proxy->GetGroups()).split(";");
}
QStringList Daemon::getTransactionList() {
return proxy->GetTransactionList();
}
uint Daemon::getTimeSinceAction(Role::Value role) {
return proxy->GetTimeSinceAction(EnumToString<Role>(role));
}
// 1 = online ; 0 = offline
bool Daemon::getNetworkState() {
QString state = proxy->GetNetworkState();
return (state == "online");
}
bool Daemon::setProxy(const QString &http_proxy, const QString &ftp_proxy) {
// hopefully do the operation first time
if ( proxy->SetProxy(http_proxy, ftp_proxy).isValid() )
return true;
else {
// ok no lucky...
if ( polkit->getAuth(AUTH_SETPROXY) )
return proxy->SetProxy(http_proxy, ftp_proxy).isValid();
else
return false;
}
}
void Daemon::suggestQuit() {
proxy->SuggestDaemonQuit();
}
void Daemon::stateHasChanged(const QString &reason) {
proxy->StateHasChanged(reason);
}
Transaction* Daemon::newTransaction() {
return new Transaction(this);
}
QString Daemon::getTid() {
return proxy->GetTid();
}
void Daemon::NetworkStateChanged_cb(const QString &status) {
emit NetworkStateChanged((status == "online"));
}
|