]>
git.saurik.com Git - wxWidgets.git/blob - user/wxFile/FMJobs.cpp
4 * Author: Robert Roebling
6 * Copyright: (C) 1997, GNU (Robert Roebling)
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.
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.
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.
24 #pragma implementation "FMJobs.h"
29 #include "wx/filefn.h"
30 #include "wx/msgdlg.h"
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 IMPLEMENT_DYNAMIC_CLASS(wxCopyStatusDia
,wxDialog
);
38 const ID_CANCEL_COPY
= 1000;
40 BEGIN_EVENT_TABLE(wxCopyStatusDia
,wxDialog
)
41 EVT_BUTTON (ID_CANCEL_COPY
, wxCopyStatusDia::OnCommand
)
44 wxCopyStatusDia::wxCopyStatusDia( wxFrame
*parent
, const wxString
&dest
, wxArrayString
*files
) :
45 wxDialog( parent
, -1, "FileMaker copy job control", wxPoint(180,180), wxSize(500,200) )
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) );
63 m_cancelButton
= new wxButton( this, ID_CANCEL_COPY
, "Return", wxPoint(w
-130,h
-50), wxSize(85,30) );
65 Centre( wxVERTICAL
| wxHORIZONTAL
);
67 m_timer
= new wxCopyTimer( this );
68 m_timer
->Start( 300, TRUE
);
73 wxCopyStatusDia::~wxCopyStatusDia()
78 void wxCopyStatusDia::OnCommand( wxCommandEvent
&WXUNUSED(event
) )
80 if (m_stop
) EndModal(wxID_CANCEL
);
84 void wxCopyStatusDia::DoCopy(void)
88 if (!wxDirExists(m_dest
))
90 wxMessageBox( "Target is not a directory or it doesn`t exist. Can`t copy.", "FileMaker" );
94 for (uint i
= 0; i
< m_files
->Count(); i
++)
96 wxString src
= (*m_files
)[i
];
97 if (wxDirExists( src
))
98 CopyDir( src
, m_dest
);
100 CopyFile( src
, m_dest
);
106 void wxCopyStatusDia::CopyDir( wxString
&srcDir
, wxString
&destDir
)
108 wxString src
= srcDir
;
109 wxString dest
= destDir
;
111 dest
+= wxFileNameFromPath( src
);
112 if (!wxMkdir( dest
))
114 wxMessageBox( "Could not create target directory.", "FileMaker" );
120 char *f
= wxFindFirstFile( src
, wxDIR
);
124 f
= wxFindNextFile();
127 for (uint i
= 0; i
< list
.Count(); i
++)
129 wxString filename
= list
[i
];
130 if (wxDirExists( filename
))
131 CopyDir( filename
, dest
);
133 CopyFile( filename
, dest
);
138 void wxCopyStatusDia::CopyFile( wxString
&src
, wxString
&destDir
)
140 m_sourceMsg
->SetLabel( src
);
141 wxString dest
= destDir
;
143 dest
+= wxFileNameFromPath( src
);
144 m_destMsg
->SetLabel( dest
);
148 if (wxFileExists(dest
))
150 wxString s
= "Target file ";
152 s
+= " exists already. Overwrite?";
153 int ret
= wxMessageBox( s
, "FileMaker", wxYES_NO
);
154 if (ret
== wxNO
) return;
157 FILE *fs
= (FILE *) NULL
, *fd
= (FILE *) NULL
;
158 if (!(fs
= fopen(src
, "rb")))
160 wxString s
= "Cannot open source file ";
163 wxMessageBox( s
, "FileMaker" );
167 if (!(fd
= fopen(dest
, "wb")))
170 wxString s
= "Cannot open target file ";
173 wxMessageBox( s
, "FileMaker" );
181 while ((ch
= getc( fs
)) != EOF
)
185 if (counter
== 1000) break;
188 m_statusMsg
->SetLabel( IntToString( kcounter
) );
190 if (ch
== EOF
) break;
197 //-----------------------------------------------------------------------------
199 //-----------------------------------------------------------------------------
203 IMPLEMENT_DYNAMIC_CLASS(wxDeleteStatusDia,wxDialogBox);
205 wxDeleteStatusDia::wxDeleteStatusDia( wxFrame *parent, wxStringList *files ) :
206 wxDialogBox( parent, "FileMaker delete job control", TRUE,
207 180, 180, 500, 200, wxCAPTION | wxTRANSIENT )
218 wxFont *myFont = wxTheFontList->FindOrCreateFont( 12, wxROMAN, wxNORMAL, wxNORMAL );
219 SetLabelFont( myFont );
220 SetButtonFont( myFont );
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 );
229 m_cancelButton = new wxButton( this, NULL, "Return", w-130, h-50, 85, 30 );
231 Centre( wxVERTICAL | wxHORIZONTAL );
233 m_timer = new wxDeleteTimer( this );
234 m_timer->Start( 300, TRUE );
239 wxDeleteStatusDia::~wxDeleteStatusDia()
244 void wxDeleteStatusDia::OnCommand( wxWindow &win, wxCommandEvent &WXUNUSED(event) )
246 if (&win == m_cancelButton)
248 if (m_stop) Show( FALSE );
254 void wxDeleteStatusDia::DoDelete(void)
256 while (wxTheApp->Pending()) wxTheApp->Dispatch();
257 wxNode *node = m_files->First();
260 char *target = (char*)node->Data();
261 if (wxDirExists( target ))
264 DeleteFile( target );
271 void wxDeleteStatusDia::DeleteDir( char *target )
276 char *f = wxFindFirstFile( s );
280 f = wxFindNextFile();
282 wxNode *node = list.First();
285 f = (char*)node->Data();
286 if (wxDirExists( f ))
293 if (!wxRmdir( target ))
295 s = "Could not remove directory ";
298 wxMessageBox( s, "FileMaker" );
304 m_dirsMsg->SetLabel( wxIntToString( m_countDirs) );
308 void wxDeleteStatusDia::DeleteFile( char *target )
310 m_targetMsg->SetLabel( target );
311 while (wxTheApp->Pending()) wxTheApp->Dispatch();
312 if (!wxRemoveFile( target ))
314 wxString s = "Could not delete file ";
317 wxMessageBox( s, "FileMaker" );
322 m_filesMsg->SetLabel( wxIntToString( m_countFiles) );