2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2020 the Claws Mail team and Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <glib/gi18n.h>
23 #include <gdk/gdkkeysyms.h>
29 #include <sys/types.h>
36 #include "stock_pixmap.h"
37 #include "foldersel.h"
38 #include "alertpanel.h"
39 #include "manage_window.h"
40 #include "folderview.h"
41 #include "inputdialog.h"
43 #include "prefs_common.h"
44 #include "folder_item_prefs.h"
50 FOLDERSEL_PIXBUF_OPEN
,
56 typedef struct _FolderItemSearch FolderItemSearch
;
58 struct _FolderItemSearch
65 static GdkPixbuf
*folder_pixbuf
= NULL
;
66 static GdkPixbuf
*folderopen_pixbuf
= NULL
;
67 static GdkPixbuf
*foldernoselect_pixbuf
= NULL
;
68 static GdkPixbuf
*foldernoselectopen_pixbuf
= NULL
;
70 static GtkWidget
*window
;
71 static GtkWidget
*treeview
;
72 static GtkWidget
*statusbar
;
73 static gint statusbar_cid
;
74 static GtkWidget
*ok_button
;
75 static GtkWidget
*cancel_button
;
76 static GtkWidget
*new_button
;
77 static gboolean root_selectable
;
79 static FolderItem
*folder_item
;
80 static FolderItem
*selected_item
;
82 static GtkTreeStore
*tree_store
;
84 static gboolean cancelled
;
85 static gboolean finished
;
87 static void foldersel_create (const gchar
*title
);
88 static void foldersel_init (void);
90 static void foldersel_append_item (GtkTreeStore
*store
,
95 static void foldersel_set_tree (Folder
*cur_folder
,
96 FolderSelectionType type
);
98 static gboolean
foldersel_selected (GtkTreeSelection
*selection
,
101 gboolean currently_selected
,
104 static void foldersel_ok (GtkButton
*button
,
106 static void foldersel_cancel (GtkButton
*button
,
108 static void foldersel_new_folder (GtkButton
*button
,
111 static void foldersel_entry_activated (GtkEntry
*entry
,
114 static void foldersel_tree_activated (GtkTreeView
*treeview
,
116 GtkTreeViewColumn
*column
,
119 static gint
delete_event (GtkWidget
*widget
,
122 static gboolean
key_pressed (GtkWidget
*widget
,
126 static gint
foldersel_folder_name_compare (GtkTreeModel
*model
,
131 static gboolean
tree_view_folder_item_func (GtkTreeModel
*model
,
134 FolderItemSearch
*data
);
136 FolderItem
*foldersel_folder_sel(Folder
*cur_folder
, FolderSelectionType type
,
137 const gchar
*default_folder
, gboolean can_sel_mailbox
,
140 selected_item
= NULL
;
141 root_selectable
= can_sel_mailbox
;
144 foldersel_create(title
);
148 foldersel_set_tree(cur_folder
, type
);
152 FolderItemSearch fis
;
154 fis
.item
= folder_item
;
157 /* find matching model entry */
158 gtk_tree_model_foreach
159 (GTK_TREE_MODEL(tree_store
),
160 (GtkTreeModelForeachFunc
)tree_view_folder_item_func
,
164 GtkTreeSelection
*selection
;
166 selection
= gtk_tree_view_get_selection
167 (GTK_TREE_VIEW(treeview
));
168 gtk_tree_selection_select_iter(selection
, &fis
.iter
);
169 gtk_tree_view_set_cursor(GTK_TREE_VIEW(treeview
),
170 fis
.path
, NULL
, FALSE
);
171 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(treeview
),
173 NULL
, TRUE
, 0.5, 0.0);
174 gtk_tree_path_free(fis
.path
);
176 gtk_tree_view_scroll_to_point
177 (GTK_TREE_VIEW(treeview
), 0, 0);
179 gtk_tree_view_scroll_to_point(GTK_TREE_VIEW(treeview
), 0, 0);
181 gtk_widget_grab_focus(ok_button
);
182 gtk_widget_grab_focus(treeview
);
184 gtk_window_present(GTK_WINDOW(window
));
185 manage_window_set_transient(GTK_WINDOW(window
));
186 gtk_window_set_modal(GTK_WINDOW(window
), TRUE
);
188 cancelled
= finished
= FALSE
;
190 while (finished
== FALSE
)
191 gtk_main_iteration();
193 gtk_widget_destroy(window
);
197 selected_item
&& (selected_item
->path
|| root_selectable
)) {
198 folder_item
= selected_item
;
204 static gboolean
foldersel_search_name_func(GtkTreeModel
*model
, gint column
,
205 const gchar
*key
, GtkTreeIter
*iter
, gpointer search_data
)
207 gchar
*store_string
= NULL
;
211 if (column
== FOLDERSEL_FOLDERNAME
) {
212 /* get the name of the FolderItem, not the displayed string */
213 gtk_tree_model_get(model
, iter
,
214 FOLDERSEL_FOLDERITEM
, &item
, -1);
215 store_string
= folder_item_get_name(item
);
217 gtk_tree_model_get(model
, iter
, column
, &store_string
, -1);
220 if (!store_string
|| !key
)
223 retval
= (strcasestr(store_string
, key
) == NULL
);
225 g_free(store_string
);
230 static void foldersel_size_allocate_cb(GtkWidget
*widget
,
231 GtkAllocation
*allocation
)
233 cm_return_if_fail(allocation
!= NULL
);
235 prefs_common
.folderselwin_width
= allocation
->width
;
236 prefs_common
.folderselwin_height
= allocation
->height
;
239 static void foldersel_create(const gchar
*title
)
242 GtkWidget
*scrolledwin
;
243 GtkWidget
*confirm_area
;
245 GtkTreeViewColumn
*column
;
246 GtkCellRenderer
*renderer
;
247 GtkTreeSelection
*selection
;
248 static GdkGeometry geometry
;
250 window
= gtkut_window_new(GTK_WINDOW_TOPLEVEL
, "foldersel");
251 gtk_window_set_title(GTK_WINDOW(window
),_("Select folder"));
252 gtk_container_set_border_width(GTK_CONTAINER(window
), 4);
253 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_CENTER
);
254 gtk_window_set_resizable(GTK_WINDOW(window
), TRUE
);
255 gtk_window_set_type_hint(GTK_WINDOW(window
), GDK_WINDOW_TYPE_HINT_DIALOG
);
257 gtk_widget_realize(window
);
258 g_signal_connect(G_OBJECT(window
), "delete_event",
259 G_CALLBACK(delete_event
), NULL
);
260 g_signal_connect(G_OBJECT(window
), "key_press_event",
261 G_CALLBACK(key_pressed
), NULL
);
262 g_signal_connect(G_OBJECT(window
), "size_allocate",
263 G_CALLBACK(foldersel_size_allocate_cb
), NULL
);
264 MANAGE_WINDOW_SIGNALS_CONNECT(window
);
266 vbox
= gtk_vbox_new(FALSE
, 4);
267 gtk_container_add(GTK_CONTAINER(window
), vbox
);
270 label
= gtk_label_new(title
);
271 gtk_label_set_line_wrap(GTK_LABEL(label
), TRUE
);
272 gtk_box_pack_start(GTK_BOX(vbox
), label
, FALSE
, FALSE
, 0);
275 scrolledwin
= gtk_scrolled_window_new(NULL
, NULL
);
276 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin
),
277 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
278 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin
),
280 gtk_box_pack_start(GTK_BOX(vbox
), scrolledwin
, TRUE
, TRUE
, 0);
282 tree_store
= gtk_tree_store_new(N_FOLDERSEL_COLUMNS
,
289 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(tree_store
),
290 FOLDERSEL_FOLDERNAME
,
291 foldersel_folder_name_compare
,
294 treeview
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(tree_store
));
295 g_object_unref(G_OBJECT(tree_store
));
296 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview
), FALSE
);
297 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview
),
298 prefs_common
.use_stripes_everywhere
);
299 gtk_tree_view_set_enable_tree_lines(GTK_TREE_VIEW(treeview
), FALSE
);
300 gtk_tree_view_set_search_column(GTK_TREE_VIEW(treeview
),
301 FOLDERSEL_FOLDERNAME
);
302 if (prefs_common
.folder_search_wildcard
)
303 gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(treeview
),
304 foldersel_search_name_func
, NULL
, NULL
);
306 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview
));
307 gtk_tree_selection_set_mode(selection
, GTK_SELECTION_BROWSE
);
308 gtk_tree_selection_set_select_function(selection
, foldersel_selected
,
311 g_signal_connect(G_OBJECT(treeview
), "row-activated",
312 G_CALLBACK(foldersel_tree_activated
), NULL
);
313 gtk_container_add(GTK_CONTAINER(scrolledwin
), treeview
);
315 column
= gtk_tree_view_column_new();
316 gtk_tree_view_column_set_spacing(column
, 2);
317 renderer
= gtk_cell_renderer_pixbuf_new();
318 gtk_tree_view_column_pack_start(column
, renderer
, FALSE
);
319 gtk_tree_view_column_set_attributes
321 "pixbuf", FOLDERSEL_PIXBUF
,
322 "pixbuf-expander-open", FOLDERSEL_PIXBUF_OPEN
,
323 "pixbuf-expander-closed", FOLDERSEL_PIXBUF
,
326 /* create text renderer */
327 renderer
= gtk_cell_renderer_text_new();
328 gtk_cell_renderer_set_padding(renderer
, 0, 0);
329 gtk_tree_view_column_pack_start(column
, renderer
, TRUE
);
330 gtk_tree_view_column_set_attributes
332 "text", FOLDERSEL_FOLDERNAME
,
333 "foreground-gdk", FOLDERSEL_FOREGROUND
,
334 "weight", FOLDERSEL_BOLD
,
336 g_object_set(G_OBJECT(renderer
), "weight", PANGO_WEIGHT_BOLD
, NULL
);
337 gtk_tree_view_column_set_sizing(column
, GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
339 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview
), column
);
341 statusbar
= gtk_statusbar_new();
342 statusbar_cid
= gtk_statusbar_get_context_id(
343 GTK_STATUSBAR(statusbar
), "Select Folder Dialog" );
344 gtk_box_pack_start(GTK_BOX(vbox
), statusbar
, FALSE
, FALSE
, 0);
345 g_signal_connect(G_OBJECT(statusbar
), "activate",
346 G_CALLBACK(foldersel_entry_activated
), NULL
);
348 gtkut_stock_button_set_create(&confirm_area
,
349 &new_button
, GTK_STOCK_NEW
,
350 &cancel_button
, GTK_STOCK_CANCEL
,
351 &ok_button
, GTK_STOCK_OK
);
353 gtk_box_pack_end(GTK_BOX(vbox
), confirm_area
, FALSE
, FALSE
, 0);
354 gtk_widget_grab_default(ok_button
);
356 g_signal_connect(G_OBJECT(ok_button
), "clicked",
357 G_CALLBACK(foldersel_ok
), NULL
);
358 g_signal_connect(G_OBJECT(cancel_button
), "clicked",
359 G_CALLBACK(foldersel_cancel
), NULL
);
360 g_signal_connect(G_OBJECT(new_button
), "clicked",
361 G_CALLBACK(foldersel_new_folder
), NULL
);
363 if (!geometry
.min_height
) {
364 geometry
.min_width
= 300;
365 geometry
.min_height
= 360;
368 gtk_window_set_geometry_hints(GTK_WINDOW(window
), NULL
, &geometry
,
370 gtk_widget_set_size_request(window
, prefs_common
.folderselwin_width
,
371 prefs_common
.folderselwin_height
);
373 gtk_widget_show_all(vbox
);
376 static void foldersel_init(void)
378 stock_pixbuf_gdk(STOCK_PIXMAP_DIR_CLOSE
, &folder_pixbuf
);
379 stock_pixbuf_gdk(STOCK_PIXMAP_DIR_OPEN
, &folderopen_pixbuf
);
380 stock_pixbuf_gdk(STOCK_PIXMAP_DIR_NOSELECT_CLOSE
, &foldernoselect_pixbuf
);
381 stock_pixbuf_gdk(STOCK_PIXMAP_DIR_NOSELECT_OPEN
, &foldernoselectopen_pixbuf
);
384 void foldersel_reflect_prefs_pixmap_theme(void)
387 g_object_unref(folder_pixbuf
);
388 if (folderopen_pixbuf
)
389 g_object_unref(folderopen_pixbuf
);
390 if (foldernoselect_pixbuf
)
391 g_object_unref(foldernoselect_pixbuf
);
392 if (foldernoselectopen_pixbuf
)
393 g_object_unref(foldernoselectopen_pixbuf
);
397 static void foldersel_append_item(GtkTreeStore
*store
, FolderItem
*item
,
398 GtkTreeIter
*iter
, GtkTreeIter
*parent
)
400 gchar
*name
, *tmpname
;
401 GdkPixbuf
*pixbuf
, *pixbuf_open
;
403 PangoWeight weight
= PANGO_WEIGHT_NORMAL
;
404 GdkColor
*foreground
= NULL
;
405 static GdkColor color_noselect
= {0, COLOR_DIM
, COLOR_DIM
, COLOR_DIM
};
406 static GdkColor color_new
;
408 gtkut_convert_int_to_gdk_color(prefs_common
.color
[COL_NEW
], &color_new
);
410 name
= folder_item_get_name(item
);
412 if (folder_has_parent_of_type(item
, F_QUEUE
) && item
->total_msgs
> 0) {
413 tmpname
= g_strdup_printf("%s (%d)", name
, item
->total_msgs
);
414 } else if (item
->unread_msgs
> 0) {
415 tmpname
= g_strdup_printf("%s (%d)", name
, item
->unread_msgs
);
417 tmpname
= g_strdup(name
);
422 pixbuf
= item
->no_select
? foldernoselect_pixbuf
: folder_pixbuf
;
424 item
->no_select
? foldernoselectopen_pixbuf
: folderopen_pixbuf
;
426 if (folder_has_parent_of_type(item
, F_DRAFT
) ||
427 folder_has_parent_of_type(item
, F_OUTBOX
) ||
428 folder_has_parent_of_type(item
, F_TRASH
)) {
430 } else if (folder_has_parent_of_type(item
, F_QUEUE
)) {
431 use_color
= (item
->total_msgs
> 0);
432 if (item
->total_msgs
> 0)
433 weight
= PANGO_WEIGHT_BOLD
;
435 if (item
->unread_msgs
> 0)
436 weight
= PANGO_WEIGHT_BOLD
;
437 use_color
= (item
->new_msgs
> 0);
441 foreground
= &color_noselect
;
443 foreground
= &color_new
;
445 /* insert this node */
446 gtk_tree_store_append(store
, iter
, parent
);
447 gtk_tree_store_set(store
, iter
,
448 FOLDERSEL_FOLDERNAME
, name
,
449 FOLDERSEL_FOLDERITEM
, item
,
450 FOLDERSEL_PIXBUF
, pixbuf
,
451 FOLDERSEL_PIXBUF_OPEN
, pixbuf_open
,
452 FOLDERSEL_FOREGROUND
, foreground
,
453 FOLDERSEL_BOLD
, weight
,
459 static void foldersel_insert_gnode_in_store(GtkTreeStore
*store
, GNode
*node
,
466 cm_return_if_fail(node
!= NULL
);
467 cm_return_if_fail(node
->data
!= NULL
);
468 cm_return_if_fail(store
!= NULL
);
470 item
= FOLDER_ITEM(node
->data
);
471 foldersel_append_item(store
, item
, &child
, parent
);
473 /* insert its children (this node as parent) */
474 for (iter
= node
->children
; iter
!= NULL
; iter
= iter
->next
)
475 foldersel_insert_gnode_in_store(store
, iter
, &child
);
478 static void foldersel_set_tree(Folder
*cur_folder
, FolderSelectionType type
)
483 for (list
= folder_get_list(); list
!= NULL
; list
= list
->next
) {
484 folder
= FOLDER(list
->data
);
485 cm_return_if_fail(folder
!= NULL
);
487 if (type
!= FOLDER_SEL_ALL
) {
488 if (FOLDER_TYPE(folder
) == F_NEWS
)
492 if (cur_folder
&& (cur_folder
->klass
!= folder
->klass
493 && g_strcmp0(cur_folder
->name
, folder
->name
) != 0))
496 foldersel_insert_gnode_in_store(tree_store
, folder
->node
, NULL
);
499 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(tree_store
),
500 FOLDERSEL_FOLDERNAME
,
503 gtk_tree_view_expand_all(GTK_TREE_VIEW(treeview
));
506 #include "localfolder.h"
507 static gboolean
foldersel_selected(GtkTreeSelection
*selection
,
508 GtkTreeModel
*model
, GtkTreePath
*path
,
509 gboolean currently_selected
, gpointer data
)
512 FolderItem
*item
= NULL
;
514 if (currently_selected
)
517 if (!gtk_tree_model_get_iter(GTK_TREE_MODEL(model
), &iter
, path
))
520 gtk_tree_model_get(GTK_TREE_MODEL(tree_store
), &iter
,
521 FOLDERSEL_FOLDERITEM
, &item
, -1);
523 selected_item
= item
;
524 if (selected_item
&& selected_item
->path
) {
526 id
= folder_item_get_identifier(selected_item
);
527 gtk_statusbar_push(GTK_STATUSBAR(statusbar
), statusbar_cid
, id
);
529 } else if (root_selectable
&& selected_item
&& selected_item
->folder
&&
530 (FOLDER_TYPE(selected_item
->folder
) == F_MH
||
531 FOLDER_TYPE(selected_item
->folder
) == F_MBOX
||
532 FOLDER_TYPE(selected_item
->folder
) == F_IMAP
)) {
533 gchar
*id
= folder_get_identifier(selected_item
->folder
);
534 gtk_statusbar_push(GTK_STATUSBAR(statusbar
), statusbar_cid
, id
);
537 gtk_statusbar_push(GTK_STATUSBAR(statusbar
), statusbar_cid
, "");
542 static void foldersel_ok(GtkButton
*button
, gpointer data
)
547 static void foldersel_cancel(GtkButton
*button
, gpointer data
)
553 static void foldersel_new_folder(GtkButton
*button
, gpointer data
)
555 FolderItem
*new_item
;
559 GtkTreeIter selected
, new_child
;
560 GtkTreePath
*selected_p
, *new_child_p
;
563 GtkTreeSelection
*selection
;
565 if (!selected_item
|| FOLDER_TYPE(selected_item
->folder
) == F_NEWS
)
568 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview
));
569 if (!gtk_tree_selection_get_selected(selection
, &model
, &selected
))
571 store
= GTK_TREE_STORE(model
);
573 new_folder
= input_dialog_with_checkbtn(_("New folder"),
574 _("Input the name of new folder:"),
576 _("Inherit properties and processing rules from parent folder"),
577 &(prefs_common
.inherit_folder_props
));
579 if (!new_folder
) return;
580 AUTORELEASE_STR(new_folder
, {g_free(new_folder
); return;});
582 p
= strchr(new_folder
, G_DIR_SEPARATOR
);
583 if ((p
&& FOLDER_TYPE(selected_item
->folder
) != F_IMAP
) ||
584 (p
&& FOLDER_TYPE(selected_item
->folder
) == F_IMAP
&&
586 alertpanel_error(_("'%c' can't be included in folder name."),
591 if (FOLDER_TYPE(selected_item
->folder
) != F_IMAP
&&
592 FOLDER_TYPE(selected_item
->folder
) != F_NEWS
&&
593 !folder_local_name_ok(new_folder
))
596 disp_name
= trim_string(new_folder
, 32);
597 AUTORELEASE_STR(disp_name
, {g_free(disp_name
); return;});
599 /* find whether the directory already exists */
600 if (folder_find_child_item_by_name(selected_item
, new_folder
)) {
601 alertpanel_error(_("The folder '%s' already exists."),
606 new_item
= folder_create_folder(selected_item
, new_folder
);
608 alertpanel_error(_("Can't create the folder '%s'."), disp_name
);
612 if (prefs_common
.inherit_folder_props
) {
613 folder_item_prefs_copy_prefs(selected_item
, new_item
);
617 foldersel_append_item(store
, new_item
, &new_child
, &selected
);
619 selected_p
= gtk_tree_model_get_path(GTK_TREE_MODEL(store
), &selected
);
620 new_child_p
= gtk_tree_model_get_path(GTK_TREE_MODEL(store
),
623 gtk_tree_view_expand_row(GTK_TREE_VIEW(treeview
), selected_p
, FALSE
);
624 gtk_tree_selection_select_iter(selection
, &new_child
);
625 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(treeview
), new_child_p
,
626 NULL
, TRUE
, 0.5, 0.0);
627 gtk_tree_path_free(new_child_p
);
628 gtk_tree_path_free(selected_p
);
633 static void foldersel_entry_activated(GtkEntry
*entry
, gpointer data
)
635 gtk_button_clicked(GTK_BUTTON(ok_button
));
638 static void foldersel_tree_activated(GtkTreeView
*treeview
, GtkTreePath
*path
,
639 GtkTreeViewColumn
*column
, gpointer data
)
641 gtk_button_clicked(GTK_BUTTON(ok_button
));
644 static gint
delete_event(GtkWidget
*widget
, GdkEventAny
*event
, gpointer data
)
646 foldersel_cancel(NULL
, NULL
);
650 static gboolean
key_pressed(GtkWidget
*widget
, GdkEventKey
*event
, gpointer data
)
655 if (event
->keyval
== GDK_KEY_Escape
) {
656 foldersel_cancel(NULL
, NULL
);
660 GtkTreePath
*path
= NULL
;
661 gtk_tree_view_get_cursor(GTK_TREE_VIEW(treeview
), &path
, NULL
);
665 switch (event
->keyval
) {
667 if (gtk_tree_view_row_expanded(GTK_TREE_VIEW(treeview
), path
)) {
668 gtk_tree_view_collapse_row(GTK_TREE_VIEW(treeview
), path
);
670 gtk_tree_path_up(path
);
671 gtk_tree_view_set_cursor(GTK_TREE_VIEW(treeview
), path
, NULL
, FALSE
);
676 if (!gtk_tree_view_row_expanded(GTK_TREE_VIEW(treeview
), path
)) {
677 gtk_tree_view_expand_row(GTK_TREE_VIEW(treeview
), path
, FALSE
);
679 gtk_tree_path_down(path
);
680 gtk_tree_view_set_cursor(GTK_TREE_VIEW(treeview
), path
, NULL
, FALSE
);
686 gtk_tree_path_free(path
);
691 static gint
foldersel_folder_name_compare(GtkTreeModel
*model
, GtkTreeIter
*a
,
692 GtkTreeIter
*b
, gpointer context
)
694 gchar
*str_a
= NULL
, *str_b
= NULL
;
696 FolderItem
*item_a
= NULL
, *item_b
= NULL
;
699 gtk_tree_model_get(model
, a
, FOLDERSEL_FOLDERITEM
, &item_a
, -1);
700 gtk_tree_model_get(model
, b
, FOLDERSEL_FOLDERITEM
, &item_b
, -1);
702 /* no sort for root folder */
703 if (!gtk_tree_model_iter_parent(GTK_TREE_MODEL(model
), &parent
, a
))
706 /* if both a and b are special folders, sort them according to
707 * their types (which is in-order). Note that this assumes that
708 * there are no multiple folders of a special type. */
709 if (item_a
->stype
!= F_NORMAL
&& item_b
->stype
!= F_NORMAL
)
710 return item_a
->stype
- item_b
->stype
;
712 /* if b is normal folder, and a is not, b is smaller (ends up
713 * lower in the list) */
714 if (item_a
->stype
!= F_NORMAL
&& item_b
->stype
== F_NORMAL
)
715 return item_b
->stype
- item_a
->stype
;
717 /* if b is special folder, and a is not, b is larger (ends up
718 * higher in the list) */
719 if (item_a
->stype
== F_NORMAL
&& item_b
->stype
!= F_NORMAL
)
720 return item_b
->stype
- item_a
->stype
;
722 /* XXX g_utf8_collate_key() comparisons may speed things
723 * up when having large lists of folders */
724 gtk_tree_model_get(model
, a
, FOLDERSEL_FOLDERNAME
, &str_a
, -1);
725 gtk_tree_model_get(model
, b
, FOLDERSEL_FOLDERNAME
, &str_b
, -1);
727 /* otherwise just compare the folder names */
728 val
= g_utf8_collate(str_a
, str_b
);
736 static gboolean
tree_view_folder_item_func(GtkTreeModel
*model
,
739 FolderItemSearch
*data
)
741 FolderItem
*item
= NULL
;
743 gtk_tree_model_get(model
, iter
, FOLDERSEL_FOLDERITEM
, &item
, -1);
745 if (data
->item
== item
) {
746 data
->path
= gtk_tree_path_copy(path
);