Commit ceac4cca authored by Alexander Larsson's avatar Alexander Larsson Committed by Alexander Larsson

Add async x-content type getter, change sync one to only read the cached

2008-03-05  Alexander Larsson  <alexl@redhat.com>

        * libnautilus-private/nautilus-autorun.[ch]:
	Add async x-content type getter, change sync one
	to only read the cached value
	
        * src/file-manager/fm-directory-view.c:
        * src/nautilus-window-manage-views.c:
	Get x-content type async


svn path=/trunk/; revision=13884
parent b25b5655
2008-03-05 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-autorun.[ch]:
Add async x-content type getter, change sync one
to only read the cached value
* src/file-manager/fm-directory-view.c:
* src/nautilus-window-manage-views.c:
Get x-content type async
2008-03-04 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-file.c (nautilus_file_set_display_name):
......
......@@ -1269,20 +1269,80 @@ nautilus_autorun (GMount *mount, NautilusAutorunOpenWindow open_window_func, gpo
data);
}
typedef struct {
NautilusAutorunGetContent callback;
gpointer user_data;
} GetContentTypesData;
static void
get_types_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
GetContentTypesData *data;
char **types;
data = user_data;
types = _g_mount_guess_content_type_finish (G_MOUNT (source_object), res, NULL);
if (data->callback) {
data->callback (types, data->user_data);
}
g_strfreev (types);
g_free (data);
}
void
nautilus_autorun_get_x_content_types_for_mount_async (GMount *mount,
NautilusAutorunGetContent callback,
GCancellable *cancellable,
gpointer user_data)
{
char **cached;
GetContentTypesData *data;
if (mount == NULL) {
if (callback) {
callback (NULL, user_data);
}
return;
}
cached = g_object_get_data (G_OBJECT (mount), "content-type-cache");
if (cached != NULL) {
if (callback) {
callback (cached, user_data);
}
return;
}
data = g_new (GetContentTypesData, 1);
data->callback = callback;
data->user_data = user_data;
_g_mount_guess_content_type_async (mount,
FALSE,
cancellable,
get_types_cb,
data);
}
char **
nautilus_autorun_get_x_content_types_for_mount (GMount *mount,
gboolean force_rescan)
nautilus_autorun_get_cached_x_content_types_for_mount (GMount *mount)
{
char **cached;
if (mount == NULL) {
return NULL;
}
/* since we always guess the content type at mount type, we're guaranteed
* to get the cached results
*
* TODO: Really? what if we didn't mount the mount ourself?
*/
return _g_mount_guess_content_type (mount, force_rescan, NULL);
cached = g_object_get_data (G_OBJECT (mount), "content-type-cache");
if (cached != NULL) {
return g_strdupv (cached);
}
return NULL;
}
......
......@@ -66,6 +66,7 @@ typedef void (*NautilusAutorunComboBoxChanged) (gboolean selected_ask,
gpointer user_data);
typedef void (*NautilusAutorunOpenWindow) (GMount *mount, gpointer user_data);
typedef void (*NautilusAutorunGetContent) (char **content, gpointer user_data);
void nautilus_autorun_prepare_combo_box (GtkWidget *combo_box,
const char *x_content_type,
......@@ -79,8 +80,12 @@ void nautilus_autorun_get_preferences (const char *x_content_type, gboolean *pre
void nautilus_autorun (GMount *mount, NautilusAutorunOpenWindow open_window_func, gpointer user_data);
char **nautilus_autorun_get_x_content_types_for_mount (GMount *mount,
gboolean force_rescan);
char **nautilus_autorun_get_cached_x_content_types_for_mount (GMount *mount);
void nautilus_autorun_get_x_content_types_for_mount_async (GMount *mount,
NautilusAutorunGetContent callback,
GCancellable *cancellable,
gpointer user_data);
void nautilus_autorun_launch_for_mount (GMount *mount, GAppInfo *app_info);
......
......@@ -4180,7 +4180,21 @@ add_application_to_open_with_menu (FMDirectoryView *view,
}
static void
add_x_content_apps (NautilusFile *file, GList **applications)
get_x_content_async_callback (char **content,
gpointer user_data)
{
FMDirectoryView *view;
view = FM_DIRECTORY_VIEW (user_data);
if (view->details->window != NULL) {
schedule_update_menus (view);
}
g_object_unref (view);
}
static void
add_x_content_apps (FMDirectoryView *view, NautilusFile *file, GList **applications)
{
GMount *mount;
char **x_content_types;
......@@ -4194,8 +4208,7 @@ add_x_content_apps (NautilusFile *file, GList **applications)
return;
}
x_content_types = nautilus_autorun_get_x_content_types_for_mount (mount, FALSE);
x_content_types = nautilus_autorun_get_cached_x_content_types_for_mount (mount);
if (x_content_types != NULL) {
for (n = 0; x_content_types[n] != NULL; n++) {
char *x_content_type = x_content_types[n];
......@@ -4205,6 +4218,12 @@ add_x_content_apps (NautilusFile *file, GList **applications)
*applications = g_list_concat (*applications, app_info_for_x_content_type);
}
g_strfreev (x_content_types);
} else {
nautilus_autorun_get_x_content_types_for_mount_async (mount,
get_x_content_async_callback,
NULL,
g_object_ref (view));
}
g_object_unref (mount);
......@@ -4261,7 +4280,7 @@ reset_open_with_menu (FMDirectoryView *view, GList *selection)
}
if (g_list_length (selection) == 1) {
add_x_content_apps (NAUTILUS_FILE (selection->data), &applications);
add_x_content_apps (view, NAUTILUS_FILE (selection->data), &applications);
}
......
......@@ -1297,7 +1297,7 @@ add_extension_extra_widgets (NautilusWindow *window, GFile *location)
}
static void
nautilus_window_show_x_content_bar (NautilusWindow *window, GMount *mount, char **x_content_types)
nautilus_window_show_x_content_bar (NautilusWindow *window, GMount *mount, const char **x_content_types)
{
unsigned int n;
......@@ -1339,8 +1339,33 @@ nautilus_window_show_trash_bar (NautilusWindow *window)
typedef struct {
NautilusWindow *window;
GCancellable *cancellable;
GMount *mount;
} FindMountData;
static void
found_content_type_cb (const char **x_content_types, FindMountData *data)
{
NautilusWindow *window;
if (g_cancellable_is_cancelled (data->cancellable)) {
goto out;
}
window = data->window;
if (x_content_types != NULL && x_content_types[0] != NULL) {
nautilus_window_show_x_content_bar (window, data->mount, x_content_types);
update_extra_location_widgets_visibility (window);
}
window->details->find_mount_cancellable = NULL;
out:
g_object_unref (data->mount);
g_object_unref (data->cancellable);
g_free (data);
}
static void
found_mount_cb (GObject *source_object,
GAsyncResult *res,
......@@ -1349,7 +1374,6 @@ found_mount_cb (GObject *source_object,
FindMountData *data = user_data;
GMount *mount;
NautilusWindow *window;
char **x_content_types;
if (g_cancellable_is_cancelled (data->cancellable)) {
goto out;
......@@ -1361,14 +1385,12 @@ found_mount_cb (GObject *source_object,
res,
NULL);
if (mount != NULL) {
x_content_types = nautilus_autorun_get_x_content_types_for_mount (mount, FALSE);
if (x_content_types != NULL && x_content_types[0] != NULL) {
nautilus_window_show_x_content_bar (window, mount, x_content_types);
update_extra_location_widgets_visibility (window);
}
g_strfreev (x_content_types);
g_object_unref (mount);
data->mount = mount;
nautilus_autorun_get_x_content_types_for_mount_async (mount,
(NautilusAutorunGetContent)found_content_type_cb,
data->cancellable,
data);
return;
}
window->details->find_mount_cancellable = NULL;
......@@ -1455,6 +1477,7 @@ update_for_new_location (NautilusWindow *window)
data = g_new (FindMountData, 1);
data->window = window;
data->cancellable = g_cancellable_new ();
data->mount = NULL;
window->details->find_mount_cancellable = data->cancellable;
g_file_find_enclosing_mount_async (window->details->location,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment