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