[maemo-commits] [maemo-commits] r14786 - projects/haf/trunk/hildon-fm/hildon-fm
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Fri Nov 16 15:26:44 EET 2007
- Previous message: [maemo-commits] r14785 - in projects/haf/trunk/hildon-fm: . debian
- Next message: [maemo-commits] r14787 - projects/haf/trunk/hildon-fm
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: marivoll
Date: 2007-11-16 15:26:42 +0200 (Fri, 16 Nov 2007)
New Revision: 14786
Modified:
projects/haf/trunk/hildon-fm/hildon-fm/hildon-file-chooser-dialog.c
Log:
* hildon-fm/hildon-file-chooser-dialog.c (show_info_note,
show_gnome_vfs_result_for_folder_creation, create_folder,
handle_folder_popup): Reverted changed from 2007-11-09. We have
to use gtk_file_system_create_folder since folder creation must
work with any backend, not just the GnomeVFS one (N75960).
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-16 13:26:23 UTC (rev 14785)
+++ projects/haf/trunk/hildon-fm/hildon-fm/hildon-file-chooser-dialog.c 2007-11-16 13:26:42 UTC (rev 14786)
@@ -37,8 +37,6 @@
#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"
@@ -1219,66 +1217,38 @@
return dialog;
}
-static void
-show_info_note (GtkWindow *parent, const char *msg)
+static void create_folder_callback(GtkFileSystemHandle *handle,
+ const GtkFilePath *path, const GError *error, gpointer data)
{
- GtkWidget *dialog;
+ HildonFileChooserDialog *self;
+ GtkDialog *dialog;
+ const gchar *message;
- dialog = hildon_note_new_information (parent, msg);
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
-}
+ g_assert(HILDON_IS_FILE_CHOOSER_DIALOG(data));
+ self = HILDON_FILE_CHOOSER_DIALOG(data);
-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.
- */
+ g_assert(self->priv->create_folder_handle == handle);
- 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"));
- }
-}
+ self->priv->create_folder_handle = NULL;
+ dialog = GTK_DIALOG(self);
-static gboolean
-create_folder (HildonFileChooserDialog *self, const char *uri)
-{
- GnomeVFSURI *vfs_uri;
- GnomeVFSResult result;
+ 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");
- 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;
+ 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);
}
- 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;
+ /* This reference was added while setting up the callback */
+ g_object_unref(self);
}
static void handle_folder_popup(HildonFileChooserDialog *self)
@@ -1313,37 +1283,59 @@
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)
{
- g_free (uri);
-
- uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER(dialog));
+ 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);
+
+ file_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 == GTK_RESPONSE_OK)
+ if (response == HILDON_RESPONSE_FOLDER_CREATED)
{
- GtkFilePath *path;
-
- g_assert (uri != NULL);
- path = gtk_file_system_uri_to_path (backend, uri);
-
+ g_assert(file_path != NULL);
if (!hildon_file_chooser_dialog_set_current_folder
- (GTK_FILE_CHOOSER(self), path, NULL))
- {
- hildon_file_selection_move_cursor_to_uri (self->priv->filetree,
- uri);
- }
-
- gtk_file_path_free (path);
+ (GTK_FILE_CHOOSER(self), file_path, NULL) && uri) {
+ hildon_file_selection_move_cursor_to_uri (self->priv->filetree,
+ uri);
+ }
}
+ gtk_file_path_free(file_path);
}
else
{
- Previous message: [maemo-commits] r14785 - in projects/haf/trunk/hildon-fm: . debian
- Next message: [maemo-commits] r14787 - projects/haf/trunk/hildon-fm
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
