Geocode image by drag-drop
[geeqie.git] / src / misc.c
index 47bbdc3..0f74402 100644 (file)
@@ -1,20 +1,30 @@
 /*
- * Geeqie
- * Copyright (C) 2008 The Geeqie Team
+ * Copyright (C) 2008 - 2016 The Geeqie Team
  *
- * Authors: Vladimir Nadvornik / Laurent Monin
+ * Authors: Vladimir Nadvornik, Laurent Monin
  *
- * This software is released under the GNU General Public License (GNU GPL).
- * Please read the included file COPYING for more information.
- * This software comes with no warranty of any kind, use at your own risk!
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #include "main.h"
 #include "misc.h"
+#include "ui_fileops.h"
 
 gdouble get_zoom_increment(void)
 {
-       return ((options->image.zoom_increment != 0) ? (gdouble)options->image.zoom_increment / 10.0 : 1.0);
+       return ((options->image.zoom_increment != 0) ? (gdouble)options->image.zoom_increment / 100.0 : 1.0);
 }
 
 gchar *utf8_validate_or_convert(const gchar *text)
@@ -22,7 +32,7 @@ gchar *utf8_validate_or_convert(const gchar *text)
        gint len;
 
        if (!text) return NULL;
-       
+
        len = strlen(text);
        if (!g_utf8_validate(text, len, NULL))
                return g_convert(text, len, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
@@ -44,6 +54,11 @@ gint utf8_compare(const gchar *s1, const gchar *s2, gboolean case_sensitive)
                s1_t = g_utf8_casefold(s1, -1);
                s2_t = g_utf8_casefold(s2, -1);
                }
+       else
+               {
+               s1_t = (gchar *) s1;
+               s2_t = (gchar *) s2;
+               }
 
        s1_key = g_utf8_collate_key(s1_t, -1);
        s2_key = g_utf8_collate_key(s2_t, -1);
@@ -108,3 +123,98 @@ gchar *expand_tilde(const gchar *filename)
                return g_build_filename(home, G_DIR_SEPARATOR_S, NULL);
 #endif
 }
+
+/* Search for latitude/longitude parameters in a string
+ */
+
+#define GEOCODE_NAME "geocode-parameters.awk"
+#define BUFSIZE 128
+
+gchar *decode_geo_parameters(const gchar *input_text)
+{
+       gchar *message;
+       gchar *path = g_build_filename(get_rc_dir(), GEOCODE_NAME, NULL);
+       gchar *cmd = g_strconcat("echo \'", input_text, "\'  | awk -f ", path, NULL);
+
+       if (g_file_test(path, G_FILE_TEST_EXISTS))
+               {
+               gchar buf[BUFSIZE];
+               FILE *fp;
+
+               if ((fp = popen(cmd, "r")) == NULL)
+                       {
+                       message = g_strconcat("Error: opening pipe\n", input_text, NULL);
+                       }
+               else
+                       {
+                       fgets(buf, BUFSIZE, fp);
+                       message = g_strconcat(buf, NULL);
+
+                       if(pclose(fp))
+                               {
+                               message = g_strconcat("Error: Command not found or exited with error status\n", input_text, NULL);
+                               }
+                       }
+               }
+       else
+               {
+               message = g_strconcat(input_text, NULL);
+               }
+
+       g_free(path);
+       g_free(cmd);
+       return message;
+}
+
+/* Run a command like system() but may output debug messages. */
+int runcmd(gchar *cmd)
+{
+#if 1
+       return system(cmd);
+       return 0;
+#else
+       /* For debugging purposes */
+       int retval = -1;
+       FILE *in;
+
+       DEBUG_1("Running command: %s", cmd);
+
+       in = popen(cmd, "r");
+       if (in)
+               {
+               int status;
+               const gchar *msg;
+               gchar buf[2048];
+
+               while (fgets(buf, sizeof(buf), in) != NULL )
+                       {
+                       DEBUG_1("Output: %s", buf);
+                       }
+
+               status = pclose(in);
+
+               if (WIFEXITED(status))
+                       {
+                       msg = "Command terminated with exit code";
+                       retval = WEXITSTATUS(status);
+                       }
+               else if (WIFSIGNALED(status))
+                       {
+                       msg = "Command was killed by signal";
+                       retval = WTERMSIG(status);
+                       }
+               else
+                       {
+                       msg = "pclose() returned";
+                       retval = status;
+                       }
+
+               DEBUG_1("%s : %d\n", msg, retval);
+       }
+
+       return retval;
+#endif
+}
+
+
+/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */