1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Create systray statusnotifier ctor icon properly

This commit is contained in:
tux3 2015-02-22 01:36:51 +01:00
parent 18a9955f43
commit c3700fdfec
No known key found for this signature in database
GPG Key ID: 7E086DD661263264

View File

@ -40,23 +40,21 @@ SystemTrayIcon::SystemTrayIcon()
backendType = SystrayBackendType::StatusNotifier; backendType = SystrayBackendType::StatusNotifier;
gtk_init(nullptr, nullptr); gtk_init(nullptr, nullptr);
snMenu = gtk_menu_new(); snMenu = gtk_menu_new();
QString settingsDir = Settings::getSettingsDirPath(); void (*callbackFreeImage)(guchar*, gpointer) =
QFile iconFile(settingsDir+"/icon.png"); [](guchar*, gpointer image)
if (iconFile.open(QIODevice::Truncate | QIODevice::WriteOnly))
{ {
QFile resIconFile(":/img/icon.png"); delete reinterpret_cast<QImage*>(image);
if (resIconFile.open(QIODevice::ReadOnly)) };
iconFile.write(resIconFile.readAll()); QImage* image = new QImage(":/img/icon.png");
resIconFile.close(); if (image->format() != QImage::Format_RGBA8888_Premultiplied)
iconFile.close(); *image = image->convertToFormat(QImage::Format_RGBA8888_Premultiplied);
} GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(image->bits(), GDK_COLORSPACE_RGB, image->hasAlphaChannel(),
GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file((settingsDir+"/icon.png").toStdString().c_str(), 0); 8, image->width(), image->height(),
image->bytesPerLine(), callbackFreeImage, image);
statusNotifier = status_notifier_new_from_pixbuf("qtox", statusNotifier = status_notifier_new_from_pixbuf("qtox",
STATUS_NOTIFIER_CATEGORY_APPLICATION_STATUS, pixbuf); STATUS_NOTIFIER_CATEGORY_APPLICATION_STATUS, pixbuf);
status_notifier_register(statusNotifier); status_notifier_register(statusNotifier);
GtkWidget* item = gtk_menu_item_new_with_label("Test");
gtk_menu_shell_append(GTK_MENU_SHELL(snMenu), item);
gtk_widget_show(item);
} }
#endif #endif
else if (desktop.toLower() == "kde" else if (desktop.toLower() == "kde"