]> Dogcows Code - chaz/tint2/blob - src/tint2conf/main.c
add some code around taskbar_name
[chaz/tint2] / src / tint2conf / main.c
1 /**************************************************************************
2 *
3 * Tint2conf
4 *
5 * Copyright (C) 2009 Thierry lorthiois (lorthiois@bbsoft.fr)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version 2
9 * as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 **************************************************************************/
19
20 #ifdef HAVE_VERSION_H
21 #include "version.h"
22 #endif
23 #include "main.h"
24 #include "common.h"
25 #include "theme_view.h"
26 #include "properties.h"
27
28 #define SNAPSHOT_TICK 190
29
30
31 // default config file and directory
32 char *g_path_config = NULL;
33 char *g_path_dir = NULL;
34 char *g_default_theme = NULL;
35 char *g_cmd_property = NULL;
36 int g_width, g_height;
37
38 GtkWidget *g_window;
39
40 static GtkUIManager *globalUIManager = NULL;
41
42 static void menuAddWidget (GtkUIManager *, GtkWidget *, GtkContainer *);
43
44 // action on menus
45 static void menuAdd();
46 static void menuSaveAs();
47 static void menuDelete();
48 static void menuProperties();
49 static void menuQuit();
50 static void menuRefresh();
51 static void menuRefreshAll();
52 static void menuApply();
53 static void menuAbout();
54
55 static gboolean view_onPopupMenu (GtkWidget *treeview, gpointer userdata);
56 static gboolean view_onButtonPressed (GtkWidget *treeview, GdkEventButton *event, gpointer userdata);
57 static void windowSizeAllocated();
58 static void viewRowActivated(GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data);
59
60
61 // theme files
62 static void selectTheme(const gchar *name);
63 static gboolean searchTheme(const gchar *name_theme, GtkTreeModel *model, GtkTreeIter *iter);
64 static void load_theme();
65 static void initTheme();
66 static void read_config();
67 static void write_config();
68
69
70 // define menubar, toolbar and popup
71 static const char *global_ui =
72 "<ui>"
73 " <menubar name='MenuBar'>"
74 " <menu action='ThemeMenu'>"
75 " <menuitem action='ThemeAdd'/>"
76 " <menuitem action='ThemeSaveAs'/>"
77 " <separator/>"
78 " <menuitem action='ThemeDelete'/>"
79 " <separator/>"
80 // " <menuitem action='ThemeProperties'/>"
81 // " <separator/>"
82 " <menuitem action='ThemeQuit'/>"
83 " </menu>"
84 " <menu action='EditMenu'>"
85 " <menuitem action='EditRefresh'/>"
86 " <menuitem action='EditRefreshAll'/>"
87 // " <separator/>"
88 // " <menuitem action='EditPreferences'/>"
89 " </menu>"
90 " <menu action='HelpMenu'>"
91 " <menuitem action='HelpAbout'/>"
92 " </menu>"
93 " </menubar>"
94 " <toolbar name='ToolBar'>"
95 " <toolitem action='ThemeProperties'/>"
96 " <toolitem action='ViewApply'/>"
97 " </toolbar>"
98 " <popup name='ThemePopup'>"
99 " <menuitem action='ThemeProperties'/>"
100 " <menuitem action='EditRefresh'/>"
101 " <menuitem action='ViewApply'/>"
102 " <separator/>"
103 " <menuitem action='ThemeDelete'/>"
104 " </popup>"
105 "</ui>";
106
107
108 // define menubar and toolbar action
109 static GtkActionEntry entries[] = {
110 {"ThemeMenu", NULL, _("Theme"), NULL, NULL, NULL},
111 {"ThemeAdd", GTK_STOCK_ADD, _("_Add..."), "<Control>N", _("Add theme"), G_CALLBACK (menuAdd)},
112 {"ThemeSaveAs", GTK_STOCK_SAVE_AS, _("_Save as..."), NULL, _("Save theme as"), G_CALLBACK (menuSaveAs)},
113 {"ThemeDelete", GTK_STOCK_DELETE, _("_Delete"), NULL, _("Delete theme"), G_CALLBACK (menuDelete)},
114 {"ThemeProperties", GTK_STOCK_PROPERTIES, _("_Properties..."), NULL, _("Show properties"), G_CALLBACK (menuProperties)},
115 {"ThemeQuit", GTK_STOCK_QUIT, _("_Quit"), "<control>Q", _("Quit"), G_CALLBACK (menuQuit)},
116 {"EditMenu", NULL, "Edit", NULL, NULL, NULL},
117 {"EditRefresh", GTK_STOCK_REFRESH, _("Refresh"), NULL, _("Refresh"), G_CALLBACK (menuRefresh)},
118 {"EditRefreshAll", GTK_STOCK_REFRESH, _("Refresh all"), NULL, _("Refresh all"), G_CALLBACK (menuRefreshAll)},
119 // {"EditPreferences", GTK_STOCK_PREFERENCES, "Preferences", NULL, "Preferences", G_CALLBACK (menuPreferences)},
120 {"ViewApply", GTK_STOCK_APPLY, _("Apply"), NULL, _("Apply theme"), G_CALLBACK (menuApply)},
121 {"HelpMenu", NULL, _("Help"), NULL, NULL, NULL},
122 {"HelpAbout", GTK_STOCK_ABOUT, _("_About"), "<Control>A", _("About"), G_CALLBACK (menuAbout)}
123 };
124
125
126 int main (int argc, char ** argv)
127 {
128 GtkWidget *vBox = NULL, *scrollbar = NULL;
129 GtkActionGroup *actionGroup;
130
131 gtk_init (&argc, &argv);
132 g_thread_init( NULL );
133 read_config();
134 initTheme();
135
136 // define main layout : container, menubar, toolbar
137 g_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
138 gtk_window_set_title(GTK_WINDOW(g_window), _("Panel theming"));
139 gtk_window_resize(GTK_WINDOW(g_window), g_width, g_height);
140 g_signal_connect(G_OBJECT(g_window), "destroy", G_CALLBACK (menuQuit), NULL);
141 g_signal_connect(g_window, "size-allocate", G_CALLBACK(windowSizeAllocated), NULL);
142 vBox = gtk_vbox_new (FALSE, 0);
143 gtk_container_add (GTK_CONTAINER(g_window), vBox);
144
145 actionGroup = gtk_action_group_new ("menuActionGroup");
146 gtk_action_group_add_actions (actionGroup, entries, G_N_ELEMENTS (entries), NULL);
147 globalUIManager = gtk_ui_manager_new();
148 gtk_ui_manager_insert_action_group (globalUIManager, actionGroup, 0);
149 gtk_ui_manager_add_ui_from_string (globalUIManager, global_ui, -1, NULL );
150 g_signal_connect(globalUIManager, "add_widget", G_CALLBACK (menuAddWidget), vBox);
151 gtk_ui_manager_ensure_update(globalUIManager);
152 scrollbar = gtk_scrolled_window_new(NULL, NULL);
153 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollbar), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
154 gtk_box_pack_start(GTK_BOX(vBox), scrollbar, TRUE, TRUE, 0);
155
156 // define theme view
157 g_theme_view = create_view();
158 gtk_container_add(GTK_CONTAINER(scrollbar), g_theme_view);
159 gtk_widget_show(g_theme_view);
160 g_signal_connect(g_theme_view, "button-press-event", (GCallback)view_onButtonPressed, NULL);
161 g_signal_connect(g_theme_view, "popup-menu", (GCallback)view_onPopupMenu, NULL);
162 g_signal_connect(g_theme_view, "row-activated", G_CALLBACK(viewRowActivated), NULL);
163
164 // load themes
165 load_theme(g_theme_view);
166
167 /* temporaire !!!!!!!!!!!!!!
168 GtkWidget *prop = create_properties();
169 gtk_window_present(GTK_WINDOW(prop));
170 //*/
171 gtk_widget_show_all(g_window);
172 gtk_main ();
173 return 0;
174 }
175
176
177 static void menuAddWidget (GtkUIManager * p_uiManager, GtkWidget * p_widget, GtkContainer * p_box)
178 {
179 gtk_box_pack_start(GTK_BOX(p_box), p_widget, FALSE, FALSE, 0);
180 gtk_widget_show(p_widget);
181 }
182
183
184 static void menuAbout()
185 {
186 const char *authors[] = { "Thierry Lorthiois <lorthiois@bbsoft.fr>", "Andreas Fink <andreas.fink85@googlemail.com>", "Christian Ruppert <Spooky85@gmail.com> (Build system)", "Euan Freeman <euan04@gmail.com> (tintwizard)\n See http://code.google.com/p/tintwizard/", NULL };
187
188 gtk_show_about_dialog(GTK_WINDOW(g_window), "name", g_get_application_name( ),
189 "comments", _("Theming tool for tint2 panel"),
190 "version", VERSION_STRING,
191 "copyright", _("Copyright 2009 tint2 team\nTint2 License GNU GPL version 2\nTintwizard License GNU GPL version 3"),
192 "logo-icon-name", NULL, "authors", authors,
193 /* Translators: translate "translator-credits" as
194 your name to have it appear in the credits in the "About"
195 dialog */
196 "translator-credits", _("translator-credits"),
197 NULL);
198 }
199
200
201 static void menuAdd()
202 {
203 GtkWidget *dialog;
204 GtkFileChooser *chooser;
205 GtkFileFilter *filter;
206
207 dialog = gtk_file_chooser_dialog_new(_("Add a theme"), GTK_WINDOW(g_window), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_ADD, GTK_RESPONSE_ACCEPT, NULL);
208 chooser = GTK_FILE_CHOOSER(dialog);
209
210 gtk_file_chooser_set_current_folder(chooser, g_get_home_dir());
211 gtk_file_chooser_set_select_multiple(chooser, TRUE);
212
213 filter = gtk_file_filter_new();
214 gtk_file_filter_set_name(filter, _("Tint2 theme files"));
215 gtk_file_filter_add_pattern(filter, "*.tint2rc");
216 gtk_file_chooser_add_filter(chooser, filter);
217
218 if (gtk_dialog_run (GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) {
219 gtk_widget_destroy(dialog);
220 return;
221 }
222
223 GtkTreeIter iter;
224 GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_theme_view));
225 GSList *l, *list = gtk_file_chooser_get_filenames(chooser);
226 gchar *file, *pt1, *name, *path, *name_first=NULL;
227 for (l = list; l ; l = l->next) {
228 file = (char *)l->data;
229 pt1 = strrchr(file, '/');
230 if (pt1 == NULL) continue;
231 pt1++;
232 if (*pt1 == 0) continue;
233
234 name = g_strdup(pt1);
235 path = g_build_filename (g_get_user_config_dir(), "tint2", name, NULL);
236
237 // check existing
238 if (searchTheme(path, model, &iter)) {
239 gchar *message;
240 message = g_strdup_printf(_("Couldn't add duplicate theme\n\'%s\'."), pt1);
241
242 GtkWidget *w = gtk_message_dialog_new(GTK_WINDOW(g_window), 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, message, NULL);
243 g_signal_connect_swapped(w, "response", G_CALLBACK(gtk_widget_destroy), w);
244 gtk_widget_show(w);
245 g_free(message);
246 continue;
247 }
248
249 // append theme
250 copy_file(file, path);
251 custom_list_append(path);
252 if (name_first == NULL)
253 name_first = g_strdup(path);
254 g_free(path);
255 g_free(name);
256 }
257 g_slist_foreach(list, (GFunc)g_free, NULL);
258 g_slist_free(list);
259 gtk_widget_destroy(dialog);
260
261 selectTheme(name_first);
262 g_free(name_first);
263 g_timeout_add(SNAPSHOT_TICK, (GSourceFunc)update_snapshot, NULL);
264 }
265
266
267 static void menuSaveAs ()
268 {
269 GtkWidget *dialog;
270 GtkFileChooser *chooser;
271 GtkTreeSelection *sel;
272 GtkTreeIter iter;
273 GtkTreeModel *model;
274 gchar *file, *pt1;
275
276 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view));
277 if (!gtk_tree_selection_get_selected(GTK_TREE_SELECTION(sel), &model, &iter)) {
278 GtkWidget *w = gtk_message_dialog_new(GTK_WINDOW(g_window), 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Select the theme to be saved."));
279 g_signal_connect_swapped(w, "response", G_CALLBACK(gtk_widget_destroy), w);
280 gtk_widget_show(w);
281 return;
282 }
283
284 gtk_tree_model_get(model, &iter, COL_THEME_FILE, &file, -1);
285 pt1 = strrchr (file, '/');
286 if (pt1) pt1++;
287
288 dialog = gtk_file_chooser_dialog_new(_("Save theme as"), GTK_WINDOW(g_window), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);
289 chooser = GTK_FILE_CHOOSER(dialog);
290
291 gtk_file_chooser_set_do_overwrite_confirmation(chooser, TRUE);
292 gtk_file_chooser_set_current_folder(chooser, g_get_home_dir());
293 gtk_file_chooser_set_current_name(chooser, pt1);
294
295 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
296 char *filename = gtk_file_chooser_get_filename(chooser);
297 copy_file(file, filename);
298 g_free (filename);
299 }
300 g_free(file);
301 gtk_widget_destroy (dialog);
302 }
303
304
305 static void menuDelete()
306 {
307 GtkTreeSelection *sel;
308 GtkTreeIter iter;
309 GtkTreeModel *model;
310 gchar *filename;
311
312 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view));
313 if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(sel), &model, &iter)) {
314 gtk_tree_model_get(model, &iter, COL_THEME_FILE, &filename, -1);
315 gtk_tree_selection_unselect_all(sel);
316
317 // remove (gui and file)
318 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
319 GFile *file = g_file_new_for_path(filename);
320 g_file_trash(file, NULL, NULL);
321 g_object_unref(G_OBJECT(file));
322 g_free(filename);
323 }
324 }
325
326
327 static void menuProperties()
328 {
329 GtkTreeSelection *sel;
330 GtkTreeIter iter;
331 GtkTreeModel *model;
332 char *file, *cmd;
333
334 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view));
335 if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(sel), &model, &iter)) {
336 gtk_tree_model_get(model, &iter, COL_THEME_FILE, &file, -1);
337 /*
338 GtkWidget *prop;
339 prop = create_properties();
340 gtk_window_present(GTK_WINDOW(prop));
341 //printf("menuProperties : fin\n");
342 //*/
343
344 cmd = g_strdup_printf("%s \'%s\' &", g_cmd_property, file);
345 printf("cmd %s\n", cmd);
346 system(cmd);
347 g_free(cmd);
348 g_free(file);
349
350 }
351 }
352
353
354 static void menuQuit()
355 {
356 write_config();
357
358 if (g_path_config)
359 g_free(g_path_config);
360 if (g_path_dir)
361 g_free(g_path_dir);
362 if (g_default_theme)
363 g_free(g_default_theme);
364 if (g_cmd_property)
365 g_free(g_cmd_property);
366
367 gtk_main_quit ();
368 }
369
370
371 static void menuRefresh()
372 {
373 GtkTreeSelection *sel;
374 GtkTreeIter iter;
375 GtkTreeModel *model;
376
377 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view));
378 if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(sel), &model, &iter)) {
379 gtk_list_store_set(g_store, &iter, COL_SNAPSHOT, NULL, -1);
380 }
381
382 g_timeout_add(SNAPSHOT_TICK, (GSourceFunc)update_snapshot, NULL);
383 }
384
385
386 static void menuRefreshAll()
387 {
388 GtkTreeIter iter;
389 GtkTreeModel *model;
390 gboolean have_iter;
391
392 model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_theme_view));
393 have_iter = gtk_tree_model_get_iter_first(model, &iter);
394 while (have_iter) {
395 gtk_list_store_set(g_store, &iter, COL_SNAPSHOT, NULL, -1);
396 have_iter = gtk_tree_model_iter_next(model, &iter);
397 }
398
399 g_timeout_add(SNAPSHOT_TICK, (GSourceFunc)update_snapshot, NULL);
400 }
401
402
403 static void menuApply()
404 {
405 GtkTreeSelection *sel;
406 GtkTreeIter iter;
407 GtkTreeModel *model;
408
409 if (g_default_theme) {
410 g_free(g_default_theme);
411 g_default_theme = NULL;
412 }
413 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view));
414 if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(sel), &model, &iter)) {
415 gtk_tree_model_get(model, &iter, COL_THEME_FILE, &g_default_theme, -1);
416 // overwrite tint2rc
417 copy_file(g_default_theme, g_path_config);
418
419 // restart panel
420 system("killall -SIGUSR1 tint2");
421 }
422 }
423
424
425 static void view_popup_menu(GtkWidget *treeview, GdkEventButton *event, gpointer userdata)
426 {
427 GtkWidget *w = gtk_ui_manager_get_widget(globalUIManager, "/ThemePopup");
428
429 gtk_menu_popup(GTK_MENU(w), NULL, NULL, NULL, NULL, (event != NULL) ? event->button : 0, gdk_event_get_time((GdkEvent*)event));
430 }
431
432
433 static gboolean view_onButtonPressed (GtkWidget *treeview, GdkEventButton *event, gpointer userdata)
434 {
435 // single click with the right mouse button?
436 if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
437 GtkTreeSelection *selection;
438
439 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
440
441 if (gtk_tree_selection_count_selected_rows(selection) <= 1) {
442 GtkTreePath *path;
443
444 // Get tree path for row that was clicked
445 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(treeview), (gint) event->x, (gint) event->y, &path, NULL, NULL, NULL)) {
446 gtk_tree_selection_unselect_all(selection);
447 gtk_tree_selection_select_path(selection, path);
448 gtk_tree_path_free(path);
449 }
450 }
451
452 view_popup_menu(treeview, event, userdata);
453 return TRUE;
454 }
455 return FALSE;
456 }
457
458
459 static gboolean view_onPopupMenu (GtkWidget *treeview, gpointer userdata)
460 {
461 view_popup_menu(treeview, NULL, userdata);
462 return TRUE;
463 }
464
465
466 static void viewRowActivated(GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data)
467 {
468 menuApply();
469 }
470
471
472 static void windowSizeAllocated()
473 {
474 const gboolean isMaximized = g_window->window && (gdk_window_get_state(g_window->window) & GDK_WINDOW_STATE_MAXIMIZED);
475
476 if(!isMaximized)
477 gtk_window_get_size(GTK_WINDOW(g_window), &g_width, &g_height);
478 }
479
480
481 static void load_theme(GtkWidget *list)
482 {
483 GDir *dir;
484 gchar *pt1, *name;
485 const gchar *file;
486 gboolean found_theme = FALSE;
487
488 dir = g_dir_open(g_path_dir, 0, NULL);
489 if (dir == NULL) return;
490 while ((file = g_dir_read_name(dir))) {
491 pt1 = strstr(file, ".tint2rc");
492 if (pt1) {
493 found_theme = TRUE;
494 name = g_build_filename (g_path_dir, file, NULL);
495 custom_list_append(name);
496 g_free(name);
497 }
498 }
499 g_dir_close(dir);
500
501 if (!found_theme) {
502 // create default theme file
503 name = g_build_filename(g_get_user_config_dir(), "tint2", "default.tint2rc", NULL);
504 copy_file(g_path_config, name);
505 custom_list_append(name);
506 if (g_default_theme) g_free(g_default_theme);
507 g_default_theme = strdup(name);
508 g_free(name);
509 }
510
511 selectTheme(g_default_theme);
512
513 g_timeout_add(SNAPSHOT_TICK, (GSourceFunc)update_snapshot, NULL);
514 }
515
516
517 void selectTheme(const gchar *name_theme)
518 {
519 gboolean have_iter, found_theme;
520 GtkTreeIter iter;
521 GtkTreeModel *model;
522
523 if (!name_theme) return;
524
525 model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_theme_view));
526 found_theme = searchTheme(name_theme, model, &iter);
527
528 GtkTreePath *path = NULL;
529 if (found_theme)
530 path = gtk_tree_model_get_path(model, &iter);
531 else {
532 have_iter = gtk_tree_model_get_iter_first(model, &iter);
533 if (have_iter)
534 path = gtk_tree_model_get_path(model, &iter);
535 }
536 if (path) {
537 gtk_tree_selection_select_iter(gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view)), &iter);
538 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(g_theme_view), path, NULL, FALSE, 0, 0);
539 gtk_tree_path_free(path);
540 }
541 }
542
543
544 gboolean searchTheme(const gchar *name_theme, GtkTreeModel *model, GtkTreeIter *iter)
545 {
546 gchar *name;
547 gboolean have_iter, found = FALSE;
548
549 have_iter = gtk_tree_model_get_iter_first(model, iter);
550 while (have_iter) {
551 gtk_tree_model_get(model, iter, COL_THEME_FILE, &name, -1);
552 found = (strcmp(name, name_theme) == 0);
553 g_free(name);
554 if (found)
555 break;
556 have_iter = gtk_tree_model_iter_next(model, iter);
557 }
558 return found;
559 }
560
561
562 void initTheme()
563 {
564 g_path_dir = g_build_filename (g_get_user_config_dir(), "tint2", NULL);
565 if (!g_file_test (g_path_dir, G_FILE_TEST_IS_DIR))
566 g_mkdir(g_path_dir, 0777);
567
568 g_path_config = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
569 }
570
571
572 void read_config()
573 {
574 char *path;
575
576 // default values
577 if (g_default_theme != NULL) {
578 g_free(g_default_theme);
579 g_default_theme = NULL;
580 }
581 g_width = 500;
582 g_height = 350;
583 g_cmd_property = g_strconcat( "python ", INSTALL_PREFIX, "/bin/tintwizard.py", (void*)0 );
584
585 // load config
586 path = g_build_filename (g_get_user_config_dir(), "tint2", "tint2confrc", NULL);
587 if (g_file_test (path, G_FILE_TEST_EXISTS)) {
588 FILE *fp;
589 char line[80];
590 char *key, *value;
591 if ((fp = fopen(path, "r")) != NULL) {
592 while (fgets(line, sizeof(line), fp) != NULL) {
593 if (parse_line(line, &key, &value)) {
594 if (strcmp (key, "default_theme") == 0)
595 g_default_theme = strdup(value);
596 else if (strcmp (key, "cmd_property") == 0) {
597 g_free(g_cmd_property);
598 g_cmd_property = strdup(value);
599 }
600 else if (strcmp (key, "width") == 0)
601 g_width = atoi(value);
602 else if (strcmp (key, "height") == 0)
603 g_height = atoi(value);
604 free (key);
605 free (value);
606 }
607 }
608 fclose (fp);
609 }
610 }
611 g_free(path);
612 }
613
614
615 void write_config()
616 {
617 char *path;
618 FILE *fp;
619
620 path = g_build_filename (g_get_user_config_dir(), "tint2", "tint2confrc", NULL);
621 fp = fopen(path, "w");
622 if (fp != NULL) {
623 fputs("#---------------------------------------------\n", fp);
624 fputs("# TINT2CONF CONFIG FILE\n", fp);
625 if (g_default_theme != NULL) {
626 fprintf(fp, "default_theme = %s\n", g_default_theme);
627 }
628 if (g_cmd_property != NULL) {
629 fprintf(fp, "cmd_property = %s\n", g_cmd_property);
630 }
631 fprintf(fp, "width = %d\n", g_width);
632 fprintf(fp, "height = %d\n", g_height);
633 fputs("\n", fp);
634 fclose (fp);
635 }
636 g_free(path);
637 }
638
639
640
This page took 0.067022 seconds and 5 git commands to generate.