]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkfilechooserutils.c
Place the search icon in the primary slot of the entry
[~andy/gtk] / gtk / gtkfilechooserutils.c
index 1f0847bf9dac0e06f2d63da4b6165e1944bf5360..43148aa9c34654a9f33749f6b70978e18d213d51 100644 (file)
@@ -14,9 +14,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "config.h"
@@ -25,7 +23,7 @@
 #include "gtkfilesystem.h"
 #include "gtktypebuiltins.h"
 #include "gtkintl.h"
-#include "gtkalias.h"
+
 
 static gboolean       delegate_set_current_folder     (GtkFileChooser    *chooser,
                                                       GFile             *file,
@@ -360,3 +358,86 @@ delegate_confirm_overwrite (GtkFileChooser    *chooser,
   g_signal_emit_by_name (data, "confirm-overwrite", &conf);
   return conf;
 }
+
+static GFile *
+get_parent_for_uri (const char *uri)
+{
+  GFile *file;
+  GFile *parent;
+
+  file = g_file_new_for_uri (uri);
+  parent = g_file_get_parent (file);
+
+  g_object_unref (file);
+  return parent;
+       
+}
+
+/* Extracts the parent folders out of the supplied list of GtkRecentInfo* items, and returns
+ * a list of GFile* for those unique parents.
+ */
+GList *
+_gtk_file_chooser_extract_recent_folders (GList *infos)
+{
+  GList *l;
+  GList *result;
+  GHashTable *folders;
+
+  result = NULL;
+
+  folders = g_hash_table_new (g_file_hash, (GEqualFunc) g_file_equal);
+
+  for (l = infos; l; l = l->next)
+    {
+      GtkRecentInfo *info = l->data;
+      const char *uri;
+      GFile *parent;
+
+      uri = gtk_recent_info_get_uri (info);
+      parent = get_parent_for_uri (uri);
+
+      if (parent)
+       {
+         if (!g_hash_table_lookup (folders, parent))
+           {
+             g_hash_table_insert (folders, parent, (gpointer) 1);
+             result = g_list_prepend (result, g_object_ref (parent));
+           }
+
+         g_object_unref (parent);
+       }
+    }
+
+  result = g_list_reverse (result);
+
+  g_hash_table_destroy (folders);
+
+  return result;
+}
+
+GSettings *
+_gtk_file_chooser_get_settings_for_widget (GtkWidget *widget)
+{
+  static GQuark file_chooser_settings_quark = 0;
+  GtkSettings *gtksettings;
+  GSettings *settings;
+
+  if (G_UNLIKELY (file_chooser_settings_quark == 0))
+    file_chooser_settings_quark = g_quark_from_static_string ("-gtk-file-chooser-settings");
+
+  gtksettings = gtk_widget_get_settings (widget);
+  settings = g_object_get_qdata (G_OBJECT (gtksettings), file_chooser_settings_quark);
+
+  if (G_UNLIKELY (settings == NULL))
+    {
+      settings = g_settings_new ("org.gtk.Settings.FileChooser");
+      g_settings_delay (settings);
+
+      g_object_set_qdata_full (G_OBJECT (gtksettings),
+                               file_chooser_settings_quark,
+                               settings,
+                               g_object_unref);
+    }
+
+  return settings;
+}