+/**
+ * Returns the statusbar for the window
+ */
+VikStatusbar * vik_window_get_statusbar ( VikWindow *vw )
+{
+ return vw->viking_vs;
+}
+
+/**
+ * For signalling the update from a background thread
+ */
+void vik_window_signal_statusbar_update (VikWindow *vw, const gchar* message, vik_statusbar_type_t vs_type)
+{
+ g_signal_emit ( G_OBJECT(vw), window_signals[VW_STATUSBAR_UPDATE_SIGNAL], 0, message, vs_type );
+}
+
+/**
+ * For the actual statusbar update!
+ */
+static gboolean statusbar_idle_update ( gpointer indata )
+{
+ gpointer *data = indata;
+ vik_statusbar_set_message ( data[0], GPOINTER_TO_INT(data[2]), data[1] );
+ return FALSE;
+}
+
+/**
+ * Update statusbar in the main thread
+ */
+static void window_statusbar_update ( VikWindow *vw, const gchar* message, vik_statusbar_type_t vs_type )
+{
+ // ATM we know the message has been statically allocated so this is OK (no need to handle any freeing)
+ static gpointer data[3];
+ data[0] = vw->viking_vs;
+ data[1] = (gchar*) message;
+ data[2] = GINT_TO_POINTER(vs_type);
+ 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_statusbar_type_t vs_type )
+{
+ window_statusbar_update ( vw, message, vs_type );
+}
+
+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), vw);
+
+ 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
+