summaryrefslogtreecommitdiffstats
path: root/src/otrguiclient.cpp
blob: 3182898c41bb83c8741f25f1a48173916b8c1f22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/***************************************************************************
 *   Copyright (C) 2007 by Michael Zanetti  
 *
 *                                                                         *
 *   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, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
 ***************************************************************************/


#include <kaction.h>
#include <klocale.h>
#include <kactionclasses.h>
#include <kopetechatsession.h>
#include <kopeteview.h>
#include <kopetemessage.h>
#include <kdebug.h>
#include <kstandarddirs.h>
#include <kmessagebox.h>


#include "otrguiclient.h"
#include "otrplugin.h"

/**
  * @author Frank Scheffold
  * @author Michael Zanetti
  */


OtrGUIClient::OtrGUIClient( Kopete::ChatSession *parent, const char *name )
: TQObject( parent, name ), KXMLGUIClient( parent )
{
	setInstance( OTRPlugin::plugin()->instance() );

	connect( OTRPlugin::plugin(),
		TQT_SIGNAL( destroyed( TQObject * ) ), this,
		TQT_SLOT( deleteLater() )

	);

	connect(this, TQT_SIGNAL( signalOtrChatsession(Kopete::ChatSession*, bool) ), OTRPlugin::plugin(), TQT_SLOT(slotEnableOtr(Kopete::ChatSession*, bool)));

	connect( OTRPlugin::plugin(), TQT_SIGNAL( goneSecure( Kopete::ChatSession *, int ) ),
	this, TQT_SLOT( encryptionEnabled( Kopete::ChatSession *, int ) ) );

	connect( this, TQT_SIGNAL( signalVerifyFingerprint( Kopete::ChatSession * ) ), OTRPlugin::plugin(), TQT_SLOT(slotVerifyFingerprint( Kopete::ChatSession * )) );

	m_manager = parent;
	otrActionMenu = new TDEActionMenu(i18n("OTR Settings"),"otr_disabled", actionCollection(), "otr_settings");
	otrActionMenu->setDelayed( false );
	actionEnableOtr = new TDEAction(i18n( "Start OTR session" ), "otr_private", 0,this,TQT_SLOT(slotEnableOtr()),actionCollection(), "enable_otr");
	actionDisableOtr = new TDEAction(i18n("End OTR session"), "otr_disabled",0, this,TQT_SLOT(slotDisableOtr()), actionCollection(), "disable_otr");
	actionVerifyFingerprint = new TDEAction(i18n("Authenticate Contact"), "signature",0, this,TQT_SLOT(slotVerifyFingerprint()), actionCollection(), "verify_fingerprint");

	otrActionMenu->insert(actionEnableOtr);
	otrActionMenu->insert(actionDisableOtr);
	otrActionMenu->insert(actionVerifyFingerprint);

	setXMLFile("otrchatui.rc");

	encryptionEnabled( parent, OtrlChatInterface::self()->privState(parent) );
    

}

OtrGUIClient::~OtrGUIClient()
{
}

void OtrGUIClient::slotEnableOtr()
{
	emit signalOtrChatsession( m_manager, true );
}
void OtrGUIClient::slotDisableOtr()
{
 	emit signalOtrChatsession( m_manager, false );
}

void OtrGUIClient::slotVerifyFingerprint(){
	emit signalVerifyFingerprint( m_manager );
}

void OtrGUIClient::encryptionEnabled(Kopete::ChatSession *session, int state){
	if( session == m_manager ){
		switch(state){
			case 0:
				otrActionMenu->setIcon("otr_disabled");
				actionEnableOtr->setText( i18n("Start OTR session") );
				actionDisableOtr->setEnabled(false);
				actionVerifyFingerprint->setEnabled(false);
				break;
			case 1:
				otrActionMenu->setIcon("otr_unverified");
				actionEnableOtr->setText( i18n("Refresh OTR session") );
				actionDisableOtr->setEnabled(true);
				actionVerifyFingerprint->setEnabled(true);
				break;
			case 2:
				otrActionMenu->setIcon("otr_private");
				actionEnableOtr->setText( i18n("Refresh OTR session") );
				actionDisableOtr->setEnabled(true);
				actionVerifyFingerprint->setEnabled(true);
				break;
			case 3:
				otrActionMenu->setIcon("otr_finished");
				actionEnableOtr->setText( i18n("Start OTR session") );
				actionDisableOtr->setEnabled(true);
				actionVerifyFingerprint->setEnabled(false);
				break;
		}
	}
}

#include "otrguiclient.moc"

// vim: set noet ts=4 sts=4 sw=4: