Initial import.
[lxde/lxpanel.git] / src / configurator.c
CommitLineData
a52c2257
HJYP
1#ifdef HAVE_CONFIG_H
2#include "config.h"
3#endif
4
5#include "plugin.h"
6#include "panel.h"
7#include "misc.h"
8#include "bg.h"
9#include "gtkbgbox.h"
10#include <stdlib.h>
11#include <sys/types.h>
12#include <sys/stat.h>
13#include <unistd.h>
14#include <string.h>
15
16//#define DEBUG
17#include "dbg.h"
18
19void configure(void);
20void restart(void);
21
22command commands[] = {
23 { "configure", configure },
24 { "restart", restart },
25 { NULL, NULL },
26};
27
28static GtkWidget *dialog = NULL;
29static GtkSizeGroup *sg;
30
31//width
32static GtkWidget *width_spinb, *width_opt;
33static GtkAdjustment *width_adj;
34
35//height
36static GtkWidget *height_spinb, *height_opt;
37static GtkAdjustment *height_adj;
38
39//margin
40static GtkWidget *margin_label, *margin_spinb;
41static GtkAdjustment *margin_adj;
42
43//allign
44static GtkWidget *allign_opt;
45
46//edge
47static GtkWidget *edge_opt;
48
49//transparency
50static GtkWidget *tr_checkb, *tr_colorl, *tr_colorb;;
51
52//properties
53static GtkWidget *prop_dt_checkb, *prop_st_checkb;
54
55extern panel *p;
56extern gchar *cprofile;
57extern int config;
58extern FILE *pconf;
59
60void global_config_save(FILE *fp);
61void plugin_config_save(FILE *fp);
62
63static int
64mk_profile_dir()
65{
66 gchar fname[1024];
67 struct stat buf;
68 int ret;
69
70 ENTER;
71 sprintf(fname, "%s/.lxpanel", getenv("HOME"));
72 if ((ret = stat(fname, &buf))) {
73 LOG(LOG_INFO, "creating %s\n", fname);
74 mkdir(fname, 0755);
75 ret = stat(fname, &buf);
76 }
77 if (ret)
78 RET(0);
79 if (!(S_ISDIR(buf.st_mode) && (S_IWUSR & buf.st_mode) && (S_IXUSR & buf.st_mode)))
80 RET(0);
81 RET(1);
82}
83
84
85static void
86response_event(GtkDialog *widget, gint arg1, gpointer user_data)
87{
88 gchar fname[1024];
89 FILE *fp;
90
91 ENTER;
92 switch (arg1) {
93 case GTK_RESPONSE_DELETE_EVENT:
94 DBG("GTK_RESPONSE_DELETE_EVENT\n");
95 gtk_widget_destroy(dialog);
96 dialog = NULL;
97 break;
98 case GTK_RESPONSE_CLOSE:
99 gtk_widget_hide(dialog);
100 break;
101 case GTK_RESPONSE_APPLY:
102 if (!mk_profile_dir()) {
103 ERR("can't make ~/.lxpanel direcory\n");
104 RET();
105 }
106 sprintf(fname, "%s/.lxpanel/%s", getenv("HOME"), cprofile);
107 LOG(LOG_WARN, "saving profile %s as %s\n", cprofile, fname);
108 if (!(fp = fopen(fname, "w"))) {
109 ERR("can't open for write %s:", fname);
110 perror(NULL);
111 RET();
112 }
113 global_config_save(fp);
114 plugin_config_save(fp);
115 fclose(fp);
116 //sprintf(fname, "cat %s/.lxpanel/confplug >> %s/.lxpanel/%s", getenv("HOME"), getenv("HOME"), cprofile);
117 //system(fname);
118 gtk_main_quit();
119 break;
120 }
121 RET();
122}
123
124static void
125set_edge(GtkComboBox *widget, gpointer bp)
126{
127 int edge;
128
129 ENTER;
130 edge = gtk_combo_box_get_active(widget) + 1;
131 DBG("edge=%d\n", edge);
132 RET();
133}
134
135
136static void
137set_allign(GtkComboBox *widget, gpointer bp)
138{
139 int allign;
140 gboolean t;
141
142 ENTER;
143 allign = gtk_combo_box_get_active(widget) + 1;
144 DBG("allign=%d\n", allign);
145 t = (allign != ALLIGN_CENTER);
146 gtk_widget_set_sensitive(margin_label, t);
147 gtk_widget_set_sensitive(margin_spinb, t);
148 RET();
149}
150
151
152GtkWidget *
153mk_position()
154{
155 GtkWidget *hbox, *hbox2, *label, *frame;
156 GtkWidget *t;
157
158
159 ENTER;
160 frame = gtk_frame_new(NULL);
161 gtk_frame_set_shadow_type(GTK_FRAME (frame), GTK_SHADOW_NONE);
162 gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
163 label = gtk_label_new(NULL);
164 gtk_label_set_markup(GTK_LABEL (label),"<span weight=\"bold\">Position</span>");
165 gtk_frame_set_label_widget(GTK_FRAME (frame), label);
166
167 hbox2 = gtk_hbox_new(FALSE, 0);
168 gtk_container_set_border_width (GTK_CONTAINER (hbox2), 6);
169 gtk_container_add (GTK_CONTAINER (frame), hbox2);
170
171 hbox = gtk_hbox_new(FALSE, 0);
172 gtk_widget_set_size_request(hbox, 20, 1);
173 gtk_box_pack_start(GTK_BOX (hbox2), hbox, FALSE, TRUE, 0);
174
175 t = gtk_table_new(5, 2, FALSE);
176 gtk_table_set_row_spacings(GTK_TABLE(t), 3);
177 gtk_table_set_col_spacings(GTK_TABLE(t), 5);
178 gtk_box_pack_start(GTK_BOX (hbox2), t, FALSE, TRUE, 0);
179
180 //Edge
181 label = gtk_label_new("Edge:");
182 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
183 gtk_widget_show(label);
184 gtk_table_attach(GTK_TABLE(t), label, 0, 1, 0, 1, GTK_FILL, 0, 0, 0);
185 gtk_size_group_add_widget(sg, label);
186
187 edge_opt = gtk_combo_box_new_text();
188 gtk_combo_box_append_text(GTK_COMBO_BOX(edge_opt), "Left");
189 gtk_combo_box_append_text(GTK_COMBO_BOX(edge_opt), "Right");
190 gtk_combo_box_append_text(GTK_COMBO_BOX(edge_opt), "Top");
191 gtk_combo_box_append_text(GTK_COMBO_BOX(edge_opt), "Bottom");
192 g_signal_connect(G_OBJECT(edge_opt), "changed", G_CALLBACK(set_edge), NULL);
193
194 gtk_widget_show(edge_opt);
195
196 hbox = gtk_hbox_new(FALSE, 0);
197 gtk_box_pack_start(GTK_BOX (hbox), edge_opt, FALSE, TRUE, 0);
198 gtk_table_attach(GTK_TABLE(t), hbox, 1, 2, 0, 1, GTK_FILL, 0, 0, 0);
199 gtk_label_set_mnemonic_widget(GTK_LABEL(label), edge_opt);
200
201 //Allignment
202 label = gtk_label_new("Allignment:");
203 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
204 gtk_widget_show(label);
205 gtk_size_group_add_widget(sg, label);
206
207 gtk_table_attach(GTK_TABLE(t), label, 0, 1, 1, 2, GTK_FILL, 0, 0, 0);
208
209 allign_opt = gtk_combo_box_new_text();
210 gtk_combo_box_append_text(GTK_COMBO_BOX(allign_opt), "Left");
211 gtk_combo_box_append_text(GTK_COMBO_BOX(allign_opt), "Center");
212 gtk_combo_box_append_text(GTK_COMBO_BOX(allign_opt), "Right");
213 g_signal_connect(G_OBJECT(allign_opt), "changed", G_CALLBACK(set_allign), NULL);
214 gtk_widget_show(allign_opt);
215
216 hbox = gtk_hbox_new(FALSE, 0);
217 gtk_box_pack_start(GTK_BOX (hbox), allign_opt, FALSE, TRUE, 0);
218 gtk_table_attach(GTK_TABLE(t), hbox, 1, 2, 1, 2, GTK_FILL, 0, 0, 0);
219 gtk_label_set_mnemonic_widget(GTK_LABEL(label), allign_opt);
220
221
222 //Margin
223 margin_label = gtk_label_new("Margin:");
224 gtk_misc_set_alignment(GTK_MISC(margin_label), 0.0, 0.5);
225 gtk_widget_show(margin_label);
226
227 gtk_table_attach(GTK_TABLE(t), margin_label, 2, 3, 1, 2, GTK_FILL, 0, 0, 0);
228
229 margin_adj = (GtkAdjustment *) gtk_adjustment_new (0.0, 0.0, gdk_screen_width(), 1.0, 5.0, 5.0);
230 margin_spinb = gtk_spin_button_new (margin_adj, 1.0, 0);
231 gtk_table_attach(GTK_TABLE(t), margin_spinb, 3, 4, 1, 2, GTK_FILL, 0, 0, 0);
232 gtk_table_set_col_spacing(GTK_TABLE(t), 1, 20);
233
234 RET(frame);
235}
236
237
238static void
239set_width(GtkWidget *item, gpointer bp)
240{
241 int widthtype;
242 gboolean t;
243
244 ENTER;
245
246 widthtype = gtk_combo_box_get_active(GTK_COMBO_BOX(item)) + 1;
247 DBG("widthtype=%d\n", widthtype);
248 t = (widthtype != WIDTH_REQUEST);
249 gtk_widget_set_sensitive(width_spinb, t);
250 if (widthtype == WIDTH_PERCENT) {
251 width_adj->upper = 100;
252 width_adj->value = width_adj->upper;
253 } else if (widthtype == WIDTH_PIXEL) {
254 width_adj->upper = gdk_screen_width();
255 width_adj->value = width_adj->upper;
256 } else
257 RET();
258
259 gtk_adjustment_changed(width_adj);
260 gtk_adjustment_value_changed(width_adj);
261
262 RET();
263}
264
265
266GtkWidget *
267mk_size()
268{
269 GtkWidget *hbox, *hbox2, *label, *frame;
270 GtkWidget *t;
271
272
273 ENTER;
274 frame = gtk_frame_new(NULL);
275 gtk_frame_set_shadow_type(GTK_FRAME (frame), GTK_SHADOW_NONE);
276 gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
277 label = gtk_label_new(NULL);
278 gtk_label_set_markup(GTK_LABEL (label),"<span weight=\"bold\">Size</span>");
279 gtk_frame_set_label_widget(GTK_FRAME (frame), label);
280
281 hbox2 = gtk_hbox_new(FALSE, 0);
282 gtk_container_set_border_width (GTK_CONTAINER (hbox2), 6);
283 gtk_container_add (GTK_CONTAINER (frame), hbox2);
284
285 hbox = gtk_hbox_new(FALSE, 0);
286 gtk_widget_set_size_request(hbox, 20, 1);
287 gtk_box_pack_start(GTK_BOX (hbox2), hbox, FALSE, TRUE, 0);
288
289 t = gtk_table_new(3, 2, FALSE);
290 gtk_table_set_row_spacings(GTK_TABLE(t), 3);
291 gtk_table_set_col_spacings(GTK_TABLE(t), 5);
292 gtk_box_pack_start(GTK_BOX (hbox2), t, FALSE, TRUE, 0);
293
294 //width
295 label = gtk_label_new("Width:");
296 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
297 gtk_widget_show(label);
298 gtk_table_attach(GTK_TABLE(t), label, 0, 1, 0, 1, GTK_FILL, 0, 0, 0);
299 gtk_size_group_add_widget(sg, label);
300
301 width_adj = (GtkAdjustment *) gtk_adjustment_new (20.0, 0.0, 2100.0, 1.0, 5.0, 5.0);
302 width_spinb = gtk_spin_button_new (width_adj, 1.0, 0);
303 gtk_table_attach(GTK_TABLE(t), width_spinb, 1, 2, 0, 1, GTK_FILL, 0, 0, 0);
304
305
306 width_opt = gtk_combo_box_new_text();
307 gtk_combo_box_append_text(GTK_COMBO_BOX(width_opt), "dynamic");
308 gtk_combo_box_append_text(GTK_COMBO_BOX(width_opt), "pixels");
309 gtk_combo_box_append_text(GTK_COMBO_BOX(width_opt), "% of edge");
310 g_signal_connect(G_OBJECT(width_opt), "changed", G_CALLBACK(set_width), NULL);
311 gtk_widget_show(width_opt);
312
313
314 hbox = gtk_hbox_new(FALSE, 0);
315 gtk_box_pack_start(GTK_BOX (hbox), width_opt, FALSE, TRUE, 0);
316 gtk_table_attach(GTK_TABLE(t), hbox, 2, 3, 0, 1, GTK_FILL, 0, 0, 0);
317 gtk_label_set_mnemonic_widget(GTK_LABEL(label), width_opt);
318
319
320 //height
321 label = gtk_label_new("Height:");
322 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
323 gtk_widget_show(label);
324 gtk_table_attach(GTK_TABLE(t), label, 0, 1, 1, 2, GTK_FILL, 0, 0, 0);
325 gtk_size_group_add_widget(sg, label);
326
327 height_adj = (GtkAdjustment *) gtk_adjustment_new (30.0, 0.0, 300.0, 1.0, 5.0, 5.0);
328 height_spinb = gtk_spin_button_new (height_adj, 1.0, 0);
329 gtk_table_attach(GTK_TABLE(t), height_spinb, 1, 2, 1, 2, GTK_FILL, 0, 0, 0);
330
331
332 height_opt = gtk_combo_box_new_text();
333 gtk_combo_box_append_text(GTK_COMBO_BOX(height_opt), "pixels");
334 //g_signal_connect(G_OBJECT(height_opt), "changed", G_CALLBACK(set_height), NULL);
335 gtk_widget_show(height_opt);
336
337 hbox = gtk_hbox_new(FALSE, 0);
338 gtk_box_pack_start(GTK_BOX (hbox), height_opt, FALSE, TRUE, 0);
339 gtk_table_attach(GTK_TABLE(t), hbox, 2, 3, 1, 2, GTK_FILL, 0, 0, 0);
340 gtk_label_set_mnemonic_widget(GTK_LABEL(label), height_opt);
341
342 RET(frame);
343}
344
345static void
346transparency_toggle(GtkWidget *b, gpointer bp)
347{
348 gboolean t;
349
350 ENTER;
351 t = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b));
352 gtk_widget_set_sensitive(tr_colorl, t);
353 gtk_widget_set_sensitive(tr_colorb, t);
354 RET();
355}
356
357GtkWidget *
358mk_transparency()
359{
360 GtkWidget *hbox, *hbox2, *label, *frame;
361
362 ENTER;
363 frame = gtk_frame_new(NULL);
364 gtk_frame_set_shadow_type(GTK_FRAME (frame), GTK_SHADOW_NONE);
365 gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
366 label = gtk_label_new(NULL);
367 gtk_label_set_markup(GTK_LABEL (label),"<span weight=\"bold\">Transparency</span>");
368 gtk_frame_set_label_widget(GTK_FRAME (frame), label);
369
370 hbox2 = gtk_hbox_new(FALSE, 0);
371 gtk_container_set_border_width (GTK_CONTAINER (hbox2), 6);
372 gtk_container_add (GTK_CONTAINER (frame), hbox2);
373
374 hbox = gtk_hbox_new(FALSE, 0);
375 gtk_box_pack_start(GTK_BOX (hbox2), hbox, FALSE, TRUE, 0);
376 gtk_widget_set_size_request(hbox, 20, 1);
377
378 hbox = gtk_hbox_new(FALSE, 5);
379 gtk_box_pack_start(GTK_BOX (hbox2), hbox, FALSE, TRUE, 0);
380
381 tr_checkb = gtk_check_button_new_with_label("Enable Transparency");
382 gtk_widget_show(tr_checkb);
383 gtk_box_pack_start(GTK_BOX (hbox), tr_checkb, FALSE, FALSE, 0);
384 g_signal_connect(G_OBJECT(tr_checkb), "toggled", G_CALLBACK(transparency_toggle), NULL);
385 //gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tr_checkb), FALSE);
386
387 tr_colorl = gtk_label_new("Tint color:");
388 gtk_misc_set_alignment(GTK_MISC(tr_colorl), 0.0, 0.5);
389 gtk_widget_show(tr_colorl);
390 gtk_box_pack_start(GTK_BOX (hbox), tr_colorl, FALSE, FALSE, 5);
391 //gtk_widget_set_sensitive(tr_colorl, FALSE);
392
393 tr_colorb = gtk_color_button_new();
394 gtk_color_button_set_use_alpha(GTK_COLOR_BUTTON(tr_colorb), TRUE);
395 gtk_color_button_set_alpha (GTK_COLOR_BUTTON(tr_colorb), 65535/256*125);
396 gtk_box_pack_start(GTK_BOX (hbox), tr_colorb, FALSE, FALSE, 0);
397 //gtk_widget_set_sensitive(tr_colorb, FALSE);
398
399 RET(frame);
400}
401
402GtkWidget *
403mk_properties()
404{
405 GtkWidget *vbox, *hbox, *hbox2, *label, *frame;
406
407 ENTER;
408 frame = gtk_frame_new(NULL);
409 gtk_frame_set_shadow_type(GTK_FRAME (frame), GTK_SHADOW_NONE);
410 gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
411 label = gtk_label_new(NULL);
412 gtk_label_set_markup(GTK_LABEL (label),"<span weight=\"bold\">Properties</span>");
413 gtk_frame_set_label_widget(GTK_FRAME (frame), label);
414
415 hbox2 = gtk_hbox_new(FALSE, 0);
416 gtk_container_add (GTK_CONTAINER (frame), hbox2);
417 gtk_container_set_border_width (GTK_CONTAINER (hbox2), 6);
418
419 hbox = gtk_hbox_new(FALSE, 0);
420 gtk_box_pack_start(GTK_BOX (hbox2), hbox, FALSE, TRUE, 0);
421 gtk_widget_set_size_request(hbox, 20, 1);
422
423 vbox = gtk_vbox_new(FALSE, 0);
424 gtk_box_pack_start(GTK_BOX (hbox2), vbox, FALSE, TRUE, 0);
425
426 prop_dt_checkb = gtk_check_button_new_with_label("Set Dock Type");
427 gtk_box_pack_start(GTK_BOX (vbox), prop_dt_checkb, FALSE, FALSE, 0);
428
429 prop_st_checkb = gtk_check_button_new_with_label("Set Strut");
430 gtk_box_pack_start(GTK_BOX (vbox), prop_st_checkb, FALSE, FALSE, 0);
431
432 RET(frame);
433}
434
435static void
436dialog_destroy_event(GtkWidget * widget, GdkEvent * event, gpointer data)
437{
438 ENTER;
439 dialog = NULL;
440 RET();
441}
442
443static gint
444dialog_delete_event( GtkWidget *widget, GdkEvent *event, gpointer data )
445{
446
447 ENTER;
448 //if (!p->self_destroy)
449 RET(FALSE);
450}
451
452static GtkWidget *
453mk_tab_plugins()
454{
455 GtkWidget *sw, *paned, *hbox, *label;
456
457 paned = gtk_vpaned_new();
458
459 hbox = gtk_hbox_new(FALSE, 0);
460 label = gtk_label_new("Right-click to get context menu. Drag & Drop to change order.");
461 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
462 gtk_box_pack_end(GTK_BOX(hbox), label, TRUE, TRUE, 5);
463
464 gtk_paned_add1(GTK_PANED(paned), hbox);
465
466 sw = gtk_label_new("Plugins...");
467 gtk_paned_add2(GTK_PANED(paned), sw);
468
469 RET(paned);
470}
471
472static GtkWidget *
473mk_tab_general()
474{
475 GtkWidget *frame, *page;
476
477 /*
478 sw = gtk_scrolled_window_new(NULL, NULL);
479 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
480 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_NONE);
481 gtk_container_set_border_width(GTK_CONTAINER(sw), 0);
482 */
483 page = gtk_vbox_new(FALSE, 1);
484
485 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
486
487 //position
488 frame = mk_position();
489 DBG("here\n");
490 gtk_box_pack_start(GTK_BOX (page), frame, FALSE, TRUE, 0);
491
492 //size
493 frame = mk_size();
494 gtk_box_pack_start(GTK_BOX (page), frame, FALSE, TRUE, 0);
495
496 //transparency
497 frame = mk_transparency();
498 gtk_box_pack_start(GTK_BOX (page), frame, FALSE, TRUE, 0);
499
500 //properties
501 frame = mk_properties();
502 gtk_box_pack_start(GTK_BOX (page), frame, FALSE, TRUE, 0);
503 /*
504 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW (sw), page);
505 */
506 RET(page);
507}
508
509
510static GtkWidget *
511mk_dialog()
512{
513 GtkWidget *sw, *nb, *label;
514
515 DBG("creating dialog\n");
516 dialog = gtk_dialog_new_with_buttons ("lxpanel configurator",
517 NULL,
518 0, //GTK_DIALOG_DESTROY_WITH_PARENT,
519 GTK_STOCK_APPLY,
520 GTK_RESPONSE_APPLY,
521 GTK_STOCK_CLOSE,
522 GTK_RESPONSE_CLOSE,
523 NULL);
524 DBG("connecting sugnal to %p\n", dialog);
525 g_signal_connect (G_OBJECT(dialog), "response", (GCallback) response_event, NULL);
526 g_signal_connect (G_OBJECT(dialog), "destroy", (GCallback) dialog_destroy_event, NULL);
527 g_signal_connect (G_OBJECT(dialog), "delete_event", (GCallback) dialog_delete_event, NULL);
528 gtk_window_set_modal(GTK_WINDOW(dialog), FALSE);
529 gtk_window_set_default_size(GTK_WINDOW(dialog), 400, 500);
530
531 //gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), TRUE);
532 //gtk_window_set_skip_pager_hint(GTK_WINDOW(dialog), TRUE);
533
534 nb = gtk_notebook_new();
535 gtk_notebook_set_show_border (GTK_NOTEBOOK(nb), FALSE);
536 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), nb);
537
538 sw = mk_tab_general();
539 label = gtk_label_new("General");
540 gtk_misc_set_padding(GTK_MISC(label), 4, 1);
541 gtk_notebook_append_page(GTK_NOTEBOOK(nb), sw, label);
542
543 sw = mk_tab_plugins();
544 label = gtk_label_new("Plugins");
545 gtk_misc_set_padding(GTK_MISC(label), 4, 1);
546 gtk_notebook_append_page(GTK_NOTEBOOK(nb), sw, label);
547
548 g_object_unref(sg);
549
550 //gtk_widget_show_all(page);
551 gtk_widget_show_all(dialog);
552
553 RET(dialog);
554}
555
556static void
557update_opt_menu(GtkWidget *w, int ind)
558{
559 int i;
560
561 ENTER;
562 /* this trick will trigger "changed" signal even if active entry is
563 * not actually changing */
564 i = gtk_combo_box_get_active(GTK_COMBO_BOX(w));
565 if (i == ind) {
566 i = i ? 0 : 1;
567 gtk_combo_box_set_active(GTK_COMBO_BOX(w), i);
568 }
569 gtk_combo_box_set_active(GTK_COMBO_BOX(w), ind);
570 RET();
571}
572
573static void
574update_toggle_button(GtkWidget *w, gboolean n)
575{
576 gboolean c;
577
578 ENTER;
579 /* this trick will trigger "changed" signal even if active entry is
580 * not actually changing */
581 c = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
582 if (c == n) {
583 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), !n);
584 }
585 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), n);
586 RET();
587}
588
589
590
591
592void
593configure(void)
594{
595 ENTER;
596 DBG("dialog %p\n", dialog);
597 if (!dialog)
598 dialog = mk_dialog();
599 gtk_widget_show(dialog);
600
601 update_opt_menu(edge_opt, p->edge - 1);
602 update_opt_menu(allign_opt, p->allign - 1);
603 //gtk_adjustment_set_value(margin_adj, p->margin);
604 //gtk_adjustment_value_changed(margin_adj);
605 gtk_spin_button_set_value(GTK_SPIN_BUTTON(margin_spinb), p->margin);
606
607 update_opt_menu(width_opt, p->widthtype - 1);
608 gtk_adjustment_set_value(width_adj, p->width);
609 update_opt_menu(height_opt, HEIGHT_PIXEL - 1);
610 gtk_adjustment_set_value(height_adj, p->height);
611
612 update_toggle_button(tr_checkb, p->transparent);
613 gtk_color_button_set_color(GTK_COLOR_BUTTON(tr_colorb), &p->gtintcolor);
614 gtk_color_button_set_alpha (GTK_COLOR_BUTTON(tr_colorb), 256*p->alpha);
615 gtk_widget_show(dialog);
616
617 update_toggle_button(prop_dt_checkb, p->setdocktype);
618 update_toggle_button(prop_st_checkb, p->setstrut);
619 RET();
620}
621
622void
623global_config_save(FILE *fp)
624{
625 GdkColor c;
626
627 fprintf(fp, "# lxpanel <profile> config file\n");
628 fprintf(fp, "# see http://lxpanel.sf.net/docs.html for complete configuration guide\n");
629 fprintf(fp, "\n\n");
630 fprintf(fp, "Global {\n");
631 fprintf(fp, " edge = %s\n",
632 num2str(edge_pair, gtk_combo_box_get_active(GTK_COMBO_BOX(edge_opt)) + 1, "none"));
633 fprintf(fp, " allign = %s\n",
634 num2str(allign_pair, gtk_combo_box_get_active(GTK_COMBO_BOX(allign_opt)) + 1, "none"));
635 fprintf(fp, " margin = %d\n", (int) margin_adj->value);
636 fprintf(fp, " widthtype = %s\n",
637 num2str(width_pair, gtk_combo_box_get_active(GTK_COMBO_BOX(width_opt)) + 1, "none"));
638 fprintf(fp, " width = %d\n", (int) width_adj->value);
639 fprintf(fp, " height = %d\n", (int) height_adj->value);
640 fprintf(fp, " transparent = %s\n",
641 num2str(bool_pair, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tr_checkb)), "false"));
642 gtk_color_button_get_color(GTK_COLOR_BUTTON(tr_colorb), &c);
643 fprintf(fp, " tintcolor = #%06x\n", gcolor2rgb24(&c));
644 fprintf(fp, " alpha = %d\n", gtk_color_button_get_alpha(GTK_COLOR_BUTTON(tr_colorb)) * 0xff / 0xffff);
645 fprintf(fp, " setdocktype = %s\n",
646 num2str(bool_pair, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(prop_dt_checkb)), "true"));
647 fprintf(fp, " setpartialstrut = %s\n",
648 num2str(bool_pair, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(prop_st_checkb)), "true"));
649
650 fprintf(fp, "}\n\n");
651}
652
653#define TAB_WIDTH 4
654#define STR_LEN 254
655void
656plugin_config_save(FILE *fp)
657{
658 char space[STR_LEN];
659 line s;
660 int i = 0;
661 fseek(pconf, 0, SEEK_SET);
662 /*
663 while (fgets(s, 254, pconf))
664 fprintf(fp, "%s\n", s);
665 */
666 memset(space, ' ', STR_LEN);
667 space[STR_LEN -1] = 0;
668 s.len = 256;
669 while (get_line(pconf, &s) != LINE_NONE) {
670 switch (s.type) {
671 case LINE_BLOCK_START:
672 space[i*TAB_WIDTH] = 0;
673 fprintf(fp, "%s%s {\n", space, s.t[0]);
674 space[i*TAB_WIDTH] = ' ';
675 i++;
676 //just for the case
677 if (i > STR_LEN/TAB_WIDTH) {
678 i = STR_LEN/TAB_WIDTH;
679 ERR("too long line in config file\n");
680 }
681 break;
682 case LINE_BLOCK_END:
683 i--;
684 //just for the case
685 if (i < 0) {
686 ERR("unbalansed parenthesis in config file\n");
687 i = 0;
688 }
689 space[i*TAB_WIDTH] = 0;
690 fprintf(fp, "%s}\n", space);
691 space[i*TAB_WIDTH] = ' ';
692 if (!i)
693 fprintf(fp, "\n\n");
694 break;
695
696 case LINE_VAR:
697 space[i*TAB_WIDTH] = 0;
698 fprintf(fp, "%s%s = %s\n", space, s.t[0], s.t[1]);
699 space[i*TAB_WIDTH] = ' ';
700 break;
701 }
702 }
703
704}
705
706
707void
708restart(void)
709{
710 ENTER;
711 RET();
712}
713