← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~goehle/evolution-indicator/dont-quit-on-close into lp:evolution-indicator

 

Geoff Goehle has proposed merging lp:~goehle/evolution-indicator/dont-quit-on-close into lp:evolution-indicator.

Requested reviews:
  Indicator Applet Developers (indicator-applet-developers)
Related bugs:
  #460483 The plugin should allow Evolution to close to the indicator-applet
  https://bugs.launchpad.net/bugs/460483


A fix of the last merge, which was bungled.  

I've included functionality which allows the indicator-applet to have evolution run in the background with no open windows. 

Using g_signal when the last open shell window is closed the indicator applet hides the window instead of deleting it.  This gives the impression that evolution is "running in the applet".  

I also implemented the ability to turn this feature on and off and to run evolution on startup. 
-- 
https://code.launchpad.net/~goehle/evolution-indicator/dont-quit-on-close/+merge/42151
Your team ayatana-commits is subscribed to branch lp:evolution-indicator.
=== modified file 'src/evolution-indicator.c'
--- src/evolution-indicator.c	2010-10-14 12:27:45 +0000
+++ src/evolution-indicator.c	2010-11-29 17:40:10 +0000
@@ -1,4 +1,4 @@
-/*
+ /*
  * Copyright (C) 2009 Canonical Ltd
  *
  * This program is free software: you can redistribute it and/or modify
@@ -53,6 +53,8 @@
 #define PLAY_SOUND        CONF_DIR"/play_sound"
 #define SHOW_BUBBLE       CONF_DIR"/show_bubble"
 #define SHOW_NEW_IN_PANEL CONF_DIR"/show_new_messages_in_panel"
+#define MINIMIZE_TO_APPLET CONF_DIR"/minimize_to_applet"
+#define RUN_ON_STARTUP     CONF_DIR"/run_on_startup"
 
 #define ACCOUNT_DIR "/apps/evolution/mail"
 #define ACCOUNTS    ACCOUNT_DIR"/accounts"
@@ -81,11 +83,15 @@
 static gboolean      play_sound  = TRUE;
 static gboolean      show_bubble = TRUE;
 static gboolean      show_count  = FALSE;
+static gboolean      minimize_to_applet = TRUE;
+static gboolean      run_on_startup = FALSE;
 
 static guint         only_inbox_id  = 0;
 static guint         play_sound_id  = 0;
 static guint         show_bubble_id = 0;
 static guint         show_count_id  = 0;
+static guint         minimize_to_applet_id = 0;
+static guint         run_on_startup_id = 0;
 static guint         accounts_id    = 0;
 
 static gint message_count = 0;
@@ -95,8 +101,11 @@
 
 int         e_plugin_lib_enable               (EPlugin *ep, int enable);
 GtkWidget * e_plugin_lib_get_configure_widget (EPlugin *ep);
+static GtkWidget * get_cfg_widget (void);
 
 static void show_evolution (gpointer arg0, guint timestamp, gpointer arg1);
+static gboolean window_created_event (EShell *shell, GtkWindow *window);
+static gboolean window_delete_event (EShell *shell, GtkWindow *window);
 
 static void show_evolution_in_indicator_applet (void);
 static void hide_evolution_in_indicator_applet (void);
@@ -119,18 +128,6 @@
   REAP_NAME
 };
 
-static GtkWidget *
-get_cfg_widget (void)
-{
-	GtkWidget *vbox;
-
-	vbox = gtk_vbox_new (FALSE, 6);
-
-	gtk_widget_show (vbox);
-
-	return vbox;
-}
-
 static gboolean
 evolution_is_focused (void)
 {
@@ -225,15 +222,15 @@
   if (!t->new)
 		return;
 
-  if (only_inbox && !(t->is_inbox))
+  if (only_inbox && !t->is_inbox)
   {
-    g_debug ("EI: %s is not an inbox", t->uri);
+    g_debug ("Not inbox");
     return;
   }
 
   if (evolution_is_focused ())
-{
-    g_debug ("EI: Evolution is focused");
+  {
+    g_debug ("Evolution is focused");
     return;
   }
 
@@ -276,7 +273,7 @@
       }
     else
       {
-        g_warning ("EI: Unable to find account that matches %s", t->uri);
+        g_warning ("Unable to find account that matches %s", t->uri);
       }
     }
 
@@ -312,7 +309,7 @@
 
     if (error)
     {
-      g_warning ("EI: Could not update: %s", error->message);
+      g_warning ("Could not update: %s", error->message);
       g_error_free (error);
     }
   }
@@ -330,7 +327,7 @@
                            CA_PROP_CANBERRA_CACHE_CONTROL, "permanent",
                            NULL);
 
-    g_warning ("EI: Unable to play sound: %s\n", ca_strerror (ret));
+    g_warning ("Unable to play sound: %s\n", ca_strerror (ret));
   }
 
   g_static_mutex_unlock (&mlock);
@@ -356,7 +353,7 @@
                                        INDICATE_INDICATOR_MESSAGES_PROP_ATTENTION,
                                        "false");
 
-      g_debug ("EI: Setting %s to 0 unread messages",
+      g_debug ("Setting %s to 0 unread messages",
                indicate_indicator_get_property (indicator, "name"));
 
     }
@@ -399,6 +396,68 @@
 }
 
 static void
+minimize_to_applet_changed (GConfClient *gclient, 
+                    guint        id,
+                    GConfEntry  *entry,
+                    gpointer     data)
+{
+  GConfValue *value;
+  
+  value = entry->value;
+  
+  minimize_to_applet = gconf_value_get_bool (value);
+
+  g_debug ("EI: Minimize to applet %s", minimize_to_applet ? "true" : "false");
+}
+
+static void
+run_on_startup_changed (GConfClient *gclient, 
+                    guint        id,
+                    GConfEntry  *entry,
+                    gpointer     data)
+{
+  GConfValue *value;
+  char *home ;
+  char *command ;
+  char *desktopfile;
+  gboolean result;
+  
+  value = entry->value;
+  
+  run_on_startup = gconf_value_get_bool (value);
+
+  home = getenv ("HOME");
+  desktopfile = g_strdup(EVOLUTION_DESKTOP_FILE);
+
+  if (run_on_startup) {
+    command = g_strdup_printf("test -d %s/.config/autostart", home);
+    result = system(command);
+    g_free(command);
+    if (result) {
+      command = g_strdup_printf("mkdir -p %s/.config/autostart",home);
+      result = system(command);
+      g_free(command);
+
+    }
+    
+    command = g_strdup_printf("cp %s %s/.config/autostart/",desktopfile,home); 
+    result = system(command);
+    g_free(command);
+
+    if (result)
+      g_debug("EI: could not create file in autostart!");
+  } else {
+    command = g_strdup_printf("rm %s/.config/autostart/evolution.desktop",home);
+    result = system(command);
+    g_free(command);
+  }
+  
+  g_free(desktopfile);
+  g_debug ("EI: run_on_startup %s", run_on_startup ? "true" : "false");
+
+}
+
+static void
 show_new_in_panel_changed (GConfClient *gclient, 
                            guint        id,
                            GConfEntry  *entry,
@@ -475,7 +534,7 @@
   g_signal_connect (indicator, "user-display",
                     G_CALLBACK (show_evolution), NULL);
 
-  g_debug ("EI: New Indicator: %s %s", name, url);
+  g_debug ("New Indicator: %s %s", name, url);
 
   return indicator;
 }
@@ -562,7 +621,7 @@
                                     &error);
   if (accounts == NULL || error)
     {
-      g_warning ("EI: Unable to determine number of accounts, "
+      g_warning ("Unable to determine number of accounts, "
                  "defaulting to '1' (%s)",
                  error ? error->message : "unknown");
       if (error)
@@ -610,7 +669,7 @@
                   pop_indicator = create_indicator ("pop:",
                                                   g_dgettext ("evolution-2.28",
                                                                 "Inbox"));
-                  g_debug ("EI: New Inbox indicator");
+                  g_debug ("New Inbox inidicator");
                 }
               indicator = pop_indicator;
             }
@@ -628,7 +687,7 @@
               indicator = create_indicator (data.url, data.name);
               indicators = g_slist_append (indicators, indicator);
 
-              g_debug ("EI: New account: %s (%s)", data.name, data.url);
+              g_debug ("New account: %s (%s)", data.name, data.url);
             }
 
           if (!data.enabled)
@@ -660,7 +719,7 @@
       g_slist_free (accounts);
     }
 
-  g_debug ("EI: Number of email accounts: %d", n_accounts);
+  g_debug ("Number of email accounts: %d", n_accounts);
 }
 
 static void
@@ -680,7 +739,7 @@
 {
 	gchar * command = (gchar *)user_data;
 	if (!g_spawn_command_line_async(command, NULL)) {
-		g_warning("EI: Unable to execute command '%s'", command);
+		g_warning("Unable to execute command '%s'", command);
 	}
 	return;
 }
@@ -702,7 +761,7 @@
       ret = ca_context_create (&canberra_cxt);
       if (ret)
       {
-        g_warning ("EI: Canberra Init Error: %s", ca_strerror (ret));
+        g_warning ("Canberra Init Error: %s", ca_strerror (ret));
       }
       else
       {
@@ -713,7 +772,7 @@
                                        NULL);
         if (ret)
         {
-          g_warning ("EI: Unable to set props: %s\n", ca_strerror (ret));
+          g_warning ("Unable to set props: %s\n", ca_strerror (ret));
         }
       }
     }
@@ -765,12 +824,34 @@
     show_count_id = gconf_client_notify_add (client, SHOW_NEW_IN_PANEL, 
                              show_new_in_panel_changed, NULL, NULL, NULL);
 
+    minimize_to_applet = gconf_client_get_bool (client,
+						MINIMIZE_TO_APPLET,
+						NULL);
+    minimize_to_applet_id = gconf_client_notify_add (client, MINIMIZE_TO_APPLET,
+			minimize_to_applet_changed, NULL, NULL, NULL);
+
+    run_on_startup = gconf_client_get_bool (client,
+					    RUN_ON_STARTUP,
+					    NULL);
+    run_on_startup_id = gconf_client_notify_add (client, RUN_ON_STARTUP,
+			  run_on_startup_changed, NULL, NULL, NULL);
+
     gconf_client_add_dir (client, ACCOUNT_DIR,GCONF_CLIENT_PRELOAD_NONE, NULL);
     update_accounts ();
     accounts_id = gconf_client_notify_add (client, ACCOUNTS,
                                            on_accounts_changed, NULL,
                                            NULL, NULL);
 
+    EShell *shell = e_shell_get_default ();
+    
+    /* If we are minimizing to the applet, listen for created windows */
+    if (shell && minimize_to_applet)
+      {
+	g_signal_connect (
+			  shell, "window-created",
+			  G_CALLBACK (window_created_event), NULL);
+      }    
+
     if (show_count)
     {
       indicate_server_show (server);
@@ -788,6 +869,8 @@
     gconf_client_notify_remove (client, play_sound_id);
     gconf_client_notify_remove (client, show_bubble_id);
     gconf_client_notify_remove (client, show_count_id);
+    gconf_client_notify_remove (client, minimize_to_applet_id);
+    gconf_client_notify_remove (client, run_on_startup_id);
     gconf_client_notify_remove (client, accounts_id);
 
     g_object_unref (client);
@@ -812,6 +895,54 @@
 	return 0;
 }
 
+gboolean 
+window_created_event (EShell *shell, GtkWindow *window) 
+{
+
+  if (E_IS_SHELL_WINDOW(window)) {
+  
+    /* block evolutions built in handlers from acting */
+    g_signal_handlers_block_matched(window, G_SIGNAL_MATCH_DATA, 
+				    0, 0, NULL, NULL, shell);
+    
+    /* add our handler for the window deleted signal */
+    g_signal_connect_swapped (
+      window, "delete-event",
+      G_CALLBACK (window_delete_event), shell);
+
+  }
+}
+
+gboolean 
+window_delete_event (EShell *shell, GtkWindow *window) 
+{
+  /* If there is more than one window open then we can safely close this one.  
+     If there is only one then hide it instead of deleteing. */
+  
+  gboolean at_least_one = FALSE;
+  GList *list = e_shell_get_watched_windows (shell);
+  EShellWindow *shell_window;
+
+  /* Check if there is more than one shell window in the list */
+  while (list != NULL) {
+
+    if (E_IS_SHELL_WINDOW (list->data) && at_least_one) {
+      return FALSE;
+    } else if (E_IS_SHELL_WINDOW (list->data)) {
+      at_least_one = TRUE;
+      shell_window = list->data;
+    }
+    list = g_list_next (list);
+  }
+
+  /* If there wasn't more than one then hide the window.*/
+  gtk_window_iconify (GTK_WINDOW(shell_window));
+  gtk_widget_hide (GTK_WIDGET(shell_window));
+
+  return TRUE;
+
+}
+
 GtkWidget *
 e_plugin_lib_get_configure_widget (EPlugin *ep)
 {
@@ -849,12 +980,26 @@
                          gtk_toggle_button_get_active (button), NULL);
 }
 
+static void
+on_minimize_to_applet_toggled (GtkToggleButton *button, gpointer null)
+{
+  gconf_client_set_bool (client, MINIMIZE_TO_APPLET, 
+			 gtk_toggle_button_get_active (button), NULL);
+}
+
+static void
+on_run_on_startup_toggled (GtkToggleButton *button, gpointer null)
+{
+  gconf_client_set_bool (client, RUN_ON_STARTUP, 
+			 gtk_toggle_button_get_active (button), NULL);
+}
+
 GtkWidget *
 org_gnome_get_prefs (EPlugin *ep, EConfigHookItemFactoryData *data)
 {
   GtkWidget *vbox, *frame=NULL, *check;
   
-  g_debug ("EI: MAIL PREFS");
+  g_print ("EI: MAIL PREFS");
 
 	if (data->old)
     return data->old;
@@ -862,7 +1007,7 @@
   frame = data->parent;
   while (!GTK_IS_FRAME (frame))
   {
-    frame = gtk_widget_get_parent (frame);
+    frame = frame->parent;
 
     if (GTK_IS_WINDOW (frame) || !GTK_IS_WIDGET (frame))
       break;
@@ -875,9 +1020,9 @@
     gchar *str1;
     gchar *str2;
 
-    frame = gtk_widget_get_parent (gtk_widget_get_parent (gtk_widget_get_parent ((GtkWidget*)data)));
+    frame = (GtkWidget*)data->parent->parent->parent;
 
-    gtk_box_reorder_child (GTK_BOX (gtk_widget_get_parent (frame)), frame, 0);
+    gtk_box_reorder_child (GTK_BOX (frame->parent), frame, 0);
 
     box = gtk_hbox_new (FALSE, 0);
     gtk_frame_set_label_widget (GTK_FRAME (frame), box);
@@ -949,6 +1094,77 @@
   return check;
 }
 
+GtkWidget *
+get_cfg_widget (void)
+{
+  GtkWidget *vbox, *box, *check;
+  GtkWidget *label1, *label2, *label3, *combo;
+  const gchar *markup = "<b>%s</b>";
+  gchar *str1;
+  gchar *str2;
+
+  vbox = gtk_vbox_new (FALSE, 6);
+
+  box = gtk_hbox_new (FALSE, 0);
+
+  check = gtk_check_button_new_with_mnemonic (_("Keep _Evolution running in the background"));
+  g_object_set (check, "active", minimize_to_applet, NULL);
+  gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
+  g_signal_connect (check, "toggled", G_CALLBACK (on_minimize_to_applet_toggled), NULL);
+
+  check = gtk_check_button_new_with_mnemonic (_("_Run Evolution when computer starts"));
+  g_object_set (check, "active", run_on_startup, NULL);
+  gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
+  g_signal_connect (check, "toggled", G_CALLBACK (on_run_on_startup_toggled), NULL);
+
+  label1 = gtk_label_new (" ");
+  str1 = g_strdup_printf (markup, _("When new mail arri_ves in"));
+  gtk_label_set_markup_with_mnemonic (GTK_LABEL (label1), str1);
+  g_free (str1);
+    
+  label2 = gtk_label_new (" ");
+  
+  combo = gtk_combo_box_new_text ();
+  gtk_combo_box_append_text (GTK_COMBO_BOX (combo),
+			     n_accounts > 1 ? _("any Inbox") : _("Inbox"));
+  gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("any Folder"));
+  gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 
+			    only_inbox ? 0 : 1);
+  g_signal_connect (combo, "changed", G_CALLBACK (on_combo_changed), NULL);
+  
+  label3 = gtk_label_new (":");
+  /* i18n: ':' is used in the end of the above line (When New Mail Arrives:)*/
+  str2 = g_strdup_printf (markup, _(":"));
+  gtk_label_set_markup (GTK_LABEL (label3), str2);
+  g_free (str2);
+
+  gtk_box_pack_start (GTK_BOX (box), label1, FALSE, FALSE, 0);
+  gtk_box_pack_start (GTK_BOX (box), label2, FALSE, FALSE, 0);
+  gtk_box_pack_start (GTK_BOX (box), combo, FALSE, FALSE, 0);
+  gtk_box_pack_start (GTK_BOX (box), label3, FALSE, FALSE, 0);
+  
+  gtk_box_pack_start (GTK_BOX (vbox), box, FALSE, FALSE, 0);
+
+  check = gtk_check_button_new_with_mnemonic (_("Pla_y a sound"));
+  g_object_set (check, "active", play_sound, NULL);
+  gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
+  g_signal_connect (check, "toggled", G_CALLBACK (on_sound_toggled), NULL);
+  
+  check = gtk_check_button_new_with_mnemonic (_("_Display a notification"));
+  g_object_set (check, "active", show_bubble, NULL);
+  gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
+  g_signal_connect (check, "toggled", G_CALLBACK (on_bubble_toggled), NULL);
+  
+  check = gtk_check_button_new_with_mnemonic (_("_Indicate new messages in the panel"));
+  g_object_set (check, "active", show_count, NULL);
+  gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
+  g_signal_connect (check, "toggled", G_CALLBACK (on_show_panel_toggled), NULL);
+  
+  gtk_widget_show_all (vbox);
+  
+  return vbox;
+}
+
 /*
  *
  * SHOW EVOLUTION CODE
@@ -961,7 +1177,7 @@
 #define MAIL_ICON "evolution-mail"
   EShell *shell = e_shell_get_default ();
 
-  g_debug ("EI: Showing Evolution to user");
+  g_debug ("Showing Evolution to user");
 
   if (shell)
   {
@@ -984,7 +1200,7 @@
     shell_window = E_SHELL_WINDOW (list->data);
     if (!evolution_is_focused ())
     {
-        gtk_window_present_with_time (GTK_WINDOW (shell_window), timestamp);
+      gtk_window_present_with_time (GTK_WINDOW (shell_window), timestamp);
     }
 
     /* Switch to the mail view. */
@@ -1002,7 +1218,7 @@
                                        INDICATE_INDICATOR_MESSAGES_PROP_ATTENTION,
                                        "false");
 
-      g_debug ("EI: Setting %s to 0 unread messages",
+      g_debug ("Setting %s to 0 unread messages",
                indicate_indicator_get_property (indicator, "name"));
 
     }
@@ -1010,7 +1226,7 @@
   }
   else
   {
-    g_warning ("EI: Cannot show window, no shell");
+    g_warning ("Cannot show window, no shell");
     return;
   }
 }
@@ -1046,7 +1262,7 @@
 
           if (error)
             {
-              g_warning ("EI: Unable to remove blacklist file: %s", error->message);
+              g_warning ("Unable to remove blacklist file: %s", error->message);
               g_error_free (error);
             }
 
@@ -1079,7 +1295,7 @@
                                               &error);
           if (error)
             {
-              g_warning ("EI: Unable to create blacklist directory: %s",
+              g_warning ("Unable to create blacklist directory: %s",
                          error->message);
               g_error_free (error);
               g_object_unref (dirfile);
@@ -1090,7 +1306,7 @@
         }
       else
         {
-          g_warning ("EI: Unable to create blacklist directory: Unable to create "
+          g_warning ("Unable to create blacklist directory: Unable to create "
                      "GFile for path %s", bdir);
           g_free (bdir);
           g_free (bpath);
@@ -1111,11 +1327,11 @@
                            -1,
                            &error))
     {
-      g_debug ("EI: Successfully wrote blacklist file to %s", bpath);
+      g_debug ("Successfully wrote blacklist file to %s", bpath);
     }
   else
     {
-      g_debug ("EI: Unable to write blacklist file to %s: %s",
+      g_debug ("Unable to write blacklist file to %s: %s",
                bpath,
                error ? error->message : "Unknown");
       if (error)


Follow ups