[gnome-commander] search: replacing obsoleted GnomeFileEntry with GtkFileChooserButton



commit d3db357b4de12d2b2bed1125c98f1973b3b140e2
Author: Piotr Eljasiak <epiotr src gnome org>
Date:   Mon May 2 19:39:53 2011 +0200

    search: replacing obsoleted GnomeFileEntry with GtkFileChooserButton

 src/gnome-cmd-search-dialog.cc |   69 +++++++++++++++++++++++----------------
 1 files changed, 41 insertions(+), 28 deletions(-)
---
diff --git a/src/gnome-cmd-search-dialog.cc b/src/gnome-cmd-search-dialog.cc
index e9f5c78..213c43a 100755
--- a/src/gnome-cmd-search-dialog.cc
+++ b/src/gnome-cmd-search-dialog.cc
@@ -29,6 +29,7 @@
 #include "gnome-cmd-file-list.h"
 #include "gnome-cmd-file-selector.h"
 #include "gnome-cmd-main-win.h"
+#include "gnome-cmd-con-list.h"
 #include "filter.h"
 #include "utils.h"
 
@@ -65,7 +66,6 @@ struct SearchData
 
     const gchar *name_pattern;              // the pattern that file names should match to end up in the file list
     const gchar *content_pattern;           // the pattern that the content of a file should match to end up in the file list
-    const gchar *dir;                       // the current dir of the search routine
 
     gboolean recurse;                       // should we recurse or just search in the selected directory?
     Filter::Type name_filter_type;
@@ -107,7 +107,6 @@ struct GnomeCmdSearchDialogPrivate
 
     GtkWidget *pattern_combo;
     GtkWidget *dir_browser;
-    GtkWidget *dir_entry;
     GtkWidget *find_text_combo;
     GtkWidget *find_text_check;
     GnomeCmdFileList *result_list;
@@ -357,7 +356,6 @@ static gpointer perform_search_operation (SearchData *data)
 
     gnome_cmd_dir_unref (data->start_dir);
     data->start_dir = NULL;
-    data->dir = NULL;
 
     data->search_done = TRUE;
 
@@ -486,7 +484,6 @@ static gboolean start_generic_search (GnomeCmdSearchDialog *dialog)
     data->dialog = dialog;
     data->name_pattern = gtk_combo_box_get_active_text (GTK_COMBO_BOX (dialog->priv->pattern_combo));
     data->content_pattern = gtk_combo_box_get_active_text (GTK_COMBO_BOX (dialog->priv->find_text_combo));
-    data->dir = gtk_entry_get_text (GTK_ENTRY (dialog->priv->dir_entry));
     data->context_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (data->dialog->priv->statusbar), "info");
     data->content_search = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->find_text_check));
     data->content_regex = NULL;
@@ -497,11 +494,43 @@ static gboolean start_generic_search (GnomeCmdSearchDialog *dialog)
     data->recurse = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->recurse_check));
     data->case_sens = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->case_check));
 
+    gchar *dir_str = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog->priv->dir_browser));
+    GnomeVFSURI *uri = gnome_vfs_uri_new (dir_str);
+    g_free (dir_str);
+
+    dir_str = gnome_vfs_unescape_string (gnome_vfs_uri_get_path (uri), NULL);
+    gchar *dir_path = g_strconcat (dir_str, G_DIR_SEPARATOR_S, NULL);
+    g_free (dir_str);
+
+    if (strncmp(dir_path, gnome_cmd_con_get_root_path (dialog->priv->con), dialog->priv->con->root_path->len)!=0)
+    {
+        if (!gnome_vfs_uri_is_local (uri))
+        {
+            gnome_cmd_show_message (GTK_WINDOW (dialog), stringify(g_strdup_printf (_("Failed to change directory outside of %s"),
+                                                                                    gnome_cmd_con_get_root_path (dialog->priv->con))));
+            gnome_vfs_uri_unref (uri);
+            g_free (dir_path);
+
+            data->search_done = TRUE;
+            data->stopped = TRUE;
+
+            return FALSE;
+        }
+        else
+            data->start_dir = gnome_cmd_dir_new (get_home_con (), gnome_cmd_con_create_path (get_home_con (), dir_path));
+    }
+    else
+        data->start_dir = gnome_cmd_dir_new (dialog->priv->con, gnome_cmd_con_create_path (dialog->priv->con, dir_path + dialog->priv->con->root_path->len));
+
+    gnome_cmd_dir_ref (data->start_dir);
+
+    gnome_vfs_uri_unref (uri);
+    g_free (dir_path);
+
     // save default settings
     gnome_cmd_data.search_defaults.default_profile.match_case = data->case_sens;
     gnome_cmd_data.search_defaults.default_profile.recursive = data->recurse;
     gnome_cmd_data.search_defaults.name_patterns.add(data->name_pattern);
-    gnome_cmd_data.search_defaults.directories.add(data->dir);
 
     if (data->content_search)
     {
@@ -529,10 +558,6 @@ static gboolean start_generic_search (GnomeCmdSearchDialog *dialog)
         data->search_mem = (gchar *) g_malloc (SEARCH_BUFFER_SIZE);
 
     // start the search
-    GnomeCmdPath *path = gnome_cmd_con_create_path (dialog->priv->con, data->dir);
-    data->start_dir = gnome_cmd_dir_new (dialog->priv->con, path);
-    gnome_cmd_dir_ref (data->start_dir);
-
     if (!data->pdata.mutex)
         data->pdata.mutex = g_mutex_new ();
 
@@ -794,17 +819,13 @@ static void gnome_cmd_search_dialog_init (GnomeCmdSearchDialog *dialog)
     gnome_cmd_dialog_editable_enters (GNOME_CMD_DIALOG (dialog), GTK_EDITABLE (gtk_bin_get_child (GTK_BIN (dialog->priv->pattern_combo))));
 
     // search in
-    dialog->priv->dir_browser = create_file_entry (window, "dir_browser", "");
+    dialog->priv->dir_browser =  gtk_file_chooser_button_new (_("Select Directory"), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
+    gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog->priv->dir_browser), FALSE);
+    gtk_widget_show (dialog->priv->dir_browser);
     label = create_label_with_mnemonic (window, _("Search _in: "), dialog->priv->dir_browser);
     table_add (table, label, 0, 1, GTK_FILL);
 
     table_add (table, dialog->priv->dir_browser, 1, 1, (GtkAttachOptions) (GTK_EXPAND|GTK_FILL));
-    if (!defaults.directories.empty())
-        gtk_combo_set_popdown_strings (
-            GTK_COMBO (gnome_file_entry_gnome_entry (GNOME_FILE_ENTRY (dialog->priv->dir_browser))),
-            defaults.directories.ents);
-
-    dialog->priv->dir_entry = gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY (dialog->priv->dir_browser));
 
     hbox = create_hbox (window, FALSE, 0);
 
@@ -912,23 +933,15 @@ static void gnome_cmd_search_dialog_class_init (GnomeCmdSearchDialogClass *klass
 
 GtkWidget *gnome_cmd_search_dialog_new (GnomeCmdDir *default_dir)
 {
-    gchar *new_path;
     GnomeCmdSearchDialog *dialog = (GnomeCmdSearchDialog *) g_object_new (GNOME_CMD_TYPE_SEARCH_DIALOG, NULL);
 
-    gchar *path = gnome_cmd_dir_is_local (default_dir) ? GNOME_CMD_FILE (default_dir)->get_real_path() : GNOME_CMD_FILE (default_dir)->get_path();
-    if (path[strlen(path)-1] != '/')
-    {
-        new_path = g_strdup_printf ("%s/", path);
-        g_free (path);
-    }
-    else
-        new_path = path;
+    dialog->priv->con = gnome_cmd_dir_get_connection (default_dir);
 
-    gtk_entry_set_text (GTK_ENTRY (dialog->priv->dir_entry), new_path);
+    gchar *uri = gnome_cmd_dir_get_uri_str (default_dir);
 
-    g_free (new_path);
+    gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog->priv->dir_browser), uri);
 
-    dialog->priv->con = gnome_cmd_dir_get_connection (default_dir);
+    g_free (uri);
 
     return GTK_WIDGET (dialog);
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]