XML serialization for set files, bug fixes and a new full screen mode
[terminatorX.git] / terminatorX / src / tX_loaddlg.cc
1 /*
2     terminatorX - realtime audio scratching software
3     Copyright (C) 1999-2002  Alexander König
4  
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9  
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14  
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., 675 Mass Ave, Cambridge, MA 02139, USA.
18  
19     File: tX_loaddlg.cc
20  
21     Description: Displays the progress indicator dialog for file
22                  loading.
23                  
24 */ 
25 #include <gtk/gtk.h>
26 #include "tX_loaddlg.h"
27 #include <math.h>
28 #include <stdio.h>
29 #include <string.h>
30 #include "tX_mastergui.h"
31
32 GtkWidget *ld_loaddlg=(GtkWidget *) NULL;
33 GtkWidget *ld_single_l=(GtkWidget *)NULL;
34 GtkWidget *ld_single_p=(GtkWidget *)NULL;
35 GtkWidget *ld_multi_l=(GtkWidget *)NULL;
36 GtkWidget *ld_multi_p=(GtkWidget *)NULL;
37 GtkWindow *ld_window=(GtkWindow *)NULL;
38
39 int ld_mode;
40 int ld_count;
41 int ld_current;
42
43 gfloat ld_old_prog;
44
45 #define WID_DYN TRUE, TRUE, 0
46 #define WID_FIX FALSE, FALSE, 0
47 #define add_widget_dyn(wid); gtk_box_pack_start(GTK_BOX(vbox), wid, WID_DYN);\
48         gtk_widget_show(wid);
49         
50 #define add_widget_fix(wid); gtk_box_pack_start(GTK_BOX(vbox), wid, WID_FIX);\
51         gtk_widget_show(wid);
52
53 #define gtk_flush(); while (gtk_events_pending()) gtk_main_iteration(); gdk_flush();
54
55
56 int ld_create_loaddlg(int mode, int count)
57 {
58         GtkWidget *vbox;
59         GtkWidget *actionarea;
60         GtkWidget *dummy;
61         
62         if (ld_loaddlg) return(1);
63         
64         ld_mode=mode;
65         ld_count=count;
66
67         ld_loaddlg=gtk_dialog_new_with_buttons("terminatorX - loading",
68                 GTK_WINDOW(main_window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_NONE, NULL);
69         ld_window=&(GTK_DIALOG(ld_loaddlg)->window);
70         gtk_container_set_border_width(GTK_CONTAINER(ld_window), 5);
71         
72         vbox=GTK_WIDGET(GTK_DIALOG(ld_loaddlg)->vbox);
73         gtk_box_set_spacing(GTK_BOX(vbox), 5);
74
75         actionarea=GTK_WIDGET(GTK_DIALOG(ld_loaddlg)->action_area);
76         gtk_box_set_spacing(GTK_BOX(actionarea), 5);
77         
78         if (mode==TX_LOADDLG_MODE_MULTI)
79         {
80                 ld_multi_l=gtk_label_new("Loading Set");
81                 gtk_misc_set_alignment(GTK_MISC(ld_multi_l), 0.5, 0.5);
82                 add_widget_fix(ld_multi_l);
83                 
84                 ld_multi_p=gtk_progress_bar_new();
85                 add_widget_fix(ld_multi_p);
86                 
87                 dummy=gtk_hseparator_new();
88                 add_widget_fix(dummy);
89                 
90                 ld_current=0;
91         }
92         
93         ld_single_l=gtk_label_new("Loading File");
94         add_widget_fix(ld_single_l);
95                 
96         ld_single_p=gtk_progress_bar_new();
97         add_widget_fix(ld_single_p);
98
99         gtk_window_set_modal(ld_window, TRUE);
100         gtk_window_set_default_size(ld_window, 400, 100);
101         gtk_widget_realize(ld_loaddlg);
102         gdk_window_set_decorations(gtk_widget_get_parent_window(vbox),(GdkWMDecoration) 0);
103         gtk_widget_show(ld_loaddlg);
104
105         gtk_flush();
106                 
107         return 0;
108 }
109
110 char *strip_path(char *name)
111 {
112         char *tmp;
113         
114         tmp=strrchr(name, (int) '/');
115         
116         if (tmp)
117         {
118                 if (strlen(tmp)>1)
119                 {
120                         tmp++;
121                 }
122         }
123         else tmp=name;
124                 
125         return(tmp);
126 }
127
128 void ld_set_setname(char *name)
129 {
130         char *setname;
131         char buffer[1024];
132         
133         setname=strip_path(name);
134         sprintf(buffer, "Loading tX-set [%s]", setname);
135         gtk_label_set_text(GTK_LABEL(ld_multi_l), buffer);
136         gtk_flush();
137 }
138
139 void ld_set_filename(char *name)
140 {
141         char *filename;
142         char buffer[1024];
143         gfloat setprog;
144         
145         ld_current++;
146         ld_old_prog=-1;
147         filename=strip_path(name);
148         if (ld_mode==TX_LOADDLG_MODE_MULTI)
149         {
150                 sprintf(buffer, "Loading file No. %i of %i [%s]", ld_current, ld_count, filename);
151         }
152         else
153         {
154                 sprintf(buffer, "Loading file [%s]", filename); 
155         }
156         gtk_label_set_text(GTK_LABEL(ld_single_l), buffer);
157         
158         if (ld_mode==TX_LOADDLG_MODE_MULTI)
159         {
160                 setprog=(((float) ld_current)/((float) ld_count));
161                 gtk_progress_bar_update(GTK_PROGRESS_BAR(ld_multi_p), setprog);
162                 gtk_flush();            
163         }
164         gtk_flush();
165 }
166
167 void ld_set_progress(gfloat progress)
168 {
169         progress=floor(progress*200.0)/200.0;
170         if (progress>1.0) progress=1.0;
171         //printf("%f\n", progress);
172         
173         if (progress!=ld_old_prog)
174         {
175                 gtk_progress_bar_update(GTK_PROGRESS_BAR(ld_single_p), progress);
176                 gtk_flush();
177         }
178         
179         ld_old_prog=progress;
180 }
181
182 void ld_destroy()
183 {
184         if (ld_loaddlg)
185         {
186                 gtk_widget_hide(ld_loaddlg);
187                 gtk_widget_destroy(ld_loaddlg);
188         }
189         
190         ld_loaddlg=NULL;
191         mg_update_status();
192 }