2004-08-12 [colin] 0.9.12cvs59
authorColin Leroy <colin@colino.net>
Thu, 12 Aug 2004 13:15:32 +0000 (13:15 +0000)
committerColin Leroy <colin@colino.net>
Thu, 12 Aug 2004 13:15:32 +0000 (13:15 +0000)
* src/plugins/trayicon/trayicon.c
Add a context menu with most common operations

ChangeLog.claws
PATCHSETS
configure.ac
src/plugins/trayicon/trayicon.c

index 37fc0af5e2b9951c49c12e70473a9c1d0bbe146e..c6e9d0cf1db4c1aa10a5195b29adafa90926dea8 100644 (file)
@@ -1,3 +1,8 @@
+2004-08-12 [colin]     0.9.12cvs59
+
+       * src/plugins/trayicon/trayicon.c
+               Add a context menu with most common operations
+
 2004-08-12 [colin]     0.9.12cvs58
 
        * configure.ac
index 0037e64af6a4d516a52e5005451be51d90607faf..4d85027ded5ad425339b9d050152e376ba406715 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
@@ -40,3 +40,4 @@
 ( cvs diff -u -r 1.140 -r 1.141 src/main.c; cvs diff -u -r 1.14 -r 1.15 src/common/ssl.c; cvs diff -u -r 1.8 -r 1.9 src/common/sylpheed.c; cvs diff -u -r 1.6 -r 1.7 src/common/sylpheed.h; ) > 0.9.12cvs56.patchset
 ( cvs diff -u -r 1.141 -r 1.142 src/main.c; cvs diff -u -r 1.14 -r 1.15 src/common/socket.c; cvs diff -u -r 1.15 -r 1.16 src/common/ssl.c; cvs diff -u -r 1.9 -r 1.10 src/common/sylpheed.c; cvs diff -u -r 1.7 -r 1.8 src/common/sylpheed.h; ) > 0.9.12cvs57.patchset
 ( cvs diff -u -r 1.1117 -r 1.1118 configure.ac; cvs diff -u -r 1.7 -r 1.8 sylpheed.desktop; cvs diff -u -r 1.185 -r 1.186 src/Makefile.am; cvs diff -u -r 1.142 -r 1.143 src/main.c; ) > 0.9.12cvs58.patchset
+( cvs diff -u -r 1.14 -r 1.15 src/plugins/trayicon/trayicon.c; ) > 0.9.12cvs59.patchset
index 09003a6da5f5dfecb51dccf0ab4bbc7f53e95bd4..a80468bd90b2adc0094af602d9f29e88e5a71553 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=12
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=58
+EXTRA_VERSION=59
 EXTRA_RELEASE=
 
 if test \( $EXTRA_VERSION -eq 0 \) -o \( "x$EXTRA_RELEASE" != "x" \); then
index 7f1b18f3eb87ab6e75954b82b1c0c4dbd2791399..6392b60e994cd2dd0dc9d9bae9ddd448901c9792 100644 (file)
 #include "mainwindow.h"
 #include "gtkutils.h"
 #include "intl.h"
+#include "menu.h"
+#include "toolbar.h"
+#include "prefs_common.h"
+#include "main.h"
+#include "alertpanel.h"
 
 #include "eggtrayicon.h"
 #include "newmail.xpm"
@@ -50,6 +55,8 @@ static EggTrayIcon *trayicon;
 static GtkWidget *eventbox;
 static GtkWidget *image;
 static GtkTooltips *tooltips;
+static GtkWidget *traymenu_popup;
+
 guint destroy_signal_id;
 
 typedef enum
@@ -60,7 +67,22 @@ typedef enum
        TRAYICON_NOTHING,
 } TrayIconType;
 
-/* static gboolean mainwin_hidden = FALSE; */
+static void trayicon_get_cb        ( gpointer data, guint action, GtkWidget *widget );
+static void trayicon_get_all_cb            ( gpointer data, guint action, GtkWidget *widget );
+static void trayicon_compose_cb            ( gpointer data, guint action, GtkWidget *widget );
+static void trayicon_addressbook_cb ( gpointer data, guint action, GtkWidget *widget );
+static void trayicon_exit_cb       ( gpointer data, guint action, GtkWidget *widget );
+
+static GtkItemFactoryEntry trayicon_popup_menu_entries[] =
+{
+       {N_("/_Get"),                   NULL, trayicon_get_cb,          0, NULL},
+       {N_("/_Get _All"),              NULL, trayicon_get_all_cb,      0, NULL},
+       {N_("/---"),                    NULL, NULL,                     0, "<Separator>"},
+       {N_("/_Email"),                 NULL, trayicon_compose_cb,      0, NULL},
+       {N_("/Open A_ddressbook"),      NULL, trayicon_addressbook_cb,  0, NULL},
+       {N_("/---"),                    NULL, NULL,                     0, "<Separator>"},
+       {N_("/E_xit Sylpheed"),         NULL, trayicon_exit_cb,         0, NULL}
+};
 
 static void set_trayicon_pixmap(TrayIconType icontype)
 {
@@ -113,12 +135,26 @@ static gboolean click_cb(GtkWidget * widget,
 {
        MainWindow *mainwin;
 
+       if (event == NULL)
+               return TRUE;
+
        mainwin = mainwindow_get_mainwindow();
-       if (GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window))) {
-               main_window_hide(mainwin);
-       } else {
-               main_window_show(mainwin);
-        }
+       
+       switch (event->button) {
+       case 1:
+               if (GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window))) {
+                       main_window_hide(mainwin);
+               } else {
+                       main_window_show(mainwin);
+               }
+               break;
+       case 3:
+               gtk_menu_popup( GTK_MENU(traymenu_popup), NULL, NULL, NULL, NULL,
+                      event->button, event->time );
+               break;
+       default:
+               return TRUE;
+       }
        return TRUE;
 }
 
@@ -138,10 +174,11 @@ static void destroy_cb(GtkWidget *widget, gpointer *data)
 
 static void create_trayicon()
 {
+       gint n_entries = 0;
+       GtkItemFactory *traymenu_factory;
        GtkPacker *packer;
 
         trayicon = egg_tray_icon_new("Sylpheed-Claws");
-//        trayicon = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_widget_realize(GTK_WIDGET(trayicon));
        gtk_window_set_default_size(GTK_WINDOW(trayicon), 16, 16);
         gtk_container_set_border_width(GTK_CONTAINER(trayicon), 0);
@@ -173,6 +210,13 @@ static void create_trayicon()
         gtk_tooltips_set_delay(tooltips, 1000);
         gtk_tooltips_enable(tooltips);
 
+       n_entries = sizeof(trayicon_popup_menu_entries) /
+               sizeof(trayicon_popup_menu_entries[0]);
+       traymenu_popup = menu_create_items(trayicon_popup_menu_entries,
+                                      n_entries,
+                                      "<TrayiconMenu>", &traymenu_factory,
+                                      NULL);
+
         gtk_widget_show_all(GTK_WIDGET(trayicon));
 
        update();
@@ -231,3 +275,47 @@ const gchar *plugin_type(void)
 {
        return "GTK";
 }
+
+/* popup menu callbacks */
+static void trayicon_get_cb( gpointer data, guint action, GtkWidget *widget )
+{
+       MainWindow *mainwin = mainwindow_get_mainwindow();
+       inc_mail_cb(mainwin, 0, NULL);
+}
+
+static void trayicon_get_all_cb( gpointer data, guint action, GtkWidget *widget )
+{
+       MainWindow *mainwin = mainwindow_get_mainwindow();
+       inc_all_account_mail_cb(mainwin, 0, NULL);
+}
+
+static void trayicon_compose_cb( gpointer data, guint action, GtkWidget *widget )
+{
+       MainWindow *mainwin = mainwindow_get_mainwindow();
+       compose_mail_cb(mainwin, 0, NULL);
+}
+
+static void trayicon_addressbook_cb( gpointer data, guint action, GtkWidget *widget )
+{
+       addressbook_open(NULL);
+}
+
+static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
+{
+       if (prefs_common.confirm_on_exit) {
+               if (alertpanel(_("Exit"), _("Exit this program?"),
+                              _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
+                       return;
+               manage_window_focus_in(mainwin->window, NULL, NULL);
+       }
+
+       app_will_exit(NULL, mainwin);
+}
+
+static void trayicon_exit_cb( gpointer data, guint action, GtkWidget *widget )
+{
+       MainWindow *mainwin = mainwindow_get_mainwindow();
+
+       if (mainwin->lock_count == 0)
+               app_exit_cb(mainwin, 0, NULL);
+}