Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 63bc26c6 authored by Henrik Fehlauer's avatar Henrik Fehlauer

Refactor saveMode handling to use enums instead of ints

Summary:
Things like `case 0` make it really hard to work with the code and
having access to the current state of the {nav Save} button is needed
for a subsequent patch.

Test Plan: Spectacle still remembers the last used save state, defaults work too.

Reviewers: #spectacle, ngraham

Reviewed By: #spectacle, ngraham

Subscribers: ngraham

Differential Revision: https://phabricator.kde.org/D10467
parent 6742051c
......@@ -106,6 +106,12 @@ KSMainWindow::KSMainWindow(bool onClickAvailable, QWidget *parent) :
KSMainWindow::~KSMainWindow()
{}
SaveMode KSMainWindow::saveButtonMode() const
{
const SpectacleConfig *cfgManager = SpectacleConfig::instance();
return cfgManager->useDynamicSaveButton() ? cfgManager->lastUsedSaveMode() : SaveMode::SaveAs;
}
// GUI init
void KSMainWindow::init()
......@@ -225,18 +231,13 @@ void KSMainWindow::buildSaveMenu()
QAction *actionSave = KStandardAction::save(this, &KSMainWindow::save, this);
QAction *actionSaveAs = KStandardAction::saveAs(this, &KSMainWindow::saveAs, this);
// static or dynamic
SpectacleConfig *cfgManager = SpectacleConfig::instance();
int switchState = cfgManager->useDynamicSaveButton() ? cfgManager->lastUsedSaveMode() : 0;
// put the actions in order
switch (switchState) {
case 0:
default:
switch (saveButtonMode()) {
case SaveMode::SaveAs:
mSaveButton->setDefaultAction(actionSaveAs);
mSaveMenu->addAction(actionSave);
break;
case 1:
case SaveMode::Save:
mSaveButton->setDefaultAction(actionSave);
mSaveMenu->addAction(actionSaveAs);
break;
......@@ -339,7 +340,7 @@ void KSMainWindow::setScreenshotWindowTitle(QUrl location)
void KSMainWindow::save()
{
SpectacleConfig::instance()->setLastUsedSaveMode(1);
SpectacleConfig::instance()->setLastUsedSaveMode(SaveMode::Save);
buildSaveMenu();
if (SpectacleConfig::instance()->quitAfterSaveOrCopyChecked()) {
......@@ -354,7 +355,7 @@ void KSMainWindow::save()
void KSMainWindow::saveAs()
{
SpectacleConfig::instance()->setLastUsedSaveMode(0);
SpectacleConfig::instance()->setLastUsedSaveMode(SaveMode::SaveAs);
buildSaveMenu();
if (SpectacleConfig::instance()->quitAfterSaveOrCopyChecked()) {
......
......@@ -31,6 +31,7 @@
#include "PlatformBackends/ImageGrabber.h"
#include "ExportMenu.h"
#include "KSWidget.h"
#include "SpectacleConfig.h"
class KSMainWindow : public QDialog
{
......@@ -41,6 +42,10 @@ class KSMainWindow : public QDialog
explicit KSMainWindow(bool onClickAvailable, QWidget *parent = 0);
~KSMainWindow();
private:
SaveMode saveButtonMode() const;
private slots:
void captureScreenshot(ImageGrabber::GrabMode mode, int timeout, bool includePointer, bool includeDecorations);
......
......@@ -197,14 +197,14 @@ void SpectacleConfig::setUseLightRegionMaskColour(bool enabled)
// last used save mode
int SpectacleConfig::lastUsedSaveMode() const
SaveMode SpectacleConfig::lastUsedSaveMode() const
{
return mGuiConfig.readEntry(QStringLiteral("lastUsedSaveMode"), 0);
return static_cast<SaveMode>(mGuiConfig.readEntry(QStringLiteral("lastUsedSaveMode"), 0));
}
void SpectacleConfig::setLastUsedSaveMode(int index)
void SpectacleConfig::setLastUsedSaveMode(SaveMode mode)
{
mGuiConfig.writeEntry(QStringLiteral("lastUsedSaveMode"), index);
mGuiConfig.writeEntry(QStringLiteral("lastUsedSaveMode"), static_cast<int>(mode));
mGuiConfig.sync();
}
......
......@@ -27,6 +27,11 @@
#include <KSharedConfig>
#include <KConfigGroup>
enum SaveMode {
SaveAs,
Save
};
class SpectacleConfig : public QObject
{
Q_OBJECT
......@@ -85,8 +90,8 @@ class SpectacleConfig : public QObject
bool useLightRegionMaskColour() const;
void setUseLightRegionMaskColour(bool enabled);
int lastUsedSaveMode() const;
void setLastUsedSaveMode(int index);
SaveMode lastUsedSaveMode() const;
void setLastUsedSaveMode(SaveMode mode);
QString autoSaveFilenameFormat() const;
void setAutoSaveFilenameFormat(const QString &format);
......
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