gnome-terminal r3134 - trunk/src



Author: chpe
Date: Tue Oct  7 14:31:04 2008
New Revision: 3134
URL: http://svn.gnome.org/viewvc/gnome-terminal?rev=3134&view=rev

Log:
Move options handling to TerminalApp.

Modified:
   trunk/src/terminal-app.c
   trunk/src/terminal-app.h
   trunk/src/terminal-options.c
   trunk/src/terminal-options.h
   trunk/src/terminal.c

Modified: trunk/src/terminal-app.c
==============================================================================
--- trunk/src/terminal-app.c	(original)
+++ trunk/src/terminal-app.c	Tue Oct  7 14:31:04 2008
@@ -21,6 +21,8 @@
 
 #include <config.h>
 
+#include <errno.h>
+
 #include <glib.h>
 #undef G_DISABLE_SINGLE_INCLUDES
 #undef GTK_DISABLE_SINGLE_INCLUDES
@@ -150,6 +152,64 @@
 
 /* Helper functions */
 
+static GdkScreen*
+terminal_app_get_screen_by_display_name (const char *display_name,
+                                         int screen_number)
+{
+  GdkDisplay *display = NULL;
+  GdkScreen *screen = NULL;
+
+  /* --screen=screen_number overrides --display */
+
+  if (display_name == NULL)
+    display = gdk_display_get_default ();
+  else
+    {
+      GSList *displays, *l;
+      const char *period;
+
+      period = strrchr (display_name, '.');
+      if (period)
+        {
+          gulong n;
+          char *end;
+
+          errno = 0;
+          end = NULL;
+          n = g_ascii_strtoull (period + 1, &end, 0);
+          if (errno == 0 && (period + 1) != end)
+            screen_number = n;
+        }
+
+      displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
+      for (l = displays; l != NULL; l = l->next)
+        {
+          GdkDisplay *disp = l->data;
+
+          /* compare without the screen number part, if present */
+          if ((period && strncmp (gdk_display_get_name (disp), display_name, period - display_name) == 0) ||
+              (period == NULL && strcmp (gdk_display_get_name (disp), display_name) == 0))
+            {
+              display = disp;
+              break;
+            }
+        }
+      g_slist_free (displays);
+
+      if (display == NULL)
+        display = gdk_display_open (display_name); /* FIXME we never close displays */
+    }
+
+  if (display == NULL)
+    return NULL;
+  if (screen_number >= 0)
+    screen = gdk_display_get_screen (display, screen_number);
+  if (screen == NULL)
+    screen = gdk_display_get_default_screen (display);
+
+  return screen;
+}
+
 /* Menubar mnemonics settings handling */
 
 static int
@@ -1609,6 +1669,97 @@
   return global_app;
 }
 
+void
+terminal_app_handle_options (TerminalApp *app,
+                             TerminalOptions *options)
+{
+  GList *lw;
+  GdkScreen *screen;
+
+  screen = terminal_app_get_screen_by_display_name (options->display_name,
+                                                    options->screen_number);
+
+  for (lw = options->initial_windows;  lw != NULL; lw = lw->next)
+    {
+      InitialWindow *iw = lw->data;
+      TerminalWindow *window;
+      GList *lt;
+
+      g_assert (iw->tabs);
+
+      /* Create & setup new window */
+      window = terminal_app_new_window (app, screen);
+
+      if (options->startup_id)
+        terminal_window_set_startup_id (window, options->startup_id);
+
+      /* Overwrite the default, unique window role set in terminal_window_init */
+      if (iw->role)
+        gtk_window_set_role (GTK_WINDOW (window), iw->role);
+
+      if (iw->force_menubar_state)
+        terminal_window_set_menubar_visible (window, iw->menubar_state);
+
+      if (iw->start_fullscreen)
+        gtk_window_fullscreen (GTK_WINDOW (window));
+      if (iw->start_maximized)
+        gtk_window_maximize (GTK_WINDOW (window));
+
+      /* Now add the tabs */
+      for (lt = iw->tabs; lt != NULL; lt = lt->next)
+        {
+          InitialTab *it = lt->data;
+          TerminalProfile *profile = NULL;
+          TerminalScreen *screen;
+          const char *profile_name;
+          gboolean profile_is_id;
+
+          if (it->profile)
+            {
+              profile_name = it->profile;
+              profile_is_id = it->profile_is_id;
+            }
+          else
+            {
+              profile_name = options->default_profile;
+              profile_is_id = options->default_profile_is_id;
+            }
+
+          if (profile_name)
+            {
+              if (profile_is_id)
+                profile = terminal_app_get_profile_by_name (app, profile_name);
+              else
+                profile = terminal_app_get_profile_by_visible_name (app, profile_name);
+
+              if (profile == NULL)
+                g_printerr (_("No such profile \"%s\", using default profile\n"), it->profile);
+            }
+          if (profile == NULL)
+            profile = terminal_app_get_profile_for_new_term (app);
+          g_assert (profile);
+
+          screen = terminal_app_new_terminal (app, window, profile,
+                                              it->exec_argv ? it->exec_argv : options->exec_argv,
+                                              it->title ? it->title : options->default_title,
+                                              it->working_dir ? it->working_dir : options->default_working_dir,
+                                              options->env,
+                                              it->zoom_set ? it->zoom : options->zoom);
+
+          if (it->active)
+            terminal_window_switch_screen (window, screen);
+        }
+
+      if (iw->geometry)
+        {
+          if (!gtk_window_parse_geometry (GTK_WINDOW (window), iw->geometry))
+            g_printerr (_("Invalid geometry string \"%s\"\n"), iw->geometry);
+        }
+
+      gtk_window_present (GTK_WINDOW (window));
+    }
+}
+
 TerminalWindow *
 terminal_app_new_window (TerminalApp *app,
                          GdkScreen *screen)

Modified: trunk/src/terminal-app.h
==============================================================================
--- trunk/src/terminal-app.h	(original)
+++ trunk/src/terminal-app.h	Tue Oct  7 14:31:04 2008
@@ -24,6 +24,7 @@
 #include <gtk/gtk.h>
 
 #include "terminal-screen.h"
+#include "terminal-options.h"
 
 G_BEGIN_DECLS
 
@@ -59,6 +60,9 @@
 
 TerminalApp* terminal_app_get (void);
 
+void terminal_app_handle_options (TerminalApp *app,
+                                  TerminalOptions *options);
+
 void terminal_app_edit_profile (TerminalApp     *app,
                                 TerminalProfile *profile,
                                 GtkWindow       *transient_parent);

Modified: trunk/src/terminal-options.c
==============================================================================
--- trunk/src/terminal-options.c	(original)
+++ trunk/src/terminal-options.c	Tue Oct  7 14:31:04 2008
@@ -23,10 +23,12 @@
 
 #include <errno.h>
 #include <string.h>
+#include <stdlib.h>
 
 #include <glib.h>
 
 #include "terminal-options.h"
+#include "terminal-screen.h"
 #include "terminal-intl.h"
 
 static GOptionContext *get_goption_context (TerminalOptions *options);

Modified: trunk/src/terminal-options.h
==============================================================================
--- trunk/src/terminal-options.h	(original)
+++ trunk/src/terminal-options.h	Tue Oct  7 14:31:04 2008
@@ -19,24 +19,13 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#ifndef TERMINAL_OPTIONS_H
+#define TERMINAL_OPTIONS_H
+
 #include <glib.h>
 
 G_BEGIN_DECLS
 
-#include "terminal-intl.h"
-
-#include "terminal-app.h"
-#include "terminal-accels.h"
-#include "terminal-window.h"
-#include "terminal-util.h"
-#include "profile-editor.h"
-#include "encoding.h"
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <time.h>
-#include <gdk/gdkx.h>
-
 typedef struct
 {
   char   **env;
@@ -101,3 +90,5 @@
 void terminal_options_free (TerminalOptions *options);
 
 G_END_DECLS
+
+#endif /* !TERMINAL_OPTIONS_H */

Modified: trunk/src/terminal.c
==============================================================================
--- trunk/src/terminal.c	(original)
+++ trunk/src/terminal.c	Tue Oct  7 14:31:04 2008
@@ -124,157 +124,6 @@
 
 static TerminalFactory *factory = NULL;
 
-static GdkScreen*
-find_screen_by_display_name (const char *display_name,
-                             int         screen_number)
-{
-  GdkDisplay *display = NULL;
-  GdkScreen *screen;
-
-  /* --screen=screen_number overrides --display */
-
-  screen = NULL;
-
-  if (display_name == NULL)
-    display = gdk_display_get_default ();
-  else
-    {
-      GSList *displays, *l;
-      const char *period;
-
-      period = strrchr (display_name, '.');
-      if (period)
-        {
-          gulong n;
-          char *end;
-
-          errno = 0;
-          end = NULL;
-          n = g_ascii_strtoull (period + 1, &end, 0);
-          if (errno == 0 && (period + 1) != end)
-            screen_number = n;
-        }
-
-      displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
-      for (l = displays; l != NULL; l = l->next)
-        {
-          GdkDisplay *disp = l->data;
-
-          /* compare without the screen number part, if present */
-          if ((period && strncmp (gdk_display_get_name (disp), display_name, period - display_name) == 0) ||
-              (period == NULL && strcmp (gdk_display_get_name (disp), display_name) == 0))
-            {
-              display = disp;
-              break;
-            }
-        }
-      g_slist_free (displays);
-
-      if (display == NULL)
-        display = gdk_display_open (display_name); /* FIXME we never close displays */
-    }
-
-  if (display == NULL)
-    return NULL;
-  if (screen_number >= 0)
-    screen = gdk_display_get_screen (display, screen_number);
-  if (screen == NULL)
-    screen = gdk_display_get_default_screen (display);
-
-  return screen;
-}
-
-static void
-new_terminal_with_options (TerminalApp *app,
-                           TerminalOptions *results)
-{
-  GList *lw;
-  GdkScreen *screen;
-
-  screen = find_screen_by_display_name (results->display_name,
-                                        results->screen_number);
-
-  for (lw = results->initial_windows;  lw != NULL; lw = lw->next)
-    {
-      InitialWindow *iw = lw->data;
-      TerminalWindow *window;
-      GList *lt;
-
-      g_assert (iw->tabs);
-
-      /* Create & setup new window */
-      window = terminal_app_new_window (app, screen);
-
-      if (results->startup_id)
-        terminal_window_set_startup_id (window, results->startup_id);
-
-      /* Overwrite the default, unique window role set in terminal_window_init */
-      if (iw->role)
-        gtk_window_set_role (GTK_WINDOW (window), iw->role);
-
-      if (iw->force_menubar_state)
-        terminal_window_set_menubar_visible (window, iw->menubar_state);
-
-      if (iw->start_fullscreen)
-        gtk_window_fullscreen (GTK_WINDOW (window));
-      if (iw->start_maximized)
-        gtk_window_maximize (GTK_WINDOW (window));
-
-      /* Now add the tabs */
-      for (lt = iw->tabs; lt != NULL; lt = lt->next)
-        {
-          InitialTab *it = lt->data;
-          TerminalProfile *profile = NULL;
-          TerminalScreen *screen;
-          const char *profile_name;
-          gboolean profile_is_id;
-
-          if (it->profile)
-            {
-              profile_name = it->profile;
-              profile_is_id = it->profile_is_id;
-            }
-          else
-            {
-              profile_name = results->default_profile;
-              profile_is_id = results->default_profile_is_id;
-            }
-
-          if (profile_name)
-            {
-              if (profile_is_id)
-                profile = terminal_app_get_profile_by_name (app, profile_name);
-              else
-                profile = terminal_app_get_profile_by_visible_name (app, profile_name);
-
-              if (profile == NULL)
-                g_printerr (_("No such profile \"%s\", using default profile\n"), it->profile);
-            }
-          if (profile == NULL)
-            profile = terminal_app_get_profile_for_new_term (app);
-          g_assert (profile);
-
-          screen = terminal_app_new_terminal (app, window, profile,
-                                              it->exec_argv ? it->exec_argv : results->exec_argv,
-                                              it->title ? it->title : results->default_title,
-                                              it->working_dir ? it->working_dir : results->default_working_dir,
-                                              results->env,
-                                              it->zoom_set ? it->zoom : results->zoom);
-
-          if (it->active)
-            terminal_window_switch_screen (window, screen);
-        }
-
-      if (iw->geometry)
-        {
-          if (!gtk_window_parse_geometry (GTK_WINDOW (window), iw->geometry))
-            g_printerr (_("Invalid geometry string \"%s\"\n"), iw->geometry);
-        }
-
-      gtk_window_present (GTK_WINDOW (window));
-    }
-}
-
 /* Copied from libnautilus/nautilus-program-choosing.c; Needed in case
  * we have no DESKTOP_STARTUP_ID (with its accompanying timestamp).
  */
@@ -541,7 +390,7 @@
   terminal_app_initialize (options->use_factory);
   g_signal_connect (terminal_app_get (), "quit", G_CALLBACK (gtk_main_quit), NULL);
 
-  new_terminal_with_options (terminal_app_get (), options);
+  terminal_app_handle_options (terminal_app_get (), options);
   terminal_options_free (options);
 
   gtk_main ();
@@ -559,7 +408,7 @@
 static gboolean
 handle_new_terminal_event (TerminalOptions *options)
 {
-  new_terminal_with_options (terminal_app_get (), options);
+  terminal_app_handle_options (terminal_app_get (), options);
 
   return FALSE;
 }



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