Merge lp:~jeremywootten/pantheon-files/add-XDG-folders-by-default into lp:~elementary-apps/pantheon-files/trunk

Proposed by Jeremy Wootten
Status: Merged
Approved by: Cody Garver
Approved revision: 1754
Merged at revision: 1820
Proposed branch: lp:~jeremywootten/pantheon-files/add-XDG-folders-by-default
Merge into: lp:~elementary-apps/pantheon-files/trunk
Diff against target: 91 lines (+47/-4)
1 file modified
src/BookmarkList.vala (+47/-4)
To merge this branch: bzr merge lp:~jeremywootten/pantheon-files/add-XDG-folders-by-default
Reviewer Review Type Date Requested Status
elementary Apps team Pending
Review via email: mp+250551@code.launchpad.net

Commit message

Create a new bookmark file containing the user special directories by default.

Description of the change

This branch ensures that, if there is no pre-existing bookmark file, a new one containing the user special directories is created.

To post a comment you must log in.
1754. By Jeremy Wootten

Merge trunk to r1814

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/BookmarkList.vala'
2--- src/BookmarkList.vala 2015-01-01 19:31:53 +0000
3+++ src/BookmarkList.vala 2015-05-14 16:43:32 +0000
4@@ -49,33 +49,69 @@
5 "gtk-3.0",
6 "bookmarks",
7 null);
8+
9 var file = GLib.File.new_for_path (filename);
10 if (!file.query_exists (null)) {
11+ /* Bookmarks file does not exist in right place ... create a new one */
12 try {
13 file.get_parent ().make_directory_with_parents (null);
14+ }
15+ catch (GLib.Error error) {
16+ /* Probably already exists */
17+ warning ("Could not create bookmarks directory: %s", error.message);
18+ }
19+
20+ try {
21 file.create (GLib.FileCreateFlags.NONE, null);
22 }
23 catch (GLib.Error error){
24 critical ("Could not create bookmarks file: %s", error.message);
25 }
26- /* load existing bookmarks from old location if exists */
27+
28+ /* load existing bookmarks from the old location if it exists */
29 var old_filename = GLib.Path.build_filename (GLib.Environment.get_home_dir (),
30 ".gtk-bookmarks",
31 null);
32+
33 var old_file = GLib.File.new_for_path (old_filename);
34 if (old_file.query_exists (null)) {
35+ /* If there is a legacy bookmark file we copy it to the new location */
36 Marlin.BookmarkList.bookmarks_file = old_file;
37 load_bookmarks_file ();
38 Marlin.BookmarkList.bookmarks_file = file;
39- save_bookmarks_file ();
40+ } else {
41+ /* Else populate the new file with default bookmarks */
42+ Marlin.BookmarkList.bookmarks_file = file;
43+ add_special_directories ();
44 }
45- }
46- else {
47+ save_bookmarks_file ();
48+ } else {
49 Marlin.BookmarkList.bookmarks_file = file;
50 load_bookmarks_file ();
51 }
52 }
53
54+ private void add_special_directory (GLib.UserDirectory user_dir, ref GLib.List<string> uris) {
55+ string? dir_s = Environment.get_user_special_dir (user_dir);
56+
57+ if (dir_s != null)
58+ uris.prepend ("file://" + dir_s);
59+ }
60+
61+ private void add_special_directories () {
62+ GLib.List<string> uris = null;
63+ add_special_directory (UserDirectory.DOCUMENTS, ref uris);
64+ add_special_directory (UserDirectory.DOWNLOAD, ref uris);
65+ add_special_directory (UserDirectory.MUSIC, ref uris);
66+ add_special_directory (UserDirectory.PUBLIC_SHARE, ref uris);
67+ add_special_directory (UserDirectory.PICTURES, ref uris);
68+ add_special_directory (UserDirectory.TEMPLATES, ref uris);
69+ add_special_directory (UserDirectory.VIDEOS, ref uris);
70+
71+ uris.reverse ();
72+ insert_uris_at_end (uris);
73+ }
74+
75 public static BookmarkList get_instance () {
76 if (instance == null)
77 instance = new BookmarkList ();
78@@ -101,6 +137,13 @@
79 save_bookmarks_file ();
80 }
81
82+ public void insert_uris_at_end (GLib.List<string> uris) {
83+ uris.@foreach ((uri) => {
84+ append_internal (new Bookmark.from_uri (uri, null));
85+ });
86+ save_bookmarks_file ();
87+ }
88+
89 public bool contains (Marlin.Bookmark bm) {
90 return (list.find_custom (bm, Marlin.Bookmark.compare_with) != null);
91 }

Subscribers

People subscribed via source and target branches

to all changes: