mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Port main_window_linux to cppgir
This commit is contained in:
parent
7b8cdb43c4
commit
41481129f7
1 changed files with 29 additions and 32 deletions
|
@ -43,8 +43,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include <QtWidgets/QLineEdit>
|
#include <QtWidgets/QLineEdit>
|
||||||
#include <QtWidgets/QTextEdit>
|
#include <QtWidgets/QTextEdit>
|
||||||
|
|
||||||
#include <glibmm.h>
|
#include <gio/gio.hpp>
|
||||||
#include <giomm.h>
|
|
||||||
|
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -236,6 +235,8 @@ void MainWindow::updateUnityCounter() {
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
|
||||||
qApp->setBadgeNumber(Core::App().unreadBadge());
|
qApp->setBadgeNumber(Core::App().unreadBadge());
|
||||||
#else // Qt >= 6.6.0
|
#else // Qt >= 6.6.0
|
||||||
|
using namespace gi::repository;
|
||||||
|
|
||||||
static const auto djbStringHash = [](const std::string &string) {
|
static const auto djbStringHash = [](const std::string &string) {
|
||||||
uint hash = 5381;
|
uint hash = 5381;
|
||||||
for (const auto &curChar : string) {
|
for (const auto &curChar : string) {
|
||||||
|
@ -244,40 +245,36 @@ void MainWindow::updateUnityCounter() {
|
||||||
return hash;
|
return hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto launcherUrl = Glib::ustring(
|
const auto launcherUrl = "application://"
|
||||||
"application://"
|
+ QGuiApplication::desktopFileName().toStdString()
|
||||||
+ QGuiApplication::desktopFileName().toStdString()
|
+ ".desktop";
|
||||||
+ ".desktop");
|
|
||||||
const auto counterSlice = std::min(Core::App().unreadBadge(), 9999);
|
const auto counterSlice = std::min(Core::App().unreadBadge(), 9999);
|
||||||
std::map<Glib::ustring, Glib::VariantBase> dbusUnityProperties;
|
|
||||||
|
|
||||||
if (counterSlice > 0) {
|
auto connection = Gio::bus_get_sync(Gio::BusType::SESSION_, nullptr);
|
||||||
// According to the spec, it should be of 'x' D-Bus signature,
|
if (!connection) {
|
||||||
// which corresponds to signed 64-bit integer
|
return;
|
||||||
// https://wiki.ubuntu.com/Unity/LauncherAPI#Low_level_DBus_API:_com.canonical.Unity.LauncherEntry
|
|
||||||
dbusUnityProperties["count"] = Glib::create_variant(
|
|
||||||
int64(counterSlice));
|
|
||||||
dbusUnityProperties["count-visible"] = Glib::create_variant(true);
|
|
||||||
} else {
|
|
||||||
dbusUnityProperties["count-visible"] = Glib::create_variant(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
connection.emit_signal(
|
||||||
const auto connection = Gio::DBus::Connection::get_sync(
|
{},
|
||||||
Gio::DBus::BusType::SESSION);
|
"/com/canonical/unity/launcherentry/"
|
||||||
|
+ std::to_string(djbStringHash(launcherUrl)),
|
||||||
connection->emit_signal(
|
"com.canonical.Unity.LauncherEntry",
|
||||||
"/com/canonical/unity/launcherentry/"
|
"Update",
|
||||||
+ std::to_string(djbStringHash(launcherUrl)),
|
GLib::Variant::new_tuple({
|
||||||
"com.canonical.Unity.LauncherEntry",
|
GLib::Variant::new_string(launcherUrl),
|
||||||
"Update",
|
GLib::Variant::new_array({
|
||||||
{},
|
GLib::Variant::new_dict_entry(
|
||||||
Glib::create_variant(std::tuple{
|
GLib::Variant::new_string("count"),
|
||||||
launcherUrl,
|
GLib::Variant::new_variant(
|
||||||
dbusUnityProperties,
|
GLib::Variant::new_int64(counterSlice))),
|
||||||
}));
|
GLib::Variant::new_dict_entry(
|
||||||
} catch (...) {
|
GLib::Variant::new_string("count-visible"),
|
||||||
}
|
GLib::Variant::new_variant(
|
||||||
|
GLib::Variant::new_boolean(counterSlice))),
|
||||||
|
}),
|
||||||
|
}));
|
||||||
#endif // Qt < 6.6.0
|
#endif // Qt < 6.6.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue