tint2conf: cleanup GUI

This commit is contained in:
o9000 2015-04-25 15:45:15 +02:00
parent ae76f82ee0
commit 233157930b
2 changed files with 251 additions and 283 deletions

View file

@ -18,6 +18,7 @@
**************************************************************************/
#include <time.h>
#ifdef HAVE_VERSION_H
#include "version.h"
#endif
@ -28,52 +29,72 @@
#include "properties.h"
#include "properties_rw.h"
// Default path to the tint2 config file
char *g_path_config = NULL;
// Default path to the tint2 config directory
char *g_path_dir = NULL;
char *g_default_theme = NULL;
int g_width, g_height;
GtkWidget *g_window;
// ====== Utilities ======
static GtkUIManager *globalUIManager = NULL;
gchar *get_default_config_path()
{
gchar *path = NULL;
const gchar * const * system_dirs = g_get_system_config_dirs();
int i;
for (i = 0; system_dirs[i]; i++) {
path = g_build_filename(system_dirs[i], "tint2", "tint2rc", NULL);
if (g_file_test(path, G_FILE_TEST_EXISTS))
return path;
g_free(path);
path = NULL;
}
return g_strdup("/dev/null");
}
int endswith(const char *str, const char *suffix)
{
return strlen(str) >= strlen(suffix) &&
strcmp(str + strlen(str) - strlen(suffix), suffix) == 0;
}
static void menuAddWidget(GtkUIManager *ui_manager, GtkWidget *p_widget, GtkContainer *p_box)
{
gtk_box_pack_start(GTK_BOX(p_box), p_widget, FALSE, FALSE, 0);
gtk_widget_show(p_widget);
}
static void menuAddWidget(GtkUIManager *, GtkWidget *, GtkContainer *);
// action on menus
static void menuAdd();
static void menuImport();
static void menuImportDefault();
static void menuSaveAs();
static void menuDelete();
static void menuProperties();
static void menuQuit();
static void menuRefresh();
static void menuRefreshAll();
static void edit_current_theme();
static void refresh_current_theme();
static void menuAbout();
static gboolean view_onPopupMenu(GtkWidget *treeview, gpointer userdata);
static gboolean view_onButtonPressed(GtkWidget *treeview, GdkEventButton *event, gpointer userdata);
static void windowSizeAllocated();
static void viewRowActivated(GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data);
static gboolean theme_selected(GtkTreeSelection *selection,
GtkTreeModel *model,
GtkTreePath *path,
gboolean path_currently_selected,
gpointer userdata);
static void select_first_theme();
static void load_all_themes();
// theme files
static void selectTheme(const gchar *name);
static gboolean searchTheme(const gchar *name_theme, GtkTreeModel *model, GtkTreeIter *iter);
static void load_theme();
// ====== Globals ======
GtkWidget *g_window;
static GtkUIManager *globalUIManager = NULL;
GtkWidget *tint_cmd;
// define menubar, toolbar and popup
static const char *global_ui =
"<ui>"
" <menubar name='MenuBar'>"
" <menu action='ThemeMenu'>"
" <menuitem action='ThemeAdd'/>"
" <menuitem action='ThemeSaveAs'/>"
" <separator/>"
" <menuitem action='ThemeDelete'/>"
" <menuitem action='ThemeDefault'/>"
" <separator/>"
" <menuitem action='ThemeProperties'/>"
" <menuitem action='ThemeSaveAs'/>"
" <menuitem action='ThemeDelete'/>"
" <separator/>"
" <menuitem action='ThemeQuit'/>"
" </menu>"
@ -88,12 +109,10 @@ static const char *global_ui =
" </menubar>"
" <toolbar name='ToolBar'>"
" <toolitem action='ThemeProperties'/>"
" <toolitem action='ViewApply'/>"
" </toolbar>"
" <popup name='ThemePopup'>"
" <menuitem action='ThemeProperties'/>"
" <menuitem action='EditRefresh'/>"
" <menuitem action='ViewApply'/>"
" <separator/>"
" <menuitem action='ThemeDelete'/>"
" </popup>"
@ -103,15 +122,15 @@ static const char *global_ui =
// define menubar and toolbar action
static GtkActionEntry entries[] = {
{"ThemeMenu", NULL, _("Theme"), NULL, NULL, NULL},
{"ThemeAdd", GTK_STOCK_ADD, _("_Add..."), "<Control>N", _("Add theme"), G_CALLBACK(menuAdd)},
{"ThemeAdd", GTK_STOCK_ADD, _("_Import theme..."), "<Control>N", _("Import theme"), G_CALLBACK(menuImport)},
{"ThemeDefault", GTK_STOCK_NEW, _("_Import default theme..."), NULL, _("Import default theme"), G_CALLBACK(menuImportDefault)},
{"ThemeSaveAs", GTK_STOCK_SAVE_AS, _("_Save as..."), NULL, _("Save theme as"), G_CALLBACK(menuSaveAs)},
{"ThemeDelete", GTK_STOCK_DELETE, _("_Delete"), NULL, _("Delete theme"), G_CALLBACK(menuDelete)},
{"ThemeProperties", GTK_STOCK_PROPERTIES, _("_Properties..."), NULL, _("Show properties"), G_CALLBACK(menuProperties)},
{"ThemeQuit", GTK_STOCK_QUIT, _("_Quit"), "<control>Q", _("Quit"), G_CALLBACK(menuQuit)},
{"ThemeProperties", GTK_STOCK_PROPERTIES, _("_Edit theme..."), NULL, _("Edit selected theme"), G_CALLBACK(edit_current_theme)},
{"ThemeQuit", GTK_STOCK_QUIT, _("_Quit"), "<control>Q", _("Quit"), G_CALLBACK(gtk_main_quit)},
{"EditMenu", NULL, "Edit", NULL, NULL, NULL},
{"EditRefresh", GTK_STOCK_REFRESH, _("Refresh"), NULL, _("Refresh"), G_CALLBACK(menuRefresh)},
{"EditRefreshAll", GTK_STOCK_REFRESH, _("Refresh all"), NULL, _("Refresh all"), G_CALLBACK(menuRefreshAll)},
// {"EditPreferences", GTK_STOCK_PREFERENCES, "Preferences", NULL, "Preferences", G_CALLBACK(menuPreferences)},
{"EditRefresh", GTK_STOCK_REFRESH, _("Refresh"), NULL, _("Refresh"), G_CALLBACK(refresh_current_theme)},
{"EditRefreshAll", GTK_STOCK_REFRESH, _("Refresh all"), NULL, _("Refresh all"), G_CALLBACK(load_all_themes)},
{"HelpMenu", NULL, _("Help"), NULL, NULL, NULL},
{"HelpAbout", GTK_STOCK_ABOUT, _("_About"), "<Control>A", _("About"), G_CALLBACK(menuAbout)}
};
@ -125,25 +144,24 @@ int main(int argc, char **argv)
gtk_init(&argc, &argv);
g_thread_init((NULL));
g_path_dir = g_build_filename(g_get_user_config_dir(), "tint2", NULL);
if (!g_file_test(g_path_dir, G_FILE_TEST_IS_DIR))
g_mkdir(g_path_dir, 0777);
g_path_config = g_build_filename(g_get_user_config_dir(), "tint2", "tint2rc", NULL);
{
gchar *tint2_config_dir = g_build_filename(g_get_user_config_dir(), "tint2", NULL);
if (!g_file_test(tint2_config_dir, G_FILE_TEST_IS_DIR))
g_mkdir(tint2_config_dir, 0777);
g_free(tint2_config_dir);
}
g_set_application_name(_("tint2conf"));
gtk_window_set_default_icon_name("taskbar");
// config file use '.' as decimal separator
// config file uses '.' as decimal separator
setlocale(LC_NUMERIC, "POSIX");
// define main layout : container, menubar, toolbar
g_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(g_window), _("Panel theming"));
g_width = 800, g_height = 600;
gtk_window_resize(GTK_WINDOW(g_window), g_width, g_height);
g_signal_connect(G_OBJECT(g_window), "destroy", G_CALLBACK(menuQuit), NULL);
g_signal_connect(g_window, "size-allocate", G_CALLBACK(windowSizeAllocated), NULL);
gtk_window_resize(GTK_WINDOW(g_window), 800, 600);
g_signal_connect(G_OBJECT(g_window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
vBox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(g_window), vBox);
@ -154,6 +172,28 @@ int main(int argc, char **argv)
gtk_ui_manager_add_ui_from_string(globalUIManager, global_ui, -1, (NULL));
g_signal_connect(globalUIManager, "add_widget", G_CALLBACK(menuAddWidget), vBox);
gtk_ui_manager_ensure_update(globalUIManager);
GtkWidget *table, *label;
int row, col;
row = col = 0;
table = gtk_table_new(1, 2, FALSE);
gtk_widget_show(table);
gtk_box_pack_start(GTK_BOX(vBox), table, FALSE, TRUE, 0);
gtk_table_set_row_spacings(GTK_TABLE(table), 8);
gtk_table_set_col_spacings(GTK_TABLE(table), 8);
label = gtk_label_new(_("Command to run tint2: "));
gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
gtk_widget_show(label);
gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
col++;
tint_cmd = gtk_entry_new();
gtk_widget_show(tint_cmd);
gtk_entry_set_text(GTK_ENTRY(tint_cmd), "");
gtk_table_attach(GTK_TABLE(table), tint_cmd, col, col+1, row, row+1, GTK_FILL | GTK_EXPAND, 0, 0, 0);
scrollbar = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollbar), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_box_pack_start(GTK_BOX(vBox), scrollbar, TRUE, TRUE, 0);
@ -164,102 +204,98 @@ int main(int argc, char **argv)
gtk_widget_show(g_theme_view);
g_signal_connect(g_theme_view, "button-press-event", (GCallback)view_onButtonPressed, NULL);
g_signal_connect(g_theme_view, "popup-menu", (GCallback)view_onPopupMenu, NULL);
g_signal_connect(g_theme_view, "row-activated", G_CALLBACK(viewRowActivated), NULL);
gtk_tree_selection_set_select_function(gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view)), theme_selected, NULL, NULL);
// load themes
load_theme(g_theme_view);
load_all_themes();
gtk_widget_show_all(g_window);
gtk_main();
return 0;
}
static void menuAddWidget(GtkUIManager * p_uiManager, GtkWidget * p_widget, GtkContainer * p_box)
{
gtk_box_pack_start(GTK_BOX(p_box), p_widget, FALSE, FALSE, 0);
gtk_widget_show(p_widget);
}
static void menuAbout()
{
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)};
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 http://code.google.com/p/tintwizard)",
(NULL)
};
gtk_show_about_dialog(GTK_WINDOW(g_window), "name", g_get_application_name( ),
"comments", _("Theming tool for tint2 panel"),
"version", VERSION_STRING,
"copyright", _("Copyright 2009 tint2 team\nTint2 License GNU GPL version 2\nTintwizard License GNU GPL version 3"),
"logo-icon-name", "taskbar", "authors", authors,
/* Translators: translate "translator-credits" as
your name to have it appear in the credits in the "About"
dialog */
"translator-credits", _("translator-credits"),
NULL);
gtk_show_about_dialog(GTK_WINDOW(g_window),
"name", g_get_application_name( ),
"comments", _("Theming tool for tint2 panel"),
"version", VERSION_STRING,
"copyright", _("Copyright 2009-2015 tint2 team\nTint2 License GNU GPL version 2\nTintwizard License GNU GPL version 3"),
"logo-icon-name", "taskbar", "authors", authors,
/* Translators: translate "translator-credits" as
your name to have it appear in the credits in the "About"
dialog */
"translator-credits", _("translator-credits"),
NULL);
}
static void menuAdd()
// ====== Theme import/copy/delete ======
static void menuImport()
{
GtkWidget *dialog;
GtkFileChooser *chooser;
GtkFileFilter *filter;
dialog = gtk_file_chooser_dialog_new(_("Add a theme"), GTK_WINDOW(g_window), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_ADD, GTK_RESPONSE_ACCEPT, NULL);
chooser = GTK_FILE_CHOOSER(dialog);
gchar *config_dir;
config_dir = g_build_filename(g_get_home_dir(), ".config", "tint2", NULL);
gtk_file_chooser_set_current_folder(chooser, config_dir);
g_free(config_dir);
filter = gtk_file_filter_new();
gtk_file_filter_set_name(filter, _("Tint2 theme files"));
gtk_file_filter_add_pattern(filter, "*tint2rc");
gtk_file_chooser_add_filter(chooser, filter);
gtk_file_chooser_set_do_overwrite_confirmation(chooser, TRUE);
GtkWidget *dialog = gtk_file_chooser_dialog_new(_("Import theme(s)"), GTK_WINDOW(g_window), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_ADD, GTK_RESPONSE_ACCEPT, NULL);
GtkFileChooser *chooser = GTK_FILE_CHOOSER(dialog);
if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) {
gtk_widget_destroy(dialog);
return;
}
GtkTreeIter iter;
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_theme_view));
GSList *l, *list = gtk_file_chooser_get_filenames(chooser);
gchar *file, *pt1, *name, *path, *name_first=NULL;
GSList *list = gtk_file_chooser_get_filenames(chooser);
GSList *l;
for (l = list; l ; l = l->next) {
file = (char *)l->data;
pt1 = strrchr(file, '/');
if (pt1 == NULL) continue;
pt1++;
if (*pt1 == 0) continue;
name = g_strdup(pt1);
path = g_build_filename(g_get_user_config_dir(), "tint2", name, NULL);
// check existing
if (searchTheme(path, model, &iter)) {
gchar *file = (char *)l->data;
gchar *pt1 = strrchr(file, '/');
if (!pt1)
continue;
pt1++;
if (!*pt1)
continue;
}
// append theme
gchar *name = pt1;
gchar *path = g_build_filename(g_get_user_config_dir(), "tint2", name, NULL);
if (g_file_test(path, G_FILE_TEST_EXISTS))
continue;
copy_file(file, path);
custom_list_append(path);
if (name_first == NULL)
name_first = g_strdup(path);
g_free(path);
g_free(name);
}
g_slist_foreach(list, (GFunc)g_free, NULL);
g_slist_free(list);
gtk_widget_destroy(dialog);
selectTheme(name_first);
g_free(name_first);
g_timeout_add(SNAPSHOT_TICK, (GSourceFunc)update_snapshot, NULL);
load_all_themes();
}
static void menuImportDefault()
{
GtkWidget *dialog = gtk_file_chooser_dialog_new(_("Save default theme as"), GTK_WINDOW(g_window), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);
GtkFileChooser *chooser = GTK_FILE_CHOOSER(dialog);
gtk_file_chooser_set_do_overwrite_confirmation(chooser, TRUE);
gchar *config_dir;
config_dir = g_build_filename(g_get_home_dir(), ".config", "tint2", NULL);
gtk_file_chooser_set_current_folder(chooser, config_dir);
g_free(config_dir);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
gchar *save_name = gtk_file_chooser_get_filename(chooser);
gchar *path_default = get_default_config_path();
copy_file(path_default, save_name);
g_free(path_default);
g_free(save_name);
}
gtk_widget_destroy(dialog);
load_all_themes();
}
static void menuSaveAs()
{
@ -299,8 +335,9 @@ static void menuSaveAs()
}
g_free(file);
gtk_widget_destroy(dialog);
}
load_all_themes();
}
static void menuDelete()
{
@ -323,83 +360,8 @@ static void menuDelete()
}
}
char *get_current_theme_file_name()
{
GtkTreeSelection *sel;
GtkTreeIter iter;
GtkTreeModel *model;
char *file;
sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view));
if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(sel), &model, &iter)) {
gtk_tree_model_get(model, &iter, COL_THEME_FILE, &file, -1);
return file;
}
return NULL;
}
static void menuProperties()
{
GtkTreeSelection *sel;
GtkTreeIter iter;
GtkTreeModel *model;
char *file;
sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view));
if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(sel), &model, &iter)) {
gtk_tree_model_get(model, &iter, COL_THEME_FILE, &file, -1);
GtkWidget *prop;
prop = create_properties();
config_read_file(file);
gtk_window_present(GTK_WINDOW(prop));
g_free(file);
}
}
static void menuQuit()
{
if (g_path_config)
g_free(g_path_config);
if (g_path_dir)
g_free(g_path_dir);
if (g_default_theme)
g_free(g_default_theme);
gtk_main_quit();
}
static void menuRefresh()
{
GtkTreeSelection *sel;
GtkTreeIter iter;
GtkTreeModel *model;
sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view));
if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(sel), &model, &iter)) {
gtk_list_store_set(g_store, &iter, COL_SNAPSHOT, NULL, -1);
}
g_timeout_add(SNAPSHOT_TICK, (GSourceFunc)update_snapshot, NULL);
}
static void menuRefreshAll()
{
GtkTreeIter iter;
GtkTreeModel *model;
gboolean have_iter;
model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_theme_view));
have_iter = gtk_tree_model_get_iter_first(model, &iter);
while (have_iter) {
gtk_list_store_set(g_store, &iter, COL_SNAPSHOT, NULL, -1);
have_iter = gtk_tree_model_iter_next(model, &iter);
}
g_timeout_add(SNAPSHOT_TICK, (GSourceFunc)update_snapshot, NULL);
}
// ====== Theme popup menu ======
static void view_popup_menu(GtkWidget *treeview, GdkEventButton *event, gpointer userdata)
{
@ -439,34 +401,95 @@ static gboolean view_onPopupMenu(GtkWidget *treeview, gpointer userdata)
return TRUE;
}
static void viewRowActivated(GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data)
{}
static void windowSizeAllocated()
// ====== Theme selection ======
gboolean theme_selected(GtkTreeSelection *selection,
GtkTreeModel *model,
GtkTreePath *path,
gboolean path_currently_selected,
gpointer userdata)
{
const gboolean isMaximized = g_window->window &&
(gdk_window_get_state(g_window->window) & GDK_WINDOW_STATE_MAXIMIZED);
if (!isMaximized)
gtk_window_get_size(GTK_WINDOW(g_window), &g_width, &g_height);
GtkTreeIter iter;
if (gtk_tree_model_get_iter(model, &iter, path)) {
gchar *current_theme = NULL;
gtk_tree_model_get(model, &iter, COL_THEME_FILE, &current_theme, -1);
if (!path_currently_selected) {
gchar *text = g_strdup_printf("tint2 -c %s", current_theme);
gtk_entry_set_text(GTK_ENTRY(tint_cmd), text);
g_free(text);
} else {
gtk_entry_set_text(GTK_ENTRY(tint_cmd), "");
}
g_free(current_theme);
}
return TRUE;
}
int endswith(const char *str, const char *suffix)
void select_first_theme()
{
return strlen(str) >= strlen(suffix) &&
strcmp(str + strlen(str) - strlen(suffix), suffix) == 0;
gboolean have_iter;
GtkTreeIter iter;
GtkTreeModel *model;
model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_theme_view));
have_iter = gtk_tree_model_get_iter_first(model, &iter);
if (have_iter) {
GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
gtk_tree_selection_select_iter(gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view)), &iter);
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(g_theme_view), path, NULL, FALSE, 0, 0);
gtk_tree_path_free(path);
}
return;
}
static void load_theme(GtkWidget *list)
char *get_current_theme_file_name()
{
GDir *dir;
gchar *name;
const gchar *file_name;
int found_theme;
GtkTreeSelection *sel;
GtkTreeIter iter;
GtkTreeModel *model;
char *file;
dir = g_dir_open(g_path_dir, 0, NULL);
if (dir == NULL)
sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view));
if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(sel), &model, &iter)) {
gtk_tree_model_get(model, &iter, COL_THEME_FILE, &file, -1);
return file;
}
return NULL;
}
static void edit_current_theme()
{
GtkTreeSelection *sel;
GtkTreeIter iter;
GtkTreeModel *model;
char *file;
sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view));
if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(sel), &model, &iter)) {
gtk_tree_model_get(model, &iter, COL_THEME_FILE, &file, -1);
GtkWidget *prop;
prop = create_properties();
config_read_file(file);
gtk_window_present(GTK_WINDOW(prop));
g_free(file);
}
}
// ====== Theme load/reload ======
static void load_all_themes()
{
gtk_list_store_clear(GTK_LIST_STORE(g_store));
gchar *tint2_config_dir = g_build_filename(g_get_user_config_dir(), "tint2", NULL);
GDir *dir = g_dir_open(tint2_config_dir, 0, NULL);
if (dir == NULL) {
g_free(tint2_config_dir);
return;
}
gboolean found_theme = FALSE;
const gchar *file_name;
while ((file_name = g_dir_read_name(dir))) {
if (!g_file_test(file_name, G_FILE_TEST_IS_DIR) &&
!strstr(file_name, "backup") &&
@ -475,103 +498,48 @@ static void load_theme(GtkWidget *list)
(endswith(file_name, "tint2rc") ||
endswith(file_name, ".conf"))) {
found_theme = TRUE;
name = g_build_filename(g_path_dir, file_name, NULL);
gchar *name = g_build_filename(tint2_config_dir, file_name, NULL);
custom_list_append(name);
g_free(name);
}
}
if (!found_theme) {
// create default config // TODO
gchar *path_tint2rc = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
copy_file(get_default_config_path(), path_tint2rc);
g_free(path_tint2rc);
load_all_themes();
} else {
select_first_theme();
// copy tint2rc from system directory to user directory
gchar *path2 = 0;
const gchar * const * system_dirs = g_get_system_config_dirs();
int i;
for (i = 0; system_dirs[i]; i++) {
path2 = g_build_filename(system_dirs[i], "tint2", "tint2rc", NULL);
if (g_file_test(path2, G_FILE_TEST_EXISTS))
break;
g_free(path2);
path2 = 0;
GtkTreeIter iter;
GtkTreeModel *model;
gboolean have_iter;
model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_theme_view));
have_iter = gtk_tree_model_get_iter_first(model, &iter);
while (have_iter) {
gtk_list_store_set(g_store, &iter, COL_SNAPSHOT, NULL, -1);
have_iter = gtk_tree_model_iter_next(model, &iter);
}
if (path2) {
// copy file in user directory (path1)
gchar *dir = g_build_filename(g_get_user_config_dir(), "tint2", NULL);
if (!g_file_test(dir, G_FILE_TEST_IS_DIR))
g_mkdir(dir, 0777);
g_free(dir);
gchar *path1 = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
copy_file(path2, path1);
g_free(path2);
g_free(path1);
} else {
// create empty file
gchar *path1 = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
copy_file("/dev/null", path1);
g_free(path1);
}
load_theme(list);
return;
g_timeout_add(SNAPSHOT_TICK, (GSourceFunc)update_snapshot, NULL);
}
g_dir_close(dir);
selectTheme(g_default_theme);
g_timeout_add(SNAPSHOT_TICK, (GSourceFunc)update_snapshot, NULL);
g_free(tint2_config_dir);
}
void selectTheme(const gchar *name_theme)
static void refresh_current_theme()
{
gboolean have_iter, found_theme;
GtkTreeSelection *sel;
GtkTreeIter iter;
GtkTreeModel *model;
model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_theme_view));
if (!name_theme) {
have_iter = gtk_tree_model_get_iter_first(model, &iter);
if (have_iter) {
GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
gtk_tree_selection_select_iter(gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view)), &iter);
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(g_theme_view), path, NULL, FALSE, 0, 0);
gtk_tree_path_free(path);
}
return;
sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view));
if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(sel), &model, &iter)) {
gtk_list_store_set(g_store, &iter, COL_SNAPSHOT, NULL, -1);
}
found_theme = searchTheme(name_theme, model, &iter);
GtkTreePath *path = NULL;
if (found_theme) {
path = gtk_tree_model_get_path(model, &iter);
} else {
have_iter = gtk_tree_model_get_iter_first(model, &iter);
if (have_iter)
path = gtk_tree_model_get_path(model, &iter);
}
if (path) {
gtk_tree_selection_select_iter(gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view)), &iter);
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(g_theme_view), path, NULL, FALSE, 0, 0);
gtk_tree_path_free(path);
}
}
gboolean searchTheme(const gchar *name_theme, GtkTreeModel *model, GtkTreeIter *iter)
{
gchar *name;
gboolean have_iter, found = FALSE;
have_iter = gtk_tree_model_get_iter_first(model, iter);
while (have_iter) {
gtk_tree_model_get(model, iter, COL_THEME_FILE, &name, -1);
found = (strcmp(name, name_theme) == 0);
g_free(name);
if (found)
break;
have_iter = gtk_tree_model_iter_next(model, iter);
}
return found;
g_timeout_add(SNAPSHOT_TICK, (GSourceFunc)update_snapshot, NULL);
}

View file

@ -163,7 +163,7 @@ void panel_move_item_up(GtkWidget *widget, gpointer data);
void applyClicked(GtkWidget *widget, gpointer data)
{
char *file = get_current_theme_file_name();
gchar *file = get_current_theme_file_name();
if (file) {
if (config_is_manual(file)) {
gchar *backup_path = g_strdup_printf("%s.backup.%ld", file, time(NULL));