[SCM] ktp-text-ui packaging branch, master, updated. debian/15.12.1-1-1918-gdf4b0ec
Maximiliano Curia
maxy at moszumanska.debian.org
Sat May 28 00:24:44 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-text-ui.git;a=commitdiff;h=c9d43f3
The following commit has been merged in the master branch:
commit c9d43f3fbd4e17405cb2d6dee487f5f9e048bdf6
Author: Marcin Ziemiński <zieminn at gmail.com>
Date: Wed Aug 6 13:23:17 2014 +0200
Adapted OTR settings - OTR policy settings and private key generation
---
app/chat-window.cpp | 76 +++++++++++++++-----
app/chat-window.h | 6 +-
config/otr-config.cpp | 64 ++++++++++++++++-
config/otr-config.h | 10 ++-
lib/CMakeLists.txt | 2 +
lib/chat-widget.cpp | 11 ++-
lib/chat-widget.h | 3 +
lib/keygendialog.ui | 41 +++++++++++
lib/otr-constants.h | 1 +
lib/proxy-service.cpp | 193 ++++++++++++++++++++++++++++++++++++++++++++++++++
lib/proxy-service.h | 65 +++++++++++++++++
11 files changed, 452 insertions(+), 20 deletions(-)
diff --git a/app/chat-window.cpp b/app/chat-window.cpp
index 41c38d5..142a505 100644
--- a/app/chat-window.cpp
+++ b/app/chat-window.cpp
@@ -84,7 +84,12 @@ ChatWindow::ChatWindow()
: m_sendMessage(0),
m_tabWidget(0),
m_keyboardLayoutInterface(0),
- otrActionMenu(0)
+ m_otrActionMenu(0),
+ m_proxyService(
+ new ProxyService(QDBusConnection::sessionBus(),
+ KTP_PROXY_BUS_NAME,
+ KTP_PROXY_SERVICE_OBJECT_PATH,
+ this))
{
//This effectively constructs the s_krfbAvailableChecker object the first
//time that this code is executed. This is to start the d-bus query early, so
@@ -735,7 +740,13 @@ void ChatWindow::showSettingsDialog()
dialog->addModule(QLatin1String("kcm_ktp_chat_behavior"));
dialog->addModule(QLatin1String("kcm_ktp_chat_messages"));
- dialog->addModule(QLatin1String("kcm_ktp_chat_otr"));
+
+ KPageWidgetItem *otrConfigPage = dialog->addModule(QLatin1String("kcm_ktp_chat_otr"));
+ proxy = qobject_cast<KCModuleProxy*>(otrConfigPage->widget());
+ Q_ASSERT(proxy);
+ QVariant value;
+ value.setValue(m_proxyService);
+ proxy->realModule()->setProperty("proxyService", value);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->show();
@@ -893,8 +904,8 @@ void ChatWindow::setupCustomActions()
void ChatWindow::setupOTR()
{
- otrActionMenu = new KActionMenu(KIcon(QLatin1String("object-unlocked")), i18n("&OTR"), this);
- otrActionMenu->setDelayed(false);
+ m_otrActionMenu = new KActionMenu(KIcon(QLatin1String("object-unlocked")), i18n("&OTR"), this);
+ m_otrActionMenu->setDelayed(false);
KAction *startRestartOtrAction = new KAction(KIcon(QLatin1String("object-locked")), i18n("&Start session"), this);
startRestartOtrAction->setEnabled(false);
@@ -908,15 +919,21 @@ void ChatWindow::setupOTR()
authenticateBuddyAction->setEnabled(false);
connect(authenticateBuddyAction, SIGNAL(triggered()), this, SLOT(onAuthenticateBuddyTriggered()));
- otrActionMenu->addAction(startRestartOtrAction);
- otrActionMenu->addAction(stopOtrAction);
- otrActionMenu->addAction(authenticateBuddyAction);
- otrActionMenu->setEnabled(false);
+ m_otrActionMenu->addAction(startRestartOtrAction);
+ m_otrActionMenu->addAction(stopOtrAction);
+ m_otrActionMenu->addAction(authenticateBuddyAction);
+ m_otrActionMenu->setEnabled(false);
actionCollection()->addAction(QLatin1String("start-restart-otr"), startRestartOtrAction);
actionCollection()->addAction(QLatin1String("stop-otr"), stopOtrAction);
actionCollection()->addAction(QLatin1String("authenticate-otr"), authenticateBuddyAction);
- actionCollection()->addAction(QLatin1String("otr-actions"), otrActionMenu);
+ actionCollection()->addAction(QLatin1String("otr-actions"), m_otrActionMenu);
+
+ // private key generation
+ connect(m_proxyService, SIGNAL(keyGenerationStarted(Tp::AccountPtr)),
+ SLOT(onKeyGenerationStarted(Tp::AccountPtr)));
+ connect(m_proxyService, SIGNAL(keyGenerationFinished(Tp::AccountPtr, bool)),
+ SLOT(onKeyGenerationFinished(Tp::AccountPtr, bool)));
}
void ChatWindow::onOtrStatusChanged(OtrStatus status)
@@ -932,8 +949,8 @@ void ChatWindow::onOtrStatusChanged(OtrStatus status)
}
if(!status) {
- otrActionMenu->setEnabled(false);
- otrActionMenu->menu()->setIcon(KIcon(QLatin1String("object-unlocked")));
+ m_otrActionMenu->setEnabled(false);
+ m_otrActionMenu->menu()->setIcon(KIcon(QLatin1String("object-unlocked")));
return;
}
@@ -941,12 +958,13 @@ void ChatWindow::onOtrStatusChanged(OtrStatus status)
QAction* stopAction = actionCollection()->action(QLatin1String("stop-otr"));
QAction* authenticateBuddyAction = actionCollection()->action(QLatin1String("authenticate-otr"));
- otrActionMenu->setEnabled(true);
+ m_otrActionMenu->setEnabled(true);
switch(status.otrTrustLevel()) {
case Tp::OTRTrustLevelNotPrivate:
- otrActionMenu->setIcon(KIcon(QLatin1String("object-unlocked")));
+ m_otrActionMenu->setIcon(KIcon(QLatin1String("object-unlocked")));
+ m_otrActionMenu->setToolTip(i18n("Not private"));
srAction->setEnabled(true);
srAction->setText(i18n("&Start session"));
stopAction->setEnabled(false);
@@ -954,7 +972,8 @@ void ChatWindow::onOtrStatusChanged(OtrStatus status)
return;
case Tp::OTRTrustLevelUnverified:
- otrActionMenu->setIcon(KIcon(QLatin1String("object-locked-unverified")));
+ m_otrActionMenu->setIcon(KIcon(QLatin1String("object-locked-unverified")));
+ m_otrActionMenu->setToolTip(i18n("Unverified"));
srAction->setEnabled(true);
srAction->setText(i18n("&Restart session"));
stopAction->setEnabled(true);
@@ -962,7 +981,8 @@ void ChatWindow::onOtrStatusChanged(OtrStatus status)
return;
case Tp::OTRTrustLevelPrivate:
- otrActionMenu->setIcon(KIcon(QLatin1String("object-locked-verified")));
+ m_otrActionMenu->setIcon(KIcon(QLatin1String("object-locked-verified")));
+ m_otrActionMenu->setToolTip(i18n("Private"));
srAction->setEnabled(true);
srAction->setText(i18n("&Restart session"));
stopAction->setEnabled(true);
@@ -970,7 +990,8 @@ void ChatWindow::onOtrStatusChanged(OtrStatus status)
return;
case Tp::OTRTrustLevelFinished:
- otrActionMenu->setIcon(KIcon(QLatin1String("object-locked-finished")));
+ m_otrActionMenu->setIcon(KIcon(QLatin1String("object-locked-finished")));
+ m_otrActionMenu->setToolTip(i18n("Finished"));
srAction->setEnabled(true);
srAction->setText(i18n("&Restart session"));
stopAction->setEnabled(true);
@@ -1001,6 +1022,29 @@ void ChatWindow::onAuthenticateBuddyTriggered()
chat->authenticateBuddy();
}
+void ChatWindow::onKeyGenerationStarted(Tp::AccountPtr account)
+{
+ // block user text input for these tabs
+ QList<ChatTab*> allTabs = tabs();
+ Q_FOREACH(ChatTab *ct, allTabs) {
+ if(ct->account()->objectPath() == account->objectPath()) {
+ ct->blockTextInput(true);
+ }
+ }
+}
+
+void ChatWindow::onKeyGenerationFinished(Tp::AccountPtr account, bool error)
+{
+ Q_UNUSED(error);
+ // unblock user text input for these tabs
+ QList<ChatTab*> allTabs = tabs();
+ Q_FOREACH(ChatTab *ct, allTabs) {
+ if(ct->account()->objectPath() == account->objectPath()) {
+ ct->blockTextInput(false);
+ }
+ }
+}
+
void ChatWindow::setCollaborateDocumentEnabled(bool enable)
{
QAction* action = actionCollection()->action(QLatin1String("collaborate-document"));
diff --git a/app/chat-window.h b/app/chat-window.h
index b1d832a..8d73b3d 100644
--- a/app/chat-window.h
+++ b/app/chat-window.h
@@ -23,6 +23,7 @@
#define CHATWINDOW_H
#include "chat-widget.h"
+#include "proxy-service.h"
#include <KXmlGuiWindow>
#include <KTabWidget>
@@ -124,6 +125,8 @@ private Q_SLOTS:
void onStartRestartOtrTriggered();
void onStopOtrTriggered();
void onAuthenticateBuddyTriggered();
+ void onKeyGenerationStarted(Tp::AccountPtr);
+ void onKeyGenerationFinished(Tp::AccountPtr, bool error);
protected Q_SLOTS:
void showSettingsDialog();
@@ -218,7 +221,8 @@ private:
Sonnet::DictionaryComboBox *m_spellDictCombo;
QLabel *m_accountIconLabel;
qreal m_zoomFactor;
- KActionMenu *otrActionMenu;
+ KActionMenu *m_otrActionMenu;
+ ProxyService *m_proxyService;
};
#endif // CHATWINDOW_H
diff --git a/config/otr-config.cpp b/config/otr-config.cpp
index 63a9967..aa3080b 100644
--- a/config/otr-config.cpp
+++ b/config/otr-config.cpp
@@ -28,6 +28,7 @@
#include <QtDBus/QDBusConnection>
#include <TelepathyQt/AccountSet>
+#include <TelepathyQt/PendingVariant>
K_PLUGIN_FACTORY(KCMTelepathyChatOtrConfigFactory, registerPlugin<OTRConfig>();)
K_EXPORT_PLUGIN(KCMTelepathyChatOtrConfigFactory("ktp_chat_otr", "kcm_ktp_chat_otr"))
@@ -35,7 +36,8 @@ K_EXPORT_PLUGIN(KCMTelepathyChatOtrConfigFactory("ktp_chat_otr", "kcm_ktp_chat_o
OTRConfig::OTRConfig(QWidget *parent, const QVariantList& args)
: KCModule(KCMTelepathyChatOtrConfigFactory::componentData(), parent, args),
ui(new Ui::OTRConfigUi()),
- am(Tp::AccountManager::create(QDBusConnection::sessionBus()))
+ am(Tp::AccountManager::create(QDBusConnection::sessionBus())),
+ ps(NULL)
{
kDebug();
@@ -57,25 +59,44 @@ OTRConfig::~OTRConfig()
delete ui;
}
+ProxyService* OTRConfig::proxyService()
+{
+ return ps;
+}
+
+void OTRConfig::setProxyService(ProxyService *proxyService)
+{
+ ps = proxyService;
+ connect(ps, SIGNAL(keyGenerationFinished(Tp::AccountPtr, bool)), SLOT(onKeyGenerationFinished()));
+}
+
void OTRConfig::load()
{
+ Q_ASSERT(ps != NULL);
kDebug();
accounts = am->validAccounts()->accounts();
QStringList items;
Q_FOREACH(const Tp::AccountPtr ac, accounts) {
items << ac->normalizedName();
}
+ ui->cbAccounts->clear();
ui->cbAccounts->addItems(items);
if(!items.isEmpty()) {
ui->cbAccounts->setEnabled(true);
ui->btGenFingerprint->setEnabled(true);
+ ui->tlFingerprint->setEnabled(true);
+ onAccountChosen(0);
}
+
+ updatePolicy();
}
void OTRConfig::save()
{
kDebug();
+ connect(ps->setOTRPolicy(static_cast<uint>(policy)), SIGNAL(finished(Tp::PendingOperation*)),
+ SLOT(onPolicySet(Tp::PendingOperation*)));
}
void OTRConfig::changeEvent(QEvent* e)
@@ -100,10 +121,51 @@ void OTRConfig::onRadioSelected(int id)
void OTRConfig::onGenerateClicked()
{
kDebug();
+ const int index = ui->cbAccounts->currentIndex();
+ ps->generatePrivateKey(QDBusObjectPath(accounts.at(index)->objectPath()));
}
void OTRConfig::onAccountChosen(int id)
{
kDebug();
+ const QString fp = ps->fingerprintForAccount(QDBusObjectPath(accounts.at(id)->objectPath()));
+ if(fp.isEmpty()) {
+ ui->tlFingerprint->setText(i18n("No fingerprint"));
+ } else {
+ ui->tlFingerprint->setText(fp);
+ }
+}
+
+void OTRConfig::updatePolicy()
+{
+ connect(ps->getOTRPolicy(), SIGNAL(finished(Tp::PendingOperation*)), SLOT(onPolicyGet(Tp::PendingOperation*)));
}
+void OTRConfig::onPolicyGet(Tp::PendingOperation *getOp)
+{
+ if(getOp->isError()) {
+ kWarning() << "Could not get OTR policy: " << getOp->errorMessage();
+ } else {
+ Tp::PendingVariant *pv = dynamic_cast<Tp::PendingVariant*>(getOp);
+ const uint id = pv->result().toUInt(NULL);
+ Q_FOREACH(QAbstractButton *bt, ui->policyGroupButtons->buttons()) {
+ bt->setChecked(false);
+ }
+ ui->policyGroupButtons->button(id)->setChecked(true);
+ policy = static_cast<Tp::OTRPolicy>(id);
+ }
+}
+
+void OTRConfig::onPolicySet(Tp::PendingOperation *setOp)
+{
+ if(setOp->isError()) {
+ kWarning() << "OTR policy set error: " << setOp->errorMessage();
+ } else {
+ updatePolicy();
+ }
+}
+
+void OTRConfig::onKeyGenerationFinished()
+{
+ onAccountChosen(ui->cbAccounts->currentIndex());
+}
diff --git a/config/otr-config.h b/config/otr-config.h
index b2c92b4..2d30139 100644
--- a/config/otr-config.h
+++ b/config/otr-config.h
@@ -22,6 +22,7 @@
#define OTR_CONFIG_H
#include "otr-constants.h"
+#include "proxy-service.h"
#include <KCModule>
#include <QList>
@@ -35,6 +36,7 @@ class OTRConfigUi;
class OTRConfig : public KCModule
{
Q_OBJECT
+ Q_PROPERTY(ProxyService* proxyService READ proxyService WRITE setProxyService)
public:
explicit OTRConfig(QWidget *parent = 0, const QVariantList &args = QVariantList());
@@ -46,18 +48,24 @@ protected:
public Q_SLOTS:
virtual void load();
virtual void save();
+ ProxyService* proxyService();
+ void setProxyService(ProxyService *ps);
private Q_SLOTS:
void onRadioSelected(int id);
void onGenerateClicked();
void onAccountChosen(int id);
+ void updatePolicy();
+ void onPolicyGet(Tp::PendingOperation *getOp);
+ void onPolicySet(Tp::PendingOperation *setOp);
+ void onKeyGenerationFinished();
private:
Ui::OTRConfigUi *ui;
Tp::AccountManagerPtr am;
QList<Tp::AccountPtr> accounts;
- QMap<int, QString> fpCache;
Tp::OTRPolicy policy;
+ ProxyService *ps;
};
#endif // OTR_CONFIG_H
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 124dbf0..4c541af 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -21,11 +21,13 @@ set(ktpchat_SRCS
channel-adapter.cpp
otr-channel-proxy.cpp
proxy-service-interface.cpp
+ proxy-service.cpp
otr-utils.cpp
)
set(ktpchat_UI
chat-widget.ui
+ keygendialog.ui
)
kde4_add_ui_files(ktpchat_SRCS ${ktpchat_UI})
diff --git a/lib/chat-widget.cpp b/lib/chat-widget.cpp
index a6b1d03..7a57dd4 100644
--- a/lib/chat-widget.cpp
+++ b/lib/chat-widget.cpp
@@ -259,7 +259,7 @@ ChatWidget::ChatWidget(const Tp::TextChannelPtr & channel, const Tp::AccountPtr
d->notifyFilter = new NotifyFilter(this);
- // setup new otr channel along with connecting to signals
+ // setup new otr channel and connect to signals
if(d->channel.isOTRsuppored()) {
setupOTR();
}
@@ -660,6 +660,15 @@ OtrStatus ChatWidget::otrStatus() const
}
}
+void ChatWidget::blockTextInput(bool block)
+{
+ if(block) {
+ d->ui.sendMessageBox->setDisabled(true);
+ } else {
+ d->ui.sendMessageBox->setEnabled(true);
+ }
+}
+
void ChatWidget::startOtrSession()
{
if(!d->channel.isOTRsuppored()) return;
diff --git a/lib/chat-widget.h b/lib/chat-widget.h
index b61d32c..e9a9b8a 100644
--- a/lib/chat-widget.h
+++ b/lib/chat-widget.h
@@ -123,6 +123,9 @@ public:
/** Returns OtrStatus linked to the channel represented by this tab */
OtrStatus otrStatus() const;
+ /** If block then send message box is disabled */
+ void blockTextInput(bool block);
+
public Q_SLOTS:
/** toggle the search bar visibility */
void toggleSearchBar() const;
diff --git a/lib/keygendialog.ui b/lib/keygendialog.ui
new file mode 100644
index 0000000..7a359ff
--- /dev/null
+++ b/lib/keygendialog.ui
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>KeyGenDialog</class>
+ <widget class="QWidget" name="KeyGenDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>404</width>
+ <height>98</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Please Wait</string>
+ </property>
+ <layout class="QGridLayout">
+ <property name="leftMargin">
+ <number>10</number>
+ </property>
+ <property name="rightMargin">
+ <number>10</number>
+ </property>
+ <item row="0" column="0">
+ <widget class="QLabel" name="keyIcon">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLabel" name="lbText">
+ <property name="text">
+ <string>Please wait while generating the private key</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/lib/otr-constants.h b/lib/otr-constants.h
index 26d86ab..8e7db3a 100644
--- a/lib/otr-constants.h
+++ b/lib/otr-constants.h
@@ -111,6 +111,7 @@ enum OTRMessageEvent
#define KTP_IFACE_PROXY_SERVICE (QLatin1String("org.kde.TelepathyProxy.ProxyService"))
#define KTP_PROXY_CHANNEL_OBJECT_PATH_PREFIX (QLatin1String("/org/freedesktop/TelepathyProxy/OtrChannelProxy/"))
+#define KTP_PROXY_SERVICE_OBJECT_PATH (QLatin1String("/org/freedesktop/TelepathyProxy/ProxyService"))
#define KTP_PROXY_BUS_NAME (QLatin1String("org.freedesktop.Telepathy.Client.KTp.Proxy"))
diff --git a/lib/proxy-service.cpp b/lib/proxy-service.cpp
new file mode 100644
index 0000000..bedf20b
--- /dev/null
+++ b/lib/proxy-service.cpp
@@ -0,0 +1,193 @@
+/*
+ Copyright (C) 2014 Marcin Ziemiński <zieminn at gmail.com>
+
+ 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 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "proxy-service.h"
+#include "ui_keygendialog.h"
+
+#include "proxy-service-interface.h"
+
+#include <QMap>
+#include <QScopedPointer>
+#include <QCloseEvent>
+#include <KDebug>
+#include <KDialog>
+#include <KLocale>
+
+class KeyGenDialog : public KDialog
+{
+ public:
+ KeyGenDialog(const QString &accountName, QWidget *parent = 0)
+ : KDialog(parent),
+ blocked(true),
+ accountName(accountName)
+ {
+ QWidget *widget = new QWidget(this);
+ ui.setupUi(widget);
+ ui.lbText->setText(i18n("Generating the private key for %1", accountName));
+ setMainWidget(widget);
+ this->setCaption(i18n("Please wait"));
+ this->setButtons(KDialog::Ok);
+ this->enableButton(KDialog::Ok, false);
+ ui.keyIcon->setPixmap(KIcon(QLatin1String("dialog-password")).pixmap( 48, 48 ));
+ }
+ ~KeyGenDialog()
+ {
+ kDebug() << "Destructing";
+ }
+
+ void block()
+ {
+ blocked = true;
+ }
+
+ void unblock()
+ {
+ blocked = false;
+ }
+
+ void closeEvent(QCloseEvent *e)
+ {
+ if(blocked) {
+ e->ignore();
+ } else {
+ e->accept();
+ }
+ }
+
+ void setFinished(bool error)
+ {
+ if(error) {
+ ui.lbText->setText(i18n("Could not generate a private key for %1", accountName));
+ } else {
+ ui.lbText->setText(i18n("Finished generating the private key for %1", accountName));
+ }
+ this->enableButton(KDialog::Ok, true);
+ }
+
+ private:
+ bool blocked;
+ const QString accountName;
+ Ui::KeyGenDialog ui;
+
+};
+
+class ProxyService::Private
+{
+ public:
+ Private(Tp::Client::ProxyServiceInterface *psi, const QDBusConnection &dbusConnection, QWidget *parent)
+ : psi(psi),
+ am(Tp::AccountManager::create(dbusConnection)),
+ parent(parent)
+ {
+ }
+
+ QScopedPointer<Tp::Client::ProxyServiceInterface> psi;
+ Tp::AccountManagerPtr am;
+ QWidget *parent;
+ QMap<QString, KeyGenDialog*> dialogs;
+};
+
+ProxyService::ProxyService(
+ const QDBusConnection &dbusConnection,
+ const QString& busName,
+ const QString& objectPath,
+ QWidget* parent)
+ : QObject(parent),
+ d(new Private(new Tp::Client::ProxyServiceInterface(dbusConnection, busName, objectPath), dbusConnection, parent))
+{
+ connect(d->psi.data(), SIGNAL(ProxyConnected(const QDBusObjectPath&)), SIGNAL(proxyConnected(const QDBusObjectPath&)));
+ connect(d->psi.data(), SIGNAL(KeyGenerationStarted(const QDBusObjectPath&)),
+ SLOT(onKeyGenerationStarted(const QDBusObjectPath&)));
+ connect(d->psi.data(), SIGNAL(KeyGenerationFinished(const QDBusObjectPath&, bool)),
+ SLOT(onKeyGenerationFinished(const QDBusObjectPath&, bool)));
+}
+
+ProxyService::~ProxyService()
+{
+ delete d;
+}
+
+bool ProxyService::generatePrivateKey(const QDBusObjectPath& account)
+{
+ QDBusPendingReply<> rep = d->psi->GeneratePrivateKey(account);
+ rep.waitForFinished();
+ return !rep.isError();
+}
+
+QString ProxyService::fingerprintForAccount(const QDBusObjectPath& account)
+{
+ QDBusPendingReply<QString> rep = d->psi->GetFingerprintForAccount(account);
+ rep.waitForFinished();
+ if(rep.isValid()) {
+ return rep.value();
+ } else {
+ kWarning() << "Could not get fingerprint of account: " << account.path() <<
+ " due to: " << rep.error().message();
+ return QLatin1String("");
+ }
+}
+
+Tp::PendingVariant* ProxyService::getOTRPolicy() const
+{
+ return d->psi->requestPropertyPolicySettings();
+}
+
+Tp::PendingOperation* ProxyService::setOTRPolicy(uint policy)
+{
+ return d->psi->setPropertyPolicySettings(policy);
+}
+
+void ProxyService::onKeyGenerationStarted(const QDBusObjectPath &accountPath)
+{
+ kDebug();
+ KeyGenDialog *dialog = new KeyGenDialog(
+ d->am->accountForObjectPath(accountPath.path())->normalizedName(),
+ d->parent);
+
+ d->dialogs.insert(accountPath.path(), dialog);
+ dialog->block();
+ dialog->show();
+
+ Q_EMIT keyGenerationStarted(d->am->accountForObjectPath(accountPath.path()));
+}
+
+void ProxyService::onKeyGenerationFinished(const QDBusObjectPath &accountPath, bool error)
+{
+ QMap<QString, KeyGenDialog*>::iterator it = d->dialogs.find(accountPath.path());
+ if(it == d->dialogs.end()) {
+ return;
+ }
+ it.value()->setFinished(error);
+ it.value()->unblock();
+ connect(it.value(), SIGNAL(closeClicked()), SLOT(onDialogClosed()));
+ connect(it.value(), SIGNAL(okClicked()), SLOT(onDialogClosed()));
+
+ Q_EMIT keyGenerationFinished(d->am->accountForObjectPath(accountPath.path()), error);
+}
+
+void ProxyService::onDialogClosed()
+{
+ KeyGenDialog *dialog = dynamic_cast<KeyGenDialog*>(QObject::sender());
+ for(QMap<QString, KeyGenDialog*>::iterator it = d->dialogs.begin(); it != d->dialogs.end(); ++it) {
+ if(it.value() == dialog) {
+ d->dialogs.erase(it);
+ dialog->delayedDestruct();
+ return;
+ }
+ }
+}
+
diff --git a/lib/proxy-service.h b/lib/proxy-service.h
new file mode 100644
index 0000000..96e9263
--- /dev/null
+++ b/lib/proxy-service.h
@@ -0,0 +1,65 @@
+/*
+ Copyright (C) 2014 Marcin Ziemiński <zieminn at gmail.com>
+
+ 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 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef PROXY_SERIVCE_HEADER
+#define PROXY_SERIVCE_HEADER
+
+#include "ktpchat_export.h"
+
+#include <QWidget>
+#include <TelepathyQt/AccountManager>
+
+class KDE_TELEPATHY_CHAT_EXPORT ProxyService : public QObject
+{
+ Q_OBJECT
+
+ public:
+ ProxyService(
+ const QDBusConnection &dbusConnection,
+ const QString& busName,
+ const QString& objectPath,
+ QWidget* parent = 0);
+
+ ~ProxyService();
+
+ /** return true if generation could be started */
+ bool generatePrivateKey(const QDBusObjectPath& account);
+ /** fingerprint or an empty string of none available */
+ QString fingerprintForAccount(const QDBusObjectPath& account);
+
+ Tp::PendingVariant* getOTRPolicy() const;
+ Tp::PendingOperation* setOTRPolicy(uint policy);
+
+ private Q_SLOTS:
+ void onKeyGenerationStarted(const QDBusObjectPath &path);
+ void onKeyGenerationFinished(const QDBusObjectPath &path, bool error);
+ void onDialogClosed();
+
+ Q_SIGNALS:
+ void proxyConnected(const QDBusObjectPath &proxy);
+ void proxyDisconnected(const QDBusObjectPath &proxy);
+ void keyGenerationStarted(Tp::AccountPtr account);
+ void keyGenerationFinished(Tp::AccountPtr, bool error);
+
+ private:
+ class Private;
+ Private *d;
+};
+
+Q_DECLARE_METATYPE(ProxyService*)
+
+#endif
--
ktp-text-ui packaging
More information about the pkg-kde-commits
mailing list