21 #include "mailcommon/util/mailutil.h"
25 #include <KPushButton>
28 #include <Akonadi/AgentInstance>
29 #include <Akonadi/AgentManager>
31 #include <KMime/KMimeMessage>
33 #include <QListWidget>
34 #include <QHBoxLayout>
37 using namespace KMail;
39 struct InstanceStruct {
48 setCaption( i18n(
"Edit Accounts Order") );
49 setButtons( Ok|Cancel );
50 setDefaultButton( Ok );
53 setMainWidget( page );
54 QHBoxLayout * vlay =
new QHBoxLayout( page );
56 mListAccount->setDragDropMode( QAbstractItemView::InternalMove );
57 vlay->addWidget(mListAccount);
60 mUpButton =
new KPushButton( upDownBox );
61 mUpButton->setIcon( KIcon(QLatin1String(
"go-up")) );
62 mUpButton->setToolTip( i18nc(
"Move selected account up.",
"Up" ) );
63 mUpButton->setEnabled(
false );
64 mUpButton->setFocusPolicy( Qt::StrongFocus );
65 mUpButton->setAutoRepeat(
true);
67 mDownButton =
new KPushButton( upDownBox );
68 mDownButton->setIcon( KIcon(QLatin1String(
"go-down")) );
69 mDownButton->setToolTip( i18nc(
"Move selected account down.",
"Down" ) );
70 mDownButton->setEnabled(
false );
71 mDownButton->setFocusPolicy( Qt::StrongFocus );
72 mDownButton->setAutoRepeat(
true);
75 upDownBox->setStretchFactor( spacer, 100 );
76 vlay->addWidget( upDownBox );
79 connect( mUpButton, SIGNAL(clicked()),
this, SLOT(slotMoveUp()) );
80 connect( mDownButton, SIGNAL(clicked()),
this, SLOT(slotMoveDown()) );
81 connect( mListAccount, SIGNAL(itemSelectionChanged()),
this, SLOT(slotEnableControls()));
82 connect( mListAccount->model(), SIGNAL(rowsMoved(QModelIndex,
int,
int,QModelIndex,
int)),SLOT(slotEnableControls()) );
84 connect(
this, SIGNAL(okClicked()), SLOT(slotOk()) );
94 void AccountConfigOrderDialog::slotMoveUp()
96 if ( !mListAccount->currentItem() )
98 const int pos = mListAccount->row( mListAccount->currentItem() );
99 mListAccount->blockSignals(
true );
103 mListAccount->insertItem( pos -1, item );
104 mListAccount->blockSignals(
false );
105 mListAccount->setCurrentRow( pos - 1 );
108 void AccountConfigOrderDialog::slotMoveDown()
110 if ( !mListAccount->currentItem() )
112 const int pos = mListAccount->row( mListAccount->currentItem() );
113 mListAccount->blockSignals(
true );
117 mListAccount->insertItem( pos +1 , item );
118 mListAccount->blockSignals(
false );
119 mListAccount->setCurrentRow( pos + 1 );
123 void AccountConfigOrderDialog::slotEnableControls()
127 mUpButton->setEnabled( item && mListAccount->currentRow()!=0 );
128 mDownButton->setEnabled( item && mListAccount->currentRow()!=mListAccount->count()-1 );
131 void AccountConfigOrderDialog::init()
134 const QStringList listOrderAccount = group.readEntry(
"order",QStringList());
135 QStringList instanceList;
138 foreach (
const Akonadi::AgentInstance &instance, Akonadi::AgentManager::self()->instances() ) {
139 const QStringList capabilities( instance.type().capabilities() );
140 if ( instance.type().mimeTypes().contains( KMime::Message::mimeType() ) ) {
141 if ( capabilities.contains( QLatin1String(
"Resource") ) &&
142 !capabilities.contains( QLatin1String(
"Virtual") ) &&
143 !capabilities.contains( QLatin1String(
"MailTransport") ) )
145 const QString identifier = instance.identifier();
146 if (!identifier.contains(POP3_RESOURCE_IDENTIFIER)) {
147 instanceList<<instance.identifier();
148 InstanceStruct instanceStruct;
149 instanceStruct.name = instance.name();
150 if (identifier.startsWith(QLatin1String(
"akonadi_imap_resource"))) {
151 instanceStruct.name += QLatin1String(
" (IMAP)");
152 }
else if (identifier.startsWith(QLatin1String(
"akonadi_maildir_resource"))) {
153 instanceStruct.name += QLatin1String(
" (Maildir)");
154 }
else if (identifier.startsWith(QLatin1String(
"akonadi_mailbox_resource"))) {
155 instanceStruct.name += QLatin1String(
" (Mailbox)");
156 }
else if (identifier.startsWith(QLatin1String(
"akonadi_mixedmaildir_resource"))) {
157 instanceStruct.name += QLatin1String(
" (Mixedmaildir)");
159 instanceStruct.icon = instance.type().icon();
160 mapInstance.insert(instance.identifier(),instanceStruct);
165 const int numberOfList(listOrderAccount.count());
166 for (
int i = 0; i< numberOfList;++i) {
167 instanceList.removeOne(listOrderAccount.at(i));
170 QStringList finalList (listOrderAccount);
171 finalList += instanceList;
173 const int numberOfElement(finalList.count());
174 for (
int i = 0; i <numberOfElement;++i) {
175 const QString identifier(finalList.at(i));
176 if (mapInstance.contains(identifier)) {
177 InstanceStruct tmp = mapInstance.value(identifier);
179 item->setData(AccountConfigOrderDialog::IdentifierAccount, identifier);
180 mListAccount->addItem( item );
185 void AccountConfigOrderDialog::slotOk()
190 const int numberOfItems(mListAccount->count());
191 for (
int i = 0; i<numberOfItems; ++i) {
192 order << mListAccount->item(i)->data(AccountConfigOrderDialog::IdentifierAccount).toString();
195 group.writeEntry(
"order",order);
201 void AccountConfigOrderDialog::readConfig()
203 KConfigGroup accountConfigDialog(
KMKernel::self()->config(),
"AccountConfigOrderDialog" );
204 const QSize size = accountConfigDialog.readEntry(
"Size", QSize(600, 400) );
205 if ( size.isValid() ) {
210 void AccountConfigOrderDialog::writeConfig()
212 KConfigGroup accountConfigDialog(
KMKernel::self()->config(),
"AccountConfigOrderDialog" );
213 accountConfigDialog.writeEntry(
"Size", size() );
214 accountConfigDialog.sync();
219 #include "accountconfigorderdialog.moc"
static KMKernel * self()
normal control stuff
~AccountConfigOrderDialog()
AccountConfigOrderDialog(QWidget *parent)