diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-07-04 22:38:03 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-07-04 22:38:03 +0000 |
commit | dadc34655c3ab961b0b0b94a10eaaba710f0b5e8 (patch) | |
tree | 99e72842fe687baea16376a147619b6048d7e441 /kmymoney2/dialogs/kgpgkeyselectiondlg.cpp | |
download | kmymoney-dadc34655c3ab961b0b0b94a10eaaba710f0b5e8.tar.gz kmymoney-dadc34655c3ab961b0b0b94a10eaaba710f0b5e8.zip |
Added kmymoney
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kmymoney@1239792 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kmymoney2/dialogs/kgpgkeyselectiondlg.cpp')
-rw-r--r-- | kmymoney2/dialogs/kgpgkeyselectiondlg.cpp | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/kmymoney2/dialogs/kgpgkeyselectiondlg.cpp b/kmymoney2/dialogs/kgpgkeyselectiondlg.cpp new file mode 100644 index 0000000..37ddcc5 --- /dev/null +++ b/kmymoney2/dialogs/kgpgkeyselectiondlg.cpp @@ -0,0 +1,149 @@ +/*************************************************************************** + kgpgkeyselectiondlg.cpp + ------------------- + copyright : (C) 2008 by Thomas Baumgart + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +// ---------------------------------------------------------------------------- +// QT Includes + +#include <qlayout.h> +#include <qlabel.h> +#include <qwhatsthis.h> + +// ---------------------------------------------------------------------------- +// KDE Includes + +#include <klocale.h> +#include <keditlistbox.h> +#include <kled.h> + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "kgpgkeyselectiondlg.h" +#include <kmymoney/kgpgfile.h> + +KGpgKeySelectionDlg::KGpgKeySelectionDlg(QWidget *parent, const char *name) : + KDialogBase(parent, name, true, i18n("Select additional keys"), Ok | Cancel), + m_needCheckList(true), + m_listOk(false), + m_checkCount(0) +{ + QWidget* page = new QWidget(this); + setMainWidget(page); + QVBoxLayout* topLayout = new QVBoxLayout(page, 0, spacingHint()); + + m_listBox = new KEditListBox(page); + m_listBox->setTitle(i18n("User identification")); + m_listBox->setButtons( int( KEditListBox::Remove | KEditListBox::Add ) ); + QWhatsThis::add( m_listBox, i18n( "Enter the id of the key you want to use for data encryption. This can either be an e-mail address or the hexadecimal key id. In case of the key id don't forget the leading 0x." ) ); + + topLayout->addWidget(m_listBox); + + // add a LED for the availability of all keys + QHBoxLayout* ledBox = new QHBoxLayout(0, 0, 6, "ledBoxLayout"); + m_keyLed = new KLed(page); + m_keyLed->setShape( KLed::Circular ); + m_keyLed->setLook( KLed::Sunken ); + + ledBox->addWidget(m_keyLed); + ledBox->addWidget(new QLabel(i18n("Keys for all of the above user ids found"), page)); + ledBox->addItem(new QSpacerItem( 50, 20, QSizePolicy::Expanding, QSizePolicy::Minimum )); + + topLayout->addLayout(ledBox); + + connect(m_listBox, SIGNAL(changed()), this, SLOT(slotIdChanged())); + connect(m_listBox, SIGNAL(added(const QString&)), this, SLOT(slotKeyListChanged())); + connect(m_listBox, SIGNAL(removed(const QString&)), this, SLOT(slotKeyListChanged())); +} + +void KGpgKeySelectionDlg::setKeys(const QStringList& list) +{ + m_listBox->clear(); + m_listBox->insertStringList(list); + slotKeyListChanged(); +} + +#if 0 +void KGpgKeySelectionDlg::slotShowHelp(void) +{ + QString anchor = m_helpAnchor[m_criteriaTab->currentPage()]; + if(anchor.isEmpty()) + anchor = QString("details.search"); + + kapp->invokeHelp(anchor); +} +#endif + +void KGpgKeySelectionDlg::slotKeyListChanged(void) +{ + m_needCheckList = true; + slotIdChanged(); +} + +void KGpgKeySelectionDlg::slotIdChanged(void) +{ + // this looks a bit awkward. Here's why: KGPGFile::keyAvailable() starts + // an external task and processes UI events while it waits for the external + // process to finish. Thus, the first time we get here, the external process + // is started and the user may press a second key which calls this routine + // again. + // + // The second invocation is counted, but the check is not started until the + // first one finishes. Once the external process finishes, we check if we + // were called in the meantime and restart the check. + if(++m_checkCount == 1) { + while(1) { + // first we check the current edit field if filled + bool keysOk = true; + if(!m_listBox->currentText().isEmpty()) { + keysOk = KGPGFile::keyAvailable(m_listBox->currentText()); + } + + // if it is available, then scan the current list if we need to + if(keysOk) { + if(m_needCheckList) { + QStringList keys = m_listBox->items(); + QStringList::const_iterator it_s; + for(it_s = keys.begin(); keysOk && it_s != keys.end(); ++it_s) { + if(!KGPGFile::keyAvailable(*it_s)) + keysOk = false; + } + m_listOk = keysOk; + m_needCheckList = false; + + } else { + keysOk = m_listOk; + } + } + + // did we receive some more requests to check? + if(m_checkCount > 1) { + m_checkCount = 1; + continue; + } + + m_keyLed->setState(static_cast<KLed::State>(keysOk && (m_listBox->items().count() != 0) ? KLed::On : KLed::Off)); + enableButtonOK((m_listBox->items().count() == 0) || (m_keyLed->state() == KLed::On)); + break; + } + + --m_checkCount; + } +} + + +#include "kgpgkeyselectiondlg.moc" + +// vim:cin:si:ai:et:ts=2:sw=2: |