]> Dogcows Code - chaz/tint2/blob - src/tint2conf/main.c
fixed switch between config with killall -SIGUSR1 tint2
[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 #include <stdio.h>
21 #include <locale.h>
22 #include <gtk/gtk.h>
23 #include <glib.h>
24 #include <glib/gstdio.h>
25 #include <glib/gi18n.h>
26
27
28 // gcc -Wall -g main1.c -o tint2conf `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0 --libs gthread-2.0`
29 // TODO
30 // ** add, saveas
31 // - liste de fichiers tint2rc*
32 // - menu contextuel dans liste
33 // - double clic dans liste
34 // - données globales
35 // - delete
36 // - rename
37 // - apply
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...
43
44
45 #define LONG_VERSION_STRING "0.7"
46
47 static GtkUIManager *myUIManager = NULL;
48
49 static void menuAddWidget (GtkUIManager *, GtkWidget *, GtkContainer *);
50 static void viewPopup(GtkWidget *wid,GdkEventButton *event,GtkWidget *menu);
51
52 // action on menus
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);
63
64 static void onPopupMenu(GtkWidget *self, GdkEventButton *event);
65 static void viewRowActivated( GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data);
66
67 static void loadDir();
68
69
70 // define menubar and toolbar
71 static const char *fallback_ui_file =
72 "<ui>"
73 " <menubar name='MenuBar'>"
74 " <menu action='ThemeMenu'>"
75 " <menuitem action='ThemeAdd'/>"
76 " <menuitem action='ThemeSaveAs'/>"
77 " <separator/>"
78 " <menuitem action='ThemeProperties'/>"
79 " <menuitem action='ThemeRename'/>"
80 " <separator/>"
81 " <menuitem action='ThemeDelete'/>"
82 " <separator/>"
83 " <menuitem action='ThemeQuit'/>"
84 " </menu>"
85 " <menu action='ViewMenu'>"
86 " <menuitem action='ViewRefresh'/>"
87 " <menuitem action='ViewRefreshAll'/>"
88 " </menu>"
89 " <menu action='HelpMenu'>"
90 " <menuitem action='HelpAbout'/>"
91 " </menu>"
92 " </menubar>"
93 " <toolbar name='ToolBar'>"
94 " <toolitem action='ViewRefreshAll'/>"
95 " <separator/>"
96 " <toolitem action='ThemeProperties'/>"
97 " <toolitem action='ViewApply'/>"
98 " </toolbar>"
99 "</ui>";
100
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)}
116 };
117
118
119 int main (int argc, char ** argv)
120 {
121 GtkWidget *window, *themeView, *popup, *item;
122 GtkWidget *vBox = NULL;
123 GtkActionGroup *actionGroup;
124 GtkTreeViewColumn *col;
125 GtkTreeSelection *sel;
126
127 gtk_init (&argc, &argv);
128 g_thread_init( NULL );
129
130 // define main layout : container, menubar, toolbar, themeView
131 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
132 gtk_window_set_title(GTK_WINDOW(window), _("Panel theming"));
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);
137
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);
145
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);
158
159 // popup menu
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);
168
169 // load themes
170 loadDir();
171
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);
175
176 gtk_widget_show_all(window);
177 gtk_main ();
178 return 0;
179 }
180
181
182 static void menuAddWidget (GtkUIManager * p_uiManager, GtkWidget * p_widget, GtkContainer * p_box)
183 {
184 gtk_box_pack_start(GTK_BOX(p_box), p_widget, FALSE, FALSE, 0);
185 gtk_widget_show(p_widget);
186 }
187
188
189 static void viewPopup(GtkWidget *wid, GdkEventButton *event, GtkWidget *menu)
190 {
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);
193 }
194 }
195
196
197 static void menuAbout(GtkWindow * parent)
198 {
199 const char *authors[] = { "Thierry Lorthiois", "Christian Ruppert (Build system)", NULL };
200
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,
206 "authors", authors,
207 /* Translators: translate "translator-credits" as
208 your name to have it appear in the credits in the "About"
209 dialog */
210 "translator-credits", _("translator-credits"),
211 NULL );
212 }
213
214
215 static void menuAdd (GtkWindow *parent)
216 {
217 GtkWidget *dialog;
218 GtkFileChooser *chooser;
219 GtkFileFilter *filter;
220
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);
223
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);
227
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);
232
233 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
234 GSList *l, *list = gtk_file_chooser_get_filenames(chooser);
235
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 );
239 //g_free( folder );
240
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 );
245 }
246
247 g_slist_foreach(list, (GFunc)g_free, NULL);
248 g_slist_free(list);
249 }
250 gtk_widget_destroy (dialog);
251 }
252
253
254 static void menuSaveAs (GtkWindow *parent)
255 {
256 GtkWidget *dialog;
257 GtkFileChooser *chooser;
258
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);
261
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"));
265
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);
270 g_free (filename);
271 }
272 gtk_widget_destroy (dialog);
273 }
274
275
276 static void menuProperties (void)
277 {
278 printf("menuProperties\n");
279 }
280
281
282 static void menuRename (void)
283 {
284 printf("menuRename\n");
285 }
286
287
288 static void menuDelete (void)
289 {
290 printf("menuDelete\n");
291 }
292
293
294 static void menuQuit (void)
295 {
296 gtk_main_quit ();
297 }
298
299
300 static void menuRefresh (void)
301 {
302 printf("menuRefresh\n");
303 }
304
305
306 static void menuRefreshAll (void)
307 {
308 printf("menuRefreshAll\n");
309 }
310
311
312 static void menuApply (void)
313 {
314 printf("menuApply\n");
315 }
316
317
318 static void onPopupMenu(GtkWidget *self, GdkEventButton *event)
319 {
320 //GtkWidget *menu = action_get_widget("/main-window-popup");
321
322 //gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, (event ? event->button : 0), (event ? event->time : 0));
323 }
324
325
326 static void viewRowActivated(GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data)
327 {
328 //action_activate("show-torrent-properties");
329 }
330
331
332 static void loadDir()
333 {
334 char *path = g_build_filename (g_get_user_config_dir(), "tint2", NULL);
335 if (!g_file_test (path, G_FILE_TEST_IS_DIR)) {
336 g_mkdir(path, 0777);
337 }
338 g_free(path);
339
340 GDir *dir;
341 dir = g_dir_open(path, 0, NULL);
342
343 g_dir_close(dir);
344 }
345
This page took 0.062704 seconds and 5 git commands to generate.