diff options
-rw-r--r-- | docs/reference/libcaja-extension/libcaja-extension-docs.xml | 1 | ||||
-rw-r--r-- | docs/reference/libcaja-extension/libcaja-extension-sections.txt | 16 | ||||
-rw-r--r-- | libcaja-extension/caja-widget-view-provider.c | 153 | ||||
-rw-r--r-- | libcaja-extension/caja-widget-view-provider.h | 79 | ||||
-rw-r--r-- | src/caja-view-as-action.c | 7 | ||||
-rw-r--r-- | src/caja-window-manage-views.c | 8 | ||||
-rw-r--r-- | src/file-manager/fm-widget-view.c | 90 |
7 files changed, 337 insertions, 17 deletions
diff --git a/docs/reference/libcaja-extension/libcaja-extension-docs.xml b/docs/reference/libcaja-extension/libcaja-extension-docs.xml index 777a846d..54a2476d 100644 --- a/docs/reference/libcaja-extension/libcaja-extension-docs.xml +++ b/docs/reference/libcaja-extension/libcaja-extension-docs.xml @@ -25,6 +25,7 @@ <xi:include href="xml/caja-menu-provider.xml" /> <xi:include href="xml/caja-menu.xml" /> <xi:include href="xml/caja-menu-item.xml" /> + <xi:include href="xml/caja-widget-view-provider.xml" /> <xi:include href="xml/caja-property-page-provider.xml" /> <xi:include href="xml/caja-property-page.xml" /> </chapter> diff --git a/docs/reference/libcaja-extension/libcaja-extension-sections.txt b/docs/reference/libcaja-extension/libcaja-extension-sections.txt index 1e899c4c..c2633cad 100644 --- a/docs/reference/libcaja-extension/libcaja-extension-sections.txt +++ b/docs/reference/libcaja-extension/libcaja-extension-sections.txt @@ -186,3 +186,19 @@ caja_module_list_types caja_module_list_pyfiles </SECTION> +<SECTION> +<FILE>caja-widget-view-provider</FILE> +CajaWidgetViewProvider +CajaWidgetViewProviderIface +caja_widget_view_provider_get_widget +caja_widget_view_provider_add_file +caja_widget_view_provider_set_uri +caja_widget_view_provider_set_window +caja_widget_view_provider_supports_uri +<SUBSECTION Standard> +CAJA_WIDGET_VIEW_PROVIDER +CAJA_IS_WIDGET_VIEW_PROVIDER +CAJA_TYPE_WIDGET_VIEW_PROVIDER +caja_widget_view_provider_get_type +CAJA_WIDGET_VIEW_PROVIDER_GET_IFACE +</SECTION> diff --git a/libcaja-extension/caja-widget-view-provider.c b/libcaja-extension/caja-widget-view-provider.c new file mode 100644 index 00000000..d678fb26 --- /dev/null +++ b/libcaja-extension/caja-widget-view-provider.c @@ -0,0 +1,153 @@ +/* vi: set sw=4 ts=4 wrap ai: */ +/* + * caja-widget-view-provider.c: This file is part of ____ + * + * Copyright (C) 2019 yetist <yetist@yetipc> + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * */ + +#include <config.h> +#include "caja-widget-view-provider.h" + +#include <glib-object.h> + +/** + * SECTION:caja-widget-view-provider + * @title: CajaWidgetViewProvider + * @short_description: Interface to provide widgets view. + * @include: libcaja-extension/caja-widget-view-provider.h + * + * #CajaWidgetViewProvider allows extension to provide widgets view + * in the file manager. + */ + +static void +caja_widget_view_provider_base_init (gpointer g_class) +{ +} + +GType +caja_widget_view_provider_get_type (void) +{ + static GType type = 0; + + if (!type) { + const GTypeInfo info = { + sizeof (CajaWidgetViewProviderIface), + caja_widget_view_provider_base_init, + NULL, + NULL, + NULL, + NULL, + 0, + 0, + NULL + }; + + type = g_type_register_static (G_TYPE_INTERFACE, + "CajaWidgetViewProvider", + &info, 0); + g_type_interface_add_prerequisite (type, G_TYPE_OBJECT); + } + + return type; +} + +/** + * caja_widget_view_provider_get_widget: + * @provider: a #CajaWidgetViewProvider + * + * + * Returns: + **/ +GtkWidget * +caja_widget_view_provider_get_widget (CajaWidgetViewProvider *provider) +{ + g_return_val_if_fail (CAJA_IS_WIDGET_VIEW_PROVIDER (provider), NULL); + g_return_val_if_fail (CAJA_WIDGET_VIEW_PROVIDER_GET_IFACE (provider)->get_widget != NULL, NULL); + + return CAJA_WIDGET_VIEW_PROVIDER_GET_IFACE (provider)->get_widget (provider); +} + +/** + * caja_widget_view_provider_add_file: + * @provider: a #CajaWidgetViewProvider + * @file: + * @directory: + * + * + **/ +void caja_widget_view_provider_add_file (CajaWidgetViewProvider *provider, CajaFile *file, CajaFile *directory) +{ + g_return_if_fail (CAJA_IS_WIDGET_VIEW_PROVIDER (provider)); + g_return_if_fail (CAJA_WIDGET_VIEW_PROVIDER_GET_IFACE (provider)->add_file != NULL); + + CAJA_WIDGET_VIEW_PROVIDER_GET_IFACE (provider)->add_file (provider, file, directory); +} + +/** + * caja_widget_view_provider_set_location: + * @provider: a #CajaWidgetViewProvider + * @uri: the URI of the location + * + * + **/ +void caja_widget_view_provider_set_location (CajaWidgetViewProvider *provider, const char *location) +{ + g_return_if_fail (CAJA_IS_WIDGET_VIEW_PROVIDER (provider)); + g_return_if_fail (CAJA_WIDGET_VIEW_PROVIDER_GET_IFACE (provider)->set_location != NULL); + + CAJA_WIDGET_VIEW_PROVIDER_GET_IFACE (provider)->set_location (provider, location); +} + +/** + * caja_widget_view_provider_set_window: + * @provider: a #CajaWidgetViewProvider + * @window: parent #GtkWindow + * + * + **/ +void caja_widget_view_provider_set_window (CajaWidgetViewProvider *provider, GtkWindow *window) +{ + g_return_if_fail (CAJA_IS_WIDGET_VIEW_PROVIDER (provider)); + g_return_if_fail (CAJA_WIDGET_VIEW_PROVIDER_GET_IFACE (provider)->set_window != NULL); + + CAJA_WIDGET_VIEW_PROVIDER_GET_IFACE (provider)->set_window (provider, window); +} + + +/** + * caja_widget_view_provider_supports_uri: + * @provider: a #CajaWidgetViewProvider + * @uri: + * @file_type: + * @mime_type: + * + * + * + * Return value: + **/ +gboolean caja_widget_view_provider_supports_uri (CajaWidgetViewProvider *provider, + const char *uri, + GFileType file_type, + const char *mime_type) +{ + g_return_val_if_fail (CAJA_IS_WIDGET_VIEW_PROVIDER (provider), FALSE); + g_return_val_if_fail (CAJA_WIDGET_VIEW_PROVIDER_GET_IFACE (provider)->supports_uri!= NULL, FALSE); + + return CAJA_WIDGET_VIEW_PROVIDER_GET_IFACE (provider)->supports_uri (provider, uri, file_type, mime_type); +} diff --git a/libcaja-extension/caja-widget-view-provider.h b/libcaja-extension/caja-widget-view-provider.h new file mode 100644 index 00000000..1bd21a5f --- /dev/null +++ b/libcaja-extension/caja-widget-view-provider.h @@ -0,0 +1,79 @@ +/* vi: set sw=4 ts=4 wrap ai: */ +/* + * caja-widget-view-provider.h: This file is part of ____ + * + * Copyright (C) 2019 yetist <yetist@yetipc> + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * */ + +#ifndef __CAJA_WIDGET_VIEW_PROVIDER_H__ +#define __CAJA_WIDGET_VIEW_PROVIDER_H__ 1 + +#include <glib-object.h> +#include <gtk/gtk.h> +#include "caja-file-info.h" +#include "caja-extension-types.h" + +G_BEGIN_DECLS + +#define CAJA_TYPE_WIDGET_VIEW_PROVIDER (caja_widget_view_provider_get_type ()) +#define CAJA_WIDGET_VIEW_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CAJA_TYPE_WIDGET_VIEW_PROVIDER, CajaWidgetViewProvider)) +#define CAJA_IS_WIDGET_VIEW_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CAJA_TYPE_WIDGET_VIEW_PROVIDER)) +#define CAJA_WIDGET_VIEW_PROVIDER_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), CAJA_TYPE_WIDGET_VIEW_PROVIDER, CajaWidgetViewProviderIface)) + +typedef struct _CajaWidgetViewProvider CajaWidgetViewProvider; +typedef struct _CajaWidgetViewProviderIface CajaWidgetViewProviderIface; + +/** + * CajaWidgetViewProviderIface: + * @g_iface: The parent interface. + * @get_widget: Returns a #GtkWidget. + * See caja_widget_view_provider_get_widget() for details. + * + * Interface for extensions to provide widgets view. + */ +struct _CajaWidgetViewProviderIface { + GTypeInterface g_iface; + + gboolean (*supports_uri) (CajaWidgetViewProvider *provider, + const char *uri, + GFileType file_type, + const char *mime_type); + GtkWidget* (*get_widget) (CajaWidgetViewProvider *provider); + void (*add_file) (CajaWidgetViewProvider *provider, CajaFile *file, CajaFile *directory); + void (*set_location) (CajaWidgetViewProvider *provider, const char *location); + void (*set_window) (CajaWidgetViewProvider *provider, GtkWindow *window); +}; + +/* Interface Functions */ +GType caja_widget_view_provider_get_type (void); + +GtkWidget *caja_widget_view_provider_get_widget (CajaWidgetViewProvider *provider); +void caja_widget_view_provider_add_file (CajaWidgetViewProvider *provider, + CajaFile *file, + CajaFile *directory); +void caja_widget_view_provider_set_location (CajaWidgetViewProvider *provider, + const char *location); +void caja_widget_view_provider_set_window (CajaWidgetViewProvider *provider, + GtkWindow *window); +gboolean caja_widget_view_provider_supports_uri (CajaWidgetViewProvider *provider, + const char *uri, + GFileType file_type, + const char *mime_type); +G_END_DECLS + +#endif /* __CAJA_WIDGET_VIEW_PROVIDER_H__ */ diff --git a/src/caja-view-as-action.c b/src/caja-view-as-action.c index f6040205..8437fcf9 100644 --- a/src/caja-view-as-action.c +++ b/src/caja-view-as-action.c @@ -145,6 +145,12 @@ view_as_changed_callback (CajaWindow *window, } } g_object_set_data (G_OBJECT (combo_box), "num viewers", GINT_TO_POINTER (index)); + + if (g_list_length (window->details->short_list_viewers) == 1) + { + selected_index = 0; + } + if (selected_index == -1) { const char *id; @@ -156,7 +162,6 @@ view_as_changed_callback (CajaWindow *window, _(info->view_combo_label)); selected_index = index; } - gtk_combo_box_set_active (combo_box, selected_index); if (g_list_length (window->details->short_list_viewers) == 1) { gtk_widget_hide(GTK_WIDGET(combo_box)); diff --git a/src/caja-window-manage-views.c b/src/caja-window-manage-views.c index 73e8b307..6bebb308 100644 --- a/src/caja-window-manage-views.c +++ b/src/caja-window-manage-views.c @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * Caja @@ -1309,9 +1309,9 @@ got_file_info_for_view_selection_callback (CajaFile *file, } else { - if (!report_callback (slot, error)) { - display_view_selection_failure (window, file, - location, error); + if (!report_callback (slot, error)) { + display_view_selection_failure (window, file, + location, error); } if (!gtk_widget_get_visible (GTK_WIDGET (window))) diff --git a/src/file-manager/fm-widget-view.c b/src/file-manager/fm-widget-view.c index c22643a8..4edf473e 100644 --- a/src/file-manager/fm-widget-view.c +++ b/src/file-manager/fm-widget-view.c @@ -34,14 +34,16 @@ #include <libcaja-private/caja-view-factory.h> #include <libcaja-private/caja-extensions.h> #include <libcaja-private/caja-module.h> +#include <libcaja-private/caja-metadata.h> #include <libcaja-extension/caja-widget-view-provider.h> #include "fm-widget-view.h" struct _FMWidgetView { - FMDirectoryView object; - int number_of_files; + FMDirectoryView object; + int number_of_files; + CajaWidgetViewProvider *provider; }; static GList *fm_widget_view_get_selection (FMDirectoryView *view); @@ -50,11 +52,12 @@ static void fm_widget_view_scroll_to_file (CajaView *view, co static void fm_widget_view_iface_init (CajaViewIface *iface); G_DEFINE_TYPE_WITH_CODE (FMWidgetView, fm_widget_view, FM_TYPE_DIRECTORY_VIEW, - G_IMPLEMENT_INTERFACE (CAJA_TYPE_VIEW, fm_widget_view_iface_init)); + G_IMPLEMENT_INTERFACE (CAJA_TYPE_VIEW, fm_widget_view_iface_init)); static void fm_widget_view_add_file (FMDirectoryView *view, CajaFile *file, CajaDirectory *directory) { + CajaFile *file_dir; static GTimer *timer = NULL; static gdouble cumu = 0, elaps; FM_WIDGET_VIEW (view)->number_of_files++; @@ -64,7 +67,7 @@ fm_widget_view_add_file (FMDirectoryView *view, CajaFile *file, CajaDirectory *d g_timer_start (timer); icon = caja_file_get_icon_surface (file, caja_get_icon_size_for_zoom_level (CAJA_ZOOM_LEVEL_STANDARD), - TRUE, gtk_widget_get_scale_factor (GTK_WIDGET(view)), 0); + TRUE, gtk_widget_get_scale_factor (GTK_WIDGET(view)), 0); elaps = g_timer_elapsed (timer, NULL); g_timer_stop (timer); @@ -73,12 +76,63 @@ fm_widget_view_add_file (FMDirectoryView *view, CajaFile *file, CajaDirectory *d cumu += elaps; g_message ("entire loading: %.3f, cumulative %.3f", elaps, cumu); + + FMWidgetView *widget_view; + + widget_view = FM_WIDGET_VIEW (view); + file_dir = caja_directory_get_corresponding_file (directory); + caja_widget_view_provider_add_file (widget_view->provider, file, file_dir); } static void fm_widget_view_begin_loading (FMDirectoryView *view) { + GtkWindow *window; + CajaFile *file; + gchar *uri; + GList *providers, *l; + char *mimetype; + GtkWidget *widget; + FMWidgetView *widget_view; + + widget_view = FM_WIDGET_VIEW (view); + + uri = fm_directory_view_get_uri (view); + file = caja_file_get_by_uri (uri); + mimetype = caja_file_get_mime_type (file); + + providers = caja_extensions_get_for_type (CAJA_TYPE_WIDGET_VIEW_PROVIDER); + for (l = providers; l != NULL; l = l->next) + { + CajaWidgetViewProvider *provider; + + provider = CAJA_WIDGET_VIEW_PROVIDER (l->data); + if (caja_widget_view_provider_supports_uri (provider, uri, + caja_file_get_file_type (file), + mimetype)) { + widget_view->provider = provider; + break; + } + } + + caja_module_extension_list_free (providers); + + if (widget_view->provider == NULL) { + return; + } + + caja_widget_view_provider_set_location (widget_view->provider, uri); + + widget = caja_widget_view_provider_get_widget (widget_view->provider); + gtk_container_add (GTK_CONTAINER(widget_view), widget); + + window = fm_directory_view_get_containing_window (view); + caja_widget_view_provider_set_window (widget_view->provider, window); + + g_print("uri in widget_view = %s, window=%p\n", uri, window); + + g_free (mimetype); } static void @@ -183,7 +237,7 @@ fm_widget_view_get_zoom_level (FMDirectoryView *view) static void fm_widget_view_zoom_to_level (FMDirectoryView *view, - CajaZoomLevel zoom_level) + CajaZoomLevel zoom_level) { } @@ -206,8 +260,8 @@ fm_widget_view_can_zoom_out (FMDirectoryView *view) static void fm_widget_view_start_renaming_file (FMDirectoryView *view, - CajaFile *file, - gboolean select_all) + CajaFile *file, + gboolean select_all) { } @@ -263,6 +317,8 @@ fm_widget_view_emblems_changed (FMDirectoryView *directory_view) static char * fm_widget_view_get_first_visible_file (CajaView *view) { + //FIXME: return string to tell caja we are ready. + return g_strdup("file:///tmp/a.txt"); return NULL; } @@ -347,8 +403,15 @@ fm_widget_view_iface_init (CajaViewIface *iface) static void fm_widget_view_init (FMWidgetView *widget_view) { - GtkWindow *window; - window = fm_directory_view_get_containing_window (FM_DIRECTORY_VIEW(widget_view)); + //GtkWidget *widget; + + //widget = gtk_app_chooser_widget_new ("text/plain"); + //gtk_app_chooser_widget_set_show_all (GTK_APP_CHOOSER_WIDGET(widget), TRUE); + + //gtk_container_add (GTK_CONTAINER(widget_view), widget); + //gtk_widget_show(widget); + + widget_view->provider = NULL; } static CajaView * @@ -379,11 +442,16 @@ fm_widget_view_supports_uri (const char *uri, CajaWidgetViewProvider *provider; provider = CAJA_WIDGET_VIEW_PROVIDER (l->data); - if (caja_widget_view_supports_uri (provider, uri, file_type, mime_type)) { + if (caja_widget_view_provider_supports_uri (provider, uri, file_type, mime_type)) { + //CajaFile *file; + //file = caja_file_get_by_uri (uri); + //caja_file_set_metadata (file, CAJA_METADATA_KEY_DEFAULT_VIEW, NULL, FM_WIDGET_VIEW_ID); + //caja_file_unref (file); result = TRUE; } } caja_module_extension_list_free (providers); + return result; } @@ -391,7 +459,6 @@ static CajaViewInfo fm_widget_view = { .id = FM_WIDGET_VIEW_ID, .view_combo_label = N_("Widget View"), - /* translators: this is used in the view menu */ .view_menu_label_with_mnemonic = N_("_Widget View"), .error_label = N_("The widget view encountered an error."), .startup_error_label = N_("The widget view encountered an error while starting up."), @@ -410,6 +477,5 @@ fm_widget_view_register (void) fm_widget_view.startup_error_label = _(fm_widget_view.startup_error_label); fm_widget_view.display_location_label = _(fm_widget_view.display_location_label); fm_widget_view.single_view = TRUE; - caja_view_factory_register (&fm_widget_view); } |