plugin.c

Go to the documentation of this file.
00001 /***************************************************************************
00002  *            plugin.c
00003  *
00004  *  Sun Sep 24 12:12:57 2006
00005  *  Copyright  2006-2007  Neil Williams
00006  *  linux@codehelp.co.uk
00007  ****************************************************************************/
00013 /*
00014     This package is free software; you can redistribute it and/or modify
00015     it under the terms of the GNU General Public License as published by
00016     the Free Software Foundation; either version 3 of the License, or
00017     (at your option) any later version.
00018 
00019     This program is distributed in the hope that it will be useful,
00020     but WITHOUT ANY WARRANTY; without even the implied warranty of
00021     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022     GNU General Public License for more details.
00023 
00024     You should have received a copy of the GNU General Public License
00025     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00026 */
00027 
00028 #include <gmodule.h>
00029 #include <string.h>
00030 #include <stdlib.h>
00031 #include <dirent.h>
00032 #include "plugin.h"
00033 
00034 typedef struct _PluginData PluginData;
00035 
00036 struct _PluginData
00037 {
00038     GModule *handle;
00039     gchar *title;
00040     
00041     gint (*init) (PluginData *);
00042 };
00043 
00044 static GList *plugin_list = NULL;
00045 
00046 static void
00047 load_plugin (const gchar * file)
00048 {
00049     PluginData *pd;
00050     gpointer g;
00051     GList *t;
00052 
00053     pd = g_new0 (PluginData, 1);
00054     pd->handle = g_module_open (file, 0);
00055     if (!pd->handle)
00056     {
00057         g_free (pd);
00058         return;
00059     }
00060     g = &pd->init;
00061     g_module_symbol (pd->handle, "init_plugin", g);
00062     pd->init (pd);
00063     t = g_list_append (plugin_list, pd);
00064 }
00065 
00066 static void
00067 load_plugin_directory (gchar * directory)
00068 {
00069     const gchar *filename;
00070     GError *qlerr;
00071     GDir *d;
00072 
00073     qlerr = NULL;
00074     d = g_dir_open (directory, 0, &qlerr);
00075     if (qlerr != NULL)
00076         return;
00077     while ((filename = g_dir_read_name (d)) != NULL)
00078     {
00079         gchar *plugin_name = g_module_build_path (directory, filename);
00080         if (plugin_name)
00081         {
00082             load_plugin (plugin_name);
00083             g_free (plugin_name);
00084         }
00085     }
00086     g_dir_close (d);
00087 }
00088 
00089 gboolean
00090 init_plugins (void)
00091 {
00092     gchar *plugin_dir;
00093     const gchar *home_dir = g_get_home_dir ();
00094 
00095     if (!g_module_supported ())
00096         return FALSE;
00097     /* Load the user plugins */
00098     plugin_dir = g_strconcat (home_dir, "/.quicklist/plugins/", NULL);
00099     load_plugin_directory (plugin_dir);
00100     g_free (plugin_dir);
00101 
00102     return TRUE;
00103 }

Generated on Mon Jan 28 22:02:10 2008 for quicklist by  doxygen 1.5.4