Really saving preferences for applets

This commit is contained in:
Pierre Pronchery 2011-03-10 20:32:37 +00:00
parent f4f9be9b18
commit 25a9e82c7a
4 changed files with 41 additions and 29 deletions

View File

@ -37,6 +37,7 @@ typedef struct _PanelAppletHelper
char const * variable, char const * value); char const * variable, char const * value);
int (*error)(Panel * panel, char const * message, int ret); int (*error)(Panel * panel, char const * message, int ret);
void (*about_dialog)(Panel * panel); void (*about_dialog)(Panel * panel);
int (*lock)(Panel * panel);
void (*logout_dialog)(Panel * panel); void (*logout_dialog)(Panel * panel);
void (*position_menu)(GtkMenu * menu, gint * x, gint * y, void (*position_menu)(GtkMenu * menu, gint * x, gint * y,
gboolean * push_in, gpointer data); gboolean * push_in, gpointer data);

View File

@ -12,8 +12,6 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* FIXME:
* - use XActivateScreenSaver() */
@ -44,10 +42,6 @@ static GtkWidget * _lock_settings(PanelApplet * applet, gboolean apply,
static void _on_clicked(gpointer data); static void _on_clicked(gpointer data);
/* constants */
#define PANEL_LOCK_COMMAND_DEFAULT "xset s activate"
/* public */ /* public */
/* variables */ /* variables */
PanelApplet applet = PanelApplet applet =
@ -131,7 +125,7 @@ static GtkWidget * _lock_settings(PanelApplet * applet, gboolean apply,
{ {
if((p = applet->helper->config_get(applet->helper->panel, if((p = applet->helper->config_get(applet->helper->panel,
"lock", "command")) == NULL) "lock", "command")) == NULL)
p = PANEL_LOCK_COMMAND_DEFAULT; p = "xset s activate";
gtk_entry_set_text(GTK_ENTRY(lock->pr_command), p); gtk_entry_set_text(GTK_ENTRY(lock->pr_command), p);
} }
if(apply == TRUE) if(apply == TRUE)
@ -149,12 +143,6 @@ static GtkWidget * _lock_settings(PanelApplet * applet, gboolean apply,
static void _on_clicked(gpointer data) static void _on_clicked(gpointer data)
{ {
PanelAppletHelper * helper = data; PanelAppletHelper * helper = data;
char const * command = PANEL_LOCK_COMMAND_DEFAULT;
char const * p;
GError * error = NULL;
if((p = helper->config_get(helper->panel, "lock", "command")) != NULL) helper->lock(helper->panel);
command = p;
if(g_spawn_command_line_async(command, &error) != TRUE)
helper->error(NULL, error->message, 1);
} }

View File

@ -71,8 +71,6 @@ static const MainMenu _main_menus[] =
}; };
#define MAIN_MENUS_COUNT (sizeof(_main_menus) / sizeof(*_main_menus)) #define MAIN_MENUS_COUNT (sizeof(_main_menus) / sizeof(*_main_menus))
#define PANEL_MAIN_COMMAND_LOCK_DEFAULT "xset s activate"
/* prototypes */ /* prototypes */
static GtkWidget * _main_init(PanelApplet * applet); static GtkWidget * _main_init(PanelApplet * applet);
@ -441,16 +439,8 @@ static gint _idle_apps_compare(gconstpointer a, gconstpointer b)
static void _on_lock(gpointer data) static void _on_lock(gpointer data)
{ {
Main * main = data; Main * main = data;
PanelAppletHelper * helper = main->helper;
char const * command = PANEL_MAIN_COMMAND_LOCK_DEFAULT;
char const * p;
GError * error = NULL;
/* FIXME implement a helper instead */ main->helper->lock(main->helper->panel);
if((p = helper->config_get(helper->panel, "lock", "command")) != NULL)
command = p;
if(g_spawn_command_line_async(command, &error) != TRUE)
helper->error(helper->panel, error->message, 1);
} }

View File

@ -112,6 +112,7 @@ static int _panel_helper_config_set(Panel * panel, char const * section,
char const * variable, char const * value); char const * variable, char const * value);
static int _panel_helper_error(Panel * panel, char const * message, int ret); static int _panel_helper_error(Panel * panel, char const * message, int ret);
static void _panel_helper_about_dialog(Panel * panel); static void _panel_helper_about_dialog(Panel * panel);
static int _panel_helper_lock(Panel * panel);
#ifndef EMBEDDED #ifndef EMBEDDED
static void _panel_helper_logout_dialog(Panel * panel); static void _panel_helper_logout_dialog(Panel * panel);
#endif #endif
@ -156,6 +157,7 @@ Panel * panel_new(PanelPrefs const * prefs)
panel->top_helper.error = _panel_helper_error; panel->top_helper.error = _panel_helper_error;
panel->top_helper.icon_size = PANEL_ICON_SIZE_UNSET; panel->top_helper.icon_size = PANEL_ICON_SIZE_UNSET;
panel->top_helper.about_dialog = _panel_helper_about_dialog; panel->top_helper.about_dialog = _panel_helper_about_dialog;
panel->top_helper.lock = _panel_helper_lock;
#ifndef EMBEDDED #ifndef EMBEDDED
panel->top_helper.logout_dialog = _panel_helper_logout_dialog; panel->top_helper.logout_dialog = _panel_helper_logout_dialog;
#else #else
@ -463,6 +465,7 @@ int panel_load(Panel * panel, PanelPosition position, char const * applet)
&& (widget = pa->settings(pa, FALSE, FALSE)) != NULL) && (widget = pa->settings(pa, FALSE, FALSE)) != NULL)
{ {
vbox = gtk_vbox_new(FALSE, 4); vbox = gtk_vbox_new(FALSE, 4);
g_object_set_data(G_OBJECT(vbox), "applet", pa); /* XXX ugly */
gtk_container_set_border_width(GTK_CONTAINER(vbox), 4); gtk_container_set_border_width(GTK_CONTAINER(vbox), 4);
gtk_box_pack_start(GTK_BOX(vbox), widget, FALSE, TRUE, 0); gtk_box_pack_start(GTK_BOX(vbox), widget, FALSE, TRUE, 0);
gtk_widget_show(vbox); gtk_widget_show(vbox);
@ -600,8 +603,10 @@ static void _preferences_on_ok(gpointer data)
{ {
Panel * panel = data; Panel * panel = data;
gint i; gint i;
const gint cnt = sizeof(_panel_sizes) / sizeof(*_panel_sizes); gint cnt = sizeof(_panel_sizes) / sizeof(*_panel_sizes);
char * filename; char * filename;
GtkWidget * widget;
PanelApplet * pa;
gtk_widget_hide(panel->pr_window); gtk_widget_hide(panel->pr_window);
if((i = gtk_combo_box_get_active(GTK_COMBO_BOX(panel->pr_bottom_size))) if((i = gtk_combo_box_get_active(GTK_COMBO_BOX(panel->pr_bottom_size)))
@ -612,6 +617,17 @@ static void _preferences_on_ok(gpointer data)
>= 0 && i < cnt) >= 0 && i < cnt)
config_set(panel->config, NULL, "top_size", config_set(panel->config, NULL, "top_size",
_panel_sizes[i].alias); _panel_sizes[i].alias);
/* XXX applets should be known from Panel already */
cnt = gtk_notebook_get_n_pages(GTK_NOTEBOOK(panel->pr_notebook));
for(i = 1; i < cnt; i++)
{
widget = gtk_notebook_get_nth_page(GTK_NOTEBOOK(
panel->pr_notebook), i);
if(widget == NULL || (pa = g_object_get_data(G_OBJECT(widget),
"applet")) == NULL)
continue;
pa->settings(pa, TRUE, FALSE);
}
if((filename = _config_get_filename()) != NULL) if((filename = _config_get_filename()) != NULL)
config_save(panel->config, filename); config_save(panel->config, filename);
free(filename); free(filename);
@ -721,6 +737,22 @@ static gboolean _about_on_closex(gpointer data)
} }
/* panel_helper_lock */
static int _panel_helper_lock(Panel * panel)
{
/* FIXME default to calling XActivateScreenSaver() */
char const * command = "xset s activate";
char const * p;
GError * error = NULL;
if((p = config_get(panel->config, "lock", "command")) != NULL)
command = p;
if(g_spawn_command_line_async(command, &error) != TRUE)
return panel_error(panel, error->message, 1);
return 0;
}
#ifndef EMBEDDED #ifndef EMBEDDED
/* panel_helper_logout_dialog */ /* panel_helper_logout_dialog */
static gboolean _logout_dialog_on_closex(gpointer data); static gboolean _logout_dialog_on_closex(gpointer data);
@ -930,7 +962,8 @@ static int _panel_helper_suspend(Panel * panel)
#ifdef __NetBSD__ #ifdef __NetBSD__
int sleep_state = 3; int sleep_state = 3;
#else #else
char * suspend[] = { "/usr/bin/sudo", "sudo", "/sbin/apm", "-s", NULL }; char * suspend[] = { "/usr/bin/sudo", "sudo", "/usr/bin/apm", "-s",
NULL };
GError * error = NULL; GError * error = NULL;
#endif #endif
@ -938,11 +971,11 @@ static int _panel_helper_suspend(Panel * panel)
if(sysctlbyname("machdep.sleep_state", NULL, NULL, &sleep_state, if(sysctlbyname("machdep.sleep_state", NULL, NULL, &sleep_state,
sizeof(sleep_state)) != 0) sizeof(sleep_state)) != 0)
return panel_error(panel, "sysctl", 1); return panel_error(panel, "sysctl", 1);
return 0;
#else #else
if(g_spawn_async(NULL, suspend, NULL, G_SPAWN_FILE_AND_ARGV_ZERO, NULL, if(g_spawn_async(NULL, suspend, NULL, G_SPAWN_FILE_AND_ARGV_ZERO, NULL,
NULL, NULL, &error) != TRUE) NULL, NULL, &error) != TRUE)
return panel_error(panel, error->message, 1); return panel_error(panel, error->message, 1);
return 0;
#endif #endif
_panel_helper_lock(panel); /* XXX may already be suspended */
return 0;
} }