]> git.street.me.uk Git - andy/viking.git/blobdiff - src/vikgeoreflayer.c
Add Terraserver
[andy/viking.git] / src / vikgeoreflayer.c
index 7d09ae82657c700de8268429133d17ab651eb105..5a95f31492baee1c4139e8f0912e32c65b949424 100644 (file)
  *
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include "viking.h"
-#include "vikgeoreflayer_pixmap.h"
-#include <stdlib.h>
+#include <glib.h>
+#include <glib/gstdio.h>
+#include <glib/gi18n.h>
 #include <string.h>
 
+#include "icons/icons.h"
+
 VikLayerParam georef_layer_params[] = {
   { "image", VIK_LAYER_PARAM_STRING, VIK_LAYER_NOT_IN_PROPERTIES },
   { "corner_easting", VIK_LAYER_PARAM_DOUBLE, VIK_LAYER_NOT_IN_PROPERTIES },
@@ -36,7 +43,6 @@ enum { PARAM_IMAGE = 0, PARAM_CE, PARAM_CN, PARAM_ME, PARAM_MN, NUM_PARAMS };
 
 static void georef_layer_marshall( VikGeorefLayer *vgl, guint8 **data, gint *len );
 static VikGeorefLayer *georef_layer_unmarshall( guint8 *data, gint len, VikViewport *vvp );
-static VikGeorefLayer *georef_layer_copy ( VikGeorefLayer *vgl, gpointer vp );
 static gboolean georef_layer_set_param ( VikGeorefLayer *vgl, guint16 id, VikLayerParamData data, VikViewport *vp );
 static VikLayerParamData georef_layer_get_param ( VikGeorefLayer *vgl, guint16 id );
 VikGeorefLayer *georef_layer_new ( );
@@ -57,16 +63,18 @@ static gpointer georef_layer_zoom_create ( VikWindow *vw, VikViewport *vvp);
 static gboolean georef_layer_zoom_press ( VikGeorefLayer *vgl, GdkEventButton *event, VikViewport *vvp );
 
 static VikToolInterface georef_tools[] = {
-  { "Georef Move Map", (VikToolConstructorFunc) georef_layer_move_create, NULL, NULL, NULL,
-    (VikToolMouseFunc) georef_layer_move_press, NULL, (VikToolMouseFunc) georef_layer_move_release },
+  { N_("Georef Move Map"), (VikToolConstructorFunc) georef_layer_move_create, NULL, NULL, NULL,
+    (VikToolMouseFunc) georef_layer_move_press, NULL, (VikToolMouseFunc) georef_layer_move_release,
+    (VikToolKeyFunc) NULL, GDK_CURSOR_IS_PIXMAP, &cursor_geomove_pixbuf },
 
-  { "Georef Zoom Tool", (VikToolConstructorFunc) georef_layer_zoom_create, NULL, NULL, NULL,
-    (VikToolMouseFunc) georef_layer_zoom_press, NULL, NULL },
+  { N_("Georef Zoom Tool"), (VikToolConstructorFunc) georef_layer_zoom_create, NULL, NULL, NULL,
+    (VikToolMouseFunc) georef_layer_zoom_press, NULL, NULL,
+    (VikToolKeyFunc) NULL, GDK_CURSOR_IS_PIXMAP, &cursor_geozoom_pixbuf },
 };
 
 VikLayerInterface vik_georef_layer_interface = {
   "GeoRef Map",
-  &georeflayer_pixbuf, /*icon */
+  &vikgeoreflayer_pixbuf, /*icon */
 
   georef_tools,
   sizeof(georef_tools) / sizeof(VikToolInterface),
@@ -96,7 +104,6 @@ VikLayerInterface vik_georef_layer_interface = {
   (VikLayerFuncSublayerRenameRequest)   NULL,
   (VikLayerFuncSublayerToggleVisible)   NULL,
 
-  (VikLayerFuncCopy)                    georef_layer_copy,
   (VikLayerFuncMarshall)               georef_layer_marshall,
   (VikLayerFuncUnmarshall)             georef_layer_unmarshall,
 
@@ -150,23 +157,6 @@ GType vik_georef_layer_get_type ()
   return vgl_type;
 }
 
-static VikGeorefLayer *georef_layer_copy ( VikGeorefLayer *vgl, gpointer vp )
-{
-  VikGeorefLayer *rv = georef_layer_new ();
-  rv->corner = vgl->corner;
-  rv->mpp_easting = vgl->mpp_easting;
-  rv->mpp_northing = vgl->mpp_northing;
-  rv->width = vgl->width;
-  rv->height = vgl->height;
-
-  if ( vgl->image )
-  {
-    rv->image = g_strdup ( vgl->image );
-    georef_layer_load_image ( rv );
-  }
-  return rv;
-}
-
 static void georef_layer_marshall( VikGeorefLayer *vgl, guint8 **data, gint *len )
 {
   vik_layer_marshall_params ( VIK_LAYER(vgl), data, len );
@@ -275,7 +265,7 @@ static void georef_layer_load_image ( VikGeorefLayer *vgl )
 
   if (gx)
   {
-    g_warning ( "Couldn't open image file: %s", gx->message );
+    g_warning ( _("Couldn't open image file: %s"), gx->message );
     g_error_free ( gx );
   }
   else
@@ -300,14 +290,15 @@ static gboolean world_file_read_line ( gchar *buffer, gint size, FILE *f, GtkWid
 {
   if (!fgets ( buffer, 1024, f ))
   {
-    a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_WIDGET(widget), "Unexpected end of file reading World file." );
+    a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_WIDGET(widget), _("Unexpected end of file reading World file.") );
     g_free ( buffer );
     fclose ( f );
+    f = NULL;
     return FALSE;
   }
   if ( use_value )
   {
-    gdouble val = strtod ( buffer, NULL );
+    gdouble val = g_strtod ( buffer, NULL );
     gtk_spin_button_set_value ( GTK_SPIN_BUTTON(widget), val > 0 ? val : -val );
   }
   return TRUE;
@@ -315,15 +306,20 @@ static gboolean world_file_read_line ( gchar *buffer, gint size, FILE *f, GtkWid
 
 static void georef_layer_dialog_load ( GtkWidget *pass_along[4] )
 {
-  GtkWidget *file_selector = gtk_file_selection_new ("Choose World file");
-
-  if ( gtk_dialog_run ( GTK_DIALOG ( file_selector ) ) == GTK_RESPONSE_OK )
+  GtkWidget *file_selector = gtk_file_chooser_dialog_new (_("Choose World file"),
+                                     NULL,
+                                     GTK_FILE_CHOOSER_ACTION_OPEN,
+                                     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                     GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+                                     NULL);
+
+  if ( gtk_dialog_run ( GTK_DIALOG ( file_selector ) ) == GTK_RESPONSE_ACCEPT )
   {
-    FILE *f = fopen ( gtk_file_selection_get_filename ( GTK_FILE_SELECTION(file_selector) ), "r" );
+    FILE *f = g_fopen ( gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER(file_selector) ), "r" );
     gtk_widget_destroy ( file_selector ); 
     if ( !f )
     {
-      a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_WIDGET(pass_along[0]), "The World file you requested could not be opened for reading." );
+      a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_WIDGET(pass_along[0]), _("The World file you requested could not be opened for reading.") );
       return;
     }
     else
@@ -335,6 +331,7 @@ static void georef_layer_dialog_load ( GtkWidget *pass_along[4] )
       {
         g_free ( buffer );
         fclose ( f );
+       f = NULL;
       }
     }
   }
@@ -354,21 +351,27 @@ We need a
 static void georef_layer_export_params ( gpointer *pass_along[2] )
 {
   VikGeorefLayer *vgl = VIK_GEOREF_LAYER(pass_along[0]);
-  GtkWidget *file_selector = gtk_file_selection_new ("Choose World file");
-
-  if ( gtk_dialog_run ( GTK_DIALOG ( file_selector ) ) == GTK_RESPONSE_OK )
+  GtkWidget *file_selector = gtk_file_chooser_dialog_new (_("Choose World file"),
+                                     NULL,
+                                     GTK_FILE_CHOOSER_ACTION_SAVE,
+                                     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                     GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+                                     NULL);
+  if ( gtk_dialog_run ( GTK_DIALOG ( file_selector ) ) == GTK_RESPONSE_ACCEPT )
   {
-    FILE *f = fopen ( gtk_file_selection_get_filename ( GTK_FILE_SELECTION(file_selector) ), "w" );
+    FILE *f = g_fopen ( gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER(file_selector) ), "w" );
+    
     gtk_widget_destroy ( file_selector ); 
     if ( !f )
     {
-      a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_WIDGET(pass_along[0]), "The file you requested could not be opened for writing." );
+      a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_WIDGET(pass_along[0]), _("The file you requested could not be opened for writing.") );
       return;
     }
     else
     {
       fprintf ( f, "%f\n%f\n%f\n%f\n%f\n%f\n", vgl->mpp_easting, vgl->mpp_northing, 0.0, 0.0, vgl->corner.easting, vgl->corner.northing );
       fclose ( f );
+      f = NULL;
     }
   }
   else
@@ -378,14 +381,14 @@ static void georef_layer_export_params ( gpointer *pass_along[2] )
 /* returns TRUE if OK was pressed. */
 static gboolean georef_layer_dialog ( VikGeorefLayer **vgl, gpointer vp, GtkWindow *w )
 {
-  GtkWidget *dialog = gtk_dialog_new_with_buttons ("Layer Properties",
+  GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Layer Properties"),
                                                   w,
                                                   GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
                                                   GTK_STOCK_CANCEL,
                                                   GTK_RESPONSE_REJECT,
                                                   GTK_STOCK_OK,
                                                   GTK_RESPONSE_ACCEPT,
-                                                  0 );
+                                                  NULL );
   GtkWidget *table, *wfp_hbox, *wfp_label, *wfp_button, *ce_label, *ce_spin, *cn_label, *cn_spin, *xlabel, *xspin, *ylabel, *yspin, *imagelabel, *imageentry;
 
   GtkWidget *pass_along[4];
@@ -394,25 +397,25 @@ static gboolean georef_layer_dialog ( VikGeorefLayer **vgl, gpointer vp, GtkWind
   gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), table, TRUE, TRUE, 0 );
 
   wfp_hbox = gtk_hbox_new ( FALSE, 0 );
-  wfp_label = gtk_label_new ( "World File Parameters:" );
-  wfp_button = gtk_button_new_with_label ( "Load From File..." );
+  wfp_label = gtk_label_new ( _("World File Parameters:") );
+  wfp_button = gtk_button_new_with_label ( _("Load From File...") );
 
   gtk_box_pack_start ( GTK_BOX(wfp_hbox), wfp_label, TRUE, TRUE, 0 );
   gtk_box_pack_start ( GTK_BOX(wfp_hbox), wfp_button, FALSE, FALSE, 3 );
 
-  ce_label = gtk_label_new ( "Corner pixel easting:" );
+  ce_label = gtk_label_new ( _("Corner pixel easting:") );
   ce_spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( 4, 0.0, 1500000.0, 1, 5, 5 ), 1, 4 );
 
-  cn_label = gtk_label_new ( "Corner pixel northing:" );
+  cn_label = gtk_label_new ( _("Corner pixel northing:") );
   cn_spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( 4, 0.0, 9000000.0, 1, 5, 5 ), 1, 4 );
 
-  xlabel = gtk_label_new ( "X (easting) scale (mpp): ");
-  ylabel = gtk_label_new ( "Y (northing) scale (mpp): ");
+  xlabel = gtk_label_new ( _("X (easting) scale (mpp): "));
+  ylabel = gtk_label_new ( _("Y (northing) scale (mpp): "));
 
   xspin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( 4, VIK_VIEWPORT_MIN_ZOOM, VIK_VIEWPORT_MAX_ZOOM, 1, 5, 5 ), 1, 8 );
   yspin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( 4, VIK_VIEWPORT_MIN_ZOOM, VIK_VIEWPORT_MAX_ZOOM, 1, 5, 5 ), 1, 8 );
 
-  imagelabel = gtk_label_new ( "Map Image:" );
+  imagelabel = gtk_label_new ( _("Map Image:") );
   imageentry = vik_file_entry_new ();
 
   if (*vgl)
@@ -516,17 +519,17 @@ static void georef_layer_add_menu_items ( VikGeorefLayer *vgl, GtkMenu *menu, gp
   gtk_menu_shell_append ( GTK_MENU_SHELL(menu), item );
   gtk_widget_show ( item );
 
-  item = gtk_menu_item_new_with_label ( "Zoom to Fit Map" );
+  item = gtk_menu_item_new_with_label ( _("Zoom to Fit Map") );
   g_signal_connect_swapped ( G_OBJECT(item), "activate", G_CALLBACK(georef_layer_zoom_to_fit), pass_along );
   gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
   gtk_widget_show ( item );
 
-  item = gtk_menu_item_new_with_label ( "Goto Map Center" );
+  item = gtk_menu_item_new_with_label ( _("Goto Map Center") );
   g_signal_connect_swapped ( G_OBJECT(item), "activate", G_CALLBACK(georef_layer_goto_center), pass_along );
   gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
   gtk_widget_show ( item );
 
-  item = gtk_menu_item_new_with_label ( "Export to World File" );
+  item = gtk_menu_item_new_with_label ( _("Export to World File") );
   g_signal_connect_swapped ( G_OBJECT(item), "activate", G_CALLBACK(georef_layer_export_params), pass_along );
   gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
   gtk_widget_show ( item );