Eanble plugin support.
authorHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Fri, 6 Aug 2010 11:27:57 +0000 (19:27 +0800)
committerHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Fri, 6 Aug 2010 11:27:57 +0000 (19:27 +0800)
configure.ac
data/Makefile.am
data/lxappearance.pc.in [new file with mode: 0644]
data/ui/lxappearance.glade
src/Makefile.am
src/lxappearance.c
src/lxappearance.h
src/plugin.c [new file with mode: 0644]
src/plugin.h [new file with mode: 0644]

index e08d0bc..fb47f14 100644 (file)
@@ -29,11 +29,16 @@ PKG_CHECK_MODULES(XLIB, "x11")
 AC_SUBST(XLIB_CFLAGS)
 AC_SUBST(XLIB_LIBS)
 
 AC_SUBST(XLIB_CFLAGS)
 AC_SUBST(XLIB_LIBS)
 
-pkg_modules="gtk+-2.0 >= 2.12.0"
-PKG_CHECK_MODULES(GTK, [$pkg_modules])
+gtk_modules="gtk+-2.0 >= 2.12.0"
+PKG_CHECK_MODULES(GTK, [$gtk_modules])
 AC_SUBST(GTK_CFLAGS)
 AC_SUBST(GTK_LIBS)
 
 AC_SUBST(GTK_CFLAGS)
 AC_SUBST(GTK_LIBS)
 
+gmodule_modules="gmodule-export-2.0"
+PKG_CHECK_MODULES(GMODULE, [$gmodule_modules])
+AC_SUBST(GMODULE_CFLAGS)
+AC_SUBST(GMODULE_LIBS)
+
 # gio_modules="gthread-2.0 gio-unix-2.0 glib-2.0 >= 2.18.0"
 # PKG_CHECK_MODULES(GIO, [$gio_modules])
 # AC_SUBST(GIO_CFLAGS)
 # gio_modules="gthread-2.0 gio-unix-2.0 glib-2.0 >= 2.18.0"
 # PKG_CHECK_MODULES(GIO, [$gio_modules])
 # AC_SUBST(GIO_CFLAGS)
@@ -79,6 +84,7 @@ AC_CONFIG_FILES([
     data/Makefile
     data/ui/Makefile
     data/ui/about.glade
     data/Makefile
     data/ui/Makefile
     data/ui/about.glade
+    data/lxappearance.pc
     po/Makefile.in
 ])
 
     po/Makefile.in
 ])
 
index f908e14..06ccfdd 100644 (file)
@@ -4,6 +4,9 @@ SUBDIRS= \
        ui \
        $(NULL)
 
        ui \
        $(NULL)
 
+pkgconfigdir   = $(libdir)/pkgconfig
+pkgconfig_DATA = lxappearance.pc
+
 desktopdir=$(datadir)/applications
 desktop_in_files = \
        lxappearance.desktop.in \
 desktopdir=$(datadir)/applications
 desktop_in_files = \
        lxappearance.desktop.in \
diff --git a/data/lxappearance.pc.in b/data/lxappearance.pc.in
new file mode 100644 (file)
index 0000000..9abd35e
--- /dev/null
@@ -0,0 +1,10 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+datadir=@datadir@
+
+Name: lxappearance
+Description: Tool used to customize look and feel of gtk+ applications.
+Requires: gtk+-2.0 >= 2.12
+Version: @VERSION@
index de14584..65e1eee 100644 (file)
               </packing>
             </child>
             <child>
               </packing>
             </child>
             <child>
-              <object class="GtkVBox" id="vbox8">
+              <object class="GtkVBox" id="wm_page">
+                <property name="border_width">12</property>
+                <property name="spacing">18</property>
                 <child>
                   <placeholder/>
                 </child>
                 <child>
                   <placeholder/>
                 </child>
index 3e3ec92..f9ae7c9 100644 (file)
@@ -4,9 +4,13 @@ AM_CPPFLAGS = \
        -I$(srcdir) \
        -DPACKAGE_DATA_DIR=\""$(datadir)/lxappearance"\" \
        -DPACKAGE_UI_DIR=\""$(datadir)/lxappearance/ui"\" \
        -I$(srcdir) \
        -DPACKAGE_DATA_DIR=\""$(datadir)/lxappearance"\" \
        -DPACKAGE_UI_DIR=\""$(datadir)/lxappearance/ui"\" \
+       -DPACKAGE_LIB_DIR=\""$(libdir)"\" \
        -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
        $(NULL)
 
        -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
        $(NULL)
 
+lxappearance_includedir = $(includedir)/lxappearance
+lxappearance_include_HEADERS = lxappearance.h
+
 bin_PROGRAMS = lxappearance
 lxappearance_SOURCES = \
        lxappearance.c \
 bin_PROGRAMS = lxappearance
 lxappearance_SOURCES = \
        lxappearance.c \
@@ -23,15 +27,19 @@ lxappearance_SOURCES = \
        other.h \
        utils.c \
        utils.h \
        other.h \
        utils.c \
        utils.h \
+       plugin.c \
+       plugin.h \
        $(NULL)
 
 lxappearance_CFLAGS = \
        $(GTK_CFLAGS) \
        $(NULL)
 
 lxappearance_CFLAGS = \
        $(GTK_CFLAGS) \
+       $(GMODULE_CFLAGS) \
        -Werror-implicit-function-declaration \
        $(NULL)
 
 lxappearance_LDADD = \
        $(GTK_LIBS) \
        -Werror-implicit-function-declaration \
        $(NULL)
 
 lxappearance_LDADD = \
        $(GTK_LIBS) \
+       $(GMODULE_LIBS) \
        $(INTLLIBS) \
        $(NULL)
 
        $(INTLLIBS) \
        $(NULL)
 
index 1e2e397..0ce3607 100644 (file)
@@ -39,6 +39,7 @@
 #include "icon-theme.h"
 #include "cursor-theme.h"
 #include "other.h"
 #include "icon-theme.h"
 #include "cursor-theme.h"
 #include "other.h"
+#include "plugin.h"
 
 LXAppearance app = {0};
 
 
 LXAppearance app = {0};
 
@@ -401,6 +402,11 @@ int main(int argc, char** argv)
     cursor_theme_init(b);
     other_init(b);
 
     cursor_theme_init(b);
     other_init(b);
 
+    plugins_init(b);
+
+    /* the page for window manager plugins */
+    app.wm_page = GTK_WIDGET(gtk_builder_get_object(b, "wm_page"));
+
     g_signal_connect(app.dlg, "response", G_CALLBACK(on_dlg_response), NULL);
 
     gtk_window_present(GTK_WINDOW(app.dlg));
     g_signal_connect(app.dlg, "response", G_CALLBACK(on_dlg_response), NULL);
 
     gtk_window_present(GTK_WINDOW(app.dlg));
@@ -408,6 +414,8 @@ int main(int argc, char** argv)
 
     gtk_main();
 
 
     gtk_main();
 
+    plugins_finalize();
+
     return 0;
 }
 
     return 0;
 }
 
index b1c3f60..91b46db 100644 (file)
@@ -66,6 +66,9 @@ struct _LXAppearance
     GtkWidget* button_images_check;
     GtkWidget* menu_images_check;
 
     GtkWidget* button_images_check;
     GtkWidget* menu_images_check;
 
+    /* the page for window manager plugins */
+    GtkWidget* wm_page;
+
     char* widget_theme;
     char* default_font;
     char* icon_theme;
     char* widget_theme;
     char* default_font;
     char* icon_theme;
diff --git a/src/plugin.c b/src/plugin.c
new file mode 100644 (file)
index 0000000..10a3ea6
--- /dev/null
@@ -0,0 +1,86 @@
+//      plugin.c
+//
+//      Copyright 2010 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
+//
+//      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., 51 Franklin Street, Fifth Floor, Boston,
+//      MA 02110-1301, USA.
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "plugin.h"
+#include "lxappearance.h"
+#include <gmodule.h>
+
+#define PLUGIN_DIR  PACKAGE_LIB_DIR"/lxappearance/plugins"
+
+typedef gboolean (*PluginLoadFunc)(LXAppearance*, GtkBuilder*);
+typedef void (*PluginUnloadFunc)(LXAppearance*);
+
+typedef struct _Plugin Plugin;
+struct _Plugin
+{
+    GModule* module;
+    PluginLoadFunc load;
+    PluginUnloadFunc unload;
+};
+
+static GSList* plugins = NULL;
+
+void plugins_init(GtkBuilder* builder)
+{
+    GDir* dir = g_dir_open(PLUGIN_DIR, 0, NULL);
+    char* name;
+    if(!dir)
+        return;
+    while(name = g_dir_read_name(dir))
+    {
+        char* file = g_build_filename(PLUGIN_DIR, name, NULL);
+        GModule* mod = g_module_open(file, G_MODULE_BIND_LOCAL);
+        if(mod)
+        {
+            PluginLoadFunc load;
+            gboolean loaded = FALSE;
+            if(g_module_symbol(mod, "plugin_load", &load))
+                loaded = load(&app, builder);
+            if(loaded)
+            {
+                Plugin* plugin = g_slice_new0(Plugin);
+                plugin->module = mod;
+                plugin->load = load;
+                g_module_symbol(mod, "plugin_unload", &plugin->unload);
+                plugins = g_slist_prepend(plugins, plugin);
+                g_debug("plugin: %s loadad", file);
+            }
+            else
+                g_module_close(mod);
+        }
+        g_free(file);
+    }
+    g_dir_close(dir);
+}
+
+void plugins_finalize()
+{
+    GSList* l;
+    for(l = plugins; l; l=l->next)
+    {
+        Plugin* plugin = (Plugin*)l->data;
+        g_module_close(plugin->module);
+        g_slice_free(Plugin, plugin);
+    }
+    g_slist_free(plugins);
+}
diff --git a/src/plugin.h b/src/plugin.h
new file mode 100644 (file)
index 0000000..fea7e33
--- /dev/null
@@ -0,0 +1,28 @@
+//      plugin.c
+//
+//      Copyright 2010 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
+//
+//      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., 51 Franklin Street, Fifth Floor, Boston,
+//      MA 02110-1301, USA.
+
+#ifndef __PLUGIN_H__
+#define __PLUGIN_H__
+
+#include <gtk/gtk.h>
+
+void plugins_init(GtkBuilder* builder);
+void plugins_finalize();
+
+#endif