Updating branch refs/heads/master to 2709fd15751d4197f8c260989b7069473dfae65f (commit) from a8924e11dad4f268f699ce42abd348ba4dcb2492 (commit)
commit 2709fd15751d4197f8c260989b7069473dfae65f Author: Nick Schermer <n...@xfce.org> Date: Mon Jan 14 16:49:57 2008 +0000 * Drop libxfce4util as dependency * Switch to accessories-text-editor as icon name (Old svn revision: 26571) Mousepad.desktop.in.in | 2 +- Mousepad.spec.in | 2 - configure.in.in | 5 +- icons/16x16/Makefile.am | 11 ++- icons/24x24/Makefile.am | 5 + icons/scalable/Makefile.am | 5 + mousepad/Makefile.am | 2 - mousepad/main.c | 12 ++- mousepad/mousepad-application.c | 20 ++-- mousepad/mousepad-dialogs.c | 3 +- mousepad/mousepad-preferences.c | 212 +++++++++++++++++++++------------------ mousepad/mousepad-preferences.h | 2 - mousepad/mousepad-print.c | 64 ++++++++----- mousepad/mousepad-private.h | 6 +- mousepad/mousepad-util.c | 81 +++++++++++++++ mousepad/mousepad-util.h | 6 + mousepad/mousepad-window.c | 11 ++- 17 files changed, 295 insertions(+), 154 deletions(-) diff --git a/Mousepad.desktop.in.in b/Mousepad.desktop.in.in index 38a39eb..21fda29 100644 --- a/Mousepad.desktop.in.in +++ b/Mousepad.desktop.in.in @@ -5,7 +5,7 @@ _Name=Mousepad _Comment=Simple Text Editor _GenericName=Text Editor Exec=mousepad %F -Icon=mousepad +Icon=accessories-text-editor Terminal=false StartupNotify=true Type=Application diff --git a/Mousepad.spec.in b/Mousepad.spec.in index eaf1459..6261c2c 100644 --- a/Mousepad.spec.in +++ b/Mousepad.spec.in @@ -8,9 +8,7 @@ Source0: %{name}-%{version}.tar.gz Group: Applications/X11 BuildRoot: %{_tmppath}/%{name}-root Requires: gtk2 >= @GTK_REQUIRED_VERSION@ -Requires: libxfce4util >= @LIBXFCE4UTIL_REQUIRED_VERSION@ BuildRequires: gtk2-devel >= @GTK_REQUIRED_VERSION@ -BuildRequires: libxfce4util-devel >= @LIBXFCE4UTIL_REQUIRED_VERSION@ %description Mousepad is a simple text editor for the Xfce Desktop Environment. diff --git a/configure.in.in b/configure.in.in index 7099a24..74c44a5 100644 --- a/configure.in.in +++ b/configure.in.in @@ -69,8 +69,8 @@ AC_SUBST([MOUSEPAD_VERSION_MICRO]) dnl ********************************** dnl *** Check for standard headers *** dnl ********************************** -AC_CHECK_HEADERS([errno.h fcntl.h memory.h math.h stdlib.h string.h \ - sys/types.h sys/stat.h time.h unistd.h]) +AC_CHECK_HEADERS([errno.h fcntl.h libintl.h memory.h math.h stdlib.h \ + string.h sys/types.h sys/stat.h time.h unistd.h]) dnl ****************************** dnl *** Check for i18n support *** @@ -84,7 +84,6 @@ XDT_CHECK_PACKAGE([GLIB], [glib-2.0], [2.12.0]) XDT_CHECK_PACKAGE([GMODULE], [gmodule-2.0], [2.12.0]) XDT_CHECK_PACKAGE([GTHREAD], [gthread-2.0], [2.12.0]) XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [2.10.0]) -XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.4.0]) dnl ********************************** dnl *** Optional support for D-BUS *** diff --git a/icons/16x16/Makefile.am b/icons/16x16/Makefile.am index 4fe130f..6cedaf6 100644 --- a/icons/16x16/Makefile.am +++ b/icons/16x16/Makefile.am @@ -1,10 +1,15 @@ # $Id$ -appsdir = $(datadir)/icons/hicolor/16x16/apps -apps_DATA = \ +iconsdir = $(datadir)/icons/hicolor/16x16/apps +icons_DATA = \ Mousepad.png +# install symlink +install-data-local: + $(mkinstalldirs) $(DESTDIR)$(iconsdir) + -( cd $(DESTDIR)$(iconsdir) ; ln -sf Mousepad.png accessories-text-editor.png ) + EXTRA_DIST = \ - $(apps_DATA) + $(icons_DATA) # vi:set ts=8 sw=8 noet ai nocindent syntax=automake: diff --git a/icons/24x24/Makefile.am b/icons/24x24/Makefile.am index 2608272..0a73503 100644 --- a/icons/24x24/Makefile.am +++ b/icons/24x24/Makefile.am @@ -4,6 +4,11 @@ iconsdir = $(datadir)/icons/hicolor/24x24/apps icons_DATA = \ Mousepad.png +# install symlink +install-data-local: + $(mkinstalldirs) $(DESTDIR)$(iconsdir) + -( cd $(DESTDIR)$(iconsdir) ; ln -sf Mousepad.png accessories-text-editor.png ) + EXTRA_DIST = \ $(icons_DATA) diff --git a/icons/scalable/Makefile.am b/icons/scalable/Makefile.am index 305a62c..b2a0019 100644 --- a/icons/scalable/Makefile.am +++ b/icons/scalable/Makefile.am @@ -4,6 +4,11 @@ iconsdir = $(datadir)/icons/hicolor/scalable/apps icons_DATA = \ Mousepad.svg +# install symlink +install-data-local: + $(mkinstalldirs) $(DESTDIR)$(iconsdir) + -( cd $(DESTDIR)$(iconsdir) ; ln -sf Mousepad.svg accessories-text-editor.svg ) + EXTRA_DIST = \ $(icons_DATA) diff --git a/mousepad/Makefile.am b/mousepad/Makefile.am index 1d1b787..f78f66e 100644 --- a/mousepad/Makefile.am +++ b/mousepad/Makefile.am @@ -59,7 +59,6 @@ mousepad_SOURCES = \ mousepad_CFLAGS = \ $(GTK_CFLAGS) \ - $(LIBXFCE4UTIL_CFLAGS) \ $(GMODULE_CFLAGS) \ $(GTHREAD_CFLAGS) \ $(PLATFORM_CFLAGS) @@ -70,7 +69,6 @@ mousepad_LDFLAGS = \ mousepad_LDADD = \ $(GTK_LIBS) \ - $(LIBXFCE4UTIL_LIBS) \ $(GMODULE_LIBS) \ $(GTHREAD_LIBS) diff --git a/mousepad/main.c b/mousepad/main.c index 2dd937a..63d17a6 100644 --- a/mousepad/main.c +++ b/mousepad/main.c @@ -25,6 +25,9 @@ #ifdef HAVE_STDLIB_H #include <stdlib.h> #endif +#ifdef HAVE_LIBINTL_H +#include <libintl.h> +#endif #include <mousepad/mousepad-private.h> #include <mousepad/mousepad-application.h> @@ -68,8 +71,11 @@ main (gint argc, gchar **argv) MousepadDBusService *dbus_service; #endif - /* translation domain */ - xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8"); + /* bind the text domain to the locale directory */ + bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); + + /* set the package textdomain */ + textdomain (GETTEXT_PACKAGE); /* default application name */ g_set_application_name (_("Mousepad")); @@ -105,7 +111,7 @@ main (gint argc, gchar **argv) /* check if we should print version information */ if (G_UNLIKELY (opt_version)) { - g_print ("%s %s (Xfce %s)\n\n", PACKAGE_NAME, PACKAGE_VERSION, xfce_version_string ()); + g_print ("%s %s\n\n", PACKAGE_NAME, PACKAGE_VERSION); g_print ("%s\n", "Copyright (c) 2007"); g_print ("\t%s\n\n", _("The Xfce development team. All rights reserved.")); g_print (_("Please report bugs to <%s>."), PACKAGE_BUGREPORT); diff --git a/mousepad/mousepad-application.c b/mousepad/mousepad-application.c index b308d15..10e1250 100644 --- a/mousepad/mousepad-application.c +++ b/mousepad/mousepad-application.c @@ -76,17 +76,17 @@ mousepad_application_class_init (MousepadApplicationClass *klass) static void mousepad_application_init (MousepadApplication *application) { - gchar *path; + gchar *filename; /* check if we have a saved accel map */ - path = xfce_resource_lookup (XFCE_RESOURCE_CONFIG, PACKAGE_NAME G_DIR_SEPARATOR_S "accels.scm"); - if (G_LIKELY (path != NULL)) + filename = mousepad_util_get_save_location (MOUSEPAD_ACCELS_RELPATH, FALSE); + if (G_LIKELY (filename != NULL)) { /* load the accel map */ - gtk_accel_map_load (path); + gtk_accel_map_load (filename); /* cleanup */ - g_free (path); + g_free (filename); } } @@ -97,7 +97,7 @@ mousepad_application_finalize (GObject *object) { MousepadApplication *application = MOUSEPAD_APPLICATION (object); GSList *li; - gchar *path; + gchar *filename; /* flush the history items of the replace dialog * this is a bit of an ugly place, but cleaning on a window close @@ -105,14 +105,14 @@ mousepad_application_finalize (GObject *object) mousepad_replace_dialog_history_clean (); /* save the current accel map */ - path = xfce_resource_save_location (XFCE_RESOURCE_CONFIG, PACKAGE_NAME G_DIR_SEPARATOR_S "accels.scm", TRUE); - if (G_LIKELY (path != NULL)) + filename = mousepad_util_get_save_location (MOUSEPAD_ACCELS_RELPATH, TRUE); + if (G_LIKELY (filename != NULL)) { /* save the accel map */ - gtk_accel_map_save (path); + gtk_accel_map_save (filename); /* cleanup */ - g_free (path); + g_free (filename); } /* destroy the windows if they are still opened */ diff --git a/mousepad/mousepad-dialogs.c b/mousepad/mousepad-dialogs.c index 3ec9dad..498b613 100644 --- a/mousepad/mousepad-dialogs.c +++ b/mousepad/mousepad-dialogs.c @@ -40,8 +40,7 @@ mousepad_dialogs_show_about (GtkWindow *parent) "authors", authors, "comments", _("Mousepad is a fast text editor for the Xfce Desktop Environment."), "destroy-with-parent", TRUE, - "license", XFCE_LICENSE_GPL, - "logo-icon-name", PACKAGE_NAME, + "logo-icon-name", "accessories-text-editor", #if GTK_CHECK_VERSION (2,12,0) "program-name", PACKAGE_NAME, #else diff --git a/mousepad/mousepad-preferences.c b/mousepad/mousepad-preferences.c index ab1e3c1..3ae251c 100644 --- a/mousepad/mousepad-preferences.c +++ b/mousepad/mousepad-preferences.c @@ -122,8 +122,7 @@ struct _MousepadPreferences * @const GValue : String #GValue. * @GValue : Return location for a #GValue boolean. * - * Converts a string into a boolean. This is used when - * converting the XfceRc values. + * Converts a string into a boolean. **/ static void transform_string_to_boolean (const GValue *src, @@ -357,8 +356,8 @@ mousepad_preferences_finalize (GObject *object) /* flush preferences */ if (G_UNLIKELY (preferences->store_idle_id != 0)) { - mousepad_preferences_store (preferences); g_source_remove (preferences->store_idle_id); + mousepad_preferences_store (preferences); } /* release the property values */ for (n = 1; n < N_PROPERTIES; ++n) @@ -451,82 +450,88 @@ mousepad_preferences_check_option_name (GParamSpec *pspec) static void mousepad_preferences_load (MousepadPreferences *preferences) { - const gchar *string; - GParamSpec **specs; - GParamSpec *spec; - XfceRc *rc; - GValue dst = { 0, }; - GValue src = { 0, }; - guint nspecs; - guint n; - - /* try to open the config file */ - rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, MOUSEPAD_PREFERENCES_REL_PATH, TRUE); - if (G_UNLIKELY (rc == NULL)) - { - g_warning (_("Failed to load the preferences.")); - - return; - } + gchar *string; + GParamSpec **pspecs; + GParamSpec *pspec; + GKeyFile *keyfile; + gchar *filename; + GValue dst = { 0, }; + GValue src = { 0, }; + guint nspecs; + guint n; + + /* get the save location */ + filename = mousepad_util_get_save_location (MOUSEPAD_RC_RELPATH, FALSE); + + /* leave when there if no file found */ + if (G_UNLIKELY (filename == NULL)) + return; + + /* create a new key file */ + keyfile = g_key_file_new (); - /* freeze notification signals */ - g_object_freeze_notify (G_OBJECT (preferences)); - - /* set group */ - xfce_rc_set_group (rc, "Configuration"); + /* open the config file */ + if (G_LIKELY (g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, NULL))) + { + /* freeze notification signals */ + g_object_freeze_notify (G_OBJECT (preferences)); - /* get all the properties in the class */ - specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (preferences), &nspecs); + /* get all the properties in the class */ + pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (preferences), &nspecs); - for (n = 0; n < nspecs; ++n) - { - spec = specs[n]; + for (n = 0; n < nspecs; n++) + { + pspec = pspecs[n]; #ifndef NDEBUG - /* check nick name with generated option name */ - mousepad_preferences_check_option_name (spec); + /* check nick name with generated option name */ + mousepad_preferences_check_option_name (pspec); #endif - /* read the entry */ - string = xfce_rc_read_entry (rc, spec->_nick, NULL); - - if (G_UNLIKELY (string == NULL)) - continue; - - /* create gvalue with the string as value */ - g_value_init (&src, G_TYPE_STRING); - g_value_set_static_string (&src, string); - - if (spec->value_type == G_TYPE_STRING) - { - /* they have the same type, so set the property */ - g_object_set_property (G_OBJECT (preferences), spec->name, &src); - } - else if (g_value_type_transformable (G_TYPE_STRING, spec->value_type)) - { - /* transform the type */ - g_value_init (&dst, spec->value_type); - if (g_value_transform (&src, &dst)) - g_object_set_property (G_OBJECT (preferences), spec->name, &dst); - g_value_unset (&dst); - } - else - { - g_warning ("Failed to load property \"%s\"", spec->name); + /* read the propert value */ + string = g_key_file_get_string (keyfile, "Configuration", pspec->_nick, NULL); + + if (G_UNLIKELY (string == NULL)) + continue; + + /* create gvalue with the string as value */ + g_value_init (&src, G_TYPE_STRING); + g_value_take_string (&src, string); + + if (pspec->value_type == G_TYPE_STRING) + { + /* they have the same type, so set the property */ + g_object_set_property (G_OBJECT (preferences), pspec->name, &src); + } + else if (g_value_type_transformable (G_TYPE_STRING, pspec->value_type)) + { + /* transform the type */ + g_value_init (&dst, pspec->value_type); + if (g_value_transform (&src, &dst)) + g_object_set_property (G_OBJECT (preferences), pspec->name, &dst); + g_value_unset (&dst); + } + else + { + g_warning ("Failed to load property \"%s\"", pspec->name); + } + + /* cleanup */ + g_value_unset (&src); } - /* cleanup */ - g_value_unset (&src); - } + /* cleanup the specs */ + g_free (pspecs); - /* cleanup the specs */ - g_free (specs); + /* allow notifications again */ + g_object_thaw_notify (G_OBJECT (preferences)); + } - /* close the rc file */ - xfce_rc_close (rc); + /* free the key file */ + g_key_file_free (keyfile); - /* allow notifications again */ - g_object_thaw_notify (G_OBJECT (preferences)); + /* cleanup filename */ + g_free (filename); } @@ -546,63 +551,76 @@ mousepad_preferences_store (MousepadPreferences *preferences) static gboolean mousepad_preferences_store_idle (gpointer user_data) { - MousepadPreferences *preferences = MOUSEPAD_PREFERENCES (user_data); - const gchar *string; - GParamSpec **specs; - GParamSpec *spec; - XfceRc *rc; - GValue dst = { 0, }; - GValue src = { 0, }; - guint nspecs; - guint n; - - /* open the config file */ - rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, MOUSEPAD_PREFERENCES_REL_PATH, FALSE); - if (G_UNLIKELY (rc == NULL)) - { - g_warning (_("Failed to store the preferences.")); - return FALSE; - } - - /* set the group */ - xfce_rc_set_group (rc, "Configuration"); + MousepadPreferences *preferences = MOUSEPAD_PREFERENCES (user_data); + const gchar *string; + GParamSpec **pspecs; + GParamSpec *pspec; + GKeyFile *keyfile; + gchar *filename; + GValue dst = { 0, }; + GValue src = { 0, }; + guint nspecs; + guint n; + + /* get the config filename */ + filename = mousepad_util_get_save_location (MOUSEPAD_RC_RELPATH, TRUE); + + /* leave when no filename is returned */ + if (G_UNLIKELY (filename == NULL)) + return FALSE; + + /* create an empty key file */ + keyfile = g_key_file_new (); + + /* try to load the file contents, no worries if this fails */ + g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, NULL); /* get the list of properties in the class */ - specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (preferences), &nspecs); + pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (preferences), &nspecs); for (n = 0; n < nspecs; ++n) { - spec = specs[n]; + pspec = pspecs[n]; /* init a string value */ g_value_init (&dst, G_TYPE_STRING); - if (spec->value_type == G_TYPE_STRING) + if (pspec->value_type == G_TYPE_STRING) { /* set the string value */ - g_object_get_property (G_OBJECT (preferences), spec->name, &dst); + g_object_get_property (G_OBJECT (preferences), pspec->name, &dst); } else { /* property contains another type, transform it first */ - g_value_init (&src, spec->value_type); - g_object_get_property (G_OBJECT (preferences), spec->name, &src); + g_value_init (&src, pspec->value_type); + g_object_get_property (G_OBJECT (preferences), pspec->name, &src); g_value_transform (&src, &dst); g_value_unset (&src); } - /* store the setting */ + /* get the string from the value */ string = g_value_get_string (&dst); + + /* store the value */ if (G_LIKELY (string != NULL)) - xfce_rc_write_entry (rc, spec->_nick, string); + g_key_file_set_string (keyfile, "Configuration", pspec->_nick, string); /* cleanup */ g_value_unset (&dst); } + /* cleanup the specs */ + g_free (pspecs); + + /* save the keyfile */ + mousepad_util_save_key_file (keyfile, filename); + + /* close the key file */ + g_key_file_free (keyfile); + /* cleanup */ - g_free (specs); - xfce_rc_close (rc); + g_free (filename); return FALSE; } diff --git a/mousepad/mousepad-preferences.h b/mousepad/mousepad-preferences.h index c782432..d3161a0 100644 --- a/mousepad/mousepad-preferences.h +++ b/mousepad/mousepad-preferences.h @@ -27,8 +27,6 @@ G_BEGIN_DECLS #define MOUSEPAD_IS_PREFERENCES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOUSEPAD_TYPE_PREFERENCES)) #define MOUSEPAD_PREFERENCES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOUSEPAD_TYPE_PREFERENCES, MousepadPreferencesClass)) -#define MOUSEPAD_PREFERENCES_REL_PATH ("Mousepad" G_DIR_SEPARATOR_S "mousepadrc") - typedef struct _MousepadPreferencesClass MousepadPreferencesClass; typedef struct _MousepadPreferences MousepadPreferences; diff --git a/mousepad/mousepad-print.c b/mousepad/mousepad-print.c index 1a1ba60..23df23a 100644 --- a/mousepad/mousepad-print.c +++ b/mousepad/mousepad-print.c @@ -159,12 +159,13 @@ static void mousepad_print_settings_load (GtkPrintOperation *operation) { MousepadPrint *print = MOUSEPAD_PRINT (operation); - XfceRc *rc; + GKeyFile *keyfile; + gchar *filename; GtkPrintSettings *settings = NULL; gchar **keys; gint i; gchar *key; - const gchar *value; + gchar *value; GtkPageSetup *page_setup; GtkPaperSize *paper_size; PangoContext *context; @@ -173,13 +174,18 @@ mousepad_print_settings_load (GtkPrintOperation *operation) _mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (print->document)); _mousepad_return_if_fail (GTK_IS_WIDGET (print->document->textview)); - /* open the config file */ - rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, MOUSEPAD_PREFERENCES_REL_PATH, TRUE); + /* get the config file filename */ + filename = mousepad_util_get_save_location (MOUSEPAD_RC_RELPATH, FALSE); + if (G_UNLIKELY (filename == NULL)) + return; - if (G_LIKELY (rc != NULL)) + /* create a new keyfile */ + keyfile = g_key_file_new (); + + if (G_LIKELY (g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, NULL))) { /* get all the keys from the config file */ - keys = xfce_rc_get_entries (rc, "Print Settings"); + keys = g_key_file_get_keys (keyfile, "Print Settings", NULL, NULL); if (G_LIKELY (keys)) { @@ -190,7 +196,7 @@ mousepad_print_settings_load (GtkPrintOperation *operation) for (i = 0; keys[i] != NULL; i++) { /* read the value from the config file */ - value = xfce_rc_read_entry (rc, keys[i], NULL); + value = g_key_file_get_string (keyfile, "Print Settings", keys[i], NULL); /* set the value */ if (G_LIKELY (value)) @@ -198,17 +204,21 @@ mousepad_print_settings_load (GtkPrintOperation *operation) key = mousepad_util_key_name (keys[i]); gtk_print_settings_set (settings, key, value); g_free (key); + g_free (value); } } /* cleanup */ g_strfreev (keys); } - - /* close */ - xfce_rc_close (rc); } + /* free the key file */ + g_key_file_free (keyfile); + + /* cleanup */ + g_free (filename); + if (G_LIKELY (settings)) { /* apply the settings */ @@ -267,14 +277,14 @@ mousepad_print_settings_save_foreach (const gchar *key, const gchar *value, gpointer user_data) { - XfceRc *rc = (XfceRc *) user_data; - gchar *config; + GKeyFile *keyfile = user_data; + gchar *config; /* save the setting */ if (G_LIKELY (key && value)) { config = mousepad_util_config_name (key); - xfce_rc_write_entry (rc, config, value); + g_key_file_set_string (keyfile, "Print Settings", config, value); g_free (config); } } @@ -285,19 +295,21 @@ static void mousepad_print_settings_save (GtkPrintOperation *operation) { MousepadPrint *print = MOUSEPAD_PRINT (operation); - XfceRc *rc; + GKeyFile *keyfile; + gchar *filename; GtkPrintSettings *settings; GtkPageSetup *page_setup; GtkPaperSize *paper_size; - /* open the config file */ - rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, MOUSEPAD_PREFERENCES_REL_PATH, FALSE); + /* get the save location */ + filename = mousepad_util_get_save_location (MOUSEPAD_RC_RELPATH, TRUE); - if (G_LIKELY (rc != NULL)) - { - /* set print settings group */ - xfce_rc_set_group (rc, "Print Settings"); + /* create a new keyfile */ + keyfile = g_key_file_new (); + /* load the existing settings */ + if (G_LIKELY (g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, NULL))) + { /* get the print settings */ settings = gtk_print_operation_get_print_settings (operation); @@ -336,12 +348,16 @@ mousepad_print_settings_save (GtkPrintOperation *operation) gtk_print_settings_set (settings, "font-name", print->font_name); /* store all the print settings */ - gtk_print_settings_foreach (settings, mousepad_print_settings_save_foreach, rc); - } + gtk_print_settings_foreach (settings, mousepad_print_settings_save_foreach, keyfile); - /* close */ - xfce_rc_close (rc); + /* save the contents */ + mousepad_util_save_key_file (keyfile, filename); + } } + + /* cleanup */ + g_key_file_free (keyfile); + g_free (filename); } diff --git a/mousepad/mousepad-private.h b/mousepad/mousepad-private.h index 5ba0333..f271186 100644 --- a/mousepad/mousepad-private.h +++ b/mousepad/mousepad-private.h @@ -21,10 +21,14 @@ #include <glib.h> #include <glib-object.h> #include <gtk/gtk.h> -#include <libxfce4util/libxfce4util.h> +#include <glib/gi18n.h> G_BEGIN_DECLS +/* config file locations */ +#define MOUSEPAD_RC_RELPATH ("Mousepad" G_DIR_SEPARATOR_S "mousepadrc") +#define MOUSEPAD_ACCELS_RELPATH ("Mousepad" G_DIR_SEPARATOR_S "accels.scm") + /* handling flags */ #define MOUSEPAD_SET_FLAG(flags,flag) G_STMT_START{ ((flags) |= (flag)); }G_STMT_END #define MOUSEPAD_UNSET_FLAG(flags,flag) G_STMT_START{ ((flags) &= ~(flag)); }G_STMT_END diff --git a/mousepad/mousepad-util.c b/mousepad/mousepad-util.c index fdb2281..16ff0dd 100644 --- a/mousepad/mousepad-util.c +++ b/mousepad/mousepad-util.c @@ -547,6 +547,87 @@ mousepad_util_forward_iter_to_text (GtkTextIter *iter, +gchar * +mousepad_util_get_save_location (const gchar *relpath, + gboolean create_parents) +{ + gchar *filename, *dirname; + + _mousepad_return_val_if_fail (g_get_user_config_dir () != NULL, NULL); + + /* create the full filename */ + filename = g_build_filename (g_get_user_config_dir (), relpath, NULL); + + /* test if the file exists */ + if (G_UNLIKELY (g_file_test (filename, G_FILE_TEST_IS_REGULAR) == FALSE)) + { + if (create_parents) + { + /* get the directory name */ + dirname = g_path_get_dirname (filename); + + /* make the directory with parents */ + if (g_mkdir_with_parents (dirname, 0700) == -1) + { + /* show warning to the user */ + g_critical (_("Unable to create base directory \"%s\". " + "Saving to file \"%s\" will be aborted."), dirname, filename); + + /* don't return a filename, to avoid problems */ + g_free (filename); + filename = NULL; + } + + /* cleanup */ + g_free (dirname); + } + else + { + /* cleanup */ + g_free (filename); + filename = NULL; + } + } + + return filename; +} + + + +void +mousepad_util_save_key_file (GKeyFile *keyfile, + const gchar *filename) +{ + gchar *contents; + gsize length; + GError *error = NULL; + + /* get the contents of the key file */ + contents = g_key_file_to_data (keyfile, &length, &error); + + if (G_LIKELY (error == NULL)) + { + /* write the contents to the file */ + if (G_UNLIKELY (g_file_set_contents (filename, contents, length, &error) == FALSE)) + goto print_error; + } + else + { + print_error: + + /* print error */ + g_critical (_("Failed to store the preferences to \"%s\": %s"), filename, error->message); + + /* cleanup */ + g_error_free (error); + } + + /* cleanup */ + g_free (contents); +} + + + GType mousepad_util_search_flags_get_type (void) { diff --git a/mousepad/mousepad-util.h b/mousepad/mousepad-util.h index bd5d20a..0fb9032 100644 --- a/mousepad/mousepad-util.h +++ b/mousepad/mousepad-util.h @@ -102,6 +102,12 @@ gint mousepad_util_get_real_line_offset (const GtkTextIter *iter, gboolean mousepad_util_forward_iter_to_text (GtkTextIter *iter, const GtkTextIter *limit); +gchar *mousepad_util_get_save_location (const gchar *relpath, + gboolean create_parents); + +void mousepad_util_save_key_file (GKeyFile *keyfile, + const gchar *filename); + GType mousepad_util_search_flags_get_type (void) G_GNUC_CONST; gint mousepad_util_highlight (GtkTextBuffer *buffer, diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c index 8b551c3..f6ceaf7 100644 --- a/mousepad/mousepad-window.c +++ b/mousepad/mousepad-window.c @@ -550,20 +550,23 @@ mousepad_window_init (MousepadWindow *window) window->active = NULL; window->recent_manager = NULL; + /* setup window */ + gtk_window_set_icon_name (GTK_WINDOW (window), "accessories-text-editor"); + /* increase clipboard history ref count */ clipboard_history_ref_count++; /* add the preferences to the window */ window->preferences = mousepad_preferences_get (); + /* signal for handling the window delete event */ + g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (mousepad_window_delete_event), NULL); + /* allocate a closure for the menu_item_selected() callback */ window->menu_item_selected_closure = g_cclosure_new_object (G_CALLBACK (mousepad_window_menu_item_selected), G_OBJECT (window)); g_closure_ref (window->menu_item_selected_closure); g_closure_sink (window->menu_item_selected_closure); - /* signal for handling the window delete event */ - g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (mousepad_window_delete_event), NULL); - /* allocate a closure for the menu_item_deselected() callback */ window->menu_item_deselected_closure = g_cclosure_new_object (G_CALLBACK (mousepad_window_menu_item_deselected), G_OBJECT (window)); g_closure_ref (window->menu_item_deselected_closure); @@ -1818,7 +1821,7 @@ mousepad_window_menu_templates (GtkWidget *item, mousepad_window_recent_menu (window); /* get the templates path */ - templates_path = xfce_get_homefile ("Templates", NULL); + templates_path = g_build_filename (g_get_home_dir (), "Templates", NULL); /* check if the directory exists */ if (g_file_test (templates_path, G_FILE_TEST_IS_DIR)) _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits