Skip to content

Commit

Permalink
Allow the service to handle tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
tari01 committed Oct 18, 2024
1 parent e923395 commit eb93dbc
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 19 deletions.
67 changes: 58 additions & 9 deletions src/application-service-appstore.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ An object that stores the registration of all the application
indicators. It also communicates this to the indicator visualization.
Copyright 2009 Canonical Ltd.
Copyright 2024 Robert Tari
Authors:
Ted Gould <[email protected]>
Robert Tari <[email protected]>
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License version 3, as published
Expand Down Expand Up @@ -52,13 +54,15 @@ static void props_cb (GObject * object, GAsyncResult * res, gpointer user_data);
#define NOTIFICATION_ITEM_PROP_LABEL_GUIDE "XAyatanaLabelGuide"
#define NOTIFICATION_ITEM_PROP_TITLE "Title"
#define NOTIFICATION_ITEM_PROP_ORDERING_INDEX "XAyatanaOrderingIndex"
#define NOTIFICATION_ITEM_PROP_TOOLTIP "ToolTip"

#define NOTIFICATION_ITEM_SIG_NEW_ICON "NewIcon"
#define NOTIFICATION_ITEM_SIG_NEW_AICON "NewAttentionIcon"
#define NOTIFICATION_ITEM_SIG_NEW_STATUS "NewStatus"
#define NOTIFICATION_ITEM_SIG_NEW_LABEL "XAyatanaNewLabel"
#define NOTIFICATION_ITEM_SIG_NEW_ICON_THEME_PATH "NewIconThemePath"
#define NOTIFICATION_ITEM_SIG_NEW_TITLE "NewTitle"
#define NOTIFICATION_ITEM_SIG_NEW_TOOLTIP "NewToolTip"

#define OVERRIDE_GROUP_NAME "Ordering Index Overrides"
#define OVERRIDE_FILE_NAME "ordering-override.keyfile"
Expand Down Expand Up @@ -106,6 +110,9 @@ struct _Application {
guint ordering_index;
visible_state_t visible_state;
guint name_watcher;
gchar *sTooltipIcon;
gchar *sTooltipTitle;
gchar *sTooltipDescription;
};

/* GDBus Stuff */
Expand Down Expand Up @@ -425,6 +432,7 @@ got_all_properties (GObject * source_object, GAsyncResult * res,
* icon_desc = NULL, * aicon_desc = NULL,
* icon_theme_path = NULL, * index = NULL, * label = NULL,
* guide = NULL, * title = NULL;
GVariant *pTooltip = NULL;

GVariant * properties = g_dbus_proxy_call_finish(G_DBUS_PROXY(source_object), res, &error);

Expand Down Expand Up @@ -480,7 +488,12 @@ got_all_properties (GObject * source_object, GAsyncResult * res,
guide = g_variant_ref(value);
} else if (g_strcmp0(name, NOTIFICATION_ITEM_PROP_TITLE) == 0) {
title = g_variant_ref(value);
} /* else ignore */
}
else if (g_strcmp0 (name, NOTIFICATION_ITEM_PROP_TOOLTIP) == 0)
{
pTooltip = g_variant_ref (value);
}
/* else ignore */
}
g_variant_iter_free (iter);
g_variant_unref(properties);
Expand Down Expand Up @@ -574,6 +587,21 @@ got_all_properties (GObject * source_object, GAsyncResult * res,
app->title = g_strdup("");
}

g_free (app->sTooltipIcon);
g_free (app->sTooltipTitle);
g_free (app->sTooltipDescription);

if (pTooltip != NULL)
{
g_variant_get (pTooltip, "(sa(iiay)ss)", &app->sTooltipIcon, NULL, &app->sTooltipTitle, &app->sTooltipDescription);
}
else
{
app->sTooltipIcon = g_strdup ("");
app->sTooltipTitle = g_strdup ("");
app->sTooltipDescription = g_strdup ("");
}

apply_status(app);

if (app->queued_props) {
Expand All @@ -596,6 +624,11 @@ got_all_properties (GObject * source_object, GAsyncResult * res,
if (guide) g_variant_unref (guide);
if (title) g_variant_unref (title);

if (pTooltip)
{
g_variant_unref (pTooltip);
}

return;
}

Expand Down Expand Up @@ -772,6 +805,9 @@ application_free (Application * app)
g_free(app->title);
}

g_free (app->sTooltipIcon);
g_free (app->sTooltipTitle);
g_free (app->sTooltipDescription);
g_free(app);
return;
}
Expand Down Expand Up @@ -884,12 +920,12 @@ apply_status (Application * app)
if (app->visible_state == VISIBLE_STATE_HIDDEN) {
/* Put on panel */
emit_signal (appstore, "ApplicationAdded",
g_variant_new ("(sisossssss)", newicon,
g_variant_new ("(sisosssssssss)", newicon,
get_position(app),
app->dbus_name, app->menu,
app->icon_theme_path,
app->label, app->guide,
newdesc, app->id, app->title));
newdesc, app->id, app->title, app->sTooltipIcon != NULL ? app->sTooltipIcon : "", app->sTooltipTitle != NULL ? app->sTooltipTitle : "", app->sTooltipDescription != NULL ? app->sTooltipDescription : ""));
} else {
/* Icon update */
gint position = get_position(app);
Expand Down Expand Up @@ -1028,6 +1064,9 @@ application_service_appstore_application_add (ApplicationServiceAppstore * appst
app->props_cancel = NULL;
app->props = NULL;
app->queued_props = FALSE;
app->sTooltipIcon = NULL;
app->sTooltipTitle = NULL;
app->sTooltipDescription = NULL;

/* Get the DBus proxy for the NotificationItem interface */
app->dbus_proxy_cancel = g_cancellable_new();
Expand Down Expand Up @@ -1204,8 +1243,18 @@ app_receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name
g_free(label);
g_free(guide);
}
else if (g_strcmp0 (signal_name, NOTIFICATION_ITEM_SIG_NEW_TOOLTIP) == 0)
{
// The tooltip data isn't provided by the signal, so look it up
get_all_properties (app);
gint nPosition = get_position (app);

return;
if (nPosition != -1)
{
GVariant *pParams = g_variant_new ("(isss)", nPosition, app->sTooltipIcon != NULL ? app->sTooltipIcon : "", app->sTooltipTitle != NULL ? app->sTooltipTitle : "", app->sTooltipDescription != NULL ? app->sTooltipDescription : "");
emit_signal (app->appstore, "ApplicationTooltipChanged", pParams);
}
}
}

/* Looks for an application in the list of applications */
Expand Down Expand Up @@ -1310,28 +1359,28 @@ get_applications (ApplicationServiceAppstore * appstore)
GList * listpntr;
gint position = 0;

g_variant_builder_init(&builder, G_VARIANT_TYPE ("a(sisossssss)"));
g_variant_builder_init(&builder, G_VARIANT_TYPE ("a(sisosssssssss)"));

for (listpntr = priv->applications; listpntr != NULL; listpntr = g_list_next(listpntr)) {
Application * app = (Application *)listpntr->data;
if (app->visible_state == VISIBLE_STATE_HIDDEN) {
continue;
}

g_variant_builder_add (&builder, "(sisossssss)", app->icon,
g_variant_builder_add (&builder, "(sisosssssssss)", app->icon,
position++, app->dbus_name, app->menu,
app->icon_theme_path, app->label,
app->guide,
(app->icon_desc != NULL) ? app->icon_desc : "",
app->id, app->title);
app->id, app->title, app->sTooltipIcon != NULL ? app->sTooltipIcon : "", app->sTooltipTitle != NULL ? app->sTooltipTitle : "", app->sTooltipDescription != NULL ? app->sTooltipDescription : "");
}

out = g_variant_builder_end(&builder);
} else {
GError * error = NULL;
out = g_variant_parse(g_variant_type_new("a(sisossssss)"), "[]", NULL, NULL, &error);
out = g_variant_parse(g_variant_type_new("a(sisosssssssss)"), "[]", NULL, NULL, &error);
if (error != NULL) {
g_warning("Unable to parse '[]' as a 'a(sisossssss)': %s", error->message);
g_warning("Unable to parse '[]' as a 'a(sisosssssssss)': %s", error->message);
out = NULL;
g_error_free(error);
}
Expand Down
13 changes: 12 additions & 1 deletion src/ayatana-application-service.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ An interface for communication between the service and indicator.
Copyright 2009 Canonical Ltd.
Copyright 2015 Arctica Project
Copyright 2024 Robert Tari
Authors:
Ted Gould <[email protected]>
Mike Gabriel <[email protected]>
Robert Tari <[email protected]>
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License version 3, as published
Expand All @@ -28,7 +30,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.

<!-- Methods -->
<method name="GetApplications">
<arg type="a(sisossssss)" name="applications" direction="out" />
<arg type="a(sisosssssssss)" name="applications" direction="out" />
</method>
<method name="ApplicationScrollEvent">
<arg type="s" name="dbusaddress" direction="in" />
Expand All @@ -54,6 +56,9 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
<arg type="s" name="accessibledesc" direction="out" />
<arg type="s" name="hint" direction="out" />
<arg type="s" name="title" direction="out" />
<arg type="s" name="tooltipicon" direction="out" />
<arg type="s" name="tooltiptitle" direction="out" />
<arg type="s" name="tooltipdescription" direction="out" />
</signal>
<signal name="ApplicationRemoved">
<arg type="i" name="position" direction="out" />
Expand All @@ -76,5 +81,11 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
<arg type="i" name="position" direction="out" />
<arg type="s" name="title" direction="out" />
</signal>
<signal name="ApplicationTooltipChanged">
<arg type="i" name="position" direction="out" />
<arg type="s" name="icon" direction="out" />
<arg type="s" name="title" direction="out" />
<arg type="s" name="description" direction="out" />
</signal>
</interface>
</node>
Loading

0 comments on commit eb93dbc

Please sign in to comment.