Add plugin configuration page.
[lxde/lxpanel.git] / src / configurator.c
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 #include <glib/gi18n.h>
16
17 //#define DEBUG
18 #include "dbg.h"
19
20 void configure(void);
21 void restart(void);
22 void gtk_run(void);
23
24 command commands[] = {
25 { "configure", N_("Preferences"), configure },
26 { "run", N_("Run"), gtk_run },
27 { "restart", N_("Restart"), restart },
28 { NULL, NULL },
29 };
30
31 static GtkWidget *dialog = NULL;
32 static GtkSizeGroup *sg;
33
34 //width
35 static GtkWidget *width_spinb, *width_opt;
36 static GtkAdjustment *width_adj;
37
38 //height
39 static GtkWidget *height_spinb, *height_opt;
40 static GtkAdjustment *height_adj;
41
42 //margin
43 static GtkWidget *margin_label, *margin_spinb;
44 static GtkAdjustment *margin_adj;
45
46 //allign
47 static GtkWidget *allign_opt;
48
49 //edge
50 static GtkWidget *edge_opt;
51
52 //transparency
53 static GtkWidget *tr_checkb, *tr_colorl, *tr_colorb;;
54
55 //properties
56 static GtkWidget *prop_dt_checkb, *prop_st_checkb;
57
58 extern panel *p;
59 extern gchar *cprofile;
60 extern int config;
61 extern FILE *pconf;
62
63 void global_config_save(FILE *fp);
64 void plugin_config_save(FILE *fp);
65
66 static int
67 mk_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
88 static void
89 response_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
127 static void
128 set_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
139 static void
140 set_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
155 GtkWidget *
156 mk_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);
167 gtk_label_set_markup(GTK_LABEL (label),_("<b>Position</b>"));
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
184 label = gtk_label_new(_("Edge:"));
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();
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"));
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
204 //Alignment
205 label = gtk_label_new(_("Alignment:"));
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();
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"));
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
226 margin_label = gtk_label_new(_("Margin:"));
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
241 static void
242 set_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
269 GtkWidget *
270 mk_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);
281 gtk_label_set_markup(GTK_LABEL (label),_("<b>Size</b>"));
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
298 label = gtk_label_new(_("Width:"));
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();
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"));
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
324 label = gtk_label_new(_("Height:"));
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();
336 gtk_combo_box_append_text(GTK_COMBO_BOX(height_opt), _("pixels"));
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
348 static void
349 transparency_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
360 GtkWidget *
361 mk_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);
370 gtk_label_set_markup(GTK_LABEL (label),_("<b>Transparency</b>"));
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
384 tr_checkb = gtk_check_button_new_with_label(_("Enable Transparency"));
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
390 tr_colorl = gtk_label_new(_("Tint color:"));
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
405 GtkWidget *
406 mk_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);
415 gtk_label_set_markup(GTK_LABEL (label),_("<b>Properties</b>"));
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
429 prop_dt_checkb = gtk_check_button_new_with_label(_("Set Dock Type"));
430 gtk_box_pack_start(GTK_BOX (vbox), prop_dt_checkb, FALSE, FALSE, 0);
431
432 prop_st_checkb = gtk_check_button_new_with_label(_("Set Strut"));
433 gtk_box_pack_start(GTK_BOX (vbox), prop_st_checkb, FALSE, FALSE, 0);
434
435 RET(frame);
436 }
437
438 static void
439 dialog_destroy_event(GtkWidget * widget, GdkEvent * event, gpointer data)
440 {
441 ENTER;
442 dialog = NULL;
443 RET();
444 }
445
446 static gint
447 dialog_delete_event( GtkWidget *widget, GdkEvent *event, gpointer data )
448 {
449
450 ENTER;
451 //if (!p->self_destroy)
452 RET(FALSE);
453 }
454
455 static void
456 on_sel_plugin_changed( GtkTreeSelection* tree_sel, gpointer user_data )
457 {
458
459 }
460
461 static void init_plugin_list( GtkTreeView* view )
462 {
463 /* extern panel *p; */
464 GtkListStore* list;
465 GtkTreeViewColumn* col;
466 GtkCellRenderer* render;
467 GtkTreeSelection* tree_sel;
468 GList* l;
469
470 render = gtk_cell_renderer_text_new();
471 col = gtk_tree_view_column_new_with_attributes(
472 _("Currently loaded plugins"),
473 render, "text", 0, NULL );
474 gtk_tree_view_append_column( view, col );
475
476 list = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_POINTER );
477 for( l = p->plugins; l; l = l->next )
478 {
479 GtkTreeIter it;
480 plugin* pl = (plugin*)l->data;
481 gtk_list_store_append( list, &it );
482 gtk_list_store_set( list, &it,
483 0, _(pl->class->name),
484 1, pl, -1);
485 }
486 gtk_tree_view_set_model( view, GTK_TREE_MODEL( list ) );
487
488 tree_sel = gtk_tree_view_get_selection( view );
489 g_signal_connect( tree_sel, "changed",
490 G_CALLBACK(on_sel_plugin_changed), NULL);
491 }
492
493 static void on_add_plugin( GtkButton* btn, GtkTreeView* view )
494 {
495
496 }
497
498 static void on_remove_plugin( GtkButton* btn, GtkTreeView* view )
499 {
500
501 }
502
503 static int get_widget_index( plugin* pl )
504 {
505 GList* l;
506 int i;
507 for( i = 0, l = p->plugins; l; l = l->next )
508 {
509 plugin* _pl = (plugin*)l->data;
510 if( _pl == pl )
511 return i;
512 if( _pl->pwid )
513 ++i;
514 }
515 return -1;
516 }
517
518 static void on_moveup_plugin( GtkButton* btn, GtkTreeView* view )
519 {
520 GList *l;
521 GtkTreeIter it, prev;
522 GtkTreeModel* model = gtk_tree_view_get_model( view );
523 GtkTreeSelection* tree_sel = gtk_tree_view_get_selection( view );
524 int i;
525
526 if( ! gtk_tree_model_get_iter_first( model, &it ) )
527 return;
528 if( gtk_tree_selection_iter_is_selected( tree_sel, &it ) )
529 return;
530 do{
531 if( gtk_tree_selection_iter_is_selected(tree_sel, &it) )
532 {
533 plugin* pl;
534 gtk_tree_model_get( model, &it, 1, &pl, -1 );
535 gtk_list_store_move_before( GTK_LIST_STORE( model ),
536 &it, &prev );
537
538 i = 0;
539 for( l = p->plugins; l; l = l->next, ++i )
540 {
541 if( l->data == pl )
542 {
543 p->plugins = g_list_insert( p->plugins, pl, i - 1);
544 p->plugins = g_list_delete_link( p->plugins, l);
545 }
546 }
547 if( pl->pwid )
548 {
549 gtk_box_reorder_child( p->box, pl->pwid, get_widget_index( pl ) );
550 }
551 return;
552 }
553 prev = it;
554 }while( gtk_tree_model_iter_next( model, &it ) );
555 }
556
557 static void on_movedown_plugin( GtkButton* btn, GtkTreeView* view )
558 {
559 GList *l;
560 GtkTreeIter it, next;
561 GtkTreeModel* model;
562 GtkTreeSelection* tree_sel = gtk_tree_view_get_selection( view );
563 GtkTreePath* path;
564 plugin* pl;
565 int i;
566
567 if( ! gtk_tree_selection_get_selected( tree_sel, &model, &it ) )
568 return;
569 next = it;
570
571 if( ! gtk_tree_model_iter_next( model, &next) )
572 return;
573
574 gtk_tree_model_get( model, &it, 1, &pl, -1 );
575
576 gtk_list_store_move_after( GTK_LIST_STORE( model ), &it, &next );
577
578 i = 0;
579 for( l = p->plugins; l; l = l->next, ++i )
580 {
581 if( l->data == pl )
582 {
583 p->plugins = g_list_insert( p->plugins, pl, i + 2);
584 p->plugins = g_list_delete_link( p->plugins, l);
585 }
586 }
587 if( pl->pwid )
588 {
589 gtk_box_reorder_child( p->box, pl->pwid, get_widget_index( pl ) );
590 }
591 }
592
593 static GtkWidget *
594 mk_tab_plugins()
595 {
596 GtkWidget *sw, *paned, *hbox, *vbox, *rvbox, *label;
597 GtkWidget *scroll, *plugin_list, *button, *image;
598
599 paned = gtk_hpaned_new();
600 vbox = gtk_vbox_new( FALSE, 2 );
601 gtk_paned_pack1(GTK_PANED(paned), vbox, TRUE, FALSE);
602
603 /* Left pane */
604 plugin_list = gtk_tree_view_new();
605 /* plugin list */
606 scroll = gtk_scrolled_window_new(NULL, NULL);
607 gtk_scrolled_window_set_policy( scroll, GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
608 gtk_container_add( GTK_CONTAINER(scroll), plugin_list );
609 gtk_box_pack_start( GTK_BOX( vbox ), scroll, TRUE, TRUE, 4 );
610
611 init_plugin_list( GTK_TREE_VIEW( plugin_list ) );
612
613 /* buttons used to edit plugin list */
614 hbox = gtk_hbox_new( FALSE, 2 );
615 gtk_box_pack_start( GTK_BOX( vbox ), hbox, FALSE, FALSE, 4 );
616 button = gtk_button_new_with_mnemonic( _("_Add" ) );
617 gtk_box_pack_start( GTK_BOX( hbox ), button, FALSE, FALSE, 2 );
618 g_signal_connect( button, "clicked", G_CALLBACK(on_add_plugin), plugin_list );
619
620 button = gtk_button_new_with_mnemonic( _("_Remove") );
621 gtk_box_pack_start( GTK_BOX( hbox ), button, FALSE, FALSE, 2 );
622 g_signal_connect( button, "clicked", G_CALLBACK(on_remove_plugin), plugin_list );
623
624 button = gtk_button_new();
625 gtk_container_add( button, gtk_image_new_from_stock(GTK_STOCK_GO_UP, GTK_ICON_SIZE_BUTTON) );
626 gtk_box_pack_start( GTK_BOX( hbox ), button, FALSE, FALSE, 2 );
627 g_signal_connect( button, "clicked", G_CALLBACK(on_moveup_plugin), plugin_list );
628
629 button = gtk_button_new();
630 gtk_container_add( button, gtk_image_new_from_stock(GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_BUTTON) );
631 gtk_box_pack_start( GTK_BOX( hbox ), button, FALSE, FALSE, 2 );
632 g_signal_connect( button, "clicked", G_CALLBACK(on_movedown_plugin), plugin_list );
633
634 /* Right pane */
635 vbox = gtk_vbox_new( FALSE, 2 );
636 gtk_paned_add2(GTK_PANED(paned), vbox);
637
638 /* Label displaying plugin descriptions */
639 label = gtk_label_new("");
640 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
641 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 4);
642
643 RET(paned);
644 }
645
646 static GtkWidget *
647 mk_tab_general()
648 {
649 GtkWidget *frame, *page;
650
651 /*
652 sw = gtk_scrolled_window_new(NULL, NULL);
653 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
654 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_NONE);
655 gtk_container_set_border_width(GTK_CONTAINER(sw), 0);
656 */
657 page = gtk_vbox_new(FALSE, 1);
658
659 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
660
661 //position
662 frame = mk_position();
663 DBG("here\n");
664 gtk_box_pack_start(GTK_BOX (page), frame, FALSE, TRUE, 0);
665
666 //size
667 frame = mk_size();
668 gtk_box_pack_start(GTK_BOX (page), frame, FALSE, TRUE, 0);
669
670 //transparency
671 frame = mk_transparency();
672 gtk_box_pack_start(GTK_BOX (page), frame, FALSE, TRUE, 0);
673
674 //properties
675 frame = mk_properties();
676 gtk_box_pack_start(GTK_BOX (page), frame, FALSE, TRUE, 0);
677 /*
678 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW (sw), page);
679 */
680 RET(page);
681 }
682
683
684 static GtkWidget *
685 mk_dialog()
686 {
687 GtkWidget *sw, *nb, *label;
688
689 DBG("creating dialog\n");
690 dialog = gtk_dialog_new_with_buttons (_("lxpanel configurator"),
691 NULL,
692 0, //GTK_DIALOG_DESTROY_WITH_PARENT,
693 GTK_STOCK_APPLY,
694 GTK_RESPONSE_APPLY,
695 GTK_STOCK_CLOSE,
696 GTK_RESPONSE_CLOSE,
697 NULL);
698 DBG("connecting sugnal to %p\n", dialog);
699 g_signal_connect (G_OBJECT(dialog), "response", (GCallback) response_event, NULL);
700 g_signal_connect (G_OBJECT(dialog), "destroy", (GCallback) dialog_destroy_event, NULL);
701 g_signal_connect (G_OBJECT(dialog), "delete_event", (GCallback) dialog_delete_event, NULL);
702 gtk_window_set_modal(GTK_WINDOW(dialog), FALSE);
703 gtk_window_set_default_size(GTK_WINDOW(dialog), 400, 500);
704
705 //gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), TRUE);
706 //gtk_window_set_skip_pager_hint(GTK_WINDOW(dialog), TRUE);
707
708 nb = gtk_notebook_new();
709 gtk_notebook_set_show_border (GTK_NOTEBOOK(nb), FALSE);
710 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), nb);
711
712 sw = mk_tab_general();
713 label = gtk_label_new(_("General"));
714 gtk_misc_set_padding(GTK_MISC(label), 4, 1);
715 gtk_notebook_append_page(GTK_NOTEBOOK(nb), sw, label);
716
717 sw = mk_tab_plugins();
718 label = gtk_label_new(_("Plugins"));
719 gtk_misc_set_padding(GTK_MISC(label), 4, 1);
720 gtk_notebook_append_page(GTK_NOTEBOOK(nb), sw, label);
721
722 g_object_unref(sg);
723
724 //gtk_widget_show_all(page);
725 gtk_widget_show_all(dialog);
726
727 RET(dialog);
728 }
729
730 static void
731 update_opt_menu(GtkWidget *w, int ind)
732 {
733 int i;
734
735 ENTER;
736 /* this trick will trigger "changed" signal even if active entry is
737 * not actually changing */
738 i = gtk_combo_box_get_active(GTK_COMBO_BOX(w));
739 if (i == ind) {
740 i = i ? 0 : 1;
741 gtk_combo_box_set_active(GTK_COMBO_BOX(w), i);
742 }
743 gtk_combo_box_set_active(GTK_COMBO_BOX(w), ind);
744 RET();
745 }
746
747 static void
748 update_toggle_button(GtkWidget *w, gboolean n)
749 {
750 gboolean c;
751
752 ENTER;
753 /* this trick will trigger "changed" signal even if active entry is
754 * not actually changing */
755 c = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
756 if (c == n) {
757 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), !n);
758 }
759 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), n);
760 RET();
761 }
762
763
764
765
766 void
767 configure(void)
768 {
769 ENTER;
770 DBG("dialog %p\n", dialog);
771 if (!dialog)
772 dialog = mk_dialog();
773 gtk_widget_show(dialog);
774
775 update_opt_menu(edge_opt, p->edge - 1);
776 update_opt_menu(allign_opt, p->allign - 1);
777 //gtk_adjustment_set_value(margin_adj, p->margin);
778 //gtk_adjustment_value_changed(margin_adj);
779 gtk_spin_button_set_value(GTK_SPIN_BUTTON(margin_spinb), p->margin);
780
781 update_opt_menu(width_opt, p->widthtype - 1);
782 gtk_adjustment_set_value(width_adj, p->width);
783 update_opt_menu(height_opt, HEIGHT_PIXEL - 1);
784 gtk_adjustment_set_value(height_adj, p->height);
785
786 update_toggle_button(tr_checkb, p->transparent);
787 gtk_color_button_set_color(GTK_COLOR_BUTTON(tr_colorb), &p->gtintcolor);
788 gtk_color_button_set_alpha (GTK_COLOR_BUTTON(tr_colorb), 256*p->alpha);
789 gtk_widget_show(dialog);
790
791 update_toggle_button(prop_dt_checkb, p->setdocktype);
792 update_toggle_button(prop_st_checkb, p->setstrut);
793 RET();
794 }
795
796 void
797 global_config_save(FILE *fp)
798 {
799 GdkColor c;
800
801 fprintf(fp, "# lxpanel <profile> config file\n");
802 fprintf(fp, "# see http://lxpanel.sf.net/docs.html for complete configuration guide\n");
803 fprintf(fp, "\n\n");
804 fprintf(fp, "Global {\n");
805 fprintf(fp, " edge = %s\n",
806 num2str(edge_pair, gtk_combo_box_get_active(GTK_COMBO_BOX(edge_opt)) + 1, "none"));
807 fprintf(fp, " allign = %s\n",
808 num2str(allign_pair, gtk_combo_box_get_active(GTK_COMBO_BOX(allign_opt)) + 1, "none"));
809 fprintf(fp, " margin = %d\n", (int) margin_adj->value);
810 fprintf(fp, " widthtype = %s\n",
811 num2str(width_pair, gtk_combo_box_get_active(GTK_COMBO_BOX(width_opt)) + 1, "none"));
812 fprintf(fp, " width = %d\n", (int) width_adj->value);
813 fprintf(fp, " height = %d\n", (int) height_adj->value);
814 fprintf(fp, " transparent = %s\n",
815 num2str(bool_pair, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tr_checkb)), "false"));
816 gtk_color_button_get_color(GTK_COLOR_BUTTON(tr_colorb), &c);
817 fprintf(fp, " tintcolor = #%06x\n", gcolor2rgb24(&c));
818 fprintf(fp, " alpha = %d\n", gtk_color_button_get_alpha(GTK_COLOR_BUTTON(tr_colorb)) * 0xff / 0xffff);
819 fprintf(fp, " setdocktype = %s\n",
820 num2str(bool_pair, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(prop_dt_checkb)), "true"));
821 fprintf(fp, " setpartialstrut = %s\n",
822 num2str(bool_pair, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(prop_st_checkb)), "true"));
823
824 fprintf(fp, "}\n\n");
825 }
826
827 #define TAB_WIDTH 4
828 #define STR_LEN 254
829 void
830 plugin_config_save(FILE *fp)
831 {
832 char space[STR_LEN];
833 line s;
834 int i = 0;
835 fseek(pconf, 0, SEEK_SET);
836 /*
837 while (fgets(s, 254, pconf))
838 fprintf(fp, "%s\n", s);
839 */
840 memset(space, ' ', STR_LEN);
841 space[STR_LEN -1] = 0;
842 s.len = 256;
843 while (get_line(pconf, &s) != LINE_NONE) {
844 switch (s.type) {
845 case LINE_BLOCK_START:
846 space[i*TAB_WIDTH] = 0;
847 fprintf(fp, "%s%s {\n", space, s.t[0]);
848 space[i*TAB_WIDTH] = ' ';
849 i++;
850 //just for the case
851 if (i > STR_LEN/TAB_WIDTH) {
852 i = STR_LEN/TAB_WIDTH;
853 ERR("too long line in config file\n");
854 }
855 break;
856 case LINE_BLOCK_END:
857 i--;
858 //just for the case
859 if (i < 0) {
860 ERR("unbalansed parenthesis in config file\n");
861 i = 0;
862 }
863 space[i*TAB_WIDTH] = 0;
864 fprintf(fp, "%s}\n", space);
865 space[i*TAB_WIDTH] = ' ';
866 if (!i)
867 fprintf(fp, "\n\n");
868 break;
869
870 case LINE_VAR:
871 space[i*TAB_WIDTH] = 0;
872 fprintf(fp, "%s%s = %s\n", space, s.t[0], s.t[1]);
873 space[i*TAB_WIDTH] = ' ';
874 break;
875 }
876 }
877
878 }
879
880
881 void
882 restart(void)
883 {
884 ENTER;
885 RET();
886 }
887