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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
/***************************************************************************
* 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 <tqlayout.h>
#include <tqlabel.h>
#include <tqmap.h>
#include <tqptrlist.h>
#include <tqcombobox.h>
#include <tqstringlist.h>
#include <tqtable.h>
#include <tqpaintdevicemetrics.h>
#include <tqvbox.h>
#include <tqradiobutton.h>
#include <tqtabwidget.h>
#include <kgenericfactory.h>
#include <kurlrequester.h>
#include <kmessagebox.h>
#include <kconfig.h>
#include <kapplication.h>
#include <kanimwidget.h>
#include <kpassivepopup.h>
#include <kiconloader.h>
#include <kstandarddirs.h>
#include <kactivelabel.h>
#include <kopeteaccountmanager.h>
#include <kopeteaccount.h>
#include <kopeteprotocol.h>
#include "otrprefs.h"
#include "otrpreferences.h"
#include "otrplugin.h"
#include "kopete_otr.h"
/**
* @author Michael Zanetti
*/
typedef KGenericFactory<OTRPreferences> OTRPreferencesFactory;
K_EXPORT_COMPONENT_FACTORY( kcm_kopete_otr, OTRPreferencesFactory("kcm_kopete_otr"))
OTRPreferences::OTRPreferences(TQWidget *parent, const char* /*name*/, const TQStringList &args)
: KCModule(OTRPreferencesFactory::instance(), parent, args)
{
( new TQVBoxLayout( this ) )->setAutoAdd( true );
preferencesDialog = new OTRPrefsUI(this);
this->addConfig( KopeteOtrKcfg::self(), preferencesDialog );
KopeteOtrKcfg::self()->readConfig();
load();
otrlConfInterface = new OtrlConfInterface( preferencesDialog );
connect( preferencesDialog->btGenFingerprint, TQT_SIGNAL(clicked()), TQT_SLOT(generateFingerprint()));
connect( preferencesDialog->cbKeys, TQT_SIGNAL(activated(int)), TQT_SLOT(showPrivFingerprint(int)));
connect( preferencesDialog->btVerify, TQT_SIGNAL(clicked()), TQT_SLOT(verifyFingerprint()));
connect( preferencesDialog->twSettings, TQT_SIGNAL(currentChanged(TQWidget *)), TQT_SLOT(fillFingerprints()));
connect( preferencesDialog->tbFingerprints, TQT_SIGNAL(currentChanged(int, int)), TQT_SLOT(updateButtons(int, int)));
connect( preferencesDialog->btForget, TQT_SIGNAL( clicked() ), TQT_SLOT( forgetFingerprint() ) );
int index = 0;
int accountnr = 0;
TQPtrList<Kopete::Account> accounts = Kopete::AccountManager::self()->accounts();
if( !accounts.isEmpty() ){
for ( TQPtrListIterator<Kopete::Account> it( accounts );
Kopete::Account *account = it.current();
++it ){
if ( account->protocol()->pluginId() != "IRCProtocol" ){
preferencesDialog->cbKeys->insertItem(account->accountId() + " (" + account->protocol()->displayName() + ")");
privKeys.insert(index++, accountnr);
}
accountnr++;
}
}
showPrivFingerprint( preferencesDialog->cbKeys->currentItem() );
preferencesDialog->tbFingerprints->setColumnWidth( 0, 200 );
preferencesDialog->tbFingerprints->setColumnWidth( 1, 80 );
preferencesDialog->tbFingerprints->setColumnWidth( 2, 60 );
preferencesDialog->tbFingerprints->setColumnWidth( 3, 400 );
preferencesDialog->tbFingerprints->setColumnWidth( 4, 200 );
}
OTRPreferences::~OTRPreferences(){
}
void OTRPreferences::generateFingerprint()
{
TQPtrList<Kopete::Account> accounts = Kopete::AccountManager::self()->accounts();
if( (accounts.isEmpty())){
return;
}
Kopete::Account *account = accounts.at( privKeys[preferencesDialog->cbKeys->currentItem()] );
if ((otrlConfInterface->hasPrivFingerprint( account->accountId(), account->protocol()->displayName() ) ) && (KMessageBox::questionYesNo(this, i18n("Selected account already has a key. Do you want to create a new one?"), i18n("Overwrite key?")) !=3)) return;
otrlConfInterface->generateNewPrivKey( account->accountId(), account->protocol()->displayName() );
showPrivFingerprint( preferencesDialog->cbKeys->currentItem() );
}
void OTRPreferences::showPrivFingerprint( int accountnr )
{
TQPtrList<Kopete::Account> accounts = Kopete::AccountManager::self()->accounts();
if( !accounts.isEmpty() ){
Kopete::Account *account = accounts.at(privKeys[accountnr]);
preferencesDialog->tlFingerprint->setText( otrlConfInterface->getPrivFingerprint( account->accountId(), account->protocol()->displayName() ) );
}
}
void OTRPreferences::fillFingerprints(){
TQTable *fingerprintsTable = preferencesDialog->tbFingerprints;
preferencesDialog->tbFingerprints->setNumRows(0);
TQValueList<TQString[5]> list = otrlConfInterface->readAllFingerprints();
TQValueList<TQString[5]>::iterator it;
int j = 0;
for( it = list.begin(); it != list.end(); ++it ){
preferencesDialog->tbFingerprints->setNumRows( preferencesDialog->tbFingerprints->numRows() +1 );
(*it)[0] = OtrlChatInterface::self()->formatContact((*it)[0]);
for( int i = 0; i < 5; i++ ){
//preferencesDialog->tbFingerprints->setText(j, i, (*it)[i] );
fingerprintsTable->setItem(j,i, new TQAlignTableItem(fingerprintsTable, TQTableItem::Never,(*it)[i],TQt::AlignLeft));
}
j++;
}
updateButtons( preferencesDialog->tbFingerprints->currentRow(), preferencesDialog->tbFingerprints->currentColumn() );
}
void OTRPreferences::verifyFingerprint(){
int doVerify = KMessageBox::questionYesNo(
this,
i18n("Please contact %1 via another secure way and verify that the following Fingerprint is correct:").tqarg(preferencesDialog->tbFingerprints->text( preferencesDialog->tbFingerprints->currentRow(), 0 )) + "\n\n" + preferencesDialog->tbFingerprints->text( preferencesDialog->tbFingerprints->currentRow(), 3 ) + "\n\n" + i18n("Are you sure you want to trust this fingerprint?"), i18n("Verify fingerprint") );
if( doVerify == KMessageBox::Yes ){
otrlConfInterface->verifyFingerprint( preferencesDialog->tbFingerprints->text( preferencesDialog->tbFingerprints->currentRow(), 3 ), true );
} else {
otrlConfInterface->verifyFingerprint( preferencesDialog->tbFingerprints->text( preferencesDialog->tbFingerprints->currentRow(), 3 ), false );
}
fillFingerprints();
}
void OTRPreferences::updateButtons( int row, int col ){
if( row != -1 ){
if( !otrlConfInterface->isEncrypted( preferencesDialog->tbFingerprints->text( row, 3 ) ) ){
preferencesDialog->btForget->setEnabled( true );
} else {
preferencesDialog->btForget->setEnabled( false );
}
preferencesDialog->btVerify->setEnabled( true );
} else {
preferencesDialog->btVerify->setEnabled( false );
preferencesDialog->btForget->setEnabled( false );
}
}
void OTRPreferences::forgetFingerprint(){
if( !otrlConfInterface->isEncrypted( preferencesDialog->tbFingerprints->text( preferencesDialog->tbFingerprints->currentRow(), 3 ) ) ){
otrlConfInterface->forgetFingerprint( preferencesDialog->tbFingerprints->text( preferencesDialog->tbFingerprints->currentRow(), 3 ) );
fillFingerprints();
} else {
updateButtons( preferencesDialog->tbFingerprints->currentRow(), preferencesDialog->tbFingerprints->currentColumn() );
}
}
TQAlignTableItem :: TQAlignTableItem( TQTable *table, EditType editType, const TQString& text, int tqalignment )
: TQTableItem( table, editType, text ) {
align = tqalignment;
}
#include "otrpreferences.moc"
// vim: set noet ts=4 sts=4 sw=4:
|