Skip to content

Commit ca88a5f

Browse files
committed
Use our own bookmarks file
The new file is `~/.local/share/libfm-qt/bookmarks`. If it doesn't exist or is empty, as soon as a libfm-qt based app is launched, the GTK3 file `~/.config/gtk-3.0/bookmarks` will be consulted for backward compatibility, then the new file will be created and the GTK3 file will be ignored. Closes #1009 NOTE: The portal file dialogs will see the change after a reboot (or after restarting user portal services).
1 parent d186be4 commit ca88a5f

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

src/core/bookmarks.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ namespace Fm {
99
std::weak_ptr<Bookmarks> Bookmarks::globalInstance_;
1010

1111
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)};
1313
}
1414

1515
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)};
1717
}
1818

1919
BookmarkItem::BookmarkItem(const FilePath& path, const QString name):
@@ -74,14 +74,17 @@ Bookmarks::Bookmarks(QObject* parent):
7474
QObject(parent),
7575
idle_handler{false} {
7676

77-
/* trying the gtk-3.0 first and use it if it exists */
77+
/* trying our config file first */
7878
auto fpath = get_new_bookmarks_file();
7979
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 */
8282
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+
}
8588
}
8689
mon = GObjectPtr<GFileMonitor>{g_file_monitor_file(file_.gfile().get(), G_FILE_MONITOR_NONE, nullptr, nullptr), false};
8790
if(mon) {
@@ -161,18 +164,21 @@ void Bookmarks::save() {
161164
}
162165
idle_handler = false;
163166
// 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+
}
169175
}
170176
/* we changed bookmarks list, let inform who interested in that */
171177
Q_EMIT changed();
172178
}
173179

174-
void Bookmarks::load() {
175-
auto fpath = file_.localPath();
180+
void Bookmarks::load(const FilePath& path) {
181+
auto fpath = path.localPath();
176182
FILE* f;
177183
char buf[1024];
178184
/* load the file */
@@ -205,7 +211,7 @@ void Bookmarks::load() {
205211
void Bookmarks::onFileChanged(GFileMonitor* /*mon*/, GFile* /*gf*/, GFile* /*other*/, GFileMonitorEvent /*evt*/) {
206212
// reload the bookmarks
207213
items_.clear();
208-
load();
214+
load(file_);
209215
Q_EMIT changed();
210216
}
211217

src/core/bookmarks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private Q_SLOTS:
6868
void save();
6969

7070
private:
71-
void load();
71+
void load(const FilePath& path);
7272
void queueSave();
7373

7474
static void _onFileChanged(GFileMonitor* mon, GFile* gf, GFile* other, GFileMonitorEvent evt, Bookmarks* _this) {

0 commit comments

Comments
 (0)