changeset 1022:9962b24b6b43

Move miscellaneous functions to their own files (new misc.[ch]).
author zas_
date Sun, 31 Aug 2008 10:51:41 +0000
parents 988995f6b1cf
children 650c02c0c8ff
files src/Makefile.am src/bar_exif.c src/bar_info.c src/collect.c src/dupe.c src/editors.c src/img-view.c src/layout_image.c src/layout_util.c src/lirc.c src/logwindow.c src/main.c src/main.h src/misc.c src/misc.h src/pan-view.c src/remote.c src/search.c src/ui_tabcomp.c
diffstat 19 files changed, 164 insertions(+), 128 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile.am	Sun Aug 31 10:08:48 2008 +0000
+++ b/src/Makefile.am	Sun Aug 31 10:51:41 2008 +0000
@@ -168,6 +168,8 @@
 	md5-util.h	\
 	menu.c		\
 	menu.h		\
+	misc.c		\
+	misc.h		\
 	options.c	\
 	options.h	\
 	pan-calendar.c	\
--- a/src/bar_exif.c	Sun Aug 31 10:08:48 2008 +0000
+++ b/src/bar_exif.c	Sun Aug 31 10:51:41 2008 +0000
@@ -15,9 +15,10 @@
 #include "bar_exif.h"
 
 #include "exif.h"
+#include "filedata.h"
 #include "history_list.h"
+#include "misc.h"
 #include "ui_misc.h"
-#include "filedata.h"
 
 #include <math.h>
 
--- a/src/bar_info.c	Sun Aug 31 10:08:48 2008 +0000
+++ b/src/bar_info.c	Sun Aug 31 10:51:41 2008 +0000
@@ -12,20 +12,19 @@
 
 
 #include "main.h"
-#include "exif.h"
-
 #include "bar_info.h"
 
 #include "cache.h"
+#include "exif.h"
 #include "filedata.h"
 #include "history_list.h"
 #include "info.h"
+#include "misc.h"
 #include "secure_save.h"
-#include "utilops.h"
 #include "ui_fileops.h"
 #include "ui_misc.h"
 #include "ui_utildlg.h"
-
+#include "utilops.h"
 
 #define BAR_KEYWORD_AUTOSAVE_TIME 10000
 
--- a/src/collect.c	Sun Aug 31 10:08:48 2008 +0000
+++ b/src/collect.c	Sun Aug 31 10:51:41 2008 +0000
@@ -23,11 +23,12 @@
 #include "info.h"
 #include "layout.h"
 #include "layout_image.h"
+#include "misc.h"
 #include "pixbuf_util.h"
 #include "print.h"
-#include "utilops.h"
 #include "ui_fileops.h"
 #include "ui_tree_edit.h"
+#include "utilops.h"
 #include "window.h"
 
 #include <gdk/gdkkeysyms.h> /* for keyboard values */
--- a/src/dupe.c	Sun Aug 31 10:08:48 2008 +0000
+++ b/src/dupe.c	Sun Aug 31 10:51:41 2008 +0000
@@ -27,14 +27,15 @@
 #include "layout_image.h"
 #include "md5-util.h"
 #include "menu.h"
+#include "misc.h"
 #include "print.h"
 #include "thumb.h"
-#include "utilops.h"
 #include "ui_fileops.h"
 #include "ui_menu.h"
 #include "ui_misc.h"
 #include "ui_tree_edit.h"
 #include "uri_utils.h"
+#include "utilops.h"
 #include "window.h"
 
 #include <gdk/gdkkeysyms.h> /* for keyboard values */
--- a/src/editors.c	Sun Aug 31 10:08:48 2008 +0000
+++ b/src/editors.c	Sun Aug 31 10:51:41 2008 +0000
@@ -16,10 +16,11 @@
 
 #include "filedata.h"
 #include "filefilter.h"
-#include "utilops.h"
+#include "misc.h"
 #include "ui_fileops.h"
 #include "ui_spinner.h"
 #include "ui_utildlg.h"
+#include "utilops.h"
 
 #include <errno.h>
 
--- a/src/img-view.c	Sun Aug 31 10:08:48 2008 +0000
+++ b/src/img-view.c	Sun Aug 31 10:51:41 2008 +0000
@@ -26,14 +26,15 @@
 #include "layout.h"
 #include "layout_image.h"
 #include "menu.h"
+#include "misc.h"
+#include "pixbuf_util.h"
 #include "pixbuf-renderer.h"
-#include "pixbuf_util.h"
 #include "print.h"
 #include "slideshow.h"
-#include "utilops.h"
 #include "ui_fileops.h"
 #include "ui_menu.h"
 #include "uri_utils.h"
+#include "utilops.h"
 #include "window.h"
 
 #include <gdk/gdkkeysyms.h> /* for keyboard values */
--- a/src/layout_image.c	Sun Aug 31 10:08:48 2008 +0000
+++ b/src/layout_image.c	Sun Aug 31 10:51:41 2008 +0000
@@ -25,12 +25,13 @@
 #include "layout.h"
 #include "layout_util.h"
 #include "menu.h"
+#include "misc.h"
 #include "pixbuf_util.h"
-#include "utilops.h"
 #include "slideshow.h"
 #include "ui_fileops.h"
 #include "ui_menu.h"
 #include "uri_utils.h"
+#include "utilops.h"
 
 #include <gdk/gdkkeysyms.h> /* for keyboard values */
 
--- a/src/layout_util.c	Sun Aug 31 10:08:48 2008 +0000
+++ b/src/layout_util.c	Sun Aug 31 10:51:41 2008 +0000
@@ -14,8 +14,8 @@
 #include "main.h"
 #include "layout_util.h"
 
+#include "bar_exif.h"
 #include "bar_info.h"
-#include "bar_exif.h"
 #include "bar_sort.h"
 #include "cache_maint.h"
 #include "collect.h"
@@ -30,16 +30,17 @@
 #include "info.h"
 #include "layout_image.h"
 #include "logwindow.h"
+#include "misc.h"
 #include "pan-view.h"
 #include "pixbuf_util.h"
 #include "preferences.h"
 #include "print.h"
 #include "search.h"
-#include "utilops.h"
 #include "ui_fileops.h"
 #include "ui_menu.h"
 #include "ui_misc.h"
 #include "ui_tabcomp.h"
+#include "utilops.h"
 #include "view_dir.h"
 #include "window.h"
 
--- a/src/lirc.c	Sun Aug 31 10:08:48 2008 +0000
+++ b/src/lirc.c	Sun Aug 31 10:51:41 2008 +0000
@@ -1,5 +1,7 @@
 #include "lirc.h"
 
+#include "misc.h"
+
 #ifdef HAVE_LIRC
 #include <lirc/lirc_client.h>
 #include "layout_image.h"
--- a/src/logwindow.c	Sun Aug 31 10:08:48 2008 +0000
+++ b/src/logwindow.c	Sun Aug 31 10:51:41 2008 +0000
@@ -13,6 +13,7 @@
 #include "main.h"
 #include "logwindow.h"
 
+#include "misc.h"
 #include "window.h"
 
 #include <gdk/gdkkeysyms.h>
--- a/src/main.c	Sun Aug 31 10:08:48 2008 +0000
+++ b/src/main.c	Sun Aug 31 10:51:41 2008 +0000
@@ -44,111 +44,6 @@
 
 /*
  *-----------------------------------------------------------------------------
- * misc (public)
- *-----------------------------------------------------------------------------
- */
-
-
-gdouble get_zoom_increment(void)
-{
-	return ((options->image.zoom_increment != 0) ? (gdouble)options->image.zoom_increment / 10.0 : 1.0);
-}
-
-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);
-
-	return g_strdup(text);
-}
-
-gint utf8_compare(const gchar *s1, const gchar *s2, gboolean case_sensitive)
-{
-	gchar *s1_key, *s2_key;
-	gchar *s1_t, *s2_t;
-	gint ret;
-
-	g_assert(g_utf8_validate(s1, -1, NULL));
-	g_assert(g_utf8_validate(s2, -1, NULL));
-
-	if (!case_sensitive)
-		{
-		s1_t = g_utf8_casefold(s1, -1);
-		s2_t = g_utf8_casefold(s2, -1);
-		}
-
-	s1_key = g_utf8_collate_key(s1_t, -1);
-	s2_key = g_utf8_collate_key(s2_t, -1);
-
-	ret = strcmp(s1_key, s2_key);
-
-	g_free(s1_key);
-	g_free(s2_key);
-
-	if (!case_sensitive)
-		{
-		g_free(s1_t);
-		g_free(s2_t);
-		}
-
-	return ret;
-}
-
-/* Borrowed from gtkfilesystemunix.c */
-gchar *expand_tilde(const gchar *filename)
-{
-#ifndef G_OS_UNIX
-	return g_strdup(filename);
-#else
-	const gchar *notilde;
-	const gchar *slash;
-	const gchar *home;
-
-	if (filename[0] != '~')
-		return g_strdup(filename);
-
-	notilde = filename + 1;
-	slash = strchr(notilde, G_DIR_SEPARATOR);
-	if (slash == notilde || !*notilde)
-		{
-		home = g_get_home_dir();
-		if (!home)
-			return g_strdup(filename);
-		}
-	else
-		{
-		gchar *username;
-		struct passwd *passwd;
-
-		if (slash)
-			username = g_strndup(notilde, slash - notilde);
-		else
-			username = g_strdup(notilde);
-
-		passwd = getpwnam(username);
-		g_free(username);
-
-		if (!passwd)
-			return g_strdup(filename);
-
-		home = passwd->pw_dir;
-		}
-
-	if (slash)
-		return g_build_filename(home, G_DIR_SEPARATOR_S, slash + 1, NULL);
-	else
-		return g_build_filename(home, G_DIR_SEPARATOR_S, NULL);
-#endif
-}
-
-
-/*
- *-----------------------------------------------------------------------------
  * keyboard functions
  *-----------------------------------------------------------------------------
  */
--- a/src/main.h	Sun Aug 31 10:08:48 2008 +0000
+++ b/src/main.h	Sun Aug 31 10:51:41 2008 +0000
@@ -130,11 +130,6 @@
  * This also doubles as the main.c header.
  */
 
-gdouble get_zoom_increment(void);
-gchar *utf8_validate_or_convert(const gchar *text);
-gint utf8_compare(const gchar *s1, const gchar *s2, gboolean case_sensitive);
-gchar *expand_tilde(const gchar *filename);
-
 void keyboard_scroll_calc(gint *x, gint *y, GdkEventKey *event);
 gint key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data);
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/misc.c	Sun Aug 31 10:51:41 2008 +0000
@@ -0,0 +1,110 @@
+/*
+ * Geeqie
+ * Copyright (C) 2008 The Geeqie Team
+ *
+ * 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!
+ */
+
+#include "main.h"
+#include "misc.h"
+
+gdouble get_zoom_increment(void)
+{
+	return ((options->image.zoom_increment != 0) ? (gdouble)options->image.zoom_increment / 10.0 : 1.0);
+}
+
+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);
+
+	return g_strdup(text);
+}
+
+gint utf8_compare(const gchar *s1, const gchar *s2, gboolean case_sensitive)
+{
+	gchar *s1_key, *s2_key;
+	gchar *s1_t, *s2_t;
+	gint ret;
+
+	g_assert(g_utf8_validate(s1, -1, NULL));
+	g_assert(g_utf8_validate(s2, -1, NULL));
+
+	if (!case_sensitive)
+		{
+		s1_t = g_utf8_casefold(s1, -1);
+		s2_t = g_utf8_casefold(s2, -1);
+		}
+
+	s1_key = g_utf8_collate_key(s1_t, -1);
+	s2_key = g_utf8_collate_key(s2_t, -1);
+
+	ret = strcmp(s1_key, s2_key);
+
+	g_free(s1_key);
+	g_free(s2_key);
+
+	if (!case_sensitive)
+		{
+		g_free(s1_t);
+		g_free(s2_t);
+		}
+
+	return ret;
+}
+
+/* Borrowed from gtkfilesystemunix.c */
+gchar *expand_tilde(const gchar *filename)
+{
+#ifndef G_OS_UNIX
+	return g_strdup(filename);
+#else
+	const gchar *notilde;
+	const gchar *slash;
+	const gchar *home;
+
+	if (filename[0] != '~')
+		return g_strdup(filename);
+
+	notilde = filename + 1;
+	slash = strchr(notilde, G_DIR_SEPARATOR);
+	if (slash == notilde || !*notilde)
+		{
+		home = g_get_home_dir();
+		if (!home)
+			return g_strdup(filename);
+		}
+	else
+		{
+		gchar *username;
+		struct passwd *passwd;
+
+		if (slash)
+			username = g_strndup(notilde, slash - notilde);
+		else
+			username = g_strdup(notilde);
+
+		passwd = getpwnam(username);
+		g_free(username);
+
+		if (!passwd)
+			return g_strdup(filename);
+
+		home = passwd->pw_dir;
+		}
+
+	if (slash)
+		return g_build_filename(home, G_DIR_SEPARATOR_S, slash + 1, NULL);
+	else
+		return g_build_filename(home, G_DIR_SEPARATOR_S, NULL);
+#endif
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/misc.h	Sun Aug 31 10:51:41 2008 +0000
@@ -0,0 +1,21 @@
+/*
+ * Geeqie
+ * Copyright (C) 2008 The Geeqie Team
+ *
+ * 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!
+ */
+
+#ifndef MISC_H
+#define MISC_H
+
+gdouble get_zoom_increment(void);
+gchar *utf8_validate_or_convert(const gchar *text);
+gint utf8_compare(const gchar *s1, const gchar *s2, gboolean case_sensitive);
+gchar *expand_tilde(const gchar *filename);
+
+#endif /* MISC_H */
--- a/src/pan-view.c	Sun Aug 31 10:08:48 2008 +0000
+++ b/src/pan-view.c	Sun Aug 31 10:51:41 2008 +0000
@@ -23,14 +23,15 @@
 #include "img-view.h"
 #include "info.h"
 #include "menu.h"
+#include "misc.h"
 #include "pan-types.h"
 #include "thumb.h"
-#include "utilops.h"
 #include "ui_fileops.h"
 #include "ui_menu.h"
 #include "ui_tabcomp.h"
 #include "ui_utildlg.h"
 #include "uri_utils.h"
+#include "utilops.h"
 #include "window.h"
 
 #include <gdk/gdkkeysyms.h> /* for keyboard values */
--- a/src/remote.c	Sun Aug 31 10:08:48 2008 +0000
+++ b/src/remote.c	Sun Aug 31 10:51:41 2008 +0000
@@ -19,6 +19,7 @@
 #include "img-view.h"
 #include "layout.h"
 #include "layout_image.h"
+#include "misc.h"
 #include "slideshow.h"
 #include "ui_fileops.h"
 
--- a/src/search.c	Sun Aug 31 10:08:48 2008 +0000
+++ b/src/search.c	Sun Aug 31 10:51:41 2008 +0000
@@ -20,16 +20,16 @@
 #include "collect-table.h"
 #include "dnd.h"
 #include "dupe.h"
+#include "editors.h"
+#include "filedata.h"
 #include "image-load.h"
+#include "img-view.h"
 #include "info.h"
-#include "editors.h"
-#include "img-view.h"
-#include "filedata.h"
 #include "layout_image.h"
 #include "menu.h"
+#include "misc.h"
 #include "print.h"
 #include "thumb.h"
-#include "utilops.h"
 #include "ui_bookmark.h"
 #include "ui_fileops.h"
 #include "ui_menu.h"
@@ -38,6 +38,7 @@
 #include "ui_tabcomp.h"
 #include "ui_tree_edit.h"
 #include "uri_utils.h"
+#include "utilops.h"
 #include "window.h"
 
 #include <gdk/gdkkeysyms.h> /* for keyboard values */
--- a/src/ui_tabcomp.c	Sun Aug 31 10:08:48 2008 +0000
+++ b/src/ui_tabcomp.c	Sun Aug 31 10:51:41 2008 +0000
@@ -30,6 +30,7 @@
 #include "ui_tabcomp.h"
 
 #include "history_list.h"
+#include "misc.h"	/* expand_tilde() */
 #include "ui_fileops.h"
 #include "ui_spinner.h"
 #include "ui_utildlg.h"