Skip to content

Commit

Permalink
Fix KDE 5.100 deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromerobert committed Jun 19, 2023
1 parent 13d4ced commit d94cab5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
27 changes: 19 additions & 8 deletions src/k4dirstat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "ktreemapview.h"
#include <KIO/ApplicationLauncherJob>
#include <KIO/JobUiDelegate>
#include <KIO/JobUiDelegateFactory>
#include <KHelpClient>
#include <KIconEngine>
#include <KIconLoader>
Expand All @@ -54,7 +55,7 @@
#include <QSplitter>
#include <QStorageInfo>
#include <QLabel>

#include <kwidgetsaddons_version.h>
#include "settings.h"

#define USER_CLEANUPS 10 // Number of user cleanup actions
Expand Down Expand Up @@ -477,14 +478,20 @@ void k4dirstat::askWriteCache() {

if (access(file_name.toLatin1(), F_OK) == 0) // file exists
{
int button = KMessageBox::questionYesNoCancel(
this, i18n("File %1 exists. Overwrite?", file_name),
i18n("Overwrite?")); // caption

if (button == KMessageBox::Cancel)
return;
auto msg = i18n("File %1 exists. Overwrite?", file_name);
auto title = i18n("Overwrite?");
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
int button = KMessageBox::questionTwoActionsCancel(this, msg, title,
KStandardGuiItem::overwrite(), KStandardGuiItem::back());
if (button == KMessageBox::SecondaryAction)
file_name = "";
#else
int button = KMessageBox::questionYesNoCancel(this, msg, title);
if (button == KMessageBox::No)
file_name = "";
#endif
if (button == KMessageBox::Cancel)
return;
}
} while (file_name.isEmpty());

Expand All @@ -493,7 +500,7 @@ void k4dirstat::askWriteCache() {
if (!_treeView || !_treeView->writeCache(file_name)) {
QString errMsg = i18n("Error writing cache file %1", file_name);
statusMsg(errMsg);
KMessageBox::sorry(this, errMsg,
KMessageBox::error(this, errMsg,
i18n("Write Error")); // caption
}

Expand Down Expand Up @@ -540,7 +547,11 @@ void k4dirstat::cleanupOpenWith() {
QUrl::AssumeLocalFile));
auto *job = new KIO::ApplicationLauncherJob();
job->setUrls(urlList);
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
#else
job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
#endif
job->start();
}

Expand Down
15 changes: 10 additions & 5 deletions src/kdirstatsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <KSharedConfig>
#include <QGroupBox>
#include <QMenu>
#include <kwidgetsaddons_version.h>

using namespace KDirStat;

Expand Down Expand Up @@ -714,14 +715,18 @@ void KGeneralSettingsPage::deleteExcludeRule() {

if (item) {
QString excludeRule = item->text();
int result = KMessageBox::questionYesNo(
this, i18n("Really delete exclude rule \"%1\"?", excludeRule),
i18n("Delete?")); // Window title
if (result == KMessageBox::Yes) {
auto msg = i18n("Really delete exclude rule \"%1\"?", excludeRule);
auto title = i18n("Delete?");
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
bool doIt = KMessageBox::questionTwoActions(this, msg, title,
KStandardGuiItem::del(), KStandardGuiItem::cancel()) == KMessageBox::PrimaryAction;
#else
bool doIt = KMessageBox::questionYesNo(this, msg, title) == KMessageBox::Yes;
#endif
if (doIt) {
_excludeRulesListView->takeItem(_excludeRulesListView->currentRow());
}
}

checkEnabledState();
}

Expand Down
11 changes: 11 additions & 0 deletions src/kstdcleanup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include <KIO/JobUiDelegate>
#include <KJobWidgets>
#include <KLocalizedString>
#include <kio_version.h>
#if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0)
#include <KIO/DeleteOrTrashJob>
#endif

using namespace KDirStat;

Expand Down Expand Up @@ -121,6 +125,7 @@ TrashBinCleanup::TrashBinCleanup()
i18n("Delete (to Trash &Bin)")) {}

static void konqOperationsDel(QWidget *m_mainWindow, const QList<QUrl> &urls) {
#if KIO_VERSION < QT_VERSION_CHECK(5, 100, 0)
KIO::JobUiDelegate uiDelegate;
uiDelegate.setWindow(m_mainWindow);
if (uiDelegate.askDeleteConfirmation(
Expand All @@ -133,6 +138,12 @@ static void konqOperationsDel(QWidget *m_mainWindow, const QList<QUrl> &urls) {
job->uiDelegate()->setAutoErrorHandlingEnabled(
true); // or connect to the result signal
}
#else
using Iface = KIO::AskUserActionInterface;
auto * job = new KIO::DeleteOrTrashJob(urls, Iface::Trash,
Iface::DefaultConfirmation, m_mainWindow);
job->start();
#endif
}

void TrashBinCleanup::execute(KDirTree * tree) {
Expand Down

0 comments on commit d94cab5

Please sign in to comment.