1 /*
2 * Copyright (c) 2012 Sasha Vasko <sasha at aftercode.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *
18 */
19 #include "../../../configure.h"
20 #include "../../../libAfterStep/asapp.h"
21 #include "../../../libAfterStep/module.h"
22 #include "../../../libAfterStep/session.h"
23 #include "../../../libAfterConf/afterconf.h"
24 #ifdef HAVE_GTK
25 #include "../../../libASGTK/asgtk.h"
26 #else
27 typedef void* GtkWidget;
28 #endif
29 #include <signal.h>
30 #include <unistd.h>
31 #include <fcntl.h>
32
33 #define ENTRY_WIDTH 300
34
35
36 typedef struct ASMountState
37 {
38 ASFlagType flags ;
39
40 GtkWidget *main_window ;
41
42 char *current_dir;
43
44 }ASMountState;
45
46 ASMountState AppState ;
47
48 #ifdef HAVE_GTK
49 void
on_destroy(GtkWidget * widget,gpointer user_data)50 on_destroy(GtkWidget *widget, gpointer user_data)
51 {
52 gtk_main_quit();
53 }
54
55 #if 0
56 void
57 on_exec_clicked(GtkWidget *widget, gpointer user_data)
58 {
59 if( AppState.target_entry )
60 {
61 Bool in_term = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(AppState.run_in_term_check) );
62 char *text = stripcpy(gtk_entry_get_text(GTK_ENTRY(AppState.target_entry)));
63
64 if( exec_command(&text, in_term?ASRTool_Term:ASRTool_Normal) )
65 {
66 if( !get_flags( AppState.flags, ASRUN_Persist ) )
67 gtk_main_quit();
68 else
69 asgtk_combo_box_add_to_history( GTK_COMBO_BOX(AppState.target_combo), text );
70
71 free( text );
72 }
73 }
74 }
75
76 #endif
77
init_ASMount(ASFlagType flags,const char * cmd)78 void init_ASMount(ASFlagType flags, const char *cmd )
79 {
80 GtkWidget *main_vbox ;
81 GtkWidget *hbox ;
82 GtkWidget *frame ;
83 GtkWidget *exec_btn, *cancel_btn ;
84
85 memset( &AppState, 0x00, sizeof(AppState));
86 AppState.flags = flags ;
87 return;
88 AppState.main_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
89
90 gtk_window_set_title (GTK_WINDOW (AppState.main_window), MyName);
91 /*gtk_window_set_resizable( GTK_WINDOW (AppState.main_window), FALSE);*/
92 colorize_gtk_widget( AppState.main_window, get_colorschemed_style_normal() );
93
94 frame = gtk_frame_new( NULL );
95 gtk_container_add (GTK_CONTAINER (AppState.main_window), frame);
96 gtk_container_set_border_width( GTK_CONTAINER (frame), 5 );
97 gtk_widget_show(frame);
98
99 main_vbox = gtk_vbox_new (FALSE, 0);
100 gtk_container_add (GTK_CONTAINER (frame), main_vbox);
101 gtk_container_set_border_width( GTK_CONTAINER (main_vbox), 5 );
102
103 #if 0
104 /******** Line 1 *******/
105 AppState.run_in_term_check = gtk_check_button_new_with_label("Exec in terminal");
106 if( AppState.tool == ASRTool_Term )
107 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(AppState.run_in_term_check), TRUE );
108
109 hbox = gtk_hbox_new( FALSE, 5 );
110 gtk_box_pack_start (GTK_BOX (main_vbox), hbox, TRUE, TRUE, 2);
111 gtk_box_pack_start (GTK_BOX (hbox), gtk_label_new("Command to execute:"), FALSE, FALSE, 0);
112 gtk_box_pack_end (GTK_BOX (hbox), AppState.run_in_term_check, FALSE, FALSE, 0);
113 gtk_widget_show_all (hbox);
114
115 /******** Line 2 *******/
116 AppState.target_combo = gtk_combo_box_entry_new_text();
117 gtk_container_set_border_width( GTK_CONTAINER (AppState.target_combo), 1 );
118 gtk_widget_set_size_request (AppState.target_combo, ENTRY_WIDTH, -1);
119
120 frame = gtk_frame_new( NULL );
121 gtk_container_add (GTK_CONTAINER (frame), AppState.target_combo);
122 gtk_container_set_border_width( GTK_CONTAINER (frame), 1 );
123 gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 5);
124 gtk_widget_show_all(frame);
125 gtk_widget_show(frame);
126 colorize_gtk_edit( AppState.target_combo );
127
128 if( GTK_IS_CONTAINER(AppState.target_combo) )
129 gtk_container_forall( GTK_CONTAINER(AppState.target_combo), find_combobox_entry, &AppState.target_entry );
130
131 /******** Line 3 *******/
132 hbox = gtk_hbutton_box_new();
133 gtk_box_pack_end (GTK_BOX (main_vbox), hbox, TRUE, TRUE, 5);
134 exec_btn = gtk_button_new_from_stock( GTK_STOCK_EXECUTE );
135 gtk_box_pack_start (GTK_BOX (hbox), exec_btn, FALSE, FALSE, 0);
136 cancel_btn = gtk_button_new_from_stock( GTK_STOCK_CANCEL );
137 gtk_box_pack_end (GTK_BOX (hbox), cancel_btn, FALSE, FALSE, 0);
138 gtk_widget_show_all (hbox);
139
140 /******** Callbacks *******/
141 /* if above succeeded then path_entry should be not NULL here : */
142 /* TODO : insert proper change handlers and data pointers here : */
143 if( AppState.target_entry )
144 {
145 gtk_entry_set_has_frame( GTK_ENTRY(AppState.target_entry), FALSE );
146 g_signal_connect ( G_OBJECT (AppState.target_entry), "activate",
147 G_CALLBACK (on_exec_clicked), (gpointer) NULL);
148 if( cmd )
149 gtk_entry_set_text( GTK_ENTRY(AppState.target_entry), cmd );
150 }
151
152 /* g_signal_connect (G_OBJECT(AppState.target_combo), "changed",
153 G_CALLBACK (NULL), (gpointer) NULL); */
154
155 g_signal_connect (G_OBJECT (cancel_btn), "clicked", G_CALLBACK (on_destroy), NULL);
156 g_signal_connect (G_OBJECT (exec_btn), "clicked", G_CALLBACK (on_exec_clicked), NULL);
157
158 g_signal_connect (G_OBJECT (AppState.main_window), "destroy", G_CALLBACK (on_destroy), NULL);
159 /******** Show them all *******/
160 #endif
161 gtk_widget_show_all (main_vbox);
162 gtk_widget_show(AppState.main_window);
163
164 // gtk_window_set_focus( GTK_WINDOW(AppState.main_window), AppState.target_entry );
165 // GTK_WIDGET_SET_FLAGS(exec_btn, GTK_CAN_DEFAULT );
166 // gtk_window_set_default( GTK_WINDOW(AppState.main_window), exec_btn );
167 }
168 #endif /* HAVE_GTK */
169
170 typedef struct ASVolume {
171 GVolume *g_volume;
172
173
174 }ASVolume;
175
176 ASBiDirList *Volumes;
177
ASVolume_create(GVolume * g_v)178 ASVolume *ASVolume_create (GVolume *g_v)
179 {
180 ASVolume *v;
181
182 if (g_v == NULL)
183 return NULL;
184
185 v = safecalloc (1, sizeof(ASVolume));
186 v->g_volume = g_object_ref (g_v);
187 return v;
188 }
189
ASVolume_destroy(void * data)190 void ASVolume_destroy( void *data )
191 {
192 if (data) {
193 ASVolume *v = (ASVolume *) data;
194 g_object_unref (v->g_volume);
195 v->g_volume = NULL;
196 free (v);
197 }
198 }
199
ASVolume_toString(ASVolume * v)200 char* ASVolume_toString (ASVolume *v)
201 {
202 if (v && v->g_volume)
203 return g_volume_get_name(v->g_volume);
204 return mystrdup("");
205 }
206
207
check_drives()208 void check_drives()
209 {
210 Volumes = create_asbidirlist (ASVolume_destroy);
211
212 GVolumeMonitor * monitor;
213 GList * mounts;
214 GList * volumes;
215 GList *tmp;
216
217 monitor = g_volume_monitor_get();
218 mounts = g_volume_monitor_get_mounts(G_VOLUME_MONITOR(monitor));
219
220 volumes = g_volume_monitor_get_volumes(G_VOLUME_MONITOR(monitor));
221 for (tmp = volumes; tmp != NULL; tmp = tmp->next) {
222 ASVolume *v = ASVolume_create (tmp->data);
223 append_bidirelem (Volumes, v);
224 char *volume_name = ASVolume_toString(v);
225 g_print("volume: %s\n", volume_name);
226 safefree(volume_name);
227 }
228 g_list_free (volumes);
229
230 for (tmp = mounts; tmp != NULL; tmp = tmp->next) {
231 GMount *mount = tmp->data;
232 char *mount_name = g_mount_get_name(mount);
233 g_print("mount: %s\n", mount_name);
234 g_free(mount_name);
235 g_object_unref (mount);
236 }
237 g_list_free (mounts);
238
239 destroy_asbidirlist (&Volumes);
240 }
241
242 int
main(int argc,char * argv[])243 main (int argc, char *argv[])
244 {
245 ASFlagType flags = 0 ;
246 int i;
247 char * initial_command = NULL ;
248
249 #ifdef HAVE_GTK
250 init_asgtkapp( argc, argv, CLASS_ASRUN, NULL, 0);
251 #else
252 InitMyApp (CLASS_ASMOUNT, argc, argv, NULL, NULL, 0 );
253 LinkAfterStepConfig();
254 InitSession();
255 ConnectX( ASDefaultScr, 0 );
256 LoadColorScheme();
257 ReloadASEnvironment( NULL, NULL, NULL, False, True );
258 #endif
259
260 for( i = 1 ; i < argc ; ++i )
261 {
262 if( argv[i] == NULL )
263 continue;
264
265 }
266
267 ConnectAfterStep(0,0);
268
269 #ifdef HAVE_GTK
270 init_ASMount( flags, initial_command );
271
272 check_drives();
273
274 gtk_main ();
275 #endif
276 return 0;
277 }
278
279