3
* Copyright (c) 2007 Diego Ongaro <ongardie@gmail.com>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU Library General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
#include "model_system.h"
25
#include "model_user.h"
28
#include <libxfce4util/libxfce4util.h>
29
#include <glib/gstdio.h>
32
#define bookmarks_user_dir_exists(path) g_file_test(path, G_FILE_TEST_IS_DIR)
40
const BookmarksSystem *system;
47
places_bookmarks_user_reinit(BookmarksUser *b)
50
// As of 2007-04-06, this is pretty much taken from/analogous to Thunar
58
fp = fopen(b->filename, "r");
60
if(G_UNLIKELY(fp == NULL)){
61
DBG("Error opening gtk bookmarks file");
65
while( fgets(line, sizeof(line), fp) != NULL )
67
/* strip leading/trailing whitespace */
70
/* skip over the URI */
71
for (name = line; *name != '\0' && !g_ascii_isspace (*name); ++name)
74
/* zero-terminate the URI */
77
/* check if we have a name */
78
for (; g_ascii_isspace (*name); ++name)
81
/* parse the URI */ // TODO: trash:// URI's
82
path = g_filename_from_uri(line, NULL, NULL);
83
if (G_UNLIKELY(path == NULL || *path == '\0'))
86
/* if we don't have a name, find it in the path */
88
name = g_filename_display_basename(path);
94
name = g_strdup(name);
97
/* create the BookmarkInfo container */
98
bi = g_new0(BookmarkInfo, 1);
101
bi->show = bookmarks_user_dir_exists(bi->uri);
102
bi->icon = g_strdup("gnome-fs-directory");
104
places_bookmarks_system_bi_system_mod((BookmarksSystem*) b->system, bi);
106
g_ptr_array_add(b->bookmarks, bi);
113
places_bookmarks_user_get_mtime(BookmarksUser *b)
116
if(g_stat(b->filename, &buf) == 0)
121
// external interface
124
places_bookmarks_user_init(const BookmarksSystem *system)
126
BookmarksUser *b = g_new0(BookmarksUser, 1);
128
g_assert(system != NULL);
131
b->filename = xfce_get_homefile(".gtk-bookmarks", NULL);
132
b->bookmarks = g_ptr_array_new();
133
b->loaded = places_bookmarks_user_get_mtime(b);
135
places_bookmarks_user_reinit(b);
140
places_bookmarks_user_changed(BookmarksUser *b)
142
// see if the file has changed
143
time_t mtime = places_bookmarks_user_get_mtime(b);
145
if(mtime > b->loaded){
146
g_ptr_array_free(b->bookmarks, TRUE);
147
b->bookmarks = g_ptr_array_new();
149
places_bookmarks_user_reinit(b);
153
// see if any directories have been created or removed
156
gboolean ret = FALSE;
158
for(k=0; k < b->bookmarks->len; k++){
159
bi = g_ptr_array_index(b->bookmarks, k);
160
if(bi->show != bookmarks_user_dir_exists(bi->uri)){
161
bi->show = !bi->show;
170
places_bookmarks_user_visit(BookmarksUser *b, BookmarksVisitor *visitor)
175
for(k=0; k < b->bookmarks->len; k++){
176
bi = g_ptr_array_index(b->bookmarks, k);
178
visitor->item(visitor->pass_thru, bi->label, bi->uri, bi->icon);
183
places_bookmarks_user_finalize(BookmarksUser *b)
185
g_ptr_array_free(b->bookmarks, TRUE);
196
// vim: ai et tabstop=4