#include <stdlib.h>
#include <stdio.h>
#include <locale.h>
+#include <X11/Xlib.h>
+#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <glib/gstdio.h>
enum { LIST_ITEM = 0, N_COLUMNS };
// default config file and directory
-char *pathConfig = 0;
-char *pathDir = 0;
+char *g_path_config = 0;
+char *g_path_dir = 0;
+char *g_default_theme = 0;
+int g_width;
+int g_height;
+GtkWidget *g_window;
GtkWidget *g_theme_view;
GtkListStore *g_store;
static void add_to_list(GtkWidget *list, const gchar *str);
void on_changed(GtkWidget *widget, gpointer label);
-void read_config(char **defaultTheme);
-void write_config(char *defaultTheme);
+void read_config();
+void write_config();
void check_theme();
int main (int argc, char ** argv)
{
- GtkWidget *window;
GtkWidget *vBox = NULL;
GtkActionGroup *actionGroup;
GtkTreeSelection *sel;
gtk_init (&argc, &argv);
g_thread_init( NULL );
+ read_config();
check_theme();
// define main layout : container, menubar, toolbar
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- gtk_window_set_title(GTK_WINDOW(window), _("Panel theming"));
- gtk_window_set_default_size(GTK_WINDOW(window), 600, 350);
- g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (menuQuit), NULL);
+ g_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title(GTK_WINDOW(g_window), _("Panel theming"));
+ gtk_window_resize(GTK_WINDOW(g_window), g_width, g_height);
+ g_signal_connect (G_OBJECT (g_window), "destroy", G_CALLBACK (menuQuit), NULL);
vBox = gtk_vbox_new (FALSE, 0);
- gtk_container_add (GTK_CONTAINER(window), vBox);
+ gtk_container_add (GTK_CONTAINER(g_window), vBox);
actionGroup = gtk_action_group_new ("menuActionGroup");
gtk_action_group_add_actions (actionGroup, entries, G_N_ELEMENTS (entries), NULL);
// define tree view
g_theme_view = gtk_tree_view_new();
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(g_theme_view), FALSE);
+ //gtk_widget_set_size_request(g_theme_view, g_width, g_height);
//gtk_tree_view_set_fixed_height_mode(GTK_TREE_VIEW(g_theme_view), TRUE);
//col = GTK_TREE_VIEW_COLUMN (g_object_new (GTK_TYPE_TREE_VIEW_COLUMN, "title", _("Theme"), "resizable", TRUE, "sizing", GTK_TREE_VIEW_COLUMN_FIXED, NULL));
sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view));
//Glib::Thread::create(sigc::mem_fun(window.view, &Thumbview::load_cache_images), true);
//Glib::Thread::create(sigc::mem_fun(window.view, &Thumbview::create_cache_images), true);
- gtk_widget_show_all(window);
+ gtk_widget_show_all(g_window);
gtk_main ();
return 0;
}
static void menuAbout(GtkWindow * parent)
{
- const char *authors[] = { "Thierry Lorthiois", "Christian Ruppert (Build system)", NULL };
+ const char *authors[] = { "Thierry Lorthiois", "Christian Ruppert (Build system)", "Euan Freeman <euan04@gmail.com> (tintwizard)\nSee http://code.google.com/p/tintwizard/", NULL };
gtk_show_about_dialog( parent, "name", g_get_application_name( ),
"comments", _("Theming tool for tint2 panel"),
"version", LONG_VERSION_STRING,
- "copyright", _("Copyright 2009 tint2 team\nLicense GNU GPL version 2"),
+ "copyright", _("Copyright 2009 tint2 team\nTint2 License GNU GPL version 2\nTintwizard License GNU GPL version 3"),
"logo-icon-name", NULL, "authors", authors,
/* Translators: translate "translator-credits" as
your name to have it appear in the credits in the "About"
static void menuProperties (void)
{
- system("python /home/thil/Desktop/tintwizard/tintwizard.py");
+ GtkTreeSelection *sel;
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ char *value, *name1, *name2, *cmd;
+
+ 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, LIST_ITEM, &value, -1);
+
+ name1 = g_build_filename (g_get_user_config_dir(), "tint2", value, NULL);
+ name2 = g_strdup_printf("%s.tint2rc", name1);
+
+ cmd = g_strdup_printf("tintwizard.py %s", name2);
+ system(cmd);
+ g_free(cmd);
+
+ g_free(name1);
+ g_free(name2);
+ g_free(value);
+ }
}
static void menuQuit (void)
{
+ write_config();
+
g_object_unref(g_store);
gtk_main_quit ();
}
name2 = g_strdup_printf("%s.tint2rc", name1);
g_free(name1);
- copy_file(name2, pathConfig);
- write_config(value);
+ copy_file(name2, g_path_config);
+ write_config();
g_free(value);
g_free(name2);
GDir *dir;
gchar *file, *pt1, *name;
- dir = g_dir_open(pathDir, 0, NULL);
+ dir = g_dir_open(g_path_dir, 0, NULL);
while ((file = g_dir_read_name(dir))) {
pt1 = strstr(file, ".tint2rc");
if (pt1) {
// search default theme
GtkTreeIter iter;
GtkTreeModel *model;
- name = NULL;
- read_config(&name);
- if (name) {
- printf("defaultTheme %s\n", name);
+ if (g_default_theme) {
+ printf("defaultTheme %s\n", g_default_theme);
//gtk_tree_selection_select_iter(GtkTreeSelection *selection, GtkTreeIter *iter);
}
}
// theme file management
-void read_config(char **defaultTheme)
+void read_config()
{
char *path;
+ if (g_default_theme)
+ g_free(g_default_theme);
+
+ g_width = 600;
+ g_height = 350;
path = g_build_filename (g_get_user_config_dir(), "tint2", "tint2confrc", NULL);
if (g_file_test (path, G_FILE_TEST_EXISTS)) {
FILE *fp;
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) {
- *defaultTheme = strdup (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);
}
}
-void write_config(char *defaultTheme)
+void write_config()
{
char *path;
FILE *fp;
+ GtkRequisition req;
+ int x, y, width, height, depth;
+ int top, bottom, left, right;
+ GdkRectangle rect;
+
+ gtk_window_get_size(GTK_WINDOW(g_window), &width, &height);
+ printf("write_config %d, %d\n", width, height);
+
+ // GTK incapacity to return (width, height) of the window is really annoying
+ gdk_window_get_geometry(GTK_WIDGET(g_window)->window, &x, &y, &width, &height, &depth);
+ printf(" write_config %d, %d, %d, %d\n", x, y, width, height);
+ //Window xid = GDK_WINDOW_XWINDOW(GTK_WIDGET(g_window)->window);
+ //gdk_window_get_frame_extentsGTK_WINDOW(g_window), &rect);
+ //printf(" write_config %d, %d\n", rec.width, rec.height);
+
+/*
+ path = gtk_tree_path_new_from_indices( playlist_pos, -1 );
+ sel = gtk_tree_view_get_selection( (GtkTreeView*)list_view );
+ gtk_tree_selection_select_path( sel, path );
+ gtk_tree_path_free( path );
+ */
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);
- fprintf(fp, "default_theme = %s\n\n", defaultTheme);
+ 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);
void check_theme()
{
- pathDir = g_build_filename (g_get_user_config_dir(), "tint2", NULL);
- if (!g_file_test (pathDir, G_FILE_TEST_IS_DIR))
- g_mkdir(pathDir, 0777);
+ 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);
- pathConfig = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
+ g_path_config = g_build_filename (g_get_user_config_dir(), "tint2", "tint2rc", NULL);
}