Changeset View
Changeset View
Standalone View
Standalone View
src/kded/kded_accounts.cpp
- This file was moved from src/daemon/daemon.cpp.
Show All 10 Lines | |||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
12 | * GNU General Public License for more details. * | 12 | * GNU General Public License for more details. * | ||
13 | * * | 13 | * * | ||
14 | * You should have received a copy of the GNU General Public License * | 14 | * You should have received a copy of the GNU General Public License * | ||
15 | * along with this program; if not, write to the Free Software * | 15 | * along with this program; if not, write to the Free Software * | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * | ||
17 | *************************************************************************************/ | 17 | *************************************************************************************/ | ||
18 | 18 | | |||
19 | #include "daemon.h" | 19 | #include "kded_accounts.h" | ||
20 | #include "src/lib/kaccountsdplugin.h" | 20 | #include "src/lib/kaccountsdplugin.h" | ||
21 | #include <core.h> | 21 | #include <core.h> | ||
22 | 22 | | |||
23 | #include <KPluginFactory> | 23 | #include <KPluginFactory> | ||
24 | #include <KPluginMetaData> | 24 | #include <KPluginMetaData> | ||
25 | #include <KPluginLoader> | 25 | #include <KPluginLoader> | ||
26 | 26 | | |||
27 | #include <QDebug> | 27 | #include <QDebug> | ||
28 | #include <QDir> | 28 | #include <QDir> | ||
29 | #include <QPluginLoader> | 29 | #include <QPluginLoader> | ||
30 | #include <QCoreApplication> | 30 | #include <QCoreApplication> | ||
31 | 31 | | |||
32 | #include <Accounts/Manager> | 32 | #include <Accounts/Manager> | ||
33 | #include <Accounts/Service> | 33 | #include <Accounts/Service> | ||
34 | #include <Accounts/AccountService> | 34 | #include <Accounts/AccountService> | ||
35 | 35 | | |||
36 | K_PLUGIN_FACTORY_WITH_JSON(AccountsDaemonFactory, "kded_accounts.json", registerPlugin<AccountsDaemon>();) | 36 | K_PLUGIN_CLASS_WITH_JSON(KDEDAccounts, "kded_accounts.json") | ||
37 | 37 | | |||
38 | AccountsDaemon::AccountsDaemon(QObject *parent, const QList<QVariant>&) | 38 | KDEDAccounts::KDEDAccounts(QObject *parent, const QList<QVariant>&) | ||
39 | : KDEDModule(parent) | 39 | : KDEDModule(parent) | ||
40 | { | 40 | { | ||
41 | 41 | | |||
42 | QMetaObject::invokeMethod(this, "startDaemon", Qt::QueuedConnection); | 42 | QMetaObject::invokeMethod(this, "startDaemon", Qt::QueuedConnection); | ||
43 | connect(KAccounts::accountsManager(), &Accounts::Manager::accountCreated, this, &AccountsDaemon::accountCreated); | 43 | connect(KAccounts::accountsManager(), &Accounts::Manager::accountCreated, this, &KDEDAccounts::accountCreated); | ||
44 | connect(KAccounts::accountsManager(), &Accounts::Manager::accountRemoved, this, &AccountsDaemon::accountRemoved); | 44 | connect(KAccounts::accountsManager(), &Accounts::Manager::accountRemoved, this, &KDEDAccounts::accountRemoved); | ||
45 | 45 | | |||
46 | const QVector<KPluginMetaData> data = KPluginLoader::findPlugins(QStringLiteral("kaccounts/daemonplugins")); | 46 | const QVector<KPluginMetaData> data = KPluginLoader::findPlugins(QStringLiteral("kaccounts/daemonplugins")); | ||
47 | for (const KPluginMetaData& metadata : data) { | 47 | for (const KPluginMetaData& metadata : data) { | ||
48 | 48 | | |||
49 | if (!metadata.isValid()) { | 49 | if (!metadata.isValid()) { | ||
50 | qDebug() << "Invalid metadata" << metadata.name(); | 50 | qDebug() << "Invalid metadata" << metadata.name(); | ||
51 | continue; | 51 | continue; | ||
52 | } | 52 | } | ||
Show All 11 Lines | 63 | if (!plugin) { | |||
64 | qDebug() << "Error loading plugin" << metadata.name() << loader.errorString(); | 64 | qDebug() << "Error loading plugin" << metadata.name() << loader.errorString(); | ||
65 | continue; | 65 | continue; | ||
66 | } | 66 | } | ||
67 | 67 | | |||
68 | m_plugins << plugin; | 68 | m_plugins << plugin; | ||
69 | } | 69 | } | ||
70 | } | 70 | } | ||
71 | 71 | | |||
72 | AccountsDaemon::~AccountsDaemon() | 72 | KDEDAccounts::~KDEDAccounts() | ||
73 | { | 73 | { | ||
74 | qDeleteAll(m_plugins); | 74 | qDeleteAll(m_plugins); | ||
75 | } | 75 | } | ||
76 | 76 | | |||
77 | void AccountsDaemon::startDaemon() | 77 | void KDEDAccounts::startDaemon() | ||
78 | { | 78 | { | ||
79 | qDebug(); | 79 | qDebug(); | ||
80 | const Accounts::AccountIdList accList = KAccounts::accountsManager()->accountList(); | 80 | const Accounts::AccountIdList accList = KAccounts::accountsManager()->accountList(); | ||
81 | for (const Accounts::AccountId &id : accList) { | 81 | for (const Accounts::AccountId &id : accList) { | ||
82 | monitorAccount(id); | 82 | monitorAccount(id); | ||
83 | } | 83 | } | ||
84 | } | 84 | } | ||
85 | 85 | | |||
86 | void AccountsDaemon::monitorAccount(const Accounts::AccountId id) | 86 | void KDEDAccounts::monitorAccount(const Accounts::AccountId id) | ||
87 | { | 87 | { | ||
88 | qDebug() << id; | 88 | qDebug() << id; | ||
89 | Accounts::Account *acc = KAccounts::accountsManager()->account(id); | 89 | Accounts::Account *acc = KAccounts::accountsManager()->account(id); | ||
90 | const Accounts::ServiceList services = acc->services(); | 90 | const Accounts::ServiceList services = acc->services(); | ||
91 | for (const Accounts::Service &service : services) { | 91 | for (const Accounts::Service &service : services) { | ||
92 | acc->selectService(service); | 92 | acc->selectService(service); | ||
93 | } | 93 | } | ||
94 | acc->selectService(); | 94 | acc->selectService(); | ||
95 | 95 | | |||
96 | connect(acc, &Accounts::Account::enabledChanged, this, &AccountsDaemon::enabledChanged); | 96 | connect(acc, &Accounts::Account::enabledChanged, this, &KDEDAccounts::enabledChanged); | ||
97 | } | 97 | } | ||
98 | 98 | | |||
99 | void AccountsDaemon::accountCreated(const Accounts::AccountId id) | 99 | void KDEDAccounts::accountCreated(const Accounts::AccountId id) | ||
100 | { | 100 | { | ||
101 | qDebug() << id; | 101 | qDebug() << id; | ||
102 | monitorAccount(id); | 102 | monitorAccount(id); | ||
103 | 103 | | |||
104 | const Accounts::Account *acc = KAccounts::accountsManager()->account(id); | 104 | const Accounts::Account *acc = KAccounts::accountsManager()->account(id); | ||
105 | const Accounts::ServiceList services = acc->enabledServices(); | 105 | const Accounts::ServiceList services = acc->enabledServices(); | ||
106 | 106 | | |||
107 | for (KAccountsDPlugin *plugin : qAsConst(m_plugins)) { | 107 | for (KAccountsDPlugin *plugin : qAsConst(m_plugins)) { | ||
108 | plugin->onAccountCreated(id, services); | 108 | plugin->onAccountCreated(id, services); | ||
109 | } | 109 | } | ||
110 | } | 110 | } | ||
111 | 111 | | |||
112 | void AccountsDaemon::accountRemoved(const Accounts::AccountId id) | 112 | void KDEDAccounts::accountRemoved(const Accounts::AccountId id) | ||
113 | { | 113 | { | ||
114 | qDebug() << id; | 114 | qDebug() << id; | ||
115 | 115 | | |||
116 | for (KAccountsDPlugin *plugin : qAsConst(m_plugins)) { | 116 | for (KAccountsDPlugin *plugin : qAsConst(m_plugins)) { | ||
117 | plugin->onAccountRemoved(id); | 117 | plugin->onAccountRemoved(id); | ||
118 | } | 118 | } | ||
119 | } | 119 | } | ||
120 | 120 | | |||
121 | void AccountsDaemon::enabledChanged(const QString &serviceName, bool enabled) | 121 | void KDEDAccounts::enabledChanged(const QString &serviceName, bool enabled) | ||
122 | { | 122 | { | ||
123 | qDebug(); | 123 | qDebug(); | ||
124 | if (serviceName.isEmpty()) { | 124 | if (serviceName.isEmpty()) { | ||
125 | qDebug() << "ServiceName is Empty"; | 125 | qDebug() << "ServiceName is Empty"; | ||
126 | return; | 126 | return; | ||
127 | } | 127 | } | ||
128 | 128 | | |||
129 | const Accounts::AccountId accId = qobject_cast<Accounts::Account*>(sender())->id(); | 129 | const Accounts::AccountId accId = qobject_cast<Accounts::Account*>(sender())->id(); | ||
130 | 130 | | |||
131 | const Accounts::Service service = KAccounts::accountsManager()->service(serviceName); | 131 | const Accounts::Service service = KAccounts::accountsManager()->service(serviceName); | ||
132 | if (!enabled) { | 132 | if (!enabled) { | ||
133 | for (KAccountsDPlugin *plugin : qAsConst(m_plugins)) { | 133 | for (KAccountsDPlugin *plugin : qAsConst(m_plugins)) { | ||
134 | plugin->onServiceDisabled(accId, service); | 134 | plugin->onServiceDisabled(accId, service); | ||
135 | } | 135 | } | ||
136 | } else { | 136 | } else { | ||
137 | for (KAccountsDPlugin *plugin : qAsConst(m_plugins)) { | 137 | for (KAccountsDPlugin *plugin : qAsConst(m_plugins)) { | ||
138 | plugin->onServiceEnabled(accId, service); | 138 | plugin->onServiceEnabled(accId, service); | ||
139 | } | 139 | } | ||
140 | } | 140 | } | ||
141 | } | 141 | } | ||
142 | 142 | | |||
143 | #include "daemon.moc" | 143 | #include "kded_accounts.moc" |