summaryrefslogtreecommitdiff
path: root/extensions/sendto
diff options
context:
space:
mode:
authorErnestas Kulik <ernestask@gnome.org>2018-02-01 13:24:21 +0200
committerErnestas Kulik <ernestask@gnome.org>2018-02-09 06:32:38 +0200
commitcdeedcd354d9d39aaa1a870228ad40a4066b2486 (patch)
tree916cdf1dc301b4de2c637f63a42d3f6da272969d /extensions/sendto
parent6934578ebf6e1959ad0634b73196242a30514095 (diff)
downloadnautilus-cdeedcd354d9d39aaa1a870228ad40a4066b2486.tar.gz
extensions: sendto: modernize code
This mainly removes the manual type definitions.
Diffstat (limited to 'extensions/sendto')
-rw-r--r--extensions/sendto/nautilus-nste.c103
-rw-r--r--extensions/sendto/nautilus-nste.h19
-rw-r--r--extensions/sendto/nautilus-sendto-module.c2
3 files changed, 39 insertions, 85 deletions
diff --git a/extensions/sendto/nautilus-nste.c b/extensions/sendto/nautilus-nste.c
index 5c2cc0e94..3313d9a32 100644
--- a/extensions/sendto/nautilus-nste.c
+++ b/extensions/sendto/nautilus-nste.c
@@ -26,55 +26,55 @@
#include <nautilus-extension.h>
#include "nautilus-nste.h"
+struct _NautilusNste
+{
+ GObject parent_instance;
+
+ gboolean nst_present;
+};
-static GObjectClass *parent_class;
+static void menu_provider_iface_init (NautilusMenuProviderInterface *iface);
+
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (NautilusNste, nautilus_nste, G_TYPE_OBJECT, 0,
+ G_IMPLEMENT_INTERFACE_DYNAMIC (NAUTILUS_TYPE_MENU_PROVIDER,
+ menu_provider_iface_init))
static void
sendto_callback (NautilusMenuItem *item,
gpointer user_data)
{
- GList *files, *scan;
- gchar *uri;
- GString *cmd;
+ GList *files;
+ g_autoptr (GString) command = NULL;
files = g_object_get_data (G_OBJECT (item), "files");
- cmd = g_string_new ("nautilus-sendto");
+ command = g_string_new ("nautilus-sendto");
- for (scan = files; scan; scan = scan->next)
+ for (GList *l = files; l != NULL; l = l->next)
{
- NautilusFileInfo *file = scan->data;
+ g_autofree char *uri = NULL;
- uri = nautilus_file_info_get_uri (file);
- g_string_append_printf (cmd, " \"%s\"", uri);
- g_free (uri);
- }
+ uri = nautilus_file_info_get_uri (l->data);
- g_spawn_command_line_async (cmd->str, NULL);
+ g_string_append_printf (command, " \"%s\"", uri);
+ }
- g_string_free (cmd, TRUE);
+ g_spawn_command_line_async (command->str, NULL);
}
static gboolean
check_available_mailer ()
{
- GAppInfo *app_info;
+ g_autoptr (GAppInfo) app_info = NULL;
app_info = g_app_info_get_default_for_uri_scheme ("mailto");
- if (app_info)
- {
- g_clear_object (&app_info);
- return TRUE;
- }
- else
- {
- return FALSE;
- }
+
+ return app_info != NULL;
}
static GList *
-nautilus_nste_get_file_items (NautilusMenuProvider *provider,
- GtkWidget *window,
- GList *files)
+get_file_items (NautilusMenuProvider *provider,
+ GtkWidget *window,
+ GList *files)
{
GList *items = NULL;
gboolean one_item;
@@ -128,65 +128,32 @@ nautilus_nste_get_file_items (NautilusMenuProvider *provider,
}
static void
-nautilus_nste_menu_provider_iface_init (NautilusMenuProviderInterface *iface)
+menu_provider_iface_init (NautilusMenuProviderInterface *iface)
{
- iface->get_file_items = nautilus_nste_get_file_items;
+ iface->get_file_items = get_file_items;
}
static void
-nautilus_nste_instance_init (NautilusNste *nste)
+nautilus_nste_init (NautilusNste *nste)
{
- char *path;
+ g_autofree char *path = NULL;
path = g_find_program_in_path ("nautilus-sendto");
nste->nst_present = (path != NULL);
- g_free (path);
}
static void
-nautilus_nste_class_init (NautilusNsteClass *class)
+nautilus_nste_class_init (NautilusNsteClass *klass)
{
- parent_class = g_type_class_peek_parent (class);
}
-static GType nste_type = 0;
-
-GType
-nautilus_nste_get_type (void)
+static void
+nautilus_nste_class_finalize (NautilusNsteClass *klass)
{
- return nste_type;
}
void
-nautilus_nste_register_type (GTypeModule *module)
+nautilus_nste_load (GTypeModule *module)
{
- static const GTypeInfo info =
- {
- sizeof (NautilusNsteClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) nautilus_nste_class_init,
- NULL,
- NULL,
- sizeof (NautilusNste),
- 0,
- (GInstanceInitFunc) nautilus_nste_instance_init,
- };
-
- static const GInterfaceInfo menu_provider_iface_info =
- {
- (GInterfaceInitFunc) nautilus_nste_menu_provider_iface_init,
- NULL,
- NULL
- };
-
- nste_type = g_type_module_register_type (module,
- G_TYPE_OBJECT,
- "NautilusNste",
- &info, 0);
-
- g_type_module_add_interface (module,
- nste_type,
- NAUTILUS_TYPE_MENU_PROVIDER,
- &menu_provider_iface_info);
+ nautilus_nste_register_type (module);
}
diff --git a/extensions/sendto/nautilus-nste.h b/extensions/sendto/nautilus-nste.h
index 1042bc9b9..f29885a20 100644
--- a/extensions/sendto/nautilus-nste.h
+++ b/extensions/sendto/nautilus-nste.h
@@ -27,24 +27,11 @@
G_BEGIN_DECLS
-#define NAUTILUS_TYPE_NSTE (nautilus_nste_get_type ())
-#define NAUTILUS_NSTE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), NAUTILUS_TYPE_NSTE, NautilusNste))
-#define NAUTILUS_IS_NSTE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), NAUTILUS_TYPE_NSTE))
+#define NAUTILUS_TYPE_NSTE (nautilus_nste_get_type ())
-typedef struct _NautilusNste NautilusNste;
-typedef struct _NautilusNsteClass NautilusNsteClass;
+G_DECLARE_FINAL_TYPE (NautilusNste, nautilus_nste, NAUTILUS, NSTE, GObject)
-struct _NautilusNste {
- GObject __parent;
- gboolean nst_present;
-};
-
-struct _NautilusNsteClass {
- GObjectClass __parent;
-};
-
-GType nautilus_nste_get_type (void);
-void nautilus_nste_register_type (GTypeModule *module);
+void nautilus_nste_load (GTypeModule *module);
G_END_DECLS
diff --git a/extensions/sendto/nautilus-sendto-module.c b/extensions/sendto/nautilus-sendto-module.c
index c21f0c877..524a34b6a 100644
--- a/extensions/sendto/nautilus-sendto-module.c
+++ b/extensions/sendto/nautilus-sendto-module.c
@@ -29,7 +29,7 @@
void
nautilus_module_initialize (GTypeModule *module)
{
- nautilus_nste_register_type (module);
+ nautilus_nste_load (module);
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");