KDECore
kauthactionwatcher.cpp
Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 2008 Nicola Gigante <nicola.gigante@gmail.com> 00003 * Copyright (C) 2009 Dario Freddi <drf@kde.org> 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU Lesser General Public License as published by 00007 * the Free Software Foundation; either version 2.1 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public License 00016 * along with this program; if not, write to the 00017 * Free Software Foundation, Inc., 00018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . 00019 */ 00020 00021 #include "kauthactionwatcher.h" 00022 #include "BackendsManager.h" 00023 00024 #include <QHash> 00025 00026 namespace KAuth 00027 { 00028 00029 class ActionWatcher::Private 00030 { 00031 public: 00032 Private(ActionWatcher *parent) : q(parent) {} 00033 00034 ActionWatcher *q; 00035 QString action; 00036 00037 void actionStartedSlot(const QString &action); 00038 void actionPerformedSlot(const QString &action, const ActionReply &reply); 00039 void progressStepSlot(const QString &action, int i); 00040 void progressStepSlot(const QString &action, const QVariantMap &data); 00041 void statusChangedSlot(const QString &action, Action::AuthStatus status); 00042 }; 00043 00044 static QHash<QString, ActionWatcher *> s_watchers; 00045 00046 ActionWatcher::ActionWatcher(const QString &action) 00047 : QObject(0) 00048 , d(new Private(this)) 00049 { 00050 d->action = action; 00051 00052 HelperProxy *helper = BackendsManager::helperProxy(); 00053 00054 connect(helper, SIGNAL(actionStarted(QString)), this, SLOT(actionStartedSlot(QString))); 00055 connect(helper, SIGNAL(actionPerformed(QString, ActionReply)), this, SLOT(actionPerformedSlot(QString, ActionReply))); 00056 connect(helper, SIGNAL(progressStep(QString, int)), this, SLOT(progressStepSlot(QString, int))); 00057 connect(helper, SIGNAL(progressStep(QString, QVariantMap)), this, SLOT(progressStepSlot(QString, QVariantMap))); 00058 connect(BackendsManager::authBackend(), SIGNAL(actionStatusChanged(QString, Action::AuthStatus)), 00059 this, SLOT(statusChangedSlot(QString, Action::AuthStatus))); 00060 } 00061 00062 ActionWatcher::~ActionWatcher() 00063 { 00064 delete d; 00065 } 00066 00067 ActionWatcher *ActionWatcher::watcher(const QString &action) 00068 { 00069 if (!s_watchers.contains(action)) { 00070 s_watchers[action] = new ActionWatcher(action); 00071 } 00072 00073 return s_watchers[action]; 00074 } 00075 00076 QString ActionWatcher::action() const 00077 { 00078 return d->action; 00079 } 00080 00081 void ActionWatcher::Private::actionStartedSlot(const QString &taction) 00082 { 00083 if (taction == action) { 00084 emit q->actionStarted(); 00085 } 00086 } 00087 00088 void ActionWatcher::Private::actionPerformedSlot(const QString &taction, const ActionReply &reply) 00089 { 00090 if (taction == action) { 00091 emit q->actionPerformed(reply); 00092 } 00093 } 00094 00095 void ActionWatcher::Private::progressStepSlot(const QString &taction, int i) 00096 { 00097 if (taction == action) { 00098 emit q->progressStep(i); 00099 } 00100 } 00101 00102 void ActionWatcher::Private::progressStepSlot(const QString &taction, const QVariantMap &data) 00103 { 00104 if (taction == action) { 00105 emit q->progressStep(data); 00106 } 00107 } 00108 00109 void ActionWatcher::Private::statusChangedSlot(const QString &taction, Action::AuthStatus status) 00110 { 00111 if (taction == action) { 00112 emit q->statusChanged(status); 00113 } 00114 } 00115 00116 } // namespace Auth 00117 00118 #include "kauthactionwatcher.moc"
KDE 4.6 API Reference