summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWu Xiaotian <[email protected]>2019-07-31 16:51:14 +0800
committerraveit65 <[email protected]>2022-07-20 21:40:42 +0200
commitfc8b2d8e076086b8943db496af5cb2ef6f0b610f (patch)
tree56c38995d0badcad5a52d4da758f6ff70637b529
parent67eea2e0711ec51b919c9abcdde0f0abc4071538 (diff)
downloadcaja-fc8b2d8e076086b8943db496af5cb2ef6f0b610f.tar.bz2
caja-fc8b2d8e076086b8943db496af5cb2ef6f0b610f.tar.xz
add new interface
-rw-r--r--docs/reference/libcaja-extension/libcaja-extension-sections.txt10
-rw-r--r--libcaja-extension/caja-widget-view-provider.c32
-rw-r--r--libcaja-extension/caja-widget-view-provider.h53
-rw-r--r--src/file-manager/fm-widget-view.c103
-rw-r--r--src/file-manager/fm-widget-view.h6
5 files changed, 107 insertions, 97 deletions
diff --git a/docs/reference/libcaja-extension/libcaja-extension-sections.txt b/docs/reference/libcaja-extension/libcaja-extension-sections.txt
index c2633cad..c1802243 100644
--- a/docs/reference/libcaja-extension/libcaja-extension-sections.txt
+++ b/docs/reference/libcaja-extension/libcaja-extension-sections.txt
@@ -190,11 +190,15 @@ caja_module_list_pyfiles
<FILE>caja-widget-view-provider</FILE>
CajaWidgetViewProvider
CajaWidgetViewProviderIface
+caja_widget_view_provider_supports_uri
caja_widget_view_provider_get_widget
-caja_widget_view_provider_add_file
-caja_widget_view_provider_set_uri
+caja_widget_view_provider_set_location
caja_widget_view_provider_set_window
-caja_widget_view_provider_supports_uri
+caja_widget_view_provider_set_uri
+caja_widget_view_provider_add_file
+caja_widget_view_provider_get_first_visible_file
+caja_widget_view_provider_get_item_count
+caja_widget_view_provider_clear
<SUBSECTION Standard>
CAJA_WIDGET_VIEW_PROVIDER
CAJA_IS_WIDGET_VIEW_PROVIDER
diff --git a/libcaja-extension/caja-widget-view-provider.c b/libcaja-extension/caja-widget-view-provider.c
index d678fb26..44b33001 100644
--- a/libcaja-extension/caja-widget-view-provider.c
+++ b/libcaja-extension/caja-widget-view-provider.c
@@ -1,9 +1,8 @@
/* vi: set sw=4 ts=4 wrap ai: */
/*
- * caja-widget-view-provider.c: This file is part of ____
- *
- * Copyright (C) 2019 yetist <yetist@yetipc>
+ * caja-widget-view-provider.c: This file is part of caja.
*
+ * Copyright (C) 2019 Wu Xiaotian <[email protected]>
*
* 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
@@ -86,8 +85,8 @@ caja_widget_view_provider_get_widget (CajaWidgetViewProvider *provider)
/**
* caja_widget_view_provider_add_file:
* @provider: a #CajaWidgetViewProvider
- * @file:
- * @directory:
+ * @file:
+ * @directory:
*
*
**/
@@ -129,6 +128,29 @@ void caja_widget_view_provider_set_window (CajaWidgetViewProvider *provider, Gtk
CAJA_WIDGET_VIEW_PROVIDER_GET_IFACE (provider)->set_window (provider, window);
}
+guint caja_widget_view_provider_get_item_count (CajaWidgetViewProvider *provider)
+{
+ g_return_val_if_fail (CAJA_IS_WIDGET_VIEW_PROVIDER (provider), 0);
+ g_return_val_if_fail (CAJA_WIDGET_VIEW_PROVIDER_GET_IFACE (provider)->get_item_count != NULL, 0);
+
+ return CAJA_WIDGET_VIEW_PROVIDER_GET_IFACE (provider)->get_item_count (provider);
+}
+
+gchar* caja_widget_view_provider_get_first_visible_file (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_first_visible_file != NULL, NULL);
+
+ return CAJA_WIDGET_VIEW_PROVIDER_GET_IFACE (provider)->get_first_visible_file (provider);
+}
+
+void caja_widget_view_provider_clear (CajaWidgetViewProvider *provider)
+{
+ g_return_if_fail (CAJA_IS_WIDGET_VIEW_PROVIDER (provider));
+ g_return_if_fail (CAJA_WIDGET_VIEW_PROVIDER_GET_IFACE (provider)->clear != NULL);
+
+ CAJA_WIDGET_VIEW_PROVIDER_GET_IFACE (provider)->clear (provider);
+}
/**
* caja_widget_view_provider_supports_uri:
diff --git a/libcaja-extension/caja-widget-view-provider.h b/libcaja-extension/caja-widget-view-provider.h
index 1bd21a5f..e232d3b8 100644
--- a/libcaja-extension/caja-widget-view-provider.h
+++ b/libcaja-extension/caja-widget-view-provider.h
@@ -1,9 +1,8 @@
/* vi: set sw=4 ts=4 wrap ai: */
/*
- * caja-widget-view-provider.h: This file is part of ____
- *
- * Copyright (C) 2019 yetist <yetist@yetipc>
+ * caja-widget-view-provider.h: This file is part of caja.
*
+ * Copyright (C) 2019 Wu Xiaotian <[email protected]>
*
* 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
@@ -49,31 +48,37 @@ typedef struct _CajaWidgetViewProviderIface CajaWidgetViewProviderIface;
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);
+ 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);
+ guint (*get_item_count) (CajaWidgetViewProvider *provider);
+ gchar* (*get_first_visible_file) (CajaWidgetViewProvider *provider);
+ void (*clear) (CajaWidgetViewProvider *provider);
};
/* Interface Functions */
-GType caja_widget_view_provider_get_type (void);
+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);
+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);
+guint caja_widget_view_provider_get_item_count (CajaWidgetViewProvider *provider);
+gchar* caja_widget_view_provider_get_first_visible_file (CajaWidgetViewProvider *provider);
+void caja_widget_view_provider_clear (CajaWidgetViewProvider *provider);
+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/file-manager/fm-widget-view.c b/src/file-manager/fm-widget-view.c
index 4edf473e..de678a85 100644
--- a/src/file-manager/fm-widget-view.c
+++ b/src/file-manager/fm-widget-view.c
@@ -1,8 +1,8 @@
/* vi: set sw=4 ts=4 wrap ai: */
/*
- * fm-widget-view.c: This file is part of ____
+ * fm-widget-view.c: This file is part of caja.
*
- * Copyright (C) 2019 yetist <yetist@yetibook>
+ * Copyright (C) 2019 Wu Xiaotian <[email protected]>
*
*
* This program is free software; you can redistribute it and/or modify
@@ -41,9 +41,8 @@
struct _FMWidgetView
{
- FMDirectoryView object;
- int number_of_files;
- CajaWidgetViewProvider *provider;
+ FMDirectoryView object;
+ CajaWidgetViewProvider *provider;
};
static GList *fm_widget_view_get_selection (FMDirectoryView *view);
@@ -57,34 +56,18 @@ G_DEFINE_TYPE_WITH_CODE (FMWidgetView, fm_widget_view, FM_TYPE_DIRECTORY_VIEW,
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++;
- cairo_surface_t *icon;
-
- if (!timer) timer = g_timer_new ();
-
- 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);
-
- elaps = g_timer_elapsed (timer, NULL);
- g_timer_stop (timer);
-
- g_object_unref (icon);
-
- cumu += elaps;
- g_message ("entire loading: %.3f, cumulative %.3f", elaps, cumu);
-
FMWidgetView *widget_view;
+ CajaFile *file_dir;
widget_view = FM_WIDGET_VIEW (view);
+ g_return_if_fail (FM_IS_WIDGET_VIEW(view));
+ g_return_if_fail (CAJA_IS_WIDGET_VIEW_PROVIDER (widget_view->provider));
+
file_dir = caja_directory_get_corresponding_file (directory);
caja_widget_view_provider_add_file (widget_view->provider, file, file_dir);
+ caja_file_unref (file_dir);
}
-
static void
fm_widget_view_begin_loading (FMDirectoryView *view)
{
@@ -115,31 +98,36 @@ fm_widget_view_begin_loading (FMDirectoryView *view)
break;
}
}
-
+ caja_file_unref (file);
+ g_free (mimetype);
caja_module_extension_list_free (providers);
if (widget_view->provider == NULL) {
+ g_free (uri);
return;
}
caja_widget_view_provider_set_location (widget_view->provider, uri);
+ g_free (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
fm_widget_view_clear (FMDirectoryView *view)
{
-}
+ FMWidgetView *widget_view;
+ widget_view = FM_WIDGET_VIEW (view);
+ g_return_if_fail (FM_IS_WIDGET_VIEW(view));
+ g_return_if_fail (CAJA_IS_WIDGET_VIEW_PROVIDER (widget_view->provider));
+
+ caja_widget_view_provider_clear (widget_view->provider);
+}
static void
fm_widget_view_file_changed (FMDirectoryView *view, CajaFile *file, CajaDirectory *directory)
@@ -158,7 +146,6 @@ fm_widget_view_get_selection (FMDirectoryView *view)
return NULL;
}
-
static GList *
fm_widget_view_get_selection_for_file_transfer (FMDirectoryView *view)
{
@@ -168,13 +155,25 @@ fm_widget_view_get_selection_for_file_transfer (FMDirectoryView *view)
static guint
fm_widget_view_get_item_count (FMDirectoryView *view)
{
- return FM_WIDGET_VIEW (view)->number_of_files;
+ FMWidgetView *widget_view;
+
+ widget_view = FM_WIDGET_VIEW (view);
+ g_return_val_if_fail (FM_IS_WIDGET_VIEW(view), 0);
+ g_return_val_if_fail (CAJA_IS_WIDGET_VIEW_PROVIDER (widget_view->provider), 0);
+
+ return caja_widget_view_provider_get_item_count (widget_view->provider);
}
static gboolean
fm_widget_view_is_empty (FMDirectoryView *view)
{
- return FM_WIDGET_VIEW (view)->number_of_files == 0;
+ FMWidgetView *widget_view;
+
+ widget_view = FM_WIDGET_VIEW (view);
+ g_return_val_if_fail (FM_IS_WIDGET_VIEW(view), TRUE);
+ g_return_val_if_fail (CAJA_IS_WIDGET_VIEW_PROVIDER (widget_view->provider), TRUE);
+
+ return caja_widget_view_provider_get_item_count (widget_view->provider) == 0;
}
static void
@@ -185,8 +184,6 @@ fm_widget_view_end_file_changes (FMDirectoryView *view)
static void
fm_widget_view_remove_file (FMDirectoryView *view, CajaFile *file, CajaDirectory *directory)
{
- FM_WIDGET_VIEW (view)->number_of_files--;
- g_assert (FM_WIDGET_VIEW (view)->number_of_files >= 0);
}
static void
@@ -208,7 +205,6 @@ fm_widget_view_reveal_selection (FMDirectoryView *view)
static void
fm_widget_view_merge_menus (FMDirectoryView *view)
{
- //EEL_CALL_PARENT (FM_DIRECTORY_VIEW_CLASS, merge_menus, (view));
FM_DIRECTORY_VIEW_CLASS (fm_widget_view_parent_class)->merge_menus(view);
}
@@ -270,7 +266,6 @@ fm_widget_view_click_policy_changed (FMDirectoryView *directory_view)
{
}
-
static int
fm_widget_view_compare_files (FMDirectoryView *view, CajaFile *file1, CajaFile *file2)
{
@@ -302,10 +297,6 @@ fm_widget_view_end_loading (FMDirectoryView *view,
static void
fm_widget_view_finalize (GObject *object)
{
- FMWidgetView *widget_view;
-
- widget_view = FM_WIDGET_VIEW (object);
-
G_OBJECT_CLASS (fm_widget_view_parent_class)->finalize (object);
}
@@ -317,14 +308,17 @@ 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;
+ FMWidgetView *widget_view;
+
+ widget_view = FM_WIDGET_VIEW (view);
+ g_return_val_if_fail (FM_IS_WIDGET_VIEW(view), NULL);
+ g_return_val_if_fail (CAJA_IS_WIDGET_VIEW_PROVIDER (widget_view->provider), NULL);
+
+ return caja_widget_view_provider_get_first_visible_file (widget_view->provider);
}
static void
-fm_widget_view_scroll_to_file (CajaView *view,
- const char *uri)
+fm_widget_view_scroll_to_file (CajaView *view, const char *uri)
{
}
@@ -403,14 +397,6 @@ fm_widget_view_iface_init (CajaViewIface *iface)
static void
fm_widget_view_init (FMWidgetView *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;
}
@@ -443,10 +429,6 @@ fm_widget_view_supports_uri (const char *uri,
provider = CAJA_WIDGET_VIEW_PROVIDER (l->data);
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;
}
}
@@ -470,7 +452,6 @@ static CajaViewInfo fm_widget_view =
void
fm_widget_view_register (void)
{
- fm_widget_view.id = fm_widget_view.id;
fm_widget_view.view_combo_label = _(fm_widget_view.view_combo_label);
fm_widget_view.view_menu_label_with_mnemonic = _(fm_widget_view.view_menu_label_with_mnemonic);
fm_widget_view.error_label = _(fm_widget_view.error_label);
diff --git a/src/file-manager/fm-widget-view.h b/src/file-manager/fm-widget-view.h
index 6ff29699..7b12df92 100644
--- a/src/file-manager/fm-widget-view.h
+++ b/src/file-manager/fm-widget-view.h
@@ -1,9 +1,8 @@
/* vi: set sw=4 ts=4 wrap ai: */
/*
- * fm-widget-view.h: This file is part of ____
- *
- * Copyright (C) 2019 yetist <yetist@yetibook>
+ * fm-widget-view.h: This file is part of caja.
*
+ * Copyright (C) 2019 Wu Xiaotian <[email protected]>
*
* 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
@@ -31,7 +30,6 @@ G_BEGIN_DECLS
#define FM_TYPE_WIDGET_VIEW (fm_widget_view_get_type ())
G_DECLARE_FINAL_TYPE (FMWidgetView, fm_widget_view, FM, WIDGET_VIEW, FMDirectoryView)
-
FMWidgetView* fm_widget_view_new (void);
void fm_widget_view_register (void);