Commit e33ca57d authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Allow to select multi identities

parent ee4aa4ac
Pipeline #20749 passed with stage
in 10 minutes and 55 seconds
...@@ -134,7 +134,7 @@ IdentityListView::IdentityListView(QWidget *parent) ...@@ -134,7 +134,7 @@ IdentityListView::IdentityListView(QWidget *parent)
setAlternatingRowColors(true); setAlternatingRowColors(true);
setSortingEnabled(true); setSortingEnabled(true);
sortByColumn(0, Qt::AscendingOrder); sortByColumn(0, Qt::AscendingOrder);
setSelectionMode(SingleSelection); // ### Extended would be nicer... setSelectionMode(ExtendedSelection);
setColumnWidth(0, 175); setColumnWidth(0, 175);
setContextMenuPolicy(Qt::CustomContextMenu); setContextMenuPolicy(Qt::CustomContextMenu);
......
...@@ -40,6 +40,8 @@ ...@@ -40,6 +40,8 @@
#include <KLocalizedString> #include <KLocalizedString>
#include "kmail_debug.h" #include "kmail_debug.h"
#include <QTreeWidgetItem>
using namespace KMail; using namespace KMail;
QString IdentityPage::helpAnchor() const QString IdentityPage::helpAnchor() const
...@@ -216,28 +218,38 @@ void IdentityPage::slotRemoveIdentity() ...@@ -216,28 +218,38 @@ void IdentityPage::slotRemoveIdentity()
qCritical() << "Attempted to remove the last identity!"; qCritical() << "Attempted to remove the last identity!";
} }
const int numberOfIdentity = mIPage.mIdentityList->selectedItems().count();
QString identityName;
IdentityListViewItem *item = nullptr; IdentityListViewItem *item = nullptr;
if (!mIPage.mIdentityList->selectedItems().isEmpty()) { const QList<QTreeWidgetItem *> selectedItems = mIPage.mIdentityList->selectedItems();
item = dynamic_cast<IdentityListViewItem *>(mIPage.mIdentityList->selectedItems().at(0)); if (numberOfIdentity == 1) {
} if (!mIPage.mIdentityList->selectedItems().isEmpty()) {
if (!item) { item = dynamic_cast<IdentityListViewItem *>(mIPage.mIdentityList->selectedItems().at(0));
return; }
if (!item) {
return;
}
identityName = item->identity().identityName();
} }
const QString msg = i18np("<qt>Do you really want to remove the identity named "
const QString msg = i18n("<qt>Do you really want to remove the identity named " "<b>%2</b>?</qt>", "Do you really want to remove theses %2 identities?", numberOfIdentity, identityName);
"<b>%1</b>?</qt>", item->identity().identityName()); if (KMessageBox::warningContinueCancel(this, msg, i18np("Remove Identity", "Remove Identities", numberOfIdentity),
if (KMessageBox::warningContinueCancel(this, msg, i18n("Remove Identity"),
KGuiItem(i18n("&Remove"), KGuiItem(i18n("&Remove"),
QStringLiteral("edit-delete"))) QStringLiteral("edit-delete")))
== KMessageBox::Continue) { == KMessageBox::Continue) {
if (mIdentityManager->removeIdentity(item->identity().identityName())) { for (QTreeWidgetItem *item : selectedItems) {
delete item; IdentityListViewItem *identityItem = dynamic_cast<IdentityListViewItem *>(item);
identityName = identityItem->identity().identityName();
if (mIdentityManager->removeIdentity(identityName)) {
delete item;
}
if (mIPage.mIdentityList->currentItem()) { if (mIPage.mIdentityList->currentItem()) {
mIPage.mIdentityList->currentItem()->setSelected(true); mIPage.mIdentityList->currentItem()->setSelected(true);
} }
refreshList(); refreshList();
updateButtons(); updateButtons();
} }
} }
} }
...@@ -327,12 +339,14 @@ void IdentityPage::slotIdentitySelectionChanged() ...@@ -327,12 +339,14 @@ void IdentityPage::slotIdentitySelectionChanged()
void IdentityPage::updateButtons() void IdentityPage::updateButtons()
{ {
const int numSelectedItems = mIPage.mIdentityList->selectedItems().count();
mIPage.mRemoveButton->setEnabled(numSelectedItems >= 1);
mIPage.mModifyButton->setEnabled(numSelectedItems == 1);
mIPage.mRenameButton->setEnabled(numSelectedItems == 1);
IdentityListViewItem *item = nullptr; IdentityListViewItem *item = nullptr;
if (!mIPage.mIdentityList->selectedItems().isEmpty()) { if (numSelectedItems > 0) {
item = dynamic_cast<IdentityListViewItem *>(mIPage.mIdentityList->selectedItems().first()); item = dynamic_cast<IdentityListViewItem *>(mIPage.mIdentityList->selectedItems().first());
} }
mIPage.mRemoveButton->setEnabled(item && mIPage.mIdentityList->topLevelItemCount() > 1); const bool enableDefaultButton = (numSelectedItems == 1) && item && !item->identity().isDefault();
mIPage.mModifyButton->setEnabled(item); mIPage.mSetAsDefaultButton->setEnabled(enableDefaultButton);
mIPage.mRenameButton->setEnabled(item);
mIPage.mSetAsDefaultButton->setEnabled(item && !item->identity().isDefault());
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment