[ekiga] PrefsWindow: Build window on demand.



commit 40a8dc8fc615787d93e250e482788d3973dbf47a
Author: Damien Sandras <dsandras beip be>
Date:   Tue Jan 7 20:38:26 2014 +0100

    PrefsWindow: Build window on demand.
    
    The prefs window is not that often used. Keeping it in memory and
    showing/hiding it is a bad idea in terms of memory usage.
    
    We now build it and destroy it when required.

 lib/engine/gui/gtk-frontend/gtk-frontend.cpp       |   34 ++++++++++---------
 lib/engine/gui/gtk-frontend/gtk-frontend.h         |    4 +-
 lib/engine/gui/gtk-frontend/main_window.cpp        |   32 +++++++++++++++---
 lib/engine/gui/gtk-frontend/preferences-window.cpp |   22 +-----------
 4 files changed, 49 insertions(+), 43 deletions(-)
---
diff --git a/lib/engine/gui/gtk-frontend/gtk-frontend.cpp b/lib/engine/gui/gtk-frontend/gtk-frontend.cpp
index 3789c55..8d2b5d7 100644
--- a/lib/engine/gui/gtk-frontend/gtk-frontend.cpp
+++ b/lib/engine/gui/gtk-frontend/gtk-frontend.cpp
@@ -51,11 +51,11 @@
 #include "addressbook-window.h"
 #include "accounts-window.h"
 #include "assistant-window.h"
+#include "preferences-window.h"
 #include "call-window.h"
 #include "chat-window.h"
 #include "main_window.h"
 #include "statusicon.h"
-#include "preferences-window.h"
 #include "roster-view-gtk.h"
 #include "history-source.h"
 #include "opal-bank.h"
@@ -188,12 +188,6 @@ GtkFrontend::build ()
                                                   USER_INTERFACE ".chat-window"),
                                  gtk_widget_destroy);
 
-  preferences_window =
-    boost::shared_ptr<GtkWidget> (preferences_window_new (audio_input_core,
-                                                          audio_output_core,
-                                                          video_input_core),
-                                 gtk_widget_destroy);
-
   // BEWARE: the status icon needs the chat window at startup
   // FIXME: the above BEWARE is related to a FIXME in the main window code,
   // FIXME: hence should disappear with it
@@ -207,13 +201,12 @@ GtkFrontend::build ()
 
   // BEWARE: the main window uses the chat window at startup already,
   // and later on needs the call window, addressbook window,
-  // preferences window and assistant window
+  // assistant window
   main_window =
     boost::shared_ptr<GtkWidget> (gm_main_window_new (core),
                                   gtk_widget_destroy);
 
   gtk_window_set_transient_for (GTK_WINDOW (assistant_window.get ()), GTK_WINDOW (main_window.get ()));
-  gtk_window_set_transient_for (GTK_WINDOW (preferences_window.get ()), GTK_WINDOW (main_window.get ()));
 }
 
 
@@ -258,13 +251,6 @@ GtkFrontend::get_accounts_window () const
 
 
 const GtkWidget*
-GtkFrontend::get_preferences_window () const
-{
-  return preferences_window.get ();
-}
-
-
-const GtkWidget*
 GtkFrontend::get_call_window () const
 {
   return call_window.get ();
@@ -283,3 +269,19 @@ GtkFrontend::get_status_icon () const
 {
   return status_icon.get ();
 }
+
+
+GtkWidget*
+GtkFrontend::build_preferences_window ()
+{
+  boost::shared_ptr<Ekiga::AudioInputCore> audio_input_core =
+    core.get<Ekiga::AudioInputCore> ("audioinput-core");
+  boost::shared_ptr<Ekiga::AudioOutputCore> audio_output_core =
+    core.get<Ekiga::AudioOutputCore> ("audiooutput-core");
+  boost::shared_ptr<Ekiga::VideoInputCore> video_input_core =
+    core.get<Ekiga::VideoInputCore> ("videoinput-core");
+
+  return preferences_window_new (audio_input_core,
+                                 audio_output_core,
+                                 video_input_core);
+}
diff --git a/lib/engine/gui/gtk-frontend/gtk-frontend.h b/lib/engine/gui/gtk-frontend/gtk-frontend.h
index 5815d89..27bc164 100644
--- a/lib/engine/gui/gtk-frontend/gtk-frontend.h
+++ b/lib/engine/gui/gtk-frontend/gtk-frontend.h
@@ -66,8 +66,6 @@ public:
 
   const GtkWidget* get_main_window () const;
 
-  const GtkWidget *get_preferences_window () const;
-
   const GtkWidget *get_addressbook_window () const;
 
   const GtkWidget *get_accounts_window () const;
@@ -78,6 +76,8 @@ public:
 
   const StatusIcon *get_status_icon () const;
 
+  GtkWidget* build_preferences_window ();
+
 private :
 
   boost::shared_ptr<GtkWidget> assistant_window;
diff --git a/lib/engine/gui/gtk-frontend/main_window.cpp b/lib/engine/gui/gtk-frontend/main_window.cpp
index db87eba..3639239 100644
--- a/lib/engine/gui/gtk-frontend/main_window.cpp
+++ b/lib/engine/gui/gtk-frontend/main_window.cpp
@@ -185,6 +185,9 @@ static void show_dialpad_cb (GtkWidget *widget,
 static void show_gm_window_cb (GtkWidget *widget,
                                gpointer data);
 
+static void run_prefs_window_cb (G_GNUC_UNUSED GtkWidget *widget,
+                                 gpointer data);
+
 static gboolean on_delayed_hide_call_window_cb (gpointer data);
 
 static void ekiga_main_window_append_call_url (EkigaMainWindow *mw,
@@ -449,6 +452,27 @@ show_gm_window_cb (G_GNUC_UNUSED GtkWidget *widget,
 }
 
 static void
+run_prefs_window_cb (G_GNUC_UNUSED GtkWidget *widget,
+                     gpointer data)
+{
+  GtkWidget *prefs_window = NULL;
+
+  g_return_if_fail (EKIGA_IS_MAIN_WINDOW (data));
+  EkigaMainWindow *self = EKIGA_MAIN_WINDOW (data);
+
+  boost::shared_ptr<GtkFrontend> gtk_frontend = self->priv->gtk_frontend.lock ();
+
+  g_return_if_fail (gtk_frontend);
+
+  /* This will build a new window */
+  prefs_window = GTK_WIDGET (gtk_frontend->build_preferences_window ());
+
+  gtk_window_set_transient_for (GTK_WINDOW (prefs_window),
+                                GTK_WINDOW (self));
+  gtk_dialog_run (GTK_DIALOG (prefs_window));
+}
+
+static void
 on_account_updated (Ekiga::BankPtr /*bank*/,
                    Ekiga::AccountPtr account,
                    gpointer self)
@@ -971,7 +995,7 @@ ekiga_main_window_init_uri_toolbar (EkigaMainWindow *mw)
   /* The call button */
   item = gtk_tool_item_new ();
   call_button = gtk_button_new ();
-  image = gtk_image_new_from_icon_name ("phone-pick-up", GTK_ICON_SIZE_LARGE_TOOLBAR);
+  image = gtk_image_new_from_icon_name ("call-start-symbolic", GTK_ICON_SIZE_LARGE_TOOLBAR);
   gtk_button_set_image (GTK_BUTTON (call_button), image);
   gtk_button_set_relief (GTK_BUTTON (call_button), GTK_RELIEF_NONE);
   gtk_container_add (GTK_CONTAINER (item), call_button);
@@ -1078,7 +1102,6 @@ ekiga_main_window_init_menu (EkigaMainWindow *mw)
 {
   GtkWidget *addressbook_window = NULL;
   GtkWidget *accounts_window = NULL;
-  GtkWidget *prefs_window = NULL;
   GtkWidget *assistant_window = NULL;
 
   mw->priv->main_menu = gtk_menu_bar_new ();
@@ -1091,7 +1114,6 @@ ekiga_main_window_init_menu (EkigaMainWindow *mw)
 
   addressbook_window = GTK_WIDGET (gtk_frontend->get_addressbook_window ());
   accounts_window = GTK_WIDGET (gtk_frontend->get_accounts_window ());
-  prefs_window = GTK_WIDGET (gtk_frontend->get_preferences_window ());
   assistant_window = GTK_WIDGET (gtk_frontend->get_assistant_window ());
 
   static MenuEntry gnomemeeting_menu [] =
@@ -1152,8 +1174,8 @@ ekiga_main_window_init_menu (EkigaMainWindow *mw)
       GTK_MENU_ENTRY("preferences", NULL,
                     _("Change your preferences"),
                     GTK_STOCK_PREFERENCES, 0,
-                    G_CALLBACK (show_gm_window_cb),
-                    (gpointer) prefs_window, TRUE),
+                    G_CALLBACK (run_prefs_window_cb),
+                    (gpointer) mw, TRUE),
 
       GTK_MENU_NEW(_("_View")),
 
diff --git a/lib/engine/gui/gtk-frontend/preferences-window.cpp 
b/lib/engine/gui/gtk-frontend/preferences-window.cpp
index f958d4e..9257d39 100644
--- a/lib/engine/gui/gtk-frontend/preferences-window.cpp
+++ b/lib/engine/gui/gtk-frontend/preferences-window.cpp
@@ -301,13 +301,6 @@ GtkWidget * gm_pw_toggle_new (GtkWidget* grid,
 
 
 /* DESCRIPTION  :  /
- * BEHAVIOR     :  Creates a new prefs window.
- * PRE          :  /
- */
-GtkWidget *gm_pw_window_new ();
-
-
-/* DESCRIPTION  :  /
  * BEHAVIOR     :  Creates a subsection inside a section of a prefs window.
  *                 The parameters are the prefs window and the section name.
  * PRE          :  Not NULL name.
@@ -377,7 +370,7 @@ static void  gm_prefs_window_update_devices_list (PreferencesWindow *self);
 
 /* DESCRIPTION  :  This callback is called when the user clicks
  *                 on the Close or Help buttons.
- * BEHAVIOR     :  Show help or hide the window.
+ * BEHAVIOR     :  Show help or destroy the window.
  * PRE          :  /
  */
 static void dialog_response_cb (GtkDialog *dialog,
@@ -1446,20 +1439,11 @@ dialog_response_cb (GtkDialog *dialog,
     g_signal_stop_emission_by_name (dialog, "response");
     break;
   default:
-    gtk_widget_hide (GTK_WIDGET (dialog));
+    gtk_widget_destroy (GTK_WIDGET (dialog));
   }
 }
 
 
-static gboolean
-dialog_delete_event_cb (GtkWidget *dialog,
-                        G_GNUC_UNUSED gpointer data)
-{
-  gtk_widget_hide (dialog);
-  return TRUE;
-}
-
-
 static void
 refresh_devices_list_cb (G_GNUC_UNUSED GtkWidget *widget,
                          gpointer data)
@@ -1776,8 +1760,6 @@ preferences_window_new (boost::shared_ptr<Ekiga::AudioInputCore> audio_input_cor
 
   g_signal_connect (G_OBJECT (self), "response",
                     G_CALLBACK (dialog_response_cb), NULL);
-  g_signal_connect (G_OBJECT (self), "delete-event",
-                    G_CALLBACK (dialog_delete_event_cb), NULL);
 
   gtk_window_set_title (GTK_WINDOW (self), _("Ekiga Preferences"));
   pixbuf = gtk_widget_render_icon_pixbuf (GTK_WIDGET (self),


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