1 /* -*- mode: C++; c-file-style: "gnu" -*-
2 * kmail: KDE mail client
3 * Copyright (C) 2000 Espen Sand, espen@kde.org
4 * Copyright (C) 2001-2003 Marc Mutz, mutz@kde.org
5 * Contains code segments and ideas from earlier kmail dialog code.
6 * Copyright (C) 2010 Volker Krause <vkrause@kde.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include "newidentitydialog.h"
26 #include <kpimidentities/identitymanager.h>
30 #include <KLocalizedString>
32 #include <QButtonGroup>
33 #include <QHBoxLayout>
35 #include <QRadioButton>
36 #include <QVBoxLayout>
40 using namespace KMail
;
42 NewIdentityDialog::NewIdentityDialog( KPIMIdentities::IdentityManager
* manager
, QWidget
*parent
)
44 mIdentityManager( manager
)
46 setCaption( i18n("New Identity") );
47 setButtons( Ok
|Cancel
|Help
);
48 setHelp( QString::fromLatin1("configure-identity-newidentitydialog") );
49 QWidget
*page
= new QWidget( this );
50 setMainWidget( page
);
51 QVBoxLayout
* vlay
= new QVBoxLayout( page
);
52 vlay
->setSpacing( spacingHint() );
55 // row 0: line edit with label
56 QHBoxLayout
* hlay
= new QHBoxLayout(); // inherits spacing
57 vlay
->addLayout( hlay
);
58 mLineEdit
= new KLineEdit( page
);
59 mLineEdit
->setFocus();
60 mLineEdit
->setClearButtonShown( true );
61 QLabel
*l
= new QLabel( i18n("&New identity:"), page
);
62 l
->setBuddy( mLineEdit
);
64 hlay
->addWidget( mLineEdit
, 1 );
65 connect( mLineEdit
, SIGNAL(textChanged(const QString
&)),
66 this, SLOT(slotEnableOK(const QString
&)) );
68 mButtonGroup
= new QButtonGroup( page
);
70 // row 1: radio button
71 QRadioButton
*radio
= new QRadioButton( i18n("&With empty fields"), page
);
72 radio
->setChecked( true );
73 vlay
->addWidget( radio
);
74 mButtonGroup
->addButton( radio
, (int)Empty
);
76 // row 2: radio button
77 radio
= new QRadioButton( i18n("&Use System Settings values"), page
);
78 vlay
->addWidget( radio
);
79 mButtonGroup
->addButton( radio
, (int)ControlCenter
);
81 // row 3: radio button
82 radio
= new QRadioButton( i18n("&Duplicate existing identity"), page
);
83 vlay
->addWidget( radio
);
84 mButtonGroup
->addButton( radio
, (int)ExistingEntry
);
86 // row 4: combobox with existing identities and label
87 hlay
= new QHBoxLayout(); // inherits spacing
88 vlay
->addLayout( hlay
);
89 mComboBox
= new KComboBox( page
);
90 mComboBox
->setEditable( false );
91 mComboBox
->addItems( manager
->shadowIdentities() );
92 mComboBox
->setEnabled( false );
93 QLabel
*label
= new QLabel( i18n("&Existing identities:"), page
);
94 label
->setBuddy( mComboBox
);
95 label
->setEnabled( false );
96 hlay
->addWidget( label
);
97 hlay
->addWidget( mComboBox
, 1 );
99 vlay
->addStretch( 1 ); // spacer
101 // enable/disable combobox and label depending on the third radio
103 connect( radio
, SIGNAL(toggled(bool)),
104 label
, SLOT(setEnabled(bool)) );
105 connect( radio
, SIGNAL(toggled(bool)),
106 mComboBox
, SLOT(setEnabled(bool)) );
108 enableButtonOk( false ); // since line edit is empty
111 NewIdentityDialog::DuplicateMode
NewIdentityDialog::duplicateMode() const
113 int id
= mButtonGroup
->checkedId();
114 assert( id
== (int)Empty
115 || id
== (int)ControlCenter
116 || id
== (int)ExistingEntry
);
117 return static_cast<DuplicateMode
>( id
);
120 void NewIdentityDialog::slotEnableOK( const QString
& proposedIdentityName
)
122 // OK button is disabled if
123 QString name
= proposedIdentityName
.trimmed();
125 if ( name
.isEmpty() ) {
126 enableButtonOk( false );
129 // or name doesn't yet exist.
130 if ( !mIdentityManager
->isUnique( name
) ) {
131 enableButtonOk( false );
134 enableButtonOk( true );
137 QString
NewIdentityDialog::identityName() const
139 return mLineEdit
->text();
142 QString
NewIdentityDialog::duplicateIdentity() const
144 return mComboBox
->currentText();
147 #include "newidentitydialog.moc"