diff options
author | Stefano Karapetsas <[email protected]> | 2014-10-27 15:21:59 +0100 |
---|---|---|
committer | Stefano Karapetsas <[email protected]> | 2014-10-27 15:21:59 +0100 |
commit | f4c1ed23ddb3bf5d8ba6d1faf46c26b91346d926 (patch) | |
tree | 16e70e9d6b0ea866b0981aa70ad92208bb95b0cb | |
parent | 451eef9b275ce006b270a3569d96e531e24dd15a (diff) | |
download | caja-f4c1ed23ddb3bf5d8ba6d1faf46c26b91346d926.tar.bz2 caja-f4c1ed23ddb3bf5d8ba6d1faf46c26b91346d926.tar.xz |
Allow extensions to define an ini file with name, icon and description
-rw-r--r-- | libcaja-private/caja-extensions.c | 32 | ||||
-rw-r--r-- | libcaja-private/caja-extensions.h | 3 | ||||
-rw-r--r-- | src/caja-file-management-properties.c | 41 |
3 files changed, 56 insertions, 20 deletions
diff --git a/libcaja-private/caja-extensions.c b/libcaja-private/caja-extensions.c index b15923fd..f553df13 100644 --- a/libcaja-private/caja-extensions.c +++ b/libcaja-private/caja-extensions.c @@ -28,6 +28,7 @@ #include <string.h> +#define CAJA_EXTENSION_GROUP "Caja Extension" static GList *caja_extensions = NULL; @@ -36,11 +37,27 @@ Extension * extension_new (gchar *filename, gboolean state, GObject *module) { Extension *ext; - + GKeyFile *extension_file; + gchar *extension_filename; + ext = g_new0 (Extension, 1); ext->filename = filename; + ext->name = NULL; + ext->description = NULL; ext->state = state; ext->module = module; + + extension_file = g_key_file_new (); + extension_filename = g_strdup_printf(CAJA_DATADIR "/extensions/%s.caja-extension", filename); + if (g_key_file_load_from_file (extension_file, extension_filename, G_KEY_FILE_NONE, NULL)) + { + ext->name = g_key_file_get_locale_string (extension_file, CAJA_EXTENSION_GROUP, "Name", NULL, NULL); + ext->description = g_key_file_get_locale_string (extension_file, CAJA_EXTENSION_GROUP, "Description", NULL, NULL); + ext->icon = g_key_file_get_locale_string (extension_file, CAJA_EXTENSION_GROUP, "Icon", NULL, NULL); + } + g_key_file_free (extension_file); + g_free (extension_filename); + return ext; } @@ -130,13 +147,9 @@ gsettings_remove_from_list (const char *value) /* functions related to the extension management */ static gboolean -caja_extension_is_disabled (const gchar *extname) +caja_extension_get_state (const gchar *extname) { - if (gsettings_key_has_value (extname)) - { - return TRUE; - } - return FALSE; + return !gsettings_key_has_value (extname); } GList * @@ -148,6 +161,7 @@ caja_extensions_get_for_type (GType type) for (l = caja_extensions; l != NULL; l = l->next) { Extension *ext = l->data; + ext->state = caja_extension_get_state (ext->filename); if (ext->state) // only load enabled extensions { if (G_TYPE_CHECK_INSTANCE_TYPE (G_OBJECT (ext->module), type)) @@ -174,9 +188,7 @@ caja_extension_register (gchar *filename, GObject *module) gchar *extname; extname = g_strndup (filename, strlen(filename) - 3); - - if (caja_extension_is_disabled (extname)) - state = FALSE; + state = caja_extension_get_state (extname); Extension *ext = extension_new (extname, state, module); caja_extensions = g_list_append (caja_extensions, ext); diff --git a/libcaja-private/caja-extensions.h b/libcaja-private/caja-extensions.h index 35d0a50e..5efcb569 100644 --- a/libcaja-private/caja-extensions.h +++ b/libcaja-private/caja-extensions.h @@ -29,6 +29,9 @@ typedef struct _Extension { gchar *filename; + gchar *name; + gchar *description; + gchar *icon; gboolean state; GObject *module; }Extension; diff --git a/src/caja-file-management-properties.c b/src/caja-file-management-properties.c index a0902ed2..9df0695b 100644 --- a/src/caja-file-management-properties.c +++ b/src/caja-file-management-properties.c @@ -785,26 +785,47 @@ caja_file_management_properties_dialog_setup_extension_page (GtkBuilder *builder G_CALLBACK (extension_state_toggled), view); icon_theme = gtk_icon_theme_get_default(); - ext_pixbuf_icon = gtk_icon_theme_load_icon (icon_theme, "gtk-open", - GTK_ICON_SIZE_SMALL_TOOLBAR, - GTK_ICON_LOOKUP_USE_BUILTIN, NULL); for (i = 0; i < g_list_length (extensions); i++) { Extension* ext = EXTENSION (g_list_nth_data (extensions, i)); - - ext_text_info = g_markup_printf_escaped ("<b>%s</b>\n%s", - ext->filename, - "This is a placeholder."); - + + if (ext->icon != NULL) + { + ext_pixbuf_icon = gtk_icon_theme_load_icon (icon_theme, ext->icon, + 24, + GTK_ICON_LOOKUP_USE_BUILTIN, NULL); + } + else + { + ext_pixbuf_icon = gtk_icon_theme_load_icon (icon_theme, "system-run", + 24, + GTK_ICON_LOOKUP_USE_BUILTIN, NULL); + } + + if (ext->description != NULL) + { + ext_text_info = g_markup_printf_escaped ("<b>%s</b>\n%s", + ext->name ? ext->name : ext->filename, + ext->description); + } + else + { + ext_text_info = g_markup_printf_escaped ("<b>%s</b>", + ext->name ? ext->name : ext->filename); + } + gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, + gtk_list_store_set (store, &iter, EXT_STATE_COLUMN, ext->state, EXT_ICON_COLUMN, ext_pixbuf_icon, EXT_INFO_COLUMN, ext_text_info, EXT_STRUCT_COLUMN, ext, -1); + + g_free (ext_text_info); + if (ext_pixbuf_icon) + g_object_unref (ext_pixbuf_icon); } - g_free (ext_text_info); } static void |