@@ -9,11 +9,11 @@ namespace Fm {
9
9
std::weak_ptr<Bookmarks> Bookmarks::globalInstance_;
10
10
11
11
static inline CStrPtr get_legacy_bookmarks_file (void ) {
12
- return CStrPtr{g_build_filename (g_get_home_dir (), " . gtk-bookmarks" , nullptr )};
12
+ return CStrPtr{g_build_filename (g_get_user_config_dir (), " gtk-3.0 " , " bookmarks" , nullptr )};
13
13
}
14
14
15
15
static inline CStrPtr get_new_bookmarks_file (void ) {
16
- return CStrPtr{g_build_filename (g_get_user_config_dir (), " gtk-3.0 " , " bookmarks" , nullptr )};
16
+ return CStrPtr{g_build_filename (g_get_user_data_dir (), " libfm-qt " , " bookmarks" , nullptr )};
17
17
}
18
18
19
19
BookmarkItem::BookmarkItem (const FilePath& path, const QString name):
@@ -74,14 +74,17 @@ Bookmarks::Bookmarks(QObject* parent):
74
74
QObject (parent),
75
75
idle_handler{false } {
76
76
77
- /* trying the gtk-3.0 first and use it if it exists */
77
+ /* trying our config file first */
78
78
auto fpath = get_new_bookmarks_file ();
79
79
file_ = FilePath::fromLocalPath (fpath.get ());
80
- load ();
81
- if (items_.empty ()) { /* not found, use legacy file */
80
+ load (file_ );
81
+ if (items_.empty ()) { /* not found, check the legacy, gtk-3.0 file */
82
82
fpath = get_legacy_bookmarks_file ();
83
- file_ = FilePath::fromLocalPath (fpath.get ());
84
- load ();
83
+ auto gtkFile = FilePath::fromLocalPath (fpath.get ());
84
+ load (gtkFile);
85
+ if (!items_.empty ()) {
86
+ queueSave ();
87
+ }
85
88
}
86
89
mon = GObjectPtr<GFileMonitor>{g_file_monitor_file (file_.gfile ().get (), G_FILE_MONITOR_NONE, nullptr , nullptr ), false };
87
90
if (mon) {
@@ -161,18 +164,21 @@ void Bookmarks::save() {
161
164
}
162
165
idle_handler = false ;
163
166
// G_UNLOCK(bookmarks);
164
- GError* err = nullptr ;
165
- if (!g_file_replace_contents (file_.gfile ().get (), buf.c_str (), buf.length (), nullptr ,
166
- FALSE , G_FILE_CREATE_NONE, nullptr , nullptr , &err)) {
167
- g_critical (" %s" , err->message );
168
- g_error_free (err);
167
+ CStrPtr libfmDataDir{g_build_filename (g_get_user_data_dir (), " libfm-qt" , nullptr )};
168
+ if (g_mkdir_with_parents (libfmDataDir.get (), 0755 ) == 0 ) {
169
+ GError* err = nullptr ;
170
+ if (!g_file_replace_contents (file_.gfile ().get (), buf.c_str (), buf.length (), nullptr ,
171
+ FALSE , G_FILE_CREATE_NONE, nullptr , nullptr , &err)) {
172
+ g_critical (" %s" , err->message );
173
+ g_error_free (err);
174
+ }
169
175
}
170
176
/* we changed bookmarks list, let inform who interested in that */
171
177
Q_EMIT changed ();
172
178
}
173
179
174
- void Bookmarks::load () {
175
- auto fpath = file_ .localPath ();
180
+ void Bookmarks::load (const FilePath& path ) {
181
+ auto fpath = path .localPath ();
176
182
FILE* f;
177
183
char buf[1024 ];
178
184
/* load the file */
@@ -205,7 +211,7 @@ void Bookmarks::load() {
205
211
void Bookmarks::onFileChanged (GFileMonitor* /* mon*/ , GFile* /* gf*/ , GFile* /* other*/ , GFileMonitorEvent /* evt*/ ) {
206
212
// reload the bookmarks
207
213
items_.clear ();
208
- load ();
214
+ load (file_ );
209
215
Q_EMIT changed ();
210
216
}
211
217
0 commit comments