Skip to content

Commit 09146ca

Browse files
20kdclukefromdc
authored andcommitted
Add 'Configurable' interface and add support to caja-file-management-properties
1 parent adeaed2 commit 09146ca

File tree

4 files changed

+218
-3
lines changed

4 files changed

+218
-3
lines changed

libcaja-extension/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ libcaja_extension_include_HEADERS = \
3434
caja-property-page-provider.h \
3535
caja-property-page.h \
3636
caja-menu.h \
37+
caja-configurable.h \
3738
$(NULL)
3839

3940
libcaja_extension_la_SOURCES = \
@@ -50,6 +51,7 @@ libcaja_extension_la_SOURCES = \
5051
caja-property-page-provider.c \
5152
caja-property-page.c \
5253
caja-menu.c \
54+
caja-configurable.c \
5355
$(NULL)
5456

5557
pkgconfigdir=$(libdir)/pkgconfig
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* caja-configurable.c - Interface for configuration
3+
*
4+
* Copyright (C) 2003 Novell, Inc.
5+
*
6+
* This library is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Library General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 2 of the License, or (at your option) any later version.
10+
*
11+
* This library is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Library General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Library General Public
17+
* License along with this library; if not, write to the Free
18+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*
20+
* Author: 20kdc <gamemanj@hotmail.co.uk>
21+
* Based on caja-menu-provider.c by Dave Camp <dave@ximian.com>
22+
*
23+
*/
24+
25+
#include <config.h>
26+
#include "caja-configurable.h"
27+
28+
#include <glib-object.h>
29+
30+
/**
31+
* SECTION:caja-configurable
32+
* @title: CajaConfigurable
33+
* @short_description: Interface to allow an extension to be configured
34+
* @include: libcaja-extension/caja-configurable.h
35+
*
36+
* #CajaConfigurable allows an extension to show a configuration page.
37+
* The presence of CajaConfigurable enables the 'Configure' button.
38+
*/
39+
40+
static void
41+
caja_configurable_base_init (gpointer g_class)
42+
{
43+
}
44+
45+
GType
46+
caja_configurable_get_type (void)
47+
{
48+
static GType type = 0;
49+
50+
if (!type) {
51+
const GTypeInfo info = {
52+
sizeof (CajaConfigurableIface),
53+
caja_configurable_base_init,
54+
NULL,
55+
NULL,
56+
NULL,
57+
NULL,
58+
0,
59+
0,
60+
NULL
61+
};
62+
63+
type = g_type_register_static (G_TYPE_INTERFACE,
64+
"CajaConfigurable",
65+
&info, 0);
66+
g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
67+
}
68+
69+
return type;
70+
}
71+
72+
/**
73+
* caja_configurable_run:
74+
* @provider: a #CajaConfigurable
75+
*/
76+
void
77+
caja_configurable_run_config (CajaConfigurable *provider)
78+
{
79+
if (!CAJA_IS_CONFIGURABLE(provider)) {
80+
return;
81+
}
82+
83+
if (CAJA_CONFIGURABLE_GET_IFACE (provider)->run_config) {
84+
CAJA_CONFIGURABLE_GET_IFACE (provider)->run_config(provider);
85+
}
86+
}
87+
88+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* caja-configurable.c - Interface for configuration
3+
*
4+
* Copyright (C) 2003 Novell, Inc.
5+
*
6+
* This library is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Library General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 2 of the License, or (at your option) any later version.
10+
*
11+
* This library is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Library General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Library General Public
17+
* License along with this library; if not, write to the Free
18+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*
20+
* Author: 20kdc <gamemanj@hotmail.co.uk>
21+
* Based on caja-menu-provider.h by Dave Camp <dave@ximian.com>
22+
*
23+
*/
24+
25+
/* This interface is implemented by Caja extensions that want to
26+
* have configuration screens (this is particularly important for open-terminal)
27+
*/
28+
29+
#ifndef CAJA_CONFIGURABLE_H
30+
#define CAJA_CONFIGURABLE_H
31+
32+
#include <glib-object.h>
33+
#include <gtk/gtk.h>
34+
#include "caja-extension-types.h"
35+
#include "caja-file-info.h"
36+
#include "caja-menu.h"
37+
38+
G_BEGIN_DECLS
39+
40+
#define CAJA_TYPE_CONFIGURABLE (caja_configurable_get_type ())
41+
#define CAJA_CONFIGURABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CAJA_TYPE_CONFIGURABLE, CajaConfigurable))
42+
#define CAJA_IS_CONFIGURABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CAJA_TYPE_CONFIGURABLE))
43+
#define CAJA_CONFIGURABLE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), CAJA_TYPE_CONFIGURABLE, CajaConfigurableIface))
44+
45+
typedef struct _CajaConfigurable CajaConfigurable;
46+
typedef struct _CajaConfigurableIface CajaConfigurableIface;
47+
48+
/**
49+
* CajaConfigurableIface:
50+
* @g_iface: The parent interface.
51+
* @run: Starts the configuration panel (should use g_dialog_run)
52+
*
53+
* Interface for extensions to provide additional menu items.
54+
*/
55+
56+
struct _CajaConfigurableIface {
57+
GTypeInterface g_iface;
58+
59+
void (*run_config) (CajaConfigurable *provider);
60+
};
61+
62+
/* Interface Functions */
63+
GType caja_configurable_get_type (void);
64+
void caja_configurable_run_config (CajaConfigurable *provider);
65+
66+
G_END_DECLS
67+
68+
#endif

src/caja-file-management-properties.c

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343

4444
#include <libcaja-private/caja-autorun.h>
4545

46+
#include <libcaja-extension/caja-configurable.h>
47+
4648
/* string enum preferences */
4749
#define CAJA_FILE_MANAGEMENT_PROPERTIES_DEFAULT_VIEW_WIDGET "default_view_combobox"
4850
#define CAJA_FILE_MANAGEMENT_PROPERTIES_ICON_VIEW_ZOOM_WIDGET "icon_view_zoom_combobox"
@@ -622,6 +624,7 @@ other_type_combo_box_changed (GtkComboBox *combo_box, GtkComboBox *action_combo_
622624
}
623625

624626
static gulong extension_about_id = 0;
627+
static gulong extension_configure_id = 0;
625628

626629
static void
627630
extension_about_clicked (GtkButton *button, Extension *ext)
@@ -642,8 +645,29 @@ extension_about_clicked (GtkButton *button, Extension *ext)
642645
gtk_widget_destroy (GTK_WIDGET (extension_about_dialog));
643646
}
644647

648+
static int extension_configure_check (Extension *ext)
649+
{
650+
if (!ext->state) // For now, only allow configuring enabled extensions.
651+
{
652+
return 0;
653+
}
654+
if (!CAJA_IS_CONFIGURABLE(ext->module))
655+
{
656+
return 0;
657+
}
658+
return 1;
659+
}
660+
645661
static void
646-
extension_list_selection_changed (GtkTreeSelection *selection, GtkButton *about_button)
662+
extension_configure_clicked (GtkButton *button, Extension *ext)
663+
{
664+
if (extension_configure_check(ext)) {
665+
caja_configurable_run_config(CAJA_CONFIGURABLE(ext->module));
666+
}
667+
}
668+
669+
static void
670+
extension_list_selection_changed_about (GtkTreeSelection *selection, GtkButton *about_button)
647671
{
648672
GtkTreeModel *model;
649673
GtkTreeIter iter;
@@ -667,6 +691,34 @@ extension_list_selection_changed (GtkTreeSelection *selection, GtkButton *about_
667691
}
668692
}
669693

694+
static void
695+
extension_list_selection_changed_configure (GtkTreeSelection *selection, GtkButton *configure_button)
696+
{
697+
GtkTreeModel *model;
698+
GtkTreeIter iter;
699+
Extension *ext;
700+
701+
gtk_widget_set_sensitive (GTK_WIDGET (configure_button), FALSE);
702+
703+
if (extension_configure_id > 0)
704+
{
705+
g_signal_handler_disconnect (configure_button, extension_configure_id);
706+
extension_configure_id = 0;
707+
}
708+
709+
if (!gtk_tree_selection_get_selected (selection, &model, &iter))
710+
return;
711+
712+
gtk_tree_model_get (model, &iter, EXT_STRUCT_COLUMN, &ext, -1);
713+
if (ext != NULL) {
714+
// Unconfigurable extensions remain unconfigurable.
715+
if (extension_configure_check(ext)) {
716+
gtk_widget_set_sensitive (GTK_WIDGET (configure_button), TRUE);
717+
extension_configure_id = g_signal_connect (configure_button, "clicked", G_CALLBACK (extension_configure_clicked), ext);
718+
}
719+
}
720+
}
721+
670722
static void
671723
extension_state_toggled (GtkCellRendererToggle *cell, gchar *path_str, gpointer data)
672724
{
@@ -819,7 +871,7 @@ caja_file_management_properties_dialog_setup_extension_page (GtkBuilder *builder
819871
GtkTreeIter iter;
820872
GtkIconTheme *icon_theme;
821873
GdkPixbuf *ext_pixbuf_icon;
822-
GtkButton *about_button;
874+
GtkButton *about_button, *configure_button;
823875
gchar *ext_text_info;
824876

825877
GList *extensions;
@@ -883,11 +935,16 @@ caja_file_management_properties_dialog_setup_extension_page (GtkBuilder *builder
883935
}
884936

885937
about_button = GTK_BUTTON (gtk_builder_get_object (builder, "about_extension_button"));
938+
configure_button = GTK_BUTTON (gtk_builder_get_object (builder, "configure_extension_button"));
939+
886940
selection = gtk_tree_view_get_selection (view);
887941
gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
888942
g_signal_connect (selection, "changed",
889-
G_CALLBACK (extension_list_selection_changed),
943+
G_CALLBACK (extension_list_selection_changed_about),
890944
about_button);
945+
g_signal_connect (selection, "changed",
946+
G_CALLBACK (extension_list_selection_changed_configure),
947+
configure_button);
891948
}
892949

893950
static void

0 commit comments

Comments
 (0)