identityaddvcarddialog.cpp 4.35 KB
Newer Older
1
/*
Laurent Montel's avatar
Minor  
Laurent Montel committed
2
  Copyright (c) 2012, 2013 Montel Laurent <montel@kde.org>
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
  
  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 "identityaddvcarddialog.h"

20 21
#include <kpimidentities/identitymanager.h>

22
#include <KComboBox>
Laurent Montel's avatar
Laurent Montel committed
23
#include <KLocalizedString>
Laurent Montel's avatar
Laurent Montel committed
24
#include <KSeparator>
25
#include <KUrlRequester>
Laurent Montel's avatar
Laurent Montel committed
26

27
#include <QButtonGroup>
Laurent Montel's avatar
Laurent Montel committed
28 29 30
#include <QVBoxLayout>
#include <QRadioButton>
#include <QLabel>
31 32


33
IdentityAddVcardDialog::IdentityAddVcardDialog(KPIMIdentities::IdentityManager *manager, QWidget *parent)
34
    : KDialog(parent)
35
{
Laurent Montel's avatar
Minor  
Laurent Montel committed
36 37 38 39 40 41 42 43 44 45 46
    setCaption( i18n( "Create own vCard" ) );
    setButtons( Ok|Cancel );
    setDefaultButton( Ok );
    setModal( true );
    QWidget *mainWidget = new QWidget( this );
    QVBoxLayout *vlay = new QVBoxLayout( mainWidget );
    vlay->setSpacing( KDialog::spacingHint() );
    vlay->setMargin( KDialog::marginHint() );
    setMainWidget( mainWidget );

    mButtonGroup = new QButtonGroup( this );
47
    mButtonGroup->setObjectName(QLatin1String("buttongroup"));
Laurent Montel's avatar
Minor  
Laurent Montel committed
48 49 50 51 52 53 54 55

    // row 1: radio button
    QRadioButton *radio = new QRadioButton( i18n("&With empty fields"), this );
    radio->setChecked( true );
    vlay->addWidget( radio );
    mButtonGroup->addButton( radio, (int)Empty );

    // row 2: radio button
56 57 58
    QRadioButton *fromExistingVCard = new QRadioButton( i18n("&From existing vCard"), this );
    vlay->addWidget( fromExistingVCard );
    mButtonGroup->addButton( fromExistingVCard, (int)FromExistingVCard );
Laurent Montel's avatar
Minor  
Laurent Montel committed
59

60
    // row 3: KUrlRequester
Laurent Montel's avatar
Minor  
Laurent Montel committed
61 62
    QHBoxLayout* hlay = new QHBoxLayout(); // inherits spacing
    vlay->addLayout( hlay );
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


    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 );
Laurent Montel's avatar
Minor  
Laurent Montel committed
90
    mComboBox = new KComboBox( this );
91
    mComboBox->setObjectName(QLatin1String("identity_combobox"));
Laurent Montel's avatar
Minor  
Laurent Montel committed
92 93
    mComboBox->setEditable( false );

94
    mComboBox->addItems( manager ? manager->shadowIdentities() : QStringList() );
Laurent Montel's avatar
Minor  
Laurent Montel committed
95
    mComboBox->setEnabled( false );
96
    label = new QLabel( i18n("&Existing identities:"), this );
Laurent Montel's avatar
Minor  
Laurent Montel committed
97 98 99 100 101
    label->setBuddy( mComboBox );
    label->setEnabled( false );
    hlay->addWidget( label );
    hlay->addWidget( mComboBox, 1 );

Laurent Montel's avatar
Laurent Montel committed
102
    vlay->addWidget(new KSeparator);
Laurent Montel's avatar
Minor  
Laurent Montel committed
103 104 105 106
    vlay->addStretch( 1 ); // spacer

    // enable/disable combobox and label depending on the third radio
    // button's state:
107
    connect( duplicateExistingVCard, SIGNAL(toggled(bool)),
Laurent Montel's avatar
Minor  
Laurent Montel committed
108
             label, SLOT(setEnabled(bool)) );
109
    connect( duplicateExistingVCard, SIGNAL(toggled(bool)),
Laurent Montel's avatar
Minor  
Laurent Montel committed
110
             mComboBox, SLOT(setEnabled(bool)) );
Laurent Montel's avatar
Laurent Montel committed
111
    resize(350, 130);
112 113 114 115 116 117 118 119
}

IdentityAddVcardDialog::~IdentityAddVcardDialog()
{
}

IdentityAddVcardDialog::DuplicateMode IdentityAddVcardDialog::duplicateMode() const
{
Laurent Montel's avatar
Minor  
Laurent Montel committed
120 121
    const int id = mButtonGroup->checkedId();
    return static_cast<DuplicateMode>( id );
122 123 124 125
}

QString IdentityAddVcardDialog::duplicateVcardFromIdentity() const
{
Laurent Montel's avatar
Minor  
Laurent Montel committed
126
    return mComboBox->currentText();
127 128
}

129 130 131 132 133
KUrl IdentityAddVcardDialog::existingVCard() const
{
    return mVCardPath->url();
}