annotate finch/libgnt/gntfilesel.c @ 25617:5e657957999e

We're a bit slow, bump release dates
author Ethan Blanton <elb@pidgin.im>
date Tue, 19 May 2009 17:46:50 +0000
parents e2e57d3c0578
children 89644e8d4323
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17928
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16203
diff changeset
1 /**
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16203
diff changeset
2 * GNT - The GLib Ncurses Toolkit
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16203
diff changeset
3 *
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16203
diff changeset
4 * GNT is the legal property of its developers, whose names are too numerous
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16203
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16203
diff changeset
6 * source distribution.
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16203
diff changeset
7 *
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16203
diff changeset
8 * This library is free software; you can redistribute it and/or modify
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16203
diff changeset
9 * it under the terms of the GNU General Public License as published by
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16203
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16203
diff changeset
11 * (at your option) any later version.
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16203
diff changeset
12 *
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16203
diff changeset
13 * This program is distributed in the hope that it will be useful,
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16203
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16203
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16203
diff changeset
16 * GNU General Public License for more details.
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16203
diff changeset
17 *
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16203
diff changeset
18 * You should have received a copy of the GNU General Public License
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16203
diff changeset
19 * along with this program; if not, write to the Free Software
19681
44b4e8bd759b The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19378
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
17928
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16203
diff changeset
21 */
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16203
diff changeset
22
24558
e2e57d3c0578 Use glib log functions to show error messages.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22289
diff changeset
23 #include "gntinternal.h"
e2e57d3c0578 Use glib log functions to show error messages.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22289
diff changeset
24 #undef GNT_LOG_DOMAIN
e2e57d3c0578 Use glib log functions to show error messages.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22289
diff changeset
25 #define GNT_LOG_DOMAIN "FileSel"
e2e57d3c0578 Use glib log functions to show error messages.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22289
diff changeset
26
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
27 #include "gntbutton.h"
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
28 #include "gntentry.h"
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
29 #include "gntfilesel.h"
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
30 #include "gntlabel.h"
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
31 #include "gntmarshal.h"
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
32 #include "gntstyle.h"
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
33 #include "gnttree.h"
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
34
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
35 #include <string.h>
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
36 #include <sys/types.h>
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
37 #include <sys/stat.h>
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
38 #include <unistd.h>
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
39
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
40 #if 0
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
41 #include <glob.h>
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
42 #endif
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
43
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
44 enum
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
45 {
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
46 SIG_FILE_SELECTED,
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
47 SIGS
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
48 };
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
49
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
50 static GntWindowClass *parent_class = NULL;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
51 static guint signals[SIGS] = { 0 };
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
52 static void (*orig_map)(GntWidget *widget);
18200
4ea95c55e771 The file-selector needs to be a bit taller.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17928
diff changeset
53 static void (*orig_size_request)(GntWidget *widget);
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
54
18556
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
55 static void select_activated_cb(GntWidget *button, GntFileSel *sel);
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
56
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
57 static void
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
58 gnt_file_sel_destroy(GntWidget *widget)
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
59 {
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
60 GntFileSel *sel = GNT_FILE_SEL(widget);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
61 g_free(sel->current);
15936
0f1ab43db297 fix file saving
Richard Nelson <wabz@pidgin.im>
parents: 15927
diff changeset
62 g_free(sel->suggest);
15923
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
63 if (sel->tags) {
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
64 g_list_foreach(sel->tags, (GFunc)g_free, NULL);
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
65 g_list_free(sel->tags);
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
66 }
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
67 }
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
68
15992
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
69 #if !GLIB_CHECK_VERSION(2,8,0)
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
70 /* ripped from glib/gfileutils.c */
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
71 static gchar *
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
72 g_build_path_va (const gchar *separator,
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
73 gchar **str_array)
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
74 {
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
75 GString *result;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
76 gint separator_len = strlen (separator);
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
77 gboolean is_first = TRUE;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
78 gboolean have_leading = FALSE;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
79 const gchar *single_element = NULL;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
80 const gchar *next_element;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
81 const gchar *last_trailing = NULL;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
82 gint i = 0;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
83
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
84 result = g_string_new (NULL);
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
85
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
86 next_element = str_array[i++];
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
87
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
88 while (TRUE) {
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
89 const gchar *element;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
90 const gchar *start;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
91 const gchar *end;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
92
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
93 if (next_element) {
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
94 element = next_element;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
95 next_element = str_array[i++];
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
96 } else
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
97 break;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
98
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
99 /* Ignore empty elements */
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
100 if (!*element)
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
101 continue;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
102
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
103 start = element;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
104
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
105 if (separator_len) {
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
106 while (start &&
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
107 strncmp (start, separator, separator_len) == 0)
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
108 start += separator_len;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
109 }
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
110
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
111 end = start + strlen (start);
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
112
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
113 if (separator_len) {
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
114 while (end >= start + separator_len &&
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
115 strncmp (end - separator_len, separator, separator_len) == 0)
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
116 end -= separator_len;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
117
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
118 last_trailing = end;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
119 while (last_trailing >= element + separator_len &&
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
120 strncmp (last_trailing - separator_len, separator, separator_len) == 0)
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
121 last_trailing -= separator_len;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
122
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
123 if (!have_leading) {
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
124 /* If the leading and trailing separator strings are in the
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
125 * same element and overlap, the result is exactly that element
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
126 */
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
127 if (last_trailing <= start)
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
128 single_element = element;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
129
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
130 g_string_append_len (result, element, start - element);
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
131 have_leading = TRUE;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
132 } else
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
133 single_element = NULL;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
134 }
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
135
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
136 if (end == start)
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
137 continue;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
138
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
139 if (!is_first)
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
140 g_string_append (result, separator);
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
141
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
142 g_string_append_len (result, start, end - start);
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
143 is_first = FALSE;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
144 }
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
145
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
146 if (single_element) {
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
147 g_string_free (result, TRUE);
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
148 return g_strdup (single_element);
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
149 } else {
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
150 if (last_trailing)
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
151 g_string_append (result, last_trailing);
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
152
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
153 return g_string_free (result, FALSE);
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
154 }
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
155 }
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
156
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
157 static gchar *
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
158 g_build_pathv (const gchar *separator,
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
159 gchar **args)
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
160 {
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
161 if (!args)
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
162 return NULL;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
163
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
164 return g_build_path_va (separator, args);
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
165 }
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
166
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
167 #endif
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
168
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
169 static char *
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
170 process_path(const char *path)
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
171 {
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
172 char **splits = NULL;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
173 int i, j;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
174 char *str, *ret;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
175
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
176 splits = g_strsplit(path, G_DIR_SEPARATOR_S, -1);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
177 for (i = 0, j = 0; splits[i]; i++) {
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
178 if (strcmp(splits[i], ".") == 0) {
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
179 } else if (strcmp(splits[i], "..") == 0) {
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
180 if (j)
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
181 j--;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
182 } else {
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
183 if (i != j) {
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
184 g_free(splits[j]);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
185 splits[j] = splits[i];
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
186 splits[i] = NULL;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
187 }
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
188 j++;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
189 }
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
190 }
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
191 g_free(splits[j]);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
192 splits[j] = NULL;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
193 str = g_build_pathv(G_DIR_SEPARATOR_S, splits);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
194 ret = g_strdup_printf(G_DIR_SEPARATOR_S "%s", str);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
195 g_free(str);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
196 g_strfreev(splits);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
197 return ret;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
198 }
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
199
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
200 static void
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
201 update_location(GntFileSel *sel)
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
202 {
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
203 char *old;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
204 const char *tmp;
15936
0f1ab43db297 fix file saving
Richard Nelson <wabz@pidgin.im>
parents: 15927
diff changeset
205 tmp = sel->suggest ? sel->suggest :
0f1ab43db297 fix file saving
Richard Nelson <wabz@pidgin.im>
parents: 15927
diff changeset
206 (const char*)gnt_tree_get_selection_data(sel->dirsonly ? GNT_TREE(sel->dirs) : GNT_TREE(sel->files));
19378
70a3aa1f2dd5 Fix #2599. (Sound File Change Crash)
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18868
diff changeset
207 old = g_strdup_printf("%s%s%s", SAFE(sel->current), SAFE(sel->current)[1] ? G_DIR_SEPARATOR_S : "", tmp ? tmp : "");
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
208 gnt_entry_set_text(GNT_ENTRY(sel->location), old);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
209 g_free(old);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
210 }
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
211
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
212 static gboolean
15923
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
213 is_tagged(GntFileSel *sel, const char *f)
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
214 {
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
215 char *ret = g_strdup_printf("%s%s%s", sel->current, sel->current[1] ? G_DIR_SEPARATOR_S : "", f);
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
216 gboolean find = g_list_find_custom(sel->tags, ret, (GCompareFunc)g_utf8_collate) != NULL;
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
217 g_free(ret);
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
218 return find;
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
219 }
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
220
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
221 GntFile* gnt_file_new_dir(const char *name)
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
222 {
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
223 GntFile *file = g_new0(GntFile, 1);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
224 file->basename = g_strdup(name);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
225 file->type = GNT_FILE_DIR;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
226 return file;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
227 }
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
228
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
229 GntFile* gnt_file_new(const char *name, unsigned long size)
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
230 {
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
231 GntFile *file = g_new0(GntFile, 1);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
232 file->basename = g_strdup(name);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
233 file->type = GNT_FILE_REGULAR;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
234 file->size = size;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
235 return file;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
236 }
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
237
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
238 static gboolean
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
239 local_read_fn(const char *path, GList **files, GError **error)
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
240 {
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
241 GDir *dir;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
242 GntFile *file;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
243 const char *str;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
244
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
245 dir = g_dir_open(path, 0, error);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
246 if (dir == NULL || (error && *error)) {
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
247 return FALSE;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
248 }
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
249
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
250 *files = NULL;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
251 if (*path != '\0' && strcmp(path, G_DIR_SEPARATOR_S)) {
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
252 file = gnt_file_new_dir("..");
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
253 *files = g_list_prepend(*files, file);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
254 }
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
255
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
256 while ((str = g_dir_read_name(dir)) != NULL) {
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
257 char *fp = g_build_filename(path, str, NULL);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
258 struct stat st;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
259
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
260 if (stat(fp, &st)) {
24558
e2e57d3c0578 Use glib log functions to show error messages.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22289
diff changeset
261 gnt_warning("Error stating location %s", fp);
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
262 } else {
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
263 if (S_ISDIR(st.st_mode)) {
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
264 file = gnt_file_new_dir(str);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
265 } else {
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
266 file = gnt_file_new(str, (long)st.st_size);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
267 }
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
268 *files = g_list_prepend(*files, file);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
269 }
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
270 g_free(fp);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
271 }
20346
07c2e60026da applied changes from e9e74094baa29c6f5589385507221a2502b817fb
Luke Schierer <lschiere@pidgin.im>
parents: 19681
diff changeset
272 g_dir_close(dir);
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
273
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
274 *files = g_list_reverse(*files);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
275 return TRUE;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
276 }
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
277
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
278 static void
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
279 gnt_file_free(GntFile *file)
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
280 {
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
281 g_free(file->fullpath);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
282 g_free(file->basename);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
283 g_free(file);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
284 }
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
285
15923
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
286 static gboolean
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
287 location_changed(GntFileSel *sel, GError **err)
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
288 {
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
289 GList *files, *iter;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
290 gboolean success;
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
291
15848
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
292 if (!sel->dirs)
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
293 return TRUE;
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
294
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
295 gnt_tree_remove_all(GNT_TREE(sel->dirs));
15848
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
296 if (sel->files)
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
297 gnt_tree_remove_all(GNT_TREE(sel->files));
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
298 gnt_entry_set_text(GNT_ENTRY(sel->location), NULL);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
299 if (sel->current == NULL) {
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
300 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(sel), GNT_WIDGET_MAPPED))
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
301 gnt_widget_draw(GNT_WIDGET(sel));
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
302 return TRUE;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
303 }
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
304
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
305 /* XXX:\
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
306 * XXX: This is blocking.
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
307 * XXX:/
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
308 */
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
309 files = NULL;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
310 if (sel->read_fn)
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
311 success = sel->read_fn(sel->current, &files, err);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
312 else
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
313 success = local_read_fn(sel->current, &files, err);
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
314
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
315 if (!success || *err) {
24558
e2e57d3c0578 Use glib log functions to show error messages.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22289
diff changeset
316 gnt_warning("error opening location %s (%s)",
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
317 sel->current, *err ? (*err)->message : "reason unknown");
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
318 return FALSE;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
319 }
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
320
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
321 for (iter = files; iter; iter = iter->next) {
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
322 GntFile *file = iter->data;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
323 char *str = file->basename;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
324 if (file->type == GNT_FILE_DIR) {
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
325 gnt_tree_add_row_after(GNT_TREE(sel->dirs), g_strdup(str),
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
326 gnt_tree_create_row(GNT_TREE(sel->dirs), str), NULL, NULL);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
327 if (sel->multiselect && sel->dirsonly && is_tagged(sel, str))
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
328 gnt_tree_set_row_flags(GNT_TREE(sel->dirs), (gpointer)str, GNT_TEXT_FLAG_BOLD);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
329 } else if (!sel->dirsonly) {
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
330 char size[128];
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
331 snprintf(size, sizeof(size), "%ld", file->size);
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
332
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
333 gnt_tree_add_row_after(GNT_TREE(sel->files), g_strdup(str),
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
334 gnt_tree_create_row(GNT_TREE(sel->files), str, size, ""), NULL, NULL);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
335 if (sel->multiselect && is_tagged(sel, str))
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
336 gnt_tree_set_row_flags(GNT_TREE(sel->files), (gpointer)str, GNT_TEXT_FLAG_BOLD);
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
337 }
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
338 }
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
339 g_list_foreach(files, (GFunc)gnt_file_free, NULL);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
340 g_list_free(files);
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
341 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(sel), GNT_WIDGET_MAPPED))
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
342 gnt_widget_draw(GNT_WIDGET(sel));
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
343 return TRUE;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
344 }
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
345
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
346 static gboolean
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
347 dir_key_pressed(GntTree *tree, const char *key, GntFileSel *sel)
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
348 {
22289
0ba0f2804299 '\n' (ctrl-j) should behave similar to '\r' (ctrl-m). Fixes #4833.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21284
diff changeset
349 if (strcmp(key, "\r") == 0 || strcmp(key, "\n") == 0) {
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
350 char *str = g_strdup(gnt_tree_get_selection_data(tree));
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
351 char *path, *dir;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
352
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
353 if (!str)
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
354 return TRUE;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
355
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
356 path = g_build_filename(sel->current, str, NULL);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
357 dir = g_path_get_basename(sel->current);
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
358 if (!gnt_file_sel_set_current_location(sel, path)) {
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
359 gnt_tree_set_selected(tree, str);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
360 } else if (strcmp(str, "..") == 0) {
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
361 gnt_tree_set_selected(tree, dir);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
362 }
18868
d470282d49da Fix typeahead searching in the file-dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18556
diff changeset
363 gnt_bindable_perform_action_named(GNT_BINDABLE(tree), "end-search", NULL);
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
364 g_free(dir);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
365 g_free(str);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
366 g_free(path);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
367 return TRUE;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
368 }
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
369 return FALSE;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
370 }
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
371
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
372 static gboolean
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
373 location_key_pressed(GntTree *tree, const char *key, GntFileSel *sel)
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
374 {
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
375 char *path;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
376 char *str;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
377 #if 0
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
378 int count;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
379 glob_t gl;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
380 struct stat st;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
381 int glob_ret;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
382 #endif
22289
0ba0f2804299 '\n' (ctrl-j) should behave similar to '\r' (ctrl-m). Fixes #4833.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21284
diff changeset
383 if (strcmp(key, "\r") && strcmp(key, "\n"))
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
384 return FALSE;
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
385
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
386 str = (char*)gnt_entry_get_text(GNT_ENTRY(sel->location));
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
387 if (*str == G_DIR_SEPARATOR)
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
388 path = g_strdup(str);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
389 else
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
390 path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", sel->current, str);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
391 str = process_path(path);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
392 g_free(path);
15992
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
393 path = str;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
394
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
395 if (gnt_file_sel_set_current_location(sel, path))
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
396 goto success;
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
397
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
398 path = g_path_get_dirname(str);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
399 g_free(str);
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
400
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
401 if (!gnt_file_sel_set_current_location(sel, path)) {
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
402 g_free(path);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
403 return FALSE;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
404 }
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
405 #if 0
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
406 /* XXX: there needs to be a way to allow other methods for globbing,
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
407 * like the read_fn stuff. */
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
408 glob_ret = glob(path, GLOB_MARK, NULL, &gl);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
409 if (!glob_ret) { /* XXX: do something with the return value */
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
410 char *loc = g_path_get_dirname(gl.gl_pathv[0]);
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
411
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
412 stat(gl.gl_pathv[0], &st);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
413 gnt_file_sel_set_current_location(sel, loc); /* XXX: check the return value */
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
414 g_free(loc);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
415 if (!S_ISDIR(st.st_mode) && !sel->dirsonly) {
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
416 gnt_tree_remove_all(GNT_TREE(sel->files));
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
417 for (count = 0; count < gl.gl_pathc; count++) {
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
418 char *tmp = process_path(gl.gl_pathv[count]);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
419 loc = g_path_get_dirname(tmp);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
420 if (g_utf8_collate(sel->current, loc) == 0) {
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
421 char *base = g_path_get_basename(tmp);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
422 char size[128];
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
423 snprintf(size, sizeof(size), "%ld", (long)st.st_size);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
424 gnt_tree_add_row_after(GNT_TREE(sel->files), base,
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
425 gnt_tree_create_row(GNT_TREE(sel->files), base, size, ""), NULL, NULL);
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
426 }
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
427 g_free(loc);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
428 g_free(tmp);
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
429 }
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
430 gnt_widget_draw(sel->files);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
431 }
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
432 } else if (sel->files) {
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
433 gnt_tree_remove_all(GNT_TREE(sel->files));
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
434 gnt_widget_draw(sel->files);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
435 }
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
436 globfree(&gl);
15992
e78b15c2c60f "elb: g_build_pathv is Glib 2.8"
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15988
diff changeset
437 #endif
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
438 success:
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
439 g_free(path);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
440 return TRUE;
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
441 }
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
442
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
443 static void
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
444 file_sel_changed(GntWidget *widget, gpointer old, gpointer current, GntFileSel *sel)
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
445 {
16203
4f6a6443a1e3 emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents: 15992
diff changeset
446 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_HAS_FOCUS)) {
4f6a6443a1e3 emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents: 15992
diff changeset
447 g_free(sel->suggest);
4f6a6443a1e3 emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents: 15992
diff changeset
448 sel->suggest = NULL;
4f6a6443a1e3 emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents: 15992
diff changeset
449 update_location(sel);
4f6a6443a1e3 emit/handle gnttree signals appropriately
Richard Nelson <wabz@pidgin.im>
parents: 15992
diff changeset
450 }
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
451 }
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
452
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
453 static void
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
454 gnt_file_sel_map(GntWidget *widget)
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
455 {
15848
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
456 GntFileSel *sel = GNT_FILE_SEL(widget);
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
457 GntWidget *hbox, *vbox;
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
458
18434
2bf8792760fe Fix #2034.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18200
diff changeset
459 if (sel->current == NULL)
2bf8792760fe Fix #2034.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18200
diff changeset
460 gnt_file_sel_set_current_location(sel, g_get_home_dir());
2bf8792760fe Fix #2034.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18200
diff changeset
461
15848
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
462 vbox = gnt_vbox_new(FALSE);
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
463 gnt_box_set_pad(GNT_BOX(vbox), 0);
15923
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
464 gnt_box_set_alignment(GNT_BOX(vbox), GNT_ALIGN_MID);
15848
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
465
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
466 /* The dir. and files list */
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
467 hbox = gnt_hbox_new(FALSE);
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
468 gnt_box_set_pad(GNT_BOX(hbox), 0);
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
469
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
470 gnt_box_add_widget(GNT_BOX(hbox), sel->dirs);
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
471
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
472 if (!sel->dirsonly) {
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
473 gnt_box_add_widget(GNT_BOX(hbox), sel->files);
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
474 } else {
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
475 g_signal_connect(G_OBJECT(sel->dirs), "selection_changed", G_CALLBACK(file_sel_changed), sel);
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
476 }
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
477
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
478 gnt_box_add_widget(GNT_BOX(vbox), hbox);
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
479 gnt_box_add_widget(GNT_BOX(vbox), sel->location);
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
480
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
481 /* The buttons */
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
482 hbox = gnt_hbox_new(FALSE);
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
483 gnt_box_add_widget(GNT_BOX(hbox), sel->cancel);
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
484 gnt_box_add_widget(GNT_BOX(hbox), sel->select);
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
485 gnt_box_add_widget(GNT_BOX(vbox), hbox);
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
486
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
487 gnt_box_add_widget(GNT_BOX(sel), vbox);
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
488 orig_map(widget);
15848
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
489 update_location(sel);
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
490 }
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
491
15923
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
492 static gboolean
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
493 toggle_tag_selection(GntBindable *bind, GList *null)
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
494 {
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
495 GntFileSel *sel = GNT_FILE_SEL(bind);
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
496 char *str;
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
497 GList *find;
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
498 char *file;
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
499 GntWidget *tree;
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
500
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
501 if (!sel->multiselect)
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
502 return FALSE;
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
503 tree = sel->dirsonly ? sel->dirs : sel->files;
18868
d470282d49da Fix typeahead searching in the file-dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18556
diff changeset
504 if (!gnt_widget_has_focus(tree) ||
d470282d49da Fix typeahead searching in the file-dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18556
diff changeset
505 gnt_tree_is_searching(GNT_TREE(tree)))
15923
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
506 return FALSE;
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
507
18868
d470282d49da Fix typeahead searching in the file-dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18556
diff changeset
508 file = gnt_tree_get_selection_data(GNT_TREE(tree));
15923
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
509
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
510 str = gnt_file_sel_get_selected_file(sel);
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
511 if ((find = g_list_find_custom(sel->tags, str, (GCompareFunc)g_utf8_collate)) != NULL) {
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
512 g_free(find->data);
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
513 sel->tags = g_list_delete_link(sel->tags, find);
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
514 gnt_tree_set_row_flags(GNT_TREE(tree), file, GNT_TEXT_FLAG_NORMAL);
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
515 g_free(str);
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
516 } else {
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
517 sel->tags = g_list_prepend(sel->tags, str);
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
518 gnt_tree_set_row_flags(GNT_TREE(tree), file, GNT_TEXT_FLAG_BOLD);
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
519 }
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
520
15952
0ef26ac647ac move to the next entry after (un)tagging an item.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15936
diff changeset
521 gnt_bindable_perform_action_named(GNT_BINDABLE(tree), "move-down", NULL);
0ef26ac647ac move to the next entry after (un)tagging an item.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15936
diff changeset
522
15923
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
523 return TRUE;
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
524 }
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
525
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
526 static gboolean
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
527 clear_tags(GntBindable *bind, GList *null)
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
528 {
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
529 GntFileSel *sel = GNT_FILE_SEL(bind);
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
530 GntWidget *tree;
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
531 GList *iter;
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
532
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
533 if (!sel->multiselect)
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
534 return FALSE;
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
535 tree = sel->dirsonly ? sel->dirs : sel->files;
18868
d470282d49da Fix typeahead searching in the file-dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18556
diff changeset
536 if (!gnt_widget_has_focus(tree) ||
d470282d49da Fix typeahead searching in the file-dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18556
diff changeset
537 gnt_tree_is_searching(GNT_TREE(tree)))
15923
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
538 return FALSE;
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
539
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
540 g_list_foreach(sel->tags, (GFunc)g_free, NULL);
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
541 g_list_free(sel->tags);
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
542 sel->tags = NULL;
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
543
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
544 for (iter = GNT_TREE(tree)->list; iter; iter = iter->next)
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
545 gnt_tree_set_row_flags(GNT_TREE(tree), iter->data, GNT_TEXT_FLAG_NORMAL);
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
546
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
547 return TRUE;
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
548 }
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
549
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
550 static gboolean
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
551 up_directory(GntBindable *bind, GList *null)
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
552 {
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
553 char *path, *dir;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
554 GntFileSel *sel = GNT_FILE_SEL(bind);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
555 if (!gnt_widget_has_focus(sel->dirs) &&
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
556 !gnt_widget_has_focus(sel->files))
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
557 return FALSE;
18868
d470282d49da Fix typeahead searching in the file-dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18556
diff changeset
558 if (gnt_tree_is_searching(GNT_TREE(sel->dirs)) ||
d470282d49da Fix typeahead searching in the file-dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18556
diff changeset
559 gnt_tree_is_searching(GNT_TREE(sel->files)))
d470282d49da Fix typeahead searching in the file-dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18556
diff changeset
560 return FALSE;
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
561
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
562 path = g_build_filename(sel->current, "..", NULL);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
563 dir = g_path_get_basename(sel->current);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
564 if (gnt_file_sel_set_current_location(sel, path))
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
565 gnt_tree_set_selected(GNT_TREE(sel->dirs), dir);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
566 g_free(dir);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
567 g_free(path);
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
568 return TRUE;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
569 }
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
570
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
571 static void
18200
4ea95c55e771 The file-selector needs to be a bit taller.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17928
diff changeset
572 gnt_file_sel_size_request(GntWidget *widget)
4ea95c55e771 The file-selector needs to be a bit taller.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17928
diff changeset
573 {
4ea95c55e771 The file-selector needs to be a bit taller.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17928
diff changeset
574 GntFileSel *sel;
4ea95c55e771 The file-selector needs to be a bit taller.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17928
diff changeset
575 if (widget->priv.height > 0)
4ea95c55e771 The file-selector needs to be a bit taller.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17928
diff changeset
576 return;
4ea95c55e771 The file-selector needs to be a bit taller.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17928
diff changeset
577
4ea95c55e771 The file-selector needs to be a bit taller.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17928
diff changeset
578 sel = GNT_FILE_SEL(widget);
4ea95c55e771 The file-selector needs to be a bit taller.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17928
diff changeset
579 sel->dirs->priv.height = 16;
4ea95c55e771 The file-selector needs to be a bit taller.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17928
diff changeset
580 sel->files->priv.height = 16;
4ea95c55e771 The file-selector needs to be a bit taller.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17928
diff changeset
581 orig_size_request(widget);
4ea95c55e771 The file-selector needs to be a bit taller.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17928
diff changeset
582 }
4ea95c55e771 The file-selector needs to be a bit taller.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17928
diff changeset
583
4ea95c55e771 The file-selector needs to be a bit taller.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17928
diff changeset
584 static void
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
585 gnt_file_sel_class_init(GntFileSelClass *klass)
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
586 {
15923
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
587 GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass);
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
588 GntWidgetClass *kl = GNT_WIDGET_CLASS(klass);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
589 parent_class = GNT_WINDOW_CLASS(klass);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
590 kl->destroy = gnt_file_sel_destroy;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
591 orig_map = kl->map;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
592 kl->map = gnt_file_sel_map;
18200
4ea95c55e771 The file-selector needs to be a bit taller.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17928
diff changeset
593 orig_size_request = kl->size_request;
4ea95c55e771 The file-selector needs to be a bit taller.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17928
diff changeset
594 kl->size_request = gnt_file_sel_size_request;
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
595
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
596 signals[SIG_FILE_SELECTED] =
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
597 g_signal_new("file_selected",
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
598 G_TYPE_FROM_CLASS(klass),
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
599 G_SIGNAL_RUN_LAST,
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
600 G_STRUCT_OFFSET(GntFileSelClass, file_selected),
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
601 NULL, NULL,
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
602 gnt_closure_marshal_VOID__STRING_STRING,
18451
7122bcebf7c9 Since we have the file-selected signal, we might as well emit it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18449
diff changeset
603 G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING);
15923
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
604
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
605 gnt_bindable_class_register_action(bindable, "toggle-tag", toggle_tag_selection, "t", NULL);
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
606 gnt_bindable_class_register_action(bindable, "clear-tags", clear_tags, "c", NULL);
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
607 gnt_bindable_class_register_action(bindable, "up-directory", up_directory, GNT_KEY_BACKSPACE, NULL);
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
608 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass));
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
609
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
610 GNTDEBUG;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
611 }
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
612
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
613 static void
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
614 gnt_file_sel_init(GTypeInstance *instance, gpointer class)
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
615 {
18556
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
616 GntFileSel *sel = GNT_FILE_SEL(instance);
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
617
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
618 sel->dirs = gnt_tree_new();
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
619 gnt_tree_set_compare_func(GNT_TREE(sel->dirs), (GCompareFunc)g_utf8_collate);
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
620 gnt_tree_set_hash_fns(GNT_TREE(sel->dirs), g_str_hash, g_str_equal, g_free);
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
621 gnt_tree_set_column_titles(GNT_TREE(sel->dirs), "Directories");
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
622 gnt_tree_set_show_title(GNT_TREE(sel->dirs), TRUE);
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
623 gnt_tree_set_col_width(GNT_TREE(sel->dirs), 0, 20);
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
624 g_signal_connect(G_OBJECT(sel->dirs), "key_pressed", G_CALLBACK(dir_key_pressed), sel);
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
625
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
626 sel->files = gnt_tree_new_with_columns(2); /* Name, Size */
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
627 gnt_tree_set_compare_func(GNT_TREE(sel->files), (GCompareFunc)g_utf8_collate);
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
628 gnt_tree_set_column_titles(GNT_TREE(sel->files), "Filename", "Size");
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
629 gnt_tree_set_show_title(GNT_TREE(sel->files), TRUE);
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
630 gnt_tree_set_col_width(GNT_TREE(sel->files), 0, 25);
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
631 gnt_tree_set_col_width(GNT_TREE(sel->files), 1, 10);
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
632 gnt_tree_set_column_is_right_aligned(GNT_TREE(sel->files), 1, TRUE);
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
633 g_signal_connect(G_OBJECT(sel->files), "selection_changed", G_CALLBACK(file_sel_changed), sel);
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
634
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
635 /* The location entry */
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
636 sel->location = gnt_entry_new(NULL);
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
637 g_signal_connect(G_OBJECT(sel->location), "key_pressed", G_CALLBACK(location_key_pressed), sel);
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
638
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
639 sel->cancel = gnt_button_new("Cancel");
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
640 sel->select = gnt_button_new("Select");
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
641
21277
cd494bf77723 Hitting enter on a file will trigger the 'select' button in the file selector dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21253
diff changeset
642 g_signal_connect_swapped(G_OBJECT(sel->files), "activate", G_CALLBACK(gnt_widget_activate), sel->select);
18556
5e1412f4e67a Do some work to make pygnt more useful. The dbus-gnt script works fairly
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18451
diff changeset
643 g_signal_connect(G_OBJECT(sel->select), "activate", G_CALLBACK(select_activated_cb), sel);
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
644 }
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
645
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
646 /******************************************************************************
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
647 * GntFileSel API
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
648 *****************************************************************************/
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
649 GType
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
650 gnt_file_sel_get_gtype(void)
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
651 {
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
652 static GType type = 0;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
653
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
654 if(type == 0)
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
655 {
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
656 static const GTypeInfo info = {
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
657 sizeof(GntFileSelClass),
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
658 NULL, /* base_init */
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
659 NULL, /* base_finalize */
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
660 (GClassInitFunc)gnt_file_sel_class_init,
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
661 NULL, /* class_finalize */
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
662 NULL, /* class_data */
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
663 sizeof(GntFileSel),
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
664 0, /* n_preallocs */
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
665 gnt_file_sel_init, /* instance_init */
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
666 NULL
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
667 };
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
668
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
669 type = g_type_register_static(GNT_TYPE_WINDOW,
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
670 "GntFileSel",
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
671 &info, 0);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
672 }
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
673
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
674 return type;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
675 }
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
676
18451
7122bcebf7c9 Since we have the file-selected signal, we might as well emit it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18449
diff changeset
677 static void
7122bcebf7c9 Since we have the file-selected signal, we might as well emit it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18449
diff changeset
678 select_activated_cb(GntWidget *button, GntFileSel *sel)
7122bcebf7c9 Since we have the file-selected signal, we might as well emit it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18449
diff changeset
679 {
7122bcebf7c9 Since we have the file-selected signal, we might as well emit it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18449
diff changeset
680 char *path = gnt_file_sel_get_selected_file(sel);
7122bcebf7c9 Since we have the file-selected signal, we might as well emit it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18449
diff changeset
681 char *file = g_path_get_basename(path);
7122bcebf7c9 Since we have the file-selected signal, we might as well emit it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18449
diff changeset
682 g_signal_emit(sel, signals[SIG_FILE_SELECTED], 0, path, file);
7122bcebf7c9 Since we have the file-selected signal, we might as well emit it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18449
diff changeset
683 g_free(file);
7122bcebf7c9 Since we have the file-selected signal, we might as well emit it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18449
diff changeset
684 g_free(path);
7122bcebf7c9 Since we have the file-selected signal, we might as well emit it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18449
diff changeset
685 }
7122bcebf7c9 Since we have the file-selected signal, we might as well emit it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18449
diff changeset
686
15909
0592a7b4db86 This was giving me a warning saying the function wasn't previously declared
Mark Doliner <mark@kingant.net>
parents: 15848
diff changeset
687 GntWidget *gnt_file_sel_new(void)
15846
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
688 {
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
689 GntWidget *widget = g_object_new(GNT_TYPE_FILE_SEL, NULL);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
690 return widget;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
691 }
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
692
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
693 gboolean gnt_file_sel_set_current_location(GntFileSel *sel, const char *path)
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
694 {
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
695 char *old;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
696 GError *error = NULL;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
697 gboolean ret = TRUE;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
698
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
699 old = sel->current;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
700 sel->current = process_path(path);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
701 if (!location_changed(sel, &error)) {
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
702 g_error_free(error);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
703 error = NULL;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
704 g_free(sel->current);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
705 sel->current = old;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
706 location_changed(sel, &error);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
707 ret = FALSE;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
708 } else
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
709 g_free(old);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
710
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
711 update_location(sel);
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
712 return ret;
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
713 }
a2ab257116ce File selector dialog. Still in an experimental state. When properly complete, this can be used for file/folder-request etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
714
15848
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
715 void gnt_file_sel_set_dirs_only(GntFileSel *sel, gboolean dirs)
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
716 {
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
717 sel->dirsonly = dirs;
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
718 }
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
719
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
720 gboolean gnt_file_sel_get_dirs_only(GntFileSel *sel)
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
721 {
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
722 return sel->dirsonly;
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
723 }
3da9d5da9054 Directory only selection.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15846
diff changeset
724
15936
0f1ab43db297 fix file saving
Richard Nelson <wabz@pidgin.im>
parents: 15927
diff changeset
725 void gnt_file_sel_set_suggested_filename(GntFileSel *sel, const char *suggest)
0f1ab43db297 fix file saving
Richard Nelson <wabz@pidgin.im>
parents: 15927
diff changeset
726 {
21161
e119edfc0fb0 applied changes from 172a59b41412c4630834d66f2e7ec3be970cc36b
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 20346
diff changeset
727 g_free(sel->suggest);
15936
0f1ab43db297 fix file saving
Richard Nelson <wabz@pidgin.im>
parents: 15927
diff changeset
728 sel->suggest = g_strdup(suggest);
0f1ab43db297 fix file saving
Richard Nelson <wabz@pidgin.im>
parents: 15927
diff changeset
729 }
0f1ab43db297 fix file saving
Richard Nelson <wabz@pidgin.im>
parents: 15927
diff changeset
730
15849
65b45106bfbb Use the file selector for request-file.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15848
diff changeset
731 char *gnt_file_sel_get_selected_file(GntFileSel *sel)
65b45106bfbb Use the file selector for request-file.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15848
diff changeset
732 {
65b45106bfbb Use the file selector for request-file.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15848
diff changeset
733 char *ret;
15936
0f1ab43db297 fix file saving
Richard Nelson <wabz@pidgin.im>
parents: 15927
diff changeset
734 if (sel->dirsonly) {
15964
8a54f74fecdf plug some leaks
Richard Nelson <wabz@pidgin.im>
parents: 15952
diff changeset
735 ret = g_path_get_dirname(gnt_entry_get_text(GNT_ENTRY(sel->location)));
15936
0f1ab43db297 fix file saving
Richard Nelson <wabz@pidgin.im>
parents: 15927
diff changeset
736 } else {
0f1ab43db297 fix file saving
Richard Nelson <wabz@pidgin.im>
parents: 15927
diff changeset
737 ret = g_strdup(gnt_entry_get_text(GNT_ENTRY(sel->location)));
0f1ab43db297 fix file saving
Richard Nelson <wabz@pidgin.im>
parents: 15927
diff changeset
738 }
15849
65b45106bfbb Use the file selector for request-file.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15848
diff changeset
739 return ret;
65b45106bfbb Use the file selector for request-file.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15848
diff changeset
740 }
65b45106bfbb Use the file selector for request-file.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15848
diff changeset
741
65b45106bfbb Use the file selector for request-file.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15848
diff changeset
742 void gnt_file_sel_set_must_exist(GntFileSel *sel, gboolean must)
65b45106bfbb Use the file selector for request-file.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15848
diff changeset
743 {
65b45106bfbb Use the file selector for request-file.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15848
diff changeset
744 /*XXX: What do I do with this? */
65b45106bfbb Use the file selector for request-file.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15848
diff changeset
745 sel->must_exist = must;
65b45106bfbb Use the file selector for request-file.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15848
diff changeset
746 }
65b45106bfbb Use the file selector for request-file.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15848
diff changeset
747
65b45106bfbb Use the file selector for request-file.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15848
diff changeset
748 gboolean gnt_file_sel_get_must_exist(GntFileSel *sel)
65b45106bfbb Use the file selector for request-file.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15848
diff changeset
749 {
65b45106bfbb Use the file selector for request-file.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15848
diff changeset
750 return sel->must_exist;
65b45106bfbb Use the file selector for request-file.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15848
diff changeset
751 }
65b45106bfbb Use the file selector for request-file.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15848
diff changeset
752
15923
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
753 void gnt_file_sel_set_multi_select(GntFileSel *sel, gboolean set)
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
754 {
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
755 sel->multiselect = set;
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
756 }
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
757
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
758 GList *gnt_file_sel_get_selected_multi_files(GntFileSel *sel)
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
759 {
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
760 GList *list = NULL, *iter;
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
761 char *str = gnt_file_sel_get_selected_file(sel);
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
762
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
763 for (iter = sel->tags; iter; iter = iter->next) {
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
764 list = g_list_prepend(list, g_strdup(iter->data));
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
765 if (g_utf8_collate(str, iter->data)) {
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
766 g_free(str);
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
767 str = NULL;
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
768 }
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
769 }
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
770 if (str)
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
771 list = g_list_prepend(list, str);
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
772 list = g_list_reverse(list);
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
773 return list;
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
774 }
f8c16848b76d Allow selecting multiple files from the file-select dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15922
diff changeset
775
15988
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
776 void gnt_file_sel_set_read_fn(GntFileSel *sel, gboolean (*read_fn)(const char *path, GList **files, GError **error))
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
777 {
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
778 sel->read_fn = read_fn;
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
779 }
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
780
e05e5b148723 Allow using different methods for reading directory entries.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15964
diff changeset
781