From a4fa7f2644ec54eb624878d42a92b737403ec583 Mon Sep 17 00:00:00 2001 From: Stefano Karapetsas Date: Mon, 3 Nov 2014 10:18:22 +0100 Subject: Add 'Set as wallpaper' extension --- wallpaper/Makefile.am | 17 +++ wallpaper/caja-wallpaper-command.c | 50 +++++++ wallpaper/caja-wallpaper-extension.c | 186 ++++++++++++++++++++++++++ wallpaper/caja-wallpaper-extension.h | 52 +++++++ wallpaper/libcaja-wallpaper.caja-extension.in | 4 + 5 files changed, 309 insertions(+) create mode 100644 wallpaper/Makefile.am create mode 100644 wallpaper/caja-wallpaper-command.c create mode 100644 wallpaper/caja-wallpaper-extension.c create mode 100644 wallpaper/caja-wallpaper-extension.h create mode 100644 wallpaper/libcaja-wallpaper.caja-extension.in (limited to 'wallpaper') diff --git a/wallpaper/Makefile.am b/wallpaper/Makefile.am new file mode 100644 index 0000000..bca84d2 --- /dev/null +++ b/wallpaper/Makefile.am @@ -0,0 +1,17 @@ +AM_CPPFLAGS = $(CAJA_CFLAGS) + +caja_extensiondir = $(CAJA_EXTENSION_DIR) +caja_extension_LTLIBRARIES = libcaja-wallpaper.la + +libcaja_wallpaper_la_SOURCES = \ + caja-wallpaper-extension.c\ + caja-wallpaper-extension.h\ + caja-wallpaper-command.c + +libcaja_wallpaper_la_LDFLAGS = -module -avoid-version +libcaja_wallpaper_la_LIBADD = $(CAJA_LIBS) + +extensiondir = $(datadir)/caja/extensions +extension_in_files = libcaja-wallpaper.caja-extension.in +extension_DATA = $(extension_in_files:.caja-extension.in=.caja-extension) +%.caja-extension: %.caja-extension.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*.po) ; $(AM_V_GEN) LC_ALL=C $(INTLTOOL_MERGE) -d -u -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< $@ diff --git a/wallpaper/caja-wallpaper-command.c b/wallpaper/caja-wallpaper-command.c new file mode 100644 index 0000000..ddc861f --- /dev/null +++ b/wallpaper/caja-wallpaper-command.c @@ -0,0 +1,50 @@ +/* + * Caja Wallpaper extension + * + * Copyright (C) 2005 Adam Israel + * Copyright (C) 2014 Stefano Karapetsas + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Authors: Adam Israel + * Stefano Karapetsas + */ + +#include +#include +#include +#include +#include "caja-wallpaper-extension.h" + +void +caja_module_initialize (GTypeModule*module) +{ + caja_cwe_register_type (module); +} + +void +caja_module_shutdown (void) +{ +} + +void +caja_module_list_types (const GType **types, int *num_types) +{ + static GType type_list[1]; + + type_list[0] = CAJA_TYPE_CWE; + *types = type_list; + *num_types = 1; +} diff --git a/wallpaper/caja-wallpaper-extension.c b/wallpaper/caja-wallpaper-extension.c new file mode 100644 index 0000000..f274a20 --- /dev/null +++ b/wallpaper/caja-wallpaper-extension.c @@ -0,0 +1,186 @@ +/* + * Caja Wallpaper extension + * + * Copyright (C) 2005 Adam Israel + * Copyright (C) 2014 Stefano Karapetsas + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Authors: Adam Israel + * Stefano Karapetsas + */ + +#include +#include +#include +#include +#include +#include +#include +#include "caja-wallpaper-extension.h" + +#define WP_SCHEMA "org.mate.background" +#define WP_FILE_KEY "picture-filename" + +static GObjectClass *parent_class; + +static void +set_wallpaper_callback (CajaMenuItem *item, + gpointer user_data) +{ + GList *files; + GSettings *settings; + GError *err; + CajaFileInfo *file; + gchar *uri; + gchar *filename; + + files = g_object_get_data (G_OBJECT (item), "files"); + file = files->data; + + uri = caja_file_info_get_uri (file); + filename = g_filename_from_uri(uri, NULL, NULL); + + settings = g_settings_new (WP_SCHEMA); + + g_settings_set_string (settings, WP_FILE_KEY, filename); + + g_object_unref (settings); + g_free (filename); + g_free (uri); + +} + +static gboolean +is_image (CajaFileInfo *file) +{ + gchar *mimeType; + gboolean isImage; + + mimeType = caja_file_info_get_mime_type (file); + + isImage = g_str_has_prefix (caja_file_info_get_mime_type (file), "image/"); + + g_free (mimeType); + + return isImage; +} + + +static GList * +caja_cwe_get_file_items (CajaMenuProvider *provider, + GtkWidget *window, + GList *files) +{ + GList *items = NULL; + GList *scan; + gboolean one_item; + CajaMenuItem *item; + + for (scan = files; scan; scan = scan->next) { + CajaFileInfo *file = scan->data; + gchar *scheme; + gboolean local; + + scheme = caja_file_info_get_uri_scheme (file); + local = strncmp (scheme, "file", 4) == 0; + g_free (scheme); + + if (!local) + return NULL; + } + + one_item = (files != NULL) && (files->next == NULL); + if (one_item && is_image ((CajaFileInfo *)files->data) && + !caja_file_info_is_directory ((CajaFileInfo *)files->data)) { + item = caja_menu_item_new ("CajaCwe::sendto", + _("Set as wallpaper..."), + _("Set image as the current wallpaper..."), + NULL); + g_signal_connect (item, + "activate", + G_CALLBACK (set_wallpaper_callback), + provider); + g_object_set_data_full (G_OBJECT (item), + "files", + caja_file_info_list_copy (files), + (GDestroyNotify) caja_file_info_list_free); + items = g_list_append (items, item); + } + return items; +} + + +static void +caja_cwe_menu_provider_iface_init (CajaMenuProviderIface *iface) +{ + iface->get_file_items = caja_cwe_get_file_items; +} + + +static void +caja_cwe_instance_init (CajaCwe *cwe) +{ +} + + +static void +caja_cwe_class_init (CajaCweClass *class) +{ + parent_class = g_type_class_peek_parent (class); +} + + +static GType cwe_type = 0; + + +GType +caja_cwe_get_type (void) +{ + return cwe_type; +} + + +void +caja_cwe_register_type (GTypeModule *module) +{ + static const GTypeInfo info = { + sizeof (CajaCweClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) caja_cwe_class_init, + NULL, + NULL, + sizeof (CajaCwe), + 0, + (GInstanceInitFunc) caja_cwe_instance_init, + }; + + static const GInterfaceInfo menu_provider_iface_info = { + (GInterfaceInitFunc) caja_cwe_menu_provider_iface_init, + NULL, + NULL + }; + + cwe_type = g_type_module_register_type (module, + G_TYPE_OBJECT, + "CajaCwe", + &info, 0); + + g_type_module_add_interface (module, + cwe_type, + CAJA_TYPE_MENU_PROVIDER, + &menu_provider_iface_info); +} diff --git a/wallpaper/caja-wallpaper-extension.h b/wallpaper/caja-wallpaper-extension.h new file mode 100644 index 0000000..da838db --- /dev/null +++ b/wallpaper/caja-wallpaper-extension.h @@ -0,0 +1,52 @@ +/* + * Caja Wallpaper extension + * + * Copyright (C) 2005 Adam Israel + * Copyright (C) 2014 Stefano Karapetsas + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Authors: Adam Israel + * Stefano Karapetsas + */ + +#ifndef CAJA_WALLPAPER_EXTENSION_H +#define CAJA_WALLPAPER_EXTENSION_H + +#include + +G_BEGIN_DECLS + +#define CAJA_TYPE_CWE (caja_cwe_get_type ()) +#define CAJA_CWE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CAJA_TYPE_CWE, CajaCwe)) +#define CAJA_IS_CWE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CAJA_TYPE_CWE)) + +typedef struct _CajaCwe CajaCwe; +typedef struct _CajaCweClass CajaCweClass; + +struct _CajaCwe { + GObject __parent; +}; + +struct _CajaCweClass { + GObjectClass __parent; +}; + +GType caja_cwe_get_type (void); +void caja_cwe_register_type (GTypeModule *module); + +G_END_DECLS + +#endif /* CAJA_WALLPAPER_EXTENSION_H */ diff --git a/wallpaper/libcaja-wallpaper.caja-extension.in b/wallpaper/libcaja-wallpaper.caja-extension.in new file mode 100644 index 0000000..3aa89ab --- /dev/null +++ b/wallpaper/libcaja-wallpaper.caja-extension.in @@ -0,0 +1,4 @@ +[Caja Extension] +Icon=desktop +_Name=Wallpaper +_Description=Allows to quickly set wallpaper -- cgit v1.2.1