aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Tari <robert@tari.in>2021-10-15 22:52:56 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2021-10-21 21:55:54 +0200
commit641e08a678c0d83fb12c78baf917857bf6367138 (patch)
treef415af79977fad74f5c18f262affc7465b89e734 /src
parent3fc70514615c4fe2b14f33ec41be0f549e6049ee (diff)
downloadayatana-indicator-messages-641e08a678c0d83fb12c78baf917857bf6367138.tar.gz
ayatana-indicator-messages-641e08a678c0d83fb12c78baf917857bf6367138.tar.bz2
ayatana-indicator-messages-641e08a678c0d83fb12c78baf917857bf6367138.zip
Remove config.h dependency
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/im-accounts-service.c6
-rw-r--r--src/indicator-desktop-shortcuts.c1046
-rw-r--r--src/messages-service.c357
4 files changed, 703 insertions, 707 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c5cdc56..4c8ace8 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -36,7 +36,6 @@ set(
messages-service.c
)
-file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/config.h" "")# Dummy file - drop all includes once we've switched to CMake
set_source_files_properties(${SOURCES} PROPERTIES COMPILE_FLAGS ${COMPILE_FLAGS})
add_executable("ayatana-indicator-messages-service" ${SOURCES} ${SOURCES_GEN})
target_compile_definitions(
diff --git a/src/im-accounts-service.c b/src/im-accounts-service.c
index 30c80ec..8507cae 100644
--- a/src/im-accounts-service.c
+++ b/src/im-accounts-service.c
@@ -1,5 +1,6 @@
/*
* Copyright © 2014 Canonical Ltd.
+ * Copyright © 2021 Robert Tari
*
* 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
@@ -15,12 +16,9 @@
*
* Authors:
* Ted Gould <ted@canonical.com>
+ * Robert Tari <robert@tari.in>
*/
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
#include <act/act.h>
#include "im-accounts-service.h"
diff --git a/src/indicator-desktop-shortcuts.c b/src/indicator-desktop-shortcuts.c
index bbac612..5482657 100644
--- a/src/indicator-desktop-shortcuts.c
+++ b/src/indicator-desktop-shortcuts.c
@@ -3,9 +3,11 @@ A small file to parse through the actions that are available
in the desktop file and making those easily usable.
Copyright 2010 Canonical Ltd.
+Copyright 2021 Robert Tari
Authors:
Ted Gould <ted@canonical.com>
+ Robert Tari <robert@tari.in>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -21,10 +23,6 @@ License along with this library. If not, see
<http://www.gnu.org/licenses/>.
*/
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
#include <gio/gdesktopappinfo.h>
#include "indicator-desktop-shortcuts.h"
@@ -40,23 +38,23 @@ License along with this library. If not, see
typedef enum _actions_t actions_t;
enum _actions_t {
- ACTIONS_NONE,
- ACTIONS_XAYATANA,
- ACTIONS_DESKTOP_SPEC
+ ACTIONS_NONE,
+ ACTIONS_XAYATANA,
+ ACTIONS_DESKTOP_SPEC
};
typedef struct {
- actions_t actions;
- GKeyFile * keyfile;
- gchar * identity;
- GArray * nicks;
- gchar * domain;
+ actions_t actions;
+ GKeyFile * keyfile;
+ gchar * identity;
+ GArray * nicks;
+ gchar * domain;
} IndicatorDesktopShortcutsPrivate;
enum {
- PROP_0,
- PROP_DESKTOP_FILE,
- PROP_IDENTITY
+ PROP_0,
+ PROP_DESKTOP_FILE,
+ PROP_IDENTITY
};
static void indicator_desktop_shortcuts_class_init (IndicatorDesktopShortcutsClass *klass);
@@ -74,176 +72,176 @@ G_DEFINE_TYPE_WITH_PRIVATE (IndicatorDesktopShortcuts, indicator_desktop_shortcu
static void
indicator_desktop_shortcuts_class_init (IndicatorDesktopShortcutsClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->dispose = indicator_desktop_shortcuts_dispose;
- object_class->finalize = indicator_desktop_shortcuts_finalize;
-
- /* Property funcs */
- object_class->set_property = set_property;
- object_class->get_property = get_property;
-
- g_object_class_install_property(object_class, PROP_DESKTOP_FILE,
- g_param_spec_string(PROP_DESKTOP_FILE_S,
- "The path of the desktop file to read",
- "A path to a desktop file that we'll look for shortcuts in.",
- NULL,
- G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property(object_class, PROP_IDENTITY,
- g_param_spec_string(PROP_IDENTITY_S,
- "The string that represents the identity that we're acting as.",
- "Used to process ShowIn and NotShownIn fields of the desktop shortcust to get the proper list.",
- NULL,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY));
-
- return;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = indicator_desktop_shortcuts_dispose;
+ object_class->finalize = indicator_desktop_shortcuts_finalize;
+
+ /* Property funcs */
+ object_class->set_property = set_property;
+ object_class->get_property = get_property;
+
+ g_object_class_install_property(object_class, PROP_DESKTOP_FILE,
+ g_param_spec_string(PROP_DESKTOP_FILE_S,
+ "The path of the desktop file to read",
+ "A path to a desktop file that we'll look for shortcuts in.",
+ NULL,
+ G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property(object_class, PROP_IDENTITY,
+ g_param_spec_string(PROP_IDENTITY_S,
+ "The string that represents the identity that we're acting as.",
+ "Used to process ShowIn and NotShownIn fields of the desktop shortcust to get the proper list.",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY));
+
+ return;
}
/* Initialize instance data */
static void
indicator_desktop_shortcuts_init (IndicatorDesktopShortcuts *self)
{
- IndicatorDesktopShortcutsPrivate * priv = indicator_desktop_shortcuts_get_instance_private(self);
+ IndicatorDesktopShortcutsPrivate * priv = indicator_desktop_shortcuts_get_instance_private(self);
- priv->keyfile = NULL;
- priv->identity = NULL;
- priv->domain = NULL;
- priv->nicks = g_array_new(TRUE, TRUE, sizeof(gchar *));
- priv->actions = ACTIONS_NONE;
+ priv->keyfile = NULL;
+ priv->identity = NULL;
+ priv->domain = NULL;
+ priv->nicks = g_array_new(TRUE, TRUE, sizeof(gchar *));
+ priv->actions = ACTIONS_NONE;
- return;
+ return;
}
/* Clear object references */
static void
indicator_desktop_shortcuts_dispose (GObject *object)
{
- IndicatorDesktopShortcuts * self = INDICATOR_DESKTOP_SHORTCUTS(object);
- IndicatorDesktopShortcutsPrivate * priv = indicator_desktop_shortcuts_get_instance_private(self);
+ IndicatorDesktopShortcuts * self = INDICATOR_DESKTOP_SHORTCUTS(object);
+ IndicatorDesktopShortcutsPrivate * priv = indicator_desktop_shortcuts_get_instance_private(self);
- if (priv->keyfile) {
- g_key_file_free(priv->keyfile);
- priv->keyfile = NULL;
- }
+ if (priv->keyfile) {
+ g_key_file_free(priv->keyfile);
+ priv->keyfile = NULL;
+ }
- G_OBJECT_CLASS (indicator_desktop_shortcuts_parent_class)->dispose (object);
- return;
+ G_OBJECT_CLASS (indicator_desktop_shortcuts_parent_class)->dispose (object);
+ return;
}
/* Free all memory */
static void
indicator_desktop_shortcuts_finalize (GObject *object)
{
- IndicatorDesktopShortcuts * self = INDICATOR_DESKTOP_SHORTCUTS(object);
- IndicatorDesktopShortcutsPrivate * priv = indicator_desktop_shortcuts_get_instance_private(self);
-
- if (priv->identity != NULL) {
- g_free(priv->identity);
- priv->identity = NULL;
- }
-
- if (priv->domain != NULL) {
- g_free(priv->domain);
- priv->domain = NULL;
- }
-
- if (priv->nicks != NULL) {
- gint i;
- for (i = 0; i < priv->nicks->len; i++) {
- gchar * nick = g_array_index(priv->nicks, gchar *, i);
- g_free(nick);
- }
- g_array_free(priv->nicks, TRUE);
- priv->nicks = NULL;
- }
-
- G_OBJECT_CLASS (indicator_desktop_shortcuts_parent_class)->finalize (object);
- return;
+ IndicatorDesktopShortcuts * self = INDICATOR_DESKTOP_SHORTCUTS(object);
+ IndicatorDesktopShortcutsPrivate * priv = indicator_desktop_shortcuts_get_instance_private(self);
+
+ if (priv->identity != NULL) {
+ g_free(priv->identity);
+ priv->identity = NULL;
+ }
+
+ if (priv->domain != NULL) {
+ g_free(priv->domain);
+ priv->domain = NULL;
+ }
+
+ if (priv->nicks != NULL) {
+ gint i;
+ for (i = 0; i < priv->nicks->len; i++) {
+ gchar * nick = g_array_index(priv->nicks, gchar *, i);
+ g_free(nick);
+ }
+ g_array_free(priv->nicks, TRUE);
+ priv->nicks = NULL;
+ }
+
+ G_OBJECT_CLASS (indicator_desktop_shortcuts_parent_class)->finalize (object);
+ return;
}
/* Sets one of the two properties we have, only at construction though */
static void
set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec)
{
- g_return_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(object));
- IndicatorDesktopShortcuts * self = INDICATOR_DESKTOP_SHORTCUTS(object);
- IndicatorDesktopShortcutsPrivate * priv = indicator_desktop_shortcuts_get_instance_private(self);
-
- switch(prop_id) {
- case PROP_DESKTOP_FILE: {
- if (priv->keyfile != NULL) {
- g_key_file_free(priv->keyfile);
- priv->keyfile = NULL;
- priv->actions = ACTIONS_NONE;
- }
-
- GError * error = NULL;
- GKeyFile * keyfile = g_key_file_new();
- g_key_file_load_from_file(keyfile, g_value_get_string(value), G_KEY_FILE_NONE, &error);
-
- if (error != NULL) {
- g_warning("Unable to load keyfile from file '%s': %s", g_value_get_string(value), error->message);
- g_error_free(error);
- g_key_file_free(keyfile);
- break;
- }
-
- /* Always prefer the desktop spec if we can get it */
- if (priv->actions == ACTIONS_NONE && g_key_file_has_key(keyfile, G_KEY_FILE_DESKTOP_GROUP, ACTIONS_KEY, NULL)) {
- priv->actions = ACTIONS_DESKTOP_SPEC;
- }
-
- /* But fallback if we can't */
- if (priv->actions == ACTIONS_NONE && g_key_file_has_key(keyfile, G_KEY_FILE_DESKTOP_GROUP, OLD_SHORTCUTS_KEY, NULL)) {
- priv->actions = ACTIONS_XAYATANA;
- g_warning("Desktop file '%s' is using a deprecated format for its actions that will be dropped soon.", g_value_get_string(value));
- }
-
- if (priv->actions == ACTIONS_NONE) {
- g_key_file_free(keyfile);
- break;
- }
-
- priv->keyfile = keyfile;
- parse_keyfile(INDICATOR_DESKTOP_SHORTCUTS(object));
- break;
- }
- case PROP_IDENTITY:
- if (priv->identity != NULL) {
- g_warning("Identity already set to '%s' and trying to set it to '%s'.", priv->identity, g_value_get_string(value));
- return;
- }
- priv->identity = g_value_dup_string(value);
- parse_keyfile(INDICATOR_DESKTOP_SHORTCUTS(object));
- break;
- /* *********************** */
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-
- return;
+ g_return_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(object));
+ IndicatorDesktopShortcuts * self = INDICATOR_DESKTOP_SHORTCUTS(object);
+ IndicatorDesktopShortcutsPrivate * priv = indicator_desktop_shortcuts_get_instance_private(self);
+
+ switch(prop_id) {
+ case PROP_DESKTOP_FILE: {
+ if (priv->keyfile != NULL) {
+ g_key_file_free(priv->keyfile);
+ priv->keyfile = NULL;
+ priv->actions = ACTIONS_NONE;
+ }
+
+ GError * error = NULL;
+ GKeyFile * keyfile = g_key_file_new();
+ g_key_file_load_from_file(keyfile, g_value_get_string(value), G_KEY_FILE_NONE, &error);
+
+ if (error != NULL) {
+ g_warning("Unable to load keyfile from file '%s': %s", g_value_get_string(value), error->message);
+ g_error_free(error);
+ g_key_file_free(keyfile);
+ break;
+ }
+
+ /* Always prefer the desktop spec if we can get it */
+ if (priv->actions == ACTIONS_NONE && g_key_file_has_key(keyfile, G_KEY_FILE_DESKTOP_GROUP, ACTIONS_KEY, NULL)) {
+ priv->actions = ACTIONS_DESKTOP_SPEC;
+ }
+
+ /* But fallback if we can't */
+ if (priv->actions == ACTIONS_NONE && g_key_file_has_key(keyfile, G_KEY_FILE_DESKTOP_GROUP, OLD_SHORTCUTS_KEY, NULL)) {
+ priv->actions = ACTIONS_XAYATANA;
+ g_warning("Desktop file '%s' is using a deprecated format for its actions that will be dropped soon.", g_value_get_string(value));
+ }
+
+ if (priv->actions == ACTIONS_NONE) {
+ g_key_file_free(keyfile);
+ break;
+ }
+
+ priv->keyfile = keyfile;
+ parse_keyfile(INDICATOR_DESKTOP_SHORTCUTS(object));
+ break;
+ }
+ case PROP_IDENTITY:
+ if (priv->identity != NULL) {
+ g_warning("Identity already set to '%s' and trying to set it to '%s'.", priv->identity, g_value_get_string(value));
+ return;
+ }
+ priv->identity = g_value_dup_string(value);
+ parse_keyfile(INDICATOR_DESKTOP_SHORTCUTS(object));
+ break;
+ /* *********************** */
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+
+ return;
}
/* Gets either the desktop file our the identity. */
static void
get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec)
{
- g_return_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(object));
- IndicatorDesktopShortcuts * self = INDICATOR_DESKTOP_SHORTCUTS(object);
- IndicatorDesktopShortcutsPrivate * priv = indicator_desktop_shortcuts_get_instance_private(self);
-
- switch(prop_id) {
- case PROP_IDENTITY:
- g_value_set_string(value, priv->identity);
- break;
- /* *********************** */
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-
- return;
+ g_return_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(object));
+ IndicatorDesktopShortcuts * self = INDICATOR_DESKTOP_SHORTCUTS(object);
+ IndicatorDesktopShortcutsPrivate * priv = indicator_desktop_shortcuts_get_instance_private(self);
+
+ switch(prop_id) {
+ case PROP_IDENTITY:
+ g_value_set_string(value, priv->identity);
+ break;
+ /* *********************** */
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+
+ return;
}
/* Checks to see if we can, and if we can it goes through
@@ -251,97 +249,97 @@ get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspe
static void
parse_keyfile (IndicatorDesktopShortcuts * ids)
{
- IndicatorDesktopShortcuts * self = INDICATOR_DESKTOP_SHORTCUTS(ids);
- IndicatorDesktopShortcutsPrivate * priv = indicator_desktop_shortcuts_get_instance_private(self);
-
- if (priv->keyfile == NULL) {
- return;
- }
-
- if (priv->identity == NULL) {
- return;
- }
-
- /* Remove a previous translation domain if we had one
- from a previously parsed file. */
- if (priv->domain != NULL) {
- g_free(priv->domain);
- priv->domain = NULL;
- }
-
- /* Check to see if there is a custom translation domain that
- we should take into account. */
- if (priv->domain == NULL &&
- g_key_file_has_key(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, "X-GNOME-Gettext-Domain", NULL)) {
- priv->domain = g_key_file_get_string(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, "X-GNOME-Gettext-Domain", NULL);
- }
-
- if (priv->domain == NULL &&
- g_key_file_has_key(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, "X-Ubuntu-Gettext-Domain", NULL)) {
- priv->domain = g_key_file_get_string(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, "X-Ubuntu-Gettext-Domain", NULL);
- }
-
- /* We need to figure out what we're looking for and what we want to
- look for in the rest of the file */
- const gchar * list_name = NULL;
- const gchar * group_format = NULL;
- gboolean should_have_target = FALSE;
-
- switch (priv->actions) {
- case ACTIONS_NONE:
- /* None, let's just get outta here */
- return;
- case ACTIONS_XAYATANA:
- list_name = OLD_SHORTCUTS_KEY;
- group_format = "%s " OLD_GROUP_SUFFIX;
- should_have_target = TRUE;
- break;
- case ACTIONS_DESKTOP_SPEC:
- list_name = ACTIONS_KEY;
- group_format = ACTION_GROUP_PREFIX " %s";
- should_have_target = FALSE;
- break;
- default:
- g_assert_not_reached();
- return;
- }
-
- /* Okay, we've got everything we need. Let's get it on! */
- gint i;
- gsize num_nicks = 0;
- gchar ** nicks = g_key_file_get_string_list(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, list_name, &num_nicks, NULL);
-
- /* If there is an error from get_string_list num_nicks should still
- be zero, so this loop will drop out. */
- for (i = 0; i < num_nicks; i++) {
- /* g_debug("Looking at group nick %s", nicks[i]); */
- gchar * groupname = g_strdup_printf(group_format, nicks[i]);
- if (!g_key_file_has_group(priv->keyfile, groupname)) {
- g_warning("Unable to find group '%s'", groupname);
- g_free(groupname);
- continue;
- }
-
- if (!should_show(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, priv->identity, FALSE)) {
- g_free(groupname);
- continue;
- }
-
- if (!should_show(priv->keyfile, groupname, priv->identity, should_have_target)) {
- g_free(groupname);
- continue;
- }
-
- gchar * nickalloc = g_strdup(nicks[i]);
- g_array_append_val(priv->nicks, nickalloc);
- g_free(groupname);
- }
-
- if (nicks != NULL) {
- g_strfreev(nicks);
- }
-
- return;
+ IndicatorDesktopShortcuts * self = INDICATOR_DESKTOP_SHORTCUTS(ids);
+ IndicatorDesktopShortcutsPrivate * priv = indicator_desktop_shortcuts_get_instance_private(self);
+
+ if (priv->keyfile == NULL) {
+ return;
+ }
+
+ if (priv->identity == NULL) {
+ return;
+ }
+
+ /* Remove a previous translation domain if we had one
+ from a previously parsed file. */
+ if (priv->domain != NULL) {
+ g_free(priv->domain);
+ priv->domain = NULL;
+ }
+
+ /* Check to see if there is a custom translation domain that
+ we should take into account. */
+ if (priv->domain == NULL &&
+ g_key_file_has_key(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, "X-GNOME-Gettext-Domain", NULL)) {
+ priv->domain = g_key_file_get_string(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, "X-GNOME-Gettext-Domain", NULL);
+ }
+
+ if (priv->domain == NULL &&
+ g_key_file_has_key(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, "X-Ubuntu-Gettext-Domain", NULL)) {
+ priv->domain = g_key_file_get_string(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, "X-Ubuntu-Gettext-Domain", NULL);
+ }
+
+ /* We need to figure out what we're looking for and what we want to
+ look for in the rest of the file */
+ const gchar * list_name = NULL;
+ const gchar * group_format = NULL;
+ gboolean should_have_target = FALSE;
+
+ switch (priv->actions) {
+ case ACTIONS_NONE:
+ /* None, let's just get outta here */
+ return;
+ case ACTIONS_XAYATANA:
+ list_name = OLD_SHORTCUTS_KEY;
+ group_format = "%s " OLD_GROUP_SUFFIX;
+ should_have_target = TRUE;
+ break;
+ case ACTIONS_DESKTOP_SPEC:
+ list_name = ACTIONS_KEY;
+ group_format = ACTION_GROUP_PREFIX " %s";
+ should_have_target = FALSE;
+ break;
+ default:
+ g_assert_not_reached();
+ return;
+ }
+
+ /* Okay, we've got everything we need. Let's get it on! */
+ gint i;
+ gsize num_nicks = 0;
+ gchar ** nicks = g_key_file_get_string_list(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, list_name, &num_nicks, NULL);
+
+ /* If there is an error from get_string_list num_nicks should still
+ be zero, so this loop will drop out. */
+ for (i = 0; i < num_nicks; i++) {
+ /* g_debug("Looking at group nick %s", nicks[i]); */
+ gchar * groupname = g_strdup_printf(group_format, nicks[i]);
+ if (!g_key_file_has_group(priv->keyfile, groupname)) {
+ g_warning("Unable to find group '%s'", groupname);
+ g_free(groupname);
+ continue;
+ }
+
+ if (!should_show(priv->keyfile, G_KEY_FILE_DESKTOP_GROUP, priv->identity, FALSE)) {
+ g_free(groupname);
+ continue;
+ }
+
+ if (!should_show(priv->keyfile, groupname, priv->identity, should_have_target)) {
+ g_free(groupname);
+ continue;
+ }
+
+ gchar * nickalloc = g_strdup(nicks[i]);
+ g_array_append_val(priv->nicks, nickalloc);
+ g_free(groupname);
+ }
+
+ if (nicks != NULL) {
+ g_strfreev(nicks);
+ }
+
+ return;
}
/* Checks the ONLY_SHOW_IN and NOT_SHOW_IN keys for a group to
@@ -349,74 +347,74 @@ parse_keyfile (IndicatorDesktopShortcuts * ids)
static gboolean
should_show (GKeyFile * keyfile, const gchar * group, const gchar * identity, gboolean should_have_target)
{
- if (should_have_target && g_key_file_has_key(keyfile, group, OLD_ENVIRON_KEY, NULL)) {
- /* If we've got this key, we're going to return here and not
- process the deprecated keys. */
- gint j;
- gsize num_env = 0;
- gchar ** envs = g_key_file_get_string_list(keyfile, group, OLD_ENVIRON_KEY, &num_env, NULL);
-
- for (j = 0; j < num_env; j++) {
- if (g_strcmp0(envs[j], identity) == 0) {
- break;
- }
- }
-
- if (envs != NULL) {
- g_strfreev(envs);
- }
-
- if (j == num_env) {
- return FALSE;
- }
- return TRUE;
- }
-
- /* If there is a list of OnlyShowIn entries we need to check
- to see if we're in that list. If not, we drop this nick */
- if (g_key_file_has_key(keyfile, group, G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN, NULL)) {
- gint j;
- gsize num_only = 0;
- gchar ** onlies = g_key_file_get_string_list(keyfile, group, G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN, &num_only, NULL);
-
- for (j = 0; j < num_only; j++) {
- if (g_strcmp0(onlies[j], identity) == 0) {
- break;
- }
- }
-
- if (onlies != NULL) {
- g_strfreev(onlies);
- }
-
- if (j == num_only) {
- return FALSE;
- }
- }
-
- /* If there is a NotShowIn entry we need to make sure that we're
- not in that list. If we are, we need to drop out. */
- if (g_key_file_has_key(keyfile, group, G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN, NULL)) {
- gint j;
- gsize num_not = 0;
- gchar ** nots = g_key_file_get_string_list(keyfile, group, G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN, &num_not, NULL);
-
- for (j = 0; j < num_not; j++) {
- if (g_strcmp0(nots[j], identity) == 0) {
- break;
- }
- }
-
- if (nots != NULL) {
- g_strfreev(nots);
- }
-
- if (j != num_not) {
- return FALSE;
- }
- }
-
- return TRUE;
+ if (should_have_target && g_key_file_has_key(keyfile, group, OLD_ENVIRON_KEY, NULL)) {
+ /* If we've got this key, we're going to return here and not
+ process the deprecated keys. */
+ gint j;
+ gsize num_env = 0;
+ gchar ** envs = g_key_file_get_string_list(keyfile, group, OLD_ENVIRON_KEY, &num_env, NULL);
+
+ for (j = 0; j < num_env; j++) {
+ if (g_strcmp0(envs[j], identity) == 0) {
+ break;
+ }
+ }
+
+ if (envs != NULL) {
+ g_strfreev(envs);
+ }
+
+ if (j == num_env) {
+ return FALSE;
+ }
+ return TRUE;
+ }
+
+ /* If there is a list of OnlyShowIn entries we need to check
+ to see if we're in that list. If not, we drop this nick */
+ if (g_key_file_has_key(keyfile, group, G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN, NULL)) {
+ gint j;
+ gsize num_only = 0;
+ gchar ** onlies = g_key_file_get_string_list(keyfile, group, G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN, &num_only, NULL);
+
+ for (j = 0; j < num_only; j++) {
+ if (g_strcmp0(onlies[j], identity) == 0) {
+ break;
+ }
+ }
+
+ if (onlies != NULL) {
+ g_strfreev(onlies);
+ }
+
+ if (j == num_only) {
+ return FALSE;
+ }
+ }
+
+ /* If there is a NotShowIn entry we need to make sure that we're
+ not in that list. If we are, we need to drop out. */
+ if (g_key_file_has_key(keyfile, group, G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN, NULL)) {
+ gint j;
+ gsize num_not = 0;
+ gchar ** nots = g_key_file_get_string_list(keyfile, group, G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN, &num_not, NULL);
+
+ for (j = 0; j < num_not; j++) {
+ if (g_strcmp0(nots[j], identity) == 0) {
+ break;
+ }
+ }
+
+ if (nots != NULL) {
+ g_strfreev(nots);
+ }
+
+ if (j != num_not) {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
}
/* Looks through the nicks to see if this one is in the list,
@@ -424,259 +422,259 @@ should_show (GKeyFile * keyfile, const gchar * group, const gchar * identity, gb
static gboolean
is_valid_nick (gchar ** list, const gchar * nick)
{
- if (*list == NULL)
- return FALSE;
- /* g_debug("Checking Nick: %s", list[0]); */
- if (g_strcmp0(list[0], nick) == 0)
- return TRUE;
- return is_valid_nick(&list[1], nick);
+ if (*list == NULL)
+ return FALSE;
+ /* g_debug("Checking Nick: %s", list[0]); */
+ if (g_strcmp0(list[0], nick) == 0)
+ return TRUE;
+ return is_valid_nick(&list[1], nick);
}
/* API */
/**
- indicator_desktop_shortcuts_new:
- @file: The desktop file that would be opened to
- find the actions.
- @identity: This is a string that represents the identity
- that should be used in searching those actions. It
- relates to the ShowIn and NotShownIn properties.
-
- This function creates the basic object. It involves opening
- the file and parsing it. It could potentially block on IO. At
- the end of the day you'll have a fully functional object.
-
- Return value: A new #IndicatorDesktopShortcuts object.
+ indicator_desktop_shortcuts_new:
+ @file: The desktop file that would be opened to
+ find the actions.
+ @identity: This is a string that represents the identity
+ that should be used in searching those actions. It
+ relates to the ShowIn and NotShownIn properties.
+
+ This function creates the basic object. It involves opening
+ the file and parsing it. It could potentially block on IO. At
+ the end of the day you'll have a fully functional object.
+
+ Return value: A new #IndicatorDesktopShortcuts object.
*/
IndicatorDesktopShortcuts *
indicator_desktop_shortcuts_new (const gchar * file, const gchar * identity)
{
- GObject * obj = g_object_new(INDICATOR_TYPE_DESKTOP_SHORTCUTS,
- PROP_DESKTOP_FILE_S, file,
- PROP_IDENTITY_S, identity,
- NULL);
- return INDICATOR_DESKTOP_SHORTCUTS(obj);
+ GObject * obj = g_object_new(INDICATOR_TYPE_DESKTOP_SHORTCUTS,
+ PROP_DESKTOP_FILE_S, file,
+ PROP_IDENTITY_S, identity,
+ NULL);
+ return INDICATOR_DESKTOP_SHORTCUTS(obj);
}
/**
- indicator_desktop_shortcuts_get_nicks:
- @ids: The #IndicatorDesktopShortcuts object to look in
+ indicator_desktop_shortcuts_get_nicks:
+ @ids: The #IndicatorDesktopShortcuts object to look in
- Give you the list of commands that are available for this desktop
- file given the identity that was passed in at creation. This will
- filter out the various items in the desktop file. These nicks can
- then be used as keys for working with the desktop file.
+ Give you the list of commands that are available for this desktop
+ file given the identity that was passed in at creation. This will
+ filter out the various items in the desktop file. These nicks can
+ then be used as keys for working with the desktop file.
- Return value: A #NULL terminated list of strings. This memory
- is managed by the @ids object.
+ Return value: A #NULL terminated list of strings. This memory
+ is managed by the @ids object.
*/
const gchar **
indicator_desktop_shortcuts_get_nicks (IndicatorDesktopShortcuts * ids)
{
- g_return_val_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(ids), NULL);
- IndicatorDesktopShortcuts * self = INDICATOR_DESKTOP_SHORTCUTS(ids);
- IndicatorDesktopShortcutsPrivate * priv = indicator_desktop_shortcuts_get_instance_private(self);
- return (const gchar **)priv->nicks->data;
+ g_return_val_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(ids), NULL);
+ IndicatorDesktopShortcuts * self = INDICATOR_DESKTOP_SHORTCUTS(ids);
+ IndicatorDesktopShortcutsPrivate * priv = indicator_desktop_shortcuts_get_instance_private(self);
+ return (const gchar **)priv->nicks->data;
}
/**
- indicator_desktop_shortcuts_nick_get_name:
- @ids: The #IndicatorDesktopShortcuts object to look in
- @nick: Which command that we're referencing.
-
- This function looks in a desktop file for a nick to find the
- user visible name for that shortcut. The @nick parameter
- should be gotten from #indicator_desktop_shortcuts_get_nicks
- though it's not required that the exact memory location
- be the same.
-
- Return value: A user visible string for the shortcut or
- #NULL on error.
+ indicator_desktop_shortcuts_nick_get_name:
+ @ids: The #IndicatorDesktopShortcuts object to look in
+ @nick: Which command that we're referencing.
+
+ This function looks in a desktop file for a nick to find the
+ user visible name for that shortcut. The @nick parameter
+ should be gotten from #indicator_desktop_shortcuts_get_nicks
+ though it's not required that the exact memory location
+ be the same.
+
+ Return value: A user visible string for the shortcut or
+ #NULL on error.
*/
gchar *
indicator_desktop_shortcuts_nick_get_name (IndicatorDesktopShortcuts * ids, const gchar * nick)
{
- g_return_val_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(ids), NULL);
- IndicatorDesktopShortcuts * self = INDICATOR_DESKTOP_SHORTCUTS(ids);
- IndicatorDesktopShortcutsPrivate * priv = indicator_desktop_shortcuts_get_instance_private(self);
-
- g_return_val_if_fail(priv->actions != ACTIONS_NONE, NULL);
- g_return_val_if_fail(priv->keyfile != NULL, NULL);
- g_return_val_if_fail(is_valid_nick((gchar **)priv->nicks->data, nick), NULL);
-
- const gchar * group_format = NULL;
-
- switch (priv->actions) {
- case ACTIONS_XAYATANA:
- group_format = "%s " OLD_GROUP_SUFFIX;
- break;
- case ACTIONS_DESKTOP_SPEC:
- group_format = ACTION_GROUP_PREFIX " %s";
- break;
- default:
- g_assert_not_reached();
- return NULL;
- }
-
- gchar * groupheader = g_strdup_printf(group_format, nick);
- if (!g_key_file_has_group(priv->keyfile, groupheader)) {
- g_warning("The group for nick '%s' doesn't exist anymore.", nick);
- g_free(groupheader);
- return NULL;
- }
-
- if (!g_key_file_has_key(priv->keyfile, groupheader, G_KEY_FILE_DESKTOP_KEY_NAME, NULL)) {
- g_warning("No name available for nick '%s'", nick);
- g_free(groupheader);
- return NULL;
- }
-
- gchar * name = NULL;
- gchar * keyvalue = g_key_file_get_string(priv->keyfile,
- groupheader,
- G_KEY_FILE_DESKTOP_KEY_NAME,
- NULL);
- gchar * localeval = g_key_file_get_locale_string(priv->keyfile,
- groupheader,
- G_KEY_FILE_DESKTOP_KEY_NAME,
- NULL,
- NULL);
- g_free(groupheader);
-
- if (priv->domain != NULL && g_strcmp0(keyvalue, localeval) == 0) {
- name = g_strdup(g_dgettext(priv->domain, keyvalue));
- g_free(localeval);
- } else {
- name = localeval;
- }
-
- g_free(keyvalue);
-
- return name;
+ g_return_val_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(ids), NULL);
+ IndicatorDesktopShortcuts * self = INDICATOR_DESKTOP_SHORTCUTS(ids);
+ IndicatorDesktopShortcutsPrivate * priv = indicator_desktop_shortcuts_get_instance_private(self);
+
+ g_return_val_if_fail(priv->actions != ACTIONS_NONE, NULL);
+ g_return_val_if_fail(priv->keyfile != NULL, NULL);
+ g_return_val_if_fail(is_valid_nick((gchar **)priv->nicks->data, nick), NULL);
+
+ const gchar * group_format = NULL;
+
+ switch (priv->actions) {
+ case ACTIONS_XAYATANA:
+ group_format = "%s " OLD_GROUP_SUFFIX;
+ break;
+ case ACTIONS_DESKTOP_SPEC:
+ group_format = ACTION_GROUP_PREFIX " %s";
+ break;
+ default:
+ g_assert_not_reached();
+ return NULL;
+ }
+
+ gchar * groupheader = g_strdup_printf(group_format, nick);
+ if (!g_key_file_has_group(priv->keyfile, groupheader)) {
+ g_warning("The group for nick '%s' doesn't exist anymore.", nick);
+ g_free(groupheader);
+ return NULL;
+ }
+
+ if (!g_key_file_has_key(priv->keyfile, groupheader, G_KEY_FILE_DESKTOP_KEY_NAME, NULL)) {
+ g_warning("No name available for nick '%s'", nick);
+ g_free(groupheader);
+ return NULL;
+ }
+
+ gchar * name = NULL;
+ gchar * keyvalue = g_key_file_get_string(priv->keyfile,
+ groupheader,
+ G_KEY_FILE_DESKTOP_KEY_NAME,
+ NULL);
+ gchar * localeval = g_key_file_get_locale_string(priv->keyfile,
+ groupheader,
+ G_KEY_FILE_DESKTOP_KEY_NAME,
+ NULL,
+ NULL);
+ g_free(groupheader);
+
+ if (priv->domain != NULL && g_strcmp0(keyvalue, localeval) == 0) {
+ name = g_strdup(g_dgettext(priv->domain, keyvalue));
+ g_free(localeval);
+ } else {
+ name = localeval;
+ }
+
+ g_free(keyvalue);
+
+ return name;
}
/**
- indicator_desktop_shortcuts_nick_exec_with_context:
- @ids: The #IndicatorDesktopShortcuts object to look in
- @nick: Which command that we're referencing.
- @launch_context: The #GAppLaunchContext to use for launching the shortcut
+ indicator_desktop_shortcuts_nick_exec_with_context:
+ @ids: The #IndicatorDesktopShortcuts object to look in
+ @nick: Which command that we're referencing.
+ @launch_context: The #GAppLaunchContext to use for launching the shortcut
- Here we take a @nick and try and execute the action that is
- associated with it. The @nick parameter should be gotten
- from #indicator_desktop_shortcuts_get_nicks though it's not
- required that the exact memory location be the same.
+ Here we take a @nick and try and execute the action that is
+ associated with it. The @nick parameter should be gotten
+ from #indicator_desktop_shortcuts_get_nicks though it's not
+ required that the exact memory location be the same.
- Return value: #TRUE on success or #FALSE on error.
+ Return value: #TRUE on success or #FALSE on error.
*/
gboolean
indicator_desktop_shortcuts_nick_exec_with_context (IndicatorDesktopShortcuts * ids, const gchar * nick, GAppLaunchContext * launch_context)
{
- GError * error = NULL;
-
- g_return_val_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(ids), FALSE);
- IndicatorDesktopShortcuts * self = INDICATOR_DESKTOP_SHORTCUTS(ids);
- IndicatorDesktopShortcutsPrivate * priv = indicator_desktop_shortcuts_get_instance_private(self);
-
- g_return_val_if_fail(priv->actions != ACTIONS_NONE, FALSE);
- g_return_val_if_fail(priv->keyfile != NULL, FALSE);
- g_return_val_if_fail(is_valid_nick((gchar **)priv->nicks->data, nick), FALSE);
-
- const gchar * group_format = NULL;
-
- switch (priv->actions) {
- case ACTIONS_XAYATANA:
- group_format = "%s " OLD_GROUP_SUFFIX;
- break;
- case ACTIONS_DESKTOP_SPEC:
- group_format = ACTION_GROUP_PREFIX " %s";
- break;
- default:
- g_assert_not_reached();
- return FALSE;
- }
-
- gchar * groupheader = g_strdup_printf(group_format, nick);
- if (!g_key_file_has_group(priv->keyfile, groupheader)) {
- g_warning("The group for nick '%s' doesn't exist anymore.", nick);
- g_free(groupheader);
- return FALSE;
- }
-
- if (!g_key_file_has_key(priv->keyfile, groupheader, G_KEY_FILE_DESKTOP_KEY_NAME, NULL)) {
- g_warning("No name available for nick '%s'", nick);
- g_free(groupheader);
- return FALSE;
- }
-
- if (!g_key_file_has_key(priv->keyfile, groupheader, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL)) {
- g_warning("No exec available for nick '%s'", nick);
- g_free(groupheader);
- return FALSE;
- }
-
- /* Grab the name and the exec entries out of our current group */
- gchar * name = g_key_file_get_locale_string(priv->keyfile,
- groupheader,
- G_KEY_FILE_DESKTOP_KEY_NAME,
- NULL,
- NULL);
-
- gchar * exec = g_key_file_get_locale_string(priv->keyfile,
- groupheader,
- G_KEY_FILE_DESKTOP_KEY_EXEC,
- NULL,
- NULL);
-
- g_free(groupheader);
-
- GAppInfoCreateFlags flags = G_APP_INFO_CREATE_NONE;
-
- if (launch_context) {
- flags |= G_APP_INFO_CREATE_SUPPORTS_STARTUP_NOTIFICATION;
- }
-
- GAppInfo * appinfo = g_app_info_create_from_commandline(exec, name, flags, &error);
- g_free(name); g_free(exec);
-
- if (error != NULL) {
- g_warning("Unable to build Command line App info: %s", error->message);
- g_error_free(error);
- return FALSE;
- }
-
- if (appinfo == NULL) {
- g_warning("Unable to build Command line App info (unknown)");
- return FALSE;
- }
-
- gboolean launched = g_app_info_launch(appinfo, NULL, launch_context, &error);
-
- if (error != NULL) {
- g_warning("Unable to launch file from nick '%s': %s", nick, error->message);
- g_clear_error(&error);
- }
-
- g_object_unref(appinfo);
-
- return launched;
+ GError * error = NULL;
+
+ g_return_val_if_fail(INDICATOR_IS_DESKTOP_SHORTCUTS(ids), FALSE);
+ IndicatorDesktopShortcuts * self = INDICATOR_DESKTOP_SHORTCUTS(ids);
+ IndicatorDesktopShortcutsPrivate * priv = indicator_desktop_shortcuts_get_instance_private(self);
+
+ g_return_val_if_fail(priv->actions != ACTIONS_NONE, FALSE);
+ g_return_val_if_fail(priv->keyfile != NULL, FALSE);
+ g_return_val_if_fail(is_valid_nick((gchar **)priv->nicks->data, nick), FALSE);
+
+ const gchar * group_format = NULL;
+
+ switch (priv->actions) {
+ case ACTIONS_XAYATANA:
+ group_format = "%s " OLD_GROUP_SUFFIX;
+ break;
+ case ACTIONS_DESKTOP_SPEC:
+ group_format = ACTION_GROUP_PREFIX " %s";
+ break;
+ default:
+ g_assert_not_reached();
+ return FALSE;
+ }
+
+ gchar * groupheader = g_strdup_printf(group_format, nick);
+ if (!g_key_file_has_group(priv->keyfile, groupheader)) {
+ g_warning("The group for nick '%s' doesn't exist anymore.", nick);
+ g_free(groupheader);
+ return FALSE;
+ }
+
+ if (!g_key_file_has_key(priv->keyfile, groupheader, G_KEY_FILE_DESKTOP_KEY_NAME, NULL)) {
+ g_warning("No name available for nick '%s'", nick);
+ g_free(groupheader);
+ return FALSE;
+ }
+
+ if (!g_key_file_has_key(priv->keyfile, groupheader, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL)) {
+ g_warning("No exec available for nick '%s'", nick);
+ g_free(groupheader);
+ return FALSE;
+ }
+
+ /* Grab the name and the exec entries out of our current group */
+ gchar * name = g_key_file_get_locale_string(priv->keyfile,
+ groupheader,
+ G_KEY_FILE_DESKTOP_KEY_NAME,
+ NULL,
+ NULL);
+
+ gchar * exec = g_key_file_get_locale_string(priv->keyfile,
+ groupheader,
+ G_KEY_FILE_DESKTOP_KEY_EXEC,
+ NULL,
+ NULL);
+
+ g_free(groupheader);
+
+ GAppInfoCreateFlags flags = G_APP_INFO_CREATE_NONE;
+
+ if (launch_context) {
+ flags |= G_APP_INFO_CREATE_SUPPORTS_STARTUP_NOTIFICATION;
+ }
+
+ GAppInfo * appinfo = g_app_info_create_from_commandline(exec, name, flags, &error);
+ g_free(name); g_free(exec);
+
+ if (error != NULL) {
+ g_warning("Unable to build Command line App info: %s", error->message);
+ g_error_free(error);
+ return FALSE;
+ }
+
+ if (appinfo == NULL) {
+ g_warning("Unable to build Command line App info (unknown)");
+ return FALSE;
+ }
+
+ gboolean launched = g_app_info_launch(appinfo, NULL, launch_context, &error);
+
+ if (error != NULL) {
+ g_warning("Unable to launch file from nick '%s': %s", nick, error->message);
+ g_clear_error(&error);
+ }
+
+ g_object_unref(appinfo);
+
+ return launched;
}
/**
- indicator_desktop_shortcuts_nick_exec:
- @ids: The #IndicatorDesktopShortcuts object to look in
- @nick: Which command that we're referencing.
-
- Here we take a @nick and try and execute the action that is
- associated with it. The @nick parameter should be gotten
- from #indicator_desktop_shortcuts_get_nicks though it's not
- required that the exact memory location be the same.
- This function is deprecated and shouldn't be used in newly
- written code.
-
- Return value: #TRUE on success or #FALSE on error.
+ indicator_desktop_shortcuts_nick_exec:
+ @ids: The #IndicatorDesktopShortcuts object to look in
+ @nick: Which command that we're referencing.
+
+ Here we take a @nick and try and execute the action that is
+ associated with it. The @nick parameter should be gotten
+ from #indicator_desktop_shortcuts_get_nicks though it's not
+ required that the exact memory location be the same.
+ This function is deprecated and shouldn't be used in newly
+ written code.
+
+ Return value: #TRUE on success or #FALSE on error.
*/
gboolean
indicator_desktop_shortcuts_nick_exec (IndicatorDesktopShortcuts * ids, const gchar * nick)
{
- return indicator_desktop_shortcuts_nick_exec_with_context (ids, nick, NULL);
+ return indicator_desktop_shortcuts_nick_exec_with_context (ids, nick, NULL);
}
diff --git a/src/messages-service.c b/src/messages-service.c
index b123a46..1446c27 100644
--- a/src/messages-service.c
+++ b/src/messages-service.c
@@ -3,25 +3,26 @@ An indicator to show information that is in messaging applications
that the user is using.
Copyright 2012 Canonical Ltd.
+Copyright 2021 Robert Tari
Authors:
Ted Gould <ted@canonical.com>
Lars Uebernickel <lars.uebernickel@canonical.com>
+ Robert Tari <robert@tari.in>
-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
+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
by the Free Software Foundation.
-This program is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranties of
-MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranties of
+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more details.
-You should have received a copy of the GNU General Public License along
+You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <config.h>
#include <locale.h>
#include <gio/gio.h>
#include <glib/gi18n.h>
@@ -44,248 +45,248 @@ static GHashTable *menus;
static GSettings *settings;
enum {
- DBUS_ERROR_BAD_DESKTOP_FILE,
+ DBUS_ERROR_BAD_DESKTOP_FILE,
};
G_DEFINE_QUARK(indicator_messages_dbus_error, dbus_error);
static gboolean
register_application (IndicatorMessagesService *service,
- GDBusMethodInvocation *invocation,
- const gchar *desktop_id,
- const gchar *menu_path,
- gpointer user_data)
+ GDBusMethodInvocation *invocation,
+ const gchar *desktop_id,
+ const gchar *menu_path,
+ gpointer user_data)
{
- GDBusConnection *bus;
- const gchar *sender;
+ GDBusConnection *bus;
+ const gchar *sender;
- if (!im_application_list_add (applications, desktop_id)) {
- g_dbus_method_invocation_return_error(invocation, dbus_error_quark(), DBUS_ERROR_BAD_DESKTOP_FILE, "Unable to find or parse desktop file for application '%s'", desktop_id);
- return TRUE;
- }
+ if (!im_application_list_add (applications, desktop_id)) {
+ g_dbus_method_invocation_return_error(invocation, dbus_error_quark(), DBUS_ERROR_BAD_DESKTOP_FILE, "Unable to find or parse desktop file for application '%s'", desktop_id);
+ return TRUE;
+ }
- bus = g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (service));
- sender = g_dbus_method_invocation_get_sender (invocation);
+ bus = g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (service));
+ sender = g_dbus_method_invocation_get_sender (invocation);
- im_application_list_set_remote (applications, desktop_id, bus, sender, menu_path);
- g_settings_strv_append_unique (settings, "applications", desktop_id);
+ im_application_list_set_remote (applications, desktop_id, bus, sender, menu_path);
+ g_settings_strv_append_unique (settings, "applications", desktop_id);
- indicator_messages_service_complete_register_application (service, invocation);
+ indicator_messages_service_complete_register_application (service, invocation);
- return TRUE;
+ return TRUE;
}
static gboolean
unregister_application (IndicatorMessagesService *service,
- GDBusMethodInvocation *invocation,
- const gchar *desktop_id,
- gpointer user_data)
+ GDBusMethodInvocation *invocation,
+ const gchar *desktop_id,
+ gpointer user_data)
{
- im_application_list_remove (applications, desktop_id);
- g_settings_strv_remove (settings, "applications", desktop_id);
+ im_application_list_remove (applications, desktop_id);
+ g_settings_strv_remove (settings, "applications", desktop_id);
- indicator_messages_service_complete_unregister_application (service, invocation);
+ indicator_messages_service_complete_unregister_application (service, invocation);
- return TRUE;
+ return TRUE;
}
static gboolean
set_status (IndicatorMessagesService *service,
- GDBusMethodInvocation *invocation,
- const gchar *desktop_id,
- const gchar *status_str,
- gpointer user_data)
+ GDBusMethodInvocation *invocation,
+ const gchar *desktop_id,
+ const gchar *status_str,
+ gpointer user_data)
{
- GDesktopAppInfo *appinfo;
- const gchar *id;
+ GDesktopAppInfo *appinfo;
+ const gchar *id;
- g_return_val_if_fail (g_str_equal (status_str, "available") ||
- g_str_equal (status_str, "away")||
- g_str_equal (status_str, "busy") ||
- g_str_equal (status_str, "invisible") ||
- g_str_equal (status_str, "offline"),
- FALSE);
+ g_return_val_if_fail (g_str_equal (status_str, "available") ||
+ g_str_equal (status_str, "away")||
+ g_str_equal (status_str, "busy") ||
+ g_str_equal (status_str, "invisible") ||
+ g_str_equal (status_str, "offline"),
+ FALSE);
- appinfo = g_desktop_app_info_new (desktop_id);
- if (!appinfo) {
- g_warning ("could not set status for '%s', there's no desktop file with that id", desktop_id);
- return TRUE;
- }
+ appinfo = g_desktop_app_info_new (desktop_id);
+ if (!appinfo) {
+ g_warning ("could not set status for '%s', there's no desktop file with that id", desktop_id);
+ return TRUE;
+ }
- id = g_app_info_get_id (G_APP_INFO (appinfo));
+ id = g_app_info_get_id (G_APP_INFO (appinfo));
- im_application_list_set_status(applications, id, status_str);
+ im_application_list_set_status(applications, id, status_str);
- indicator_messages_service_complete_set_status (service, invocation);
+ indicator_messages_service_complete_set_status (service, invocation);
- g_object_unref (appinfo);
+ g_object_unref (appinfo);
- return TRUE;
+ return TRUE;
}
static gboolean
app_stopped (IndicatorMessagesService *service,
- GDBusMethodInvocation *invocation,
- const gchar *desktop_id,
- gpointer user_data)
+ GDBusMethodInvocation *invocation,
+ const gchar *desktop_id,
+ gpointer user_data)
{
- GDesktopAppInfo *appinfo;
- const gchar *id;
+ GDesktopAppInfo *appinfo;
+ const gchar *id;
- appinfo = g_desktop_app_info_new (desktop_id);
- if (!appinfo)
- return TRUE;
+ appinfo = g_desktop_app_info_new (desktop_id);
+ if (!appinfo)
+ return TRUE;
- id = g_app_info_get_id (G_APP_INFO (appinfo));
- im_application_list_set_remote (applications, id, NULL, NULL, NULL);
- indicator_messages_service_complete_application_stopped_running (service, invocation);
+ id = g_app_info_get_id (G_APP_INFO (appinfo));
+ im_application_list_set_remote (applications, id, NULL, NULL, NULL);
+ indicator_messages_service_complete_application_stopped_running (service, invocation);
- g_object_unref (appinfo);
+ g_object_unref (appinfo);
- return TRUE;
+ return TRUE;
}
/* The status has been set by the user, let's tell the world! */
static void
status_set_by_user (ImApplicationList * list, const gchar * status, gpointer user_data)
{
- indicator_messages_service_emit_status_changed(messages_service, status);
- return;
+ indicator_messages_service_emit_status_changed(messages_service, status);
+ return;
}
static void
on_bus_acquired (GDBusConnection *bus,
- const gchar *name,
- gpointer user_data)
+ const gchar *name,
+ gpointer user_data)
{
- GError *error = NULL;
- GHashTableIter it;
- const gchar *profile;
- ImMenu *menu;
-
- /* Register some errors */
- g_dbus_error_register_error (dbus_error_quark(), DBUS_ERROR_BAD_DESKTOP_FILE, "BadDesktopFile");
-
- g_dbus_connection_export_action_group (bus, INDICATOR_MESSAGES_DBUS_OBJECT,
- im_application_list_get_action_group (applications),
- &error);
- if (error) {
- g_warning ("unable to export action group on dbus: %s", error->message);
- g_error_free (error);
- return;
- }
-
- g_hash_table_iter_init (&it, menus);
- while (g_hash_table_iter_next (&it, (gpointer *) &profile, (gpointer *) &menu)) {
- gchar *object_path;
-
- object_path = g_strconcat (INDICATOR_MESSAGES_DBUS_OBJECT, "/", profile, NULL);
- if (!im_menu_export (menu, bus, object_path, &error)) {
- g_warning ("unable to export menu for profile '%s': %s", profile, error->message);
- g_clear_error (&error);
- }
-
- g_free (object_path);
- }
-
- g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (messages_service),
- bus, INDICATOR_MESSAGES_DBUS_SERVICE_OBJECT,
- &error);
- if (error) {
- g_warning ("unable to export messages service on dbus: %s", error->message);
- g_error_free (error);
- return;
- }
+ GError *error = NULL;
+ GHashTableIter it;
+ const gchar *profile;
+ ImMenu *menu;
+
+ /* Register some errors */
+ g_dbus_error_register_error (dbus_error_quark(), DBUS_ERROR_BAD_DESKTOP_FILE, "BadDesktopFile");
+
+ g_dbus_connection_export_action_group (bus, INDICATOR_MESSAGES_DBUS_OBJECT,
+ im_application_list_get_action_group (applications),
+ &error);
+ if (error) {
+ g_warning ("unable to export action group on dbus: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ g_hash_table_iter_init (&it, menus);
+ while (g_hash_table_iter_next (&it, (gpointer *) &profile, (gpointer *) &menu)) {
+ gchar *object_path;
+
+ object_path = g_strconcat (INDICATOR_MESSAGES_DBUS_OBJECT, "/", profile, NULL);
+ if (!im_menu_export (menu, bus, object_path, &error)) {
+ g_warning ("unable to export menu for profile '%s': %s", profile, error->message);
+ g_clear_error (&error);
+ }
+
+ g_free (object_path);
+ }
+
+ g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (messages_service),
+ bus, INDICATOR_MESSAGES_DBUS_SERVICE_OBJECT,
+ &error);
+ if (error) {
+ g_warning ("unable to export messages service on dbus: %s", error->message);
+ g_error_free (error);
+ return;
+ }
}
static void
on_name_lost (GDBusConnection *bus,
- const gchar *name,
- gpointer user_data)
+ const gchar *name,
+ gpointer user_data)
{
- GMainLoop *mainloop = user_data;
+ GMainLoop *mainloop = user_data;
- g_main_loop_quit (mainloop);
+ g_main_loop_quit (mainloop);
}
static gboolean
sig_term_handler (gpointer user_data)
{
- GMainLoop *mainloop = user_data;
+ GMainLoop *mainloop = user_data;
- g_main_loop_quit (mainloop);
+ g_main_loop_quit (mainloop);
- return FALSE;
+ return FALSE;
}
int
main (int argc, char ** argv)
{
- GMainLoop * mainloop = NULL;
- GBusNameOwnerFlags flags;
+ GMainLoop * mainloop = NULL;
+ GBusNameOwnerFlags flags;
- /* Glib init */
+ /* Glib init */
#if G_ENCODE_VERSION(GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION) <= GLIB_VERSION_2_34
- g_type_init();
+ g_type_init();
#endif
- mainloop = g_main_loop_new (NULL, FALSE);
-
- /* Setting up i18n and gettext. Apparently, we need
- all of these. */
- setlocale (LC_ALL, "");
- bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
- textdomain (GETTEXT_PACKAGE);
-
- /* Bring up the service DBus interface */
- messages_service = indicator_messages_service_skeleton_new ();
-
- flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT;
- if (argc >= 2 && g_str_equal (argv[1], "--replace"))
- flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE;
-
- g_bus_own_name (G_BUS_TYPE_SESSION, "org.ayatana.indicator.messages", flags,
- on_bus_acquired, NULL, on_name_lost, mainloop, NULL);
-
- g_signal_connect (messages_service, "handle-register-application",
- G_CALLBACK (register_application), NULL);
- g_signal_connect (messages_service, "handle-unregister-application",
- G_CALLBACK (unregister_application), NULL);
- g_signal_connect (messages_service, "handle-set-status",
- G_CALLBACK (set_status), NULL);
- g_signal_connect (messages_service, "handle-application-stopped-running",
- G_CALLBACK (app_stopped), NULL);
-
- applications = im_application_list_new ();
- g_signal_connect (applications, "status-set",
- G_CALLBACK (status_set_by_user), NULL);
-
- settings = g_settings_new ("org.ayatana.indicator.messages");
- {
- gchar **app_ids;
- gchar **id;
-
- app_ids = g_settings_get_strv (settings, "applications");
- for (id = app_ids; *id; id++)
- im_application_list_add (applications, *id);
-
- g_strfreev (app_ids);
- }
-
- menus = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref);
- g_hash_table_insert (menus, "phone", im_phone_menu_new (applications, FALSE));
- g_hash_table_insert (menus, "phone_greeter", im_phone_menu_new (applications, TRUE));
- g_hash_table_insert (menus, "desktop", im_desktop_menu_new (applications));
- g_hash_table_insert (menus, "desktop_greeter", im_desktop_menu_new (applications));
-
- g_unix_signal_add(SIGTERM, sig_term_handler, mainloop);
-
- g_main_loop_run(mainloop);
-
- /* Clean up */
- g_hash_table_unref (menus);
- g_object_unref (messages_service);
- g_object_unref (settings);
- g_object_unref (applications);
- return 0;
+ mainloop = g_main_loop_new (NULL, FALSE);
+
+ /* Setting up i18n and gettext. Apparently, we need
+ all of these. */
+ setlocale (LC_ALL, "");
+ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+ textdomain (GETTEXT_PACKAGE);
+
+ /* Bring up the service DBus interface */
+ messages_service = indicator_messages_service_skeleton_new ();
+
+ flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT;
+ if (argc >= 2 && g_str_equal (argv[1], "--replace"))
+ flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE;
+
+ g_bus_own_name (G_BUS_TYPE_SESSION, "org.ayatana.indicator.messages", flags,
+ on_bus_acquired, NULL, on_name_lost, mainloop, NULL);
+
+ g_signal_connect (messages_service, "handle-register-application",
+ G_CALLBACK (register_application), NULL);
+ g_signal_connect (messages_service, "handle-unregister-application",
+ G_CALLBACK (unregister_application), NULL);
+ g_signal_connect (messages_service, "handle-set-status",
+ G_CALLBACK (set_status), NULL);
+ g_signal_connect (messages_service, "handle-application-stopped-running",
+ G_CALLBACK (app_stopped), NULL);
+
+ applications = im_application_list_new ();
+ g_signal_connect (applications, "status-set",
+ G_CALLBACK (status_set_by_user), NULL);
+
+ settings = g_settings_new ("org.ayatana.indicator.messages");
+ {
+ gchar **app_ids;
+ gchar **id;
+
+ app_ids = g_settings_get_strv (settings, "applications");
+ for (id = app_ids; *id; id++)
+ im_application_list_add (applications, *id);
+
+ g_strfreev (app_ids);
+ }
+
+ menus = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref);
+ g_hash_table_insert (menus, "phone", im_phone_menu_new (applications, FALSE));
+ g_hash_table_insert (menus, "phone_greeter", im_phone_menu_new (applications, TRUE));
+ g_hash_table_insert (menus, "desktop", im_desktop_menu_new (applications));
+ g_hash_table_insert (menus, "desktop_greeter", im_desktop_menu_new (applications));
+
+ g_unix_signal_add(SIGTERM, sig_term_handler, mainloop);
+
+ g_main_loop_run(mainloop);
+
+ /* Clean up */
+ g_hash_table_unref (menus);
+ g_object_unref (messages_service);
+ g_object_unref (settings);
+ g_object_unref (applications);
+ return 0;
}