summaryrefslogtreecommitdiff
path: root/command/command.c
diff options
context:
space:
mode:
authorEllis Kenyo <[email protected]>2014-09-22 10:30:05 +0200
committerStefano Karapetsas <[email protected]>2014-09-22 10:30:05 +0200
commit92840d935a0fc478f25e19869702f84f2275b778 (patch)
tree6a93b112021dfbc015c7f834c3edcb3001ac458b /command/command.c
parent0cead530505e9ee27376258ea52d8192156e99f3 (diff)
downloadmate-applets-92840d935a0fc478f25e19869702f84f2275b778.tar.bz2
mate-applets-92840d935a0fc478f25e19869702f84f2275b778.tar.xz
command: Added width adjustment for command output
Diffstat (limited to 'command/command.c')
-rw-r--r--command/command.c41
1 files changed, 35 insertions, 6 deletions
diff --git a/command/command.c b/command/command.c
index e7113b65..7a606e1f 100644
--- a/command/command.c
+++ b/command/command.c
@@ -41,15 +41,13 @@
#define COMMAND_KEY "command"
#define INTERVAL_KEY "interval"
#define SHOW_ICON_KEY "show-icon"
+#define WIDTH_KEY "width"
/* 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
-
typedef struct
{
MatePanelApplet *applet;
@@ -62,6 +60,7 @@ typedef struct
gchar *command;
gint interval;
+ gint width;
guint timeout_id;
} CommandApplet;
@@ -123,6 +122,7 @@ command_settings_callback (GtkAction *action, CommandApplet *command_applet)
GtkWidget *widget;
GtkWidget *command;
GtkWidget *interval;
+ GtkWidget *width;
GtkWidget *showicon;
dialog = GTK_DIALOG (gtk_dialog_new_with_buttons(_("Command Applet Preferences"),
@@ -131,7 +131,7 @@ command_settings_callback (GtkAction *action, CommandApplet *command_applet)
GTK_STOCK_CLOSE,
GTK_RESPONSE_CLOSE,
NULL));
- table = gtk_table_new (3, 2, FALSE);
+ table = gtk_table_new (4, 2, FALSE);
gtk_table_set_row_spacings (table, 12);
gtk_table_set_col_spacings (table, 12);
@@ -159,6 +159,17 @@ command_settings_callback (GtkAction *action, CommandApplet *command_applet)
GTK_EXPAND | GTK_FILL | GTK_SHRINK, GTK_FILL,
0, 0);
+ widget = gtk_label_new (_("Maximum width (chars):"));
+ gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
+ gtk_table_attach (table, widget, 1, 2, 2, 3,
+ GTK_FILL, GTK_FILL,
+ 0, 0);
+
+ width = gtk_spin_button_new_with_range(1.0, 100.0, 1.0);
+ gtk_table_attach (table, width, 2, 3, 2, 3,
+ GTK_EXPAND | GTK_FILL | GTK_SHRINK, GTK_FILL,
+ 0, 0);
+
showicon = gtk_check_button_new_with_label (_("Show icon"));
gtk_table_attach (table, showicon, 2, 3, 3, 4,
GTK_EXPAND | GTK_FILL | GTK_SHRINK, GTK_FILL,
@@ -171,6 +182,7 @@ command_settings_callback (GtkAction *action, CommandApplet *command_applet)
/* use g_settings_bind to manage settings */
g_settings_bind (command_applet->settings, COMMAND_KEY, command, "text", G_SETTINGS_BIND_DEFAULT);
g_settings_bind (command_applet->settings, INTERVAL_KEY, interval, "value", G_SETTINGS_BIND_DEFAULT);
+ g_settings_bind (command_applet->settings, WIDTH_KEY, width, "value", G_SETTINGS_BIND_DEFAULT);
g_settings_bind (command_applet->settings, SHOW_ICON_KEY, showicon, "active", G_SETTINGS_BIND_DEFAULT);
gtk_widget_show_all (GTK_WIDGET (dialog));
@@ -193,6 +205,18 @@ settings_command_changed (GSettings *settings, gchar *key, CommandApplet *comman
command_applet->command = g_strdup ("");
}
+settings_width_changed (GSettings *settings, gchar *key, CommandApplet *command_applet)
+{
+ gint width;
+
+ width = g_settings_get_int (command_applet->settings, WIDTH_KEY);
+
+ command_applet->width = width;
+
+ /* execute command to start new timer */
+ command_execute(command_applet);
+}
+
static void
settings_interval_changed (GSettings *settings, gchar *key, CommandApplet *command_applet)
{
@@ -257,10 +281,10 @@ command_execute (CommandApplet *command_applet)
else
{
/* check output length */
- if (strlen(output) > MAX_OUTPUT_LENGTH)
+ if (strlen(output) > command_applet->width)
{
GString *strip_output;
- strip_output = g_string_new_len (output, MAX_OUTPUT_LENGTH);
+ strip_output = g_string_new_len (output, command_applet->width);
g_free (output);
output = strip_output->str;
g_string_free (strip_output, FALSE);
@@ -307,6 +331,7 @@ command_applet_fill (MatePanelApplet* applet)
command_applet->interval = g_settings_get_int (command_applet->settings, INTERVAL_KEY);
command_applet->command = g_settings_get_string (command_applet->settings, COMMAND_KEY);
+ command_applet->width = g_settings_get_int (command_applet->settings, WIDTH_KEY);
command_applet->hbox = gtk_hbox_new (FALSE, 0);
command_applet->image = gtk_image_new_from_icon_name (APPLET_ICON, 24);
@@ -339,6 +364,10 @@ command_applet_fill (MatePanelApplet* applet)
"changed::" INTERVAL_KEY,
G_CALLBACK (settings_interval_changed),
command_applet);
+ g_signal_connect(command_applet->settings,
+ "changed::" WIDTH_KEY,
+ G_CALLBACK (settings_width_changed),
+ command_applet);
g_settings_bind (command_applet->settings,
SHOW_ICON_KEY,
command_applet->image,