1 /*************************************************************************
2 * Copyright <2007 - 2013> <Michael Zanetti> <mzanetti@kde.org> *
3 * *
4 * This program is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU General Public License as *
6 * published by the Free Software Foundation; either version 2 of *
7 * the License or (at your option) version 3 or any later version *
8 * accepted by the membership of KDE e.V. (or its successor approved *
9 * by the membership of KDE e.V.), which shall act as a proxy *
10 * defined in Section 14 of version 3 of the license. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19 *************************************************************************/
20
21 #include "otrguiclient.h"
22 #include "otrplugin.h"
23 #include "otrlchatinterface.h"
24
25 #include <QAction>
26 #include <KLocalizedString>
27 #include <kactionmenu.h>
28 #include <kopetechatsession.h>
29 #include <ui/kopeteview.h>
30 #include <kopetemessage.h>
31 #include "plugin_otr_debug.h"
32
33 #include <kmessagebox.h>
34 #include <qicon.h>
35 #include <kactioncollection.h>
36
37 /**
38 * @author Frank Scheffold
39 * @author Michael Zanetti
40 */
41
OtrGUIClient(Kopete::ChatSession * parent)42 OtrGUIClient::OtrGUIClient(Kopete::ChatSession *parent)
43 : QObject(parent)
44 , KXMLGUIClient(parent)
45 {
46 setComponentName(QStringLiteral("kopete_otr"), i18n("Kopete"));
47 connect(OTRPlugin::plugin(),
48 SIGNAL(destroyed(QObject*)), this,
49 SLOT(deleteLater())
50
51 );
52
53 connect(this, SIGNAL(signalOtrChatsession(Kopete::ChatSession*,bool)), OTRPlugin::plugin(), SLOT(slotEnableOtr(Kopete::ChatSession*,bool)));
54
55 connect(OtrlChatInterface::self(), SIGNAL(goneSecure(Kopete::ChatSession*,int)),
56 this, SLOT(encryptionEnabled(Kopete::ChatSession*,int)));
57
58 connect(this, SIGNAL(signalVerifyFingerprint(Kopete::ChatSession*)), OTRPlugin::plugin(), SLOT(slotVerifyFingerprint(Kopete::ChatSession*)));
59
60 m_manager = parent;
61
62 otrActionMenu = new KActionMenu(QIcon::fromTheme(QStringLiteral("document-decrypt")), i18n("OTR Encryption"), actionCollection());
63 otrActionMenu->setDelayed(false);
64 actionCollection()->addAction(QStringLiteral("otr_settings"), otrActionMenu);
65
66 actionEnableOtr = new QAction(QIcon::fromTheme(QStringLiteral("object-locked")), i18n("Start OTR Session"), this);
67 actionCollection()->addAction(QStringLiteral("enableOtr"), actionEnableOtr);
68 connect(actionEnableOtr, SIGNAL(triggered(bool)), this, SLOT(slotEnableOtr()));
69
70 actionDisableOtr = new QAction(QIcon::fromTheme(QStringLiteral("object-unlocked")), i18n("End OTR Session"), this);
71 actionCollection()->addAction(QStringLiteral("disableOtr"), actionDisableOtr);
72 connect(actionDisableOtr, SIGNAL(triggered(bool)), this, SLOT(slotDisableOtr()));
73
74 actionVerifyFingerprint = new QAction(QIcon::fromTheme(QStringLiteral("application-pgp-signature")), i18n("Authenticate Contact"), this);
75 actionCollection()->addAction(QStringLiteral("verifyFingerprint"), actionVerifyFingerprint);
76 connect(actionVerifyFingerprint, SIGNAL(triggered(bool)), this, SLOT(slotVerifyFingerprint()));
77
78 // jpetso says: please request an icon named "document-verify" or something like that, the "sign" icon is not really appropriate for this purpose imho
79 // mzanetti says: the "document-sign" icon is the same as kgpg uses to sign fingerprints. Anyways I will discuss that on #kopete. Re-using "document-sign for now.
80
81 otrActionMenu->addAction(actionEnableOtr);
82 otrActionMenu->addAction(actionDisableOtr);
83 otrActionMenu->addAction(actionVerifyFingerprint);
84
85 setXMLFile(QStringLiteral("otrchatui.rc"));
86
87 encryptionEnabled(parent, OtrlChatInterface::self()->privState(parent));
88 }
89
~OtrGUIClient()90 OtrGUIClient::~OtrGUIClient()
91 {
92 }
93
slotEnableOtr()94 void OtrGUIClient::slotEnableOtr()
95 {
96 emit signalOtrChatsession(m_manager, true);
97 }
98
slotDisableOtr()99 void OtrGUIClient::slotDisableOtr()
100 {
101 emit signalOtrChatsession(m_manager, false);
102 }
103
slotVerifyFingerprint()104 void OtrGUIClient::slotVerifyFingerprint()
105 {
106 emit signalVerifyFingerprint(m_manager);
107 }
108
encryptionEnabled(Kopete::ChatSession * session,int state)109 void OtrGUIClient::encryptionEnabled(Kopete::ChatSession *session, int state)
110 {
111 qCDebug(KOPETE_PLUGIN_OTR_LOG) << "OTRGUIClient switched security state to: " << state;
112 if (session == m_manager) {
113 switch (state) {
114 case 0:
115 otrActionMenu->setIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
116 actionEnableOtr->setText(i18n("Start OTR Session"));
117 actionDisableOtr->setEnabled(false);
118 actionVerifyFingerprint->setEnabled(false);
119 break;
120 case 1:
121 otrActionMenu->setIcon(QIcon::fromTheme(QStringLiteral("object-locked-unverified")));
122 actionEnableOtr->setText(i18n("Refresh OTR Session"));
123 actionDisableOtr->setEnabled(true);
124 actionVerifyFingerprint->setEnabled(true);
125 break;
126 case 2:
127 otrActionMenu->setIcon(QIcon::fromTheme(QStringLiteral("object-locked-verified")));
128 actionEnableOtr->setText(i18n("Refresh OTR Session"));
129 actionDisableOtr->setEnabled(true);
130 actionVerifyFingerprint->setEnabled(true);
131 break;
132 case 3:
133 otrActionMenu->setIcon(QIcon::fromTheme(QStringLiteral("object-locked-finished")));
134 actionEnableOtr->setText(i18n("Start OTR Session"));
135 actionDisableOtr->setEnabled(true);
136 actionVerifyFingerprint->setEnabled(false);
137 break;
138 }
139 }
140 }
141
142 // vim: set noet ts=4 sts=4 sw=4:
143