Skip to content

Commit e452c15

Browse files
Mike LimanskyMike Limansky
authored andcommitted
Add setting to turn system notifications on/off.
1 parent a6039cb commit e452c15

5 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/settings.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ static const char* ITEM_FORMAT = "ItemFormat";
2727
static const char* NOTIFICATIONS = "Notifications";
2828
static const char* NTF_DEVICES = "Devices";
2929
static const char* NTF_MOUNT = "Mount";
30+
#ifdef WITH_LIBNOTIFY
31+
static const char* USE_LIBNOTIFY = "UseLibNotify";
32+
#endif
33+
3034

3135
static const char* DEFAULT_ITEM_FORMAT = "%name% (%fs%) %size%";
3236

@@ -51,6 +55,9 @@ void SettingsManager::readSettings()
5155
s.beginGroup(NOTIFICATIONS);
5256
settings.deviceNotifications = s.value(NTF_DEVICES, true).toBool();
5357
settings.mountNotifications= s.value(NTF_MOUNT, true).toBool();
58+
#ifdef WITH_LIBNOTIFY
59+
settings.useLibnotify = s.value(USE_LIBNOTIFY, true).toBool();
60+
#endif
5461
}
5562

5663
void SettingsManager::save(const Settings& newSettings)
@@ -64,6 +71,9 @@ void SettingsManager::save(const Settings& newSettings)
6471
s.beginGroup(NOTIFICATIONS);
6572
s.setValue(NTF_DEVICES, settings.deviceNotifications);
6673
s.setValue(NTF_MOUNT, settings.mountNotifications);
74+
#ifdef WITH_LIBNOTIFY
75+
s.setValue(USE_LIBNOTIFY, settings.useLibnotify);
76+
#endif
6777
}
6878

6979
QString SettingsManager::defaultItemFormat()

src/settings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ struct Settings
2828
bool deviceNotifications;
2929
bool mountNotifications;
3030
bool mountAutomaticaly;
31+
#ifdef WITH_LIBNOTIFY
32+
bool useLibnotify;
33+
#endif
3134
QString itemFormat;
3235
};
3336

src/settingsdialog.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ SettingsDialog::SettingsDialog(const Settings& settings, QWidget *parent) :
1414
ui->mountNotify->setChecked(settings.mountNotifications);
1515

1616
ui->itemFormat->setText(settings.itemFormat);
17+
#ifdef WITH_LIBNOTIFY
18+
useLibNotify = new QCheckBox(tr("Use system notifications"));
19+
useLibNotify->setChecked(settings.useLibnotify);
20+
ui->notifyGroupBox->layout()->addWidget(useLibNotify);
21+
#endif
1722
}
1823

1924
SettingsDialog::~SettingsDialog()
@@ -30,6 +35,10 @@ Settings SettingsDialog::getSettings()
3035
settings.deviceNotifications = ui->deviceNotify->isChecked();
3136
settings.mountNotifications = ui->deviceNotify->isChecked();
3237

38+
#ifdef WITH_LIBNOTIFY
39+
settings.useLibnotify = useLibNotify->isChecked();
40+
#endif
41+
3342
settings.itemFormat = ui->itemFormat->text();
3443
return settings;
3544
}

src/settingsdialog.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ namespace Ui {
88
}
99

1010
class Settings;
11+
#ifdef WITH_LIBNOTIFY
12+
class QCheckBox;
13+
#endif
1114

1215
class SettingsDialog : public QDialog
1316
{
@@ -26,6 +29,9 @@ private slots:
2629

2730
private:
2831
Ui::SettingsDialog *ui;
32+
#ifdef WITH_LIBNOTIFY
33+
QCheckBox* useLibNotify;
34+
#endif
2935
};
3036

3137
#endif // SETTINGSDIALOG_H

src/tinymounttray.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,14 @@ void TinyMountTray::showSettings()
283283
void TinyMountTray::showNotification(const QString& title, const QString &message)
284284
{
285285
#ifdef WITH_LIBNOTIFY
286-
notifier->showNotification(title, message);
286+
if (SettingsManager::instance().getSettings().useLibnotify)
287+
{
288+
notifier->showNotification(title, message);
289+
}
290+
else
291+
{
292+
tray->showMessage(title, message);
293+
}
287294
#else
288295
tray->showMessage(title, message);
289296
#endif

0 commit comments

Comments
 (0)