[gnome-applets/wip/muktupavels/per-applet-notes-file: 3/3] sticky-notes: cleanup stickynotes_load
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-applets/wip/muktupavels/per-applet-notes-file: 3/3] sticky-notes: cleanup stickynotes_load
- Date: Wed, 14 Oct 2020 22:04:23 +0000 (UTC)
commit 4f50683535df40d8814108e505893097be00ec7e
Author: Sebastian Geiger <sbastig gmx net>
Date: Mon Apr 13 16:44:04 2020 +0200
sticky-notes: cleanup stickynotes_load
This commit extracts the get_notes_file and migrate_legacy_note_file
functions to make stickynotes_load more readable.
gnome-applets/sticky-notes/sticky-notes.c | 153 +++++++++++++++++++-----------
1 file changed, 96 insertions(+), 57 deletions(-)
---
diff --git a/gnome-applets/sticky-notes/sticky-notes.c b/gnome-applets/sticky-notes/sticky-notes.c
index 43d5f0cff..64f0c1934 100644
--- a/gnome-applets/sticky-notes/sticky-notes.c
+++ b/gnome-applets/sticky-notes/sticky-notes.c
@@ -1303,12 +1303,102 @@ get_unique_filename (void)
return filename;
}
+static char *
+get_notes_file (StickyNotesApplet *applet)
+{
+ const char *dir;
+ char *filename;
+ char *notes_file;
+
+ dir = g_get_user_config_dir ();
+ filename = g_settings_get_string (applet->settings, KEY_FILENAME);
+
+ g_free (applet->filename);
+
+ if (*filename == '\0')
+ {
+ g_free (filename);
+ filename = get_unique_filename ();
+
+ notes_file = g_build_filename (dir,
+ "gnome-applets",
+ "sticky-notes",
+ filename,
+ NULL);
+
+
+
+ applet->filename = filename;
+ g_settings_set_string (applet->settings, KEY_FILENAME, filename);
+ }
+ else
+ {
+ applet->filename = filename;
+ notes_file = g_build_filename (dir,
+ "gnome-applets",
+ "sticky-notes",
+ filename,
+ NULL);
+ }
+
+ return notes_file;
+}
+
+/**
+ * The sticky-notes file had various locations in past versions of the applet.
+ *
+ * Until version 3.24 the location was: `~/.config/gnome-applets/stickynotes`.
+ * In version 3.26 the location changed to: `<XDG_CONFIG_HOME>/gnome-applets/sticky-notes/sticky-notes.xml`.
+ * In version 3.38 the location changed to:
`<XDG_CONFIG_HOME>/gnome-applets/sticky-notes/sticky-notes-%d.xml`
+ * where `%d` is incremented for each notes applet on the panel.
+ */
+static void
+migrate_legacy_note_file (StickyNotesApplet *applet,
+ const char *notes_file)
+{
+ const char *dir;
+ char *old_file;
+
+ dir = g_get_user_config_dir ();
+
+ old_file = g_build_filename (dir,
+ "gnome-applets",
+ "sticky-notes",
+ "sticky-notes.xml",
+ NULL);
+
+ if (g_file_test (old_file, G_FILE_TEST_EXISTS))
+ {
+ g_rename (old_file, notes_file);
+
+ g_free (old_file);
+ old_file = g_build_filename (dir,
+ "gnome-applets",
+ "stickynotes",
+ NULL);
+
+ if (g_file_test (old_file, G_FILE_TEST_EXISTS))
+ g_unlink (old_file);
+ }
+ else
+ {
+ g_free (old_file);
+ old_file = g_build_filename (dir,
+ "gnome-applets",
+ "stickynotes",
+ NULL);
+
+ if (g_file_test (old_file, G_FILE_TEST_EXISTS))
+ g_rename (old_file, notes_file);
+ }
+
+ g_free (old_file);
+}
+
/* Load all sticky notes from an XML configuration file */
void
stickynotes_load (StickyNotesApplet *applet)
{
- const char *dir;
- char *filename;
char *notes_file;
xmlDocPtr doc;
xmlNodePtr root;
@@ -1317,62 +1407,11 @@ stickynotes_load (StickyNotesApplet *applet)
GList *new_notes, *tmp1; /* Lists of StickyNote*'s */
int x, y, w, h;
- dir = g_get_user_config_dir ();
- filename = g_settings_get_string (applet->settings, KEY_FILENAME);
- g_free (applet->filename);
-
- if (*filename == '\0') {
- char *old_file;
-
- g_free (filename);
- filename = get_unique_filename ();
-
- notes_file = g_build_filename (dir,
- "gnome-applets",
- "sticky-notes",
- filename,
- NULL);
-
- old_file = g_build_filename (dir,
- "gnome-applets",
- "sticky-notes",
- "sticky-notes.xml",
- NULL);
-
- if (g_file_test (old_file, G_FILE_TEST_EXISTS)) {
- g_rename (old_file, notes_file);
-
- g_free (old_file);
- old_file = g_build_filename (dir,
- "gnome-applets",
- "stickynotes",
- NULL);
-
- if (g_file_test (old_file, G_FILE_TEST_EXISTS))
- g_unlink (old_file);
- } else {
- g_free (old_file);
- old_file = g_build_filename (dir,
- "gnome-applets",
- "stickynotes",
- NULL);
-
- if (g_file_test (old_file, G_FILE_TEST_EXISTS))
- g_rename (old_file, notes_file);
- }
+ notes_file = get_notes_file (applet);
- applet->filename = filename;
- g_settings_set_string (applet->settings, KEY_FILENAME, filename);
-
- g_free (old_file);
- } else {
- applet->filename = filename;
- notes_file = g_build_filename (dir,
- "gnome-applets",
- "sticky-notes",
- filename,
- NULL);
- }
+ if (!g_file_test (notes_file, G_FILE_TEST_EXISTS)) {
+ migrate_legacy_note_file (applet, notes_file);
+ }
if (!g_file_test (notes_file, G_FILE_TEST_EXISTS)) {
g_free (notes_file);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]