]> git.saurik.com Git - wxWidgets.git/blob - user/wxFile/FMJobs.cpp
documented wxHF_BOOKMARKS flag for wxHtmlHelpController
[wxWidgets.git] / user / wxFile / FMJobs.cpp
1 /*
2 * Program: FMJobs.cpp
3 *
4 * Author: Robert Roebling
5 *
6 * Copyright: (C) 1997, GNU (Robert Roebling)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #ifdef __GNUG__
24 #pragma implementation "FMJobs.h"
25 #endif
26
27 #include "FMJobs.h"
28 #include "wx/utils.h"
29 #include "wx/filefn.h"
30 #include "wx/msgdlg.h"
31
32 //-----------------------------------------------------------------------------
33 // wxCopyStatusDia
34 //-----------------------------------------------------------------------------
35
36 IMPLEMENT_DYNAMIC_CLASS(wxCopyStatusDia,wxDialog);
37
38 const ID_CANCEL_COPY = 1000;
39
40 BEGIN_EVENT_TABLE(wxCopyStatusDia,wxDialog)
41 EVT_BUTTON (ID_CANCEL_COPY, wxCopyStatusDia::OnCommand)
42 END_EVENT_TABLE()
43
44 wxCopyStatusDia::wxCopyStatusDia( wxFrame *parent, const wxString &dest, wxArrayString *files ) :
45 wxDialog( parent, -1, "FileMaker copy job control", wxPoint(180,180), wxSize(500,200) )
46 {
47 int w = 0;
48 int h = 0;
49 GetSize( &w, &h );
50
51 m_dest = dest;
52 m_files = files;
53 m_stop = FALSE;
54
55 (void)new wxStaticText( this, -1, "Copying files", wxPoint(10,10) );
56 (void)new wxStaticText( this, -1, "from:", wxPoint(30,40) );
57 m_sourceMsg = new wxStaticText( this, -1, "", wxPoint(80,40), wxSize(200,-1) );
58 (void)new wxStaticText( this, -1, " to:", wxPoint(30,70) );
59 m_destMsg = new wxStaticText( this, -1, "", wxPoint(80,70), wxSize(200,-1) );
60 (void)new wxStaticText( this, -1, " Kb copied:", wxPoint(30,100) );
61 m_statusMsg = new wxStaticText( this, -1, "0", wxPoint(120,100), wxSize(100,-1) );
62
63 m_cancelButton = new wxButton( this, ID_CANCEL_COPY, "Return", wxPoint(w-130,h-50), wxSize(85,30) );
64
65 Centre( wxVERTICAL | wxHORIZONTAL );
66
67 m_timer = new wxCopyTimer( this );
68 m_timer->Start( 300, TRUE );
69
70 Show( TRUE );
71 };
72
73 wxCopyStatusDia::~wxCopyStatusDia()
74 {
75 delete m_timer;
76 };
77
78 void wxCopyStatusDia::OnCommand( wxCommandEvent &WXUNUSED(event) )
79 {
80 if (m_stop) EndModal(wxID_CANCEL);
81 m_stop = TRUE;
82 };
83
84 void wxCopyStatusDia::DoCopy(void)
85 {
86 wxYield();
87
88 if (!wxDirExists(m_dest))
89 {
90 wxMessageBox( "Target is not a directory or it doesn`t exist. Can`t copy.", "FileMaker" );
91 return;
92 };
93
94 for (uint i = 0; i < m_files->Count(); i++)
95 {
96 wxString src = (*m_files)[i];
97 if (wxDirExists( src ))
98 CopyDir( src, m_dest );
99 else
100 CopyFile( src, m_dest );
101 if (m_stop) return;
102 };
103 m_stop = TRUE;
104 };
105
106 void wxCopyStatusDia::CopyDir( wxString &srcDir, wxString &destDir )
107 {
108 wxString src = srcDir;
109 wxString dest = destDir;
110 dest += "/";
111 dest += wxFileNameFromPath( src );
112 if (!wxMkdir( dest ))
113 {
114 wxMessageBox( "Could not create target directory.", "FileMaker" );
115 return;
116 };
117
118 wxArrayString list;
119 src += "/*";
120 char *f = wxFindFirstFile( src, wxDIR );
121 while (f)
122 {
123 list.Add( f );
124 f = wxFindNextFile();
125 };
126
127 for (uint i = 0; i < list.Count(); i++)
128 {
129 wxString filename = list[i];
130 if (wxDirExists( filename ))
131 CopyDir( filename, dest );
132 else
133 CopyFile( filename, dest );
134 if (m_stop) return;
135 };
136 };
137
138 void wxCopyStatusDia::CopyFile( wxString &src, wxString &destDir )
139 {
140 m_sourceMsg->SetLabel( src );
141 wxString dest = destDir;
142 dest += "/";
143 dest += wxFileNameFromPath( src );
144 m_destMsg->SetLabel( dest );
145
146 wxYield();
147
148 if (wxFileExists(dest))
149 {
150 wxString s = "Target file ";
151 s += dest;
152 s += " exists already. Overwrite?";
153 int ret = wxMessageBox( s, "FileMaker", wxYES_NO );
154 if (ret == wxNO) return;
155 };
156
157 FILE *fs = (FILE *) NULL, *fd = (FILE *) NULL;
158 if (!(fs = fopen(src, "rb")))
159 {
160 wxString s = "Cannot open source file ";
161 s += src;
162 s += ".";
163 wxMessageBox( s, "FileMaker" );
164 return;
165 }
166 else
167 if (!(fd = fopen(dest, "wb")))
168 {
169 fclose(fs);
170 wxString s = "Cannot open target file ";
171 s += dest;
172 s += ".";
173 wxMessageBox( s, "FileMaker" );
174 return;
175 };
176 int ch;
177 long kcounter = 0;
178 while (!m_stop)
179 {
180 int counter = 0;
181 while ((ch = getc( fs )) != EOF)
182 {
183 putc( ch, fd );
184 counter++;
185 if (counter == 1000) break;
186 };
187 kcounter++;
188 m_statusMsg->SetLabel( IntToString( kcounter) );
189 wxYield();
190 if (ch == EOF) break;
191 };
192 fclose( fs );
193 fclose( fd );
194 };
195
196
197 //-----------------------------------------------------------------------------
198 // wxDeleteStatusDia
199 //-----------------------------------------------------------------------------
200
201 /*
202
203 IMPLEMENT_DYNAMIC_CLASS(wxDeleteStatusDia,wxDialogBox);
204
205 wxDeleteStatusDia::wxDeleteStatusDia( wxFrame *parent, wxStringList *files ) :
206 wxDialogBox( parent, "FileMaker delete job control", TRUE,
207 180, 180, 500, 200, wxCAPTION | wxTRANSIENT )
208 {
209 int w = 0;
210 int h = 0;
211 GetSize( &w, &h );
212
213 m_files = files;
214 m_stop = FALSE;
215 m_countFiles = 0;
216 m_countDirs = 0;
217
218 wxFont *myFont = wxTheFontList->FindOrCreateFont( 12, wxROMAN, wxNORMAL, wxNORMAL );
219 SetLabelFont( myFont );
220 SetButtonFont( myFont );
221
222 wxStaticText *msg = new wxStaticText( this, "Deleting file or directory:", 10, 10 );
223 m_targetMsg = new wxStaticText( this, "", 80, 40, 300 );
224 msg = new wxStaticText( this, " Directories deleted:", 10, 80 );
225 m_dirsMsg = new wxStaticText( this, "0", 120, 80, 80 );
226 msg = new wxStaticText( this, " Files deleted:", 10, 110 );
227 m_filesMsg = new wxStaticText( this, "0", 120, 110, 100 );
228
229 m_cancelButton = new wxButton( this, NULL, "Return", w-130, h-50, 85, 30 );
230
231 Centre( wxVERTICAL | wxHORIZONTAL );
232
233 m_timer = new wxDeleteTimer( this );
234 m_timer->Start( 300, TRUE );
235
236 Show( TRUE );
237 };
238
239 wxDeleteStatusDia::~wxDeleteStatusDia()
240 {
241 delete m_timer;
242 };
243
244 void wxDeleteStatusDia::OnCommand( wxWindow &win, wxCommandEvent &WXUNUSED(event) )
245 {
246 if (&win == m_cancelButton)
247 {
248 if (m_stop) Show( FALSE );
249 m_stop = TRUE;
250 return;
251 };
252 };
253
254 void wxDeleteStatusDia::DoDelete(void)
255 {
256 while (wxTheApp->Pending()) wxTheApp->Dispatch();
257 wxNode *node = m_files->First();
258 while (node)
259 {
260 char *target = (char*)node->Data();
261 if (wxDirExists( target ))
262 DeleteDir( target );
263 else
264 DeleteFile( target );
265 if (m_stop) return;
266 node = node->Next();
267 };
268 m_stop = TRUE;
269 };
270
271 void wxDeleteStatusDia::DeleteDir( char *target )
272 {
273 wxString s = target;
274 s += "// *";
275 wxStringList list;
276 char *f = wxFindFirstFile( s );
277 while (f)
278 {
279 list.Add( f );
280 f = wxFindNextFile();
281 };
282 wxNode *node = list.First();
283 while (node)
284 {
285 f = (char*)node->Data();
286 if (wxDirExists( f ))
287 DeleteDir( f );
288 else
289 DeleteFile( f );
290 if (m_stop) return;
291 node = node->Next();
292 };
293 if (!wxRmdir( target ))
294 {
295 s = "Could not remove directory ";
296 s += target;
297 s += ".";
298 wxMessageBox( s, "FileMaker" );
299 return;
300 }
301 else
302 {
303 m_countDirs++;
304 m_dirsMsg->SetLabel( wxIntToString( m_countDirs) );
305 };
306 };
307
308 void wxDeleteStatusDia::DeleteFile( char *target )
309 {
310 m_targetMsg->SetLabel( target );
311 while (wxTheApp->Pending()) wxTheApp->Dispatch();
312 if (!wxRemoveFile( target ))
313 {
314 wxString s = "Could not delete file ";
315 s += target;
316 s += ".";
317 wxMessageBox( s, "FileMaker" );
318 }
319 else
320 {
321 m_countFiles++;
322 m_filesMsg->SetLabel( wxIntToString( m_countFiles) );
323 };
324 };
325
326 */