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 "config.h"
23 #include "i18n.h"
24 #include "misc.h"
25 #include "plugin.h"
26 #include "plugins.h"
27 #include "preferences.h"
28 #include "ui_preferences.h"
29 
31 {
32  PluginMiscData * misc = plugin_get_misc_data (plugin);
33  Plugin * header = plugin_get_header (plugin);
34 
35  if (misc->about_window)
36  {
37  gtk_window_present ((GtkWindow *) misc->about_window);
38  return;
39  }
40 
41  const char * name = header->name;
42  const char * text = header->about_text;
43 
44  if (PLUGIN_HAS_FUNC (header, domain))
45  {
46  name = dgettext (header->domain, name);
47  text = dgettext (header->domain, text);
48  }
49 
50  char * title = g_strdup_printf (_("About %s"), name);
51  audgui_simple_message ((GtkWidget * *) & misc->about_window, GTK_MESSAGE_INFO, title, text);
52  g_free (title);
53 }
54 
55 static void response_cb (GtkWidget * window, int response, const PluginPreferences * p)
56 {
57  if (response == GTK_RESPONSE_OK && p->apply)
58  p->apply ();
59 
60  gtk_widget_destroy (window);
61 }
62 
63 static void destroy_cb (GtkWidget * window, const PluginPreferences * p)
64 {
65  if (p->cleanup)
66  p->cleanup ();
67 }
68 
70 {
71  PluginMiscData * misc = plugin_get_misc_data (plugin);
72  Plugin * header = plugin_get_header (plugin);
73  const PluginPreferences * p = header->prefs;
74 
75  if (misc->config_window)
76  {
77  gtk_window_present ((GtkWindow *) misc->config_window);
78  return;
79  }
80 
81  if (p->init)
82  p->init ();
83 
84  const char * name = header->name;
85  if (PLUGIN_HAS_FUNC (header, domain))
86  name = dgettext (header->domain, header->name);
87 
88  char * title = g_strdup_printf (_("%s Settings"), name);
89 
90  GtkWidget * window = p->apply ? gtk_dialog_new_with_buttons (title, NULL, 0,
91  GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL)
92  : gtk_dialog_new_with_buttons (title, NULL, 0, GTK_STOCK_CLOSE,
93  GTK_RESPONSE_CLOSE, NULL);
94 
95  g_free (title);
96 
97  GtkWidget * content = gtk_dialog_get_content_area ((GtkDialog *) window);
98  GtkWidget * box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
99  create_widgets_with_domain (box, p->widgets, p->n_widgets, header->domain);
100  gtk_box_pack_start ((GtkBox *) content, box, TRUE, TRUE, 0);
101 
102  g_signal_connect (window, "response", (GCallback) response_cb, (void *) p);
103  g_signal_connect (window, "destroy", (GCallback) destroy_cb, (void *) p);
104 
105  misc->config_window = window;
106  g_signal_connect (window, "destroy", (GCallback) gtk_widget_destroyed, & misc->config_window);
107 
108  gtk_widget_show_all (window);
109 }
110 
112 {
113  PluginMiscData * misc = plugin_get_misc_data (plugin);
114 
115  if (misc->about_window)
116  gtk_widget_destroy (misc->about_window);
117  if (misc->config_window)
118  gtk_widget_destroy (misc->config_window);
119 }