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