aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/exporter.cpp1
-rw-r--r--src/menu.cpp62
2 files changed, 54 insertions, 9 deletions
diff --git a/src/exporter.cpp b/src/exporter.cpp
index 8103b5b..86e3670 100644
--- a/src/exporter.cpp
+++ b/src/exporter.cpp
@@ -85,7 +85,6 @@ Exporter::on_bus_acquired(GDBusConnection* connection, const gchar* /*name*/)
{
const auto path = std::string(BUS_PATH) + "/" + menu->name();
const auto id = g_dbus_connection_export_menu_model(m_dbus_connection, path.c_str(), menu->menu_model(), &error);
-g_message ("path %s id %d", path.c_str(), (int)id);
if (id)
{
m_exported_menu_ids.insert(id);
diff --git a/src/menu.cpp b/src/menu.cpp
index 43e07ae..5b19d92 100644
--- a/src/menu.cpp
+++ b/src/menu.cpp
@@ -26,6 +26,8 @@
#include <datetime/state.h>
#include <datetime/timezones.h>
+#include <json-glib/json-glib.h>
+
#include <glib/gi18n.h>
#include <gio/gio.h>
@@ -53,6 +55,9 @@ protected:
m_actions(actions),
m_formatter(formatter)
{
+ // preload the alarm icon from click
+ m_serialized_alarm_icon = create_alarm_icon();
+
// initialize the menu
create_gmenu();
for (int i=0; i<NUM_SECTIONS; i++)
@@ -110,19 +115,60 @@ protected:
std::shared_ptr<Formatter> m_formatter;
GMenu* m_submenu = nullptr;
- GVariant* get_serialized_alarm_icon()
+ GVariant* get_serialized_alarm_icon() { return m_serialized_alarm_icon; }
+
+private:
+
+ /* try to get the clock app's filename from click. (/$pkgdir/$icon) */
+ static GVariant* create_alarm_icon()
{
- if (G_UNLIKELY(m_serialized_alarm_icon == nullptr))
+ GVariant* serialized = nullptr;
+ gchar* icon_filename = nullptr;
+ gchar* standard_error = nullptr;
+ gchar* pkgdir = nullptr;
+
+ g_spawn_command_line_sync("click pkgdir com.ubuntu.clock", &pkgdir, &standard_error, nullptr, nullptr);
+ g_clear_pointer(&standard_error, g_free);
+ if (pkgdir != nullptr)
{
- auto i = g_themed_icon_new_with_default_fallbacks(ALARM_CLOCK_ICON_NAME);
- m_serialized_alarm_icon = g_icon_serialize(i);
- g_object_unref(i);
+ gchar* manifest = nullptr;
+ g_strstrip(pkgdir);
+ g_spawn_command_line_sync("click info com.ubuntu.clock", &manifest, &standard_error, nullptr, nullptr);
+ g_clear_pointer(&standard_error, g_free);
+ if (manifest != nullptr)
+ {
+ JsonParser* parser = json_parser_new();
+ if (json_parser_load_from_data(parser, manifest, -1, nullptr))
+ {
+ JsonNode* root = json_parser_get_root(parser); /* transfer-none */
+ if ((root != nullptr) && (JSON_NODE_TYPE(root) == JSON_NODE_OBJECT))
+ {
+ JsonObject* o = json_node_get_object(root); /* transfer-none */
+ const gchar* icon_name = json_object_get_string_member(o, "icon");
+ if (icon_name != nullptr)
+ icon_filename = g_build_filename(pkgdir, icon_name, nullptr);
+ }
+ }
+ g_object_unref(parser);
+ g_free(manifest);
+ }
+ g_free(pkgdir);
}
- return m_serialized_alarm_icon;
- }
+ if (icon_filename != nullptr)
+ {
+ GFile* file = g_file_new_for_path(icon_filename);
+ GIcon* icon = g_file_icon_new(file);
-private:
+ serialized = g_icon_serialize(icon);
+
+ g_object_unref(icon);
+ g_object_unref(file);
+ g_free(icon_filename);
+ }
+
+ return serialized;
+ }
GVariant* get_serialized_calendar_icon()
{