diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index 45336ee68..1d626ca47 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -289,6 +289,12 @@ void Settings::loadPersonnal(Profile* profile) SettingsSerializer ps(filePath, profile->getPassword()); ps.load(); friendLst.clear(); + + ps.beginGroup("Privacy"); + typingNotification = ps.value("typingNotification", true).toBool(); + enableLogging = ps.value("enableLogging", true).toBool(); + ps.endGroup(); + ps.beginGroup("Friends"); int size = ps.beginReadArray("Friend"); friendLst.reserve(size); @@ -327,11 +333,6 @@ void Settings::loadPersonnal(Profile* profile) } ps.endArray(); ps.endGroup(); - - ps.beginGroup("Privacy"); - typingNotification = ps.value("typingNotification", true).toBool(); - enableLogging = ps.value("enableLogging", true).toBool(); - ps.endGroup(); } void Settings::saveGlobal() diff --git a/src/platform/statusnotifier/statusnotifier.c b/src/platform/statusnotifier/statusnotifier.c index 084ab9f7a..21a5e4945 100644 --- a/src/platform/statusnotifier/statusnotifier.c +++ b/src/platform/statusnotifier/statusnotifier.c @@ -1608,7 +1608,7 @@ get_prop (GDBusConnection *conn, else if (!g_strcmp0 (property, "ToolTip")) { GVariant *variant; - GVariantBuilder *builder; + GVariant *pixmap; if (!priv->icon[STATUS_NOTIFIER_TOOLTIP_ICON].has_pixbuf) { @@ -1621,13 +1621,13 @@ get_prop (GDBusConnection *conn, return variant; } - builder = get_icon_pixmap (sn, STATUS_NOTIFIER_TOOLTIP_ICON); + pixmap = get_icon_pixmap (sn, STATUS_NOTIFIER_TOOLTIP_ICON); variant = g_variant_new ("(sa(iiay)ss)", "", - builder, + pixmap, (priv->tooltip_title) ? priv->tooltip_title : "", (priv->tooltip_body) ? priv->tooltip_body : ""); - g_variant_builder_unref (builder); + g_variant_unref (pixmap); return variant; } diff --git a/src/video/cameradevice.cpp b/src/video/cameradevice.cpp index ab3cb130f..2602f9805 100644 --- a/src/video/cameradevice.cpp +++ b/src/video/cameradevice.cpp @@ -226,8 +226,11 @@ QVector> CameraDevice::getRawDeviceListGeneric() { av_dict_free(&tmp); avformat_free_context(s); + return devices; } avdevice_list_devices(s, &devlist); + av_dict_free(&tmp); + avformat_free_context(s); if (!devlist) { qWarning() << "avdevice_list_devices failed"; diff --git a/src/widget/form/profileform.cpp b/src/widget/form/profileform.cpp index f4cd55774..537155a23 100644 --- a/src/widget/form/profileform.cpp +++ b/src/widget/form/profileform.cpp @@ -79,7 +79,7 @@ ProfileForm::ProfileForm(QWidget *parent) : toxId->setToolTip(bodyUI->toxId->toolTip()); QVBoxLayout *toxIdGroup = qobject_cast(bodyUI->toxGroup->layout()); - toxIdGroup->replaceWidget(bodyUI->toxId, toxId); + delete toxIdGroup->replaceWidget(bodyUI->toxId, toxId); // Original toxId is in heap, delete it bodyUI->toxId->hide(); bodyUI->qrLabel->setWordWrap(true); diff --git a/src/widget/systemtrayicon.cpp b/src/widget/systemtrayicon.cpp index b066b2403..5f735ce95 100644 --- a/src/widget/systemtrayicon.cpp +++ b/src/widget/systemtrayicon.cpp @@ -65,18 +65,12 @@ SystemTrayIcon::SystemTrayIcon() qDebug() << "Using GTK backend"; backendType = SystrayBackendType::GTK; gtk_init(nullptr, nullptr); - void (*callbackFreeImage)(guchar*, gpointer) = - [](guchar*, gpointer image) - { - delete reinterpret_cast(image); - }; - QImage* image = new QImage(":/img/icon.png"); - if (image->format() != QImage::Format_RGBA8888_Premultiplied) - *image = image->convertToFormat(QImage::Format_RGBA8888_Premultiplied); - GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(image->bits(), GDK_COLORSPACE_RGB, image->hasAlphaChannel(), - 8, image->width(), image->height(), - image->bytesPerLine(), callbackFreeImage, image); + + // No ':' needed in resource path! + GdkPixbuf *pixbuf = gdk_pixbuf_new_from_resource("/img/icon.png", NULL); gtkIcon = gtk_status_icon_new_from_pixbuf(pixbuf); + g_object_unref(pixbuf); + gtkMenu = gtk_menu_new(); void (*callbackTrigger)(GtkStatusIcon*, gpointer) = @@ -102,21 +96,13 @@ SystemTrayIcon::SystemTrayIcon() backendType = SystrayBackendType::StatusNotifier; gtk_init(nullptr, nullptr); snMenu = gtk_menu_new(); - void (*callbackFreeImage)(guchar*, gpointer) = - [](guchar*, gpointer image) - { - delete reinterpret_cast(image); - }; - QImage image(":/img/icon.png"); - if (image.format() != QImage::Format_RGBA8888_Premultiplied) - image = image.convertToFormat(QImage::Format_RGBA8888_Premultiplied); - GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(image.bits(), GDK_COLORSPACE_RGB, image.hasAlphaChannel(), - 8, image.width(), image.height(), - image.bytesPerLine(), callbackFreeImage, &image); + // No ':' needed in resource path! + GdkPixbuf *pixbuf = gdk_pixbuf_new_from_resource("/img/icon.png", NULL); statusNotifier = status_notifier_new_from_pixbuf("qtox", STATUS_NOTIFIER_CATEGORY_APPLICATION_STATUS, pixbuf); status_notifier_register(statusNotifier); + g_object_unref(pixbuf); } #endif else if (desktop == "kde" @@ -182,19 +168,24 @@ void SystemTrayIcon::setContextMenu(QMenu* menu) else { void (*callbackFreeImage)(guchar*, gpointer) = - [](guchar*, gpointer image) + [](guchar*, gpointer image_bytes) { - delete reinterpret_cast(image); + free(reinterpret_cast(image_bytes)); }; - QImage* image = new QImage(a->icon().pixmap(64, 64).toImage()); - if (image->format() != QImage::Format_RGBA8888_Premultiplied) - *image = image->convertToFormat(QImage::Format_RGBA8888_Premultiplied); - GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(image->bits(), GDK_COLORSPACE_RGB, image->hasAlphaChannel(), - 8, image->width(), image->height(), - image->bytesPerLine(), callbackFreeImage, image); + QImage image = a->icon().pixmap(64, 64).toImage(); + if (image.format() != QImage::Format_RGBA8888_Premultiplied) + image = image.convertToFormat(QImage::Format_RGBA8888_Premultiplied); + guchar* image_bytes = (guchar*)malloc(image.byteCount()); + memcpy(image_bytes, image.bits(), image.byteCount()); + + GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(image_bytes, GDK_COLORSPACE_RGB, image.hasAlphaChannel(), + 8, image.width(), image.height(), image.bytesPerLine(), + callbackFreeImage, image_bytes); + item = gtk_image_menu_item_new_with_label(aText.toStdString().c_str()); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), gtk_image_new_from_pixbuf(pixbuf)); gtk_image_menu_item_set_always_show_image(GTK_IMAGE_MENU_ITEM(item),TRUE); + g_object_unref(pixbuf); } gtk_menu_shell_append(GTK_MENU_SHELL(snMenu), item); void (*callback)(GtkMenu*, gpointer data) = [](GtkMenu*, gpointer a) @@ -227,19 +218,24 @@ void SystemTrayIcon::setContextMenu(QMenu* menu) else { void (*callbackFreeImage)(guchar*, gpointer) = - [](guchar*, gpointer image) + [](guchar*, gpointer image_bytes) { - delete reinterpret_cast(image); + free(reinterpret_cast(image_bytes)); }; - QImage* image = new QImage(a->icon().pixmap(64, 64).toImage()); - if (image->format() != QImage::Format_RGBA8888_Premultiplied) - *image = image->convertToFormat(QImage::Format_RGBA8888_Premultiplied); - GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(image->bits(), GDK_COLORSPACE_RGB, image->hasAlphaChannel(), - 8, image->width(), image->height(), - image->bytesPerLine(), callbackFreeImage, image); + QImage image = a->icon().pixmap(64, 64).toImage(); + if (image.format() != QImage::Format_RGBA8888_Premultiplied) + image = image.convertToFormat(QImage::Format_RGBA8888_Premultiplied); + guchar* image_bytes = (guchar*)malloc(image.byteCount()); + memcpy(image_bytes, image.bits(), image.byteCount()); + + GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(image_bytes, GDK_COLORSPACE_RGB, image.hasAlphaChannel(), + 8, image.width(), image.height(), image.bytesPerLine(), + callbackFreeImage, image_bytes); + item = gtk_image_menu_item_new_with_label(aText.toStdString().c_str()); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), gtk_image_new_from_pixbuf(pixbuf)); gtk_image_menu_item_set_always_show_image(GTK_IMAGE_MENU_ITEM(item),TRUE); + g_object_unref(pixbuf); } gtk_menu_shell_append(GTK_MENU_SHELL(gtkMenu), item); void (*callback)(GtkMenu*, gpointer data) = [](GtkMenu*, gpointer a) @@ -360,34 +356,44 @@ void SystemTrayIcon::setIcon(QIcon &icon) else if (backendType == SystrayBackendType::StatusNotifier) { void (*callbackFreeImage)(guchar*, gpointer) = - [](guchar*, gpointer image) + [](guchar*, gpointer image_bytes) { - delete reinterpret_cast(image); + free(reinterpret_cast(image_bytes)); }; - QImage* image = new QImage(icon.pixmap(64, 64).toImage()); - if (image->format() != QImage::Format_RGBA8888_Premultiplied) - *image = image->convertToFormat(QImage::Format_RGBA8888_Premultiplied); - GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(image->bits(), GDK_COLORSPACE_RGB, image->hasAlphaChannel(), - 8, image->width(), image->height(), - image->bytesPerLine(), callbackFreeImage, image); + QImage image = icon.pixmap(64, 64).toImage(); + if (image.format() != QImage::Format_RGBA8888_Premultiplied) + image = image.convertToFormat(QImage::Format_RGBA8888_Premultiplied); + guchar* image_bytes = (guchar*)malloc(image.byteCount()); + memcpy(image_bytes, image.bits(), image.byteCount()); + + GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(image_bytes, GDK_COLORSPACE_RGB, image.hasAlphaChannel(), + 8, image.width(), image.height(), image.bytesPerLine(), + callbackFreeImage, image_bytes); + status_notifier_set_from_pixbuf(statusNotifier, STATUS_NOTIFIER_ICON, pixbuf); + g_object_unref(pixbuf); } #endif #ifdef ENABLE_SYSTRAY_GTK_BACKEND else if (backendType == SystrayBackendType::GTK) { void (*callbackFreeImage)(guchar*, gpointer) = - [](guchar*, gpointer image) + [](guchar*, gpointer image_bytes) { - delete reinterpret_cast(image); + free(reinterpret_cast(image_bytes)); }; - QImage* image = new QImage(icon.pixmap(64, 64).toImage()); - if (image->format() != QImage::Format_RGBA8888_Premultiplied) - *image = image->convertToFormat(QImage::Format_RGBA8888_Premultiplied); - GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(image->bits(), GDK_COLORSPACE_RGB, image->hasAlphaChannel(), - 8, image->width(), image->height(), - image->bytesPerLine(), callbackFreeImage, image); + QImage image = icon.pixmap(64, 64).toImage(); + if (image.format() != QImage::Format_RGBA8888_Premultiplied) + image = image.convertToFormat(QImage::Format_RGBA8888_Premultiplied); + guchar* image_bytes = (guchar*)malloc(image.byteCount()); + memcpy(image_bytes, image.bits(), image.byteCount()); + + GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(image_bytes, GDK_COLORSPACE_RGB, image.hasAlphaChannel(), + 8, image.width(), image.height(), image.bytesPerLine(), + callbackFreeImage, image_bytes); + gtk_status_icon_set_from_pixbuf(gtkIcon, pixbuf); + g_object_unref(pixbuf); } #endif #ifdef ENABLE_SYSTRAY_UNITY_BACKEND