summaryrefslogtreecommitdiff
path: root/command/command.c
diff options
context:
space:
mode:
authorStefano Karapetsas <[email protected]>2014-01-27 10:58:10 +0100
committerStefano Karapetsas <[email protected]>2014-01-27 10:58:10 +0100
commitad455000190cf4843e06b0128b979b1ab154bc38 (patch)
treebe4c229785dc59246a4885aa6cd0d2c4f81bb42f /command/command.c
parentd9ad5361d81e50184d7554838e7379c672cecbab (diff)
downloadmate-applets-ad455000190cf4843e06b0128b979b1ab154bc38.tar.bz2
mate-applets-ad455000190cf4843e06b0128b979b1ab154bc38.tar.xz
command: Add support for output in GKeyFile (INI) format, allowing to change font and icon
The output of the command now can be in INI format, like: [Command] Output=MATE Icon=mate Output can be in pango format, icon need to be a stock name
Diffstat (limited to 'command/command.c')
-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);