tint2conf: GUI changes
git-svn-id: http://tint2.googlecode.com/svn/trunk@764 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
This commit is contained in:
parent
167bb31084
commit
aa9e1afdf2
2 changed files with 113 additions and 179 deletions
|
@ -49,7 +49,6 @@ static void menuProperties();
|
|||
static void menuQuit();
|
||||
static void menuRefresh();
|
||||
static void menuRefreshAll();
|
||||
void menuApply();
|
||||
static void menuAbout();
|
||||
|
||||
static gboolean view_onPopupMenu(GtkWidget *treeview, gpointer userdata);
|
||||
|
@ -62,9 +61,6 @@ static void viewRowActivated(GtkTreeView *tree_view, GtkTreePath *path, GtkTreeV
|
|||
static void selectTheme(const gchar *name);
|
||||
static gboolean searchTheme(const gchar *name_theme, GtkTreeModel *model, GtkTreeIter *iter);
|
||||
static void load_theme();
|
||||
static void initTheme();
|
||||
static void read_config();
|
||||
static void write_config();
|
||||
|
||||
|
||||
// define menubar, toolbar and popup
|
||||
|
@ -116,7 +112,6 @@ static GtkActionEntry entries[] = {
|
|||
{"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)},
|
||||
{"ViewApply", GTK_STOCK_APPLY, _("Apply"), NULL, _("Apply theme"), G_CALLBACK (menuApply)},
|
||||
{"HelpMenu", NULL, _("Help"), NULL, NULL, NULL},
|
||||
{"HelpAbout", GTK_STOCK_ABOUT, _("_About"), "<Control>A", _("About"), G_CALLBACK(menuAbout)}
|
||||
};
|
||||
|
@ -128,9 +123,14 @@ int main (int argc, char ** argv)
|
|||
GtkActionGroup *actionGroup;
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
g_thread_init( NULL );
|
||||
read_config();
|
||||
initTheme();
|
||||
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);
|
||||
|
||||
g_set_application_name(_("tint2conf"));
|
||||
gtk_window_set_default_icon_name("taskbar");
|
||||
|
||||
|
@ -140,6 +140,7 @@ int main (int argc, char ** argv)
|
|||
// 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);
|
||||
|
@ -150,7 +151,7 @@ int main (int argc, char ** argv)
|
|||
gtk_action_group_add_actions(actionGroup, entries, G_N_ELEMENTS(entries), NULL);
|
||||
globalUIManager = gtk_ui_manager_new();
|
||||
gtk_ui_manager_insert_action_group(globalUIManager, actionGroup, 0);
|
||||
gtk_ui_manager_add_ui_from_string (globalUIManager, global_ui, -1, NULL );
|
||||
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);
|
||||
scrollbar = gtk_scrolled_window_new(NULL, NULL);
|
||||
|
@ -183,7 +184,7 @@ static void menuAddWidget (GtkUIManager * p_uiManager, GtkWidget * p_widget, Gtk
|
|||
|
||||
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)\n See 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"),
|
||||
|
@ -204,19 +205,19 @@ static void menuAdd()
|
|||
GtkFileChooser *chooser;
|
||||
GtkFileFilter *filter;
|
||||
|
||||
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);
|
||||
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);
|
||||
gtk_file_chooser_set_select_multiple(chooser, TRUE);
|
||||
|
||||
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);
|
||||
|
||||
if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) {
|
||||
gtk_widget_destroy(dialog);
|
||||
|
@ -239,13 +240,6 @@ static void menuAdd()
|
|||
|
||||
// check existing
|
||||
if (searchTheme(path, model, &iter)) {
|
||||
gchar *message;
|
||||
message = g_strdup_printf(_("Couldn't add duplicate theme\n\'%s\'."), pt1);
|
||||
|
||||
GtkWidget *w = gtk_message_dialog_new(GTK_WINDOW(g_window), 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, message, NULL);
|
||||
g_signal_connect_swapped(w, "response", G_CALLBACK(gtk_widget_destroy), w);
|
||||
gtk_widget_show(w);
|
||||
g_free(message);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -365,8 +359,6 @@ static void menuProperties()
|
|||
|
||||
static void menuQuit()
|
||||
{
|
||||
write_config();
|
||||
|
||||
if (g_path_config)
|
||||
g_free(g_path_config);
|
||||
if (g_path_dir)
|
||||
|
@ -409,37 +401,6 @@ static void menuRefreshAll()
|
|||
g_timeout_add(SNAPSHOT_TICK, (GSourceFunc)update_snapshot, NULL);
|
||||
}
|
||||
|
||||
|
||||
void menuApply()
|
||||
{
|
||||
GtkTreeSelection *sel;
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel *model;
|
||||
|
||||
if (g_default_theme) {
|
||||
g_free(g_default_theme);
|
||||
g_default_theme = 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, &g_default_theme, -1);
|
||||
// Create backup if the config file has been edited manually
|
||||
if (config_is_manual(g_path_config)) {
|
||||
char timestamp[64];
|
||||
sprintf(timestamp, "%ld", time(NULL));
|
||||
gchar *backup_path = g_build_filename(g_get_user_config_dir(), "tint2", "tint2rc.backup.", timestamp, NULL);
|
||||
copy_file(g_path_config, backup_path);
|
||||
g_free(backup_path);
|
||||
}
|
||||
// Write config file
|
||||
printf("Writing %s to %s\n", g_default_theme, g_path_config);
|
||||
copy_file(g_default_theme, g_path_config);
|
||||
// Restart panel
|
||||
int unused = system("killall -SIGUSR1 tint2");
|
||||
(void)unused;
|
||||
}
|
||||
}
|
||||
|
||||
static void view_popup_menu(GtkWidget *treeview, GdkEventButton *event, gpointer userdata)
|
||||
{
|
||||
GtkWidget *w = gtk_ui_manager_get_widget(globalUIManager, "/ThemePopup");
|
||||
|
@ -479,9 +440,7 @@ static gboolean view_onPopupMenu (GtkWidget *treeview, gpointer userdata)
|
|||
}
|
||||
|
||||
static void viewRowActivated(GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data)
|
||||
{
|
||||
menuApply();
|
||||
}
|
||||
{}
|
||||
|
||||
static void windowSizeAllocated()
|
||||
{
|
||||
|
@ -492,37 +451,74 @@ static void windowSizeAllocated()
|
|||
gtk_window_get_size(GTK_WINDOW(g_window), &g_width, &g_height);
|
||||
}
|
||||
|
||||
int endswith(const char *str, const char *suffix)
|
||||
{
|
||||
return strlen(str) >= strlen(suffix) &&
|
||||
strcmp(str + strlen(str) - strlen(suffix), suffix) == 0;
|
||||
}
|
||||
|
||||
static void load_theme(GtkWidget *list)
|
||||
{
|
||||
GDir *dir;
|
||||
gchar *name;
|
||||
const gchar *file;
|
||||
gboolean found_theme = FALSE;
|
||||
const gchar *file_name;
|
||||
int found_theme;
|
||||
|
||||
dir = g_dir_open(g_path_dir, 0, NULL);
|
||||
if (dir == NULL)
|
||||
return;
|
||||
while ((file = g_dir_read_name(dir))) {
|
||||
if (g_str_has_suffix(file, ".tint2rc")) {
|
||||
while ((file_name = g_dir_read_name(dir))) {
|
||||
if (!g_file_test(file_name, G_FILE_TEST_IS_DIR) &&
|
||||
!strstr(file_name, "backup") &&
|
||||
!strstr(file_name, "copy") &&
|
||||
!strstr(file_name, "~") &&
|
||||
(endswith(file_name, "tint2rc") ||
|
||||
endswith(file_name, ".conf"))) {
|
||||
found_theme = TRUE;
|
||||
name = g_build_filename (g_path_dir, file, NULL);
|
||||
name = g_build_filename(g_path_dir, file_name, NULL);
|
||||
custom_list_append(name);
|
||||
g_free(name);
|
||||
}
|
||||
}
|
||||
g_dir_close(dir);
|
||||
|
||||
if (!found_theme) {
|
||||
// create default theme file
|
||||
name = g_build_filename(g_get_user_config_dir(), "tint2", "default.tint2rc", NULL);
|
||||
copy_file(g_path_config, name);
|
||||
custom_list_append(name);
|
||||
if (g_default_theme)
|
||||
g_free(g_default_theme);
|
||||
g_default_theme = strdup(name);
|
||||
g_free(name);
|
||||
// create default config // TODO
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
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_dir_close(dir);
|
||||
|
||||
selectTheme(g_default_theme);
|
||||
|
||||
g_timeout_add(SNAPSHOT_TICK, (GSourceFunc)update_snapshot, NULL);
|
||||
|
@ -534,10 +530,18 @@ void selectTheme(const gchar *name_theme)
|
|||
GtkTreeIter iter;
|
||||
GtkTreeModel *model;
|
||||
|
||||
if (!name_theme)
|
||||
return;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
found_theme = searchTheme(name_theme, model, &iter);
|
||||
|
||||
GtkTreePath *path = NULL;
|
||||
|
@ -571,73 +575,3 @@ gboolean searchTheme(const gchar *name_theme, GtkTreeModel *model, GtkTreeIter *
|
|||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
// Initializes the paths to the tint2 config locations.
|
||||
void initTheme()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
// Reads the tint2conf config file.
|
||||
void read_config()
|
||||
{
|
||||
char *path;
|
||||
|
||||
// default values
|
||||
if (g_default_theme != NULL) {
|
||||
g_free(g_default_theme);
|
||||
g_default_theme = NULL;
|
||||
}
|
||||
g_width = 500;
|
||||
g_height = 350;
|
||||
|
||||
// load config
|
||||
path = g_build_filename (g_get_user_config_dir(), "tint2", "tint2confrc", NULL);
|
||||
if (g_file_test (path, G_FILE_TEST_EXISTS)) {
|
||||
FILE *fp;
|
||||
char line[80];
|
||||
char *key, *value;
|
||||
if ((fp = fopen(path, "r")) != NULL) {
|
||||
while (fgets(line, sizeof(line), fp) != NULL) {
|
||||
if (parse_line(line, &key, &value)) {
|
||||
if (strcmp (key, "default_theme") == 0)
|
||||
g_default_theme = strdup(value);
|
||||
else if (strcmp (key, "width") == 0)
|
||||
g_width = atoi(value);
|
||||
else if (strcmp (key, "height") == 0)
|
||||
g_height = atoi(value);
|
||||
free (key);
|
||||
free (value);
|
||||
}
|
||||
}
|
||||
fclose (fp);
|
||||
}
|
||||
}
|
||||
g_free(path);
|
||||
}
|
||||
|
||||
// Writes the tint2conf config file.
|
||||
void write_config()
|
||||
{
|
||||
char *path;
|
||||
FILE *fp;
|
||||
|
||||
path = g_build_filename (g_get_user_config_dir(), "tint2", "tint2confrc", NULL);
|
||||
fp = fopen(path, "w");
|
||||
if (fp != NULL) {
|
||||
fputs("#---------------------------------------------\n", fp);
|
||||
fputs("# TINT2CONF CONFIG FILE\n", fp);
|
||||
if (g_default_theme != NULL) {
|
||||
fprintf(fp, "default_theme = %s\n", g_default_theme);
|
||||
}
|
||||
fprintf(fp, "width = %d\n", g_width);
|
||||
fprintf(fp, "height = %d\n", g_height);
|
||||
fputs("\n", fp);
|
||||
fclose (fp);
|
||||
}
|
||||
g_free(path);
|
||||
}
|
||||
|
|
|
@ -165,10 +165,10 @@ void applyClicked(GtkWidget *widget, gpointer data)
|
|||
char *file = get_current_theme_file_name();
|
||||
if (file)
|
||||
config_save_file(file);
|
||||
int unused = system("killall -SIGUSR1 tint2");
|
||||
(void)unused;
|
||||
g_free(file);
|
||||
g_timeout_add(SNAPSHOT_TICK, (GSourceFunc)update_snapshot, NULL);
|
||||
// TODO if this is not the current theme, don't do anything
|
||||
menuApply();
|
||||
}
|
||||
|
||||
void cancelClicked(GtkWidget *widget, gpointer data)
|
||||
|
|
Loading…
Reference in a new issue