Skip to content

Commit c1e7603

Browse files
Mike LimanskyMike Limansky
authored andcommitted
Add setting to hide the tray icon if there are no connected devices.
1 parent baf33e8 commit c1e7603

File tree

8 files changed

+61
-30
lines changed

8 files changed

+61
-30
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
TinyMount-0.2.4
2+
- Add setting to hide the tray icon if there are no connected devices.
3+
14
TinyMount-0.2.2
25
---------------
36
- Add libnotify support.

src/settings.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <QSettings>
2222

2323
static const char* SHOW_SYSTEM_DISKS = "ShowSystemDisks";
24+
static const char* HIDE_ICON = "HideIcon";
2425
static const char* MOUNT_AUTOMATICALY = "MountAutomaticaly";
2526
static const char* ITEM_FORMAT = "ItemFormat";
2627

@@ -49,6 +50,7 @@ void SettingsManager::readSettings()
4950
{
5051
QSettings s("tinymount", "tinymount");
5152
settings.showSystemDisks = s.value(SHOW_SYSTEM_DISKS, true).toBool();
53+
settings.hideIcon = s.value(HIDE_ICON, false).toBool();
5254
settings.mountAutomaticaly = s.value(MOUNT_AUTOMATICALY, false).toBool();
5355
settings.itemFormat = s.value(ITEM_FORMAT, DEFAULT_ITEM_FORMAT).toString();
5456

@@ -66,8 +68,10 @@ void SettingsManager::save(const Settings& newSettings)
6668

6769
QSettings s("tinymount", "tinymount");
6870
s.setValue(SHOW_SYSTEM_DISKS, settings.showSystemDisks);
71+
s.setValue(HIDE_ICON, settings.hideIcon);
6972
s.setValue(MOUNT_AUTOMATICALY, settings.mountAutomaticaly);
7073
s.setValue(ITEM_FORMAT, settings.itemFormat);
74+
7175
s.beginGroup(NOTIFICATIONS);
7276
s.setValue(NTF_DEVICES, settings.deviceNotifications);
7377
s.setValue(NTF_MOUNT, settings.mountNotifications);

src/settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
struct Settings
2626
{
2727
bool showSystemDisks;
28+
bool hideIcon;
2829
bool deviceNotifications;
2930
bool mountNotifications;
3031
bool mountAutomaticaly;

src/settingsdialog.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ SettingsDialog::SettingsDialog(const Settings& settings, QWidget *parent) :
88
{
99
ui->setupUi(this);
1010
ui->systemDisks->setChecked(settings.showSystemDisks);
11+
ui->hideIcon->setChecked(settings.hideIcon);
1112
ui->autoMount->setChecked(settings.mountAutomaticaly);
1213

1314
ui->deviceNotify->setChecked(settings.deviceNotifications);
@@ -30,6 +31,7 @@ Settings SettingsDialog::getSettings()
3031
{
3132
Settings settings;
3233
settings.showSystemDisks = ui->systemDisks->isChecked();
34+
settings.hideIcon = ui->hideIcon->isChecked();
3335
settings.mountAutomaticaly = ui->autoMount->isChecked();
3436

3537
settings.deviceNotifications = ui->deviceNotify->isChecked();

src/settingsdialog.ui

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>419</width>
10-
<height>265</height>
10+
<height>267</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -27,6 +27,13 @@
2727
</property>
2828
</widget>
2929
</item>
30+
<item>
31+
<widget class="QCheckBox" name="hideIcon">
32+
<property name="text">
33+
<string>Hide icon if there are no devices</string>
34+
</property>
35+
</widget>
36+
</item>
3037
<item>
3138
<widget class="QCheckBox" name="autoMount">
3239
<property name="enabled">
@@ -112,7 +119,10 @@ p, li { white-space: pre-wrap; }
112119
</widget>
113120
<tabstops>
114121
<tabstop>systemDisks</tabstop>
122+
<tabstop>hideIcon</tabstop>
115123
<tabstop>autoMount</tabstop>
124+
<tabstop>itemFormat</tabstop>
125+
<tabstop>resetFormatButton</tabstop>
116126
<tabstop>deviceNotify</tabstop>
117127
<tabstop>mountNotify</tabstop>
118128
<tabstop>buttonBox</tabstop>

src/src.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
TEMPLATE = app
2121
TARGET = tinymount
22-
VERSION = 0.2.2
22+
VERSION = 0.2.4
2323

2424
DEPENDPATH += .
2525
INCLUDEPATH += .
@@ -63,7 +63,7 @@ RESOURCES += tinymount.qrc
6363

6464
TRANSLATIONS = translations/tinymount_ru.ts
6565

66-
# CONFIG += with_libnotify
66+
CONFIG += with_libnotify
6767

6868
with_libnotify {
6969
DEFINES += WITH_LIBNOTIFY

src/tinymounttray.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,14 @@ void TinyMountTray::reloadDevices()
140140
trayMenu->clear();
141141

142142
bool showSystem = SettingsManager::instance().getSettings().showSystemDisks;
143+
bool hasDevices = false;
143144

144145
foreach (const DeviceInfoPtr d, manager->devices())
145146
{
146147
if (!showSystem && d->isSystem) continue;
147148

149+
hasDevices = true;
150+
148151
QIcon icon;
149152
QString text = SettingsManager::instance().getSettings().itemFormat;
150153
text.replace("%name%", d->name).replace("%fs%", d->fileSystem).replace("%size%", formatFileSize(d->size));
@@ -179,6 +182,8 @@ void TinyMountTray::reloadDevices()
179182
trayMenu->addAction(tr("Settings"), this, SLOT(showSettings()));
180183
trayMenu->addAction(tr("About..."), this, SLOT(showAbout()));
181184
trayMenu->addAction(tr("Quit"), qApp, SLOT(quit()));
185+
186+
if (SettingsManager::instance().getSettings().hideIcon) tray->setVisible(hasDevices);
182187
}
183188

184189
void TinyMountTray::onDeviceAdded(const DeviceInfo &device)
@@ -282,7 +287,8 @@ void TinyMountTray::showSettings()
282287
const Settings& settings = dlg.getSettings();
283288
const Settings& oldSettings = SettingsManager::instance().getSettings();
284289
bool refreshList = settings.showSystemDisks != oldSettings.showSystemDisks
285-
|| settings.itemFormat != oldSettings.itemFormat;
290+
|| settings.itemFormat != oldSettings.itemFormat
291+
|| settings.hideIcon != oldSettings.hideIcon;
286292
SettingsManager::instance().save(settings);
287293

288294
if (refreshList)

src/translations/tinymount_ru.ts

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,22 @@
7575
<translation>Показывать системные диски</translation>
7676
</message>
7777
<message>
78-
<location filename="../settingsdialog.ui" line="36"/>
78+
<location filename="../settingsdialog.ui" line="33"/>
79+
<source>Hide icon if there are no devices</source>
80+
<translation>Скрывать иконку если нет устройств</translation>
81+
</message>
82+
<message>
83+
<location filename="../settingsdialog.ui" line="43"/>
7984
<source>Mount devices automaticaly</source>
8085
<translation>Монтировать диски автоматически</translation>
8186
</message>
8287
<message>
83-
<location filename="../settingsdialog.ui" line="45"/>
88+
<location filename="../settingsdialog.ui" line="52"/>
8489
<source>Item format:</source>
8590
<translation>Формат элемента:</translation>
8691
</message>
8792
<message>
88-
<location filename="../settingsdialog.ui" line="52"/>
93+
<location filename="../settingsdialog.ui" line="59"/>
8994
<source>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
9095
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
9196
p, li { white-space: pre-wrap; }
@@ -104,32 +109,32 @@ p, li { white-space: pre-wrap; }
104109
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;%mounted%&lt;/span&gt; - точка монтирования&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</translation>
105110
</message>
106111
<message>
107-
<location filename="../settingsdialog.ui" line="66"/>
112+
<location filename="../settingsdialog.ui" line="73"/>
108113
<source>Reset format to default</source>
109114
<translation>Сбросить формат к исходному</translation>
110115
</message>
111116
<message>
112-
<location filename="../settingsdialog.ui" line="69"/>
117+
<location filename="../settingsdialog.ui" line="76"/>
113118
<source>X</source>
114119
<translation>X</translation>
115120
</message>
116121
<message>
117-
<location filename="../settingsdialog.ui" line="81"/>
122+
<location filename="../settingsdialog.ui" line="88"/>
118123
<source>Notifications</source>
119124
<translation>Уведомления</translation>
120125
</message>
121126
<message>
122-
<location filename="../settingsdialog.ui" line="87"/>
127+
<location filename="../settingsdialog.ui" line="94"/>
123128
<source>Notify when device added/removed</source>
124129
<translation>Уведомлять о добавлении устройства</translation>
125130
</message>
126131
<message>
127-
<location filename="../settingsdialog.ui" line="94"/>
132+
<location filename="../settingsdialog.ui" line="101"/>
128133
<source>Notify when device mounted/unmounted</source>
129134
<translation>Уведомлять о монтировании устройства</translation>
130135
</message>
131136
<message>
132-
<location filename="../settingsdialog.cpp" line="18"/>
137+
<location filename="../settingsdialog.cpp" line="19"/>
133138
<source>Use system notifications</source>
134139
<translation>Использовать системные уведомления</translation>
135140
</message>
@@ -138,87 +143,87 @@ p, li { white-space: pre-wrap; }
138143
<name>TinyMountTray</name>
139144
<message>
140145
<location filename="../main.cpp" line="156"/>
141-
<location filename="../tinymounttray.cpp" line="271"/>
146+
<location filename="../tinymounttray.cpp" line="276"/>
142147
<source>TinyMount, version %1</source>
143148
<translation>TinyMount, версия %1</translation>
144149
</message>
145150
<message>
146-
<location filename="../tinymounttray.cpp" line="180"/>
151+
<location filename="../tinymounttray.cpp" line="183"/>
147152
<source>About...</source>
148153
<translation>О программе...</translation>
149154
</message>
150155
<message>
151-
<location filename="../tinymounttray.cpp" line="181"/>
156+
<location filename="../tinymounttray.cpp" line="184"/>
152157
<source>Quit</source>
153158
<translation>Выход</translation>
154159
</message>
155160
<message>
156-
<location filename="../tinymounttray.cpp" line="189"/>
161+
<location filename="../tinymounttray.cpp" line="194"/>
157162
<source>Device is added</source>
158163
<translation>Устройство добавлено</translation>
159164
</message>
160165
<message>
161-
<location filename="../tinymounttray.cpp" line="190"/>
166+
<location filename="../tinymounttray.cpp" line="195"/>
162167
<source>Device %1 is added</source>
163168
<translation>Добавлено устройство %1</translation>
164169
</message>
165170
<message>
166-
<location filename="../tinymounttray.cpp" line="204"/>
171+
<location filename="../tinymounttray.cpp" line="209"/>
167172
<source>Device is removed</source>
168173
<translation>Устройство удалено</translation>
169174
</message>
170175
<message>
171-
<location filename="../tinymounttray.cpp" line="205"/>
176+
<location filename="../tinymounttray.cpp" line="210"/>
172177
<source>Device %1 is removed</source>
173178
<translation>Устройство %1 удалено</translation>
174179
</message>
175180
<message>
176-
<location filename="../tinymounttray.cpp" line="238"/>
181+
<location filename="../tinymounttray.cpp" line="243"/>
177182
<source>Device is mounted</source>
178183
<translation>Устройство смонтировано</translation>
179184
</message>
180185
<message>
181-
<location filename="../tinymounttray.cpp" line="239"/>
186+
<location filename="../tinymounttray.cpp" line="244"/>
182187
<source>%1 is mounted to %2.</source>
183188
<translation>%1 смонтирован в %2.</translation>
184189
</message>
185190
<message>
186-
<location filename="../tinymounttray.cpp" line="245"/>
191+
<location filename="../tinymounttray.cpp" line="250"/>
187192
<source>%1 mounting error. %2.</source>
188193
<translation>Не могу смонтировать %1. %2.</translation>
189194
</message>
190195
<message>
191-
<location filename="../tinymounttray.cpp" line="258"/>
196+
<location filename="../tinymounttray.cpp" line="263"/>
192197
<source>%1 is unmounted successfuly.</source>
193198
<translation>%1 успешно отмонтирован.</translation>
194199
</message>
195200
<message>
196-
<location filename="../tinymounttray.cpp" line="264"/>
201+
<location filename="../tinymounttray.cpp" line="269"/>
197202
<source>Failed to unmount %1. %2.</source>
198203
<translation>Не могу отмонтировать %1. %2.</translation>
199204
</message>
200205
<message>
201-
<location filename="../tinymounttray.cpp" line="244"/>
206+
<location filename="../tinymounttray.cpp" line="249"/>
202207
<source>Mount failed</source>
203208
<translation>Ошибка монтирования</translation>
204209
</message>
205210
<message>
206-
<location filename="../tinymounttray.cpp" line="179"/>
211+
<location filename="../tinymounttray.cpp" line="182"/>
207212
<source>Settings</source>
208213
<translation>Настройки</translation>
209214
</message>
210215
<message>
211-
<location filename="../tinymounttray.cpp" line="257"/>
216+
<location filename="../tinymounttray.cpp" line="262"/>
212217
<source>Device is unmounted</source>
213218
<translation>Устройство отмонтировано</translation>
214219
</message>
215220
<message>
216-
<location filename="../tinymounttray.cpp" line="263"/>
221+
<location filename="../tinymounttray.cpp" line="268"/>
217222
<source>Unmount failed</source>
218223
<translation>Ошибка размонтирования</translation>
219224
</message>
220225
<message>
221-
<location filename="../tinymounttray.cpp" line="272"/>
226+
<location filename="../tinymounttray.cpp" line="277"/>
222227
<source>Copyright (c) 2012 Mike Limansky
223228

224229
Use and redistribute under terms of the GNU General Public License Version 2.</source>

0 commit comments

Comments
 (0)