Skip to content

Commit e7789b8

Browse files
Mike LimanskyMike Limansky
authored andcommitted
Add notification icon.
1 parent e452c15 commit e7789b8

4 files changed

Lines changed: 34 additions & 19 deletions

File tree

src/libnotifier.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ LibNotifier::~LibNotifier()
3232
notify_uninit();
3333
}
3434

35-
void LibNotifier::showNotification(const QString& title, const QString& message)
35+
void LibNotifier::showNotification(const QString& title, const QString& message, const QString& icon)
3636
{
37-
NotifyNotification* n = notify_notification_new(title.toUtf8().constData(), message.toUtf8().constData(), 0);
37+
NotifyNotification* n = notify_notification_new(title.toUtf8().constData(),
38+
message.toUtf8().constData(),
39+
icon.toUtf8().constData());
3840

3941
GError* err = 0;
4042
notify_notification_show(n, &err);

src/libnotifier.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class LibNotifier
2828
explicit LibNotifier(const QString& appname);
2929
~LibNotifier();
3030

31-
void showNotification(const QString& title, const QString& message);
31+
void showNotification(const QString& title, const QString& message, const QString &icon);
3232
};
3333

3434
#endif // LIBNOTIFIER_H

src/tinymounttray.cpp

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,22 @@
3434
#include <QMessageBox>
3535

3636
namespace {
37-
QIcon iconForType (DeviceInfo::DeviceType type)
37+
QString iconNameForType (DeviceInfo::DeviceType type)
3838
{
3939
switch (type)
4040
{
4141
case DeviceInfo::CD:
42-
return QIcon::fromTheme("media-optical");
42+
return "media-optical";
4343
case DeviceInfo::Flash:
4444
case DeviceInfo::Other:
45-
return QIcon::fromTheme("media-flash");
45+
return "media-flash";
4646
case DeviceInfo::Floppy:
47-
return QIcon::fromTheme("media-floppy");
47+
return "media-floppy";
4848
case DeviceInfo::HDD:
49-
return QIcon::fromTheme("drive-harddisk");
49+
return "drive-harddisk";
5050
}
5151

52-
return QIcon();
52+
return QString();
5353
}
5454

5555
QString formatFileSize(qulonglong size)
@@ -156,7 +156,7 @@ void TinyMountTray::reloadDevices()
156156
}
157157
else
158158
{
159-
icon = iconForType(d->type);
159+
icon = QIcon::fromTheme(iconNameForType(d->type));
160160
text.replace("%mounted%", "");
161161
}
162162

@@ -186,7 +186,9 @@ void TinyMountTray::onDeviceAdded(const DeviceInfo &device)
186186
qDebug() << "Device added:" << device.name;
187187

188188
if (SettingsManager::instance().getSettings().deviceNotifications)
189-
showNotification(tr("Device is added"), tr("Device %1 is added").arg(device.name));
189+
showNotification(tr("Device is added"),
190+
tr("Device %1 is added").arg(device.name),
191+
iconNameForType(device.type));
190192

191193
if (SettingsManager::instance().getSettings().mountAutomaticaly)
192194
manager->mountDevice(device.udisksPath);
@@ -199,7 +201,9 @@ void TinyMountTray::onDeviceRemoved(const DeviceInfo& device)
199201
qDebug() << "Device removed:" << device.name;
200202

201203
if (SettingsManager::instance().getSettings().deviceNotifications)
202-
showNotification(tr("Device is removed"), tr("Device %1 is removed").arg(device.name));
204+
showNotification(tr("Device is removed"),
205+
tr("Device %1 is removed").arg(device.name),
206+
iconNameForType(device.type));
203207

204208
reloadDevices();
205209
}
@@ -231,11 +235,15 @@ void TinyMountTray::onMountDone(const DeviceInfo &device, const QString &mountPa
231235
if (DiskManager::OK == status)
232236
{
233237
if (SettingsManager::instance().getSettings().mountNotifications)
234-
showNotification(tr("Device is mounted"), tr("%1 is mounted to %2.").arg(device.name).arg(mountPath));
238+
showNotification(tr("Device is mounted"),
239+
tr("%1 is mounted to %2.").arg(device.name).arg(mountPath),
240+
iconNameForType(device.type));
235241
}
236242
else
237243
{
238-
showNotification(tr("Mount failed"), tr("%1 mounting error. %2.").arg(device.name).arg(errorToString(status)));
244+
showNotification(tr("Mount failed"),
245+
tr("%1 mounting error. %2.").arg(device.name).arg(errorToString(status)),
246+
"dialog-error");
239247
}
240248
}
241249

@@ -246,11 +254,15 @@ void TinyMountTray::onUnmountDone(const DeviceInfo &device, int status)
246254
if (DiskManager::OK == status)
247255
{
248256
if (SettingsManager::instance().getSettings().mountNotifications)
249-
showNotification(tr("Device is unmounted"), tr("%1 is unmounted successfuly.").arg(device.name));
257+
showNotification(tr("Device is unmounted"),
258+
tr("%1 is unmounted successfuly.").arg(device.name),
259+
iconNameForType(device.type));
250260
}
251261
else
252262
{
253-
showNotification(tr("Unmount failed"), tr("Failed to unmount %1. %2.").arg(device.name).arg(errorToString(status)));
263+
showNotification(tr("Unmount failed"),
264+
tr("Failed to unmount %1. %2.").arg(device.name).arg(errorToString(status)),
265+
"dialog-error");
254266
}
255267
}
256268

@@ -280,18 +292,19 @@ void TinyMountTray::showSettings()
280292
}
281293
}
282294

283-
void TinyMountTray::showNotification(const QString& title, const QString &message)
295+
void TinyMountTray::showNotification(const QString& title, const QString &message, const QString& icon)
284296
{
285297
#ifdef WITH_LIBNOTIFY
286298
if (SettingsManager::instance().getSettings().useLibnotify)
287299
{
288-
notifier->showNotification(title, message);
300+
notifier->showNotification(title, message, icon);
289301
}
290302
else
291303
{
292304
tray->showMessage(title, message);
293305
}
294306
#else
307+
Q_UNUSED(icon);
295308
tray->showMessage(title, message);
296309
#endif
297310
}

src/tinymounttray.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public slots:
5353
void onUnmountDone(const DeviceInfo& device, int status);
5454

5555
private:
56-
void showNotification(const QString& title, const QString &message);
56+
void showNotification(const QString& title, const QString &message, const QString &icon);
5757

5858
private:
5959
QSystemTrayIcon* tray;

0 commit comments

Comments
 (0)