]> git.street.me.uk Git - andy/viking.git/commitdiff
Move window code that is unnecessarily in main.c to vikwindow.c
authorRob Norris <rw_norris@hotmail.com>
Sat, 15 Sep 2012 08:30:00 +0000 (09:30 +0100)
committerRob Norris <rw_norris@hotmail.com>
Mon, 1 Oct 2012 00:05:18 +0000 (01:05 +0100)
Much better scoping of the window code. Minor rename of functions and update header appropriately.

src/main.c
src/vikwindow.c
src/vikwindow.h

index 2395216aa4ca262e842199983b0ef6c0b105fb0f..e22b43aa2b28f9c03c9d7d0a85f9fe80377e6b43 100644 (file)
@@ -50,8 +50,6 @@ void a_datasource_gc_init();
 
 #include "modules.h"
 
-#define MAX_WINDOWS 1024
-
 /* FIXME LOCALEDIR must be configured by ./configure --localedir */
 /* But something does not work actually. */
 /* So, we need to redefine this variable on windows. */
@@ -60,14 +58,6 @@ void a_datasource_gc_init();
 #define LOCALEDIR "locale"
 #endif
 
-static guint window_count = 0;
-
-static VikWindow *new_window ();
-static void open_window ( VikWindow *vw, GSList *files );
-static void statusbar_update ( VikWindow *vw, const gchar *message );
-static void destroy( GtkWidget *widget,
-                     gpointer   data );
-
 #if GLIB_CHECK_VERSION (2, 32, 0)
 /* Callback to log message */
 static void log_debug(const gchar *log_domain,
@@ -88,66 +78,6 @@ static void mute_log(const gchar *log_domain,
 }
 #endif
 
-/* Another callback */
-static void destroy( GtkWidget *widget,
-                     gpointer   data )
-{
-    if ( ! --window_count )
-      gtk_main_quit ();
-}
-
-// Only here because other signal handlers are!
-// TODO: why can't we just move all these into VikWindow and be done with it?!
-static void statusbar_update ( VikWindow *vw, const gchar *message )
-{
-  vik_window_statusbar_update ( vw, message );
-}
-
-static VikWindow *new_window ()
-{
-  if ( window_count < MAX_WINDOWS )
-  {
-    VikWindow *vw = vik_window_new ();
-
-    g_signal_connect (G_OBJECT (vw), "destroy",
-                     G_CALLBACK (destroy), NULL);
-    g_signal_connect (G_OBJECT (vw), "newwindow",
-                     G_CALLBACK (new_window), NULL);
-    g_signal_connect (G_OBJECT (vw), "openwindow",
-                     G_CALLBACK (open_window), NULL);
-    g_signal_connect (G_OBJECT (vw), "statusbarupdate",
-                     G_CALLBACK (statusbar_update), NULL);
-
-    gtk_widget_show_all ( GTK_WIDGET(vw) );
-
-    window_count++;
-
-    return vw;
-  }
-  return NULL;
-}
-
-static void open_window ( VikWindow *vw, GSList *files )
-{
-  gboolean change_fn = (g_slist_length(files) == 1); /* only change fn if one file */
-  GSList *cur_file = files;
-  while ( cur_file ) {
-    // Only open a new window if a viking file
-    gchar *file_name = cur_file->data;
-    if (vw != NULL && check_file_magic_vik ( file_name ) ) {
-      VikWindow *newvw = new_window();
-      if (newvw)
-       vik_window_open_file ( newvw, file_name, change_fn );
-    }
-    else {
-      vik_window_open_file ( vw, file_name, change_fn );
-    }
-    g_free (file_name);
-    cur_file = g_slist_next (cur_file);
-  }
-  g_slist_free (files);
-}
-
 /* Options */
 static GOptionEntry entries[] = 
 {
@@ -232,7 +162,7 @@ int main( int argc, char *argv[] )
   gtk_window_set_default_icon(main_icon);
 
   /* Create the first window */
-  first_window = new_window();
+  first_window = vik_window_new_window();
 
   gdk_threads_enter ();
   while ( ++i < argc ) {
index b23fab90025dfafeccfc6f8b6176e07765837c96..2d2bbf361e38b270ff55bb41546f3b278ca62d88 100644 (file)
 #include <gio/gio.h>
 #include <gdk/gdkkeysyms.h>
 
+// This seems rather arbitary, quite large and pointless
+//  I mean, if you have a thousand windows open;
+//   why not be allowed to open a thousand more...
+#define MAX_WINDOWS 1024
+static guint window_count = 0;
+
 #define VIKING_WINDOW_WIDTH      1000
 #define VIKING_WINDOW_HEIGHT     800
 #define DRAW_IMAGE_DEFAULT_WIDTH 1280
@@ -68,10 +74,18 @@ static void window_init ( VikWindow *vw );
 static void window_class_init ( VikWindowClass *klass );
 static void window_set_filename ( VikWindow *vw, const gchar *filename );
 
+static VikWindow *window_new ();
+
 static void draw_update ( VikWindow *vw );
 
 static void newwindow_cb ( GtkAction *a, VikWindow *vw );
 
+// Signals
+static void open_window ( VikWindow *vw, GSList *files );
+static void statusbar_update ( VikWindow *vw, const gchar *message );
+static void destroy_window ( GtkWidget *widget,
+                             gpointer   data );
+
 /* Drawing & stuff */
 
 static gboolean delete_event( VikWindow *vw );
@@ -279,6 +293,65 @@ void vik_window_statusbar_update ( VikWindow *vw, const gchar* message )
   g_idle_add ( (GSourceFunc) statusbar_idle_update, data );
 }
 
+// Actual signal handlers
+static void destroy_window ( GtkWidget *widget,
+                             gpointer   data )
+{
+    if ( ! --window_count )
+      gtk_main_quit ();
+}
+
+static void statusbar_update ( VikWindow *vw, const gchar *message )
+{
+  vik_window_statusbar_update ( vw, message );
+}
+
+VikWindow *vik_window_new_window ()
+{
+  if ( window_count < MAX_WINDOWS )
+  {
+    VikWindow *vw = window_new ();
+
+    g_signal_connect (G_OBJECT (vw), "destroy",
+                     G_CALLBACK (destroy_window), NULL);
+    g_signal_connect (G_OBJECT (vw), "newwindow",
+                     G_CALLBACK (vik_window_new_window), NULL);
+    g_signal_connect (G_OBJECT (vw), "openwindow",
+                     G_CALLBACK (open_window), NULL);
+    g_signal_connect (G_OBJECT (vw), "statusbarupdate",
+                     G_CALLBACK (statusbar_update), NULL);
+
+    gtk_widget_show_all ( GTK_WIDGET(vw) );
+
+    window_count++;
+
+    return vw;
+  }
+  return NULL;
+}
+
+static void open_window ( VikWindow *vw, GSList *files )
+{
+  gboolean change_fn = (g_slist_length(files) == 1); /* only change fn if one file */
+  GSList *cur_file = files;
+  while ( cur_file ) {
+    // Only open a new window if a viking file
+    gchar *file_name = cur_file->data;
+    if (vw != NULL && check_file_magic_vik ( file_name ) ) {
+      VikWindow *newvw = vik_window_new_window ();
+      if (newvw)
+       vik_window_open_file ( newvw, file_name, change_fn );
+    }
+    else {
+      vik_window_open_file ( vw, file_name, change_fn );
+    }
+    g_free (file_name);
+    cur_file = g_slist_next (cur_file);
+  }
+  g_slist_free (files);
+}
+// End signals
+
 void vik_window_selected_layer(VikWindow *vw, VikLayer *vl)
 {
   int i, j, tool_count;
@@ -401,7 +474,7 @@ static void window_init ( VikWindow *vw )
   vw->save_img_dir_dia = NULL;
 }
 
-VikWindow *vik_window_new ()
+static VikWindow *window_new ()
 {
   return VIK_WINDOW ( g_object_new ( VIK_WINDOW_TYPE, NULL ) );
 }
index 44055f29169c74335298d184b5e85bd9a739bf5a..751ac987c9854ee3f02e30d1969cad4d8be3dc02 100644 (file)
@@ -51,7 +51,9 @@ struct _VikWindowClass
 
 GType vik_window_get_type ();
 
-VikWindow *vik_window_new ();
+// To call from main to start things off:
+VikWindow *vik_window_new_window ();
+
 GtkWidget *vik_window_get_drawmode_button ( VikWindow *vw, VikViewportDrawMode mode );
 gboolean vik_window_get_pan_move ( VikWindow *vw );
 void vik_window_open_file ( VikWindow *vw, const gchar *filename, gboolean changefilename );
@@ -62,8 +64,6 @@ struct _VikLayersPanel * vik_window_layers_panel(VikWindow *vw);
 struct _VikStatusbar * vik_window_get_statusbar(VikWindow *vw);
 // Only for use from background.c:
 void vik_window_signal_statusbar_update (VikWindow *vw, const gchar* message );
-// This one only from main.c:
-void vik_window_statusbar_update (VikWindow *vw, const gchar* message );
 
 void vik_window_set_redraw_trigger(struct _VikLayer *vl);