1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
3
* Copyright (C) 2005 Red Hat, Inc.
5
* Nautilus is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License as
7
* published by the Free Software Foundation; either version 2 of the
8
* License, or (at your option) any later version.
10
* Nautilus 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 GNU
13
* General Public License for more details.
15
* You should have received a copy of the GNU General Public
16
* License along with this program; see the file COPYING. If not,
17
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
* Boston, MA 02111-1307, USA.
20
* Author: Alexander Larsson <alexl@redhat.com>
25
#include "nautilus-query-editor.h"
28
#include <glib/gi18n.h>
30
#include <gdk/gdkkeysyms.h>
33
#include <eel/eel-glib-extensions.h>
34
#include <libnautilus-private/nautilus-file-utilities.h>
37
NAUTILUS_QUERY_EDITOR_ROW_TYPE,
39
NAUTILUS_QUERY_EDITOR_ROW_LAST
40
} NautilusQueryEditorRowType;
43
NautilusQueryEditorRowType type;
44
NautilusQueryEditor *editor;
49
GtkWidget *type_widget;
50
} NautilusQueryEditorRow;
55
GtkWidget * (*create_widgets) (NautilusQueryEditorRow *row);
56
void (*add_to_query) (NautilusQueryEditorRow *row,
57
NautilusQuery *query);
58
void (*add_rows_from_query) (NautilusQueryEditor *editor,
59
NautilusQuery *query);
60
} NautilusQueryEditorRowOps;
62
struct NautilusQueryEditorDetails {
64
gboolean change_frozen;
65
guint typing_timeout_id;
67
GtkWidget *search_current_button;
68
GtkWidget *search_all_button;
83
static guint signals[LAST_SIGNAL];
85
static void entry_activate_cb (GtkWidget *entry, NautilusQueryEditor *editor);
86
static void entry_changed_cb (GtkWidget *entry, NautilusQueryEditor *editor);
87
static void nautilus_query_editor_changed_force (NautilusQueryEditor *editor,
89
static void nautilus_query_editor_changed (NautilusQueryEditor *editor);
90
static NautilusQueryEditorRow * nautilus_query_editor_add_row (NautilusQueryEditor *editor,
91
NautilusQueryEditorRowType type);
93
static GtkWidget *type_row_create_widgets (NautilusQueryEditorRow *row);
94
static void type_row_add_to_query (NautilusQueryEditorRow *row,
95
NautilusQuery *query);
96
static void type_add_rows_from_query (NautilusQueryEditor *editor,
97
NautilusQuery *query);
101
static NautilusQueryEditorRowOps row_type[] = {
103
type_row_create_widgets,
104
type_row_add_to_query,
105
type_add_rows_from_query
109
G_DEFINE_TYPE (NautilusQueryEditor, nautilus_query_editor, GTK_TYPE_BOX);
112
nautilus_query_editor_handle_event (NautilusQueryEditor *editor,
116
GtkWidget *old_focus;
120
/* if we're focused already, no need to handle the event manually */
121
if (gtk_widget_has_focus (editor->details->entry)) {
125
/* never handle these events */
126
if (event->keyval == GDK_KEY_slash || event->keyval == GDK_KEY_Delete) {
130
/* don't activate search for these events */
131
if (!gtk_widget_get_visible (GTK_WIDGET (editor)) && event->keyval == GDK_KEY_space) {
135
/* if it's not printable we don't need it */
136
if (!g_unichar_isprint (gdk_keyval_to_unicode (event->keyval))) {
140
if (!gtk_widget_get_realized (editor->details->entry)) {
141
gtk_widget_realize (editor->details->entry);
144
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (editor));
145
if (gtk_widget_is_toplevel (toplevel)) {
146
old_focus = gtk_window_get_focus (GTK_WINDOW (toplevel));
151
/* input methods will typically only process events after getting focus */
152
gtk_widget_grab_focus (editor->details->entry);
154
new_event = gdk_event_copy ((GdkEvent *) event);
155
g_object_unref (((GdkEventKey *) new_event)->window);
156
((GdkEventKey *) new_event)->window = g_object_ref
157
(gtk_widget_get_window (editor->details->entry));
158
retval = gtk_widget_event (editor->details->entry, new_event);
159
gdk_event_free (new_event);
161
if (!retval && old_focus) {
162
gtk_widget_grab_focus (old_focus);
169
row_destroy (NautilusQueryEditorRow *row)
171
gtk_widget_destroy (row->toolbar);
176
nautilus_query_editor_dispose (GObject *object)
178
NautilusQueryEditor *editor;
180
editor = NAUTILUS_QUERY_EDITOR (object);
182
if (editor->details->typing_timeout_id > 0) {
183
g_source_remove (editor->details->typing_timeout_id);
184
editor->details->typing_timeout_id = 0;
187
g_clear_object (&editor->details->query);
189
g_list_free_full (editor->details->rows, (GDestroyNotify) row_destroy);
190
editor->details->rows = NULL;
192
G_OBJECT_CLASS (nautilus_query_editor_parent_class)->dispose (object);
196
nautilus_query_editor_grab_focus (GtkWidget *widget)
198
NautilusQueryEditor *editor = NAUTILUS_QUERY_EDITOR (widget);
200
if (gtk_widget_get_visible (widget) && !gtk_widget_is_focus (editor->details->entry)) {
201
/* avoid selecting the entry text */
202
gtk_widget_grab_focus (editor->details->entry);
203
gtk_editable_set_position (GTK_EDITABLE (editor->details->entry), -1);
208
nautilus_query_editor_class_init (NautilusQueryEditorClass *class)
210
GObjectClass *gobject_class;
211
GtkWidgetClass *widget_class;
212
GtkBindingSet *binding_set;
214
gobject_class = G_OBJECT_CLASS (class);
215
gobject_class->dispose = nautilus_query_editor_dispose;
217
widget_class = GTK_WIDGET_CLASS (class);
218
widget_class->grab_focus = nautilus_query_editor_grab_focus;
221
g_signal_new ("changed",
222
G_TYPE_FROM_CLASS (class),
224
G_STRUCT_OFFSET (NautilusQueryEditorClass, changed),
226
g_cclosure_marshal_generic,
227
G_TYPE_NONE, 2, NAUTILUS_TYPE_QUERY, G_TYPE_BOOLEAN);
230
g_signal_new ("cancel",
231
G_TYPE_FROM_CLASS (class),
232
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
233
G_STRUCT_OFFSET (NautilusQueryEditorClass, cancel),
235
g_cclosure_marshal_VOID__VOID,
239
g_signal_new ("activated",
240
G_TYPE_FROM_CLASS (class),
241
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
242
G_STRUCT_OFFSET (NautilusQueryEditorClass, activated),
244
g_cclosure_marshal_VOID__VOID,
247
binding_set = gtk_binding_set_by_class (class);
248
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "cancel", 0);
250
g_type_class_add_private (class, sizeof (NautilusQueryEditorDetails));
254
nautilus_query_editor_get_location (NautilusQueryEditor *editor)
257
if (editor->details->current_uri != NULL)
258
file = g_file_new_for_uri (editor->details->current_uri);
263
entry_activate_cb (GtkWidget *entry, NautilusQueryEditor *editor)
265
g_signal_emit (editor, signals[ACTIVATED], 0);
269
typing_timeout_cb (gpointer user_data)
271
NautilusQueryEditor *editor;
273
editor = NAUTILUS_QUERY_EDITOR (user_data);
274
editor->details->typing_timeout_id = 0;
276
nautilus_query_editor_changed (editor);
281
#define TYPING_TIMEOUT 250
284
entry_changed_cb (GtkWidget *entry, NautilusQueryEditor *editor)
286
if (editor->details->change_frozen) {
290
if (editor->details->typing_timeout_id > 0) {
291
g_source_remove (editor->details->typing_timeout_id);
294
editor->details->typing_timeout_id =
295
g_timeout_add (TYPING_TIMEOUT,
303
type_separator_func (GtkTreeModel *model,
310
gtk_tree_model_get (model, iter, 0, &text, -1);
312
res = text != NULL && strcmp (text, "---") == 0;
321
} mime_type_groups[] = {
324
"application/msword",
325
"application/vnd.sun.xml.writer",
326
"application/vnd.sun.xml.writer.global",
327
"application/vnd.sun.xml.writer.template",
328
"application/vnd.oasis.opendocument.text",
329
"application/vnd.oasis.opendocument.text-template",
330
"application/x-abiword",
331
"application/x-applix-word",
332
"application/x-mswrite",
333
"application/docbook+xml",
334
"application/x-kword",
335
"application/x-kword-crypt",
342
"audio/x-vorbis+ogg",
351
"audio/x-pn-realaudio",
367
"video/x-real-video",
372
{ "application/vnd.oasis.opendocument.image",
373
"application/x-krita",
382
"image/x-compressed-xcf",
391
{ N_("Illustration"),
392
{ "application/illustrator",
393
"application/vnd.corel-draw",
394
"application/vnd.stardivision.draw",
395
"application/vnd.oasis.opendocument.graphics",
396
"application/x-dia-diagram",
397
"application/x-karbon",
398
"application/x-killustrator",
399
"application/x-kivio",
400
"application/x-kontour",
406
{ "application/vnd.lotus-1-2-3",
407
"application/vnd.ms-excel",
408
"application/vnd.stardivision.calc",
409
"application/vnd.sun.xml.calc",
410
"application/vnd.oasis.opendocument.spreadsheet",
411
"application/x-applix-spreadsheet",
412
"application/x-gnumeric",
413
"application/x-kspread",
414
"application/x-kspread-crypt",
415
"application/x-quattropro",
417
"application/x-siag",
421
{ N_("Presentation"),
422
{ "application/vnd.ms-powerpoint",
423
"application/vnd.sun.xml.impress",
424
"application/vnd.oasis.opendocument.presentation",
425
"application/x-magicpoint",
426
"application/x-kpresenter",
430
{ N_("Pdf / Postscript"),
432
"application/postscript",
446
type_add_custom_type (NautilusQueryEditorRow *row,
447
const char *mime_type,
448
const char *description,
454
model = gtk_combo_box_get_model (GTK_COMBO_BOX (row->type_widget));
455
store = GTK_LIST_STORE (model);
457
gtk_list_store_append (store, iter);
458
gtk_list_store_set (store, iter,
466
type_combo_changed (GtkComboBox *combo_box, NautilusQueryEditorRow *row)
472
if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (row->type_widget),
477
model = gtk_combo_box_get_model (GTK_COMBO_BOX (row->type_widget));
478
gtk_tree_model_get (model, &iter, 3, &other, -1);
481
GList *mime_infos, *l;
483
GtkWidget *scrolled, *treeview;
485
GtkTreeViewColumn *column;
486
GtkCellRenderer *renderer;
488
GtkTreeSelection *selection;
490
mime_infos = g_content_types_get_registered ();
492
store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
493
for (l = mime_infos; l != NULL; l = l->next) {
495
char *mime_type = l->data;
498
description = g_content_type_get_description (mime_type);
499
if (description == NULL) {
500
description = g_strdup (mime_type);
503
gtk_list_store_append (store, &iter);
504
gtk_list_store_set (store, &iter,
510
g_free (description);
512
g_list_free (mime_infos);
516
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
517
dialog = gtk_dialog_new_with_buttons (_("Select type"),
518
GTK_WINDOW (toplevel),
520
_("_Cancel"), GTK_RESPONSE_CANCEL,
521
_("Select"), GTK_RESPONSE_OK,
523
gtk_window_set_default_size (GTK_WINDOW (dialog), 400, 600);
525
scrolled = gtk_scrolled_window_new (NULL, NULL);
526
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
527
GTK_POLICY_AUTOMATIC,
528
GTK_POLICY_AUTOMATIC);
529
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
532
gtk_widget_show (scrolled);
533
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), scrolled, TRUE, TRUE, 6);
535
treeview = gtk_tree_view_new ();
536
gtk_tree_view_set_model (GTK_TREE_VIEW (treeview),
537
GTK_TREE_MODEL (store));
538
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), 0,
541
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
542
gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
545
renderer = gtk_cell_renderer_text_new ();
546
column = gtk_tree_view_column_new_with_attributes ("Name",
551
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
552
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
554
gtk_widget_show (treeview);
555
gtk_container_add (GTK_CONTAINER (scrolled), treeview);
557
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
558
char *mimetype, *description;
560
gtk_tree_selection_get_selected (selection, NULL, &iter);
561
gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
566
type_add_custom_type (row, mimetype, description, &iter);
567
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (row->type_widget),
570
gtk_combo_box_set_active (GTK_COMBO_BOX (row->type_widget), 0);
573
gtk_widget_destroy (dialog);
576
nautilus_query_editor_changed (row->editor);
580
type_row_create_widgets (NautilusQueryEditorRow *row)
583
GtkCellRenderer *cell;
588
store = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_BOOLEAN);
589
combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
590
g_object_unref (store);
592
cell = gtk_cell_renderer_text_new ();
593
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
594
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell,
597
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo),
601
gtk_list_store_append (store, &iter);
602
gtk_list_store_set (store, &iter, 0, _("Any"), -1);
603
gtk_list_store_append (store, &iter);
604
gtk_list_store_set (store, &iter, 0, "---", -1);
606
for (i = 0; i < G_N_ELEMENTS (mime_type_groups); i++) {
607
gtk_list_store_append (store, &iter);
608
gtk_list_store_set (store, &iter,
609
0, gettext (mime_type_groups[i].name),
610
1, mime_type_groups[i].mimetypes,
614
gtk_list_store_append (store, &iter);
615
gtk_list_store_set (store, &iter, 0, "---", -1);
616
gtk_list_store_append (store, &iter);
617
gtk_list_store_set (store, &iter, 0, _("Other Type…"), 3, TRUE, -1);
619
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
621
g_signal_connect (combo, "changed",
622
G_CALLBACK (type_combo_changed),
625
gtk_widget_show (combo);
627
gtk_box_pack_start (GTK_BOX (row->hbox), combo, FALSE, FALSE, 0);
633
type_row_add_to_query (NautilusQueryEditorRow *row,
634
NautilusQuery *query)
641
if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (row->type_widget),
646
model = gtk_combo_box_get_model (GTK_COMBO_BOX (row->type_widget));
647
gtk_tree_model_get (model, &iter, 1, &mimetypes, 2, &mimetype, -1);
649
if (mimetypes != NULL) {
650
while (*mimetypes != NULL) {
651
nautilus_query_add_mime_type (query, *mimetypes);
656
nautilus_query_add_mime_type (query, mimetype);
662
all_group_types_in_list (char **group_types, GList *mime_types)
669
group_type = group_types;
670
while (*group_type != NULL) {
673
for (l = mime_types; l != NULL; l = l->next) {
676
if (strcmp (mime_type, *group_type) == 0) {
691
remove_group_types_from_list (char **group_types, GList *mime_types)
697
group_type = group_types;
698
while (*group_type != NULL) {
699
for (l = mime_types; l != NULL; l = next) {
703
if (strcmp (mime_type, *group_type) == 0) {
704
mime_types = g_list_remove_link (mime_types, l);
717
type_add_rows_from_query (NautilusQueryEditor *editor,
718
NautilusQuery *query)
723
NautilusQueryEditorRow *row;
729
mime_types = nautilus_query_get_mime_types (query);
731
if (mime_types == NULL) {
735
for (i = 0; i < G_N_ELEMENTS (mime_type_groups); i++) {
736
if (all_group_types_in_list (mime_type_groups[i].mimetypes,
738
mime_types = remove_group_types_from_list (mime_type_groups[i].mimetypes,
741
row = nautilus_query_editor_add_row (editor,
742
NAUTILUS_QUERY_EDITOR_ROW_TYPE);
744
model = gtk_combo_box_get_model (GTK_COMBO_BOX (row->type_widget));
746
gtk_tree_model_iter_nth_child (model, &iter, NULL, i + 2);
747
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (row->type_widget),
752
for (l = mime_types; l != NULL; l = l->next) {
755
desc = g_content_type_get_description (mime_type);
760
row = nautilus_query_editor_add_row (editor,
761
NAUTILUS_QUERY_EDITOR_ROW_TYPE);
763
type_add_custom_type (row, mime_type, desc, &iter);
764
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (row->type_widget),
768
g_list_free_full (mime_types, g_free);
771
/* End of row types */
773
static NautilusQueryEditorRowType
774
get_next_free_type (NautilusQueryEditor *editor)
776
NautilusQueryEditorRow *row;
777
NautilusQueryEditorRowType type;
782
for (type = 0; type < NAUTILUS_QUERY_EDITOR_ROW_LAST; type++) {
784
for (l = editor->details->rows; l != NULL; l = l->next) {
786
if (row->type == type) {
795
return NAUTILUS_QUERY_EDITOR_ROW_TYPE;
799
remove_row_cb (GtkButton *clicked_button, NautilusQueryEditorRow *row)
801
NautilusQueryEditor *editor;
803
editor = row->editor;
804
editor->details->rows = g_list_remove (editor->details->rows, row);
807
nautilus_query_editor_changed (editor);
811
create_type_widgets (NautilusQueryEditorRow *row)
813
row->type_widget = row_type[row->type].create_widgets (row);
817
row_type_combo_changed_cb (GtkComboBox *combo_box, NautilusQueryEditorRow *row)
819
NautilusQueryEditorRowType type;
821
type = gtk_combo_box_get_active (combo_box);
823
if (type == row->type) {
827
if (row->type_widget != NULL) {
828
gtk_widget_destroy (row->type_widget);
829
row->type_widget = NULL;
834
create_type_widgets (row);
836
nautilus_query_editor_changed (row->editor);
839
static NautilusQueryEditorRow *
840
nautilus_query_editor_add_row (NautilusQueryEditor *editor,
841
NautilusQueryEditorRowType type)
843
GtkWidget *hbox, *button, *image, *combo;
845
NautilusQueryEditorRow *row;
848
row = g_new0 (NautilusQueryEditorRow, 1);
849
row->editor = editor;
852
/* create the toolbar and the box container for its contents */
853
row->toolbar = gtk_toolbar_new ();
854
gtk_box_pack_start (GTK_BOX (editor), row->toolbar, TRUE, TRUE, 0);
856
item = gtk_tool_item_new ();
857
gtk_tool_item_set_expand (item, TRUE);
858
gtk_toolbar_insert (GTK_TOOLBAR (row->toolbar), item, -1);
860
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
861
gtk_container_add (GTK_CONTAINER (item), hbox);
864
/* create the criterion selector combobox */
865
combo = gtk_combo_box_text_new ();
867
for (i = 0; i < NAUTILUS_QUERY_EDITOR_ROW_LAST; i++) {
868
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), gettext (row_type[i].name));
870
gtk_box_pack_start (GTK_BOX (hbox), combo, FALSE, FALSE, 0);
872
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), row->type);
874
editor->details->rows = g_list_append (editor->details->rows, row);
876
g_signal_connect (combo, "changed",
877
G_CALLBACK (row_type_combo_changed_cb), row);
879
create_type_widgets (row);
881
/* create the remove row button */
882
button = gtk_button_new ();
883
gtk_style_context_add_class (gtk_widget_get_style_context (button),
884
GTK_STYLE_CLASS_RAISED);
885
gtk_widget_set_tooltip_text (button,
886
_("Remove this criterion from the search"));
887
gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
889
image = gtk_image_new_from_icon_name ("window-close-symbolic",
891
gtk_container_add (GTK_CONTAINER (button), image);
893
g_signal_connect (button, "clicked",
894
G_CALLBACK (remove_row_cb), row);
896
/* show everything */
897
gtk_widget_show_all (row->toolbar);
903
add_new_row_cb (GtkButton *clicked_button, NautilusQueryEditor *editor)
905
nautilus_query_editor_add_row (editor, get_next_free_type (editor));
906
nautilus_query_editor_changed (editor);
910
nautilus_query_editor_init (NautilusQueryEditor *editor)
912
editor->details = G_TYPE_INSTANCE_GET_PRIVATE (editor, NAUTILUS_TYPE_QUERY_EDITOR,
913
NautilusQueryEditorDetails);
915
gtk_orientable_set_orientation (GTK_ORIENTABLE (editor), GTK_ORIENTATION_VERTICAL);
919
on_location_button_toggled (GtkToggleButton *button,
920
NautilusQueryEditor *editor)
922
nautilus_query_editor_changed (editor);
926
entry_key_press_event_cb (GtkWidget *widget,
928
NautilusQueryEditor *editor)
930
if (event->keyval == GDK_KEY_Down) {
931
nautilus_window_grab_focus (NAUTILUS_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (widget))));
937
setup_widgets (NautilusQueryEditor *editor)
940
GtkWidget *toolbar, *button_box, *hbox;
941
GtkWidget *button, *image;
943
/* create the toolbar and the box container for its contents */
944
toolbar = gtk_toolbar_new ();
945
gtk_style_context_add_class (gtk_widget_get_style_context (toolbar),
946
GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
947
gtk_box_pack_start (GTK_BOX (editor), toolbar, TRUE, TRUE, 0);
949
item = gtk_tool_item_new ();
950
gtk_tool_item_set_expand (item, TRUE);
951
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
953
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
954
gtk_container_add (GTK_CONTAINER (item), hbox);
956
/* create the search entry */
957
editor->details->entry = gtk_search_entry_new ();
958
gtk_box_pack_start (GTK_BOX (hbox), editor->details->entry, TRUE, TRUE, 0);
960
g_signal_connect (editor->details->entry, "key-press-event",
961
G_CALLBACK (entry_key_press_event_cb), editor);
962
g_signal_connect (editor->details->entry, "activate",
963
G_CALLBACK (entry_activate_cb), editor);
964
g_signal_connect (editor->details->entry, "changed",
965
G_CALLBACK (entry_changed_cb), editor);
967
/* create the Current/All Files selector */
968
editor->details->search_current_button = gtk_radio_button_new_with_label (NULL, _("Current"));
969
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (editor->details->search_current_button), FALSE);
970
editor->details->search_all_button = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (editor->details->search_current_button),
972
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (editor->details->search_all_button), FALSE);
974
/* connect to the signal only on one of the two, since they're mutually exclusive */
975
g_signal_connect (editor->details->search_current_button, "toggled",
976
G_CALLBACK (on_location_button_toggled), editor);
978
button_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
979
gtk_box_pack_start (GTK_BOX (hbox), button_box, FALSE, FALSE, 0);
980
gtk_style_context_add_class (gtk_widget_get_style_context (button_box),
981
GTK_STYLE_CLASS_LINKED);
982
gtk_style_context_add_class (gtk_widget_get_style_context (button_box),
983
GTK_STYLE_CLASS_RAISED);
985
gtk_box_pack_start (GTK_BOX (button_box), editor->details->search_current_button, FALSE, FALSE, 0);
986
gtk_box_pack_start (GTK_BOX (button_box), editor->details->search_all_button, FALSE, FALSE, 0);
988
/* finally, create the add new row button */
989
button = gtk_button_new ();
990
gtk_style_context_add_class (gtk_widget_get_style_context (button),
991
GTK_STYLE_CLASS_RAISED);
992
gtk_widget_set_tooltip_text (button,
993
_("Add a new criterion to this search"));
994
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
996
image = gtk_image_new_from_icon_name ("list-add-symbolic",
998
gtk_container_add (GTK_CONTAINER (button), image);
1000
g_signal_connect (button, "clicked",
1001
G_CALLBACK (add_new_row_cb), editor);
1003
/* show everything */
1004
gtk_widget_show_all (toolbar);
1008
nautilus_query_editor_changed_force (NautilusQueryEditor *editor, gboolean force_reload)
1010
NautilusQuery *query;
1012
if (editor->details->change_frozen) {
1016
query = nautilus_query_editor_get_query (editor);
1017
g_signal_emit (editor, signals[CHANGED], 0,
1018
query, force_reload);
1019
g_object_unref (query);
1023
nautilus_query_editor_changed (NautilusQueryEditor *editor)
1025
nautilus_query_editor_changed_force (editor, TRUE);
1029
add_location_to_query (NautilusQueryEditor *editor,
1030
NautilusQuery *query)
1034
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->details->search_all_button))) {
1035
uri = nautilus_get_home_directory_uri ();
1037
uri = g_strdup (editor->details->current_uri);
1040
nautilus_query_set_location (query, uri);
1045
nautilus_query_editor_get_query (NautilusQueryEditor *editor)
1047
const char *query_text;
1048
NautilusQuery *query;
1050
NautilusQueryEditorRow *row;
1052
if (editor == NULL || editor->details == NULL || editor->details->entry == NULL) {
1056
query_text = gtk_entry_get_text (GTK_ENTRY (editor->details->entry));
1058
query = nautilus_query_new ();
1059
nautilus_query_set_text (query, query_text);
1061
add_location_to_query (editor, query);
1063
for (l = editor->details->rows; l != NULL; l = l->next) {
1066
row_type[row->type].add_to_query (row, query);
1073
nautilus_query_editor_new (void)
1077
editor = g_object_new (NAUTILUS_TYPE_QUERY_EDITOR, NULL);
1078
setup_widgets (NAUTILUS_QUERY_EDITOR (editor));
1084
update_location (NautilusQueryEditor *editor)
1089
file = nautilus_file_get_by_uri (editor->details->current_uri);
1093
if (nautilus_file_is_home (file)) {
1094
name = g_strdup (_("Home"));
1096
name = nautilus_file_get_display_name (file);
1099
gtk_button_set_label (GTK_BUTTON (editor->details->search_current_button), name);
1102
label = gtk_bin_get_child (GTK_BIN (editor->details->search_current_button));
1103
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_MIDDLE);
1104
g_object_set (label, "max-width-chars", 30, NULL);
1106
nautilus_file_unref (file);
1111
nautilus_query_editor_set_location (NautilusQueryEditor *editor,
1114
g_free (editor->details->current_uri);
1115
editor->details->current_uri = g_file_get_uri (location);
1116
update_location (editor);
1120
update_rows (NautilusQueryEditor *editor,
1121
NautilusQuery *query)
1123
NautilusQueryEditorRowType type;
1125
/* if we were just created, set the rows from query,
1126
* otherwise, re-use the query setting we have already.
1128
if (query != NULL && editor->details->query == NULL) {
1129
for (type = 0; type < NAUTILUS_QUERY_EDITOR_ROW_LAST; type++) {
1130
row_type[type].add_rows_from_query (editor, query);
1132
} else if (query == NULL && editor->details->query != NULL) {
1133
g_list_free_full (editor->details->rows, (GDestroyNotify) row_destroy);
1134
editor->details->rows = NULL;
1139
nautilus_query_editor_set_query (NautilusQueryEditor *editor,
1140
NautilusQuery *query)
1143
char *current_text = NULL;
1145
if (query != NULL) {
1146
text = nautilus_query_get_text (query);
1150
text = g_strdup ("");
1153
editor->details->change_frozen = TRUE;
1155
current_text = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (editor->details->entry))));
1156
if (!g_str_equal (current_text, text)) {
1157
gtk_entry_set_text (GTK_ENTRY (editor->details->entry), text);
1159
g_free (current_text);
1161
g_free (editor->details->current_uri);
1162
editor->details->current_uri = NULL;
1164
update_rows (editor, query);
1165
g_clear_object (&editor->details->query);
1167
if (query != NULL) {
1168
editor->details->query = g_object_ref (query);
1169
editor->details->current_uri = nautilus_query_get_location (query);
1170
update_location (editor);
1173
editor->details->change_frozen = FALSE;