2007-08-24 [holger] 2.10.0cvs170
[claws.git] / src / plugins / trayicon / trayicon.c
index a91784abcee06484802c9e78e83117ee23c5b807..4f01ce88da47870b3eec2fef3e7d7d16797a1b4f 100644 (file)
@@ -4,7 +4,7 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -13,8 +13,8 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 
  */
 
 #ifdef HAVE_CONFIG_H
@@ -65,6 +65,7 @@ static guint folder_hook_id;
 static guint offline_hook_id;
 static guint account_hook_id;
 static guint close_hook_id;
+static guint iconified_hook_id;
 
 static GdkPixmap *newmail_pixmap[2];
 static GdkPixmap *newmail_bitmap[2];
@@ -251,13 +252,27 @@ static gboolean trayicon_close_hook(gpointer source, gpointer data)
 {
        if (source) {
                gboolean *close_allowed = (gboolean*)source;
+
+               if (trayicon_prefs.close_to_tray) {
                MainWindow *mainwin = mainwindow_get_mainwindow();
 
-               if (trayicon_prefs.close_to_tray)
                        *close_allowed = FALSE;
                if (GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window)))
                        main_window_hide(mainwin);
        }
+       }
+       return FALSE;
+}
+
+static gboolean trayicon_got_iconified_hook(gpointer source, gpointer data)
+{
+       MainWindow *mainwin = mainwindow_get_mainwindow();
+
+       if (trayicon_prefs.hide_when_iconified
+                       && GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window))
+                       && !gtk_window_get_skip_taskbar_hint(GTK_WINDOW(mainwin->window))) {
+               gtk_window_set_skip_taskbar_hint(GTK_WINDOW(mainwin->window), TRUE);
+       }
        return FALSE;
 }
 
@@ -284,13 +299,17 @@ static gboolean click_cb(GtkWidget * widget,
                        if ((gdk_window_get_state(GTK_WIDGET(mainwin->window)->window)&GDK_WINDOW_STATE_ICONIFIED)
                                        || mainwindow_is_obscured()) {
                                gtk_window_deiconify(GTK_WINDOW(mainwin->window));
+                               gtk_window_set_skip_taskbar_hint(GTK_WINDOW(mainwin->window), FALSE);
                                main_window_show(mainwin);
+                               gtk_window_present(GTK_WINDOW(mainwin->window));
                        } else {
                                main_window_hide(mainwin);
                        }
                } else {
                        gtk_window_deiconify(GTK_WINDOW(mainwin->window));
+                       gtk_window_set_skip_taskbar_hint(GTK_WINDOW(mainwin->window), FALSE);
                        main_window_show(mainwin);
+                       gtk_window_present(GTK_WINDOW(mainwin->window));
         }
                break;
        case 3:
@@ -299,10 +318,10 @@ static gboolean click_cb(GtkWidget * widget,
                /* initialize checkitem according to current offline state */
                gtk_check_menu_item_set_active(
                        GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(traymenu_factory,
-                       _("/Work Offline"))), prefs_common.work_offline);
+                       "/Work Offline")), prefs_common.work_offline);
                gtk_widget_set_sensitive(
                        GTK_WIDGET(gtk_item_factory_get_item(traymenu_factory,
-                       _("/Get Mail"))), mainwin->lock_count == 0);
+                       "/Get Mail")), mainwin->lock_count == 0);
                updating_menu = FALSE;
 
                gtk_menu_popup( GTK_MENU(traymenu_popup), NULL, NULL, NULL, NULL,
@@ -376,7 +395,7 @@ static void create_trayicon()
 
 int plugin_init(gchar **error)
 {
-       if (!check_plugin_version(MAKE_NUMERIC_VERSION(0, 9, 3, 86),
+       if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
                                VERSION_NUMERIC, PLUGIN_NAME, error))
                return -1;
 
@@ -399,7 +418,7 @@ int plugin_init(gchar **error)
        }
 
        account_hook_id = hooks_register_hook (ACCOUNT_LIST_CHANGED_HOOKLIST, trayicon_set_accounts_hook, NULL);
-       if (offline_hook_id == -1) {
+       if (account_hook_id == -1) {
                *error = g_strdup(_("Failed to register account list changed hook"));
                return -1;
        }
@@ -410,6 +429,12 @@ int plugin_init(gchar **error)
                return -1;
        }
 
+       iconified_hook_id = hooks_register_hook (MAIN_WINDOW_GOT_ICONIFIED, trayicon_got_iconified_hook, NULL);
+       if (iconified_hook_id == -1) {
+               *error = g_strdup(_("Failed to register got iconified hook"));
+               return -1;
+       }
+
        create_trayicon();
        trayicon_set_accounts_hook(NULL, NULL);
 
@@ -420,12 +445,13 @@ int plugin_init(gchar **error)
 
                if (GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window)))
                        main_window_hide(mainwin);
+               main_set_show_at_startup(FALSE);
        }
 
        return 0;
 }
 
-void plugin_done(void)
+gboolean plugin_done(void)
 {
        trayicon_prefs_done();
 
@@ -434,9 +460,10 @@ void plugin_done(void)
        hooks_unregister_hook(OFFLINE_SWITCH_HOOKLIST, offline_hook_id);
        hooks_unregister_hook(ACCOUNT_LIST_CHANGED_HOOKLIST, account_hook_id);
        hooks_unregister_hook(MAIN_WINDOW_CLOSE, close_hook_id);
+       hooks_unregister_hook(MAIN_WINDOW_GOT_ICONIFIED, iconified_hook_id);
 
        if (claws_is_exiting())
-               return;
+               return TRUE;
 
        g_signal_handler_disconnect(G_OBJECT(trayicon), destroy_signal_id);
        
@@ -445,6 +472,7 @@ void plugin_done(void)
        while (gtk_events_pending()) {
                gtk_main_iteration();
        }
+       return TRUE;
 }
 
 const gchar *plugin_name(void)
@@ -469,7 +497,7 @@ const gchar *plugin_type(void)
 
 const gchar *plugin_licence(void)
 {
-       return "GPL";
+       return "GPL3+";
 }
 
 const gchar *plugin_version(void)
@@ -513,7 +541,7 @@ static void trayicon_toggle_offline_cb( gpointer data, guint action, GtkWidget *
 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
 {
        if (prefs_common.confirm_on_exit) {
-               if (alertpanel(_("Exit"), _("Exit this program?"),
+               if (alertpanel(_("Exit"), _("Exit Claws Mail?"),
                               GTK_STOCK_CANCEL, GTK_STOCK_OK,
                               NULL) != G_ALERTALTERNATE) {
                        return;