1 //
2 // C++ Interface: wxDFast
3 //
4 // Description: This file include the external files, and declare the
5 //              classes used by the program.
6 //
7 //
8 // Author: Max Magalhães Velasques <maxvelasques@gmail.com>, (C) 2006
9 //
10 // Copyright: See COPYING file that comes with this distribution
11 //
12 //
13 
14 #ifndef __WXPROG_H__
15     #define __WXPROG_H__
16     #include "wx/wxprec.h"
17     #include "wx/wx.h"
18     #include "wx/app.h"
19     #include "wx/utils.h"
20     #include "wx/listctrl.h"
21     #include "wx/treectrl.h"
22     #include "wx/html/htmlwin.h"
23     #include "wx/frame.h"
24     #include "wx/fileconf.h"
25     #include "wx/splitter.h"
26     #include "wx/notebook.h"
27     #include "wx/imaglist.h"
28     #include "wx/protocol/ftp.h"
29     #include "wx/protocol/http.h"
30     #include "wx/file.h"
31     #include "wx/thread.h"
32     #include "wx/toolbar.h"
33     #include "wx/bitmap.h"
34     #include "wx/filename.h"
35     #include "wx/menu.h"
36     #include "wx/clipbrd.h"
37     #include "wx/sckstrm.h"
38     #include "wx/fdrepdlg.h"
39     #include "wx/cmdline.h"
40     #include "wx/progdlg.h"
41     #include "wx/ipc.h"
42     #include "wx/process.h"
43     #include "wx/socket.h"
44     #include "wx/spinctrl.h"
45     #include "wx/taskbar.h"
46     #include "wx/xrc/xmlres.h"
47     #include "wx/image.h"
48     #include "wx/snglinst.h"
49     #include "wx/pen.h"
50     #include "wx/calctrl.h"
51     #include "wx/tokenzr.h"
52     #include "wx/wfstream.h"
53     #include "wx/longlong.h"
54     #include "wx/uri.h"
55     #include "wx/datectrl.h"
56     #include "wx/xml/xml.h"
57     #include "wx/zipstrm.h"
58     #include "wx/dcbuffer.h"
59     #include "wxMD5/wxMD5.h"
60     #include "wxSHA1/wxSHA1.h"
61     #ifndef USE_EXTERNAL_XRC
62     extern void InitXmlResource();
63     #endif
64 
65 
66     //CUSTOM EVENTS
67     extern const wxEventType wxEVT_OPEN_URL;
68     extern const wxEventType wxEVT_SHUTDOWN;
69     extern const wxEventType wxEVT_DISCONNECT;
70     extern const wxEventType wxEVT_NEW_RELEASE;
71     extern const wxEventType wxEVT_NEW_DOWNLOAD;
72     extern const wxEventType wxEVT_EXECUTE_COMMAND;
73 
74     const wxCmdLineEntryDesc cmdlinedesc[] =
75     {
76         { wxCMD_LINE_SWITCH, wxT("hide"), wxT("hide"), wxT("Start with the the main frame hide.")},
77         { wxCMD_LINE_SWITCH, wxT("notray"), wxT("notray"),  wxT("Don't show the icon on system tray")},
78         { wxCMD_LINE_OPTION, wxT("list"), wxT("list"),  wxT("Parse a text file with the list of files to download")},
79         { wxCMD_LINE_OPTION, wxT("destination"), wxT("destination"),  wxT("Destination directory")},
80         { wxCMD_LINE_OPTION, wxT("comments"), wxT("comments"),  wxT("Add comments to download")},
81         { wxCMD_LINE_OPTION, wxT("reference"), wxT("reference"),  wxT("Set a reference URL")},
82         { wxCMD_LINE_PARAM, NULL, NULL,  wxT("URL of the file(s) to be downloaded"),wxCMD_LINE_VAL_STRING,wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE},
83         { wxCMD_LINE_NONE }
84     };
85 
86     #define ID_MY_WINDOW    1324
87     #ifdef __WXMSW__
88         #define wxXPM(x)  (wxBitmap((const char **)x))
89     #else
90         #define wxXPM(x)  (wxBitmap(x))
91     #endif
92 
93     const wxString PROGRAM_NAME = wxT("wxDownload Fast");
94     const wxString VERSION = wxT("0.6.0");
95     const wxString SEPARATOR_URL = wxT("/");
96     #ifdef __WXMSW__
97        const wxString SEPARATOR_DIR = wxT("\\");
98     #else
99        const wxString SEPARATOR_DIR = wxT("/");
100     #endif
101 
102     #define MANUAL                     0
103     #define NOW                        1
104     #define SCHEDULE                   2
105 
106     #define MAX_NUM_PARTS              32
107     #define DEFAULT_NUM_PARTS          5
108     #define DEFAULT_START_OPTION       NOW
109     #define DEFAULT_ONTOP_OPTION       false
110                                         //START THE DOWNLOAD IMMEDIATLY
111     #define MIN_SIZE_TO_SPLIT          500000l
112     #define USE_HTML_MESSAGES          1
113                                         //CHANGE THIS AND THE FILE MAIN_WINDOW.XRC
114     #define MAX_SCHEDULE_EXCEPTIONS    9
115 
116     #define IPC_SERVICE                wxT("24242")
117     #define IPC_TOPIC                  wxT("IPC_WXDOWNLAD_FAST_")
118     #define IPC_END_CONNECTION         wxT("IPC_WXDOWNLAD_FAST_END_CONECTION")
119 
120     #ifdef __WXMAC__
121         #define DISABLE_MUTEX
122     #endif
123 
124     const wxString STOPWITHOUTSAVINGSTOPSTATUS = wxT("STOPWITHOUTSAVINGSTOPSTATUS");
125 
126     const wxString DFAST_REG = wxT("wxDownloadFast");
127     const wxString FILES_REG = wxT("files");
128     const wxString INPROGRESS_REG = wxT("files/inprogress");
129     const wxString FINISHED_REG = wxT("files/finished");
130     const wxString BACK_DIR_REG = wxT("..");
131     const wxString NAME_REG = wxT("name");
132     const wxString INDEX_REG = wxT("index");
133     const wxString STATUS_REG = wxT("status");
134     const wxString SCHEDULED_REG = wxT("scheduled");
135     const wxString RESTART_REG = wxT("restart");
136     const wxString PARTS_REG = wxT("parts");
137     const wxString DESTINATION_REG = wxT("destination");
138     const wxString TEMPDESTINATION_REG = wxT("tempdestination");
139     const wxString SIZE_REG = wxT("size");
140     const wxString SIZEPART_REG = wxT("sizepart");
141     const wxString SIZECOMPLETED_REG = wxT("sizecompleted");
142     const wxString SIZEPARTCOMPLETED_REG = wxT("sizepartcompleted");
143     const wxString TIMEPASSED_REG = wxT("timepassed");
144     const wxString PERCENTUAL_REG = wxT("percentual");
145     const wxString SPEED_REG = wxT("speed");
146     const wxString URL_REG = wxT("url");
147     const wxString MD5_REG = wxT("md5");
148     const wxString COMMENTS_REG = wxT("comments");
149     const wxString REFERENCE_REG = wxT("reference");
150     const wxString COMMAND_REG = wxT("command");
151     const wxString CONTENTTYPE_REG = wxT("contenttype");
152     const wxString BANDWIDTH_REG = wxT("bandwidth");
153     const wxString START_REG = wxT("date_start");
154     const wxString END_REG = wxT("date_end");
155     const wxString USER_REG = wxT("user");
156     const wxString PASSWORD_REG = wxT("password");
157     const wxString NEED_TO_REGET_METALINK_REG = wxT("needtoregetmetalink");
158     const wxString METALINK_INDEX_REG = wxT("metalinkindex");
159 
160     const wxString CONFIG_REG = wxT("config");
161     const wxString LANGUAGE_REG = wxT("language");
162     const wxString DETAILS_REG = wxT("details");
163     const wxString SIZE_X_REG = wxT("width");
164     const wxString SIZE_Y_REG = wxT("height");
165     const wxString POS_X_REG = wxT("posx");
166     const wxString POS_Y_REG = wxT("posy");
167     const wxString MAXIMIZED_REG = wxT("maximized");
168     const wxString SEPARATOR01_REG = wxT("separator01position");
169     const wxString SEPARATOR02_REG = wxT("separator02position");
170 
171     const wxString OPT_LAST_NEW_RELEASE_CHECK = wxT("lastnewreleasecheck");
172     const wxString OPT_CURRENT_RELEASE = wxT("currentrelease");
173     const wxString OPT_DIALOG_CLOSE_REG = wxT("closewindow");
174     const wxString OPT_ATTEMPTS_REG = wxT("attempts");
175     const wxString OPT_ATTEMPTS_TIME_REG = wxT("attemptstime");
176     const wxString OPT_SIMULTANEOUS_REG = wxT("simultaneous");
177     const wxString OPT_REMEMBER_BOXNEW_OPTIONS_REG = wxT("rememberboxnewoptions");
178     const wxString OPT_DESTINATION_REG = wxT("dirdestination");
179     const wxString OPT_DOWNLOAD_PARTS_DEFAULT_DIR_REG = wxT("downloadpartsdefaultdir");
180     const wxString OPT_FILE_MANAGER_PATH_REG = wxT("filemanagerpath");
181     const wxString OPT_BROWSER_PATH_REG = wxT("browserpath");
182     const wxString OPT_SHUTDOWN_REG = wxT("shutdown");
183     const wxString OPT_SHUTDOWN_CMD_REG = wxT("shutdowncmd");
184     const wxString OPT_DISCONNECT_REG = wxT("disconnect");
185     const wxString OPT_DISCONNECT_CMD_REG = wxT("disconnectcmd");
186     const wxString OPT_TIMERINTERVAL_REG = wxT("timerinterval");
187     const wxString OPT_READBUFFERSIZE_REG = wxT("readbuffersize");
188     const wxString OPT_RESTORE_MAINFRAME_REG = wxT("restoremainframe");
189     const wxString OPT_HIDE_MAINFRAME_REG = wxT("hidemainframe");
190     const wxString OPT_CHECK_FOR_UPDATES_REG = wxT("checkforupdates");
191     const wxString OPT_PROGRESS_BAR_SHOW_REG = wxT("progressbarshow");
192     const wxString OPT_GRAPH_SHOW_REG = wxT("graphshow");
193     const wxString OPT_GRAPH_HOWMANYVALUES_REG = wxT("graphhowmanyvalues");
194     const wxString OPT_GRAPH_REFRESHTIME_REG = wxT("graphrefreshtime");
195     const wxString OPT_GRAPH_SCALE_REG = wxT("graphscale");
196     const wxString OPT_GRAPH_TEXTAREA_REG = wxT("graphtextarea");
197     const wxString OPT_GRAPH_HEIGHT_REG = wxT("graphheight");
198     const wxString OPT_GRAPH_SPEEDFONTSIZE_REG = wxT("graphspeedfontsize");
199     const wxString OPT_GRAPH_LINEWIDTH_REG = wxT("graphlinewidth");
200     const wxString OPT_GRAPH_COLORBACK_REG = wxT("graphcolorbackground");
201     const wxString OPT_GRAPH_COLORGRID_REG = wxT("graphcolorgrid");
202     const wxString OPT_GRAPH_COLORLINE_REG = wxT("graphcolorline");
203     const wxString OPT_GRAPH_COLORFONT_REG = wxT("graphcolorfont");
204     const wxString OPT_SCHED_ACTIVATESCHEDULING_REG = wxT("activatescheduling");
205     const wxString OPT_SCHED_STARTDATETIME_REG = wxT("schedstartdatetime");
206     const wxString OPT_SCHED_FINISHDATETIME_REG = wxT("schedfinishdatetime");
207     const wxString OPT_SCHED_SCHEDULEEXCEPTION_START_REG = wxT("scheduleexceptionstart");
208     const wxString OPT_SCHED_SCHEDULEEXCEPTION_FINISH_REG = wxT("scheduleexceptionfinish");
209     const wxString OPT_SCHED_SCHEDULEEXCEPTION_DAY_REG = wxT("scheduleexceptionday");
210     const wxString OPT_SCHED_SCHEDULEEXCEPTION_ISACTIVE_REG = wxT("scheduleexceptionisactive");
211     const wxString OPT_LAST_DESTINATION_REG = wxT("lastdestination");
212     const wxString OPT_LAST_COMMAND_REG = wxT("lastcommand");
213     const wxString OPT_LAST_NUMBER_OF_PARTS_REG = wxT("lastnumberofparts");
214     const wxString OPT_LAST_START_OPTION_REG = wxT("laststartoption");
215     const wxString OPT_LAST_ONTOP_OPTION_REG = wxT("lastontopoption");
216     const wxString OPT_LAST_BOXNEW_X_REG = wxT("lastboxnew_x");
217     const wxString OPT_LAST_BOXNEW_Y_REG = wxT("lastboxnew_y");
218     const wxString OPT_BAND_WIDTH_OPTION_REG = wxT("bandwidthoption");
219     const wxString OPT_BAND_WIDTH_GENERAL_REG = wxT("bandwidthgeneral");
220     const wxString OPT_TASKBAR_ICON_SIZE_REG = wxT("taskbariconsize");
221     const wxString OPT_PROXY_REG = wxT("proxyuse");
222     const wxString OPT_PROXY_SERVER_REG = wxT("proxyserver");
223     const wxString OPT_PROXY_PORT_REG = wxT("proxyport");
224     const wxString OPT_PROXY_USERNAME_REG = wxT("proxyusername");
225     const wxString OPT_PROXY_AUTHSTRING_REG = wxT("proxyauthstring");
226 
227 
228     const wxString EXT = wxT(".dfast");
229     #ifdef __WXMSW__
230         const wxString PREFIX = wxT("");
231     #else
232         #ifdef WXDFAST_PORTABLE
233         const wxString PREFIX = wxT("");
234         #else
235         const wxString PREFIX = wxT(".");
236         #endif
237     #endif
238     const wxString LINE = wxT("-");
239     const wxString CRLF = wxT("\r\n");
240     const wxString ANONYMOUS_USER = wxT("anonymous");
241     const wxString ANONYMOUS_PASS = wxT("anonymous@anonymous.com");
242 
243     const wxColor RED = wxColor(255,0,30);
244     const wxColor BLUE = wxColor(0,47,94);
245     const wxColor LIGHT_BLUE = wxColor(0,0,200);
246     const wxColor GREEN = wxColor(0,98,65);
247     const wxColor LIGHT_GREEN = wxColor(0,181,0);
248     const wxColor YELLOW = wxColor(250,230,24);
249 
250     const wxString HTMLERROR = wxT("#FF0030");         //RED
251     const wxString HTMLSERVER = wxT("#009865");        //GREEN
252     const wxString HTMLNORMAL = wxT("#002f5e");        //BLUE
253     const wxString HTMLBLACK = wxT("#000000");        //BLACK
254 
255     const wxString days[7] = {_("Sundays"),_("Mondays"),_("Tuesdays"),
256                               _("Wednesdays"),_("Thursdays"),_("Fridays"),
257                               _("Saturdays")};
258 
259     const int INPROGRESS_ICON01 = 0;
260     const int INPROGRESS_ICON02 = 1;
261     const int INPROGRESS_NAME = 2;
262     const int INPROGRESS_SIZE = 3;
263     const int INPROGRESS_COMPLETED = 4;
264     const int INPROGRESS_PERCENTUAL = 5;
265     const int INPROGRESS_TIMEPASSED = 6;
266     const int INPROGRESS_TIMEREMAINING = 7;
267     const int INPROGRESS_SPEED = 8;
268     const int INPROGRESS_ATTEMPTS = 9;
269     const int INPROGRESS_URL = 10;
270 
271     const int FINISHED_ICON01 = 0;
272     const int FINISHED_NAME = 1;
273     const int FINISHED_SIZE = 2;
274     const int FINISHED_END = 3;
275 
276     #define HTTP                1
277     #define FTP                 2
278     #define LOCAL_FILE          3
279     #define READ                4
280     #define WRITE               5
281 
282     #define HIDE                1000
283     #define NEW                 1001
284     #define CLOSE               1002
285     #define TIMER_ID            1003
286     #define BAND                1004
287     #define OFF                 1005
288     #define ON                  1006
289     #define PERDOWNLOAD         1007
290 
291     //mDownloadFile STATUS
292     #define STATUS_STOPED               0
293     #define STATUS_ACTIVE               1
294     #define STATUS_FINISHED             2
295     #define STATUS_ERROR                3
296     #define STATUS_QUEUE                4
297     #define STATUS_SCHEDULE_QUEUE       5
298 
299 
300     //mDownloadFile RESTART
301     #define YES                 0
302     #define NO                  1
303 
304     class mMainFrame;
305     class mUrlName;
306     class mBoxNew;
307     class mBoxOptions;
308     class mInProgressList;
309     class mFinishedList;
310     class mTaskBarIcon;
311     class mConnection;
312     class mClient;
313     class mServer;
314     class mDownloadThread;
315     class mGraph;
316     class mProgressBar;
317     class mMetalinkData;
318 
319     WX_DECLARE_OBJARRAY(int,mListSelection);
320     WX_DEFINE_ARRAY(mDownloadThread *, mDownloadThreadArray);
321     WX_DECLARE_LIST(mUrlName, mUrlList);
322 
323     class mDownloadFile
324     {
325     public:
~mDownloadFile()326         ~mDownloadFile()
327         {
328             if (this->urllist)
329                 delete this->urllist;
330             //if (this->metalinkdata)
331                 //delete this->metalinkdata;
332         };
333         //FUNCTIONS
334         void RegisterListItemOnDisk();
335         void RemoveListItemFromDisk();
336         int GetStatus();
337         void SetAsActive();
338         void SetAsStoped(bool stopschedule = TRUE);
339         void SetAsFinished();
340         void ErrorOccurred();
341         void PutOnQueue();
342         bool IsScheduled();
343         void PutOnScheduleQueue();
344         //int GetIndex();
345         wxString GetName();
346         wxString GetExposedName();
347         void SetExposedName(wxString name);
348         void UnSetExposedName();
349         wxString GetDestination();
350         wxString GetTemporaryDestination();
351         wxString GetReferenceURL();
352         wxString GetComments();
353         wxString GetUser();
354         wxString GetPassword();
355         int RestartSupport();
356         void SetRestartSupport(bool support = TRUE);
357         wxString GetContentType();
358         void SetContentType(wxString contenttype);
359         bool IsMetalink();
360         bool IsHtml();
361         bool IsZip();
362         int GetNumberofParts();
363         int GetCurrentAttempt();
364         void ResetAttempts();
365         void IncrementAttempt();
366         mUrlName GetFirstUrl();
367         mUrlName GetNextUrl();
368         bool AppendUrl(mUrlName *url);
369         bool FindUrl(mUrlName url);
370         int GetUrlCount();
371         wxArrayString GetUrlArray();
372         void SetFinishedDateTime(wxDateTime time);
373         wxDateTime GetFinishedDateTime();
374         void SetMD5(wxString md5);
375         int GetProgress();
376         void SetProgress(int percentual);
377         bool IsSplitted();
378         void Split(bool split);
379         bool WaitingForSplit();
380         void WaitSplit();
381         bool WriteIsPending();
382         void MarkWriteAsPending(bool pending);
383         bool RemoveIsPending();
384         void MarkRemoveAsPending(bool pending);
385         void SetFree(bool free = TRUE);
386         bool IsFree();
387         void SetBandWidth(int band);
388         int GetBandWidth();
389         bool NeedToReGetMetalink();
390         void SetToReGetMetalinkWhenNeeded(bool reget);
391         void SetMetalinkFileIndex(int index);
392         int GetMetalinkFileIndex();
393         wxString GetCommand();
394         void SetChangedSinceLastSave();
395 
396         //PUBLIC VARIABLES
397         friend class mDownloadList;
398         wxLongLong timepassed;
399         wxLongLong timeremaining;
400         wxLongLong totalsize;
401         wxLongLong totalsizecompleted;
402         long totalspeed;
403 
404         bool criticalerror;
405         bool speedpoint;
406         int speedpointowner;
407         #ifndef DISABLE_MUTEX
408         wxMutex *mutex_speedcalc;
409         #endif
410 
411         bool finished[MAX_NUM_PARTS];
412         wxLongLong startpoint[MAX_NUM_PARTS];
413         wxLongLong size[MAX_NUM_PARTS];
414         wxLongLong sizecompleted[MAX_NUM_PARTS];
415         long delta_size[MAX_NUM_PARTS];
416         int percentualparts[MAX_NUM_PARTS];
417         wxString messages[MAX_NUM_PARTS];
418         mMetalinkData *metalinkdata;
419     private:
420         int index;
421         int status;
422         bool split;
423         bool waitbeforesplit;
424         bool free;
425         bool needtoregetmetalink;
426         wxString name;
427         wxString exposedname;
428         wxString destination;
429         wxString tempdestination;
430         wxString reference;
431         wxString comments;
432         wxString user;
433         wxString password;
434         wxString MD5;
435         int scheduled;
436         int restart;
437         wxString contenttype;
438         mUrlList *urllist;
439         unsigned int currenturl;
440         int parts;
441         int currentattempt;
442         wxDateTime start;
443         wxDateTime end;
444         int percentual;
445         bool writependig;
446         bool removepending;
447         int bandwidth;
448         int metalinkindex;
449         wxString command;
450         bool changedsincelastsave;
451     };
452 
453     WX_DECLARE_LIST(mDownloadFile, mDownloadListType);
454 
455     class mDownloadList: public mDownloadListType
456     {
457     public:
458         void ChangePosition(mDownloadFile *file01, mDownloadFile *file02);
459         mDownloadFile *NewDownloadRegister(mUrlList *urllist,wxFileName destination,wxFileName tempdestination, int metalinkindex, int parts, wxString user, wxString password,wxString reference, wxString comments,wxString command,int scheduled,int bandwidth,int ontop);
460         void RemoveDownloadRegister(mDownloadFile *currentfile);
461         void ChangeDownload(mDownloadFile *file, mUrlList *urllist,wxFileName destination, wxString user, wxString password, wxString reference, wxString comments,wxString command,int bandwidth);
462         void ChangeName(mDownloadFile *file, wxString name, int value = 0);
463         mDownloadFile *FindDownloadFile(wxString str);
464         void LoadDownloadListFromDisk();
465         void RecreateIndex();
466         static int ListCompareByIndex(const mDownloadFile** arg1, const mDownloadFile** arg2);
467         int GetNumberofActiveDownloads();
468         void SetNumberofActiveDownloads(int number);
469     private:
470         int numberofactivedownloads;
471     };
472 
473     WX_DECLARE_LIST(float, mGraphPoints);
474 
475     class mScheduleException
476     {
477     public:
478         wxString start,finish;
479         wxString newstart,newfinish;
480         int day;    //0 - Sunday
481         int newday; //1 - Monday ...
482         int isactive;
483     };
484 
485     class mOptions
486     {
487     public:
488         wxString currentrelease;
489         wxDateTime lastnewreleasecheck;
490         int attempts;             //number of attempts
491         bool closedialog;         //show the close dialog
492         int simultaneous;         //number of simultaneous downloads
493         int attemptstime;         //time between the attempts in seconds
494         bool shutdown;
495         bool disconnect;
496         bool alwaysshutdown;
497         bool alwaysdisconnect;
498         int timerupdateinterval; //time between the timer refreshs in milliseconds
499         long readbuffersize;
500         bool restoremainframe;   //Restore the mainframe when all downloads are finished
501         bool hidemainframe;      //Hide the mainframe when the user start a download
502         bool checkforupdates;
503         bool progressbarshow;
504         bool graphshow;
505         int graphhowmanyvalues;
506         int graphrefreshtime;    //time between the graph refreshs in milliseconds
507         int graphscale;          //max value showed in the graph
508         int graphtextarea;       //size the area reserved for the speed value
509         int graphheight;
510         int graphspeedfontsize;
511         wxColour graphbackcolor;
512         wxColour graphgridcolor;
513         wxColour graphlinecolor;
514         int graphlinewidth;
515         wxColour graphfontcolor;
516         wxString shutdowncmd;
517         wxString disconnectcmd;
518         wxString destination;
519         wxString browserpath;
520         wxString filemanagerpath;
521         wxString downloadpartsdefaultdir;
522         bool activatescheduling;
523         wxDateTime startdatetime;
524         wxDateTime finishdatetime;
525         mScheduleException scheduleexceptions[MAX_SCHEDULE_EXCEPTIONS];
526         bool scheduleexceptionschanged;
527         wxString lastcommand;
528         wxString lastdestination;
529         int lastnumberofparts;
530         int laststartoption;
531         int lastontopoption;
532         bool rememberboxnewoptions;
533         int bandwidthoption;
534         long bandwidth;
535         int taskbariconsize;
536         int boxnew_x, boxnew_y;
537         bool proxy;
538         wxString proxy_server;
539         wxString proxy_port;
540         wxString proxy_username;
541         wxString proxy_authstring;
542     };
543 
544     class mApplication : public wxApp
545     {
546     public:
547         mApplication();
548         virtual ~mApplication();
549         virtual bool OnInit();
550         virtual int OnExit();
551         bool NewInstance();
552         mDownloadList downloadlist;
553         mDownloadThreadArray *downloadthreads;
554         static wxString Configurations(int operation, wxString option, wxString value);
555         static int Configurations(int operation, wxString option, int value);
556         static long Configurations(int operation, wxString option,long value);
557         mMainFrame *mainframe;
558         wxCmdLineParser *parameters;
559         mServer *m_server;
560         wxSocketBase *dummy;
561         mConnection *connection;
562         wxSingleInstanceChecker *m_checker;
563         wxCriticalSection m_critsect;
564         wxMutex m_mutexAllDone;
565         wxCondition m_condAllDone;
566         bool m_waitingUntilAllDone;
567         void SetLanguage(int language);
568         wxString themepath;
569         wxIcon appicon;
570         #ifdef __WXMSW__
571         wxString programvolume;
572         #endif
573     private:
574         wxLocale *m_locale;
575     };
576 
DECLARE_APP(mApplication)577     DECLARE_APP(mApplication)
578 
579     class mMainFrame : public wxFrame
580     {
581     public:
582         mMainFrame();
583         ~mMainFrame();
584         void OnTimer(wxTimerEvent& event);
585         bool NewDownload(wxArrayString url, wxString destination,int metalinkindex, int parts,wxString user,wxString password,wxString reference,wxString comments,wxString command,int startoption, bool ontop, bool show,bool permitdifferentnames);
586         bool StartDownload(mDownloadFile *downloadfile);
587         void StopDownload(mDownloadFile *downloadfile,bool stopschedule = TRUE);
588         void OnNew(wxCommandEvent& event);
589         void OnRemove(wxCommandEvent& event);
590         void OnSchedule(wxCommandEvent& event);
591         void OnStart(wxCommandEvent& event);
592         void OnStop(wxCommandEvent& event);
593         void OnStartAll(wxCommandEvent& event);
594         void OnStopAll(wxCommandEvent& event);
595         void OnPasteURL(wxCommandEvent& event);
596         void OnCopyURL(wxCommandEvent& event);
597         void OnSelectAll(wxCommandEvent& event);
598         void OnInvertSelection(wxCommandEvent& event);
599         void OnFind(wxCommandEvent& event);
600         void OnShowProgressBar(wxCommandEvent& event);
601         void OnShowGraph(wxCommandEvent& event);
602         void ShowHideResizeGraph(int oldgraphheight);
603         void OnDetails(wxCommandEvent& event);
604         //Languages
605         void MarkCurrentLanguageMenu(int language);
606         void SetLanguage(int language);
607         void OnDefaultLanguage(wxCommandEvent& event);
608         void OnEnglish(wxCommandEvent& event);
609         void OnPortuguese(wxCommandEvent& event);
610         void OnPortugueseBrazil(wxCommandEvent& event);
611         void OnGerman(wxCommandEvent& event);
612         void OnSpanish(wxCommandEvent& event);
613         void OnCzech(wxCommandEvent& event);
614         void OnHungarian(wxCommandEvent& event);
615         void OnRussian(wxCommandEvent& event);
616         void OnIndonesian(wxCommandEvent& event);
617         void OnArmenian(wxCommandEvent& event);
618         void OnPolish(wxCommandEvent& event);
619         void OnTurkish(wxCommandEvent& event);
620         void OnFrench(wxCommandEvent& event);
621         void OnDutch(wxCommandEvent& event);
622 
623         void OnProperties(wxCommandEvent& event);
624         void OnMove(wxCommandEvent& event);
625         void OnDownloadAgain(wxCommandEvent& event);
626         void OnCheckMD5(wxCommandEvent& event);
627         void OnOpenDestination(wxCommandEvent& event);
628         void OnCopyDownloadData(wxCommandEvent& event);
629         void OnExportConf(wxCommandEvent& event);
630         void OnImportConf(wxCommandEvent& event);
631         bool ImportConf(wxString path);
632         bool ExportConf(wxString dir);
633         void OnShutdown(wxCommandEvent& event);
634         void OnDisconnect(wxCommandEvent& event);
635         void OnOptions(wxCommandEvent& event);
636         void OnIconize(wxIconizeEvent& event);
637         void OnExit(wxCommandEvent& event);
638         void OnClose(wxCloseEvent& event);
639         void OnSite(wxCommandEvent& event);
640         void OnBug(wxCommandEvent& event);
641         void OnDonate(wxCommandEvent& event);
642         void OnAbout(wxCommandEvent& WXUNUSED(event));
643         void BrowserFile();
644         void OnToolLeftClick(wxCommandEvent& event);
645         void OnToolMouseMove(wxCommandEvent& event);
646         void OnUpDown(bool up);
647         void OnOpenURL(wxCommandEvent& event);
648         void OnShutdownEvent(wxCommandEvent& event);
649         void OnDisconnectEvent(wxCommandEvent& event);
650         void OnExecuteEvent(wxCommandEvent& event);
651         bool UpdateListItemField(mDownloadFile *current);
652         void CheckNewRelease();
653         void OnNewRelease(wxCommandEvent& event);
654         void OnFilePreview(wxCommandEvent& event);
655         void OnNewDownloadEvent(wxCommandEvent& event);
656         mTaskBarIcon *taskbaricon;
657         mProgressBar *progressbar;
658         mGraph *graph;
659         wxMenuBar *menubar;
660         wxToolBar *toolbar;
661         wxStatusBar *statusbar;
662         wxMenu *menupopup;
663         mOptions programoptions;
664         #ifndef DISABLE_MUTEX
665         wxMutex *mutex_programoptions;
666         #endif
667         mGraphPoints graphpoints;
668         int timerinterval;
669         int writetimerinterval;
670         bool active;
671         wxString defaultstatusbarmessage;
672     private:
673         int completed[MAX_NUM_PARTS];
674         wxTimer *mtimer;
675         wxImageList *imageslist;
676         DECLARE_EVENT_TABLE()
677     };
678 
679     class mGraph : public wxPanel
680     {
681     public:
682         mGraph();
683         bool Hide();
684         bool Show(bool show = TRUE);
685         void OnPaint(wxPaintEvent &event);
686         void SetMainFrame(mMainFrame *mainframe);
687         mGraphPoints *graphpoints;
688         DECLARE_DYNAMIC_CLASS(mGraph)
689     private:
690         mMainFrame *mainframe;
691         mOptions *programoptions;
692         DECLARE_EVENT_TABLE()
693     };
694 
695     class mProgressBar : public wxPanel
696     {
697     public:
698         mProgressBar();
699         void OnPaint(wxPaintEvent &event);
700         bool Hide();
701         bool Show(bool show = TRUE);
702         void SetMainFrame(mMainFrame *mainframe);
703         void SetParams(int parts,int *completed);
704         DECLARE_DYNAMIC_CLASS(mProgressBar)
705     private:
706         mMainFrame *mainframe;
707         int parts;
708         int completed[MAX_NUM_PARTS];
709         DECLARE_EVENT_TABLE()
710     };
711 
712 
713     class mTaskBarIcon: public wxTaskBarIcon
714     {
715     public:
716         mTaskBarIcon(mMainFrame *frame);
717         void OnLButtonClick(wxTaskBarIconEvent&);
718         void OnMouseMove(wxTaskBarIconEvent&);
719         void OnClose(wxCommandEvent& event);
720         void OnHide(wxCommandEvent& event);
721         void OnNew(wxCommandEvent& event);
722         void OnBandUnlimited(wxCommandEvent& event);
723         void OnBandControlOn(wxCommandEvent& event);
724         void OnBandControlPerDownload(wxCommandEvent& event);
725         virtual wxMenu *CreatePopupMenu();
726         bool restoring;
727         wxBitmap NewDownload;
728         wxBitmap Quit;
729     private:
730         mMainFrame *mainframe;
731         DECLARE_EVENT_TABLE()
732     };
733 
734     class mBoxNew: public wxDialog
735     {
736     public:
737         void OnOk(wxCommandEvent& event);
738         void OnCancel(wxCommandEvent& event);
739         void OnButtonDir(wxCommandEvent& event);
740         void OnButtonAdd(wxCommandEvent& event);
741         void OnButtonEdit(wxCommandEvent& event);
742         int CheckURL(mUrlName url);
743         bool PermitDifferentNames();
744         void SetDifferentNamesPermition(bool permit);
745     private:
746         bool permitdifferentnames;
747         DECLARE_EVENT_TABLE()
748     };
749 
750     class mBoxOptions: public wxDialog
751     {
752     public:
753         void OnOk(wxCommandEvent& event);
754         void OnCancel(wxCommandEvent& event);
755         void OnButtonDir(wxCommandEvent& event);
756         void OnBrowserPath(wxCommandEvent& event);
757         void OnFileManagerPath(wxCommandEvent& event);
758         void OnTempPath(wxCommandEvent& event);
759         void OnGraphBackgroundColour(wxCommandEvent& event);
760         void OnGraphGridColour(wxCommandEvent& event);
761         void OnGraphLineColour(wxCommandEvent& event);
762         void OnGraphFontColour(wxCommandEvent& event);
763         void OnButtonStartDate(wxCommandEvent& event);
764         void OnButtonFinishDate(wxCommandEvent& event);
765         void OnAdd(wxCommandEvent& event);
766         void OnRemove(wxCommandEvent& event);
767     private:
768         DECLARE_EVENT_TABLE()
769     };
770 
771     class mDatePicker: public wxDialog
772     {
773     public:
mDatePicker(wxWindow * parent,wxWindowID id,const wxString & title,wxString date)774         mDatePicker(wxWindow* parent, wxWindowID id, const wxString& title, wxString date):
775                 wxDialog(parent, id, title)
776         {
777             //int wdate,hdate,wbtn,hbtn;
778             wxDateTime tmpdate;
779             tmpdate.ParseDate(date);
780             m_datepicker = new wxCalendarCtrl(this,0,tmpdate,wxPoint(0,0),wxDefaultSize);
781             m_btnok = new wxButton(this,wxID_OK,_("OK"));
782 
783             grid_sizer = new wxFlexGridSizer(2, 1, 0, 0);
784             grid_sizer->Add(m_datepicker, 1, wxEXPAND, 0);
785             grid_sizer->Add(m_btnok, 0, wxALIGN_RIGHT|wxADJUST_MINSIZE, 0);
786             SetAutoLayout(true);
787             SetSizer(grid_sizer);
788             grid_sizer->Fit(this);
789             grid_sizer->SetSizeHints(this);
790             Layout();
791             this->CentreOnParent();
792         };
~mDatePicker()793         ~mDatePicker()
794         {
795             delete m_datepicker;
796             delete m_btnok;
797         };
OnOk(wxCommandEvent & event)798         void OnOk(wxCommandEvent& event)
799         {
800             m_selecteddate = m_datepicker->GetDate().Format(wxT("%Y/%m/%d"));
801             EndModal(wxID_OK);
802         };
GetSelectedDate()803         wxString GetSelectedDate()
804         {
805             return m_selecteddate;
806         };
807     private:
808         wxFlexGridSizer* grid_sizer;
809         wxCalendarCtrl *m_datepicker;
810         wxButton *m_btnok;
811         wxString m_selecteddate;
812         DECLARE_EVENT_TABLE()
813     };
814 
815     class mBoxOptionsColorPanel: public wxPanel
816     {
817     public:
818         void OnPaint(wxPaintEvent &event);
819         wxColor colour;
820         DECLARE_DYNAMIC_CLASS(mBoxOptionsColorPanel)
821     private:
822         DECLARE_EVENT_TABLE()
823     };
824 
825     class mBoxFind: public wxFindReplaceDialog {
826     public:
827         mBoxFind(wxWindow * parent, wxFindReplaceData* data, const wxString& title, int style = 0):
wxFindReplaceDialog(parent,data,title,style)828         wxFindReplaceDialog(parent, data, title, style){}
829 
830         void OnFind(wxFindDialogEvent& event);
831         void OnClose(wxFindDialogEvent& event);
832     private:
833         DECLARE_EVENT_TABLE()
834     };
835 
836     class mInProgressList : public wxListCtrl
837     {
838     public:
839         mInProgressList();
840         void OnRClick(wxListEvent& event);
841         void OnDoubleClick(wxListEvent& event);
842         void OnSelected(wxListEvent& event);
843         void OnDeselected(wxListEvent& event);
844         void OnLeaveWindow(wxMouseEvent& event);
845         void OnEnterWindow(wxMouseEvent& event);
846         void SelectUnselect(bool selected,int selection);
847         int Insert(mDownloadFile *current, int item,bool ontop = false);
848         mListSelection GetCurrentSelection();
849         int GetCurrentLastSelection();
850         void SetCurrentSelection(int selection);
851         void RemoveItemListandFile(int item);
852         void HandleSelectDeselectEvents(bool value);
853         void GenerateList(wxImageList *imageslist);
854         mMainFrame *mainframe;
855          DECLARE_DYNAMIC_CLASS(mInProgressList)
856     private:
857         int lastselection;
858         bool handleselectdeselectevents;
859         DECLARE_EVENT_TABLE()
860     };
861 
862     class mFinishedList : public wxListCtrl
863     {
864     public:
865         void OnRClick(wxListEvent& event);
866         void OnDoubleClick(wxListEvent& event);
867         void OnSelected(wxListEvent& event);
868         void OnDeselected(wxListEvent& event);
869         void OnLeaveWindow(wxMouseEvent& event);
870         void OnEnterWindow(wxMouseEvent& event);
871         void SelectUnselect(bool selected,int selection);
872         mListSelection GetCurrentSelection();
873         int GetCurrentLastSelection();
874         void SetCurrentSelection(int selection);
875         void GenerateList(wxImageList *imageslist);
876         static int wxCALLBACK CompareDates(long item1, long item2, long WXUNUSED(sortData));
877         mMainFrame *mainframe;
878         DECLARE_DYNAMIC_CLASS(mFinishedList)
879     private:
880         int lastselection;
881         DECLARE_EVENT_TABLE()
882     };
883 
884     class mNotebook : public wxNotebook
885     {
886     public:
887         void ReSetPagesLabel();
888         void OnChangePage(wxNotebookEvent& event);
889         DECLARE_DYNAMIC_CLASS(mNotebook)
890     private:
891         wxString labelpage01;
892         wxString labelpage02;
893         DECLARE_EVENT_TABLE()
894     };
895 
896     class mUrlName : public wxURI
897     {
898     public:
899         mUrlName();
900         mUrlName(wxString uri);
901         //~mUrlName();
902         wxString GetHost();
903         wxString GetPort();
904         wxString GetDir();
905         wxString GetFullName();
906         wxString GetFullRealName();
907         wxString GetFullPath();
908         int Type();
909         bool IsComplete();
910     };
911 
912     class mFTP: public wxFTP
913     {
914     public:
915         wxLongLong GetFileSize(const wxString& fileName);
916         wxInputStream *GetInputStream(const wxString& path);
917     };
918 
919     class mHTTP: public wxHTTP
920     {
921     public:
922         mHTTP();
923         wxString BuildGetRequest(mUrlName url,wxLongLong start);
924         void SendGetRequest();
925         wxString GetResponseMessage();
926         bool Connect(wxSockAddress& addr, bool wait);
927         int GetResponse() { return m_http_response; }
928         int GetCompleteResponse() { return m_http_complete_response; }
929         void UseProxy(wxString proxy_authstring);
930     private:
931         bool ParseHeaders();
932         char *wxstr2str(wxString wxstr);
933         wxString m_headersmsg;
934         wxString m_getcommand;
935         wxString m_messagereceived;
936         wxString path;
937         int m_http_complete_response;
938         bool m_use_proxy;
939         wxString m_proxy_authstring;
940     };
941 
942     class mConnection: public wxConnection
943     {
944     public:
945         bool OnExecute(const wxString& topic, wxChar* data, int size, wxIPCFormat format);
946     };
947 
948     class mClient: public wxClient
949     {
950     public:
951         wxConnectionBase *OnMakeConnection(void) { return new mConnection; }
952     };
953 
954     class mServer: public wxServer
955     {
956     public:
957         wxConnectionBase *OnAcceptConnection(const wxString& topic);
958     };
959 
960     class mDownloadThread : public wxThread
961     {
962     public:
963         mDownloadThread(mDownloadFile *file, int index);
964         // thread execution starts here
965         virtual void *Entry();
966 
967         // called when the thread exits - whether it terminates normally or is
968         // stopped with Delete() (but not when it is Kill()ed!)
969         virtual void OnExit();
970         mUrlName CheckHtmlFile(bool downloaded = FALSE);
971         wxLongLong CurrentSize(wxString filepath,wxString filename);
972         int FinishDownload(wxFileName *destination,wxFileName tempdestination);
973         wxSocketClient *ConnectHTTP(wxLongLong *start);
974         wxSocketClient *ConnectFTP(wxLongLong *start);
975         wxInputStream *ConnectLOCAL_FILE(wxLongLong start);
976         int  DownloadPart(wxSocketClient *connection, wxInputStream *filestream, wxLongLong start, wxLongLong end);
977                         //the parameter wxInputStream *filestream is used just for LOCAL_FILE
978         void PrintMessage(wxString str,wxString color=HTMLNORMAL);
979         void WaitUntilAllFinished(bool canstop = TRUE);
980         bool JoinFiles(wxFileName *destination,wxFileName tempdestination);
981         void SpeedCalculation(long delta_t);
982         mDownloadFile *downloadfile;
983         mOptions *programoptions;
984         int downloadpartindex;
985         mUrlName currenturl;
986         bool redirecting;
987         mDownloadList *downloadlist;
988         wxLongLong realtotalsize_copy;
989         mUrlName *proxy_address;
990         bool proxy;
991         wxString proxy_authstring;
992     };
993 
994     class mCheckNewReleaseThread : public wxThread
995     {
996     public:
997         mCheckNewReleaseThread();
998         // thread execution starts here
999         virtual void *Entry();
1000 
1001         // called when the thread exits - whether it terminates normally or is
1002         // stopped with Delete() (but not when it is Kill()ed!)
1003         virtual void OnExit();
1004     };
1005 
1006     class mMetalinkData
1007     {
1008     public:
1009         wxString publishername;
1010         wxString publisherurl;
1011         wxString description;
1012         wxString filename;
1013         wxString version;
1014         wxLongLong size;
1015         wxString language;
1016         wxString os;
1017         wxString md5;
1018         wxString sha1;
1019         mUrlList urllist;
1020         void Clear();
1021     };
1022 
1023     class mMetalinkDocument : public wxXmlDocument
1024     {
1025     public:
1026         int GetMetalinkData(mMetalinkData *data,int index);
1027     private:
1028         int GetFileData(mMetalinkData *data,wxXmlNode *subnode);
1029         wxString GetContent(wxXmlNode *children);
1030     };
1031 
1032     class MyUtilFunctions
1033     {
1034     public:
1035         static wxString int2wxstr(long value,int format = 0);
1036         static wxString TimeString(long value);
1037         static wxString TimeString(wxLongLong value);
1038         static wxString GetLine(wxString text, int line);
1039         static wxString str2wxstr(char *str);
1040         static wxString str2wxstr(char str);
1041         static wxString ByteString(long size);
1042         static wxString ByteString(wxLongLong size);
1043         static wxLongLong wxstrtolonglong(wxString string);
1044         static double wxlonglongtodouble(wxLongLong value);
1045         static wxString GenerateAuthString(wxString user, wxString pass);
1046         #ifdef __WXMSW__
1047         static wxString GetProgramFilesDir();
1048         static wxString GetMyDocumentsDir();
1049         static wxString GetDefaultBrowser();
1050         #endif
1051     };
1052 #endif
1053