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 #ifndef OTRPLUGIN_H
22 #define OTRPLUGIN_H
23 
24 #include <kopeteplugin.h>
25 #include <kopetemessagehandler.h>
26 
27 #include "otrlchatinterface.h"
28 
29 #include "qvariant.h"
30 #include <QPointer>
31 #include <QPair>
32 
33 /**
34   * @author Michael Zanetti
35   */
36 
37 class OTRPlugin;
38 class KSelectAction;
39 
40 class OtrMessageHandler : public Kopete::MessageHandler
41 {
42 private:
43     QPointer<OTRPlugin> plugin;
44 public:
OtrMessageHandler(OTRPlugin * plugin)45     OtrMessageHandler(OTRPlugin *plugin) : plugin(plugin)
46     {
47 //		kdDebug() << "MessageHandler created" << endl;
48     }
49 
~OtrMessageHandler()50     ~OtrMessageHandler()
51     {
52 //		kdDebug() << "MessageHandler destroyed" << endl;
53     }
54 
55     void handleMessage(Kopete::MessageEvent *event) Q_DECL_OVERRIDE;
56 };
57 
58 class OtrMessageHandlerFactory : public Kopete::MessageHandlerFactory
59 {
60 private:
61     OTRPlugin *plugin;
62     OtrMessageHandler *messageHandler;
63 public:
OtrMessageHandlerFactory(OTRPlugin * plugin)64     OtrMessageHandlerFactory(OTRPlugin *plugin) : plugin(plugin)
65     {
66     }
67 
create(Kopete::ChatSession *,Kopete::Message::MessageDirection direction)68     Kopete::MessageHandler *create(Kopete::ChatSession *, Kopete::Message::MessageDirection direction) Q_DECL_OVERRIDE
69     {
70         Q_UNUSED(direction)
71         return new OtrMessageHandler(plugin);
72     }
73 
filterPosition(Kopete::ChatSession *,Kopete::Message::MessageDirection)74     int filterPosition(Kopete::ChatSession *, Kopete::Message::MessageDirection) Q_DECL_OVERRIDE
75     {
76         return Kopete::MessageHandlerFactory::InStageToSent+1;
77     }
78 };
79 
80 class OTRPlugin : public Kopete::Plugin
81 {
82     Q_OBJECT
83 
84 public:
85 
86     static OTRPlugin *plugin();
87 
88     OTRPlugin(QObject *parent, const QVariantList &args);
89     ~OTRPlugin();
90 
91     void emitGoneSecure(Kopete::ChatSession *session, int status);
92     QMap<QString, QPair<QString, bool> > getMessageCache();
93 
94 public Q_SLOTS:
95 
96     void slotOutgoingMessage(Kopete::Message &msg);
97     void slotEnableOtr(Kopete::ChatSession *session, bool enable);
98     void slotSettingsChanged();
99     void slotVerifyFingerprint(Kopete::ChatSession *session);
100 
101 private Q_SLOTS:
102     void slotNewChatSessionWindow(Kopete::ChatSession *);
103     void slotSelectionChanged(bool single);
104     void slotSetPolicy();
105     void slotSecuritySate(Kopete::ChatSession *session, int state);
106 
107 private:
108     static OTRPlugin *pluginStatic_;
109     OtrMessageHandlerFactory *m_inboundHandler;
110     OtrlChatInterface *otrlChatInterface;
111     QMap<QString, QPair<QString, bool> > messageCache;
112     KSelectAction *otrPolicyMenu;
113 Q_SIGNALS:
114     void goneSecure(Kopete::ChatSession *session, int state);
115 };
116 
117 #endif
118