Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add settings dialog.

  • Loading branch information...
commit 975b89a48e06c7e60c09fe486c65241f6f507c8d 1 parent cb6b3da
Mike Limansky authored
1  .gitignore
View
@@ -2,6 +2,7 @@ Makefile*
*.o
moc_*
qrc_*
+ui_*
*.pro.user
tinymount
*.qm
27 src/settings.cpp
View
@@ -26,35 +26,34 @@ static const char* NOTIFICATIONS = "Notifications";
static const char* NTF_DEVICES = "Devices";
static const char* NTF_MOUNT = "Mount";
-Settings::Settings()
- : mShowSystemDisks(true)
- , mDeviceNotifications(true)
- , mMountNotifications(true)
+SettingsManager::SettingsManager()
{
readSettings();
}
-Settings& Settings::instance()
+SettingsManager& SettingsManager::instance()
{
- static Settings settings;
+ static SettingsManager settings;
return settings;
}
-void Settings::readSettings()
+void SettingsManager::readSettings()
{
QSettings s("tinymount", "tinymount");
- mShowSystemDisks = s.value(SHOW_SYSTEM_DISKS, true).toBool();
+ settings.showSystemDisks = s.value(SHOW_SYSTEM_DISKS, true).toBool();
s.beginGroup(NOTIFICATIONS);
- mDeviceNotifications = s.value(NTF_DEVICES, true).toBool();
- mMountNotifications= s.value(NTF_MOUNT, true).toBool();
+ settings.deviceNotifications = s.value(NTF_DEVICES, true).toBool();
+ settings.mountNotifications= s.value(NTF_MOUNT, true).toBool();
}
-void Settings::save()
+void SettingsManager::save(const Settings& newSettings)
{
+ settings = newSettings;
+
QSettings s("tinymount", "tinymount");
- s.setValue(SHOW_SYSTEM_DISKS, mShowSystemDisks);
+ s.setValue(SHOW_SYSTEM_DISKS, settings.showSystemDisks);
s.beginGroup(NOTIFICATIONS);
- s.setValue(NTF_DEVICES, mDeviceNotifications);
- s.setValue(NTF_MOUNT, mMountNotifications);
+ s.setValue(NTF_DEVICES, settings.deviceNotifications);
+ s.setValue(NTF_MOUNT, settings.mountNotifications);
}
30 src/settings.h
View
@@ -20,31 +20,29 @@
#ifndef SETTINGS_H
#define SETTINGS_H
-class Settings
+struct Settings
{
-public:
- static Settings& instance();
-
- bool showSystemDisks() const { return mShowSystemDisks; }
- void setShowSystemDisks(bool enabled) { mShowSystemDisks = enabled; }
+ bool showSystemDisks;
+ bool deviceNotifications;
+ bool mountNotifications;
+};
- bool deviceNotifications() const { return mDeviceNotifications; }
- void setDeviceNotifications(bool enabled) { mDeviceNotifications = enabled; }
+class SettingsManager
+{
+public:
+ static SettingsManager& instance();
- bool mountNotifications() const { return mMountNotifications; }
- void setMountNotifications(bool enabled) { mMountNotifications = enabled; }
+ const Settings& getSettings() const { return settings; }
+ void save(const Settings& newSettings);
- void save();
private:
- Settings();
- Settings(const Settings&);
+ SettingsManager();
+ SettingsManager(const SettingsManager&);
void readSettings();
private:
- bool mShowSystemDisks;
- bool mDeviceNotifications;
- bool mMountNotifications;
+ Settings settings;
};
#endif // SETTINGS_H
28 src/settingsdialog.cpp
View
@@ -0,0 +1,28 @@
+#include "settingsdialog.h"
+#include "ui_settingsdialog.h"
+#include "settings.h"
+
+SettingsDialog::SettingsDialog(const Settings& settings, QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::SettingsDialog)
+{
+ ui->setupUi(this);
+ ui->systemDisks->setChecked(settings.showSystemDisks);
+
+ ui->deviceNotify->setChecked(settings.deviceNotifications);
+ ui->mountNotify->setChecked(settings.mountNotifications);
+}
+
+SettingsDialog::~SettingsDialog()
+{
+ delete ui;
+}
+
+Settings SettingsDialog::getSettings()
+{
+ Settings settings;
+ settings.showSystemDisks = ui->systemDisks->isChecked();
+ settings.deviceNotifications = ui->deviceNotify->isChecked();
+ settings.mountNotifications = ui->deviceNotify->isChecked();
+ return settings;
+}
26 src/settingsdialog.h
View
@@ -0,0 +1,26 @@
+#ifndef SETTINGSDIALOG_H
+#define SETTINGSDIALOG_H
+
+#include <QDialog>
+
+namespace Ui {
+ class SettingsDialog;
+}
+
+class Settings;
+
+class SettingsDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit SettingsDialog(const Settings& settings, QWidget *parent = 0);
+ ~SettingsDialog();
+
+ Settings getSettings();
+
+private:
+ Ui::SettingsDialog *ui;
+};
+
+#endif // SETTINGSDIALOG_H
120 src/settingsdialog.ui
View
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>SettingsDialog</class>
+ <widget class="QDialog" name="SettingsDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>329</width>
+ <height>214</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Dialog</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QGroupBox" name="mainGroupBox">
+ <property name="title">
+ <string>General</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <item>
+ <widget class="QCheckBox" name="systemDisks">
+ <property name="text">
+ <string>Show system disks</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="autoMount">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Mount devices automaticaly</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="notifyGroupBox">
+ <property name="title">
+ <string>Notifications</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QCheckBox" name="deviceNotify">
+ <property name="text">
+ <string>Notify when device added/removed</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="mountNotify">
+ <property name="text">
+ <string>Notify when device mounted/unmounted</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <tabstops>
+ <tabstop>systemDisks</tabstop>
+ <tabstop>autoMount</tabstop>
+ <tabstop>deviceNotify</tabstop>
+ <tabstop>mountNotify</tabstop>
+ <tabstop>buttonBox</tabstop>
+ </tabstops>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>SettingsDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>SettingsDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
14 src/src.pro
View
@@ -19,7 +19,7 @@
TEMPLATE = app
TARGET = tinymount
-VERSION = 0.1.95
+VERSION = 0.1.96
DEPENDPATH += .
INCLUDEPATH += .
@@ -40,12 +40,14 @@ SOURCES = \
main.cpp \
diskmanager.cpp \
tinymounttray.cpp \
- settings.cpp
+ settings.cpp \
+ settingsdialog.cpp
HEADERS = \
diskmanager.h \
tinymounttray.h \
- settings.h
+ settings.h \
+ settingsdialog.h
HEADERS += \
udisks/udisksinterface.h \
@@ -75,4 +77,10 @@ INSTALLS = target translations
DEFINES += TINYMOUNT_VERSION=\\\"$${VERSION}\\\" DATADIR=\\\"$${DATADIR}\\\"
+FORMS += \
+ settingsdialog.ui
+
+
+
+
18 src/tinymounttray.cpp
View
@@ -20,6 +20,7 @@
#include "tinymounttray.h"
#include "diskmanager.h"
#include "settings.h"
+#include "settingsdialog.h"
#include <QSystemTrayIcon>
#include <QIcon>
@@ -122,7 +123,7 @@ void TinyMountTray::reloadDevices()
qDeleteAll(handers);
handers.clear();
- bool showSystem = Settings::instance().showSystemDisks();
+ bool showSystem = SettingsManager::instance().getSettings().showSystemDisks;
foreach (const DeviceInfoPtr d, manager->devices())
{
@@ -153,6 +154,7 @@ void TinyMountTray::reloadDevices()
}
trayMenu->addSeparator();
+ trayMenu->addAction(tr("Settings"), this, SLOT(showSettings()));
trayMenu->addAction(tr("About..."), this, SLOT(showAbout()));
trayMenu->addAction(tr("Quit"), qApp, SLOT(quit()));
}
@@ -161,7 +163,7 @@ void TinyMountTray::onDeviceAdded(const DeviceInfo &device)
{
qDebug() << "Device added:" << device.name;
- if (Settings::instance().deviceNotifications())
+ if (SettingsManager::instance().getSettings().deviceNotifications)
tray->showMessage(tr("Device is added"), tr("Device %1 is added").arg(device.name));
reloadDevices();
@@ -171,7 +173,7 @@ void TinyMountTray::onDeviceRemoved(const DeviceInfo& device)
{
qDebug() << "Device removed:" << device.name;
- if (Settings::instance().deviceNotifications())
+ if (SettingsManager::instance().getSettings().deviceNotifications)
tray->showMessage(tr("Device is removed"), tr("Device %1 is removed").arg(device.name));
reloadDevices();
@@ -186,7 +188,7 @@ void TinyMountTray::onMountDone(const QString &devPath, const QString &mountPath
if (DiskManager::OK == status)
{
- if (Settings::instance().mountNotifications())
+ if (SettingsManager::instance().getSettings().mountNotifications)
tray->showMessage(tr("Device is mounted"), tr("%1 is mounted to %2.").arg(d->name).arg(mountPath));
}
else
@@ -204,7 +206,7 @@ void TinyMountTray::onUnmountDone(const QString &devPath, int status)
if (DiskManager::OK == status)
{
- if (Settings::instance().mountNotifications())
+ if (SettingsManager::instance().getSettings().mountNotifications)
tray->showMessage(tr("Device is unmounted"), tr("%1 is unmounted successfuly.").arg(d->name));
}
else
@@ -220,6 +222,12 @@ void TinyMountTray::showAbout()
"Use and redistribute under terms of the GNU General Public License Version 2."));
}
+void TinyMountTray::showSettings()
+{
+ SettingsDialog dlg(SettingsManager::instance().getSettings());
+ dlg.exec();
+}
+
EventHandler::EventHandler(const QString &id, DiskManager &diskManager, QObject *parent)
: QObject(parent)
, deviceId(id)
1  src/tinymounttray.h
View
@@ -39,6 +39,7 @@ public slots:
void onDeviceRemoved(const DeviceInfo& device);
void reloadDevices();
void showAbout();
+ void showSettings();
void onMountDone(const QString& devPath, const QString& mountPath, int status);
void onUnmountDone(const QString& devPath, int status);
Please sign in to comment.
Something went wrong with that request. Please try again.