drop KNotifications from settings window

--introduce a new dependency for KIO, it works
really nice in order to open files in filemanager
and selecting them
pull/11/head
Michail Vourlakos 5 years ago
parent 01bab50d67
commit 6e09bb5601

@ -21,7 +21,7 @@ find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED NO_MODULE COMPONENTS DBus Gui
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
Activities Archive CoreAddons GuiAddons Crash DBusAddons Declarative GlobalAccel I18n
IconThemes NewStuff Notifications Plasma PlasmaQuick Wayland WindowSystem XmlGui)
IconThemes KIO NewStuff Notifications Plasma PlasmaQuick Wayland WindowSystem XmlGui)
find_package(X11 REQUIRED)
set_package_properties(X11 PROPERTIES DESCRIPTION "X11 libraries"

@ -45,6 +45,7 @@ Minimum requirements:
KF5Package >= 5.38.0
KF5XmlGui >= 5.38.0
KF5IconThemes >= 5.38.0
KF5KIO >= 5.38.0
KF5I18n >= 5.38.0
KF5Notifications >= 5.38.0
KF5NewStuff >= 5.38.0

@ -51,6 +51,7 @@ if(${KF5_VERSION_MINOR} LESS "62")
KF5::GlobalAccel
KF5::I18n
KF5::IconThemes
KF5::KIOWidgets
KF5::Notifications
KF5::NewStuff
KF5::QuickAddons
@ -75,6 +76,7 @@ else()
KF5::GlobalAccel
KF5::I18n
KF5::IconThemes
KF5::KIOWidgets
KF5::Notifications
KF5::NewStuff
KF5::QuickAddons

@ -453,7 +453,7 @@ void Layouts::loadLayouts()
//! there are broken layouts and the user must be informed!
if (brokenLayouts.count() > 0) {
if (brokenLayouts.count() == 1) {
m_parentDialog->showInlineMessage(i18nc("settings:broken layouts", "Layout <b>%0</b> <i/>is broken</i>! Please <b>remove it</b> to improve stability...").arg(brokenLayouts.join(",")),
m_parentDialog->showInlineMessage(i18nc("settings:broken layout", "Layout <b>%0</b> <i/>is broken</i>! Please <b>remove it</b> to improve stability...").arg(brokenLayouts.join(",")),
KMessageWidget::Error);
} else {
m_parentDialog->showInlineMessage(i18nc("settings:broken layouts", "Layouts <b>%0</b> <i/>are broken</i>! Please <b>remove them</b> to improve stability...").arg(brokenLayouts.join(",")),

@ -38,7 +38,6 @@
// Qt
#include <QButtonGroup>
#include <QColorDialog>
#include <QDesktopServices>
#include <QDir>
#include <QFileDialog>
#include <QMenuBar>
@ -47,8 +46,8 @@
// KDE
#include <KActivities/Controller>
#include <KIO/OpenFileManagerWindowJob>
#include <KLocalizedString>
#include <KNotification>
#include <KWindowSystem>
#include <KNewStuff3/KNS3/DownloadDialog>
@ -59,6 +58,7 @@ const int SCREENTRACKERDEFAULTVALUE = 2500;
const int OUTLINEDEFAULTWIDTH = 1;
const int SettingsDialog::INFORMATIONINTERVAL;
const int SettingsDialog::INFORMATIONWITHACTIONINTERVAL;
const int SettingsDialog::WARNINGINTERVAL;
const int SettingsDialog::ERRORINTERVAL;
@ -137,6 +137,15 @@ SettingsDialog::SettingsDialog(QWidget *parent, Latte::Corona *corona)
m_editLayoutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_E));
m_editLayoutAction->setToolTip("You can edit layout file when layout is not active or locked");
m_openUrlAction = new QAction(i18n("Open Location..."), this);
connect(m_openUrlAction, &QAction::triggered, this, [&]() {
QString file = m_openUrlAction->data().toString();
if (!file.isEmpty()) {
KIO::highlightInFileManager({file});
}
});
QAction *infoLayoutAction = layoutMenu->addAction(i18nc("layout information","&Information..."));
infoLayoutAction->setIcon(QIcon::fromTheme("document-properties"));
infoLayoutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_I));
@ -226,6 +235,11 @@ SettingsDialog::SettingsDialog(QWidget *parent, Latte::Corona *corona)
m_hideInlineMessageTimer.setInterval(2000);
connect(&m_hideInlineMessageTimer, &QTimer::timeout, this, [&]() {
ui->messageWidget->animatedHide();
ui->messageWidget->removeAction(m_openUrlAction);
});
connect(ui->messageWidget, &KMessageWidget::hideAnimationFinished, this, [&]() {
ui->messageWidget->removeAction(m_openUrlAction);
});
}
@ -336,24 +350,24 @@ void SettingsDialog::on_importButton_clicked()
qDebug() << Q_FUNC_INFO;
QFileDialog *fileDialog = new QFileDialog(this, i18nc("import layout/configuration", "Import Layout/Configuration")
QFileDialog *importFileDialog = new QFileDialog(this, i18nc("import layout/configuration", "Import Layout/Configuration")
, QDir::homePath()
, QStringLiteral("layout.latte"));
fileDialog->setFileMode(QFileDialog::AnyFile);
fileDialog->setAcceptMode(QFileDialog::AcceptOpen);
fileDialog->setDefaultSuffix("layout.latte");
importFileDialog->setWindowIcon(QIcon::fromTheme("favorites"));
importFileDialog->setLabelText(QFileDialog::Accept, i18nc("import layout","Import"));
importFileDialog->setFileMode(QFileDialog::AnyFile);
importFileDialog->setAcceptMode(QFileDialog::AcceptOpen);
importFileDialog->setDefaultSuffix("layout.latte");
QStringList filters;
filters << QString(i18nc("import latte layout", "Latte Dock Layout file v0.2") + "(*.layout.latte)")
<< QString(i18nc("import latte layouts/configuration", "Latte Dock Full Configuration file (v0.1, v0.2)") + "(*.latterc)");
fileDialog->setNameFilters(filters);
importFileDialog->setNameFilters(filters);
connect(fileDialog, &QFileDialog::finished
, fileDialog, &QFileDialog::deleteLater);
connect(importFileDialog, &QFileDialog::finished, importFileDialog, &QFileDialog::deleteLater);
connect(fileDialog, &QFileDialog::fileSelected
, this, [&](const QString & file) {
connect(importFileDialog, &QFileDialog::fileSelected, this, [&](const QString & file) {
Layouts::Importer::LatteFileVersion version = Layouts::Importer::fileVersion(file);
qDebug() << "VERSION :::: " << version;
@ -419,7 +433,7 @@ void SettingsDialog::on_importButton_clicked()
}
});
fileDialog->open();
importFileDialog->open();
}
void SettingsDialog::on_exportButton_clicked()
@ -428,7 +442,7 @@ void SettingsDialog::on_exportButton_clicked()
return;
}
QString layoutExported = m_layoutsController->selectedLayout().id;
Settings::Data::Layout selectedLayout = m_layoutsController->selectedLayout();
//! Update ALL active original layouts before exporting,
//! this is needed because the export method can export also the full configuration
@ -436,12 +450,13 @@ void SettingsDialog::on_exportButton_clicked()
m_corona->layoutsManager()->synchronizer()->syncActiveLayoutsToOriginalFiles();
QFileDialog *fileDialog = new QFileDialog(this, i18nc("export layout/configuration", "Export Layout/Configuration")
QFileDialog *exportFileDialog = new QFileDialog(this, i18nc("export layout/configuration", "Export Layout/Configuration")
, QDir::homePath(), QStringLiteral("layout.latte"));
fileDialog->setFileMode(QFileDialog::AnyFile);
fileDialog->setAcceptMode(QFileDialog::AcceptSave);
fileDialog->setDefaultSuffix("layout.latte");
exportFileDialog->setLabelText(QFileDialog::Accept, i18nc("export layout","Export"));
exportFileDialog->setFileMode(QFileDialog::AnyFile);
exportFileDialog->setAcceptMode(QFileDialog::AcceptSave);
exportFileDialog->setDefaultSuffix("layout.latte");
QStringList filters;
QString filter1(i18nc("export layout", "Latte Dock Layout file v0.2") + "(*.layout.latte)");
@ -450,27 +465,24 @@ void SettingsDialog::on_exportButton_clicked()
filters << filter1
<< filter2;
fileDialog->setNameFilters(filters);
exportFileDialog->setNameFilters(filters);
connect(fileDialog, &QFileDialog::finished
, fileDialog, &QFileDialog::deleteLater);
connect(exportFileDialog, &QFileDialog::finished, exportFileDialog, &QFileDialog::deleteLater);
connect(fileDialog, &QFileDialog::fileSelected
, this, [ &, layoutExported](const QString & file) {
auto showNotificationError = []() {
auto notification = new KNotification("export-fail", KNotification::CloseOnTimeout);
notification->setText(i18nc("export layout", "Failed to export layout"));
notification->sendEvent();
connect(exportFileDialog, &QFileDialog::fileSelected, this, [ &, selectedLayout](const QString & file) {
auto showExportLayoutError = [this](const Settings::Data::Layout &layout) {
showInlineMessage(i18nc("settings:layout export fail","<b>%0</b> export failed...").arg(layout.currentName()),
KMessageWidget::Error);
};
if (QFile::exists(file) && !QFile::remove(file)) {
showNotificationError();
showExportLayoutError(selectedLayout);
return;
}
if (file.endsWith(".layout.latte")) {
if (!QFile(layoutExported).copy(file)) {
showNotificationError();
if (!QFile(selectedLayout.id).copy(file)) {
showExportLayoutError(selectedLayout);
return;
}
@ -484,44 +496,31 @@ void SettingsDialog::on_exportButton_clicked()
layoutS.setActivities(QStringList());
layoutS.clearLastUsedActivity();
//NOTE: The pointer is automatically deleted when the event is closed
auto notification = new KNotification("export-done", KNotification::CloseOnTimeout);
notification->setActions({i18nc("export layout", "Open location")});
notification->setText(i18nc("export layout", "Layout exported successfully"));
connect(notification, &KNotification::action1Activated
, this, [file]() {
QDesktopServices::openUrl({QFileInfo(file).canonicalPath()});
});
notification->sendEvent();
m_openUrlAction->setData(file);
ui->messageWidget->addAction(m_openUrlAction);
showInlineMessage(i18nc("settings:layout export success","<b>%0</b> export succeeded...").arg(selectedLayout.currentName()),
KMessageWidget::Information,
SettingsDialog::INFORMATIONWITHACTIONINTERVAL);
} else if (file.endsWith(".latterc")) {
auto showNotificationError = []() {
auto notification = new KNotification("export-fail", KNotification::CloseOnTimeout);
notification->setText(i18nc("import/export config", "Failed to export configuration"));
notification->sendEvent();
auto showExportConfigurationError = [this]() {
showInlineMessage(i18nc("settings:full configuration export fail","Full configuration export failed..."),
KMessageWidget::Error);
};
if (m_corona->layoutsManager()->importer()->exportFullConfiguration(file)) {
auto notification = new KNotification("export-done", KNotification::CloseOnTimeout);
notification->setActions({i18nc("import/export config", "Open location")});
notification->setText(i18nc("import/export config", "Full Configuration exported successfully"));
connect(notification, &KNotification::action1Activated
, this, [file]() {
QDesktopServices::openUrl({QFileInfo(file).canonicalPath()});
});
notification->sendEvent();
m_openUrlAction->setData(file);
ui->messageWidget->addAction(m_openUrlAction);
showInlineMessage(i18nc("settings:full configuration export success","Full configuration export succeeded..."),
KMessageWidget::Information,
SettingsDialog::INFORMATIONWITHACTIONINTERVAL);
} else {
showNotificationError();
showExportConfigurationError();
}
}
});
fileDialog->open();
exportFileDialog->open();
exportFileDialog->selectFile(selectedLayout.currentName());
}
void SettingsDialog::requestImagesDialog(int row)
@ -661,7 +660,8 @@ void SettingsDialog::on_switchButton_clicked()
bool hasChanges = (selectedLayout.nameWasEdited() || m_layoutsController->dataAreChanged());
if (hasChanges) {
showInlineMessage(i18nc("settings:not permitted switching layout","You need to save your changes to switch layout."), KMessageWidget::Warning);
showInlineMessage(i18nc("settings:not permitted switching layout","You need to save your changes to switch layout."),
KMessageWidget::Warning);
return;
}

@ -58,6 +58,7 @@ class SettingsDialog : public QDialog
Q_OBJECT
public:
static const int INFORMATIONINTERVAL = 3000;
static const int INFORMATIONWITHACTIONINTERVAL = 5000;
static const int WARNINGINTERVAL = 3000;
static const int ERRORINTERVAL = 3000;
@ -112,6 +113,7 @@ private:
QButtonGroup *m_inMemoryButtons;
QButtonGroup *m_mouseSensitivityButtons;
QAction *m_openUrlAction{nullptr};
QAction *m_editLayoutAction{nullptr};
KHelpMenu *m_helpMenu{nullptr};
@ -123,6 +125,8 @@ private:
//! original data
QList<int> o_settingsOriginalData;
};
}

Loading…
Cancel
Save