annotate libaudacious/dirbrowser.c @ 2098:425963ded156 trunk

[svn] - provide the old ABI for plugins (intermediate layer). Pointed out by yaz, pointy hat to me.
author nenolod
date Mon, 11 Dec 2006 05:49:54 -0800
parents 2618fcfb3bcf
children f18a5b617c34
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2046
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
1 /* XMMS - Cross-platform multimedia player
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
2 * Copyright (C) 1998-2002 Peter Alm, Mikael Alm, Olle Hallnas,
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
3 * Thomas Nilsson and 4Front Technologies
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
4 * Copyright (C) 1999-2002 Haavard Kvaalen
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
5 *
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
9 * (at your option) any later version.
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
10 *
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
14 * GNU General Public License for more details.
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
15 *
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
19 */
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
20
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
21 #ifdef HAVE_CONFIG_H
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
22 # include "config.h"
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
23 #endif
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
24
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
25 #define GETTEXT_PACKAGE PACKAGE
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
26
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
27 #include <glib.h>
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
28 #include <glib/gi18n-lib.h>
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
29 #include <gtk/gtk.h>
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
30 #include <stdio.h>
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
31 #include <string.h>
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
32
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
33 #include <unistd.h>
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
34 #include <dirent.h>
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
35 #include <sys/types.h>
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
36 #include <sys/stat.h>
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
37
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
38
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
39 /* XPM */
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
40 static gchar *folder[] = {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
41 "16 16 16 1",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
42 " c None",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
43 ". c #f4f7e4",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
44 "X c #dee4b5",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
45 "o c #e1e7b9",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
46 "O c #c6cba4",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
47 "+ c #dce2b8",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
48 "@ c #e9e9ec",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
49 "# c #d3d8ae",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
50 "$ c #d8daca",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
51 "% c #b2b2b5",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
52 "& c #767862",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
53 "* c #e3e6c3",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
54 "= c #1b1b1a",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
55 "- c #939684",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
56 "; c #555555",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
57 ": c #000000",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
58 " ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
59 " ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
60 " :::: ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
61 " :.@@O: ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
62 ":-&&&&&::::: ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
63 ":.@@@@@*$O#O= ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
64 ":@*+XXXX+##O: ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
65 ":.*#oooXXXXX: ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
66 ":@+XoXXXXXX#: ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
67 ":@*ooXXXXXX#: ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
68 ":@**XXXXXXX#: ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
69 ":@*XXXXXXXX%: ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
70 ":$.*OOOOOO%-: ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
71 " ;::::::::::: ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
72 " ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
73 " "
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
74 };
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
75
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
76 /* Icon by Jakub Steiner <jimmac@ximian.com> */
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
77
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
78 /* XPM */
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
79 static gchar *ofolder[] = {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
80 "16 16 16 1",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
81 " c None",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
82 ". c #a9ad93",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
83 "X c #60634d",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
84 "o c #dee4b5",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
85 "O c #9ca085",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
86 "+ c #0c0d04",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
87 "@ c #2f2f31",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
88 "# c #3b3d2c",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
89 "$ c #c8cda2",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
90 "% c #e6e6e9",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
91 "& c #b3b5a5",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
92 "* c #80826d",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
93 "= c #292a1c",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
94 "- c #fefef6",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
95 "; c #8f937b",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
96 ": c #000000",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
97 " ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
98 " ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
99 " :::: ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
100 " :-%%&: ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
101 ":-;;;OX::::: ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
102 ":-;;;;O;O;&.: ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
103 ":-*X##@@@@@=#: ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
104 ":%*+-%%ooooooO: ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
105 ":%X;%ooooooo.*: ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
106 ":.+-%oooooooO: ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
107 ":*O-oooooooo*: ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
108 ":O-oooooooo.: ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
109 ":*-%$$$$$$OX: ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
110 " ::::::::::: ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
111 " ",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
112 " "
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
113 };
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
114
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
115 #define NODE_SPACING 4
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
116
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
117 typedef void (*db_handler_t) (char *);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
118
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
119 static GdkPixmap *folder_pixmap = NULL, *ofolder_pixmap;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
120 static GdkBitmap *folder_mask, *ofolder_mask;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
121
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
122 struct dirnode {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
123 guint scanned:1;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
124 gchar *path;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
125 };
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
126
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
127 static gboolean
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
128 check_for_subdir(gchar * path)
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
129 {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
130 DIR *dir;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
131 struct dirent *dirent;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
132 struct stat statbuf;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
133 gchar *npath;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
134
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
135 if ((dir = opendir(path)) != NULL) {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
136 while ((dirent = readdir(dir)) != NULL) {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
137 if (dirent->d_name[0] == '.')
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
138 continue;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
139
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
140 npath = g_strconcat(path, dirent->d_name, NULL);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
141 if (stat(npath, &statbuf) != -1 && S_ISDIR(statbuf.st_mode)) {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
142 g_free(npath);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
143 closedir(dir);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
144 return TRUE;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
145 }
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
146 g_free(npath);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
147 }
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
148 closedir(dir);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
149 }
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
150 return FALSE;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
151 }
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
152
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
153 static void
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
154 destroy_cb(gpointer data)
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
155 {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
156 struct dirnode *node = data;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
157
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
158 g_free(node->path);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
159 g_free(node);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
160 }
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
161
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
162 static void
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
163 add_dir(GtkCTree * tree, GtkCTreeNode * pnode, gchar * parent, gchar * dir)
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
164 {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
165 struct stat statbuf;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
166 gchar *path;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
167
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
168 /* Don't show hidden dirs, nor . and .. */
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
169 if (dir[0] == '.')
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
170 return;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
171
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
172 path = g_strconcat(parent, dir, NULL);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
173 if (stat(path, &statbuf) != -1 && S_ISDIR(statbuf.st_mode)) {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
174 gboolean has_subdir;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
175 gchar *text = "";
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
176 GtkCTreeNode *node;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
177 struct dirnode *dirnode = g_new0(struct dirnode, 1);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
178 dirnode->path = g_strconcat(path, "/", NULL);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
179 has_subdir = check_for_subdir(dirnode->path);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
180 node = gtk_ctree_insert_node(tree, pnode, NULL, &dir,
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
181 NODE_SPACING, folder_pixmap,
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
182 folder_mask, ofolder_pixmap,
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
183 ofolder_mask, !has_subdir, FALSE);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
184 gtk_ctree_node_set_row_data_full(tree, node, dirnode, destroy_cb);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
185 if (has_subdir)
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
186 gtk_ctree_insert_node(tree, node, NULL, &text,
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
187 NODE_SPACING, NULL, NULL,
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
188 NULL, NULL, FALSE, FALSE);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
189 }
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
190 g_free(path);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
191 }
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
192
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
193 static void
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
194 expand_cb(GtkWidget * widget, GtkCTreeNode * parent_node)
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
195 {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
196 struct dirent *dirent;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
197 GtkCTree *tree = GTK_CTREE(widget);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
198 struct dirnode *parent_dirnode;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
199
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
200 parent_dirnode = gtk_ctree_node_get_row_data(tree, parent_node);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
201 if (!parent_dirnode->scanned) {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
202 DIR *dir;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
203
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
204 gtk_clist_freeze(GTK_CLIST(widget));
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
205 gtk_ctree_remove_node(tree, GTK_CTREE_ROW(parent_node)->children);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
206 if ((dir = opendir(parent_dirnode->path)) != NULL) {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
207 while ((dirent = readdir(dir)) != NULL) {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
208 add_dir(tree, parent_node,
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
209 parent_dirnode->path, dirent->d_name);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
210 }
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
211 closedir(dir);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
212 gtk_ctree_sort_node(tree, parent_node);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
213 }
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
214 gtk_clist_thaw(GTK_CLIST(widget));
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
215 parent_dirnode->scanned = TRUE;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
216 }
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
217 }
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
218
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
219 static void
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
220 select_row_cb(GtkWidget * widget, gint row, gint column,
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
221 GdkEventButton * bevent, gpointer data)
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
222 {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
223 struct dirnode *dirnode;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
224 GtkCTreeNode *node;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
225 db_handler_t handler;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
226
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
227 if (bevent && bevent->type == GDK_2BUTTON_PRESS) {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
228 node = gtk_ctree_node_nth(GTK_CTREE(widget), row);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
229 dirnode = gtk_ctree_node_get_row_data(GTK_CTREE(widget), node);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
230 handler = (db_handler_t) gtk_object_get_user_data(GTK_OBJECT(widget));
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
231 if (handler)
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
232 handler(dirnode->path);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
233 }
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
234 }
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
235
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
236 static void
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
237 show_cb(GtkWidget * widget, gpointer data)
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
238 {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
239 GtkCTree *tree = GTK_CTREE(data);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
240 GtkCTreeNode *node = gtk_object_get_data(GTK_OBJECT(tree),
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
241 "selected_node");
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
242
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
243 if (node)
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
244 gtk_ctree_node_moveto(tree, node, -1, 0.6, 0);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
245 }
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
246
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
247 static void
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
248 ok_clicked(GtkWidget * widget, GtkWidget * tree)
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
249 {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
250 GtkCTreeNode *node;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
251 struct dirnode *dirnode;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
252 GList *list_node;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
253 GtkWidget *window;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
254 db_handler_t handler;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
255
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
256 window = gtk_object_get_user_data(GTK_OBJECT(widget));
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
257 gtk_widget_hide(window);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
258 list_node = GTK_CLIST(tree)->selection;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
259 while (list_node) {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
260 node = list_node->data;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
261 dirnode = gtk_ctree_node_get_row_data(GTK_CTREE(tree), node);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
262 handler = (db_handler_t) gtk_object_get_user_data(GTK_OBJECT(tree));
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
263 if (handler)
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
264 handler(dirnode->path);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
265 list_node = g_list_next(list_node);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
266 }
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
267 gtk_widget_destroy(window);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
268
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
269 }
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
270
2058
2618fcfb3bcf [svn] - a directory browser widget
nenolod
parents: 2046
diff changeset
271 /**
2618fcfb3bcf [svn] - a directory browser widget
nenolod
parents: 2046
diff changeset
272 * xmms_create_dir_browser:
2618fcfb3bcf [svn] - a directory browser widget
nenolod
parents: 2046
diff changeset
273 * @title: The title of the dir browser.
2618fcfb3bcf [svn] - a directory browser widget
nenolod
parents: 2046
diff changeset
274 * @current_path: The path that the dir browser should represent.
2618fcfb3bcf [svn] - a directory browser widget
nenolod
parents: 2046
diff changeset
275 * @mode: The GtkSelectionMode that should be used.
2618fcfb3bcf [svn] - a directory browser widget
nenolod
parents: 2046
diff changeset
276 * @handler: A handler to execute upon a selection.
2618fcfb3bcf [svn] - a directory browser widget
nenolod
parents: 2046
diff changeset
277 *
2618fcfb3bcf [svn] - a directory browser widget
nenolod
parents: 2046
diff changeset
278 * Creates a directory browser.
2618fcfb3bcf [svn] - a directory browser widget
nenolod
parents: 2046
diff changeset
279 *
2618fcfb3bcf [svn] - a directory browser widget
nenolod
parents: 2046
diff changeset
280 * Return value: A GtkWidget containing the directory browser.
2618fcfb3bcf [svn] - a directory browser widget
nenolod
parents: 2046
diff changeset
281 **/
2046
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
282 GtkWidget *
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
283 xmms_create_dir_browser(gchar * title, gchar * current_path,
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
284 GtkSelectionMode mode, void (*handler) (gchar *))
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
285 {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
286 GtkWidget *window, *scroll_win, *tree, *vbox, *bbox, *ok, *cancel, *sep;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
287 gchar *root_text = "/", *text = "";
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
288 GtkCTreeNode *root_node, *node, *selected_node = NULL;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
289 GtkCTree *ctree;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
290 struct dirnode *dirnode;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
291
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
292 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
293 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
294 gtk_window_set_title(GTK_WINDOW(window), title);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
295 gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
296 gtk_container_border_width(GTK_CONTAINER(window), 10);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
297
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
298 vbox = gtk_vbox_new(FALSE, 10);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
299 gtk_container_add(GTK_CONTAINER(window), vbox);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
300
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
301 scroll_win = gtk_scrolled_window_new(NULL, NULL);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
302 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_win),
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
303 GTK_POLICY_AUTOMATIC,
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
304 GTK_POLICY_AUTOMATIC);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
305 gtk_widget_set_usize(scroll_win, 450, 400);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
306 gtk_box_pack_start(GTK_BOX(vbox), scroll_win, TRUE, TRUE, 0);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
307 gtk_widget_show(scroll_win);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
308
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
309 gtk_widget_realize(window);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
310 if (!folder_pixmap) {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
311 folder_pixmap = gdk_pixmap_create_from_xpm_d(window->window,
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
312 &folder_mask,
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
313 NULL, folder);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
314 ofolder_pixmap = gdk_pixmap_create_from_xpm_d(window->window,
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
315 &ofolder_mask,
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
316 NULL, ofolder);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
317 }
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
318
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
319 tree = gtk_ctree_new(1, 0);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
320 ctree = GTK_CTREE(tree);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
321 gtk_clist_set_column_auto_resize(GTK_CLIST(tree), 0, TRUE);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
322 gtk_clist_set_selection_mode(GTK_CLIST(tree), mode);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
323 gtk_ctree_set_line_style(ctree, GTK_CTREE_LINES_DOTTED);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
324 g_signal_connect(G_OBJECT(tree), "tree_expand",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
325 G_CALLBACK(expand_cb), NULL);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
326 g_signal_connect(G_OBJECT(tree), "select_row",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
327 G_CALLBACK(select_row_cb), NULL);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
328 g_signal_connect(G_OBJECT(window), "show", G_CALLBACK(show_cb), tree);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
329 gtk_container_add(GTK_CONTAINER(scroll_win), tree);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
330 gtk_object_set_user_data(GTK_OBJECT(tree), (void *) handler);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
331
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
332 root_node = gtk_ctree_insert_node(ctree, NULL, NULL,
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
333 &root_text, NODE_SPACING,
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
334 folder_pixmap, folder_mask,
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
335 ofolder_pixmap, ofolder_mask,
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
336 FALSE, FALSE);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
337 dirnode = g_new0(struct dirnode, 1);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
338 dirnode->path = g_strdup(G_DIR_SEPARATOR_S);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
339 gtk_ctree_node_set_row_data_full(ctree, root_node, dirnode, destroy_cb);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
340 node = gtk_ctree_insert_node(ctree, root_node, NULL,
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
341 &text, 4, NULL, NULL, NULL,
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
342 NULL, TRUE, TRUE);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
343 gtk_ctree_expand(ctree, root_node);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
344 gtk_widget_show(tree);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
345
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
346 sep = gtk_hseparator_new();
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
347 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
348 gtk_widget_show(sep);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
349
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
350 bbox = gtk_hbutton_box_new();
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
351 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
352 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
353
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
354 ok = gtk_button_new_from_stock(GTK_STOCK_OK);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
355 gtk_object_set_user_data(GTK_OBJECT(ok), window);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
356 GTK_WIDGET_SET_FLAGS(ok, GTK_CAN_DEFAULT);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
357 gtk_window_set_default(GTK_WINDOW(window), ok);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
358 gtk_box_pack_start(GTK_BOX(bbox), ok, TRUE, TRUE, 0);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
359 g_signal_connect(G_OBJECT(ok), "clicked", G_CALLBACK(ok_clicked), tree);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
360 gtk_widget_show(ok);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
361
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
362 cancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
363 GTK_WIDGET_SET_FLAGS(cancel, GTK_CAN_DEFAULT);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
364 gtk_box_pack_start(GTK_BOX(bbox), cancel, TRUE, TRUE, 0);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
365 g_signal_connect_swapped(G_OBJECT(cancel), "clicked",
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
366 G_CALLBACK(gtk_widget_destroy),
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
367 GTK_OBJECT(window));
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
368 gtk_widget_show(cancel);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
369
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
370 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
371 gtk_widget_show(bbox);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
372 gtk_widget_show(vbox);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
373
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
374 if (current_path && *current_path) {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
375 gchar **dir;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
376 gint i;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
377
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
378 dir = g_strsplit(current_path, G_DIR_SEPARATOR_S, 0);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
379 node = root_node;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
380 for (i = 0; dir[i] != NULL; i++) {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
381 if (dir[i][0] == '\0')
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
382 continue;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
383
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
384 for (node = GTK_CTREE_ROW(node)->children; node != NULL;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
385 node = GTK_CTREE_ROW(node)->sibling) {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
386 gchar *tmp;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
387 if (gtk_ctree_node_get_pixtext(ctree, node, 0,
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
388 &tmp, NULL, NULL, NULL))
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
389 if (!strcmp(dir[i], tmp))
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
390 break;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
391 }
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
392 if (!node)
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
393 break;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
394 if (!GTK_CTREE_ROW(node)->is_leaf && dir[i + 1])
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
395 gtk_ctree_expand(ctree, node);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
396 else {
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
397 selected_node = node;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
398 break;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
399 }
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
400 }
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
401 g_strfreev(dir);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
402 }
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
403
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
404 if (!selected_node)
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
405 selected_node = root_node;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
406
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
407 gtk_ctree_select(ctree, selected_node);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
408 gtk_object_set_data(GTK_OBJECT(tree), "selected_node", selected_node);
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
409
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
410 return window;
456c74b6880a [svn] - bleah, put dirbrowser back
nenolod
parents:
diff changeset
411 }