Audacious  $Id:Doxyfile42802007-03-2104:39:00Znenolod$
plugin-preferences.c
Go to the documentation of this file.
1 /*
2  * plugin-preferences.c
3  * Copyright 2012 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 <libaudgui/libaudgui-gtk.h>
21 
22 #include "i18n.h"
23 #include "misc.h"
24 #include "plugin.h"
25 #include "plugins.h"
26 #include "preferences.h"
27 #include "ui_preferences.h"
28 
29 typedef struct {
30  GtkWidget * about_window;
31  GtkWidget * config_window;
33 
35 {
36  PluginMiscData * misc = plugin_get_misc_data (plugin, sizeof (PluginMiscData));
37  Plugin * header = plugin_get_header (plugin);
38 
39  if (misc->about_window)
40  {
41  gtk_window_present ((GtkWindow *) misc->about_window);
42  return;
43  }
44 
45  const char * name = header->name;
46  const char * text = header->about_text;
47 
48  if (PLUGIN_HAS_FUNC (header, domain))
49  {
50  name = dgettext (header->domain, name);
51  text = dgettext (header->domain, text);
52  }
53 
54  char * title = g_strdup_printf (_("About %s"), name);
55  audgui_simple_message (& misc->about_window, GTK_MESSAGE_INFO, title, text);
56  g_free (title);
57 }
58 
59 static void response_cb (GtkWidget * window, int response, const PluginPreferences * p)
60 {
61  if (response == GTK_RESPONSE_OK && p->apply)
62  p->apply ();
63 
64  gtk_widget_destroy (window);
65 }
66 
67 static void destroy_cb (GtkWidget * window, const PluginPreferences * p)
68 {
69  if (p->cleanup)
70  p->cleanup ();
71 }
72 
74 {
75  PluginMiscData * misc = plugin_get_misc_data (plugin, sizeof (PluginMiscData));
76  Plugin * header = plugin_get_header (plugin);
77  const PluginPreferences * p = header->prefs;
78 
79  if (misc->config_window)
80  {
81  gtk_window_present ((GtkWindow *) misc->config_window);
82  return;
83  }
84 
85  if (p->init)
86  p->init ();
87 
88  const char * name = header->name;
89  if (PLUGIN_HAS_FUNC (header, domain))
90  name = dgettext (header->domain, header->name);
91 
92  char * title = g_strdup_printf (_("%s Settings"), name);
93 
94  GtkWidget * window = p->apply ? gtk_dialog_new_with_buttons (title, NULL, 0,
95  GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL)
96  : gtk_dialog_new_with_buttons (title, NULL, 0, GTK_STOCK_CLOSE,
97  GTK_RESPONSE_CLOSE, NULL);
98 
99  g_free (title);
100 
101  GtkWidget * content = gtk_dialog_get_content_area ((GtkDialog *) window);
102  GtkWidget * box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
103  create_widgets_with_domain (box, p->widgets, p->n_widgets, header->domain);
104  gtk_box_pack_start ((GtkBox *) content, box, TRUE, TRUE, 0);
105 
106  g_signal_connect (window, "response", (GCallback) response_cb, (void *) p);
107  g_signal_connect (window, "destroy", (GCallback) destroy_cb, (void *) p);
108 
109  misc->config_window = window;
110  g_signal_connect (window, "destroy", (GCallback) gtk_widget_destroyed, & misc->config_window);
111 
112  gtk_widget_show_all (window);
113 }
114 
116 {
117  PluginMiscData * misc = plugin_get_misc_data (plugin, sizeof (PluginMiscData));
118 
119  if (misc->about_window)
120  gtk_widget_destroy (misc->about_window);
121  if (misc->config_window)
122  gtk_widget_destroy (misc->config_window);
123 }
GtkWidget * config_window
static void destroy_cb(GtkWidget *window, const PluginPreferences *p)
static void response_cb(GtkWidget *window, int response, const PluginPreferences *p)
#define _(String)
Definition: i18n.h:25
void plugin_make_config_window(PluginHandle *plugin)
#define PLUGIN_HAS_FUNC(p, func)
Definition: plugin.h:515
void plugin_misc_cleanup(PluginHandle *plugin)
const void * plugin_get_header(PluginHandle *plugin)
const char * name
Definition: plugin-init.c:38
#define NULL
Definition: core.h:29
void * plugin_get_misc_data(PluginHandle *plugin, int size)
#define TRUE
Definition: core.h:39
GtkWidget * about_window
void create_widgets_with_domain(void *box, const PreferencesWidget *widgets, int amt, const char *domain)
void plugin_make_about_window(PluginHandle *plugin)
const char PluginHandle decoder const char PluginHandle decoder const char PluginHandle decoder void box
Definition: misc-api.h:103
void data PluginHandle plugin
Definition: plugins-api.h:54