[maemo-commits] [maemo-commits] r14750 - in projects/haf/trunk/hildon-fm: . debian hildon-fm

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Fri Nov 9 14:35:55 EET 2007
Author: marivoll
Date: 2007-11-09 14:35:53 +0200 (Fri, 09 Nov 2007)
New Revision: 14750

Modified:
   projects/haf/trunk/hildon-fm/ChangeLog
   projects/haf/trunk/hildon-fm/debian/changelog
   projects/haf/trunk/hildon-fm/hildon-fm/hildon-file-chooser-dialog.c
Log:
	* hildon-fm/hildon-file-chooser-dialog.c
	(update_folder_button_visibility): Update can-focus property of
	location eventbox as well.
	(on_location_hw_enter_pressed,
	hildon_file_chooser_dialog_location_pressed): Do nothing when
	folder button is not shown. (N74281)
	(show_info_note, show_gnome_vfs_result_for_folder_creation,
	create_folder): New, use gnome_vfs_make_directory instead of
	gtk_file_system_create_folder in order to get better error
	reporting.
	(handle_folder_popup): Use it (N71845).


Modified: projects/haf/trunk/hildon-fm/ChangeLog
===================================================================
--- projects/haf/trunk/hildon-fm/ChangeLog	2007-11-09 11:10:51 UTC (rev 14749)
+++ projects/haf/trunk/hildon-fm/ChangeLog	2007-11-09 12:35:53 UTC (rev 14750)
@@ -1,3 +1,17 @@
+2007-11-09  Marius Vollmer  <marius.vollmer at nokia.com>
+
+	* hildon-fm/hildon-file-chooser-dialog.c
+	(update_folder_button_visibility): Update can-focus property of
+	location eventbox as well.
+	(on_location_hw_enter_pressed,
+	hildon_file_chooser_dialog_location_pressed): Do nothing when
+	folder button is not shown. (N74281)
+	(show_info_note, show_gnome_vfs_result_for_folder_creation,
+	create_folder): New, use gnome_vfs_make_directory instead of
+	gtk_file_system_create_folder in order to get better error
+	reporting.
+	(handle_folder_popup): Use it (N71845).
+	
 2007-11-01  Marius Vollmer  <marius.vollmer at nokia.com>
 
 	Released 1.9.47

Modified: projects/haf/trunk/hildon-fm/debian/changelog
===================================================================
--- projects/haf/trunk/hildon-fm/debian/changelog	2007-11-09 11:10:51 UTC (rev 14749)
+++ projects/haf/trunk/hildon-fm/debian/changelog	2007-11-09 12:35:53 UTC (rev 14750)
@@ -1,6 +1,6 @@
 libhildonfm (1:1.9.48~unreleased) unstable; urgency=low
 
-  * 
+  * Fixes: NB#74281, NB#71845.
 
  -- Marius Vollmer <marius.vollmer at nokia.com>  Fri, 09 Nov 2007 13:10:02 +0200
 

Modified: projects/haf/trunk/hildon-fm/hildon-fm/hildon-file-chooser-dialog.c
===================================================================
--- projects/haf/trunk/hildon-fm/hildon-fm/hildon-file-chooser-dialog.c	2007-11-09 11:10:51 UTC (rev 14749)
+++ projects/haf/trunk/hildon-fm/hildon-fm/hildon-file-chooser-dialog.c	2007-11-09 12:35:53 UTC (rev 14750)
@@ -37,6 +37,8 @@
 #include <gtk/gtkfilechooserutils.h>
 #include <gtk/gtkfilesystem.h>
 
+#include <libgnomevfs/gnome-vfs.h>
+
 #include "hildon-file-selection.h"
 #include "hildon-file-chooser-dialog.h"
 #include "hildon-file-system-private.h"
@@ -127,6 +129,7 @@
     GtkWidget *caption_control_name;
     GtkWidget *caption_control_location;
     GtkWidget *entry_name;
+    GtkWidget *eventbox_location;
     GtkWidget *hbox_location, *image_location, *title_location;
     GtkWidget *extensions_combo;
     GtkFileChooserAction action;
@@ -1011,9 +1014,17 @@
     if (priv->should_show_folder_button
         && (priv->action == GTK_FILE_CHOOSER_ACTION_SAVE
             || priv->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER))
+      {
         gtk_widget_show(priv->folder_button);
+	g_object_set (G_OBJECT (priv->eventbox_location),
+		      "can-focus", TRUE, NULL);
+      }
     else
+      {
         gtk_widget_hide(priv->folder_button);
+	g_object_set (G_OBJECT (priv->eventbox_location),
+		      "can-focus", FALSE, NULL);
+      }
 }
 
 static void update_location_visibility(HildonFileChooserDialogPrivate *
@@ -1208,41 +1219,68 @@
     return dialog;
 }
 
-static void create_folder_callback(GtkFileSystemHandle *handle,
-    const GtkFilePath *path, const GError *error, gpointer data)
+static void
+show_info_note (GtkWindow *parent, const char *msg)
 {
-    HildonFileChooserDialog *self;
-    GtkDialog *dialog;
-    const gchar *message;
+  GtkWidget *dialog;
 
-    g_assert(HILDON_IS_FILE_CHOOSER_DIALOG(data));
-    self = HILDON_FILE_CHOOSER_DIALOG(data);
+  dialog = hildon_note_new_information (parent, msg);
+  gtk_dialog_run (GTK_DIALOG (dialog));
+  gtk_widget_destroy (dialog);
+}
 
-    g_assert(self->priv->create_folder_handle == handle);
+static void
+show_gnome_vfs_result_for_folder_creation (HildonFileChooserDialog *self,
+					   GnomeVFSResult result)
+{
+  /* XXX - We always use NULL as the parent for info banners.
+           Otherwise, they might get obscured by menus.
+  */
 
-    self->priv->create_folder_handle = NULL;
-    dialog = GTK_DIALOG(self);
+  if (result == GNOME_VFS_ERROR_FILE_EXISTS)
+    {
+      hildon_banner_show_information 
+	(NULL, NULL, HCS ("ckdg_ib_folder_already_exists"));
+    }
+  else if (result == GNOME_VFS_ERROR_NOT_SUPPORTED)
+    {
+      hildon_banner_show_information 
+	(NULL, NULL, _ ("sfil_ib_create_folder_not_allowed"));
+    } 
+  else if (result == GNOME_VFS_ERROR_NO_SPACE)
+    {
+      show_info_note (GTK_WINDOW (self),
+		      HCS ("sfil_ni_not_enough_memory"));
+    }
+  else
+    {
+      show_info_note (GTK_WINDOW (self),
+		      HCS ("sfil_ni_operation_failed"));
+    }
+}
 
-    if (error) {
-        if (g_error_matches(error, GTK_FILE_SYSTEM_ERROR,
-			    GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS))
-            message = HCS("ckdg_ib_folder_already_exists");
-        else
-            message = HCS("sfil_ni_operation_failed");
+static gboolean
+create_folder (HildonFileChooserDialog *self, const char *uri)
+{
+  GnomeVFSURI *vfs_uri;
+  GnomeVFSResult result;
 
-        hildon_banner_show_information (GTK_WIDGET(self), NULL, message);
-        hildon_file_chooser_dialog_select_text(self->priv);
-        gtk_dialog_set_response_sensitive(dialog, GTK_RESPONSE_OK, TRUE);
-    } else {
-        /* Fake response to close the dialog after folder is created */
-        gtk_dialog_response(dialog, HILDON_RESPONSE_FOLDER_CREATED);
+  vfs_uri = gnome_vfs_uri_new (uri);
+  if (!vfs_uri)
+    {
+      show_gnome_vfs_result_for_folder_creation (self,
+						 GNOME_VFS_ERROR_INVALID_URI);
+      return FALSE;
     }
 
-    /* This reference was added while setting up the callback */
-    g_object_unref(self);
+  result = gnome_vfs_make_directory_for_uri (vfs_uri, 0755);
+  if (result != GNOME_VFS_OK)
+    show_gnome_vfs_result_for_folder_creation (self, result);
+    
+  gnome_vfs_uri_unref (vfs_uri);
+  return result == GNOME_VFS_OK;
 }
 
-
 static void handle_folder_popup(HildonFileChooserDialog *self)
 {
   GtkFileSystem *backend;
@@ -1275,60 +1313,37 @@
 
   if (self->priv->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
   {
-    GtkFilePath *file_path = NULL;
-
     dialog = hildon_file_chooser_dialog_create_sub_dialog(self,
                GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER);
 
     while ((response = gtk_dialog_run(GTK_DIALOG(dialog))) == GTK_RESPONSE_OK)
-    {
-      uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog));
-      ULOG_INFO_F("About to create folder %s", uri);
+      {
+	g_free (uri);
+	
+	uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER(dialog));
+	ULOG_INFO_F("About to create folder %s", uri);
+	
+	if (create_folder (self, uri))
+	  break;
+      }
 
-      if (file_path)
-        gtk_file_path_free(file_path);
+    /* If we created a folder, change into it */
+    if (response == GTK_RESPONSE_OK)
+      {
+	GtkFilePath *path;
 
-      file_path = gtk_file_system_uri_to_path(backend, uri);
+        g_assert (uri != NULL);
+	path = gtk_file_system_uri_to_path (backend, uri);
 
-      /* There shouldn't be a way to invoke two simultaneous folder
-         creating actions */
-
-      HildonFileChooserDialogPrivate *sub_priv =
-        HILDON_FILE_CHOOSER_DIALOG (dialog)->priv;
-
-      if (sub_priv->create_folder_handle)
-        {
-	  gtk_file_system_cancel_operation (sub_priv->create_folder_handle);
-	  sub_priv->create_folder_handle = NULL;
-	}
-
-      /* Callback is quaranteed to be called, it unrefs the object data */
-      sub_priv->create_folder_handle =
-        gtk_file_system_create_folder (backend, file_path,
-                                       create_folder_callback,
-                                       g_object_ref(dialog));
-
-      /* Make OK button insensitive while folder operation is going */
-      gtk_dialog_set_response_sensitive
-        (GTK_DIALOG(dialog), GTK_RESPONSE_OK, FALSE);
-    }
-
-    /* If user cancelled the operation, we still can have handle
-     */
-    if (self->priv->create_folder_handle)
-      gtk_file_system_cancel_operation (self->priv->create_folder_handle);
-
-    /* If we created a folder, change into it */
-    if (response == HILDON_RESPONSE_FOLDER_CREATED)
-      {
-        g_assert(file_path != NULL);
         if (!hildon_file_chooser_dialog_set_current_folder
-          (GTK_FILE_CHOOSER(self), file_path, NULL) && uri) {
-			hildon_file_selection_move_cursor_to_uri (self->priv->filetree, 
-														uri);
-		}
+	    (GTK_FILE_CHOOSER(self), path, NULL))
+	  {
+	    hildon_file_selection_move_cursor_to_uri (self->priv->filetree, 
+						      uri);
+	  }
+	
+	gtk_file_path_free (path);
       }
-    gtk_file_path_free(file_path);
   }
   else
   {
@@ -1352,8 +1367,9 @@
   HildonFileChooserDialog *self = HILDON_FILE_CHOOSER_DIALOG(data);
   switch (event->keyval) {
   case GDK_Return:
-    if (self->priv->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
-	self->priv->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
+    if (self->priv->should_show_folder_button
+	&& (self->priv->action == GTK_FILE_CHOOSER_ACTION_SAVE
+            || self->priv->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER))
       handle_folder_popup(self);
     return TRUE;
   default:
@@ -1366,8 +1382,12 @@
 {
   HildonFileChooserDialog *self = HILDON_FILE_CHOOSER_DIALOG(data);
 
-  if (self->priv->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
-	self->priv->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
+  fprintf (stderr, "LOCATION_PRESSED %d\n",
+	   self->priv->should_show_folder_button);
+
+  if (self->priv->should_show_folder_button
+      && (self->priv->action == GTK_FILE_CHOOSER_ACTION_SAVE
+	  || self->priv->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER))
     handle_folder_popup(self);
 
   return FALSE;
@@ -1993,10 +2013,11 @@
     gtk_box_pack_start(GTK_BOX(priv->hbox_location), priv->title_location,
                        TRUE, TRUE, 0);
     eventbox = gtk_event_box_new();
+    priv->eventbox_location = eventbox;
     gtk_event_box_set_visible_window(GTK_EVENT_BOX(eventbox), FALSE);
     gtk_container_add(GTK_CONTAINER(eventbox), priv->hbox_location);
     gtk_widget_add_events(eventbox, GDK_BUTTON_PRESS_MASK);
-    g_object_set (G_OBJECT (eventbox), "can-focus", TRUE, NULL);
+    g_object_set (G_OBJECT (eventbox), "can-focus", FALSE, NULL);
   
     priv->caption_control_location =
       hildon_caption_new(size_group, _("sfil_fi_save_objects_items"),


More information about the maemo-commits mailing list