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)
setAlternatingRowColors(true);
setSortingEnabled(true);
sortByColumn(0, Qt::AscendingOrder);
setSelectionMode(SingleSelection); // ### Extended would be nicer...
setSelectionMode(ExtendedSelection);
setColumnWidth(0, 175);
setContextMenuPolicy(Qt::CustomContextMenu);
......
......@@ -40,6 +40,8 @@
#include <KLocalizedString>
#include "kmail_debug.h"
#include <QTreeWidgetItem>
using namespace KMail;
QString IdentityPage::helpAnchor() const
......@@ -216,28 +218,38 @@ void IdentityPage::slotRemoveIdentity()
qCritical() << "Attempted to remove the last identity!";
}
const int numberOfIdentity = mIPage.mIdentityList->selectedItems().count();
QString identityName;
IdentityListViewItem *item = nullptr;
const QList<QTreeWidgetItem *> selectedItems = mIPage.mIdentityList->selectedItems();
if (numberOfIdentity == 1) {
if (!mIPage.mIdentityList->selectedItems().isEmpty()) {
item = dynamic_cast<IdentityListViewItem *>(mIPage.mIdentityList->selectedItems().at(0));
}
if (!item) {
return;
}
const QString msg = i18n("<qt>Do you really want to remove the identity named "
"<b>%1</b>?</qt>", item->identity().identityName());
if (KMessageBox::warningContinueCancel(this, msg, i18n("Remove Identity"),
identityName = item->identity().identityName();
}
const QString msg = i18np("<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);
if (KMessageBox::warningContinueCancel(this, msg, i18np("Remove Identity", "Remove Identities", numberOfIdentity),
KGuiItem(i18n("&Remove"),
QStringLiteral("edit-delete")))
== KMessageBox::Continue) {
if (mIdentityManager->removeIdentity(item->identity().identityName())) {
for (QTreeWidgetItem *item : selectedItems) {
IdentityListViewItem *identityItem = dynamic_cast<IdentityListViewItem *>(item);
identityName = identityItem->identity().identityName();
if (mIdentityManager->removeIdentity(identityName)) {
delete item;
}
if (mIPage.mIdentityList->currentItem()) {
mIPage.mIdentityList->currentItem()->setSelected(true);
}
refreshList();
updateButtons();
}
}
}
......@@ -327,12 +339,14 @@ void IdentityPage::slotIdentitySelectionChanged()
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;
if (!mIPage.mIdentityList->selectedItems().isEmpty()) {
if (numSelectedItems > 0) {
item = dynamic_cast<IdentityListViewItem *>(mIPage.mIdentityList->selectedItems().first());
}
mIPage.mRemoveButton->setEnabled(item && mIPage.mIdentityList->topLevelItemCount() > 1);
mIPage.mModifyButton->setEnabled(item);
mIPage.mRenameButton->setEnabled(item);
mIPage.mSetAsDefaultButton->setEnabled(item && !item->identity().isDefault());
const bool enableDefaultButton = (numSelectedItems == 1) && item && !item->identity().isDefault();
mIPage.mSetAsDefaultButton->setEnabled(enableDefaultButton);
}
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