identityaddvcarddialog.cpp 3.06 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 23
#include <KComboBox>
#include <KLocale>
Laurent Montel's avatar
Laurent Montel committed
24 25
#include <KSeparator>

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


32
IdentityAddVcardDialog::IdentityAddVcardDialog(KPIMIdentities::IdentityManager *manager, QWidget *parent)
Laurent Montel's avatar
Minor  
Laurent Montel committed
33
    :KDialog(parent)
34
{
Laurent Montel's avatar
Minor  
Laurent Montel committed
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
    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 );

    // 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
    radio = new QRadioButton( i18n("&Duplicate existing vCard"), this );
    vlay->addWidget( radio );
    mButtonGroup->addButton( radio, (int)ExistingEntry );

    // row 3: combobox with existing identities and label
    QHBoxLayout* hlay = new QHBoxLayout(); // inherits spacing
    vlay->addLayout( hlay );
    mComboBox = new KComboBox( this );
    mComboBox->setEditable( false );

    mComboBox->addItems( manager->shadowIdentities() );
    mComboBox->setEnabled( false );
    QLabel *label = new QLabel( i18n("&Existing identities:"), this );
    label->setBuddy( mComboBox );
    label->setEnabled( false );
    hlay->addWidget( label );
    hlay->addWidget( mComboBox, 1 );

Laurent Montel's avatar
Laurent Montel committed
72
    vlay->addWidget(new KSeparator);
Laurent Montel's avatar
Minor  
Laurent Montel committed
73 74 75 76 77 78 79 80
    vlay->addStretch( 1 ); // spacer

    // enable/disable combobox and label depending on the third radio
    // button's state:
    connect( radio, SIGNAL(toggled(bool)),
             label, SLOT(setEnabled(bool)) );
    connect( radio, SIGNAL(toggled(bool)),
             mComboBox, SLOT(setEnabled(bool)) );
Laurent Montel's avatar
Laurent Montel committed
81
    resize(350, 130);
82 83 84 85 86 87 88 89
}

IdentityAddVcardDialog::~IdentityAddVcardDialog()
{
}

IdentityAddVcardDialog::DuplicateMode IdentityAddVcardDialog::duplicateMode() const
{
Laurent Montel's avatar
Minor  
Laurent Montel committed
90 91
    const int id = mButtonGroup->checkedId();
    return static_cast<DuplicateMode>( id );
92 93 94 95
}

QString IdentityAddVcardDialog::duplicateVcardFromIdentity() const
{
Laurent Montel's avatar
Minor  
Laurent Montel committed
96
    return mComboBox->currentText();
97 98
}