From 498ff4e365566b987d2c7a1e54065e0e126556f7 Mon Sep 17 00:00:00 2001 From: tpearson Date: Fri, 19 Feb 2010 18:38:42 +0000 Subject: Added abandoned KDE3 version of kopete-otr git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kopete-otr@1092925 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- src/otrpreferences.cpp | 199 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 src/otrpreferences.cpp (limited to 'src/otrpreferences.cpp') diff --git a/src/otrpreferences.cpp b/src/otrpreferences.cpp new file mode 100644 index 0000000..b056d58 --- /dev/null +++ b/src/otrpreferences.cpp @@ -0,0 +1,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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "otrprefs.h" +#include "otrpreferences.h" +#include "otrplugin.h" +#include "kopete_otr.h" + +/** + * @author Michael Zanetti + */ + +typedef KGenericFactory OTRPreferencesFactory; +K_EXPORT_COMPONENT_FACTORY( kcm_kopete_otr, OTRPreferencesFactory("kcm_kopete_otr")) + +OTRPreferences::OTRPreferences(QWidget *parent, const char* /*name*/, const QStringList &args) + : KCModule(OTRPreferencesFactory::instance(), parent, args) +{ + ( new QVBoxLayout( this ) )->setAutoAdd( true ); + preferencesDialog = new OTRPrefsUI(this); + + + this->addConfig( KopeteOtrKcfg::self(), preferencesDialog ); + KopeteOtrKcfg::self()->readConfig(); + load(); + + + + otrlConfInterface = new OtrlConfInterface( preferencesDialog ); + + connect( preferencesDialog->btGenFingerprint, SIGNAL(clicked()), SLOT(generateFingerprint())); + connect( preferencesDialog->cbKeys, SIGNAL(activated(int)), SLOT(showPrivFingerprint(int))); + connect( preferencesDialog->btVerify, SIGNAL(clicked()), SLOT(verifyFingerprint())); + connect( preferencesDialog->twSettings, SIGNAL(currentChanged(QWidget *)), SLOT(fillFingerprints())); + connect( preferencesDialog->tbFingerprints, SIGNAL(currentChanged(int, int)), SLOT(updateButtons(int, int))); + connect( preferencesDialog->btForget, SIGNAL( clicked() ), SLOT( forgetFingerprint() ) ); + + int index = 0; + int accountnr = 0; + QPtrList accounts = Kopete::AccountManager::self()->accounts(); + if( !accounts.isEmpty() ){ + for ( QPtrListIterator 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() +{ + QPtrList 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 ) +{ + QPtrList 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(){ + QTable *fingerprintsTable = preferencesDialog->tbFingerprints; + preferencesDialog->tbFingerprints->setNumRows(0); + QValueList list = otrlConfInterface->readAllFingerprints(); + QValueList::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 QAlignTableItem(fingerprintsTable, QTableItem::Never,(*it)[i],Qt::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:").arg(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() ); + } +} + +QAlignTableItem :: QAlignTableItem( QTable *table, EditType editType, const QString& text, int alignment ) + : QTableItem( table, editType, text ) { + align = alignment; +} + + +#include "otrpreferences.moc" + +// vim: set noet ts=4 sts=4 sw=4: -- cgit v1.2.1