annotate libaudacious/dirbrowser.c @ 2159:35bdfcd17ba7 trunk

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