Commit 7e2605c6 authored by Ernestas Kulik's avatar Ernestas Kulik 🦑

general: refactor extension library

The changes include:

  * adding a single-include header and deprecating
    nautilus-extension-types.h and direct inclusions of individual
    headers;

  * type definition simplifications - this causes some breakages in
    nautilus-file, because NautilusFile used to be typedefed to
    NautilusFileInfo, and that is no longer possible, so the interface
    implementation was moved to static functions and the public
    NautilusFile API provides thin wrappers for them to maintain
    compatibility;

  * documentation cleanups and reorganization;

  * general build rule and code cleanups: mostly g_auto* sprinkled
    around and style changes (sorry)
parent 2128efcc
...@@ -14,19 +14,24 @@ ...@@ -14,19 +14,24 @@
<part> <part>
<title>API Reference</title> <title>API Reference</title>
<chapter>
<title>Core Classes</title>
<xi:include href="xml/nautilus-column.xml" />
<xi:include href="xml/nautilus-file-info.xml" />
<xi:include href="xml/nautilus-menu.xml" />
<xi:include href="xml/nautilus-menu-item.xml" />
<xi:include href="xml/nautilus-property-page.xml" />
</chapter>
<xi:include href="xml/nautilus-extension.xml" />
<chapter> <chapter>
<title>Extension Interfaces</title> <title>Extension Interfaces</title>
<xi:include href="xml/nautilus-column-provider.xml" /> <xi:include href="xml/nautilus-column-provider.xml" />
<xi:include href="xml/nautilus-column.xml" />
<xi:include href="xml/nautilus-extension-types.xml" />
<xi:include href="xml/nautilus-file-info.xml" />
<xi:include href="xml/nautilus-info-provider.xml" /> <xi:include href="xml/nautilus-info-provider.xml" />
<xi:include href="xml/nautilus-location-widget-provider.xml" /> <xi:include href="xml/nautilus-location-widget-provider.xml" />
<xi:include href="xml/nautilus-menu-provider.xml" /> <xi:include href="xml/nautilus-menu-provider.xml" />
<xi:include href="xml/nautilus-menu.xml" />
<xi:include href="xml/nautilus-menu-item.xml" />
<xi:include href="xml/nautilus-property-page-provider.xml" /> <xi:include href="xml/nautilus-property-page-provider.xml" />
<xi:include href="xml/nautilus-property-page.xml" />
</chapter> </chapter>
</part> </part>
......
<INCLUDE>nautilus-extension.h</INCLUDE>
<SECTION>
<FILE>nautilus-extension</FILE>
nautilus_module_initialize
nautilus_module_shutdown
nautilus_module_list_types
</SECTION>
<SECTION> <SECTION>
<FILE>nautilus-location-widget-provider</FILE> <FILE>nautilus-location-widget-provider</FILE>
NautilusLocationWidgetProvider NautilusLocationWidgetProvider
NautilusLocationWidgetProviderIface NautilusLocationWidgetProviderInterface
nautilus_location_widget_provider_get_widget nautilus_location_widget_provider_get_widget
<SUBSECTION Standard>
NAUTILUS_LOCATION_WIDGET_PROVIDER
NAUTILUS_IS_LOCATION_WIDGET_PROVIDER
NAUTILUS_TYPE_LOCATION_WIDGET_PROVIDER
nautilus_location_widget_provider_get_type
NAUTILUS_LOCATION_WIDGET_PROVIDER_GET_IFACE
</SECTION> </SECTION>
<SECTION> <SECTION>
<FILE>nautilus-menu-provider</FILE> <FILE>nautilus-menu-provider</FILE>
NautilusMenuProvider NautilusMenuProvider
NautilusMenuProviderIface NautilusMenuProviderInterface
nautilus_menu_provider_get_file_items nautilus_menu_provider_get_file_items
nautilus_menu_provider_get_background_items nautilus_menu_provider_get_background_items
nautilus_menu_provider_emit_items_updated_signal nautilus_menu_provider_emit_items_updated_signal
<SUBSECTION Standard>
NAUTILUS_MENU_PROVIDER
NAUTILUS_IS_MENU_PROVIDER
NAUTILUS_TYPE_MENU_PROVIDER
nautilus_menu_provider_get_type
NAUTILUS_MENU_PROVIDER_GET_IFACE
</SECTION> </SECTION>
<SECTION> <SECTION>
<FILE>nautilus-menu</FILE> <FILE>nautilus-menu</FILE>
NautilusMenuPrivate
NautilusMenu NautilusMenu
nautilus_menu_new nautilus_menu_new
nautilus_menu_append_item nautilus_menu_append_item
nautilus_menu_get_items nautilus_menu_get_items
<SUBSECTION Standard>
NAUTILUS_MENU
NAUTILUS_IS_MENU
NAUTILUS_TYPE_MENU
nautilus_menu_get_type
NAUTILUS_MENU_CLASS
NAUTILUS_IS_MENU_CLASS
NAUTILUS_MENU_GET_CLASS
</SECTION> </SECTION>
<SECTION> <SECTION>
...@@ -51,40 +39,20 @@ nautilus_menu_item_get_type ...@@ -51,40 +39,20 @@ nautilus_menu_item_get_type
nautilus_menu_item_new nautilus_menu_item_new
nautilus_menu_item_activate nautilus_menu_item_activate
nautilus_menu_item_set_submenu nautilus_menu_item_set_submenu
<SUBSECTION Standard>
NAUTILUS_TYPE_MENU_ITEM
NAUTILUS_MENU_ITEM
NAUTILUS_MENU_ITEM_CLASS
NAUTILUS_MENU_IS_ITEM
NAUTILUS_MENU_IS_ITEM_CLASS
NAUTILUS_MENU_ITEM_GET_CLASS
NautilusMenuItemDetails
</SECTION> </SECTION>
<SECTION> <SECTION>
<FILE>nautilus-column-provider</FILE> <FILE>nautilus-column-provider</FILE>
NautilusColumnProvider NautilusColumnProvider
NautilusColumnProviderIface NautilusColumnProviderInterface
nautilus_column_provider_get_columns nautilus_column_provider_get_columns
<SUBSECTION Standard>
NAUTILUS_COLUMN_PROVIDER
NAUTILUS_IS_COLUMN_PROVIDER
NAUTILUS_TYPE_COLUMN_PROVIDER
nautilus_column_provider_get_type
NAUTILUS_COLUMN_PROVIDER_GET_IFACE
</SECTION> </SECTION>
<SECTION> <SECTION>
<FILE>nautilus-property-page-provider</FILE> <FILE>nautilus-property-page-provider</FILE>
NautilusPropertyPageProvider NautilusPropertyPageProvider
NautilusPropertyPageProviderIface NautilusPropertyPageProviderInterface
nautilus_property_page_provider_get_pages nautilus_property_page_provider_get_pages
<SUBSECTION Standard>
NAUTILUS_PROPERTY_PAGE_PROVIDER
NAUTILUS_IS_PROPERTY_PAGE_PROVIDER
NAUTILUS_TYPE_PROPERTY_PAGE_PROVIDER
nautilus_property_page_provider_get_type
NAUTILUS_PROPERTY_PAGE_PROVIDER_GET_IFACE
</SECTION> </SECTION>
<SECTION> <SECTION>
...@@ -92,7 +60,7 @@ NAUTILUS_PROPERTY_PAGE_PROVIDER_GET_IFACE ...@@ -92,7 +60,7 @@ NAUTILUS_PROPERTY_PAGE_PROVIDER_GET_IFACE
NAUTILUS_FILE_DEFINED NAUTILUS_FILE_DEFINED
NautilusFile NautilusFile
NautilusFileInfo NautilusFileInfo
NautilusFileInfoIface NautilusFileInfoInterface
nautilus_file_info_create nautilus_file_info_create
nautilus_file_info_create_for_uri nautilus_file_info_create_for_uri
nautilus_file_info_lookup nautilus_file_info_lookup
...@@ -118,68 +86,28 @@ nautilus_file_info_add_emblem ...@@ -118,68 +86,28 @@ nautilus_file_info_add_emblem
nautilus_file_info_get_string_attribute nautilus_file_info_get_string_attribute
nautilus_file_info_add_string_attribute nautilus_file_info_add_string_attribute
nautilus_file_info_invalidate_extension_info nautilus_file_info_invalidate_extension_info
<SUBSECTION Standard>
NAUTILUS_FILE_INFO
NAUTILUS_IS_FILE_INFO
NAUTILUS_TYPE_FILE_INFO
nautilus_file_info_get_type
NAUTILUS_FILE_INFO_GET_IFACE
</SECTION> </SECTION>
<SECTION> <SECTION>
<FILE>nautilus-column</FILE> <FILE>nautilus-column</FILE>
NautilusColumn NautilusColumn
nautilus_column_new nautilus_column_new
<SUBSECTION Standard>
NAUTILUS_COLUMN
NAUTILUS_INFO_IS_COLUMN
NAUTILUS_TYPE_COLUMN
nautilus_column_get_type
NAUTILUS_COLUMN_CLASS
NAUTILUS_INFO_IS_COLUMN_CLASS
NAUTILUS_COLUMN_GET_CLASS
NautilusColumnDetails
</SECTION> </SECTION>
<SECTION> <SECTION>
<FILE>nautilus-info-provider</FILE> <FILE>nautilus-info-provider</FILE>
NautilusInfoProvider NautilusInfoProvider
NautilusInfoProviderIface NautilusInfoProviderInterface
NautilusInfoProviderUpdateComplete
NautilusOperationHandle NautilusOperationHandle
NautilusOperationResult NautilusOperationResult
nautilus_info_provider_update_file_info nautilus_info_provider_update_file_info
nautilus_info_provider_cancel_update nautilus_info_provider_cancel_update
nautilus_info_provider_update_complete_invoke nautilus_info_provider_update_complete_invoke
<SUBSECTION Standard>
NAUTILUS_TYPE_OPERATION_RESULT
nautilus_operation_result_get_type
NAUTILUS_INFO_PROVIDER
NAUTILUS_IS_INFO_PROVIDER
NAUTILUS_TYPE_INFO_PROVIDER
nautilus_info_provider_get_type
NAUTILUS_INFO_PROVIDER_GET_IFACE
</SECTION> </SECTION>
<SECTION> <SECTION>
<FILE>nautilus-property-page</FILE> <FILE>nautilus-property-page</FILE>
NautilusPropertyPage NautilusPropertyPage
nautilus_property_page_new nautilus_property_page_new
<SUBSECTION Standard>
NAUTILUS_PROPERTY_PAGE
NAUTILUS_IS_PROPERTY_PAGE
NAUTILUS_TYPE_PROPERTY_PAGE
nautilus_property_page_get_type
NAUTILUS_PROPERTY_PAGE_CLASS
NAUTILUS_IS_PROPERTY_PAGE_CLASS
NAUTILUS_PROPERTY_PAGE_GET_CLASS
NautilusPropertyPageDetails
</SECTION>
<SECTION>
<FILE>nautilus-extension-types</FILE>
nautilus_module_initialize
nautilus_module_shutdown
nautilus_module_list_types
</SECTION> </SECTION>
nautilus_extension_version = '1.4.0' nautilus_extension_version = '1.5.0'
libnautilus_extension_deprecated_headers = [
'nautilus-extension-types.h',
'nautilus-menu-item.h'
]
libnautilus_extension_headers = [ libnautilus_extension_headers = [
'nautilus-column-provider.h', 'nautilus-column-provider.h',
'nautilus-column.h', 'nautilus-column.h',
'nautilus-extension-types.h',
'nautilus-file-info.h', 'nautilus-file-info.h',
'nautilus-info-provider.h', 'nautilus-info-provider.h',
'nautilus-location-widget-provider.h', 'nautilus-location-widget-provider.h',
'nautilus-menu-item.h',
'nautilus-menu-provider.h', 'nautilus-menu-provider.h',
'nautilus-property-page-provider.h', 'nautilus-property-page-provider.h',
'nautilus-property-page.h', 'nautilus-property-page.h',
'nautilus-menu.h' 'nautilus-menu.h'
] ]
install_headers(
'nautilus-extension.h',
subdir: 'nautilus'
)
install_headers( install_headers(
libnautilus_extension_headers, libnautilus_extension_headers,
libnautilus_extension_deprecated_headers,
subdir: join_paths('nautilus', 'libnautilus-extension') subdir: join_paths('nautilus', 'libnautilus-extension')
) )
libnautilus_extension_sources = [ libnautilus_extension_sources = [
gnome.mkenums_simple(
'nautilus-extension-enum-types',
install_header: true,
install_dir: join_paths(includedir, 'nautilus', 'libnautilus-extension'),
sources: [
'nautilus-info-provider.h'
]
),
libnautilus_extension_headers,
'nautilus-column-provider.c', 'nautilus-column-provider.c',
'nautilus-column.c', 'nautilus-column.c',
'nautilus-extension-types.c', 'nautilus-extension.h',
'nautilus-extension-private.h', 'nautilus-extension-private.h',
'nautilus-file-info.c', 'nautilus-file-info.c',
'nautilus-info-provider.c', 'nautilus-info-provider.c',
...@@ -40,8 +57,13 @@ libnautilus_extension_deps = [ ...@@ -40,8 +57,13 @@ libnautilus_extension_deps = [
] ]
libnautilus_extension = shared_library( libnautilus_extension = shared_library(
'nautilus-extension', 'nautilus-extension', [
libnautilus_extension_sources, libnautilus_extension_deprecated_headers,
libnautilus_extension_sources,
],
c_args: [
'-DNAUTILUS_COMPILATION'
],
dependencies: libnautilus_extension_deps, dependencies: libnautilus_extension_deps,
include_directories: nautilus_include_dirs, include_directories: nautilus_include_dirs,
version: nautilus_extension_version, version: nautilus_extension_version,
...@@ -50,10 +72,10 @@ libnautilus_extension = shared_library( ...@@ -50,10 +72,10 @@ libnautilus_extension = shared_library(
gnome.generate_gir( gnome.generate_gir(
libnautilus_extension, libnautilus_extension,
sources: [ extra_args: [
libnautilus_extension_headers, '-DNAUTILUS_COMPILATION'
libnautilus_extension_sources
], ],
sources: libnautilus_extension_sources,
nsversion: '3.0', nsversion: '3.0',
namespace: 'Nautilus', namespace: 'Nautilus',
includes: [ includes: [
...@@ -61,6 +83,7 @@ gnome.generate_gir( ...@@ -61,6 +83,7 @@ gnome.generate_gir(
'Gio-2.0', 'Gio-2.0',
'GLib-2.0' 'GLib-2.0'
], ],
header: 'nautilus-extension.h',
install: true install: true
) )
......
...@@ -21,55 +21,24 @@ ...@@ -21,55 +21,24 @@
* *
*/ */
#include <config.h>
#include "nautilus-column-provider.h" #include "nautilus-column-provider.h"
#include <glib-object.h> G_DEFINE_INTERFACE (NautilusColumnProvider, nautilus_column_provider, G_TYPE_OBJECT)
/** /**
* SECTION:nautilus-column-provider * SECTION:nautilus-column-provider
* @title: NautilusColumnProvider * @title: NautilusColumnProvider
* @short_description: Interface to provide additional list view columns * @short_description: Interface to provide additional list view columns
* @include: libnautilus-extension/nautilus-column-provider.h
* *
* #NautilusColumnProvider allows extension to provide additional columns * #NautilusColumnProvider allows extension to provide additional columns
* in the file manager list view. * in the file manager list view.
*/ */
static void static void
nautilus_column_provider_base_init (gpointer g_class) nautilus_column_provider_default_init (NautilusColumnProviderInterface *klass)
{ {
} }
GType
nautilus_column_provider_get_type (void)
{
static GType type = 0;
if (!type)
{
const GTypeInfo info =
{
sizeof (NautilusColumnProviderIface),
nautilus_column_provider_base_init,
NULL,
NULL,
NULL,
NULL,
0,
0,
NULL
};
type = g_type_register_static (G_TYPE_INTERFACE,
"NautilusColumnProvider",
&info, 0);
g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
}
return type;
}
/** /**
* nautilus_column_provider_get_columns: * nautilus_column_provider_get_columns:
* @provider: a #NautilusColumnProvider * @provider: a #NautilusColumnProvider
...@@ -77,11 +46,15 @@ nautilus_column_provider_get_type (void) ...@@ -77,11 +46,15 @@ nautilus_column_provider_get_type (void)
* Returns: (element-type NautilusColumn) (transfer full): the provided #NautilusColumn objects * Returns: (element-type NautilusColumn) (transfer full): the provided #NautilusColumn objects
*/ */
GList * GList *
nautilus_column_provider_get_columns (NautilusColumnProvider *provider) nautilus_column_provider_get_columns (NautilusColumnProvider *self)
{ {
g_return_val_if_fail (NAUTILUS_IS_COLUMN_PROVIDER (provider), NULL); NautilusColumnProviderInterface *iface;
g_return_val_if_fail (NAUTILUS_COLUMN_PROVIDER_GET_IFACE (provider)->get_columns != NULL, NULL);
g_return_val_if_fail (NAUTILUS_IS_COLUMN_PROVIDER (self), NULL);
iface = NAUTILUS_COLUMN_PROVIDER_GET_IFACE (self);
g_return_val_if_fail (iface->get_columns != NULL, NULL);
return NAUTILUS_COLUMN_PROVIDER_GET_IFACE (provider)->get_columns return iface->get_columns (self);
(provider);
} }
...@@ -30,37 +30,40 @@ ...@@ -30,37 +30,40 @@
#ifndef NAUTILUS_COLUMN_PROVIDER_H #ifndef NAUTILUS_COLUMN_PROVIDER_H
#define NAUTILUS_COLUMN_PROVIDER_H #define NAUTILUS_COLUMN_PROVIDER_H
#if !defined (NAUTILUS_EXTENSION_H) && !defined (NAUTILUS_COMPILATION)
#warning "Only <nautilus-extension.h> should be included directly."
#endif
#include <glib-object.h> #include <glib-object.h>
#include "nautilus-extension-types.h"
#include "nautilus-column.h"
G_BEGIN_DECLS G_BEGIN_DECLS
#define NAUTILUS_TYPE_COLUMN_PROVIDER (nautilus_column_provider_get_type ()) #define NAUTILUS_TYPE_COLUMN_PROVIDER (nautilus_column_provider_get_type ())
#define NAUTILUS_COLUMN_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NAUTILUS_TYPE_COLUMN_PROVIDER, NautilusColumnProvider))
#define NAUTILUS_IS_COLUMN_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NAUTILUS_TYPE_COLUMN_PROVIDER)) G_DECLARE_INTERFACE (NautilusColumnProvider, nautilus_column_provider,
#define NAUTILUS_COLUMN_PROVIDER_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), NAUTILUS_TYPE_COLUMN_PROVIDER, NautilusColumnProviderIface)) NAUTILUS, COLUMN_PROVIDER,
GObject)
typedef struct _NautilusColumnProvider NautilusColumnProvider; /* For compatibility reasons, remove this once you start introducing breaking changes. */
typedef struct _NautilusColumnProviderIface NautilusColumnProviderIface; typedef NautilusColumnProviderInterface NautilusColumnProviderIface;
/** /**
* NautilusColumnProviderIface: * NautilusColumnProviderInterface:
* @g_iface: The parent interface. * @g_iface: The parent interface.
* @get_columns: Returns a #GList of #NautilusColumn. * @get_columns: Returns a #GList of #NautilusColumn.
* See nautilus_column_provider_get_columns() for details. * See nautilus_column_provider_get_columns() for details.
* *
* Interface for extensions to provide additional list view columns. * Interface for extensions to provide additional list view columns.
*/ */
struct _NautilusColumnProviderIface { struct _NautilusColumnProviderInterface
GTypeInterface g_iface; {
GTypeInterface g_iface;
GList *(*get_columns) (NautilusColumnProvider *provider); GList *(*get_columns) (NautilusColumnProvider *provider);
}; };
/* Interface Functions */ /* Interface Functions */
GType nautilus_column_provider_get_type (void); GList *nautilus_column_provider_get_columns (NautilusColumnProvider *provider);
GList *nautilus_column_provider_get_columns (NautilusColumnProvider *provider);
G_END_DECLS G_END_DECLS
......
...@@ -21,8 +21,6 @@ ...@@ -21,8 +21,6 @@
* *
*/ */
#include <config.h>
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "nautilus-column.h" #include "nautilus-column.h"
...@@ -39,8 +37,10 @@ enum ...@@ -39,8 +37,10 @@ enum
LAST_PROP LAST_PROP
}; };
struct _NautilusColumnDetails struct _NautilusColumn
{ {
GObject parent_instance;
char *name; char *name;
GQuark attribute; GQuark attribute;
char *label; char *label;
...@@ -55,7 +55,6 @@ G_DEFINE_TYPE (NautilusColumn, nautilus_column, G_TYPE_OBJECT); ...@@ -55,7 +55,6 @@ G_DEFINE_TYPE (NautilusColumn, nautilus_column, G_TYPE_OBJECT);
* SECTION:nautilus-column * SECTION:nautilus-column
* @title: NautilusColumn * @title: NautilusColumn
* @short_description: List view column descriptor object * @short_description: List view column descriptor object
* @include: libnautilus-extension/nautilus-column.h
* *
* #NautilusColumn is an object that describes a column in the file manager * #NautilusColumn is an object that describes a column in the file manager
* list view. Extensions can provide #NautilusColumn by registering a * list view. Extensions can provide #NautilusColumn by registering a
...@@ -112,43 +111,43 @@ nautilus_column_get_property (GObject *object, ...@@ -112,43 +111,43 @@ nautilus_column_get_property (GObject *object,
{ {
case PROP_NAME: case PROP_NAME:
{ {
g_value_set_string (value, column->details->name); g_value_set_string (value, column->name);
} }
break; break;
case PROP_ATTRIBUTE: case PROP_ATTRIBUTE:
{ {
g_value_set_string (value, g_quark_to_string (column->details->attribute)); g_value_set_string (value, g_quark_to_string (column->attribute));
} }
break; break;
case PROP_ATTRIBUTE_Q: case PROP_ATTRIBUTE_Q:
{ {
g_value_set_uint (value, column->details->attribute); g_value_set_uint (value, column->attribute);
} }
break; break;
case PROP_LABEL: case PROP_LABEL:
{ {
g_value_set_string (value, column->details->label); g_value_set_string (value, column->label);
} }
break; break;
case PROP_DESCRIPTION: case PROP_DESCRIPTION:
{ {
g_value_set_string (value, column->details->description); g_value_set_string (value, column->description);
} }
break; break;
case PROP_XALIGN: case PROP_XALIGN:
{ {
g_value_set_float (value, column->details->xalign); g_value_set_float (value, column->xalign);
} }
break; break;
case PROP_DEFAULT_SORT_ORDER: case PROP_DEFAULT_SORT_ORDER:
{ {
g_value_set_enum (value, column->details->default_sort_order); g_value_set_enum (value, column->default_sort_order);
} }
break; break;
...@@ -174,15 +173,15 @@ nautilus_column_set_property (GObject *object, ...@@ -174,15 +173,15 @@ nautilus_column_set_property (GObject *object,
{ {
case PROP_NAME: case PROP_NAME:
{ {
g_free (column->details->name); g_free (column->name);
column->details->name = g_strdup (g_value_get_string (value)); column->name = g_strdup (g_value_get_string (value));
g_object_notify (object, "name"); g_object_notify (object, "name");
} }
break; break;
case PROP_ATTRIBUTE: case PROP_ATTRIBUTE:
{ {
column->details->attribute = g_quark_from_string (g_value_get_string (value)); column->attribute = g_quark_from_string (g_value_get_string (value));
g_object_notify (object, "attribute"); g_object_notify (object, "attribute");
g_object_notify (object, "attribute_q"); g_object_notify (object, "attribute_q");
} }
...@@ -190,30 +189,30 @@ nautilus_column_set_property (GObject *object, ...@@ -190,30 +189,30 @@ nautilus_column_set_property (GObject *object,
case PROP_LABEL: case PROP_LABEL:
{ {
g_free (column->details->label); g_free (column->label);
column->details->label = g_strdup (g_value_get_string (value)); column->label = g_strdup (g_value_get_string (value));