28 #ifndef KCM_KPIMIDENTITIES_STANDALONE
33 #include <mailcommon/kernel/mailkernel.h>
34 #include <messageviewer/utils/autoqpointer.h>
35 #include <kpimidentities/identity.h>
36 #include <kpimidentities/identitymanager.h>
39 #include <KMessageBox>
42 using namespace KMail;
52 mOldNumberOfIdentities( 0 ),
55 if ( !MailCommon::Kernel::self()->kernelIsRegistered() ) {
58 mIdentityManager = KernelIf->identityManager();
60 mIPage.setupUi(
this );
61 mIPage.mIdentityList->setIdentityManager( mIdentityManager );
63 connect( mIPage.mIdentityList, SIGNAL(itemSelectionChanged()),
64 SLOT(slotIdentitySelectionChanged()) );
65 connect(
this, SIGNAL(changed(
bool)),
66 SLOT(slotIdentitySelectionChanged()) );
69 connect( mIPage.mIdentityList, SIGNAL(itemDoubleClicked(
QTreeWidgetItem*,
int)),
70 SLOT(slotModifyIdentity()) );
75 connect( mIPage.mButtonAdd, SIGNAL(clicked()),
76 this, SLOT(slotNewIdentity()) );
77 connect( mIPage.mModifyButton, SIGNAL(clicked()),
78 this, SLOT(slotModifyIdentity()) );
79 connect( mIPage.mRenameButton, SIGNAL(clicked()),
80 this, SLOT(slotRenameIdentity()) );
81 connect( mIPage.mRemoveButton, SIGNAL(clicked()),
82 this, SLOT(slotRemoveIdentity()) );
83 connect( mIPage.mSetAsDefaultButton, SIGNAL(clicked()),
84 this, SLOT(slotSetAsDefault()) );
93 if ( !MailCommon::Kernel::self()->kernelIsRegistered() ) {
96 mOldNumberOfIdentities = mIdentityManager->shadowIdentities().count();
98 mIPage.mIdentityList->clear();
100 KPIMIdentities::IdentityManager::Iterator end( mIdentityManager->modifyEnd() );
102 for ( KPIMIdentities::IdentityManager::Iterator it = mIdentityManager->modifyBegin(); it != end; ++it ) {
105 if ( mIPage.mIdentityList->currentItem() ) {
106 mIPage.mIdentityList->currentItem()->setSelected(
true );
112 if ( !MailCommon::Kernel::self()->kernelIsRegistered() ) {
115 mIdentityManager->sort();
116 mIdentityManager->commit();
118 #ifndef KCM_KPIMIDENTITIES_STANDALONE
119 if( mOldNumberOfIdentities < 2 && mIPage.mIdentityList->topLevelItemCount() > 1 ) {
127 if( mOldNumberOfIdentities > 1 && mIPage.mIdentityList->topLevelItemCount() < 2 ) {
130 showHeaders &= ~KMail::Composer::HDR_IDENTITY;
136 void IdentityPage::slotNewIdentity()
138 Q_ASSERT( !mIdentityDialog );
141 mIdentityManager,
this ) );
144 if ( dialog->exec() == QDialog::Accepted && dialog ) {
146 Q_ASSERT( !identityName.
isEmpty() );
151 switch ( dialog->duplicateMode() ) {
154 KPIMIdentities::Identity &dupThis = mIdentityManager->modifyIdentityForName( dialog->duplicateIdentity() );
155 mIdentityManager->newFromExisting( dupThis, identityName );
159 mIdentityManager->newFromControlCenter( identityName );
162 mIdentityManager->newFromScratch( identityName );
169 KPIMIdentities::Identity &newIdent = mIdentityManager->modifyIdentityForName( identityName );
171 if ( !mIPage.mIdentityList->selectedItems().isEmpty() ) {
172 item = mIPage.mIdentityList->selectedItems()[0];
177 newItem =
new IdentityListViewItem( mIPage.mIdentityList, mIPage.mIdentityList->itemAbove( item ), newIdent );
182 mIPage.mIdentityList->selectionModel()->clearSelection();
187 slotModifyIdentity();
192 void IdentityPage::slotModifyIdentity()
194 Q_ASSERT( !mIdentityDialog );
197 if ( !mIPage.mIdentityList->selectedItems().isEmpty() ) {
208 if ( mIdentityDialog->exec() == QDialog::Accepted ) {
214 delete mIdentityDialog;
218 void IdentityPage::slotRemoveIdentity()
220 Q_ASSERT( !mIdentityDialog );
222 if ( mIdentityManager->shadowIdentities().count() < 2 ) {
223 kFatal() <<
"Attempted to remove the last identity!";
227 if ( !mIPage.mIdentityList->selectedItems().isEmpty() ) {
234 const QString msg = i18n(
"<qt>Do you really want to remove the identity named "
235 "<b>%1</b>?</qt>", item->
identity().identityName() );
236 if( KMessageBox::warningContinueCancel(
this, msg, i18n(
"Remove Identity"),
237 KGuiItem(i18n(
"&Remove"),
239 == KMessageBox::Continue ) {
240 if ( mIdentityManager->removeIdentity( item->
identity().identityName() ) ) {
242 if ( mIPage.mIdentityList->currentItem() ) {
243 mIPage.mIdentityList->currentItem()->setSelected(
true );
251 void IdentityPage::slotRenameIdentity()
253 Q_ASSERT( !mIdentityDialog );
257 if ( !mIPage.mIdentityList->selectedItems().isEmpty() ) {
258 item = mIPage.mIdentityList->selectedItems().first();
263 mIPage.mIdentityList->editItem( item );
273 !mIdentityManager->shadowIdentities().contains( newName ) ) {
274 KPIMIdentities::Identity &ident = item->
identity();
275 ident.setIdentityName( newName );
284 menu->
addAction( i18n(
"Add..." ),
this, SLOT(slotNewIdentity()) );
286 menu->
addAction( i18n(
"Modify..." ),
this, SLOT(slotModifyIdentity()) );
287 menu->
addAction( i18n(
"Rename" ),
this, SLOT(slotRenameIdentity()) );
288 if ( mIPage.mIdentityList->topLevelItemCount() > 1 ) {
289 menu->
addAction( i18n(
"Remove" ),
this, SLOT(slotRemoveIdentity()) );
291 if ( !item->
identity().isDefault() ) {
293 menu->
addAction( i18n(
"Set as Default" ),
this, SLOT(slotSetAsDefault()) );
301 void IdentityPage::slotSetAsDefault()
303 Q_ASSERT( !mIdentityDialog );
306 if ( !mIPage.mIdentityList->selectedItems().isEmpty() ) {
313 mIdentityManager->setAsDefault( item->
identity().uoid() );
315 mIPage.mSetAsDefaultButton->setEnabled(
false );
318 void IdentityPage::refreshList()
320 const int numberOfTopLevel( mIPage.mIdentityList->topLevelItemCount() );
321 for (
int i = 0; i < numberOfTopLevel; ++i ) {
330 void IdentityPage::slotIdentitySelectionChanged()
335 void IdentityPage::updateButtons()
338 if ( !mIPage.mIdentityList->selectedItems().isEmpty() ) {
341 mIPage.mRemoveButton->setEnabled( item && mIPage.mIdentityList->topLevelItemCount() > 1 );
342 mIPage.mModifyButton->setEnabled( item );
343 mIPage.mRenameButton->setEnabled( item );
344 mIPage.mSetAsDefaultButton->setEnabled( item && !item->
identity().isDefault() );
void updateIdentity(KPIMIdentities::Identity &ident)
IdentityPage(const KComponentData &instance, QWidget *parent=0)
virtual QByteArray text(quint32 serialNumber) const =0
KPIMIdentities::Identity & identity() const
QString helpAnchor() const
Should return the help anchor for this page or tab.
A QWidgetTreeItem for use in IdentityListView.
static GlobalSettings * self()
QString fromLatin1(const char *str, int size)
void setIdentity(KPIMIdentities::Identity &ident)