summaryrefslogtreecommitdiff
path: root/command
diff options
context:
space:
mode:
Diffstat (limited to 'command')
-rw-r--r--command/command.c56
1 files changed, 44 insertions, 12 deletions
diff --git a/command/command.c b/command/command.c
index c07040f9..a476a690 100644
--- a/command/command.c
+++ b/command/command.c
@@ -41,6 +41,11 @@
#define INTERVAL_KEY "interval"
#define SHOW_ICON_KEY "show-icon"
+/* GKeyFile constants */
+#define GK_COMMAND_GROUP "Command"
+#define GK_COMMAND_OUTPUT "Output"
+#define GK_COMMAND_ICON "Icon"
+
/* Max output lenght accepted from commands */
#define MAX_OUTPUT_LENGTH 30
@@ -222,22 +227,49 @@ command_execute (CommandApplet *command_applet)
{
if ((output != NULL) && (output[0] != 0))
{
- /* check output length */
- if (strlen(output) > MAX_OUTPUT_LENGTH)
+ /* check if output is a custom GKeyFile */
+ if (g_str_has_prefix (output, "[Command]"))
{
- GString *strip_output;
- strip_output = g_string_new_len (output, MAX_OUTPUT_LENGTH);
- g_free (output);
- output = strip_output->str;
- g_string_free (strip_output, FALSE);
+ GKeyFile *file = g_key_file_new ();
+ if (g_key_file_load_from_data (file, output, -1, G_KEY_FILE_NONE, NULL))
+ {
+ gchar *goutput = g_key_file_get_string (file, GK_COMMAND_GROUP, GK_COMMAND_OUTPUT, NULL);
+ gchar *icon = g_key_file_get_string (file, GK_COMMAND_GROUP, GK_COMMAND_ICON, NULL);
+
+ if (goutput)
+ {
+ gtk_label_set_use_markup (command_applet->label, TRUE);
+ gtk_label_set_markup (command_applet->label, goutput);
+ }
+ if (icon)
+ gtk_image_set_from_icon_name (command_applet->image, icon, 24);
+
+ g_free (goutput);
+ g_free (icon);
+ }
+ else
+ gtk_label_set_text (command_applet->label, ERROR_OUTPUT);
+ g_key_file_free (file);
}
- /* remove last char if it is '\n' to avoid aligment problems */
- if (g_str_has_suffix (output, "\n"))
+ else
{
- output[strlen(output) - 1] = 0;
+ /* check output length */
+ if (strlen(output) > MAX_OUTPUT_LENGTH)
+ {
+ GString *strip_output;
+ strip_output = g_string_new_len (output, MAX_OUTPUT_LENGTH);
+ g_free (output);
+ output = strip_output->str;
+ g_string_free (strip_output, FALSE);
+ }
+ /* remove last char if it is '\n' to avoid aligment problems */
+ if (g_str_has_suffix (output, "\n"))
+ {
+ output[strlen(output) - 1] = 0;
+ }
+
+ gtk_label_set_text (command_applet->label, output);
}
-
- gtk_label_set_text (command_applet->label, output);
}
else
gtk_label_set_text (command_applet->label, ERROR_OUTPUT);