[evolution-rss] Do not use global variables for EShellView and EShellWindow



commit 07cbc97175b5859fae1764223ac0cc9aa104c690
Author: Milan Crha <mcrha redhat com>
Date:   Fri Aug 21 11:42:20 2015 +0200

    Do not use global variables for EShellView and EShellWindow
    
    These variables depended on actual windows, which could be closed
    without the evolution-rss code noticing it, effectively using
    already freed structure. This had been reported at:
    https://bugzilla.redhat.com/show_bug.cgi?id=1255380

 src/e-mail-formatter-evolution-rss.c |    2 +-
 src/notification.c                   |   19 ++++---
 src/notification.h                   |    2 +-
 src/rss-config-factory.c             |    5 +-
 src/rss-formatter.c                  |    9 ++-
 src/rss-status-icon.c                |   22 ++++++++-
 src/rss.c                            |   91 ++++++++++++++++++++++++----------
 src/rss.h                            |    1 +
 8 files changed, 108 insertions(+), 43 deletions(-)
---
diff --git a/src/e-mail-formatter-evolution-rss.c b/src/e-mail-formatter-evolution-rss.c
index ac838c8..cdeb42b 100644
--- a/src/e-mail-formatter-evolution-rss.c
+++ b/src/e-mail-formatter-evolution-rss.c
@@ -80,7 +80,7 @@ static gboolean
 feed_async(gpointer key)
 {
        HD *hd = (HD *)key;
-       gchar *result;
+
        e_mail_display_load_images(rss_get_display());
        e_web_view_load_string (E_WEB_VIEW (rss_get_display()), hd->content);
 
diff --git a/src/notification.c b/src/notification.c
index ad027a3..f3bda53 100644
--- a/src/notification.c
+++ b/src/notification.c
@@ -33,7 +33,6 @@ extern int rss_verbose_debug;
 #include "network-soup.h"
 #include "notification.h"
 
-extern EShellView *rss_shell_view;
 extern rssfeed *rf;
 
 #if (EVOLUTION_VERSION < 29102)
@@ -168,21 +167,25 @@ out:    g_free(msg);
 
 
 void
-taskbar_push_message(gchar *message)
+taskbar_push_message (const gchar *message)
 {
+#if EVOLUTION_VERSION >= 22900
+       EShellView *shell_view;
        EShellTaskbar *shell_taskbar;
-       g_return_if_fail(rss_shell_view != NULL);
-       shell_taskbar = e_shell_view_get_shell_taskbar (rss_shell_view);
+
+       shell_view = rss_get_mail_shell_view (FALSE);
+
+       g_return_if_fail (shell_view != NULL);
+
+       shell_taskbar = e_shell_view_get_shell_taskbar (shell_view);
        e_shell_taskbar_set_message (shell_taskbar, message);
+#endif
 }
 
 void
 taskbar_pop_message(void)
 {
-       EShellTaskbar *shell_taskbar;
-       g_return_if_fail(rss_shell_view != NULL);
-       shell_taskbar = e_shell_view_get_shell_taskbar (rss_shell_view);
-       e_shell_taskbar_set_message (shell_taskbar, "");
+       taskbar_push_message ("");
 }
 
 void
diff --git a/src/notification.h b/src/notification.h
index 52e55a5..d2ceb97 100644
--- a/src/notification.h
+++ b/src/notification.h
@@ -32,6 +32,6 @@ taskbar_op_abort(gpointer key);
 #endif
 void taskbar_op_set_progress(gchar *key, gchar *msg, gdouble progress);
 void taskbar_op_finish(gchar *key);
-void taskbar_push_message(gchar *message);
+void taskbar_push_message(const gchar *message);
 void taskbar_pop_message(void);
 
diff --git a/src/rss-config-factory.c b/src/rss-config-factory.c
index 31625b5..1fe0edd 100644
--- a/src/rss-config-factory.c
+++ b/src/rss-config-factory.c
@@ -69,7 +69,6 @@
 #endif
 
 extern int rss_verbose_debug;
-extern EShellView *rss_shell_view;
 
 #include "rss.h"
 #include "rss-formatter.h"
@@ -513,6 +512,7 @@ folder_cb (GtkWidget *widget, gpointer data)
 {
        EMailBackend *backend;
        EMailSession *session;
+       EShellView *shell_view;
 #if EVOLUTION_VERSION >= 30101
        CamelStore *store = NULL;
        gchar *folder_name = NULL;
@@ -540,7 +540,8 @@ folder_cb (GtkWidget *widget, gpointer data)
 
        gchar *text = (gchar *)gtk_label_get_text(GTK_LABEL(data));
 
-       shell_content = e_shell_view_get_shell_content (rss_shell_view);
+       shell_view = rss_get_mail_shell_view (TRUE);
+       shell_content = e_shell_view_get_shell_content (shell_view);
        reader = E_MAIL_READER (shell_content);
        backend = e_mail_reader_get_backend (reader);
 
diff --git a/src/rss-formatter.c b/src/rss-formatter.c
index a118ff3..9634980 100644
--- a/src/rss-formatter.c
+++ b/src/rss-formatter.c
@@ -31,7 +31,6 @@
 #include "rss-formatter.h"
 
 extern int rss_verbose_debug;
-extern EShellView *rss_shell_view;
 extern rssfeed *rf;
 
 gchar *
@@ -47,10 +46,12 @@ rss_process_feed(gchar *feed, guint len)
        gchar *result;
        EMailReader *reader;
        EShellContent *shell_content;
+       EShellView *shell_view;
        EMailDisplay *display;
        GtkAllocation alloc;
 
-       shell_content = e_shell_view_get_shell_content (rss_shell_view);
+       shell_view = rss_get_mail_shell_view (TRUE);
+       shell_content = e_shell_view_get_shell_content (shell_view);
        reader = E_MAIL_READER (shell_content);
        display = e_mail_reader_get_mail_display (reader);
        gtk_widget_get_allocation((GtkWidget *)display, &alloc);
@@ -167,8 +168,10 @@ rss_get_display(void)
 {
        EMailReader *reader;
        EShellContent *shell_content;
+       EShellView *shell_view;
 
-       shell_content = e_shell_view_get_shell_content (rss_shell_view);
+       shell_view = rss_get_mail_shell_view (TRUE);
+       shell_content = e_shell_view_get_shell_content (shell_view);
        reader = E_MAIL_READER (shell_content);
        return e_mail_reader_get_mail_display (reader);
 }
diff --git a/src/rss-status-icon.c b/src/rss-status-icon.c
index 967f0b0..f6138a9 100644
--- a/src/rss-status-icon.c
+++ b/src/rss-status-icon.c
@@ -26,7 +26,6 @@
 
 GtkStatusIcon *status_icon = NULL;
 gboolean winstatus;
-extern GtkWidget *evo_window;
 extern GQueue *status_msg;
 
 void status_text_free(StatusText *st);
@@ -159,6 +158,27 @@ toggle_window(void)
                }
        }
 #else
+       GtkWidget *evo_window = NULL;
+       GList *windows, *link;
+
+       windows = gtk_application_get_windows (GTK_APPLICATION (e_shell_get_default ()));
+       for (link = windows; link; link = g_list_next (link)) {
+               if (E_IS_SHELL_WINDOW (link->data)) {
+                       EShellWindow *shell_window = link->data;
+                       EShellView *shell_view;
+
+                       shell_view = e_shell_window_peek_shell_view (shell_window, "mail");
+                       if (shell_view) {
+                               evo_window = GTK_WIDGET (shell_window);
+                               if (g_strcmp0 (e_shell_window_get_active_view (shell_window), "mail") == 0)
+                                       break;
+                       }
+               }
+       }
+
+       if (!evo_window)
+               return;
+
        if (gtk_window_is_active(GTK_WINDOW(evo_window))) {
                gtk_window_iconify(GTK_WINDOW(evo_window));
                gtk_window_set_skip_taskbar_hint(
diff --git a/src/rss.c b/src/rss.c
index caa7f54..7150f34 100644
--- a/src/rss.c
+++ b/src/rss.c
@@ -260,7 +260,6 @@ struct _EMFormatRSSControlsPURI {
 GtkWidget *RSS_BTN_BACK;
 GtkWidget *RSS_BTN_FORW;
 GtkWidget *RSS_BTN_STOP;
-GtkWidget *evo_window;
 GHashTable *icons = NULL;
 #if (DATASERVER_VERSION >= 2023001)
 extern EProxy *proxy;
@@ -322,9 +321,6 @@ gboolean show_webkit(GtkWidget *webkit);
 void sync_folders(void);
 
 GtkTreeStore *evolution_store = NULL;
-#if EVOLUTION_VERSION >= 22900
-EShellView *rss_shell_view = NULL;
-#endif
 
 /*======================================================================*/
 
@@ -885,6 +881,38 @@ receive_cancel(GtkButton *button, struct _send_info *info)
 //     abort_all_soup();
 }
 
+#if EVOLUTION_VERSION >= 22900
+EShellView *
+rss_get_mail_shell_view (gboolean with_mail_reader)
+{
+       GList *windows, *link;
+       EShellView *adept_shell_view = NULL;
+
+       windows = gtk_application_get_windows (GTK_APPLICATION (e_shell_get_default ()));
+       for (link = windows; link; link = g_list_next (link)) {
+               if (E_IS_SHELL_WINDOW (link->data)) {
+                       EShellWindow *shell_window = link->data;
+                       EShellView *shell_view;
+
+                       shell_view = e_shell_window_peek_shell_view (shell_window, "mail");
+                       if (shell_view) {
+                               EShellContent *shell_content;
+
+                               shell_content = e_shell_view_get_shell_content (shell_view);
+                               if (!with_mail_reader || E_IS_MAIL_READER (shell_content)) {
+                                       if (g_strcmp0 (e_shell_window_get_active_view (shell_window), "mail") 
== 0)
+                                               return shell_view;
+
+                                       adept_shell_view = shell_view;
+                               }
+                       }
+               }
+       }
+
+       return adept_shell_view;
+}
+#endif
+
 void
 rss_select_folder(gchar *folder_name)
 {
@@ -893,18 +921,24 @@ rss_select_folder(gchar *folder_name)
 #if EVOLUTION_VERSION >= 29101
        const
 #endif
-       gchar *uri;
+       gchar *uri = NULL;
        EShellSidebar *shell_sidebar;
+       EShellView *shell_view;
 
        d("rss_select_folder() %s:%d\n", __FILE__, __LINE__);
 
        g_return_if_fail(folder_name != NULL);
 
-       shell_sidebar  = e_shell_view_get_shell_sidebar(rss_shell_view);
-       g_object_get (shell_sidebar, "folder-tree", &folder_tree, NULL);
+       shell_view = rss_get_mail_shell_view (FALSE);
+       if (shell_view) {
+               shell_sidebar = e_shell_view_get_shell_sidebar (shell_view);
+               g_object_get (shell_sidebar, "folder-tree", &folder_tree, NULL);
 
-       uri = lookup_uri_by_folder_name(folder_name);
-       em_folder_tree_set_selected(folder_tree, uri, 0);
+               if (folder_tree) {
+                       uri = lookup_uri_by_folder_name (folder_name);
+                       em_folder_tree_set_selected (folder_tree, uri, 0);
+               }
+       }
 #endif
 #if EVOLUTION_VERSION < 29101
        if (uri) g_free(uri);
@@ -1200,13 +1234,10 @@ rss_get_mail_session(void);
 EMailSession*
 rss_get_mail_session(void)
 {
-       EMailBackend *backend;
-       EMailReader *reader;
-       EShellContent *shell_content;
-       shell_content = e_shell_view_get_shell_content (rss_shell_view);
-       reader = E_MAIL_READER (shell_content);
-       backend = e_mail_reader_get_backend (reader);
-       return e_mail_backend_get_session (backend);
+       EShellBackend *shell_backend;
+
+       shell_backend = e_shell_get_backend_by_name (e_shell_get_default (), "mail");
+       return e_mail_backend_get_session (E_MAIL_BACKEND (shell_backend));
 }
 #endif
 
@@ -2679,7 +2710,7 @@ rss_component_peek_local_store(void)
        EMailSession *session;
        EShellBackend *shell_backend;
 
-       shell_backend = e_shell_view_get_shell_backend (rss_shell_view);
+       shell_backend = e_shell_get_backend_by_name (e_shell_get_default (), "mail");
 
        backend = E_MAIL_BACKEND (shell_backend);
        session = e_mail_backend_get_session (backend);
@@ -3454,11 +3485,18 @@ refresh_mail_folder(CamelFolder *mail_folder)
 #if EVOLUTION_VERSION < 30505
         mail_refresh_folder(mail_folder, NULL, NULL);
 #else
-        EShellContent *shell_content;
-        EMailReader *reader;
-        shell_content = e_shell_view_get_shell_content (rss_shell_view);
-        reader = E_MAIL_READER (shell_content);
-        e_mail_reader_refresh_folder(reader, mail_folder);
+       EShellView *shell_view;
+
+       shell_view = rss_get_mail_shell_view (TRUE);
+
+       if (shell_view) {
+               EShellContent *shell_content;
+
+               shell_content = e_shell_view_get_shell_content (shell_view);
+               if (E_IS_MAIL_READER (shell_content)) {
+                       e_mail_reader_refresh_folder (E_MAIL_READER (shell_content), mail_folder);
+               }
+       }
 #endif
 #if (DATASERVER_VERSION >= 2033001)
                 camel_folder_synchronize (mail_folder, FALSE, G_PRIORITY_DEFAULT,
@@ -3744,23 +3782,22 @@ e_plugin_ui_init (GtkUIManager *ui_manager,
 {
        EShellWindow *shell_window;
 
-       rss_shell_view = shell_view;
-       shell_window = e_shell_view_get_shell_window (rss_shell_view);
-       evo_window = (GtkWidget *)shell_window;
+       shell_window = e_shell_view_get_shell_window (shell_view);
+
        g_signal_connect (
                e_shell_window_get_action (
                        E_SHELL_WINDOW (shell_window),
                        "mail-folder-refresh"),
                        "activate",
                G_CALLBACK (org_gnome_cooly_folder_refresh),
-               rss_shell_view);
+               shell_view);
        g_signal_connect (
                e_shell_window_get_action (
                        E_SHELL_WINDOW (shell_window),
                        "quit"),
                "activate",
                G_CALLBACK (quit_cb),
-               rss_shell_view);
+               shell_view);
        rss_hooks_init();
        return TRUE;
 }
diff --git a/src/rss.h b/src/rss.h
index 9205665..0eb614a 100644
--- a/src/rss.h
+++ b/src/rss.h
@@ -559,6 +559,7 @@ gboolean check_if_enabled (
 void free_filter_uids (gpointer user_data, GObject *ex_msg);
 #if EVOLUTION_VERSION >= 22900
 void quit_cb(void *ep, EShellView *shell_view);
+EShellView *rss_get_mail_shell_view (gboolean with_mail_reader);
 #endif
 void rebase_feeds(gchar *old_name, gchar *new_name);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]