diff options
author | Wu Xiaotian <[email protected]> | 2019-07-20 22:59:42 +0800 |
---|---|---|
committer | raveit65 <[email protected]> | 2019-08-26 14:21:14 +0200 |
commit | 35876a8ad959dac4561e0c0fc753cb303c9c6283 (patch) | |
tree | f93a88a9abb2d7db89948ed8c51191e46015f283 /src/file-manager/fm-widget-view.c | |
parent | 9114911ff3350c7e11fe44ef52c36b095dacd5b5 (diff) | |
download | caja-35876a8ad959dac4561e0c0fc753cb303c9c6283.tar.bz2 caja-35876a8ad959dac4561e0c0fc753cb303c9c6283.tar.xz |
add CajaWidgetViewProvider docs
Diffstat (limited to 'src/file-manager/fm-widget-view.c')
-rw-r--r-- | src/file-manager/fm-widget-view.c | 90 |
1 files changed, 78 insertions, 12 deletions
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); } |