ced132ee4fa8295d731360c5e9eede524c72ae55
[claws.git] / src / foldersel.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2005 Hiroyuki Yamamoto
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #include "defs.h"
21
22 #include <glib.h>
23 #include <glib/gi18n.h>
24 #include <gdk/gdkkeysyms.h>
25 #include <gtk/gtkmain.h>
26 #include <gtk/gtkwidget.h>
27 #include <gtk/gtktreestore.h>
28 #include <gtk/gtktreeview.h>
29 #include <gtk/gtkwindow.h>
30 #include <gtk/gtkvbox.h>
31 #include <gtk/gtkscrolledwindow.h>
32 #include <gtk/gtkentry.h>
33 #include <gtk/gtkhbbox.h>
34 #include <gtk/gtksignal.h>
35 #include <stdio.h>
36 #include <unistd.h>
37 #include <string.h>
38 #include <sys/stat.h>
39 #include <sys/types.h>
40 #include <fcntl.h>
41 #include <errno.h>
42
43 #include "main.h"
44 #include "utils.h"
45 #include "gtkutils.h"
46 #include "stock_pixmap.h"
47 #include "foldersel.h"
48 #include "alertpanel.h"
49 #include "manage_window.h"
50 #include "folderview.h"
51 #include "inputdialog.h"
52 #include "folder.h"
53 #include "prefs_common.h"
54
55 enum {
56         FOLDERSEL_FOLDERNAME,
57         FOLDERSEL_FOLDERITEM,
58         FOLDERSEL_PIXBUF,
59         FOLDERSEL_PIXBUF_OPEN,
60         FOLDERSEL_EXPANDER,
61         N_FOLDERSEL_COLUMNS
62 };
63
64 typedef struct _FolderItemSearch        FolderItemSearch;
65
66 struct _FolderItemSearch
67 {
68         FolderItem *item;
69         GtkTreePath *path;
70         GtkTreeIter iter;
71 };
72
73 static GdkPixbuf *folder_pixbuf;
74 static GdkPixbuf *folderopen_pixbuf;
75 static GdkPixbuf *foldernoselect_pixbuf;
76
77 static GtkWidget *window;
78 static GtkWidget *treeview;
79 static GtkWidget *entry;
80 static GtkWidget *ok_button;
81 static GtkWidget *cancel_button;
82 static GtkWidget *new_button;
83
84 static FolderItem *folder_item;
85 static FolderItem *selected_item;
86
87 static GtkTreeStore *tree_store;
88
89 static gboolean cancelled;
90 static gboolean finished;
91
92 static void foldersel_create            (void);
93 static void foldersel_init              (void);
94
95 static void foldersel_append_item       (GtkTreeStore   *store,
96                                          FolderItem     *item,
97                                          GtkTreeIter    *iter,
98                                          GtkTreeIter    *parent);
99
100 static void foldersel_set_tree          (Folder                 *cur_folder,
101                                          FolderSelectionType     type);
102
103 static gboolean foldersel_selected      (GtkTreeSelection *selection,
104                                          GtkTreeModel     *model,
105                                          GtkTreePath      *path,
106                                          gboolean          currently_selected,
107                                          gpointer          data);
108
109 static void foldersel_ok                (GtkButton      *button,
110                                          gpointer        data);
111 static void foldersel_cancel            (GtkButton      *button,
112                                          gpointer        data);
113 static void foldersel_new_folder        (GtkButton      *button,
114                                          gpointer        data);
115
116 static void foldersel_entry_activated   (GtkEntry       *entry,
117                                          gpointer        data);
118
119 static void foldersel_tree_activated    (GtkTreeView            *treeview,
120                                          GtkTreePath            *path,
121                                          GtkTreeViewColumn      *column,
122                                          gpointer                data);
123
124 static gint delete_event                (GtkWidget      *widget,
125                                          GdkEventAny    *event,
126                                          gpointer        data);
127 static gboolean key_pressed             (GtkWidget      *widget,
128                                          GdkEventKey    *event,
129                                          gpointer        data);
130
131 static gint foldersel_folder_name_compare       (GtkTreeModel   *model,
132                                                  GtkTreeIter    *a,
133                                                  GtkTreeIter    *b,
134                                                  gpointer        context);
135
136 static gboolean tree_view_folder_item_func      (GtkTreeModel     *model,
137                                                  GtkTreePath      *path,
138                                                  GtkTreeIter      *iter,
139                                                  FolderItemSearch *data);
140
141 FolderItem *foldersel_folder_sel(Folder *cur_folder, FolderSelectionType type,
142                                  const gchar *default_folder)
143 {
144         selected_item = NULL;
145
146         if (!window) {
147                 foldersel_create();
148                 foldersel_init();
149         }
150
151         foldersel_set_tree(cur_folder, type);
152
153         /* select current */
154         if (folder_item) {
155                 FolderItemSearch fis;
156
157                 fis.item = folder_item;
158                 fis.path = NULL;
159
160                 /* find matching model entry */
161                 gtk_tree_model_foreach
162                         (GTK_TREE_MODEL(tree_store),
163                          (GtkTreeModelForeachFunc)tree_view_folder_item_func,
164                          &fis);
165
166                 if (fis.path) {
167                         GtkTreeSelection *selection;
168
169                         selection = gtk_tree_view_get_selection
170                                 (GTK_TREE_VIEW(treeview));
171                         gtk_tree_selection_select_iter(selection, &fis.iter);
172                         gtk_tree_view_set_cursor(GTK_TREE_VIEW(treeview),
173                                                  fis.path, NULL, FALSE);
174                         gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(treeview),
175                                                      fis.path,
176                                                      NULL, TRUE, 0.5, 0.0);
177                         gtk_tree_path_free(fis.path);
178                 } else
179                         gtk_tree_view_scroll_to_point
180                                 (GTK_TREE_VIEW(treeview), 0, 0);
181         } else
182                 gtk_tree_view_scroll_to_point(GTK_TREE_VIEW(treeview), 0, 0);
183
184         gtk_widget_grab_focus(ok_button);
185         gtk_widget_grab_focus(treeview);
186
187         gtk_widget_show(window);
188         manage_window_set_transient(GTK_WINDOW(window));
189
190         cancelled = finished = FALSE;
191
192         while (finished == FALSE)
193                 gtk_main_iteration();
194
195         gtk_widget_hide(window);
196         gtk_entry_set_text(GTK_ENTRY(entry), "");
197         gtk_tree_store_clear(tree_store);
198
199         if (!cancelled &&
200             selected_item && selected_item->path && !selected_item->no_select) {
201                 folder_item = selected_item;
202                 return folder_item;
203         } else
204                 return NULL;
205 }
206
207 static void foldersel_create(void)
208 {
209         GtkWidget *vbox;
210         GtkWidget *scrolledwin;
211         GtkWidget *confirm_area;
212         GtkTreeViewColumn *column;
213         GtkCellRenderer *renderer;
214         GtkTreeSelection *selection;
215
216         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
217         gtk_window_set_title(GTK_WINDOW(window), _("Select folder"));
218         gtk_container_set_border_width(GTK_CONTAINER(window), 4);
219         gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
220         gtk_window_set_modal(GTK_WINDOW(window), TRUE);
221         gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, FALSE);
222         gtk_window_set_wmclass
223                 (GTK_WINDOW(window), "folder_selection", "Sylpheed");
224         gtk_widget_realize(window);
225         g_signal_connect(G_OBJECT(window), "delete_event",
226                          G_CALLBACK(delete_event), NULL);
227         g_signal_connect(G_OBJECT(window), "key_press_event",
228                          G_CALLBACK(key_pressed), NULL);
229         MANAGE_WINDOW_SIGNALS_CONNECT(window);
230
231         vbox = gtk_vbox_new(FALSE, 4);
232         gtk_container_add(GTK_CONTAINER(window), vbox);
233
234         scrolledwin = gtk_scrolled_window_new(NULL, NULL);
235         gtk_widget_set_size_request(scrolledwin, 300, 360);
236         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
237                                        GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
238         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
239                                             GTK_SHADOW_IN);
240         gtk_box_pack_start(GTK_BOX(vbox), scrolledwin, TRUE, TRUE, 0);
241
242         tree_store = gtk_tree_store_new(N_FOLDERSEL_COLUMNS,
243                                         G_TYPE_STRING,
244                                         G_TYPE_POINTER,
245                                         GDK_TYPE_PIXBUF,
246                                         GDK_TYPE_PIXBUF,
247                                         G_TYPE_BOOLEAN);
248         gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(tree_store),
249                                         FOLDERSEL_FOLDERNAME,
250                                         foldersel_folder_name_compare,
251                                         NULL, NULL);
252
253         treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(tree_store));
254         g_object_unref(G_OBJECT(tree_store));
255         gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE);
256         gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview),
257                                      prefs_common.enable_rules_hint);
258         gtk_tree_view_set_search_column(GTK_TREE_VIEW(treeview),
259                                         FOLDERSEL_FOLDERNAME);
260
261         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
262         gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE);
263         gtk_tree_selection_set_select_function(selection, foldersel_selected,
264                                                NULL, NULL);
265
266         g_signal_connect(G_OBJECT(treeview), "row-activated",
267                          G_CALLBACK(foldersel_tree_activated), NULL);
268
269         gtk_container_add(GTK_CONTAINER(scrolledwin), treeview);
270
271         column = gtk_tree_view_column_new();
272         gtk_tree_view_column_set_spacing(column, 2);
273         renderer = gtk_cell_renderer_pixbuf_new();
274         gtk_tree_view_column_pack_start(column, renderer, FALSE);
275         gtk_tree_view_column_set_attributes
276                 (column, renderer,
277                  "is-expander", FOLDERSEL_EXPANDER,
278                  "pixbuf", FOLDERSEL_PIXBUF,
279                  "pixbuf-expander-open", FOLDERSEL_PIXBUF_OPEN,
280                  "pixbuf-expander-closed", FOLDERSEL_PIXBUF,
281                  NULL);
282
283         /* create text renderer */
284         renderer = gtk_cell_renderer_text_new();
285         gtk_tree_view_column_pack_start(column, renderer, TRUE);
286         gtk_tree_view_column_set_attributes(column, renderer,
287                                             "text", FOLDERSEL_FOLDERNAME,
288                                             NULL);
289         gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
290
291         gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
292
293         entry = gtk_entry_new();
294         gtk_entry_set_editable(GTK_ENTRY(entry), FALSE);
295         gtk_box_pack_start(GTK_BOX(vbox), entry, FALSE, FALSE, 0);
296         g_signal_connect(G_OBJECT(entry), "activate",
297                          G_CALLBACK(foldersel_entry_activated), NULL);
298
299         gtkut_stock_button_set_create(&confirm_area,
300                                       &ok_button,     GTK_STOCK_OK,
301                                       &cancel_button, GTK_STOCK_CANCEL,
302                                       &new_button,    GTK_STOCK_NEW);
303
304         gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
305         gtk_widget_grab_default(ok_button);
306
307         g_signal_connect(G_OBJECT(ok_button), "clicked",
308                          G_CALLBACK(foldersel_ok), NULL);
309         g_signal_connect(G_OBJECT(cancel_button), "clicked",
310                          G_CALLBACK(foldersel_cancel), NULL);
311         g_signal_connect(G_OBJECT(new_button), "clicked",
312                          G_CALLBACK(foldersel_new_folder), NULL);
313
314         gtk_widget_show_all(vbox);
315 }
316
317 static void foldersel_init(void)
318 {
319         stock_pixbuf_gdk(treeview, STOCK_PIXMAP_DIR_CLOSE,
320                          &folder_pixbuf);
321         stock_pixbuf_gdk(treeview, STOCK_PIXMAP_DIR_OPEN,
322                          &folderopen_pixbuf);
323         stock_pixbuf_gdk(treeview, STOCK_PIXMAP_DIR_NOSELECT,
324                          &foldernoselect_pixbuf);
325 }
326
327 static void foldersel_append_item(GtkTreeStore *store, FolderItem *item,
328                                   GtkTreeIter *iter, GtkTreeIter *parent)
329 {
330         gchar *name, *tmpname;
331         GdkPixbuf *pixbuf, *pixbuf_open;
332
333         name = tmpname = folder_item_get_name(item);
334
335         if (item->stype != F_NORMAL && FOLDER_IS_LOCAL(item->folder)) {
336                 switch (item->stype) {
337                 case F_INBOX:
338                         if (!strcmp2(item->name, INBOX_DIR))
339                                 name = _("Inbox");
340                         break;
341                 case F_OUTBOX:
342                         if (!strcmp2(item->name, OUTBOX_DIR))
343                                 name = _("Sent");
344                         break;
345                 case F_QUEUE:
346                         if (!strcmp2(item->name, QUEUE_DIR))
347                                 name = _("Queue");
348                         break;
349                 case F_TRASH:
350                         if (!strcmp2(item->name, TRASH_DIR))
351                                 name = _("Trash");
352                         break;
353                 case F_DRAFT:
354                         if (!strcmp2(item->name, DRAFT_DIR))
355                                 name = _("Drafts");
356                         break;
357                 default:
358                         break;
359                 }
360         }
361
362         /* CLAWS: already adds the UI string to the folder name */
363 #ifndef CLAWS         
364         if (!item->parent) {
365                 switch (FOLDER_TYPE(item->folder)) {
366                 case F_MH:
367                         Xstrcat_a(name, name, " (MH)", ); break;
368                 case F_IMAP:
369                         Xstrcat_a(name, name, " (IMAP4)", ); break;
370                 case F_NEWS:
371                         Xstrcat_a(name, name, " (News)", ); break;
372                 default:
373                         break;
374                 }
375         }
376 #endif        
377
378         gtk_tree_store_append(store, iter, parent);
379
380         pixbuf = item->no_select ? foldernoselect_pixbuf : folder_pixbuf,
381         pixbuf_open =
382                 item->no_select ? foldernoselect_pixbuf : folderopen_pixbuf,
383
384         /* insert this node */
385         gtk_tree_store_set(store, iter,
386                            FOLDERSEL_FOLDERNAME, name,
387                            FOLDERSEL_FOLDERITEM, item,
388                            FOLDERSEL_PIXBUF, pixbuf,
389                            FOLDERSEL_PIXBUF_OPEN, pixbuf_open,
390                            FOLDERSEL_EXPANDER,
391                                 item->node->children ? TRUE : FALSE,
392                            -1);
393         
394         g_free(tmpname);
395 }
396
397 static void foldersel_insert_gnode_in_store(GtkTreeStore *store, GNode *node,
398                                             GtkTreeIter *parent)
399 {
400         FolderItem *item;
401         GtkTreeIter child;
402         GNode *iter;
403
404         g_return_if_fail(node != NULL);
405         g_return_if_fail(node->data != NULL);
406         g_return_if_fail(store != NULL);
407
408         item = FOLDER_ITEM(node->data);
409         foldersel_append_item(store, item, &child, parent);
410
411         /* insert its children (this node as parent) */
412         for (iter = node->children; iter != NULL; iter = iter->next)
413                 foldersel_insert_gnode_in_store(store, iter, &child);
414 }
415
416 static void foldersel_set_tree(Folder *cur_folder, FolderSelectionType type)
417 {
418         Folder *folder;
419         GList *list;
420
421         for (list = folder_get_list(); list != NULL; list = list->next) {
422                 folder = FOLDER(list->data);
423                 g_return_if_fail(folder != NULL);
424
425                 if (type != FOLDER_SEL_ALL) {
426                         if (FOLDER_TYPE(folder) == F_NEWS)
427                                 continue;
428                 }
429
430                 foldersel_insert_gnode_in_store(tree_store, folder->node, NULL);
431         }
432
433         gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(tree_store),
434                                              FOLDERSEL_FOLDERNAME,
435                                              GTK_SORT_ASCENDING);
436
437         gtk_tree_view_expand_all(GTK_TREE_VIEW(treeview));
438 }
439
440 static gboolean foldersel_selected(GtkTreeSelection *selection,
441                                    GtkTreeModel *model, GtkTreePath *path,
442                                    gboolean currently_selected, gpointer data)
443 {
444         GtkTreeIter iter;
445         FolderItem *item = NULL;
446
447         if (currently_selected)
448                 return TRUE;
449
450         if (!gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path))
451                 return TRUE;
452
453         gtk_tree_model_get(GTK_TREE_MODEL(tree_store), &iter,
454                            FOLDERSEL_FOLDERITEM, &item, -1);
455
456         selected_item = item;
457         if (selected_item && selected_item->path && !selected_item->no_select) {
458                 gchar *id;
459                 id = folder_item_get_identifier(selected_item);
460                 gtk_entry_set_text(GTK_ENTRY(entry), id);
461                 g_free(id);
462         } else
463                 gtk_entry_set_text(GTK_ENTRY(entry), "");
464
465         return TRUE;
466 }
467
468 static void foldersel_ok(GtkButton *button, gpointer data)
469 {
470         finished = TRUE;
471 }
472
473 static void foldersel_cancel(GtkButton *button, gpointer data)
474 {
475         cancelled = TRUE;
476         finished = TRUE;
477 }
478
479 static void foldersel_new_folder(GtkButton *button, gpointer data)
480 {
481         FolderItem *new_item;
482         gchar *new_folder;
483         gchar *disp_name;
484         gchar *p;
485         GtkTreeIter selected, new_child;
486         GtkTreePath *selected_p, *new_child_p;
487         GtkTreeStore *store;
488         GtkTreeModel *model;
489         GtkTreeSelection *selection;
490
491         if (!selected_item || FOLDER_TYPE(selected_item->folder) == F_NEWS)
492                 return;
493
494         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
495         if (!gtk_tree_selection_get_selected(selection, &model, &selected))
496                 return;
497         store = GTK_TREE_STORE(model);
498
499         new_folder = input_dialog(_("New folder"),
500                                   _("Input the name of new folder:"),
501                                   _("NewFolder"));
502         if (!new_folder) return;
503         AUTORELEASE_STR(new_folder, {g_free(new_folder); return;});
504
505         p = strchr(new_folder, G_DIR_SEPARATOR);
506         if ((p && FOLDER_TYPE(selected_item->folder) != F_IMAP) ||
507             (p && FOLDER_TYPE(selected_item->folder) == F_IMAP &&
508              *(p + 1) != '\0')) {
509                 alertpanel_error(_("`%c' can't be included in folder name."),
510                                 G_DIR_SEPARATOR);
511                 return;
512         }
513
514         disp_name = trim_string(new_folder, 32);
515         AUTORELEASE_STR(disp_name, {g_free(disp_name); return;});
516
517         /* find whether the directory already exists */
518         if (folder_find_child_item_by_name(selected_item, new_folder)) {
519                 alertpanel_error(_("The folder `%s' already exists."),
520                                  disp_name);
521                 return;
522         }
523
524         new_item = folder_create_folder(selected_item, new_folder);
525         if (!new_item) {
526                 alertpanel_error(_("Can't create the folder `%s'."), disp_name);
527                 return;
528         }
529
530         /* parent can expand */
531         gtk_tree_store_set(store, &selected, FOLDERSEL_EXPANDER, TRUE,
532                            -1);
533
534         /* add new child */
535         foldersel_append_item(store, new_item, &new_child, &selected);
536         
537         selected_p = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &selected);
538         new_child_p = gtk_tree_model_get_path(GTK_TREE_MODEL(store),
539                                               &new_child);
540
541         gtk_tree_view_expand_row(GTK_TREE_VIEW(treeview), selected_p, FALSE);
542         gtk_tree_selection_select_iter(selection, &new_child);
543         gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(treeview), new_child_p,
544                                      NULL, TRUE, 0.5, 0.0);
545         gtk_tree_path_free(new_child_p);
546         gtk_tree_path_free(selected_p);
547
548         folder_write_list();
549 }
550
551 static void foldersel_entry_activated(GtkEntry *entry, gpointer data)
552 {
553         gtk_button_clicked(GTK_BUTTON(ok_button));
554 }
555
556 static void foldersel_tree_activated(GtkTreeView *treeview, GtkTreePath *path,
557                                      GtkTreeViewColumn *column, gpointer data)
558 {
559         gtk_button_clicked(GTK_BUTTON(ok_button));
560 }
561
562 static gint delete_event(GtkWidget *widget, GdkEventAny *event, gpointer data)
563 {
564         foldersel_cancel(NULL, NULL);
565         return TRUE;
566 }
567
568 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
569 {
570         if (event && event->keyval == GDK_Escape)
571                 foldersel_cancel(NULL, NULL);
572         return FALSE;
573 }
574
575 static gint foldersel_folder_name_compare(GtkTreeModel *model, GtkTreeIter *a,
576                                           GtkTreeIter *b, gpointer context)
577 {
578         gchar *str_a = NULL, *str_b = NULL;
579         gint val = 0;
580         FolderItem *item_a = NULL, *item_b = NULL;
581         GtkTreeIter parent;
582
583         gtk_tree_model_get(model, a, FOLDERSEL_FOLDERITEM, &item_a, -1);
584         gtk_tree_model_get(model, b, FOLDERSEL_FOLDERITEM, &item_b, -1);
585
586         /* no sort for root folder */
587         if (!gtk_tree_model_iter_parent(GTK_TREE_MODEL(model), &parent, a))
588                 return 0;
589
590         /* if both a and b are special folders, sort them according to
591          * their types (which is in-order). Note that this assumes that
592          * there are no multiple folders of a special type. */
593         if (item_a->stype != F_NORMAL && item_b->stype != F_NORMAL)
594                 return item_a->stype - item_b->stype;
595
596         /* if b is normal folder, and a is not, b is smaller (ends up
597          * lower in the list) */
598         if (item_a->stype != F_NORMAL && item_b->stype == F_NORMAL)
599                 return item_b->stype - item_a->stype;
600
601         /* if b is special folder, and a is not, b is larger (ends up
602          * higher in the list) */
603         if (item_a->stype == F_NORMAL && item_b->stype != F_NORMAL)
604                 return item_b->stype - item_a->stype;
605
606         /* XXX g_utf8_collate_key() comparisons may speed things
607          * up when having large lists of folders */
608         gtk_tree_model_get(model, a, FOLDERSEL_FOLDERNAME, &str_a, -1);
609         gtk_tree_model_get(model, b, FOLDERSEL_FOLDERNAME, &str_b, -1);
610
611         /* otherwise just compare the folder names */
612         val = g_utf8_collate(str_a, str_b);
613
614         g_free(str_a);
615         g_free(str_b);
616
617         return val;
618 }
619
620 static gboolean tree_view_folder_item_func(GtkTreeModel *model,
621                                            GtkTreePath *path,
622                                            GtkTreeIter *iter,
623                                            FolderItemSearch *data)
624 {
625         FolderItem *item = NULL;
626
627         gtk_tree_model_get(model, iter, FOLDERSEL_FOLDERITEM, &item, -1);
628
629         if (data->item == item) {
630                 data->path = gtk_tree_path_copy(path);
631                 data->iter = *iter;
632                 return TRUE;
633         }
634
635         return FALSE;
636 }