Commit 889578c4 authored by Laurent Montel's avatar Laurent Montel
Browse files

Adapt to new api (scripted)

parent 9eeafe3a
Pipeline #248486 passed with stage
in 3 minutes and 3 seconds
......@@ -17,8 +17,9 @@
#include <QApplication>
#include <QDebug>
#include <QDrag>
#include <QMimeData>
#include <QIcon>
#include <QMimeData>
#include <kwidgetsaddons_version.h>
/****************
* KWalletFolderItem - ListView items to represent kwallet folders
......@@ -223,11 +224,23 @@ static bool decodeFolder(KWallet::Wallet *_wallet, QDataStream &ds)
QString folder;
ds >> folder;
if (_wallet->hasFolder(folder)) {
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
int rc = KMessageBox::warningTwoActionsCancel(nullptr,
i18n("A folder by the name '%1' already exists. What would you like to do?", folder),
QString(),
KStandardGuiItem::cont(),
KGuiItem(i18n("Replace")));
#else
int rc = KMessageBox::warningYesNoCancel(nullptr, i18n("A folder by the name '%1' already exists. What would you like to do?", folder), QString(), KStandardGuiItem::cont(), KGuiItem(i18n("Replace")));
#endif
if (rc == KMessageBox::Cancel) {
return false;
}
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
if (rc == KMessageBox::ButtonCode::SecondaryAction) {
#else
if (rc == KMessageBox::No) {
#endif
_wallet->removeFolder(folder);
_wallet->createFolder(folder);
}
......
......@@ -49,6 +49,7 @@
#include <cassert>
#include <cstdlib>
#include <kwidgetsaddons_version.h>
QAction *KWalletEditor::_newFolderAction = nullptr;
QAction *KWalletEditor::_deleteFolderAction = nullptr;
......@@ -417,8 +418,20 @@ void KWalletEditor::createFolder()
}
if (_entryList->existsFolder(n)) {
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
int rc = KMessageBox::questionTwoActions(this,
i18n("Sorry, that folder name is in use. Try again?"),
QString(),
KGuiItem(i18n("Try Again")),
KGuiItem(i18n("Do Not Try")));
#else
int rc = KMessageBox::questionYesNo(this, i18n("Sorry, that folder name is in use. Try again?"), QString(), KGuiItem(i18n("Try Again")), KGuiItem(i18n("Do Not Try")));
#endif
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
if (rc == KMessageBox::ButtonCode::PrimaryAction) {
#else
if (rc == KMessageBox::Yes) {
#endif
continue;
}
n.clear();
......@@ -476,8 +489,17 @@ void KWalletEditor::entrySelectionChanged(QTreeWidgetItem *item)
{
// do not forget to save changes
if (_saveChanges->isEnabled() && _displayedItem && (_displayedItem != item)) {
if (KMessageBox::Yes == KMessageBox::questionYesNo(this,
i18n("The contents of the current item has changed.\nDo you want to save changes?"))) {
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
if (KMessageBox::ButtonCode::PrimaryAction
== KMessageBox::questionTwoActions(this,
#else
if (KMessageBox::Yes
== KMessageBox::questionYesNo(this,
#endif
i18n("The contents of the current item has changed.\nDo you want to save changes?"),
{},
KStandardGuiItem::save(),
KStandardGuiItem::cancel())) {
saveEntry();
} else {
_saveChanges->setEnabled(false);
......@@ -774,8 +796,20 @@ void KWalletEditor::newEntry()
// FIXME: prohibits the use of the subheadings
if (fi->contains(n)) {
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
int rc = KMessageBox::questionTwoActions(this,
i18n("Sorry, that entry already exists. Try again?"),
QString(),
KGuiItem(i18n("Try Again")),
KGuiItem(i18n("Do Not Try")));
#else
int rc = KMessageBox::questionYesNo(this, i18n("Sorry, that entry already exists. Try again?"), QString(), KGuiItem(i18n("Try Again")), KGuiItem(i18n("Do Not Try")));
#endif
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
if (rc == KMessageBox::ButtonCode::PrimaryAction) {
#else
if (rc == KMessageBox::Yes) {
#endif
continue;
}
n.clear();
......
......@@ -35,15 +35,15 @@
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QRegExpValidator>
#endif
#include <QTimer>
#include <QFileDialog>
#include <QDialog>
#include <QLineEdit>
#include <QFile>
#include <QFileDialog>
#include <QFileInfo>
#include <QLineEdit>
#include <QMimeDatabase>
#include <QMimeType>
#include <QTimer>
#include <kwidgetsaddons_version.h>
KWalletManager::KWalletManager(QCommandLineParser *commandLineParser)
: KXmlGuiWindow()
......@@ -65,9 +65,21 @@ void KWalletManager::beginConfiguration() {
if (walletConfigGroup.readEntry("Enabled", true)){
QTimer::singleShot(0, this, &KWalletManager::configUI);
} else {
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
int rc = KMessageBox::warningTwoActions(this,
#else
int rc = KMessageBox::warningYesNo(this,
i18n("The KDE Wallet system is not enabled. Do you want me to enable it? If not, the KWalletManager will quit as it cannot work without reading the wallets."));
#endif
i18n("The KDE Wallet system is not enabled. Do you want me to enable it? If not, the KWalletManager will quit "
"as it cannot work without reading the wallets."),
{},
KStandardGuiItem::ok(),
KStandardGuiItem::cancel());
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
if (rc == KMessageBox::ButtonCode::PrimaryAction) {
#else
if (rc == KMessageBox::Yes) {
#endif
walletConfigGroup.writeEntry("Enabled", true);
QTimer::singleShot(0, this, &KWalletManager::configUI);
} else {
......@@ -250,8 +262,21 @@ void KWalletManager::closeWallet(const QString &walletName)
int rc = KWallet::Wallet::closeWallet(walletName, false);
if (rc != 0) {
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
rc =
KMessageBox::warningTwoActions(this,
i18n("Unable to close wallet cleanly. It is probably in use by other applications. Do you wish to force it closed?"),
QString(),
KGuiItem(i18n("Force Closure")),
KGuiItem(i18n("Do Not Force")));
#else
rc = KMessageBox::warningYesNo(this, i18n("Unable to close wallet cleanly. It is probably in use by other applications. Do you wish to force it closed?"), QString(), KGuiItem(i18n("Force Closure")), KGuiItem(i18n("Do Not Force")));
#endif
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
if (rc == KMessageBox::ButtonCode::PrimaryAction) {
#else
if (rc == KMessageBox::Yes) {
#endif
rc = KWallet::Wallet::closeWallet(walletName, true);
if (rc != 0) {
KMessageBox::error(this, i18n("Unable to force the wallet closed. Error code was %1.", rc));
......@@ -350,8 +375,20 @@ void KWalletManager::createWallet()
}
if (_managerWidget->hasWallet(name)) {
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
int rc = KMessageBox::questionTwoActions(this,
i18n("Sorry, that wallet already exists. Try a new name?"),
QString(),
KGuiItem(i18n("Try New")),
KGuiItem(i18n("Do Not Try")));
#else
int rc = KMessageBox::questionYesNo(this, i18n("Sorry, that wallet already exists. Try a new name?"), QString(), KGuiItem(i18n("Try New")), KGuiItem(i18n("Do Not Try")));
#endif
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
if (rc == KMessageBox::ButtonCode::SecondaryAction) {
#else
if (rc == KMessageBox::No) {
#endif
return;
}
lineEdit->clear();
......@@ -490,8 +527,16 @@ bool KWalletManager::hasUnsavedChanges(const QString &name) const
bool KWalletManager::canIgnoreUnsavedChanges()
{
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
int rc = KMessageBox::warningTwoActions(this, i18n("Ignore unsaved changes?"), {}, KGuiItem(i18n("Ignore")), KStandardGuiItem::cancel());
#else
int rc = KMessageBox::warningYesNo(this, i18n("Ignore unsaved changes?"));
#endif
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
return (rc == KMessageBox::ButtonCode::PrimaryAction);
#else
return (rc == KMessageBox::Yes);
#endif
}
void KWalletManager::handleActivate(const QStringList &arguments, const QString &workingDirectory)
......
......@@ -16,6 +16,7 @@
#include <QTimer>
#include <kwidgetsaddons_version.h>
WalletControlWidget::WalletControlWidget(QWidget *parent, const QString &walletName):
QWidget(parent),
......@@ -100,16 +101,37 @@ void WalletControlWidget::onOpenClose()
// TODO create some fancy animation here to make _walletEditor appear or dissapear in a fancy way
if (_wallet) {
if (hasUnsavedChanges()) {
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
int choice = KMessageBox::warningTwoActions(this, i18n("Ignore unsaved changes?"), {}, KGuiItem(i18n("Ignore")), KStandardGuiItem::cancel());
#else
int choice = KMessageBox::warningYesNo(this, i18n("Ignore unsaved changes?"));
#endif
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
if (choice == KMessageBox::ButtonCode::SecondaryAction) {
#else
if (choice == KMessageBox::No) {
#endif
return;
}
}
// Wallet is open, attempt close it
int rc = KWallet::Wallet::closeWallet(_walletName, false);
if (rc != 0) {
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
rc = KMessageBox::warningTwoActions(
this,
i18n("Unable to close wallet cleanly. It is probably in use by other applications. Do you wish to force it closed?"),
QString(),
KGuiItem(i18n("Force Closure")),
KGuiItem(i18n("Do Not Force")));
#else
rc = KMessageBox::warningYesNo(this, i18n("Unable to close wallet cleanly. It is probably in use by other applications. Do you wish to force it closed?"), QString(), KGuiItem(i18n("Force Closure")), KGuiItem(i18n("Do Not Force")));
#endif
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
if (rc == KMessageBox::ButtonCode::PrimaryAction) {
#else
if (rc == KMessageBox::Yes) {
#endif
rc = KWallet::Wallet::closeWallet(_walletName, true);
if (rc != 0) {
KMessageBox::error(this, i18n("Unable to force the wallet closed. Error code was %1.", rc));
......
Supports Markdown
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