From c6c12511a57af9d29a9a2d8a19524b00b1141537 Mon Sep 17 00:00:00 2001 From: Montel Laurent Date: Tue, 15 Jul 2014 09:22:22 +0200 Subject: [PATCH] Fix Bug 337435 - kmail vcard import pgp key FIXED-IN: 4.14 BUG: 337435 --- kmail/identity/identityaddvcarddialog.cpp | 53 ++++++++++++++++++---- kmail/identity/identityaddvcarddialog.h | 6 ++- kmail/identity/identitydialog.cpp | 9 ++++ kmail/tests/CMakeLists.txt | 4 ++ kmail/tests/identityaddvcarddialogtest.cpp | 47 +++++++++++++++++++ kmail/tests/identityaddvcarddialogtest.h | 33 ++++++++++++++ 6 files changed, 142 insertions(+), 10 deletions(-) create mode 100644 kmail/tests/identityaddvcarddialogtest.cpp create mode 100644 kmail/tests/identityaddvcarddialogtest.h diff --git a/kmail/identity/identityaddvcarddialog.cpp b/kmail/identity/identityaddvcarddialog.cpp index e21c88f267..9c3174b68b 100644 --- a/kmail/identity/identityaddvcarddialog.cpp +++ b/kmail/identity/identityaddvcarddialog.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -30,7 +31,7 @@ IdentityAddVcardDialog::IdentityAddVcardDialog(KPIMIdentities::IdentityManager *manager, QWidget *parent) - :KDialog(parent) + : KDialog(parent) { setCaption( i18n( "Create own vCard" ) ); setButtons( Ok|Cancel ); @@ -43,6 +44,7 @@ IdentityAddVcardDialog::IdentityAddVcardDialog(KPIMIdentities::IdentityManager * setMainWidget( mainWidget ); mButtonGroup = new QButtonGroup( this ); + mButtonGroup->setObjectName(QLatin1String("buttongroup")); // row 1: radio button QRadioButton *radio = new QRadioButton( i18n("&With empty fields"), this ); @@ -51,19 +53,47 @@ IdentityAddVcardDialog::IdentityAddVcardDialog(KPIMIdentities::IdentityManager * mButtonGroup->addButton( radio, (int)Empty ); // row 2: radio button - radio = new QRadioButton( i18n("&Duplicate existing vCard"), this ); - vlay->addWidget( radio ); - mButtonGroup->addButton( radio, (int)ExistingEntry ); + QRadioButton *fromExistingVCard = new QRadioButton( i18n("&From existing vCard"), this ); + vlay->addWidget( fromExistingVCard ); + mButtonGroup->addButton( fromExistingVCard, (int)FromExistingVCard ); - // row 3: combobox with existing identities and label + // row 3: KUrlRequester QHBoxLayout* hlay = new QHBoxLayout(); // inherits spacing vlay->addLayout( hlay ); + + + mVCardPath = new KUrlRequester; + mVCardPath->setObjectName(QLatin1String("kurlrequester_vcardpath")); + + mVCardPath->setMode(KFile::LocalOnly|KFile::File); + QLabel *label = new QLabel( i18n("&VCard path:"), this ); + label->setBuddy( mVCardPath ); + label->setEnabled( false ); + mVCardPath->setEnabled( false ); + hlay->addWidget( label ); + hlay->addWidget( mVCardPath ); + + connect( fromExistingVCard, SIGNAL(toggled(bool)), + label, SLOT(setEnabled(bool)) ); + connect( fromExistingVCard, SIGNAL(toggled(bool)), + mVCardPath, SLOT(setEnabled(bool)) ); + + + // row 4: radio button + QRadioButton *duplicateExistingVCard = new QRadioButton( i18n("&Duplicate existing vCard"), this ); + vlay->addWidget( duplicateExistingVCard ); + mButtonGroup->addButton( duplicateExistingVCard, (int)ExistingEntry ); + + // row 5: combobox with existing identities and label + hlay = new QHBoxLayout(); // inherits spacing + vlay->addLayout( hlay ); mComboBox = new KComboBox( this ); + mComboBox->setObjectName(QLatin1String("identity_combobox")); mComboBox->setEditable( false ); - mComboBox->addItems( manager->shadowIdentities() ); + mComboBox->addItems( manager ? manager->shadowIdentities() : QStringList() ); mComboBox->setEnabled( false ); - QLabel *label = new QLabel( i18n("&Existing identities:"), this ); + label = new QLabel( i18n("&Existing identities:"), this ); label->setBuddy( mComboBox ); label->setEnabled( false ); hlay->addWidget( label ); @@ -74,9 +104,9 @@ IdentityAddVcardDialog::IdentityAddVcardDialog(KPIMIdentities::IdentityManager * // enable/disable combobox and label depending on the third radio // button's state: - connect( radio, SIGNAL(toggled(bool)), + connect( duplicateExistingVCard, SIGNAL(toggled(bool)), label, SLOT(setEnabled(bool)) ); - connect( radio, SIGNAL(toggled(bool)), + connect( duplicateExistingVCard, SIGNAL(toggled(bool)), mComboBox, SLOT(setEnabled(bool)) ); resize(350, 130); } @@ -96,3 +126,8 @@ QString IdentityAddVcardDialog::duplicateVcardFromIdentity() const return mComboBox->currentText(); } +KUrl IdentityAddVcardDialog::existingVCard() const +{ + return mVCardPath->url(); +} + diff --git a/kmail/identity/identityaddvcarddialog.h b/kmail/identity/identityaddvcarddialog.h index 0438ec154f..cc422a7c88 100644 --- a/kmail/identity/identityaddvcarddialog.h +++ b/kmail/identity/identityaddvcarddialog.h @@ -20,6 +20,7 @@ #include class QButtonGroup; class KComboBox; +class KUrlRequester; namespace KPIMIdentities { class IdentityManager; @@ -31,7 +32,8 @@ class IdentityAddVcardDialog: public KDialog public: enum DuplicateMode { Empty, - ExistingEntry + ExistingEntry, + FromExistingVCard }; explicit IdentityAddVcardDialog(KPIMIdentities::IdentityManager *manager, QWidget *parent = 0); @@ -39,10 +41,12 @@ public: DuplicateMode duplicateMode() const; QString duplicateVcardFromIdentity() const; + KUrl existingVCard() const; private: QButtonGroup *mButtonGroup; KComboBox *mComboBox; + KUrlRequester *mVCardPath; }; #endif // IDENTITYADDVCARDDIALOG_H diff --git a/kmail/identity/identitydialog.cpp b/kmail/identity/identitydialog.cpp index 084cac330f..ef6d1de669 100644 --- a/kmail/identity/identitydialog.cpp +++ b/kmail/identity/identitydialog.cpp @@ -999,6 +999,15 @@ void IdentityDialog::slotEditVcard() editVcard(mVcardFilename); break; } + case IdentityAddVcardDialog::FromExistingVCard: { + const QString filename = dlg->existingVCard().path(); + if(!filename.isEmpty()) { + mVcardFilename = filename; + } + qDebug()<<" filename "< + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + 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 "identityaddvcarddialogtest.h" +#include "../identity/identityaddvcarddialog.h" + +#include +#include +#include + +#include + +identityaddvcarddialogtest::identityaddvcarddialogtest() +{ +} + +void identityaddvcarddialogtest::shouldHaveDefaultValue() +{ + IdentityAddVcardDialog dlg(0,0); + KComboBox *identityComboBox = qFindChild(&dlg, QLatin1String("identity_combobox")); + QVERIFY(identityComboBox); + QCOMPARE(identityComboBox->isEnabled(), false); + + KUrlRequester *urlRequester = qFindChild(&dlg, QLatin1String("kurlrequester_vcardpath")); + QVERIFY(urlRequester); + QCOMPARE(urlRequester->isEnabled(), false); + + QButtonGroup *buttonGroup = qFindChild(&dlg, QLatin1String("buttongroup")); + QVERIFY(buttonGroup); + QCOMPARE(dlg.duplicateMode(), IdentityAddVcardDialog::Empty); +} + +QTEST_KDEMAIN(identityaddvcarddialogtest, GUI) diff --git a/kmail/tests/identityaddvcarddialogtest.h b/kmail/tests/identityaddvcarddialogtest.h new file mode 100644 index 0000000000..c7fa1d0c61 --- /dev/null +++ b/kmail/tests/identityaddvcarddialogtest.h @@ -0,0 +1,33 @@ +/* + Copyright (c) 2014 Montel Laurent + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + 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 +*/ + + +#ifndef IDENTITYADDVCARDDIALOGTEST_H +#define IDENTITYADDVCARDDIALOGTEST_H + +#include + +class identityaddvcarddialogtest : public QObject +{ + Q_OBJECT +public: + identityaddvcarddialogtest(); +private Q_SLOTS: + void shouldHaveDefaultValue(); +}; + +#endif // IDENTITYADDVCARDDIALOGTEST_H -- GitLab