From 6ff9a11467a3a6d043ed5399bd65a41c1dd9b552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Olsson?= Date: Sun, 15 Aug 2010 15:10:00 +0200 Subject: [PATCH] Add functionality to run command when there is no more unread messages Works like "run on new messages" but is triggered if there previously was unread messages but now changed to zero unread messages --- panel-plugin/mailwatch-plugin-4.2.c | 47 +++++++++++++++++++++++++++++++++- panel-plugin/mailwatch-plugin.c | 43 +++++++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 3 deletions(-) diff --git a/panel-plugin/mailwatch-plugin-4.2.c b/panel-plugin/mailwatch-plugin-4.2.c index 0adf652..f0ec66e 100644 --- a/panel-plugin/mailwatch-plugin-4.2.c +++ b/panel-plugin/mailwatch-plugin-4.2.c @@ -57,7 +57,8 @@ typedef struct gchar *click_command; gchar *new_messages_command; - + gchar *no_more_unread_command; + gchar *normal_icon; gchar *new_mail_icon; @@ -114,6 +115,8 @@ mailwatch_new_messages_changed_cb(XfceMailwatch *mailwatch, gpointer arg, gtk_tooltips_set_tip(mwp->tooltip, mwp->button, _("No new mail"), NULL); mwp->newmail_icon_visible = FALSE; mwp->new_messages = 0; + if(mwp->no_more_unread_command); + xfce_exec(mwp->no_more_unread_command, FALSE, FALSE, NULL); } else if(new_messages > 0) { if(!mwp->newmail_icon_visible) { mailwatch_set_icon( mwp, TRUE ); @@ -310,7 +313,13 @@ mailwatch_read_config(Control *c, xmlNodePtr node) mwp->new_messages_command = g_strdup(value); xmlFree(value); } - + + value = xmlGetProp(node, (const xmlChar *)"no_more_unread_messages_command"); + if(value) { + mwp->no_more_unread_command = g_strdup(value); + xmlFree(value); + } + value = xmlGetProp(node, (const xmlChar *)"normal_icon"); if(value) { mwp->normal_icon = g_strdup(value); @@ -375,6 +384,8 @@ mailwatch_write_config(Control *c, xmlNodePtr node) mwp->click_command?mwp->click_command:""); xmlSetProp(node, (const xmlChar *)"new_messages_command", mwp->new_messages_command?mwp->new_messages_command:""); + xmlSetProp(node, (const xmlChar *)"no_more_unread_messages_command", + mwp->no_more_unread_command?mwp->no_more_unread_command:""); xmlSetProp(node, (const xmlChar *)"normal_icon", mwp->normal_icon?mwp->normal_icon:DEFAULT_NORMAL_ICON); @@ -579,6 +590,21 @@ mailwatch_newmsg_command_focusout_cb(GtkWidget *w, GdkEventFocus *evt, return FALSE; } +static gboolean +mailwatch_nomoreunread_command_focusout_cb(GtkWidget *w, GdkEventFocus *evt, + gpointer user_data) +{ + XfceMailwatchPlugin *mwp = user_data; + gchar *command; + + g_free(mwp->no_more_unread_command); + + command = gtk_editable_get_chars(GTK_EDITABLE(w), 0, -1); + mwp->no_more_unread_command = g_strdup(command?command:""); + + return FALSE; +} + static void mailwatch_iconbtn_clicked_cb(GtkWidget *w, gpointer user_data) { @@ -714,6 +740,23 @@ mailwatch_create_options(Control *c, GtkContainer *con, GtkWidget *done) gtk_label_set_mnemonic_widget(GTK_LABEL(lbl), entry); g_signal_connect(G_OBJECT(entry), "focus-out-event", G_CALLBACK(mailwatch_newmsg_command_focusout_cb), mwp); + + hbox = gtk_hbox_new(FALSE, BORDER/2); + gtk_widget_show(hbox); + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); + + lbl = gtk_label_new_with_mnemonic(_("Run on no more _unread messages:")); + gtk_widget_show(lbl); + gtk_box_pack_start(GTK_BOX(hbox), lbl, FALSE, FALSE, 0); + + entry = gtk_entry_new(); + if(mwp->no_more_unread_command) + gtk_entry_set_text(GTK_ENTRY(entry), mwp->no_more_unread_command); + gtk_widget_show(entry); + gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0); + gtk_label_set_mnemonic_widget(GTK_LABEL(lbl), entry); + g_signal_connect(G_OBJECT(entry), "focus-out-event", + G_CALLBACK(mailwatch_nomoreunread_command_focusout_cb), mwp); frame = xfce_framebox_new(_("Icons"), TRUE); gtk_widget_show(frame); diff --git a/panel-plugin/mailwatch-plugin.c b/panel-plugin/mailwatch-plugin.c index 6bd6c4b..8dce30d 100644 --- a/panel-plugin/mailwatch-plugin.c +++ b/panel-plugin/mailwatch-plugin.c @@ -61,7 +61,8 @@ typedef struct gchar *click_command; gchar *new_messages_command; - + gchar *no_more_unread_command; + gchar *normal_icon; gchar *new_mail_icon; @@ -107,6 +108,8 @@ mailwatch_new_messages_changed_cb(XfceMailwatch *mailwatch, gpointer arg, xfce_panel_plugin_get_size(mwp->plugin), mwp); gtk_tooltips_set_tip(mwp->tooltip, mwp->button, _("No new mail"), NULL); + if(mwp->no_more_unread_command); + xfce_exec(mwp->no_more_unread_command, FALSE, FALSE, NULL); } else if(new_messages > 0) { if(!mwp->newmail_icon_visible) { mwp->newmail_icon_visible = TRUE; @@ -473,6 +476,10 @@ mailwatch_read_config(XfcePanelPlugin *plugin, XfceMailwatchPlugin *mwp) value = xfce_rc_read_entry(rc, "new_messages_command", NULL); if(value) mwp->new_messages_command = g_strdup(value); + + value = xfce_rc_read_entry(rc, "no_more_unread_messages_command", NULL); + if(value) + mwp->no_more_unread_command = g_strdup(value); value = xfce_rc_read_entry(rc, "normal_icon", NULL); if(value) { @@ -530,6 +537,8 @@ mailwatch_write_config(XfcePanelPlugin *plugin, XfceMailwatchPlugin *mwp) mwp->click_command?mwp->click_command:""); xfce_rc_write_entry(rc, "new_messages_command", mwp->new_messages_command?mwp->new_messages_command:""); + xfce_rc_write_entry(rc, "no_more_unread_messages_command", + mwp->no_more_unread_command?mwp->no_more_unread_command:""); xfce_rc_write_entry(rc, "normal_icon", mwp->normal_icon?mwp->normal_icon:DEFAULT_NORMAL_ICON); xfce_rc_write_entry(rc, "new_mail_icon", @@ -725,6 +734,21 @@ mailwatch_newmsg_command_focusout_cb(GtkWidget *w, GdkEventFocus *evt, return FALSE; } +static gboolean +mailwatch_nomoreunread_command_focusout_cb(GtkWidget *w, GdkEventFocus *evt, + gpointer user_data) +{ + XfceMailwatchPlugin *mwp = user_data; + gchar *command; + + g_free(mwp->no_more_unread_command); + + command = gtk_editable_get_chars(GTK_EDITABLE(w), 0, -1); + mwp->no_more_unread_command = g_strdup(command?command:""); + + return FALSE; +} + static void mailwatch_iconbtn_clicked_cb(GtkWidget *w, XfceMailwatchPlugin *mwp) { @@ -920,6 +944,23 @@ mailwatch_create_options(XfcePanelPlugin *plugin, XfceMailwatchPlugin *mwp) gtk_label_set_mnemonic_widget(GTK_LABEL(lbl), entry); g_signal_connect(G_OBJECT(entry), "focus-out-event", G_CALLBACK(mailwatch_newmsg_command_focusout_cb), mwp); + + hbox = gtk_hbox_new(FALSE, BORDER/2); + gtk_widget_show(hbox); + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); + + lbl = gtk_label_new_with_mnemonic(_("Run on no more _unread messages:")); + gtk_widget_show(lbl); + gtk_box_pack_start(GTK_BOX(hbox), lbl, FALSE, FALSE, 0); + + entry = gtk_entry_new(); + if(mwp->no_more_unread_command) + gtk_entry_set_text(GTK_ENTRY(entry), mwp->no_more_unread_command); + gtk_widget_show(entry); + gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0); + gtk_label_set_mnemonic_widget(GTK_LABEL(lbl), entry); + g_signal_connect(G_OBJECT(entry), "focus-out-event", + G_CALLBACK(mailwatch_nomoreunread_command_focusout_cb), mwp); frame = xfce_mailwatch_create_framebox(_("Icons"), &frame_bin); gtk_widget_show(frame); -- 1.7.2.1