1 /**************************************************************************
5 * Copyright (C) 2009 Thierry lorthiois (lorthiois@bbsoft.fr)
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.
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 **************************************************************************/
24 #include <glib/gstdio.h>
25 #include <glib/gi18n.h>
28 // gcc -Wall -g main1.c -o tint2conf `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0 --libs gthread-2.0`
31 // - liste de fichiers tint2rc*
32 // - menu contextuel dans liste
33 // - double clic dans liste
38 // - sauvegarde et lecture taille de fenetre
39 // - activation des menus sur sélection dans la liste
40 // - dialogue propriétés ...
41 // tint2 -d directory, plutot que -c config ??
42 // tint2 preview, comment gérer les barres verticales...
45 #define LONG_VERSION_STRING "0.7"
47 static GtkUIManager
*myUIManager
= NULL
;
49 static void menuAddWidget (GtkUIManager
*, GtkWidget
*, GtkContainer
*);
50 static void viewPopup(GtkWidget
*wid
,GdkEventButton
*event
,GtkWidget
*menu
);
53 static void menuAdd (GtkWindow
* parent
);
54 static void menuSaveAs (GtkWindow
*parent
);
55 static void menuProperties (void);
56 static void menuRename (void);
57 static void menuDelete (void);
58 static void menuQuit (void);
59 static void menuRefresh (void);
60 static void menuRefreshAll (void);
61 static void menuApply (void);
62 static void menuAbout(GtkWindow
* parent
);
64 static void onPopupMenu(GtkWidget
*self
, GdkEventButton
*event
);
65 static void viewRowActivated( GtkTreeView
*tree_view
, GtkTreePath
*path
, GtkTreeViewColumn
*column
, gpointer user_data
);
67 static void loadDir();
70 // define menubar and toolbar
71 static const char *fallback_ui_file
=
73 " <menubar name='MenuBar'>"
74 " <menu action='ThemeMenu'>"
75 " <menuitem action='ThemeAdd'/>"
76 " <menuitem action='ThemeSaveAs'/>"
78 " <menuitem action='ThemeProperties'/>"
79 " <menuitem action='ThemeRename'/>"
81 " <menuitem action='ThemeDelete'/>"
83 " <menuitem action='ThemeQuit'/>"
85 " <menu action='ViewMenu'>"
86 " <menuitem action='ViewRefresh'/>"
87 " <menuitem action='ViewRefreshAll'/>"
89 " <menu action='HelpMenu'>"
90 " <menuitem action='HelpAbout'/>"
93 " <toolbar name='ToolBar'>"
94 " <toolitem action='ViewRefreshAll'/>"
96 " <toolitem action='ThemeProperties'/>"
97 " <toolitem action='ViewApply'/>"
101 // define menubar and toolbar action
102 static GtkActionEntry entries
[] = {
103 {"ThemeMenu", NULL
, "Theme", NULL
, NULL
, NULL
},
104 {"ThemeAdd", GTK_STOCK_ADD
, "_Add...", "<Control>N", "Add theme", G_CALLBACK (menuAdd
)},
105 {"ThemeSaveAs", GTK_STOCK_SAVE_AS
, "_Save as...", NULL
, "Save theme as", G_CALLBACK (menuSaveAs
)},
106 {"ThemeProperties", GTK_STOCK_PROPERTIES
, "_Properties...", NULL
, "Show properties", G_CALLBACK (menuProperties
)},
107 {"ThemeRename", NULL
, "_Rename...", NULL
, "Rename theme", G_CALLBACK (menuRename
)},
108 {"ThemeDelete", GTK_STOCK_DELETE
, "_Delete", NULL
, "Delete theme", G_CALLBACK (menuDelete
)},
109 {"ThemeQuit", GTK_STOCK_QUIT
, "_Quit", "<control>Q", "Quit", G_CALLBACK (menuQuit
)},
110 {"ViewMenu", NULL
, "View", NULL
, NULL
, NULL
},
111 {"ViewRefresh", GTK_STOCK_REFRESH
, "Refresh", NULL
, "Refresh", G_CALLBACK (menuRefresh
)},
112 {"ViewRefreshAll", GTK_STOCK_REFRESH
, "Refresh all", NULL
, "Refresh all", G_CALLBACK (menuRefreshAll
)},
113 {"ViewApply", GTK_STOCK_APPLY
, "Apply", NULL
, "Apply theme", G_CALLBACK (menuApply
)},
114 {"HelpMenu", NULL
, "Help", NULL
, NULL
, NULL
},
115 {"HelpAbout", GTK_STOCK_ABOUT
, "_About", "<Control>A", "About", G_CALLBACK (menuAbout
)}
119 int main (int argc
, char ** argv
)
121 GtkWidget
*window
, *themeView
, *popup
, *item
;
122 GtkWidget
*vBox
= NULL
;
123 GtkActionGroup
*actionGroup
;
124 GtkTreeViewColumn
*col
;
125 GtkTreeSelection
*sel
;
127 gtk_init (&argc
, &argv
);
128 g_thread_init( NULL
);
130 // define main layout : container, menubar, toolbar, themeView
131 window
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
132 gtk_window_set_title(GTK_WINDOW(window
), _("Tint2 theme"));
133 gtk_window_set_default_size(GTK_WINDOW(window
), 600, 350);
134 g_signal_connect (G_OBJECT (window
), "destroy", G_CALLBACK (menuQuit
), NULL
);
135 vBox
= gtk_vbox_new (FALSE
, 0);
136 gtk_container_add (GTK_CONTAINER(window
), vBox
);
138 actionGroup
= gtk_action_group_new ("menuActionGroup");
139 gtk_action_group_add_actions (actionGroup
, entries
, G_N_ELEMENTS (entries
), NULL
);
140 myUIManager
= gtk_ui_manager_new();
141 gtk_ui_manager_insert_action_group (myUIManager
, actionGroup
, 0);
142 gtk_ui_manager_add_ui_from_string ( myUIManager
, fallback_ui_file
, -1, NULL
);
143 g_signal_connect(myUIManager
, "add_widget", G_CALLBACK (menuAddWidget
), vBox
);
144 gtk_ui_manager_ensure_update(myUIManager
);
146 themeView
= gtk_tree_view_new();
147 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(themeView
), FALSE
);
148 gtk_tree_view_set_fixed_height_mode(GTK_TREE_VIEW(themeView
), TRUE
);
149 col
= GTK_TREE_VIEW_COLUMN (g_object_new (GTK_TYPE_TREE_VIEW_COLUMN
, "title", _("Theme"), "resizable", TRUE
, "sizing", GTK_TREE_VIEW_COLUMN_FIXED
, NULL
));
150 sel
= gtk_tree_view_get_selection(GTK_TREE_VIEW(themeView
));
151 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(sel
), GTK_SELECTION_SINGLE
);
152 gtk_box_pack_start(GTK_BOX(vBox
), themeView
, TRUE
, TRUE
, 0);
153 gtk_widget_show(themeView
);
154 g_signal_connect(themeView
, "popup-menu", G_CALLBACK(onPopupMenu
), NULL
);
155 g_signal_connect(themeView
, "row-activated", G_CALLBACK(viewRowActivated
), NULL
);
156 //g_signal_connect(themeView, "button-press-event", G_CALLBACK(onViewButtonPressed), (void *)onViewButtonPressed);
157 //g_signal_connect(themeView, "button-release-event", G_CALLBACK(onViewButtonReleased), NULL);
160 // all you need to do is add the GDK_BUTTON_PRESS_MASK to the window's events
161 gtk_widget_add_events(window
, GDK_BUTTON_PRESS_MASK
);
162 popup
= gtk_menu_new();
163 item
= gtk_menu_item_new_with_label("victory");
164 gtk_menu_shell_append(GTK_MENU_SHELL(popup
), item
);
165 gtk_menu_attach_to_widget(GTK_MENU(popup
), window
, NULL
);
166 gtk_widget_show_all(popup
);
167 g_signal_connect(G_OBJECT(window
),"button-press-event", G_CALLBACK(viewPopup
), (gpointer
)popup
);
172 // rig up idle/thread routines
173 //Glib::Thread::create(sigc::mem_fun(window.view, &Thumbview::load_cache_images), true);
174 //Glib::Thread::create(sigc::mem_fun(window.view, &Thumbview::create_cache_images), true);
176 gtk_widget_show_all(window
);
182 static void menuAddWidget (GtkUIManager
* p_uiManager
, GtkWidget
* p_widget
, GtkContainer
* p_box
)
184 gtk_box_pack_start(GTK_BOX(p_box
), p_widget
, FALSE
, FALSE
, 0);
185 gtk_widget_show(p_widget
);
189 static void viewPopup(GtkWidget
*wid
, GdkEventButton
*event
, GtkWidget
*menu
)
191 if((event
->button
== 3) && (event
->type
== GDK_BUTTON_PRESS
)) {
192 gtk_menu_popup(GTK_MENU(menu
),NULL
,NULL
,NULL
,NULL
,event
->button
,event
->time
);
197 static void menuAbout(GtkWindow
* parent
)
199 const char *authors
[] = { "Thierry Lorthiois", "Christian Ruppert (Build system)", NULL
};
201 gtk_show_about_dialog( parent
, "name", g_get_application_name( ),
202 "comments", _("Theming tool for tint2 panel"),
203 "version", LONG_VERSION_STRING
,
204 "copyright", _("Copyright 2009 tint2 team\nLicense GNU GPL version 2"),
205 "logo-icon-name", NULL
,
207 /* Translators: translate "translator-credits" as
208 your name to have it appear in the credits in the "About"
210 "translator-credits", _("translator-credits"),
215 static void menuAdd (GtkWindow
*parent
)
218 GtkFileChooser
*chooser
;
219 GtkFileFilter
*filter
;
221 dialog
= gtk_file_chooser_dialog_new(_("Add a theme"), parent
, GTK_FILE_CHOOSER_ACTION_OPEN
, GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
, GTK_STOCK_ADD
, GTK_RESPONSE_ACCEPT
, NULL
);
222 chooser
= GTK_FILE_CHOOSER(dialog
);
224 //gtk_dialog_set_alternative_button_order(GTK_DIALOG(w), GTK_RESPONSE_ACCEPT, GTK_RESPONSE_CANCEL, -1);
225 gtk_file_chooser_set_current_folder(chooser
, g_get_home_dir());
226 gtk_file_chooser_set_select_multiple(chooser
, TRUE
);
228 filter
= gtk_file_filter_new();
229 gtk_file_filter_set_name(filter
, _("Tint2 theme files"));
230 gtk_file_filter_add_pattern(filter
, "*.tint2rc");
231 gtk_file_chooser_add_filter(chooser
, filter
);
233 if (gtk_dialog_run (GTK_DIALOG(dialog
)) == GTK_RESPONSE_ACCEPT
) {
234 GSList
*l
, *list
= gtk_file_chooser_get_filenames(chooser
);
236 // TODO: remember this folder the next time we use this dialog
237 //char *folder = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(dialog));
238 //pref_string_set( PREF_KEY_OPEN_DIALOG_FOLDER, folder );
241 for (l
= list
; l
; l
= l
->next
) {
242 printf("fichier %s\n", (char *)l
->data
);
243 //add_filename(core, l->data, FALSE);
244 //tr_core_torrents_added( core );
247 g_slist_foreach(list
, (GFunc
)g_free
, NULL
);
250 gtk_widget_destroy (dialog
);
254 static void menuSaveAs (GtkWindow
*parent
)
257 GtkFileChooser
*chooser
;
259 dialog
= gtk_file_chooser_dialog_new (_("Save theme as"), parent
, GTK_FILE_CHOOSER_ACTION_SAVE
, GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
, GTK_STOCK_SAVE
, GTK_RESPONSE_ACCEPT
, NULL
);
260 chooser
= GTK_FILE_CHOOSER(dialog
);
262 gtk_file_chooser_set_do_overwrite_confirmation (chooser
, TRUE
);
263 gtk_file_chooser_set_current_folder (chooser
, g_get_home_dir());
264 gtk_file_chooser_set_current_name (chooser
, _("Untitled document"));
266 if (gtk_dialog_run (GTK_DIALOG(dialog
)) == GTK_RESPONSE_ACCEPT
) {
267 char *filename
= gtk_file_chooser_get_filename(chooser
);
268 printf("fichier %s\n", filename
);
269 //save_to_file (filename);
272 gtk_widget_destroy (dialog
);
276 static void menuProperties (void)
278 printf("menuProperties\n");
282 static void menuRename (void)
284 printf("menuRename\n");
288 static void menuDelete (void)
290 printf("menuDelete\n");
294 static void menuQuit (void)
300 static void menuRefresh (void)
302 printf("menuRefresh\n");
306 static void menuRefreshAll (void)
308 printf("menuRefreshAll\n");
312 static void menuApply (void)
314 printf("menuApply\n");
318 static void onPopupMenu(GtkWidget
*self
, GdkEventButton
*event
)
320 //GtkWidget *menu = action_get_widget("/main-window-popup");
322 //gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, (event ? event->button : 0), (event ? event->time : 0));
326 static void viewRowActivated(GtkTreeView
*tree_view
, GtkTreePath
*path
, GtkTreeViewColumn
*column
, gpointer user_data
)
328 //action_activate("show-torrent-properties");
332 static void loadDir()
334 char *path
= g_build_filename (g_get_user_config_dir(), "tint2", NULL
);
335 if (!g_file_test (path
, G_FILE_TEST_IS_DIR
)) {
341 dir
= g_dir_open(path
, 0, NULL
);