Audacious  $Id:Doxyfile42802007-03-2104:39:00Znenolod$
general.c
Go to the documentation of this file.
1 /*
2  * general.c
3  * Copyright 2011 John Lindgren
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions, and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions, and the following disclaimer in the documentation
13  * provided with the distribution.
14  *
15  * This software is provided "as is" and without any warranty, express or
16  * implied. In no event shall the authors be liable for any damages arising from
17  * the use of this software.
18  */
19 
20 #include <gtk/gtk.h>
21 
22 #include "debug.h"
23 #include "general.h"
24 #include "interface.h"
25 #include "plugin.h"
26 #include "plugins.h"
27 #include "ui_preferences.h"
28 
29 typedef struct {
32  GtkWidget * widget;
34 
35 static int running = FALSE;
36 static GList * loaded_general_plugins = NULL;
37 
39 {
40  return (general->plugin == plugin) ? 0 : -1;
41 }
42 
44 {
45  GList * node = g_list_find_custom (loaded_general_plugins, plugin,
46  (GCompareFunc) general_find_cb);
47  if (node != NULL)
48  return;
49 
50  AUDDBG ("Loading %s.\n", plugin_get_name (plugin));
51  GeneralPlugin * gp = plugin_get_header (plugin);
52  g_return_if_fail (gp != NULL);
53 
54  LoadedGeneral * general = g_slice_new (LoadedGeneral);
55  general->plugin = plugin;
56  general->gp = gp;
57  general->widget = NULL;
58 
59  if (gp->get_widget != NULL)
60  general->widget = gp->get_widget ();
61 
62  if (general->widget != NULL)
63  {
64  AUDDBG ("Adding %s to interface.\n", plugin_get_name (plugin));
65  g_signal_connect (general->widget, "destroy", (GCallback)
66  gtk_widget_destroyed, & general->widget);
67  interface_add_plugin_widget (plugin, general->widget);
68  }
69 
70  loaded_general_plugins = g_list_prepend (loaded_general_plugins, general);
71 }
72 
74 {
75  GList * node = g_list_find_custom (loaded_general_plugins, plugin,
76  (GCompareFunc) general_find_cb);
77  if (node == NULL)
78  return;
79 
80  AUDDBG ("Unloading %s.\n", plugin_get_name (plugin));
81  LoadedGeneral * general = node->data;
82  loaded_general_plugins = g_list_delete_link (loaded_general_plugins, node);
83 
84  if (general->widget != NULL)
85  {
86  AUDDBG ("Removing %s from interface.\n", plugin_get_name (plugin));
87  interface_remove_plugin_widget (plugin, general->widget);
88  g_return_if_fail (general->widget == NULL); /* not destroyed? */
89  }
90 
91  g_slice_free (LoadedGeneral, general);
92 }
93 
95 {
96  general_load (plugin);
97  return TRUE;
98 }
99 
100 void general_init (void)
101 {
102  g_return_if_fail (! running);
103  running = TRUE;
104 
107 }
108 
109 static void general_cleanup_cb (LoadedGeneral * general)
110 {
111  general_unload (general->plugin);
112 }
113 
114 void general_cleanup (void)
115 {
116  g_return_if_fail (running);
117  running = FALSE;
118 
119  g_list_foreach (loaded_general_plugins, (GFunc) general_cleanup_cb, NULL);
120 }
121 
123 {
124  GeneralPlugin * gp = plugin_get_header (plugin);
125  g_return_val_if_fail (gp != NULL, FALSE);
126 
127  if (gp->init != NULL && ! gp->init ())
128  return FALSE;
129 
130  if (running)
131  general_load (plugin);
132 
133  return TRUE;
134 }
135 
137 {
138  GeneralPlugin * gp = plugin_get_header (plugin);
139  g_return_if_fail (gp != NULL);
140 
141  if (running)
142  general_unload (plugin);
143 
144  if (gp->cleanup != NULL)
145  gp->cleanup ();
146 }
147 
148 PluginHandle * general_plugin_by_widget (/* GtkWidget * */ void * widget)
149 {
150  g_return_val_if_fail (widget, NULL);
151 
152  for (GList * node = loaded_general_plugins; node; node = node->next)
153  {
154  LoadedGeneral * general = node->data;
155  if (general->widget == widget)
156  return general->plugin;
157  }
158 
159  return NULL;
160 }
void general_cleanup(void)
Definition: general.c:114
static GList * loaded_general_plugins
Definition: general.c:36
static void general_unload(PluginHandle *plugin)
Definition: general.c:73
void interface_add_plugin_widget(PluginHandle *plugin, GtkWidget *widget)
Definition: interface.c:155
void *(* get_widget)(void)
Definition: plugin.h:443
void interface_remove_plugin_widget(PluginHandle *plugin, GtkWidget *widget)
Definition: interface.c:173
GtkWidget * widget
Definition: general.c:32
#define FALSE
Definition: core.h:35
static void general_cleanup_cb(LoadedGeneral *general)
Definition: general.c:109
static int general_find_cb(LoadedGeneral *general, PluginHandle *plugin)
Definition: general.c:38
PluginHandle * general_plugin_by_widget(void *widget)
Definition: general.c:148
Index Index bool_t
Definition: playlist-api.h:122
void general_init(void)
Definition: general.c:100
#define AUDDBG(...)
Definition: debug.h:30
bool_t general_plugin_start(PluginHandle *plugin)
Definition: general.c:122
const void * plugin_get_header(PluginHandle *plugin)
static void general_load(PluginHandle *plugin)
Definition: general.c:43
void general_plugin_stop(PluginHandle *plugin)
Definition: general.c:136
#define NULL
Definition: core.h:27
static int running
Definition: general.c:35
bool_t(* PluginForEachFunc)(PluginHandle *plugin, void *data)
Definition: plugins.h:27
PluginHandle * plugin
Definition: general.c:30
#define TRUE
Definition: core.h:37
static bool_t general_init_cb(PluginHandle *plugin)
Definition: general.c:94
void plugin_for_enabled(int type, PluginForEachFunc func, void *data)
void data PluginHandle plugin
Definition: plugins-api.h:54
const char * plugin_get_name(PluginHandle *plugin)
GeneralPlugin * gp
Definition: general.c:31