1 //
2 // C++ Implementation: MainFrame
3 //
4 // Description: Implements the mainframe events, including menus and the toolbar.
5 //
6 //
7 // Author: Max Magalhães Velasques <maxvelasques@gmail.com>, (C) 2006
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12 
13 #include "wxDFast.h"
14 
15 IMPLEMENT_DYNAMIC_CLASS(mNotebook, wxNotebook)
16 IMPLEMENT_DYNAMIC_CLASS(mBoxOptionsColorPanel, wxPanel)
17 
18 ////////////////////////XPM IMAGES////////////////////////////////
19 /*#ifndef __WXMSW__
20 #include "../resources/xpm/wxdfast.xpm"
21 #endif
22 #include "../resources/xpm/small/stop.xpm"
23 #include "../resources/xpm/small/start.xpm"
24 #include "../resources/xpm/small/ok.xpm"
25 #include "../resources/xpm/small/error.xpm"
26 #include "../resources/xpm/small/queue.xpm"
27 #include "../resources/xpm/small/schedule.xpm"
28 #include "../resources/xpm/small/new.xpm"
29 #include "../resources/xpm/small/exit.xpm"*/
30 
31 const wxEventType wxEVT_OPEN_URL = wxNewEventType();
32 #define wxEVT_OPEN_URL(id, fn) \
33     DECLARE_EVENT_TABLE_ENTRY( \
34         wxEVT_OPEN_URL, id, wxID_ANY, \
35         (wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxCommandEventFunction, &fn ), \
36         (wxObject *) NULL \
37     ),
38 
39 const wxEventType wxEVT_SHUTDOWN = wxNewEventType();
40 #define wxEVT_SHUTDOWN(id, fn) \
41     DECLARE_EVENT_TABLE_ENTRY( \
42         wxEVT_SHUTDOWN, id, wxID_ANY, \
43         (wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxCommandEventFunction, &fn ), \
44         (wxObject *) NULL \
45     ),
46 
47 const wxEventType wxEVT_DISCONNECT = wxNewEventType();
48 #define wxEVT_DISCONNECT(id, fn) \
49     DECLARE_EVENT_TABLE_ENTRY( \
50         wxEVT_DISCONNECT, id, wxID_ANY, \
51         (wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxCommandEventFunction, &fn ), \
52         (wxObject *) NULL \
53     ),
54 
55 const wxEventType wxEVT_NEW_RELEASE = wxNewEventType();
56 #define wxEVT_NEW_RELEASE(id, fn) \
57     DECLARE_EVENT_TABLE_ENTRY( \
58         wxEVT_NEW_RELEASE, id, wxID_ANY, \
59         (wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxCommandEventFunction, &fn ), \
60         (wxObject *) NULL \
61     ),
62 
63 const wxEventType wxEVT_NEW_DOWNLOAD = wxNewEventType();
64 #define wxEVT_NEW_DOWNLOAD(id, fn) \
65     DECLARE_EVENT_TABLE_ENTRY( \
66         wxEVT_NEW_DOWNLOAD, id, wxID_ANY, \
67         (wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxCommandEventFunction, &fn ), \
68         (wxObject *) NULL \
69     ),
70 
71 const wxEventType wxEVT_EXECUTE_COMMAND = wxNewEventType();
72 #define wxEVT_EXECUTE_COMMAND(id, fn) \
73     DECLARE_EVENT_TABLE_ENTRY( \
74         wxEVT_EXECUTE_COMMAND, id, wxID_ANY, \
75         (wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent( wxCommandEventFunction, &fn ), \
76         (wxObject *) NULL \
77     ),
78 
BEGIN_EVENT_TABLE(mMainFrame,wxFrame)79 BEGIN_EVENT_TABLE(mMainFrame,wxFrame)
80     EVT_MENU(XRCID("menunew"),  mMainFrame::OnNew)
81     EVT_MENU(XRCID("menuremove"),  mMainFrame::OnRemove)
82     EVT_MENU(XRCID("menuschedule"),  mMainFrame::OnSchedule)
83     EVT_MENU(XRCID("menustart"),  mMainFrame::OnStart)
84     EVT_MENU(XRCID("menustop"),  mMainFrame::OnStop)
85     EVT_MENU(XRCID("menustartall"),  mMainFrame::OnStartAll)
86     EVT_MENU(XRCID("menustopall"),  mMainFrame::OnStopAll)
87     EVT_MENU(XRCID("menuexit"),  mMainFrame::OnExit)
88     EVT_MENU(XRCID("menusite"),  mMainFrame::OnSite)
89     EVT_MENU(XRCID("menubug"),  mMainFrame::OnBug)
90     EVT_MENU(XRCID("menudonate"),  mMainFrame::OnDonate)
91     EVT_MENU(XRCID("menuabout"), mMainFrame::OnAbout)
92     EVT_MENU(XRCID("menulang_default"), mMainFrame::OnDefaultLanguage)
93     EVT_MENU(XRCID("menulang_ent"), mMainFrame::OnEnglish)
94     EVT_MENU(XRCID("menulang_pt"), mMainFrame::OnPortuguese)
95     EVT_MENU(XRCID("menulang_ptbr"), mMainFrame::OnPortugueseBrazil)
96     EVT_MENU(XRCID("menulang_de"), mMainFrame::OnGerman)
97     EVT_MENU(XRCID("menulang_es"), mMainFrame::OnSpanish)
98     EVT_MENU(XRCID("menulang_cs"), mMainFrame::OnCzech)
99     EVT_MENU(XRCID("menulang_hu"), mMainFrame::OnHungarian)
100     EVT_MENU(XRCID("menulang_ru"), mMainFrame::OnRussian)
101     EVT_MENU(XRCID("menulang_id"), mMainFrame::OnIndonesian)
102     EVT_MENU(XRCID("menulang_hy"), mMainFrame::OnArmenian)
103     EVT_MENU(XRCID("menulang_pl"), mMainFrame::OnPolish)
104     EVT_MENU(XRCID("menulang_tr"), mMainFrame::OnTurkish)
105     EVT_MENU(XRCID("menulang_fr"), mMainFrame::OnFrench)
106     EVT_MENU(XRCID("menulang_nl"), mMainFrame::OnDutch)
107     EVT_MENU(XRCID("menushowgraph"), mMainFrame::OnShowGraph)
108     EVT_MENU(XRCID("menushowprogressbar"), mMainFrame::OnShowProgressBar)
109     EVT_MENU(XRCID("menudetails"), mMainFrame::OnDetails)
110     EVT_MENU(XRCID("menupaste"), mMainFrame::OnPasteURL)
111     EVT_MENU(XRCID("menuoptions"), mMainFrame::OnOptions)
112     EVT_MENU(XRCID("menuproperties"), mMainFrame::OnProperties)
113     EVT_MENU(XRCID("menuselectall"), mMainFrame::OnSelectAll)
114     EVT_MENU(XRCID("menuinvertselection"), mMainFrame::OnInvertSelection)
115     EVT_MENU(XRCID("menufind"), mMainFrame::OnFind)
116     EVT_MENU(XRCID("menuagain"), mMainFrame::OnDownloadAgain)
117     EVT_MENU(XRCID("menumove"), mMainFrame::OnMove)
118     EVT_MENU(XRCID("menumd5"), mMainFrame::OnCheckMD5)
119     EVT_MENU(XRCID("menuopendestination"), mMainFrame::OnOpenDestination)
120     EVT_MENU(XRCID("menucopyurl"), mMainFrame::OnCopyURL)
121     EVT_MENU(XRCID("menucopydownloaddata"), mMainFrame::OnCopyDownloadData)
122     EVT_MENU(XRCID("menuexport"), mMainFrame::OnExportConf)
123     EVT_MENU(XRCID("menuimport"), mMainFrame::OnImportConf)
124     EVT_MENU(XRCID("menushutdown"), mMainFrame::OnShutdown)
125     EVT_MENU(XRCID("menudisconnect"), mMainFrame::OnDisconnect)
126     EVT_BUTTON(XRCID("btnpreview"), mMainFrame::OnFilePreview)
127     wxEVT_OPEN_URL(wxID_ANY,mMainFrame::OnOpenURL)
128     wxEVT_SHUTDOWN(wxID_ANY, mMainFrame::OnShutdownEvent)
129     wxEVT_DISCONNECT(wxID_ANY, mMainFrame::OnDisconnectEvent)
130     wxEVT_EXECUTE_COMMAND(wxID_ANY, mMainFrame::OnExecuteEvent)
131     wxEVT_NEW_RELEASE(wxID_ANY, mMainFrame::OnNewRelease)
132     wxEVT_NEW_DOWNLOAD(wxID_ANY, mMainFrame::OnNewDownloadEvent)
133     EVT_TOOL(-1, mMainFrame::OnToolLeftClick)
134     EVT_TOOL_ENTER(-1, mMainFrame::OnToolMouseMove)
135     EVT_ICONIZE(mMainFrame::OnIconize)
136     EVT_TIMER(TIMER_ID, mMainFrame::OnTimer)
137     EVT_CLOSE(mMainFrame::OnClose)
138 END_EVENT_TABLE()
139 
140 
141 BEGIN_EVENT_TABLE(mNotebook,wxNotebook)
142     EVT_NOTEBOOK_PAGE_CHANGED(XRCID("notebook01"),  mNotebook::OnChangePage)
143 END_EVENT_TABLE()
144 
145 void mNotebook::ReSetPagesLabel()
146 {
147     SetPageText(0,wxGetTranslation(_("Downloads in Progress")));
148     SetPageText(1,wxGetTranslation(_("Finished Downloads")));
149 }
150 
OnChangePage(wxNotebookEvent & event)151 void mNotebook::OnChangePage(wxNotebookEvent& event)
152 {
153     int oldselection = event.GetOldSelection();
154     if (oldselection == 0)
155     {
156         XRCCTRL(*(wxGetApp().mainframe), "inprogresslist",mInProgressList )->SelectUnselect(FALSE,-1);
157         XRCCTRL(*(wxGetApp().mainframe), "finishedlist",mFinishedList )->SelectUnselect(FALSE,-1);
158     }
159     else if (oldselection == 1)
160     {
161         XRCCTRL(*(wxGetApp().mainframe), "finishedlist",mFinishedList )->SelectUnselect(FALSE,-1);
162         XRCCTRL(*(wxGetApp().mainframe), "inprogresslist",mInProgressList )->SelectUnselect(FALSE,-1);
163     }
164     if (event.GetSelection() == 1)
165     {
166         XRCCTRL(*(wxGetApp().mainframe), "finishedlist",mFinishedList )->SortItems(mFinishedList::CompareDates, 0l);
167     }
168     event.Skip();
169 };
170 
mMainFrame()171 mMainFrame::mMainFrame()
172 {
173     imageslist = new wxImageList(16, 16, TRUE);
174     wxBitmap image[6];
175     int i,timerupdateinterval;
176 
177     wxString iconpath = wxGetApp().themepath;
178     image[0] = wxXmlResource::Get()->LoadBitmap(wxT("stop_png"));
179     image[1] = wxXmlResource::Get()->LoadBitmap(wxT("start_png"));
180     image[2] = wxXmlResource::Get()->LoadBitmap(wxT("completed_png"));
181     image[3] = wxXmlResource::Get()->LoadBitmap(wxT("error_png"));
182     image[4] = wxXmlResource::Get()->LoadBitmap(wxT("scheduled_png"));
183     image[5] = wxXmlResource::Get()->LoadBitmap(wxT("schedule_png"));
184 
185     for (i=0;i<=5;i++)
186        imageslist->Add(image[i]);
187     wxXmlResource::Get()->LoadFrame(this,NULL, wxT("mainframe"));
188     SetSize(-1,-1,600,400);
189     SetTitle(PROGRAM_NAME);
190 
191     //LOAD USER OPTIONS
192     programoptions.currentrelease = mApplication::Configurations(READ,OPT_CURRENT_RELEASE,VERSION);
193     programoptions.lastnewreleasecheck.Set((time_t)mApplication::Configurations(READ,OPT_LAST_NEW_RELEASE_CHECK,0));
194     programoptions.closedialog = mApplication::Configurations(READ,OPT_DIALOG_CLOSE_REG,1);
195     programoptions.rememberboxnewoptions = mApplication::Configurations(READ,OPT_REMEMBER_BOXNEW_OPTIONS_REG,1);
196     #ifdef __WXMSW__
197     programoptions.destination = mApplication::Configurations(READ,OPT_DESTINATION_REG,MyUtilFunctions::GetMyDocumentsDir());
198     programoptions.filemanagerpath = mApplication::Configurations(READ,OPT_FILE_MANAGER_PATH_REG,wxGetOSDirectory() + wxT("\\explorer.exe"));
199     programoptions.browserpath = mApplication::Configurations(READ,OPT_BROWSER_PATH_REG,wxEmptyString);
200     if (programoptions.browserpath.IsEmpty())
201         programoptions.browserpath = MyUtilFunctions::GetDefaultBrowser();
202     //defaultbrowserpath = MyUtilFunctions::GetProgramFilesDir() + wxT("\\Mozilla Firefox\\firefox.exe");
203     #else
204     programoptions.destination = mApplication::Configurations(READ,OPT_DESTINATION_REG,wxGetHomeDir());
205     programoptions.filemanagerpath = mApplication::Configurations(READ,OPT_FILE_MANAGER_PATH_REG,wxT("/usr/bin/nautilus"));
206     programoptions.browserpath = mApplication::Configurations(READ,OPT_BROWSER_PATH_REG,wxT("/usr/bin/firefox"));
207     #endif
208     #ifdef WXDFAST_PORTABLE
209     programoptions.downloadpartsdefaultdir = wxT("partial");
210     if (!wxFileName::DirExists(programoptions.downloadpartsdefaultdir))
211         wxFileName::Mkdir(programoptions.downloadpartsdefaultdir); //CREATE THE PARTIAL DIRECTORY
212     #else
213     programoptions.downloadpartsdefaultdir = mApplication::Configurations(READ,OPT_DOWNLOAD_PARTS_DEFAULT_DIR_REG,wxGetHomeDir());
214     #endif
215     programoptions.attempts = mApplication::Configurations(READ,OPT_ATTEMPTS_REG,999);
216     programoptions.attemptstime = mApplication::Configurations(READ,OPT_ATTEMPTS_TIME_REG,5);
217     programoptions.simultaneous = mApplication::Configurations(READ,OPT_SIMULTANEOUS_REG,5);
218     programoptions.alwaysshutdown = mApplication::Configurations(READ,OPT_SHUTDOWN_REG,0);
219     programoptions.shutdown = programoptions.alwaysshutdown;
220     programoptions.alwaysdisconnect = mApplication::Configurations(READ,OPT_DISCONNECT_REG,0);
221     programoptions.timerupdateinterval = mApplication::Configurations(READ,OPT_TIMERINTERVAL_REG,500);
222     programoptions.readbuffersize = mApplication::Configurations(READ,OPT_READBUFFERSIZE_REG,1024);
223     programoptions.disconnect = programoptions.alwaysdisconnect;
224     #ifdef __WXMSW__
225     programoptions.shutdowncmd = mApplication::Configurations(READ,OPT_SHUTDOWN_CMD_REG,wxGetOSDirectory() + wxT("\\system32\\shutdown.exe -s -t 0"));
226     programoptions.disconnectcmd = mApplication::Configurations(READ,OPT_DISCONNECT_CMD_REG,wxGetOSDirectory() + wxT("\\system32\\rasdial.exe /disconnect"));
227     #else
228     programoptions.shutdowncmd = mApplication::Configurations(READ,OPT_SHUTDOWN_CMD_REG,wxT("sudo /sbin/shutdown -h now"));
229     programoptions.disconnectcmd = mApplication::Configurations(READ,OPT_DISCONNECT_CMD_REG,wxT("/usr/bin/poff"));
230     #endif
231     programoptions.restoremainframe = mApplication::Configurations(READ,OPT_RESTORE_MAINFRAME_REG, 1);
232     programoptions.hidemainframe = mApplication::Configurations(READ,OPT_HIDE_MAINFRAME_REG, 0);
233     programoptions.checkforupdates = mApplication::Configurations(READ,OPT_CHECK_FOR_UPDATES_REG, 1);
234     programoptions.progressbarshow = mApplication::Configurations(READ,OPT_PROGRESS_BAR_SHOW_REG, 1);
235     programoptions.graphshow = mApplication::Configurations(READ,OPT_GRAPH_SHOW_REG, 1);
236     programoptions.graphhowmanyvalues = mApplication::Configurations(READ,OPT_GRAPH_HOWMANYVALUES_REG, 300);
237     programoptions.graphrefreshtime = mApplication::Configurations(READ,OPT_GRAPH_REFRESHTIME_REG, 1000);
238     programoptions.graphscale = mApplication::Configurations(READ,OPT_GRAPH_SCALE_REG, 200);
239     programoptions.graphtextarea = mApplication::Configurations(READ,OPT_GRAPH_TEXTAREA_REG, 80);
240     programoptions.graphspeedfontsize = mApplication::Configurations(READ,OPT_GRAPH_SPEEDFONTSIZE_REG, 18);
241     programoptions.graphheight = mApplication::Configurations(READ,OPT_GRAPH_HEIGHT_REG, 48);
242     programoptions.graphlinewidth = mApplication::Configurations(READ,OPT_GRAPH_LINEWIDTH_REG, 3);
243     {
244         wxString colour;
245         long red,green,blue;
246         colour = mApplication::Configurations(READ,OPT_GRAPH_COLORBACK_REG, wxT(""));
247         if (!colour.Mid(0,3).ToLong(&red))            red = wxBLACK->Red();
248         if (!colour.Mid(4,3).ToLong(&green))        green = wxBLACK->Green();
249         if (!colour.Mid(8,3).ToLong(&blue))            blue = wxBLACK->Blue();
250         programoptions.graphbackcolor.Set(red,green,blue);
251     }
252     {
253         wxString colour;
254         long red,green,blue;
255         colour = mApplication::Configurations(READ,OPT_GRAPH_COLORGRID_REG, wxT(""));
256         if (!colour.Mid(0,3).ToLong(&red))            red = wxGREEN->Red();
257         if (!colour.Mid(4,3).ToLong(&green))        green = wxGREEN->Green();
258         if (!colour.Mid(8,3).ToLong(&blue))            blue = wxGREEN->Blue();
259         programoptions.graphgridcolor.Set(red,green,blue);
260     }
261     {
262         wxString colour;
263         long red,green,blue;
264         colour = mApplication::Configurations(READ,OPT_GRAPH_COLORLINE_REG, wxT(""));
265         if (!colour.Mid(0,3).ToLong(&red))            red = wxRED->Red();
266         if (!colour.Mid(4,3).ToLong(&green))        green = wxRED->Green();
267         if (!colour.Mid(8,3).ToLong(&blue))            blue = wxRED->Blue();
268         programoptions.graphlinecolor.Set(red,green,blue);
269     }
270     {
271         wxString colour;
272         long red,green,blue;
273         colour = mApplication::Configurations(READ,OPT_GRAPH_COLORFONT_REG, wxT(""));
274         if (!colour.Mid(0,3).ToLong(&red))            red = wxBLUE->Red();
275         if (!colour.Mid(4,3).ToLong(&green))        green = wxBLUE->Green();
276         if (!colour.Mid(8,3).ToLong(&blue))            blue = wxBLUE->Blue();
277         programoptions.graphfontcolor.Set(red,green,blue);
278     }
279     programoptions.activatescheduling = mApplication::Configurations(READ,OPT_SCHED_ACTIVATESCHEDULING_REG,0);
280     programoptions.startdatetime.Set((time_t)mApplication::Configurations(READ,OPT_SCHED_STARTDATETIME_REG,wxDateTime::Now().GetTicks()));
281     programoptions.finishdatetime.Set((time_t)mApplication::Configurations(READ,OPT_SCHED_FINISHDATETIME_REG,wxDateTime::Now().GetTicks()));
282     programoptions.scheduleexceptionschanged = FALSE;
283     for (i=0;i<MAX_SCHEDULE_EXCEPTIONS;i++)
284     {
285         programoptions.scheduleexceptions[i].isactive = mApplication::Configurations(READ,OPT_SCHED_SCHEDULEEXCEPTION_ISACTIVE_REG+MyUtilFunctions::int2wxstr(i),0);
286         programoptions.scheduleexceptions[i].start = mApplication::Configurations(READ,OPT_SCHED_SCHEDULEEXCEPTION_START_REG+MyUtilFunctions::int2wxstr(i),wxT("00:00"));
287         programoptions.scheduleexceptions[i].finish = mApplication::Configurations(READ,OPT_SCHED_SCHEDULEEXCEPTION_FINISH_REG+MyUtilFunctions::int2wxstr(i),wxT("00:00"));
288         programoptions.scheduleexceptions[i].day = mApplication::Configurations(READ,OPT_SCHED_SCHEDULEEXCEPTION_DAY_REG+MyUtilFunctions::int2wxstr(i),0);
289         programoptions.scheduleexceptions[i].newday = 0;
290         programoptions.scheduleexceptions[i].newstart = wxEmptyString;
291         programoptions.scheduleexceptions[i].newfinish = wxEmptyString;
292     }
293     programoptions.boxnew_x = mApplication::Configurations(READ,OPT_LAST_BOXNEW_X_REG,200);
294     programoptions.boxnew_y = mApplication::Configurations(READ,OPT_LAST_BOXNEW_Y_REG,200);
295     programoptions.lastcommand = mApplication::Configurations(READ,OPT_LAST_COMMAND_REG,wxEmptyString);
296     programoptions.lastdestination = mApplication::Configurations(READ,OPT_LAST_DESTINATION_REG,programoptions.destination);
297     programoptions.lastnumberofparts = mApplication::Configurations(READ,OPT_LAST_NUMBER_OF_PARTS_REG,DEFAULT_NUM_PARTS);
298     programoptions.laststartoption = mApplication::Configurations(READ,OPT_LAST_START_OPTION_REG,DEFAULT_START_OPTION);
299     programoptions.lastontopoption = mApplication::Configurations(READ,OPT_LAST_ONTOP_OPTION_REG,DEFAULT_ONTOP_OPTION);
300     programoptions.bandwidthoption = mApplication::Configurations(READ,OPT_BAND_WIDTH_OPTION_REG,0);
301     programoptions.bandwidth = mApplication::Configurations(READ,OPT_BAND_WIDTH_GENERAL_REG,20l);
302     programoptions.taskbariconsize = mApplication::Configurations(READ,OPT_TASKBAR_ICON_SIZE_REG,32);
303     programoptions.proxy = mApplication::Configurations(READ,OPT_PROXY_REG,0);
304     programoptions.proxy_server = mApplication::Configurations(READ,OPT_PROXY_SERVER_REG,wxEmptyString);
305     programoptions.proxy_port = mApplication::Configurations(READ,OPT_PROXY_PORT_REG,wxEmptyString);
306     programoptions.proxy_username = mApplication::Configurations(READ,OPT_PROXY_USERNAME_REG,wxEmptyString);
307     programoptions.proxy_authstring = mApplication::Configurations(READ,OPT_PROXY_AUTHSTRING_REG,wxEmptyString);
308 
309    //LOAD THE PROGRAM ICON
310     wxBitmap tmpicon = wxXmlResource::Get()->LoadBitmap(wxT("wxdfast_png"));
311     wxGetApp().appicon.CopyFromBitmap(tmpicon);
312 
313     SetIcon(wxGetApp().appicon);
314 
315     //SET THE PROGRESS BAR VARS
316     progressbar = XRCCTRL(*(this), "progressbar",mProgressBar );
317     progressbar->SetMainFrame(this);
318     progressbar->SetBackgroundStyle(wxBG_STYLE_CUSTOM);
319 
320     //SET THE GRAPH VARS
321     graphpoints.DeleteContents(TRUE);
322     graph = XRCCTRL(*(this), "graphpanel",mGraph );
323     graph->graphpoints = &graphpoints;
324     graph->SetMainFrame(this);
325     graph->SetBackgroundStyle(wxBG_STYLE_CUSTOM);
326 
327     //LOAD THE MENU BAR
328     if ((menubar = wxXmlResource::Get()->LoadMenuBar(wxT("menubar"))))
329         this->SetMenuBar(menubar);
330     else
331         menubar = NULL;
332 
333     //LOAD THE TOOL BAR
334     if ((toolbar = wxXmlResource::Get()->LoadToolBar(this,wxT("toolbar"))))
335         this->SetToolBar(toolbar);
336     else
337         toolbar = NULL;
338 
339     statusbar = this->GetStatusBar();
340 
341     //CHECK THE RIGHT LANGUAGE MENU
342     MarkCurrentLanguageMenu(mApplication::Configurations(READ,LANGUAGE_REG,0));
343 
344     if (menubar)
345     {
346         menubar->GetMenu(3)->Check(XRCID("menushutdown"),programoptions.shutdown);
347         menubar->GetMenu(3)->Check(XRCID("menudisconnect"),programoptions.disconnect);
348     }
349     timerupdateinterval = programoptions.timerupdateinterval;
350 
351 
352     //SET NOTEBOOK TAB LABELS
353     XRCCTRL(*(this), "notebook01",mNotebook )->ReSetPagesLabel();
354 
355     //GENERATE THE LISTS
356     XRCCTRL(*this, "inprogresslist",mInProgressList )->mainframe = this;
357     XRCCTRL(*this, "finishedlist",mFinishedList )->mainframe = this;
358     XRCCTRL(*this, "inprogresslist",mInProgressList )->GenerateList(imageslist);
359     XRCCTRL(*this, "finishedlist",mFinishedList )->GenerateList(imageslist);
360 
361     //CREATE THE POPUPMENU FOR THE LISTS
362     menupopup = new wxMenu;
363     wxMenuItem *schedule = new wxMenuItem(menupopup,XRCID("menuschedule"), _("Schedule Download"));
364     wxMenuItem *start = new wxMenuItem(menupopup,XRCID("menustart"), _("Start Download"));
365     wxMenuItem *stop = new wxMenuItem(menupopup,XRCID("menustop"), _("Stop Download"));
366     wxMenuItem *remove = new wxMenuItem(menupopup,XRCID("menuremove"), _("Remove Download"));
367     wxMenuItem *properties = new wxMenuItem(menupopup,XRCID("menuproperties"), _("Properties of Download"));
368     wxMenuItem *downloadagain = new wxMenuItem(menupopup,XRCID("menuagain"), _("Download File Again"));
369     wxMenuItem *move = new wxMenuItem(menupopup,XRCID("menumove"), _("Move File"));
370     wxMenuItem *checkmd5 = new wxMenuItem(menupopup,XRCID("menumd5"), _("Check Integrity"));
371     wxMenuItem *copyurl = new wxMenuItem(menupopup,XRCID("menucopyurl"), _("Copy URL"));
372     wxMenuItem *copydownloaddata = new wxMenuItem(menupopup,XRCID("menucopydownloaddata"), _("Copy Download Data"));
373     wxMenuItem *opendestination = new wxMenuItem(menupopup,XRCID("menuopendestination"), _("Open Destination Directory"));
374 
375     start->SetBitmap(image[1]);
376     stop->SetBitmap(image[0]);
377     schedule->SetBitmap(image[5]);
378     remove->SetBitmap(wxXmlResource::Get()->LoadBitmap(wxT("remove_png")));
379     properties->SetBitmap(wxXmlResource::Get()->LoadBitmap(wxT("properties_png")));
380     copyurl->SetBitmap(wxXmlResource::Get()->LoadBitmap(wxT("copyurl_png")));
381     copydownloaddata->SetBitmap(wxXmlResource::Get()->LoadBitmap(wxT("copydata_png")));
382     menupopup->Append(schedule);
383     menupopup->Append(start);
384     menupopup->Append(stop);
385     menupopup->Append(remove);
386     menupopup->Append(properties);
387     menupopup->AppendSeparator();
388     menupopup->Append(copyurl);
389     menupopup->Append(copydownloaddata);
390     menupopup->Append(checkmd5);
391     menupopup->Append(opendestination);
392     menupopup->AppendSeparator();
393     menupopup->Append(move);
394     menupopup->Append(downloadagain);
395 
396     #ifndef DISABLE_MUTEX
397     mutex_programoptions = new wxMutex();
398     #endif
399 
400     //CREATE TASKBARICON
401     this->active = TRUE;
402     taskbaricon = new mTaskBarIcon(this);
403     if (!(wxGetApp().parameters->Found(wxT("notray"))))
404         taskbaricon->SetIcon(wxGetApp().appicon,PROGRAM_NAME);
405     taskbaricon->restoring = FALSE;
406     taskbaricon->NewDownload = wxXmlResource::Get()->LoadBitmap(wxT("new_png"));
407     taskbaricon->Quit = wxXmlResource::Get()->LoadBitmap(wxT("quit_png"));
408 
409     //HIDE OR SHOW THE SPEED GRAPH
410     if (!programoptions.graphshow)
411         graph->Hide();
412     else
413         graph->Show();
414 
415     //HIDE OR SHOW THE PROGRESS BAR
416     if (!programoptions.progressbarshow)
417         progressbar->Hide();
418     else
419         progressbar->Show();
420 
421     //DEFINE THE STATUSBAR DEFAULT TEXT
422     if (statusbar)
423     {
424         this->defaultstatusbarmessage = wxEmptyString;
425         wxStringTokenizer newrelease(programoptions.currentrelease,wxT("."));
426         wxStringTokenizer currentrelease(VERSION,wxT("."));
427         long old01,old02,old03,new01,new02,new03;
428         newrelease.GetNextToken().ToLong(&new01);
429         currentrelease.GetNextToken().ToLong(&old01);
430         newrelease.GetNextToken().ToLong(&new02);
431         currentrelease.GetNextToken().ToLong(&old02);
432         newrelease.GetNextToken().ToLong(&new03);
433         currentrelease.GetNextToken().ToLong(&old03);
434         if ((new01*100)+(new02*10)+(new03) > (old01*100)+(old02*10)+(old03))
435         {
436             this->defaultstatusbarmessage = _("NEW RELEASE: ");
437             this->defaultstatusbarmessage += wxT("wxDownload Fast ");
438             this->defaultstatusbarmessage += programoptions.currentrelease + _(" is available.");
439         }
440         statusbar->SetStatusText(this->defaultstatusbarmessage);
441         if (programoptions.bandwidthoption == 1)
442         {
443             wxString temp = _("Band control");
444             temp += wxT(": ");
445             temp += _("Per Download");
446             statusbar->SetStatusText(temp,2);
447         }
448         else if (programoptions.bandwidthoption == 2)
449         {
450             wxString temp = _("Band control");
451             temp += wxT(": ");
452             temp += _("Active");
453             temp += wxT(" (") + MyUtilFunctions::int2wxstr(programoptions.bandwidth) + wxT(" kB/s)");
454             statusbar->SetStatusText(temp,2);
455         }
456         else
457         {
458             wxString temp = _("Band control");
459             temp += wxT(": ");
460             temp += _("Unlimited");
461             statusbar->SetStatusText(temp,2);
462         }
463     }
464 
465     //DEFINE THE PREVIEW PANEL TEXT
466     {
467         wxString contentstring =  _("File type");
468         contentstring += wxT(":\n");
469         XRCCTRL(*this, "lblpreview", wxStaticText )->SetLabel(contentstring);
470         XRCCTRL(*this, "btnpreview", wxButton )->SetLabel(_("Preview"));
471     }
472 
473     mtimer = new wxTimer(this, TIMER_ID);
474     timerinterval = 0;
475     writetimerinterval = 0;
476 
477     mtimer->Start(timerupdateinterval);
478 }
479 
OnIconize(wxIconizeEvent & event)480 void mMainFrame::OnIconize(wxIconizeEvent& event)
481 {
482     if ((wxGetApp().parameters->Found(wxT("notray"))))
483            event.Skip();
484     else
485     {
486         if ((event.Iconized()) && (taskbaricon->restoring == FALSE))
487         {
488             wxCommandEvent eventtmp;
489             taskbaricon->OnHide(eventtmp);
490         }
491     }
492 }
493 
~mMainFrame()494 mMainFrame::~mMainFrame()
495 {
496     wxSplitterWindow *splitter01 = XRCCTRL(*this, "splitter01",wxSplitterWindow);
497     wxSplitterWindow *splitter02 = XRCCTRL(*this, "splitter02",wxSplitterWindow);
498     if (splitter01->IsSplit())
499     {
500         mApplication::Configurations(WRITE,SEPARATOR01_REG,splitter01->GetSashPosition());
501         if (splitter01->IsSplit())
502             mApplication::Configurations(WRITE,SEPARATOR02_REG,splitter02->GetSashPosition());
503         mApplication::Configurations(WRITE,DETAILS_REG,TRUE);
504     }
505     else
506         mApplication::Configurations(WRITE,DETAILS_REG,FALSE);
507     if (!IsIconized())
508     {
509         int x,y,width,height,maximized;
510         GetSize(&width,&height);
511         GetPosition(&x,&y);
512         maximized = IsMaximized();
513         if (!maximized)
514         {
515             mApplication::Configurations(WRITE,SIZE_X_REG,width);
516             mApplication::Configurations(WRITE,SIZE_Y_REG,height);
517             mApplication::Configurations(WRITE,POS_X_REG,x);
518             mApplication::Configurations(WRITE,POS_Y_REG,y);
519         }
520         mApplication::Configurations(WRITE,MAXIMIZED_REG,maximized);
521     }
522 
523     delete taskbaricon;
524     delete mtimer;
525     delete imageslist;
526     delete menupopup;
527     //mutex_programoptions->Unlock();
528     //delete mutex_programoptions;
529 }
530 
OnTimer(wxTimerEvent & event)531 void mMainFrame::OnTimer(wxTimerEvent& event)
532 {
533     #ifndef DISABLE_MUTEX
534     if (mutex_programoptions->TryLock() != wxMUTEX_NO_ERROR)
535         return;
536     #endif
537     mInProgressList* list01 = XRCCTRL(*this, "inprogresslist",mInProgressList );
538     mFinishedList* list02 = XRCCTRL(*this, "finishedlist",mFinishedList );
539     int selection = list01->GetCurrentLastSelection();
540     int simultaneous = programoptions.simultaneous;
541     bool somedownloadfinishednow = FALSE,writeondisk = FALSE;
542     long currentspeed = 0;
543     int numberofactivedownloads = 0;
544     mDownloadFile *current;
545     #ifdef USE_HTML_MESSAGES
546     if ((selection < 0) && (*(XRCCTRL(*(this), "messages",wxHtmlWindow)->GetParser()->GetSource()) != wxEmptyString))
547         XRCCTRL(*(this), "messages",wxHtmlWindow)->SetPage(wxEmptyString);
548     #else
549     if ((selection < 0) && (XRCCTRL(*(this), "messages",wxTextCtrl)->GetValue() != wxEmptyString))
550         XRCCTRL(*(this), "messages",wxTextCtrl)->Clear();
551     #endif
552     if ((selection < 0) &&  (((int)XRCCTRL(*(this), "treemessages",wxTreeCtrl)->GetCount()) > 0))
553         XRCCTRL(*(this), "treemessages",wxTreeCtrl)->DeleteAllItems();
554     if ((selection < 0) && (programoptions.progressbarshow))
555         progressbar->SetParams(0,NULL);
556     writetimerinterval += mtimer->GetInterval();
557     if (writetimerinterval > 10000) //SAVE ALL DOWNLOAD STATUS ON DISK EVERY 10 SECONDS
558     {
559         writeondisk = TRUE;
560         writetimerinterval = 0;
561     }
562 
563     for ( mDownloadList::Node *node = wxGetApp().downloadlist.GetFirst(); node; node = node->GetNext() )
564     {
565         current = node->GetData();
566         if ((current->GetStatus() == STATUS_FINISHED) && (current->IsFree()))
567         {
568             if (current->GetCommand() != wxEmptyString)
569             {
570                 wxCommandEvent command(wxEVT_EXECUTE_COMMAND);
571                 command.SetString(current->GetCommand());
572                 GetEventHandler()->AddPendingEvent(command);
573             }
574             int i = list02->GetItemCount();
575             int index = wxGetApp().downloadlist.IndexOf(current);
576             mUrlName url(current->GetFirstUrl());
577             list02->InsertItem(i, wxEmptyString);
578             list02->SetItem(i, FINISHED_ICON01, wxEmptyString,current->GetStatus());
579             list02->SetItem(i, FINISHED_NAME, current->GetName());
580             list02->SetItem(i, FINISHED_SIZE, MyUtilFunctions::ByteString(current->totalsize));
581             list02->SetItem(i, FINISHED_END, current->GetFinishedDateTime().Format());
582             list02->SetItemData(i,current->GetFinishedDateTime().GetTicks());
583             current->RegisterListItemOnDisk();
584             if (index > 0)
585                 node = node->GetPrevious();  //GO TO THE PREVIOUS NODE BEFORE DELETE THE CURRENT ONE
586             wxGetApp().downloadlist.RemoveDownloadRegister(current);
587             list01->DeleteItem(index);
588             list01->SelectUnselect(FALSE,-1);
589             somedownloadfinishednow = TRUE;
590             if (index > 0)  //IF THIS IS THE FIRST NODE, WE CANN'T GO TO THE PREVIOUS ONE
591                 continue;
592             else
593                 break;
594         }
595         else
596         {
597             if (current->RemoveIsPending())
598             {
599                 int index = wxGetApp().downloadlist.IndexOf(current);
600                 node = node->GetPrevious();
601                 current->RemoveListItemFromDisk();
602                 wxGetApp().downloadlist.RemoveDownloadRegister(current);
603                 list01->DeleteItem(index);
604                 list01->SelectUnselect(FALSE,-1);
605                 if (index > 0)
606                     continue;
607                 else
608                     break;
609             }
610             int parts = 1;
611             if (current->IsSplitted())
612                 parts = current->GetNumberofParts();
613 
614             if ((current->WriteIsPending()) || (writeondisk))
615                 current->RegisterListItemOnDisk();
616 
617             //REFRESH THE LISTCTRL
618             if (UpdateListItemField(current)) //TRUE IF CHANGE SPEED, TIME, ETC
619             {
620                 //CALCULATE THE TOTAL SPEED
621                 currentspeed += current->totalspeed;
622             }
623 
624             if (current->GetStatus() == STATUS_ACTIVE)
625             {
626                 simultaneous--;
627                 numberofactivedownloads++;
628             }
629 
630             if (selection == wxGetApp().downloadlist.IndexOf(current))
631             {
632                 wxString contentstring = _("File type");
633                 contentstring += wxT(":\n") + current->GetContentType();
634                 XRCCTRL(*this, "lblpreview", wxStaticText )->SetLabel(contentstring);
635                 if (current->IsZip())
636                     XRCCTRL(*this, "btnpreview", wxButton )->Enable(TRUE);
637 
638                 long treeindex = 0;
639                 wxString piecestring = _("Piece ");
640                 if  (((int)XRCCTRL(*(this), "treemessages",wxTreeCtrl)->GetCount()) != parts)
641                 {
642                     wxTreeCtrl *tree = XRCCTRL(*(this), "treemessages",wxTreeCtrl);
643                     wxTreeItemId root;
644                     tree->DeleteAllItems();
645                     root = tree->AddRoot(wxEmptyString);
646                     for (int i=0;i<parts;i++)
647                         tree->AppendItem(root,piecestring + MyUtilFunctions::int2wxstr(i+1,2));
648                     treeindex = 0;
649                     tree->Refresh();
650                 }
651                 else
652                 {
653                     wxTreeCtrl *tree = XRCCTRL(*(this), "treemessages",wxTreeCtrl);
654                     wxTreeItemId treeitemid = tree->GetSelection();
655                     if (treeitemid.IsOk())
656                     {
657                         wxString text = tree->GetItemText(treeitemid);
658                         text.Mid(piecestring.Length()).ToLong(&treeindex);
659                         treeindex--;
660                         if ((treeindex < 0) || (treeindex >= parts))
661                             treeindex = 0;
662                     }
663                     else
664                         treeindex = 0;
665                 }
666 
667                 //SET PROGRESS BAR NEW PARAMETERS
668                 if (programoptions.progressbarshow)
669                 {
670                     if ((!current->IsSplitted()) && (current->GetStatus() == STATUS_ACTIVE))
671                         progressbar->SetParams(1,current->percentualparts);
672                     else
673                         progressbar->SetParams(current->GetNumberofParts(),current->percentualparts);
674                 }
675 
676                 #ifdef USE_HTML_MESSAGES
677                 if  (*(XRCCTRL(*(this), "messages",wxHtmlWindow)->GetParser()->GetSource()) != current->messages[treeindex])
678                 {
679                     int x,y,xx,yy;
680                     XRCCTRL(*(this), "messages",wxHtmlWindow)->SetPage(wxEmptyString);
681                     XRCCTRL(*(this), "messages",wxHtmlWindow)->AppendToPage(current->messages[treeindex]);
682                     XRCCTRL(*(this), "messages",wxHtmlWindow)->GetScrollPixelsPerUnit(&x,&y);
683                     XRCCTRL(*(this), "messages",wxHtmlWindow)->GetVirtualSize(&xx,&yy);
684                     xx /= x;
685                     yy /= y;
686                     XRCCTRL(*(this), "messages",wxHtmlWindow)->Scroll(-1,yy);
687                 }
688 
689                 #else
690                 if  (XRCCTRL(*(this), "messages",wxTextCtrl)->GetValue() != current->messages[treeindex])
691                 {
692                     XRCCTRL(*(this), "messages",wxTextCtrl)->Clear();
693                     XRCCTRL(*(this), "messages",wxTextCtrl)->SetValue(current->messages[treeindex]);
694                     XRCCTRL(*(this), "messages",wxTextCtrl)->ShowPosition(current->messages[treeindex].Length()-200);
695 
696                 }
697                    #endif
698             }
699         }
700     }
701     wxGetApp().downloadlist.SetNumberofActiveDownloads(numberofactivedownloads);
702 
703     if (programoptions.scheduleexceptionschanged)
704     {
705         programoptions.scheduleexceptionschanged = FALSE;
706         for (int i=0;i<MAX_SCHEDULE_EXCEPTIONS;i++)
707         {
708             if (programoptions.scheduleexceptions[i].newstart != wxEmptyString)
709             {
710                 programoptions.scheduleexceptions[i].start = programoptions.scheduleexceptions[i].newstart;
711                 programoptions.scheduleexceptions[i].finish = programoptions.scheduleexceptions[i].newfinish;
712                 programoptions.scheduleexceptions[i].day = programoptions.scheduleexceptions[i].newday;
713                 programoptions.scheduleexceptions[i].isactive = TRUE;
714             }
715             else
716                 programoptions.scheduleexceptions[i].isactive = FALSE;
717         }
718     }
719 
720     if (programoptions.activatescheduling)
721     {
722         wxDateTime now = wxDateTime::Now();
723         wxDateTime exceptionstart,exceptionfinish;
724         long hour,minute;
725         bool stopscheduled = FALSE;
726         bool exceptionhappened = FALSE;
727 
728         if ((now > programoptions.startdatetime) && (now < programoptions.finishdatetime))
729         {
730             for (int i = 0;i < MAX_SCHEDULE_EXCEPTIONS;i++)
731             {
732                 if ((programoptions.scheduleexceptions[i].day == now.GetWeekDay()) && (programoptions.scheduleexceptions[i].isactive))
733                 {
734                     programoptions.scheduleexceptions[i].start.Mid(0,2).ToLong(&hour);
735                     programoptions.scheduleexceptions[i].start.Mid(3,2).ToLong(&minute);
736                     exceptionstart.Set(hour,minute);
737                     programoptions.scheduleexceptions[i].finish.Mid(0,2).ToLong(&hour);
738                     programoptions.scheduleexceptions[i].finish.Mid(3,2).ToLong(&minute);
739                     exceptionfinish.Set(hour,minute);
740                     if ((now > exceptionstart) && (now < exceptionfinish))
741                     {
742                         stopscheduled = TRUE;
743                         exceptionhappened = TRUE;
744                         break;
745                     }
746                 }
747             }
748 
749             if ((simultaneous > 0) && (!stopscheduled))
750             {
751                 for ( mDownloadList::Node *node = wxGetApp().downloadlist.GetFirst(); node; node = node->GetNext() )
752                 {
753                     current = node->GetData();
754                     if (current->GetStatus() == STATUS_SCHEDULE_QUEUE)
755                     {
756                         if (StartDownload(current))
757                         {
758                             simultaneous--;
759                             if (simultaneous <= 0)
760                                 break;
761                         }
762                     }
763                 }
764             }
765         }
766         else
767             stopscheduled = TRUE;
768         if (stopscheduled)
769         {
770             mInProgressList *list = XRCCTRL(*this, "inprogresslist",mInProgressList );
771             if (now > programoptions.finishdatetime)
772                 programoptions.activatescheduling = FALSE;
773             for ( mDownloadList::Node *node = wxGetApp().downloadlist.GetFirst(); node; node = node->GetNext() )
774             {
775                 current = node->GetData();
776                 if ((current->GetStatus() == STATUS_ACTIVE) && (current->IsScheduled()))
777                 {
778                     list->SetCurrentSelection(wxGetApp().downloadlist.IndexOf(current));
779                     StopDownload(current,FALSE); //STOP BUT DON'T CHANGE THE SCHEDULE
780                     if (!exceptionhappened)
781                         somedownloadfinishednow = TRUE;
782                 }
783             }
784         }
785     }
786     if (simultaneous > 0)
787     {
788         for ( mDownloadList::Node *node = wxGetApp().downloadlist.GetFirst(); node; node = node->GetNext() )
789         {
790             current = node->GetData();
791             if ((current->GetStatus() == STATUS_QUEUE) && (!current->IsScheduled()))
792             {
793                 if (StartDownload(current))
794                 {
795                     simultaneous--;
796                     if (simultaneous <= 0)
797                         break;
798                 }
799             }
800         }
801     }
802     if (somedownloadfinishednow)
803     {
804         bool somedownloadactive = FALSE;
805         for ( mDownloadList::Node *node = wxGetApp().downloadlist.GetFirst(); node; node = node->GetNext() )
806         {
807             current = node->GetData();
808             if ((current->GetStatus() == STATUS_ACTIVE) || ((current->GetStatus() == STATUS_SCHEDULE_QUEUE) && (programoptions.activatescheduling)))
809                 somedownloadactive = TRUE;
810         }
811         if (!somedownloadactive)
812         {
813             if (programoptions.restoremainframe)
814             {
815                 if (!this->IsShown())
816                 {
817                     wxCommandEvent iconizeevent;
818                     taskbaricon->OnHide(iconizeevent);
819                 }
820             }
821             if (programoptions.shutdown)
822             {
823                 wxCommandEvent shutdown(wxEVT_SHUTDOWN);
824                 GetEventHandler()->AddPendingEvent(shutdown);
825             }
826             else if (programoptions.disconnect)
827             {
828                 wxCommandEvent disconnect(wxEVT_DISCONNECT);
829                 GetEventHandler()->AddPendingEvent(disconnect);
830             }
831         }
832     }
833     if (timerinterval >= (programoptions.graphrefreshtime))
834     {
835         float *value = new float();
836         wxString msg,temp;
837         *value = ((float)currentspeed) / 1024.0;
838         graphpoints.Append(value);
839 
840         msg = _("Total Speed:");
841         msg += wxT(" %0.1f kB/s");
842         temp.Printf(msg, *value);
843         temp.Replace(wxT(","),wxT("."));
844         if (statusbar)
845             statusbar->SetStatusText(temp,1);
846 
847         if (graphpoints.GetCount() > (unsigned int)programoptions.graphhowmanyvalues)
848             graphpoints.DeleteNode(graphpoints.GetFirst());
849 
850         timerinterval = 0;
851         if (this->IsShown())
852         {
853             #ifndef DISABLE_MUTEX
854             mutex_programoptions->Unlock();
855             #endif
856 
857             //REFRESH THE GRAPH
858             if (programoptions.graphshow)
859                 graph->Refresh();
860 
861             //REFRESH THE PROGRESS BAR
862             if (programoptions.progressbarshow)
863                 progressbar->Refresh();
864         }
865     }
866     timerinterval += mtimer->GetInterval();
867     #ifndef DISABLE_MUTEX
868     mutex_programoptions->Unlock();
869     #endif
870 }
871 
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)872 bool mMainFrame::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)
873 {
874     mBoxNew dlg;
875     wxTextCtrl *edturl, *edtdestination, *edtuser ,*edtpassword, *edtreferenceurl, *edtcomments, *edtcommand;
876     wxCheckListBox *lstaddresslist;
877     wxSpinCtrl *spinsplit, *spinbandwidth;
878     wxRadioButton *optnow,*optschedule;
879     wxCheckBox *chkaddontop;
880     int result;
881     int i;
882     wxXmlResource::Get()->LoadDialog(&dlg, this, wxT("boxnew"));
883 
884     edturl = XRCCTRL(dlg, "edturl",wxTextCtrl);
885     edtdestination = XRCCTRL(dlg, "edtdestination",wxTextCtrl);
886     edtuser = XRCCTRL(dlg, "edtuser",wxTextCtrl);
887     edtpassword = XRCCTRL(dlg, "edtpassword",wxTextCtrl);
888     edtreferenceurl = XRCCTRL(dlg, "edtreferenceurl",wxTextCtrl);
889     edtcommand = XRCCTRL(dlg, "edtcommand",wxTextCtrl);
890     edtcomments = XRCCTRL(dlg, "edtcomments",wxTextCtrl);
891     lstaddresslist = XRCCTRL(dlg, "lstaddresslist",wxCheckListBox);
892     optnow = XRCCTRL(dlg, "optnow",wxRadioButton);
893     optschedule = XRCCTRL(dlg, "optschedule",wxRadioButton);
894     spinsplit = XRCCTRL(dlg, "spinsplit",wxSpinCtrl);
895     spinbandwidth = XRCCTRL(dlg, "spinbandwidth",wxSpinCtrl);
896     chkaddontop = XRCCTRL(dlg, "chkaddontop",wxCheckBox);
897 
898     lstaddresslist->Clear();
899     if ((url.GetCount() == 1) && (show))
900         edturl->SetValue(url.Item(0));
901     else
902     {
903         lstaddresslist->InsertItems(url,0);
904         for (unsigned int i = 0; i < lstaddresslist->GetCount() ;i++)
905             lstaddresslist->Check(i);
906     }
907     #if wxCHECK_VERSION(2, 8, 0)
908     dlg.SetInitialSize();
909     #else
910     dlg.SetBestFittingSize();
911     #endif
912     dlg.SetDifferentNamesPermition(permitdifferentnames);
913     edtdestination->SetValue(destination);
914     /*if (user == ANONYMOUS_USER)
915     {
916         edtuser->SetValue(wxEmptyString);
917         edtpassword->SetValue(wxEmptyString);
918     }
919     else
920     {*/
921     edtuser->SetValue(user);
922     edtpassword->SetValue(password);
923     edtreferenceurl->SetValue(reference);
924     edtcommand->SetValue(command);
925     edtcomments->SetValue(comments);
926     if (startoption == NOW)
927         optnow->SetValue(TRUE);
928     else
929         optnow->SetValue(FALSE);
930     chkaddontop->SetValue(ontop);
931     spinsplit->SetValue(parts);
932     if (show)
933     {
934         this->active = FALSE;
935         dlg.SetSize(programoptions.boxnew_x,programoptions.boxnew_y,-1,-1);
936         result = dlg.ShowModal();
937         dlg.GetPosition(&programoptions.boxnew_x,&programoptions.boxnew_y);
938         this->active = TRUE;
939     }
940     else
941         result = XRCID("btnok");
942 
943     if (result == XRCID("btnok"))
944     {
945         wxFileName destinationvalue,tempdestinationvalue;
946         mDownloadFile *currentfile = NULL;
947         int scheduled, now,forindex;
948         int nparams = lstaddresslist->GetCount();
949         int bandwidth = spinbandwidth->GetValue();
950         wxString name = wxEmptyString;
951         scheduled = optschedule->GetValue();
952         now = optnow->GetValue();
953         ontop = chkaddontop->GetValue();
954 
955         destinationvalue.Assign(edtdestination->GetValue());
956         tempdestinationvalue.Assign(programoptions.downloadpartsdefaultdir);
957         if (nparams == 0)
958             return FALSE;
959 
960         for (i = 0; i < nparams; i++)
961         {
962             if (ontop)
963                 forindex = nparams-i-1;
964             else
965                 forindex = i;
966             if (!lstaddresslist->IsChecked(forindex))
967                 continue;
968 
969             mUrlName *urltmp = new mUrlName(lstaddresslist->GetString(forindex));
970 
971             if (name.IsEmpty())
972                 name = urltmp->GetFullName();
973             if ((!permitdifferentnames) && (name != urltmp->GetFullName()))
974                 continue;
975 
976             currentfile = wxGetApp().downloadlist.FindDownloadFile(urltmp->GetFullName());
977 
978             if (!currentfile)
979             {
980                 mUrlList *urllist = new mUrlList();
981                 urllist->Append(urltmp);
982                 currentfile = wxGetApp().downloadlist.NewDownloadRegister(urllist,destinationvalue, tempdestinationvalue,metalinkindex,spinsplit->GetValue(),
983                         edtuser->GetValue(), edtpassword->GetValue(), edtreferenceurl->GetValue(), edtcomments->GetValue(),edtcommand->GetValue(),scheduled,bandwidth,ontop);
984                 XRCCTRL(*this, "inprogresslist",mInProgressList )->Insert(currentfile,-1,ontop);
985             }
986             else
987             {
988                 if (!currentfile->FindUrl(*urltmp))
989                     currentfile->AppendUrl(urltmp);
990                 continue;
991             }
992 
993             if (now)
994             {
995                 currentfile->PutOnQueue();
996                 if (programoptions.hidemainframe) //HIDE THE MAINFRAME
997                 {
998                     wxIconizeEvent iconizeevent;
999                     this->OnIconize(iconizeevent);
1000                 }
1001             }
1002             else if (scheduled)
1003                 currentfile->PutOnScheduleQueue();
1004         }
1005         //SET THE LAST BOXNEW OPTIONS LIKE THE DEFAULT ONE
1006         programoptions.lastnumberofparts = spinsplit->GetValue();
1007         if (scheduled)
1008             programoptions.laststartoption = SCHEDULE;
1009         else if (now)
1010             programoptions.laststartoption = NOW;
1011         else
1012             programoptions.laststartoption = MANUAL;
1013         programoptions.lastdestination = edtdestination->GetValue();
1014         programoptions.lastcommand = edtcommand->GetValue();
1015         programoptions.lastontopoption = chkaddontop->GetValue();
1016 
1017         //WRITE THE LAST BOXNEW OPTIONS ON DISK
1018         mApplication::Configurations(WRITE,OPT_LAST_BOXNEW_X_REG, programoptions.boxnew_x);
1019         mApplication::Configurations(WRITE,OPT_LAST_BOXNEW_Y_REG, programoptions.boxnew_y);
1020         mApplication::Configurations(WRITE,OPT_LAST_COMMAND_REG, programoptions.lastcommand);
1021         mApplication::Configurations(WRITE,OPT_LAST_DESTINATION_REG, programoptions.lastdestination);
1022         mApplication::Configurations(WRITE,OPT_LAST_NUMBER_OF_PARTS_REG, programoptions.lastnumberofparts);
1023         mApplication::Configurations(WRITE,OPT_LAST_START_OPTION_REG, programoptions.laststartoption);
1024         mApplication::Configurations(WRITE,OPT_LAST_ONTOP_OPTION_REG, programoptions.lastontopoption);
1025     }
1026     return TRUE;
1027 }
1028 
OnNew(wxCommandEvent & event)1029 void mMainFrame::OnNew(wxCommandEvent& event)
1030 {
1031     OnPasteURL(event);
1032 }
1033 
OnRemove(wxCommandEvent & event)1034 void mMainFrame::OnRemove(wxCommandEvent& event)
1035 {
1036     mInProgressList *inprogresslist = XRCCTRL(*this, "inprogresslist",mInProgressList );
1037     if (inprogresslist->GetCurrentSelection().GetCount() > 0)
1038     {
1039         mListSelection currentselectionlist = inprogresslist->GetCurrentSelection();
1040         int nselection = currentselectionlist.GetCount();
1041         mDownloadFile *currentfile;
1042 
1043         wxProgressDialog *waitbox = new wxProgressDialog(_("Stopping the download..."),_("Stopping the current download before removing..."));
1044         for (int i = 0; i < nselection;i++)
1045         {
1046             currentfile = wxGetApp().downloadlist.Item(currentselectionlist.Item(i))->GetData();
1047             StopDownload(currentfile); //STOP AND SET SCHEDULE = FALSE
1048             while ((currentfile->IsFree() == FALSE) || (currentfile->GetStatus() == STATUS_ACTIVE))
1049                 wxYield();
1050             waitbox->Update(100*(i+1)/nselection);
1051         }
1052         waitbox->Update(100);
1053         delete waitbox;
1054 
1055         wxMessageDialog *dlg = new wxMessageDialog(this, _("Do you also want to remove the partial downloaded file from the disk?"),_("Remove..."),
1056                     wxYES_NO | wxCANCEL | wxICON_QUESTION);
1057 
1058         if (dlg)
1059         {
1060             int resp;
1061             dlg->Centre(wxBOTH);
1062             this->active = FALSE;
1063             resp = dlg->ShowModal();
1064             this->active = TRUE;
1065             for (int i = nselection-1 ; i >= 0 ;i--) //REMOVE THE ITEM BACKWARD
1066             {
1067                 currentfile = wxGetApp().downloadlist.Item(currentselectionlist.Item(i))->GetData();
1068                 if (((currentfile->GetStatus() == STATUS_STOPED) || (currentfile->GetStatus() == STATUS_ERROR)) && (currentfile->IsFree()))
1069                 {
1070                     if (resp == wxID_YES)
1071                     {
1072                         wxString destination = currentfile->GetDestination();
1073                         wxString name = currentfile->GetName();
1074                         currentfile->MarkRemoveAsPending(TRUE);
1075                         if (destination.Mid(destination.Length()-1,1) != SEPARATOR_DIR)
1076                             destination = destination + SEPARATOR_DIR;
1077                         for (int i = 0; i< MAX_NUM_PARTS;i++)
1078                             ::wxRemoveFile(destination + PREFIX + name + EXT + MyUtilFunctions::int2wxstr(i));
1079                     }
1080                     else if (resp == wxID_NO)
1081                     {
1082                         currentfile->MarkRemoveAsPending(TRUE);
1083                     }
1084                 }
1085             }
1086             dlg->Destroy();
1087         }
1088         return ;
1089     }
1090     mFinishedList *finishedlist = XRCCTRL(*this, "finishedlist",mFinishedList );
1091     if (finishedlist->GetCurrentSelection().GetCount() > 0)
1092     {
1093         wxMessageDialog *dlg = new wxMessageDialog(this, _("Do you also want to remove downloaded file(s) from the disk?"),_("Remove..."),
1094                     wxYES_NO | wxCANCEL | wxICON_QUESTION);
1095         if (dlg)
1096         {
1097             int resp;
1098             int currentselection;
1099             dlg->Centre(wxBOTH);
1100             this->active = FALSE;
1101             resp = dlg->ShowModal();
1102             this->active = TRUE;
1103             mListSelection currentselectionlist = finishedlist->GetCurrentSelection();
1104             #ifdef WXDFAST_PORTABLE
1105             wxFileConfig *config = new wxFileConfig(DFAST_REG, wxEmptyString, DFAST_REG + wxT(".ini"), wxEmptyString,
1106                                             wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_RELATIVE_PATH);
1107             #else
1108             wxFileConfig *config = new wxFileConfig(DFAST_REG);
1109             #endif
1110             config->SetPath(FINISHED_REG);
1111             int nselection = currentselectionlist.GetCount();
1112             for (int i = nselection-1 ; i >= 0 ;i--) //REMOVE THE ITEM BACKWARD
1113             {
1114                 currentselection = currentselectionlist.Item(i);
1115                 if (resp != wxID_CANCEL)
1116                 {
1117                     wxString destination,name;
1118                     if (destination.Mid(destination.Length()-1,1) != SEPARATOR_DIR)
1119                         destination = destination + SEPARATOR_DIR;
1120 
1121                     wxListItem item;
1122                     item.SetId(currentselection);
1123                     item.SetColumn(FINISHED_NAME);
1124                     item.SetMask(wxLIST_MASK_DATA|wxLIST_MASK_STATE|wxLIST_MASK_TEXT|wxLIST_MASK_IMAGE);
1125                     finishedlist->GetItem(item);
1126 
1127                     config->SetPath(item.GetText());
1128 
1129                     destination = wxEmptyString;
1130                     config->Read(DESTINATION_REG,&destination);
1131                     #ifdef WXDFAST_PORTABLE
1132                     {
1133                         #ifdef __WXMSW__
1134                         wxFileName destinationtmp(destination);
1135                         if (destinationtmp.GetVolume().Upper() == wxT("PORTABLE"))
1136                         {
1137                             destinationtmp.SetVolume(wxGetApp().programvolume);
1138                             destination = destinationtmp.GetFullPath();
1139                         }
1140                         #endif
1141                     }
1142                     #endif
1143                     if (destination.Mid(destination.Length()-1,1) != SEPARATOR_DIR)
1144                         destination = destination + SEPARATOR_DIR;
1145 
1146                     name = wxEmptyString;
1147                     config->Read(NAME_REG,&name);
1148 
1149                     config->SetPath(BACK_DIR_REG);
1150                     config->DeleteGroup(item.GetText());
1151                     finishedlist->DeleteItem(currentselection);
1152 
1153                     if (resp == wxID_YES)
1154                         ::wxRemoveFile(destination + name);
1155                 }
1156             }
1157             delete config;
1158         }
1159     }
1160 }
1161 
OnSchedule(wxCommandEvent & event)1162 void mMainFrame::OnSchedule(wxCommandEvent& event)
1163 {
1164     mInProgressList *list = XRCCTRL(*this, "inprogresslist",mInProgressList );
1165     if (list->GetCurrentSelection().GetCount() > 0)
1166     {
1167         mListSelection selectionlist = list->GetCurrentSelection();
1168         mDownloadFile *file;
1169         int status;
1170         for (unsigned int i = 0; i < selectionlist.GetCount();i++)
1171         {
1172             file = wxGetApp().downloadlist.Item(selectionlist.Item(i))->GetData();
1173             status = file->GetStatus();
1174             if (((status == STATUS_STOPED) || (status == STATUS_QUEUE) || (status == STATUS_ERROR)) && (file->IsFree()))
1175             {
1176                 file->PutOnScheduleQueue();
1177                 file->MarkWriteAsPending(TRUE);
1178             }
1179         }
1180     }
1181 }
1182 
OnStart(wxCommandEvent & event)1183 void mMainFrame::OnStart(wxCommandEvent& event)
1184 {
1185     mInProgressList *list = XRCCTRL(*this, "inprogresslist",mInProgressList );
1186     if (list->GetCurrentSelection().GetCount() > 0)
1187     {
1188         mListSelection selectionlist = list->GetCurrentSelection();
1189         mDownloadFile *file;
1190         int status;
1191         for (unsigned int i = 0; i < selectionlist.GetCount();i++)
1192         {
1193             file = wxGetApp().downloadlist.Item(selectionlist.Item(i))->GetData();
1194             status = file->GetStatus();
1195             if (((status == STATUS_STOPED) || (status == STATUS_ERROR)) && (file->IsFree()))
1196             {
1197                 file->PutOnQueue();
1198                 file->MarkWriteAsPending(TRUE);
1199                 if (programoptions.hidemainframe) //HIDE THE MAINFRAME
1200                 {
1201                     wxIconizeEvent iconizeevent;
1202                     this->OnIconize(iconizeevent);
1203                 }
1204             }
1205         }
1206     }
1207 }
1208 
StartDownload(mDownloadFile * downloadfile)1209 bool mMainFrame::StartDownload(mDownloadFile *downloadfile)
1210 {
1211     if (downloadfile->IsFree())
1212     {
1213         if ((programoptions.checkforupdates) && ((wxDateTime::Now()-programoptions.lastnewreleasecheck).GetDays() >= 10))
1214         {
1215             programoptions.lastnewreleasecheck = wxDateTime::Now();
1216             mApplication::Configurations(WRITE,OPT_LAST_NEW_RELEASE_CHECK,programoptions.lastnewreleasecheck.GetTicks());
1217             CheckNewRelease();
1218         }
1219         downloadfile->SetFree(FALSE);
1220         downloadfile->WaitSplit();
1221         downloadfile->speedpointowner = -1;
1222         for (int i=0; i < downloadfile->GetNumberofParts();i++)
1223         {
1224             mDownloadThread *thread = new mDownloadThread(downloadfile,i);
1225             if ( thread->Create() != wxTHREAD_NO_ERROR )
1226             {
1227                 wxMessageBox(_("Error creating thread!"),_("Error...") ,wxOK | wxICON_ERROR,this);
1228                 return FALSE;
1229             }
1230             else
1231             {
1232                 wxCriticalSectionLocker enter(wxGetApp().m_critsect);
1233                 if ( thread->Run() != wxTHREAD_NO_ERROR )
1234                 {
1235                     wxMessageBox(_("Error starting thread!"),_("Error...") ,wxOK | wxICON_ERROR,this);
1236                     return FALSE;
1237                 }
1238             }
1239         }
1240         Refresh();
1241         return TRUE;
1242     }
1243     return FALSE;
1244 }
1245 
OnStop(wxCommandEvent & event)1246 void mMainFrame::OnStop(wxCommandEvent& event)
1247 {
1248     mInProgressList *list = XRCCTRL(*this, "inprogresslist",mInProgressList );
1249     mListSelection currentselectionlist = list->GetCurrentSelection();
1250     if (currentselectionlist.GetCount() > 0)
1251     {
1252         int status;
1253         mDownloadFile *file;
1254         for (unsigned int i = 0; i < currentselectionlist.GetCount();i++)
1255         {
1256             file = wxGetApp().downloadlist.Item(currentselectionlist.Item(i))->GetData();
1257             status = file->GetStatus();
1258             StopDownload(file); //STOP AND SET SCHEDULE = FALSE
1259             if ((status == STATUS_QUEUE) || (status == STATUS_SCHEDULE_QUEUE)) //WHEN THE DOWNLOAD IS ALREADY ACTIVE
1260                 file->MarkWriteAsPending(TRUE);                                //THE WRITE ON DISK WILL BE MADE IN THE TIMER
1261         }
1262     }
1263 }
1264 
StopDownload(mDownloadFile * downloadfile,bool stopschedule)1265 void mMainFrame::StopDownload(mDownloadFile *downloadfile,bool stopschedule)
1266 {
1267     if ((downloadfile->GetStatus() != STATUS_FINISHED) && (downloadfile->GetStatus() != STATUS_ERROR))
1268         downloadfile->SetAsStoped(stopschedule);
1269 }
1270 
OnStartAll(wxCommandEvent & event)1271 void mMainFrame::OnStartAll(wxCommandEvent& event)
1272 {
1273     mInProgressList *list = XRCCTRL(*this, "inprogresslist",mInProgressList );
1274     wxProgressDialog *waitbox = new wxProgressDialog(_("Starting the downloads..."),_("Starting the downloads..."),100,NULL,wxPD_AUTO_HIDE | wxPD_APP_MODAL|wxPD_CAN_ABORT|wxPD_ELAPSED_TIME);
1275     int total = list->GetItemCount();
1276     for (int i=0 ; i < total;i++)
1277     {
1278         list->SetCurrentSelection(i);
1279         OnStart(event);
1280         waitbox->Update((int)(i*100/total));
1281     }
1282     waitbox->Update(100);
1283     delete waitbox;
1284     wxMilliSleep(200);
1285 }
1286 
OnStopAll(wxCommandEvent & event)1287 void mMainFrame::OnStopAll(wxCommandEvent& event)
1288 {
1289     mDownloadFile *currentfile;
1290     mInProgressList *list = XRCCTRL(*this, "inprogresslist",mInProgressList );
1291     wxProgressDialog *waitbox = new wxProgressDialog(_("Stopping the downloads..."),_("Stopping the downloads..."),100,NULL,wxPD_AUTO_HIDE | wxPD_APP_MODAL|wxPD_CAN_ABORT|wxPD_ELAPSED_TIME);
1292     int total = list->GetItemCount();
1293     for (int i=0 ; i < total;i++)
1294     {
1295         list->SetCurrentSelection(i);
1296         if (event.GetString() == STOPWITHOUTSAVINGSTOPSTATUS)
1297             StopDownload(wxGetApp().downloadlist.Item(i)->GetData()); //STOP AND DON'T CARE ABOUT SCHEDULE
1298         else
1299             OnStop(event);
1300     }
1301     for (int i=0 ; i < total;i++)
1302     {
1303         currentfile = wxGetApp().downloadlist.Item(i)->GetData();
1304         while ((!currentfile->IsFree()) && (waitbox->Update((int)(i*100/total))))
1305         {
1306             wxYield();
1307             wxMilliSleep(200);
1308         }
1309     }
1310     waitbox->Update(100);
1311     delete waitbox;
1312     wxMilliSleep(200);
1313 }
1314 
OnPasteURL(wxCommandEvent & event)1315 void mMainFrame::OnPasteURL(wxCommandEvent& event)
1316 {
1317     int numberofparts, startoption;
1318     bool ontop;
1319     wxString destinationtmp = wxEmptyString, command = wxEmptyString;
1320     wxArrayString urltmp;
1321     if (wxTheClipboard->Open())
1322     {
1323         if (wxTheClipboard->IsSupported( wxDF_TEXT ))
1324         {
1325             wxTextDataObject data;
1326             wxTheClipboard->GetData( data );
1327             mUrlName url(data.GetText().Strip(wxString::both));
1328             if (url.IsComplete())
1329                 urltmp.Add(url.GetFullPath());
1330         }
1331         wxTheClipboard->Close();
1332     }
1333 
1334     if (programoptions.rememberboxnewoptions)
1335     {
1336         numberofparts = programoptions.lastnumberofparts;
1337         startoption = programoptions.laststartoption;
1338         destinationtmp = programoptions.lastdestination;
1339         command = programoptions.lastcommand;
1340         ontop = programoptions.lastontopoption;
1341     }
1342     else
1343     {
1344         numberofparts = DEFAULT_NUM_PARTS;
1345         startoption = DEFAULT_START_OPTION;
1346         ontop = DEFAULT_ONTOP_OPTION;
1347         destinationtmp = programoptions.destination;
1348     }
1349     NewDownload(urltmp,destinationtmp,-1,numberofparts,wxEmptyString,wxEmptyString,wxEmptyString,wxEmptyString,command,startoption,ontop,TRUE,FALSE);
1350 }
1351 
OnCopyURL(wxCommandEvent & event)1352 void mMainFrame::OnCopyURL(wxCommandEvent& event)
1353 {
1354     wxString urltmp,destinationtmp;
1355     if (wxTheClipboard->Open())
1356     {
1357         #ifdef WXDFAST_PORTABLE
1358         wxFileConfig *config = new wxFileConfig(DFAST_REG, wxEmptyString, DFAST_REG + wxT(".ini"), wxEmptyString,
1359                                                 wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_RELATIVE_PATH);
1360         #else
1361         wxFileConfig *config = new wxFileConfig(DFAST_REG);
1362         #endif
1363         wxString str,name;
1364         wxTextDataObject data;
1365         int currentselection,column;
1366         wxListCtrl *list;
1367         mInProgressList *list01 = XRCCTRL(*(wxGetApp().mainframe), "inprogresslist",mInProgressList );
1368         mFinishedList *list02 = XRCCTRL(*(wxGetApp().mainframe), "finishedlist",mFinishedList);
1369         if ((currentselection = list01->GetCurrentLastSelection()) >= 0)
1370         {
1371             list01->SetCurrentSelection(currentselection);
1372             config->SetPath(INPROGRESS_REG);
1373             column = INPROGRESS_NAME;
1374             list = (wxListCtrl*)list01;
1375         }
1376         else if ((currentselection = list02->GetCurrentLastSelection()) >= 0)
1377         {
1378             list02->SetCurrentSelection(currentselection);
1379             config->SetPath(FINISHED_REG);
1380             column = FINISHED_NAME;
1381             list = (wxListCtrl*)list02;
1382         }
1383         else
1384         {
1385             wxTheClipboard->Close();
1386             return;
1387         }
1388 
1389         if (column == INPROGRESS_NAME)
1390             name = wxGetApp().downloadlist.Item(currentselection)->GetData()->GetName();
1391         else
1392         {
1393             wxListItem item;
1394             item.SetId(currentselection);
1395             item.SetColumn(column);
1396             item.SetMask(wxLIST_MASK_DATA|wxLIST_MASK_STATE|wxLIST_MASK_TEXT|wxLIST_MASK_IMAGE);
1397             list->GetItem(item);
1398             name = item.GetText();
1399         }
1400         config->SetPath(name);
1401         str = wxEmptyString;
1402         config->Read(URL_REG + wxT("1"),&str);
1403         wxTheClipboard->SetData( new wxTextDataObject(str));
1404         wxTheClipboard->Close();
1405         delete config;
1406     }
1407     else
1408         wxMessageBox(_("Unable to open the clipboard!"),_("Error...") ,wxOK | wxICON_ERROR,this);
1409 }
1410 
OnCopyDownloadData(wxCommandEvent & event)1411 void mMainFrame::OnCopyDownloadData(wxCommandEvent& event)
1412 {
1413     wxString urltmp,destinationtmp;
1414     if (wxTheClipboard->Open())
1415     {
1416         #ifdef WXDFAST_PORTABLE
1417         wxFileConfig *config = new wxFileConfig(DFAST_REG, wxEmptyString, DFAST_REG + wxT(".ini"), wxEmptyString,
1418                                                 wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_RELATIVE_PATH);
1419         #else
1420         wxFileConfig *config = new wxFileConfig(DFAST_REG);
1421         #endif
1422         wxString str = wxEmptyString, downloadinfo = wxEmptyString, name;
1423         wxTextDataObject data;
1424         int currentselection,column;
1425         wxListCtrl *list;
1426         mInProgressList *list01 = XRCCTRL(*(wxGetApp().mainframe), "inprogresslist",mInProgressList );
1427         mFinishedList *list02 = XRCCTRL(*(wxGetApp().mainframe), "finishedlist",mFinishedList);
1428         if ((currentselection = list01->GetCurrentLastSelection()) >= 0)
1429         {
1430             list01->SetCurrentSelection(currentselection);
1431             config->SetPath(INPROGRESS_REG);
1432             column = INPROGRESS_NAME;
1433             list = (wxListCtrl*)list01;
1434         }
1435         else if ((currentselection = list02->GetCurrentLastSelection()) >= 0)
1436         {
1437             list02->SetCurrentSelection(currentselection);
1438             config->SetPath(FINISHED_REG);
1439             column = FINISHED_NAME;
1440             list = (wxListCtrl*)list02;
1441         }
1442         else
1443         {
1444             wxTheClipboard->Close();
1445             return;
1446         }
1447 
1448         if (column == INPROGRESS_NAME)
1449             name = wxGetApp().downloadlist.Item(currentselection)->GetData()->GetName();
1450         else
1451         {
1452             wxListItem item;
1453             item.SetId(currentselection);
1454             item.SetColumn(column);
1455             item.SetMask(wxLIST_MASK_DATA|wxLIST_MASK_STATE|wxLIST_MASK_TEXT|wxLIST_MASK_IMAGE);
1456             list->GetItem(item);
1457             name = item.GetText();
1458         }
1459         config->SetPath(name);
1460 
1461         downloadinfo += _("Name");
1462         downloadinfo += wxT(": ") + name + wxT("\n");
1463 
1464         str = wxEmptyString;
1465         config->Read(CONTENTTYPE_REG,&str);
1466         downloadinfo += _("File type");
1467         downloadinfo += wxT(": ") + str + wxT("\n");
1468 
1469         str = wxEmptyString;
1470         config->Read(SIZE_REG,&str);
1471         downloadinfo += _("Size");
1472         downloadinfo += wxT(": ") + MyUtilFunctions::ByteString(MyUtilFunctions::wxstrtolonglong(str)) + wxT("\n");
1473 
1474         str = wxEmptyString;
1475         config->Read(TIMEPASSED_REG,&str);
1476         downloadinfo += _("Time");
1477         downloadinfo += wxT(": ") + MyUtilFunctions::TimeString(MyUtilFunctions::wxstrtolonglong(str)) + wxT("\n");
1478 
1479         str = wxEmptyString;
1480         config->Read(DESTINATION_REG,&str);
1481         #ifdef WXDFAST_PORTABLE
1482         {
1483             #ifdef __WXMSW__
1484             wxFileName destinationtmp(str);
1485             if (destinationtmp.GetVolume().Upper() == wxT("PORTABLE"))
1486             {
1487                 destinationtmp.SetVolume(wxGetApp().programvolume);
1488                 str = destinationtmp.GetFullPath();
1489             }
1490             #endif
1491         }
1492         #endif
1493         downloadinfo += _("Destination");
1494         downloadinfo += wxT(": ") + str + wxT("\n");
1495 
1496         if (column == FINISHED_NAME)
1497         {
1498             str = wxEmptyString;
1499             config->Read(MD5_REG,&str);
1500             downloadinfo += _("MD5");
1501             downloadinfo += wxT(": ") + str + wxT("\n");
1502         }
1503 
1504         str = wxEmptyString;
1505         config->Read(REFERENCE_REG,&str);
1506         downloadinfo += _("Reference URL");
1507         downloadinfo += wxT(": ") + str + wxT("\n");
1508 
1509         str = wxEmptyString;
1510         config->Read(COMMENTS_REG,&str);
1511         downloadinfo += _("Comments");
1512         downloadinfo += wxT(": ") + str + wxT("\n");
1513 
1514         str = wxEmptyString;
1515         config->Read(URL_REG + wxT("1"),&str);
1516         downloadinfo += _("URLs");
1517         downloadinfo += wxT(":\t") + str + wxT("\n");
1518 
1519         bool existurl = TRUE;
1520         int count = 2;
1521         while (existurl)
1522         {
1523             str = wxEmptyString;
1524             config->Read(URL_REG + MyUtilFunctions::int2wxstr(count),&(str));
1525             if (str.IsEmpty())
1526                 break;
1527             else
1528                 downloadinfo += wxT("\t") + str + wxT("\n");
1529             count++;
1530         }
1531 
1532         wxTheClipboard->SetData( new wxTextDataObject(downloadinfo));
1533         wxTheClipboard->Close();
1534         delete config;
1535     }
1536     else
1537         wxMessageBox(_("Unable to open the clipboard!"),_("Error...") ,wxOK | wxICON_ERROR,this);
1538 }
OnSelectAll(wxCommandEvent & event)1539 void mMainFrame::OnSelectAll(wxCommandEvent& event)
1540 {
1541     mNotebook *notebook = XRCCTRL(*(this), "notebook01",mNotebook );
1542     wxListCtrl *list;
1543     if (notebook->GetSelection() == 0)
1544     {
1545         list = XRCCTRL(*(this), "inprogresslist",mInProgressList);
1546     }else if (notebook->GetSelection() == 1)
1547     {
1548         list = XRCCTRL(*(this), "finishedlist",mFinishedList);
1549     }
1550     else
1551         return;
1552     for (int i=0;i<list->GetItemCount();i++)
1553         list->SetItemState(i,wxLIST_STATE_SELECTED,wxLIST_STATE_SELECTED);
1554 }
1555 
OnInvertSelection(wxCommandEvent & event)1556 void mMainFrame::OnInvertSelection(wxCommandEvent& event)
1557 {
1558     mNotebook *notebook = XRCCTRL(*(this), "notebook01",mNotebook );
1559     mListSelection selectionlist;
1560     if (notebook->GetSelection() == 0)
1561     {
1562         mInProgressList *list = XRCCTRL(*(this), "inprogresslist",mInProgressList);
1563         selectionlist = list->GetCurrentSelection();
1564         list->SelectUnselect(FALSE,-1);
1565         int nitems = list->GetItemCount();
1566         int nselections = selectionlist.GetCount();
1567         int count = 0;
1568         int next = -1;
1569         if (nselections > 0)
1570             next = selectionlist.Item(count);
1571         for (int i = 0; i < nitems ; i++)
1572         {
1573             if (i != next)
1574                 list->SetItemState(i,wxLIST_STATE_SELECTED,wxLIST_STATE_SELECTED);
1575             else
1576             {
1577                 count++;
1578                 if (count < nselections)
1579                 {
1580                     next = selectionlist.Item(count);
1581                 }
1582             }
1583         }
1584     }
1585     else if (notebook->GetSelection() == 1)
1586     {
1587         mFinishedList *list = XRCCTRL(*(this), "finishedlist",mFinishedList);
1588         selectionlist = list->GetCurrentSelection();
1589         list->SelectUnselect(FALSE,-1);
1590         int nitems = list->GetItemCount();
1591         int nselections = selectionlist.GetCount();
1592         int count = 0;
1593         int next = -1;
1594         if (nselections > 0)
1595             next = selectionlist.Item(count);
1596         for (int i = 0; i < nitems ; i++)
1597         {
1598             if (i != next)
1599                 list->SetItemState(i,wxLIST_STATE_SELECTED,wxLIST_STATE_SELECTED);
1600             else
1601             {
1602                 count++;
1603                 if (count < nselections)
1604                 {
1605                     next = selectionlist.Item(count);
1606                 }
1607             }
1608         }
1609     }
1610     else
1611         return;
1612 }
1613 
OnFind(wxCommandEvent & event)1614 void mMainFrame::OnFind(wxCommandEvent& event)
1615 {
1616     wxFindReplaceData *data = new wxFindReplaceData();
1617     data->SetFlags(wxFR_DOWN);
1618     mBoxFind *dlg = new mBoxFind(this,data,_("Find file..."));
1619     if (dlg)
1620     {
1621         this->active = FALSE;
1622         dlg->Show();
1623         this->active = TRUE;
1624     }
1625 }
1626 
OnShowProgressBar(wxCommandEvent & event)1627 void mMainFrame::OnShowProgressBar(wxCommandEvent& event)
1628 {
1629     if (programoptions.progressbarshow)
1630     {
1631         programoptions.progressbarshow = FALSE;
1632         progressbar->Hide();
1633     }
1634     else
1635     {
1636         programoptions.progressbarshow = TRUE;
1637         progressbar->Show();
1638     }
1639     mApplication::Configurations(WRITE,OPT_PROGRESS_BAR_SHOW_REG,programoptions.progressbarshow);
1640 }
1641 
OnShowGraph(wxCommandEvent & event)1642 void mMainFrame::OnShowGraph(wxCommandEvent& event)
1643 {
1644     if (programoptions.graphshow)
1645         programoptions.graphshow = FALSE;
1646     else
1647         programoptions.graphshow = TRUE;
1648     mApplication::Configurations(WRITE,OPT_GRAPH_SHOW_REG,programoptions.graphshow);
1649     ShowHideResizeGraph(programoptions.graphheight);
1650 }
1651 
ShowHideResizeGraph(int oldgraphheight)1652 void mMainFrame::ShowHideResizeGraph(int oldgraphheight)
1653 {
1654     if (programoptions.graphheight != oldgraphheight) //SHOW/HIDE/CHANGE THE HEIGHT OF THE GRAPH
1655     {
1656         int currentgraphheight = programoptions.graphheight;
1657         programoptions.graphheight = oldgraphheight;
1658         graph->Hide();
1659         programoptions.graphheight = currentgraphheight;
1660         if (programoptions.graphshow)
1661             graph->Show();
1662     }
1663     else
1664     {
1665         if (!programoptions.graphshow)
1666             graph->Hide();
1667         else
1668             graph->Show();
1669     }
1670 }
1671 
OnDetails(wxCommandEvent & event)1672 void mMainFrame::OnDetails(wxCommandEvent& event)
1673 {
1674     wxSplitterWindow *splitter = XRCCTRL(*this, "splitter01",wxSplitterWindow);
1675     if (splitter->IsSplit())
1676         splitter->Unsplit();
1677     else
1678     {
1679         splitter->SplitHorizontally(XRCCTRL(*this, "inprogresslist",mInProgressList ),XRCCTRL(*this, "panelmessages01",wxPanel));
1680         XRCCTRL(*this, "panelmessages01",wxPanel)->Show();
1681     }
1682 
1683 }
1684 
OnUpDown(bool up)1685 void mMainFrame::OnUpDown(bool up)
1686 {
1687     mInProgressList *list = XRCCTRL(*this, "inprogresslist",mInProgressList );
1688     int newselection = -1,currentselection;
1689     currentselection = list->GetCurrentLastSelection();
1690     if ((currentselection > 0) && (up == TRUE))
1691         newselection = currentselection -1;
1692     if ((currentselection >= 0) && (up == FALSE) && (currentselection+1 < list->GetItemCount()))
1693         newselection = currentselection +1;
1694     if (newselection >= 0)
1695     {
1696         mDownloadFile *currentfile = wxGetApp().downloadlist.Item(currentselection)->GetData();
1697         mDownloadFile *newfile = wxGetApp().downloadlist.Item(newselection)->GetData();
1698 
1699         wxGetApp().downloadlist.ChangePosition(currentfile,newfile);
1700 
1701         currentfile->MarkWriteAsPending(TRUE);
1702         newfile->MarkWriteAsPending(TRUE);
1703 
1704         list->Insert(currentfile,newselection);
1705         list->Insert(newfile,currentselection);
1706         list->HandleSelectDeselectEvents(FALSE);
1707         list->SetCurrentSelection(newselection);
1708         list->HandleSelectDeselectEvents(TRUE);
1709     }
1710 }
1711 
MarkCurrentLanguageMenu(int language)1712 void mMainFrame::MarkCurrentLanguageMenu(int language)
1713 {
1714     if (!menubar)
1715         return;
1716     if (language != wxLANGUAGE_DEFAULT)
1717         menubar->GetMenu(2)->Check(XRCID("menulang_default"),FALSE);
1718     else
1719         menubar->GetMenu(2)->Check(XRCID("menulang_default"),TRUE);
1720 
1721     if (language != wxLANGUAGE_ENGLISH)
1722         menubar->GetMenu(2)->Check(XRCID("menulang_ent"),FALSE);
1723     else
1724         menubar->GetMenu(2)->Check(XRCID("menulang_ent"),TRUE);
1725 
1726     if (language != wxLANGUAGE_PORTUGUESE)
1727         menubar->GetMenu(2)->Check(XRCID("menulang_pt"),FALSE);
1728     else
1729         menubar->GetMenu(2)->Check(XRCID("menulang_pt"),TRUE);
1730 
1731     if (language != wxLANGUAGE_PORTUGUESE_BRAZILIAN)
1732         menubar->GetMenu(2)->Check(XRCID("menulang_ptbr"),FALSE);
1733     else
1734         menubar->GetMenu(2)->Check(XRCID("menulang_ptbr"),TRUE);
1735 
1736     if (language != wxLANGUAGE_GERMAN)
1737         menubar->GetMenu(2)->Check(XRCID("menulang_de"),FALSE);
1738     else
1739         menubar->GetMenu(2)->Check(XRCID("menulang_de"),TRUE);
1740 
1741     if (language != wxLANGUAGE_SPANISH)
1742         menubar->GetMenu(2)->Check(XRCID("menulang_es"),FALSE);
1743     else
1744         menubar->GetMenu(2)->Check(XRCID("menulang_es"),TRUE);
1745 
1746     if (language != wxLANGUAGE_CZECH)
1747         menubar->GetMenu(2)->Check(XRCID("menulang_cs"),FALSE);
1748     else
1749         menubar->GetMenu(2)->Check(XRCID("menulang_cs"),TRUE);
1750 
1751     if (language != wxLANGUAGE_RUSSIAN)
1752         menubar->GetMenu(2)->Check(XRCID("menulang_ru"),FALSE);
1753     else
1754         menubar->GetMenu(2)->Check(XRCID("menulang_ru"),TRUE);
1755 
1756     if (language != wxLANGUAGE_HUNGARIAN)
1757         menubar->GetMenu(2)->Check(XRCID("menulang_hu"),FALSE);
1758     else
1759         menubar->GetMenu(2)->Check(XRCID("menulang_hu"),TRUE);
1760 
1761     if (language != wxLANGUAGE_INDONESIAN)
1762         menubar->GetMenu(2)->Check(XRCID("menulang_id"),FALSE);
1763     else
1764         menubar->GetMenu(2)->Check(XRCID("menulang_id"),TRUE);
1765 
1766     if (language != wxLANGUAGE_ARMENIAN)
1767         menubar->GetMenu(2)->Check(XRCID("menulang_hy"),FALSE);
1768     else
1769         menubar->GetMenu(2)->Check(XRCID("menulang_hy"),TRUE);
1770 
1771     if (language != wxLANGUAGE_POLISH)
1772         menubar->GetMenu(2)->Check(XRCID("menulang_pl"),FALSE);
1773     else
1774         menubar->GetMenu(2)->Check(XRCID("menulang_pl"),TRUE);
1775 
1776     if (language != wxLANGUAGE_TURKISH)
1777         menubar->GetMenu(2)->Check(XRCID("menulang_tr"),FALSE);
1778     else
1779         menubar->GetMenu(2)->Check(XRCID("menulang_tr"),TRUE);
1780 
1781     if (language != wxLANGUAGE_FRENCH)
1782         menubar->GetMenu(2)->Check(XRCID("menulang_fr"),FALSE);
1783     else
1784         menubar->GetMenu(2)->Check(XRCID("menulang_fr"),TRUE);
1785 
1786     if (language != wxLANGUAGE_DUTCH)
1787         menubar->GetMenu(2)->Check(XRCID("menulang_nl"),FALSE);
1788     else
1789         menubar->GetMenu(2)->Check(XRCID("menulang_nl"),TRUE);
1790 }
1791 
SetLanguage(int language)1792 void mMainFrame::SetLanguage(int language)
1793 {
1794     wxGetApp().SetLanguage(language);
1795 
1796     //STOP THE TIMER BEFORE UPDATE THE INTERFACE
1797     mtimer->Stop();
1798 
1799     //RELOAD THE MENU BAR
1800     wxMenuBar *oldmenubar = menubar;
1801     if ((menubar = wxXmlResource::Get()->LoadMenuBar(wxT("menubar"))))
1802     {
1803         this->SetMenuBar(menubar);
1804         delete oldmenubar;
1805     }
1806     else
1807         menubar = oldmenubar;
1808 
1809     //RELOAD THE TOOL BAR
1810     wxToolBar *oldtoolbar = toolbar;
1811     if ((toolbar = wxXmlResource::Get()->LoadToolBar(this,wxT("toolbar"))))
1812     {
1813         this->SetToolBar(toolbar);
1814         delete oldtoolbar;
1815     }
1816     else
1817         toolbar = oldtoolbar;
1818 
1819     //MARK CURRENT LANGUAGE ON MENU
1820     MarkCurrentLanguageMenu(language);
1821 
1822     //REGENERATE THE LISTS
1823     XRCCTRL(*(this), "inprogresslist",mInProgressList )->GenerateList(imageslist);
1824     XRCCTRL(*(this), "finishedlist",mFinishedList )->GenerateList(imageslist);
1825 
1826     //RESET NOTEBOOK PAGES LABELS
1827     XRCCTRL(*(this), "notebook01",mNotebook )->ReSetPagesLabel();
1828 
1829     //RESET THE PREVIEW PANEL TEXT
1830     {
1831         wxString contentstring =  _("File type");
1832         contentstring += wxT(":\n");
1833         XRCCTRL(*this, "lblpreview", wxStaticText )->SetLabel(contentstring);
1834         XRCCTRL(*this, "btnpreview", wxButton )->SetLabel(_("Preview"));
1835     }
1836 
1837     //RESET THE STATUSBAR TEXT
1838     if (statusbar)
1839     {
1840         this->defaultstatusbarmessage = wxEmptyString;
1841         wxStringTokenizer newrelease(programoptions.currentrelease,wxT("."));
1842         wxStringTokenizer currentrelease(VERSION,wxT("."));
1843         long old01,old02,old03,new01,new02,new03;
1844         newrelease.GetNextToken().ToLong(&new01);
1845         currentrelease.GetNextToken().ToLong(&old01);
1846         newrelease.GetNextToken().ToLong(&new02);
1847         currentrelease.GetNextToken().ToLong(&old02);
1848         newrelease.GetNextToken().ToLong(&new03);
1849         currentrelease.GetNextToken().ToLong(&old03);
1850         if ((new01*100)+(new02*10)+(new03) > (old01*100)+(old02*10)+(old03))
1851         {
1852             this->defaultstatusbarmessage = _("NEW RELEASE: ");
1853             this->defaultstatusbarmessage += wxT("wxDownload Fast ");
1854             this->defaultstatusbarmessage += programoptions.currentrelease + _(" is available.");
1855         }
1856         statusbar->SetStatusText(this->defaultstatusbarmessage);
1857         if (programoptions.bandwidthoption == 1)
1858         {
1859             wxString temp = _("Band control");
1860             temp += wxT(": ");
1861             temp += _("Per Download");
1862             statusbar->SetStatusText(temp,2);
1863         }
1864         else if (programoptions.bandwidthoption == 2)
1865         {
1866             wxString temp = _("Band control");
1867             temp += wxT(": ");
1868             temp += _("Active");
1869             temp += wxT(" (") + MyUtilFunctions::int2wxstr(programoptions.bandwidth) + wxT(" kB/s)");
1870             statusbar->SetStatusText(temp,2);
1871         }
1872         else
1873         {
1874             wxString temp = _("Band control");
1875             temp += wxT(": ");
1876             temp += _("Unlimited");
1877             statusbar->SetStatusText(temp,2);
1878         }
1879     }
1880 
1881     //WRITE LANGUAGE SELECTION
1882     mApplication::Configurations(WRITE,LANGUAGE_REG,language);
1883 
1884     //RESTART THE TIMER
1885     mtimer->Start();
1886 }
1887 
OnDefaultLanguage(wxCommandEvent & event)1888 void mMainFrame::OnDefaultLanguage(wxCommandEvent& event)
1889 {
1890     SetLanguage(wxLANGUAGE_DEFAULT);
1891 }
1892 
OnEnglish(wxCommandEvent & event)1893 void mMainFrame::OnEnglish(wxCommandEvent& event)
1894 {
1895     SetLanguage(wxLANGUAGE_ENGLISH);
1896 }
1897 
OnPortuguese(wxCommandEvent & event)1898 void mMainFrame::OnPortuguese(wxCommandEvent& event)
1899 {
1900     SetLanguage(wxLANGUAGE_PORTUGUESE);
1901 }
1902 
OnPortugueseBrazil(wxCommandEvent & event)1903 void mMainFrame::OnPortugueseBrazil(wxCommandEvent& event)
1904 {
1905     SetLanguage(wxLANGUAGE_PORTUGUESE_BRAZILIAN);
1906 }
1907 
OnGerman(wxCommandEvent & event)1908 void mMainFrame::OnGerman(wxCommandEvent& event)
1909 {
1910     SetLanguage(wxLANGUAGE_GERMAN);
1911 }
1912 
OnSpanish(wxCommandEvent & event)1913 void mMainFrame::OnSpanish(wxCommandEvent& event)
1914 {
1915     SetLanguage(wxLANGUAGE_SPANISH);
1916 }
1917 
OnCzech(wxCommandEvent & event)1918 void mMainFrame::OnCzech(wxCommandEvent& event)
1919 {
1920     SetLanguage(wxLANGUAGE_CZECH);
1921 }
1922 
OnHungarian(wxCommandEvent & event)1923 void mMainFrame::OnHungarian(wxCommandEvent& event)
1924 {
1925     SetLanguage(wxLANGUAGE_HUNGARIAN);
1926 }
1927 
OnRussian(wxCommandEvent & event)1928 void mMainFrame::OnRussian(wxCommandEvent& event)
1929 {
1930     SetLanguage(wxLANGUAGE_RUSSIAN);
1931 }
1932 
OnArmenian(wxCommandEvent & event)1933 void mMainFrame::OnArmenian(wxCommandEvent& event)
1934 {
1935     SetLanguage(wxLANGUAGE_ARMENIAN);
1936 }
1937 
OnIndonesian(wxCommandEvent & event)1938 void mMainFrame::OnIndonesian(wxCommandEvent& event)
1939 {
1940     SetLanguage(wxLANGUAGE_INDONESIAN);
1941 }
1942 
OnPolish(wxCommandEvent & event)1943 void mMainFrame::OnPolish(wxCommandEvent& event)
1944 {
1945     SetLanguage(wxLANGUAGE_POLISH);
1946 }
1947 
OnTurkish(wxCommandEvent & event)1948 void mMainFrame::OnTurkish(wxCommandEvent& event)
1949 {
1950     SetLanguage(wxLANGUAGE_TURKISH);
1951 }
1952 
OnFrench(wxCommandEvent & event)1953 void mMainFrame::OnFrench(wxCommandEvent& event)
1954 {
1955     SetLanguage(wxLANGUAGE_FRENCH);
1956 }
1957 
OnDutch(wxCommandEvent & event)1958 void mMainFrame::OnDutch(wxCommandEvent& event)
1959 {
1960     SetLanguage(wxLANGUAGE_DUTCH);
1961 }
1962 
OnProperties(wxCommandEvent & event)1963 void mMainFrame::OnProperties(wxCommandEvent& event)
1964 {
1965     mInProgressList *list = XRCCTRL(*this, "inprogresslist",mInProgressList );
1966     int currentselection;
1967     if ((currentselection = list->GetCurrentLastSelection()) >= 0)
1968     {
1969         mDownloadFile *currentfile = wxGetApp().downloadlist.Item(currentselection)->GetData();
1970         list->SetCurrentSelection(currentselection);
1971         mBoxNew dlg;
1972         wxString newname, oldname;
1973         wxCheckListBox *lstaddresslist;
1974         wxXmlResource::Get()->LoadDialog(&dlg, this, wxT("boxnew"));
1975         dlg.Centre(wxBOTH);
1976         dlg.SetTitle(_("Download Properties"));
1977         lstaddresslist = XRCCTRL(dlg,"lstaddresslist",wxCheckListBox);
1978 
1979         XRCCTRL(dlg, "edtdestination",wxTextCtrl)->SetValue(currentfile->GetDestination());
1980         lstaddresslist->Clear();
1981         lstaddresslist->InsertItems(currentfile->GetUrlArray(),0);
1982         for (unsigned int i = 0; i < lstaddresslist->GetCount() ;i++)
1983             lstaddresslist->Check(i);
1984 
1985         /*if (currentfile->GetUser() == ANONYMOUS_USER)
1986         {
1987             XRCCTRL(dlg, "edtuser",wxTextCtrl)->SetValue(wxEmptyString);
1988             XRCCTRL(dlg, "edtpassword",wxTextCtrl)->SetValue(wxEmptyString);
1989         }
1990         else
1991         {*/
1992         XRCCTRL(dlg, "edtuser",wxTextCtrl)->SetValue(currentfile->GetUser());
1993         XRCCTRL(dlg, "edtpassword",wxTextCtrl)->SetValue(currentfile->GetPassword());
1994         XRCCTRL(dlg, "spinsplit",wxSpinCtrl)->SetValue(currentfile->GetNumberofParts());
1995         XRCCTRL(dlg, "edtcomments",wxTextCtrl)->SetValue(currentfile->GetComments());
1996         XRCCTRL(dlg, "edtreferenceurl",wxTextCtrl)->SetValue(currentfile->GetReferenceURL());
1997         XRCCTRL(dlg, "edtcommand",wxTextCtrl)->SetValue(currentfile->GetCommand());
1998         XRCCTRL(dlg, "spinbandwidth",wxSpinCtrl)->SetValue(currentfile->GetBandWidth());
1999         XRCCTRL(dlg, "optmanual",wxRadioButton)->Enable(FALSE);
2000         XRCCTRL(dlg, "optnow",wxRadioButton)->Enable(FALSE);
2001         XRCCTRL(dlg, "optschedule",wxRadioButton)->Enable(FALSE);
2002 
2003         oldname = currentfile->GetFirstUrl().GetFullName();
2004         if ((currentfile->GetStatus() != STATUS_STOPED) && (currentfile->GetStatus() != STATUS_FINISHED) && (currentfile->GetStatus() != STATUS_ERROR))
2005         {
2006             XRCCTRL(dlg, "edturl",wxTextCtrl)->SetEditable(FALSE);
2007             XRCCTRL(dlg, "edtdestination",wxTextCtrl)->SetEditable(FALSE);
2008             XRCCTRL(dlg, "edtuser",wxTextCtrl)->SetEditable(FALSE);
2009             XRCCTRL(dlg, "edtpassword",wxTextCtrl)->SetEditable(FALSE);
2010             XRCCTRL(dlg, "edtcomments",wxTextCtrl)->SetEditable(FALSE);
2011             XRCCTRL(dlg, "edtreferenceurl",wxTextCtrl)->SetEditable(FALSE);
2012             XRCCTRL(dlg, "edtcommand",wxTextCtrl)->SetEditable(FALSE);
2013             lstaddresslist->Enable(FALSE);
2014             XRCCTRL(dlg,"btndir",wxButton)->Enable(FALSE);
2015             XRCCTRL(dlg,"btnadd",wxButton)->Enable(FALSE);
2016             XRCCTRL(dlg, "spinbandwidth",wxSpinCtrl)->Enable(FALSE);
2017             XRCCTRL(dlg, "chkaddontop",wxCheckBox)->Enable(FALSE);
2018         }
2019         XRCCTRL(dlg, "spinsplit",wxSpinCtrl)->Enable(FALSE);
2020 
2021         #if wxCHECK_VERSION(2, 8, 0)
2022         dlg.SetInitialSize();
2023         #else
2024         dlg.SetBestFittingSize();
2025         #endif
2026         dlg.SetDifferentNamesPermition(FALSE);
2027 
2028         this->active = FALSE;
2029         if (dlg.ShowModal() == XRCID("btnok"))
2030         {
2031             wxFileName destination; destination.AssignDir(XRCCTRL(dlg, "edtdestination",wxTextCtrl)->GetValue());
2032             wxString user = XRCCTRL(dlg, "edtuser",wxTextCtrl)->GetValue();
2033             wxString password = XRCCTRL(dlg, "edtpassword",wxTextCtrl)->GetValue();
2034             wxString reference = XRCCTRL(dlg, "edtreferenceurl",wxTextCtrl)->GetValue();
2035             wxString command = XRCCTRL(dlg, "edtcommand",wxTextCtrl)->GetValue();
2036             wxString comments = XRCCTRL(dlg, "edtcomments",wxTextCtrl)->GetValue();
2037             int bandwidth = XRCCTRL(dlg, "spinbandwidth",wxSpinCtrl)->GetValue();
2038 
2039             mUrlList *urllist = new mUrlList();
2040             for (unsigned int i = 0; i < lstaddresslist->GetCount(); i++)
2041             {
2042                 if (!lstaddresslist->IsChecked(i))
2043                     continue;
2044                 mUrlName *urltmp = new mUrlName(lstaddresslist->GetString(i));
2045                 urllist->Append(urltmp);
2046             }
2047             wxGetApp().downloadlist.ChangeDownload(currentfile,urllist,destination,user,password,reference,comments,command,bandwidth);
2048 
2049             //VERIFY IF THE USER CHANGED THE FILE NAME
2050             newname = urllist->GetFirst()->GetData()->GetFullName();
2051             if (newname != oldname)
2052             {
2053                 wxGetApp().downloadlist.ChangeName(currentfile,newname);
2054                 XRCCTRL(*this, "inprogresslist",mInProgressList )->SetItem(wxGetApp().downloadlist.IndexOf(currentfile),INPROGRESS_NAME,currentfile->GetName());
2055             }
2056             list->SetItem(wxGetApp().downloadlist.IndexOf(currentfile),INPROGRESS_URL,currentfile->GetFirstUrl().GetFullPath());
2057 
2058         }
2059         this->active = TRUE;
2060         dlg.Destroy();
2061     }
2062 }
2063 
OnDownloadAgain(wxCommandEvent & event)2064 void mMainFrame::OnDownloadAgain(wxCommandEvent& event)
2065 {
2066     int currentselection;
2067     mFinishedList *list = XRCCTRL(*this, "finishedlist",mFinishedList );
2068     if (list->GetCurrentSelection().GetCount() > 0)
2069     {
2070         mListSelection currentselectionlist = list->GetCurrentSelection();
2071         int nselection = currentselectionlist.GetCount()-1;
2072         for (int i = nselection ; i >= 0 ;i--)
2073         {
2074             currentselection = currentselectionlist.Item(i);
2075             #ifdef WXDFAST_PORTABLE
2076             wxFileConfig *config = new wxFileConfig(DFAST_REG, wxEmptyString, DFAST_REG + wxT(".ini"), wxEmptyString,
2077                                                     wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_RELATIVE_PATH);
2078             #else
2079             wxFileConfig *config = new wxFileConfig(DFAST_REG);
2080             #endif
2081             wxListItem item;
2082             int startoption,ontop;
2083             wxString url,destination,user,password,comments,reference,command;
2084             wxArrayString urlarray;
2085             int parts;
2086             item.SetId(currentselection);
2087             item.SetColumn(FINISHED_NAME);
2088             item.SetMask(wxLIST_MASK_DATA|wxLIST_MASK_STATE|wxLIST_MASK_TEXT|wxLIST_MASK_IMAGE);
2089             list->GetItem(item);
2090 
2091             config->SetPath(FINISHED_REG);
2092             config->SetPath(item.GetText());
2093 
2094             destination = wxEmptyString;
2095             config->Read(DESTINATION_REG,&destination);
2096             #ifdef WXDFAST_PORTABLE
2097             {
2098                 #ifdef __WXMSW__
2099                 wxFileName destinationtmp(destination);
2100                 if (destinationtmp.GetVolume().Upper() == wxT("PORTABLE"))
2101                 {
2102                     destinationtmp.SetVolume(wxGetApp().programvolume);
2103                     destination = destinationtmp.GetFullPath();
2104                 }
2105                 #endif
2106             }
2107             #endif
2108 
2109             parts = 1;
2110             config->Read(PARTS_REG,&parts);
2111 
2112             user = wxEmptyString;
2113             config->Read(USER_REG,&user);
2114 
2115             password = wxEmptyString;
2116             config->Read(PASSWORD_REG,&password);
2117 
2118             comments = wxEmptyString;
2119             config->Read(COMMENTS_REG,&comments);
2120 
2121             reference = wxEmptyString;
2122             config->Read(REFERENCE_REG,&reference);
2123 
2124             command = wxEmptyString;
2125             config->Read(COMMAND_REG,&command);
2126 
2127             bool existurl = TRUE;
2128             int count = 1;
2129             while (existurl)
2130             {
2131                 url = wxEmptyString;
2132                 config->Read(URL_REG + MyUtilFunctions::int2wxstr(count),&(url));
2133                 if (url.IsEmpty())
2134                     break;
2135                 else
2136                     urlarray.Add(url);
2137                 count++;
2138             }
2139             config->SetPath(BACK_DIR_REG);
2140 
2141             if (programoptions.rememberboxnewoptions)
2142             {
2143                 startoption = programoptions.laststartoption;
2144                 ontop = programoptions.lastontopoption;
2145             }
2146             else
2147             {
2148                 startoption = DEFAULT_START_OPTION;
2149                 ontop = DEFAULT_ONTOP_OPTION;
2150             }
2151 
2152             if (NewDownload(urlarray, destination,-1, parts, user, password, reference, comments, command, startoption,ontop, FALSE,FALSE))
2153             {
2154                 config->DeleteGroup(item.GetText());
2155                 list->DeleteItem(currentselection);
2156                 list->SelectUnselect(FALSE,-1);
2157             }
2158             delete config;
2159         }
2160     }
2161 }
2162 
OnMove(wxCommandEvent & event)2163 void mMainFrame::OnMove(wxCommandEvent& event)
2164 {
2165     int currentselection = -1;
2166     mFinishedList *list = XRCCTRL(*this, "finishedlist",mFinishedList );
2167     if (list->GetCurrentSelection().GetCount() > 0)
2168     {
2169         wxString dir;
2170         dir = wxDirSelector(_("Select the directory:"));
2171         if (dir != wxEmptyString)
2172         {
2173             mListSelection currentselectionlist = list->GetCurrentSelection();
2174             if (dir.Mid(dir.Length()-1,1) != SEPARATOR_DIR)
2175                 dir = dir + SEPARATOR_DIR;
2176             #ifdef WXDFAST_PORTABLE
2177             wxFileConfig *config = new wxFileConfig(DFAST_REG, wxEmptyString, DFAST_REG + wxT(".ini"), wxEmptyString,
2178                                                     wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_RELATIVE_PATH);
2179             #else
2180             wxFileConfig *config = new wxFileConfig(DFAST_REG);
2181             #endif
2182             wxListItem item;
2183             config->SetPath(FINISHED_REG);
2184 
2185             for (unsigned int i = 0; i < currentselectionlist.GetCount();i++)
2186             {
2187                 currentselection = currentselectionlist.Item(i);
2188 
2189                 wxString name,destination;
2190                 item.SetId(currentselection);
2191                 item.SetColumn(FINISHED_NAME);
2192                 item.SetMask(wxLIST_MASK_DATA|wxLIST_MASK_STATE|wxLIST_MASK_TEXT|wxLIST_MASK_IMAGE);
2193                 list->GetItem(item);
2194 
2195                 config->SetPath(item.GetText());
2196 
2197                 name = wxEmptyString;
2198                 config->Read(NAME_REG,&name);
2199 
2200                 destination = wxEmptyString;
2201                 config->Read(DESTINATION_REG,&destination);
2202                 #ifdef WXDFAST_PORTABLE
2203                 {
2204                     #ifdef __WXMSW__
2205                     wxFileName destinationtmp(destination);
2206                     if (destinationtmp.GetVolume().Upper() == wxT("PORTABLE"))
2207                     {
2208                         destinationtmp.SetVolume(wxGetApp().programvolume);
2209                         destination = destinationtmp.GetFullPath();
2210                     }
2211                     #endif
2212                 }
2213                 #endif
2214 
2215                 if (destination.Mid(destination.Length()-1,1) != SEPARATOR_DIR)
2216                     destination = destination + SEPARATOR_DIR;
2217 
2218                 if (destination != dir)
2219                 {
2220                     if (::wxFileExists(destination+name))
2221                     {
2222                         this->active = FALSE;
2223                         wxProgressDialog *dlg = new wxProgressDialog(_("Moving..."),_("Moving file..."));
2224                         wxLogNull logNo;
2225                         if (::wxCopyFile(destination+name,dir+name,TRUE))
2226                         {
2227                             dlg->Update(50);
2228                             #ifdef WXDFAST_PORTABLE
2229                             {
2230                                 #ifdef __WXMSW__
2231                                 wxFileName destinationtmp(dir);
2232                                 if (destinationtmp.GetVolume().Lower() == wxGetApp().programvolume.Lower())
2233                                 {
2234                                     destinationtmp.SetVolume(wxEmptyString);
2235                                     config->Write(DESTINATION_REG,wxT("PORTABLE:") + destinationtmp.GetFullPath());
2236                                 }
2237                                 else
2238                                     config->Write(DESTINATION_REG,dir);
2239                                 #else
2240                                 config->Write(DESTINATION_REG,dir);
2241                                 #endif
2242                             }
2243                             #else
2244                             config->Write(DESTINATION_REG,dir);
2245                             #endif
2246                             ::wxRemoveFile(destination+name);
2247                         }
2248                         else
2249                             wxMessageBox(_("Error moving file."),_("Error..."),wxOK|wxICON_ERROR,this);
2250                         this->active = TRUE;
2251                         delete dlg;
2252                     }
2253                     else
2254                     {
2255                         wxString message = _("The file isn't in the path that it was saved initially.\nDo you want to change only the old path for the current one?");
2256                         message += wxT("\n\nFilename: ") + name;
2257                         if (wxMessageBox(message ,
2258                                 _("Continue..."),wxYES | wxNO | wxICON_QUESTION, this) == wxYES)
2259                         {
2260                             #ifdef WXDFAST_PORTABLE
2261                             {
2262                                 #ifdef __WXMSW__
2263                                 wxFileName destinationtmp(dir);
2264                                 if (destinationtmp.GetVolume().Lower() == wxGetApp().programvolume.Lower())
2265                                 {
2266                                     destinationtmp.SetVolume(wxEmptyString);
2267                                     config->Write(DESTINATION_REG,wxT("PORTABLE:") + destinationtmp.GetFullPath());
2268                                 }
2269                                 else
2270                                     config->Write(DESTINATION_REG,dir);
2271                                 #else
2272                                 config->Write(DESTINATION_REG,dir);
2273                                 #endif
2274                             }
2275                             #else
2276                             config->Write(DESTINATION_REG,dir);
2277                             #endif
2278                         }
2279                     }
2280                 }
2281                 config->SetPath(BACK_DIR_REG);
2282             }
2283             delete config;
2284             list->SelectUnselect(TRUE,currentselection);
2285         }
2286     }
2287 }
2288 
OnCheckMD5(wxCommandEvent & event)2289 void mMainFrame::OnCheckMD5(wxCommandEvent& event)
2290 {
2291     int currentselection;
2292     mFinishedList *list = XRCCTRL(*this, "finishedlist",mFinishedList );
2293     if ((currentselection = list->GetCurrentLastSelection()) >= 0)
2294     {
2295         list->SetCurrentSelection(currentselection);
2296         #ifdef WXDFAST_PORTABLE
2297         wxFileConfig *config = new wxFileConfig(DFAST_REG, wxEmptyString, DFAST_REG + wxT(".ini"), wxEmptyString,
2298                                                 wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_RELATIVE_PATH);
2299         #else
2300         wxFileConfig *config = new wxFileConfig(DFAST_REG);
2301         #endif
2302         wxListItem item;
2303         wxString name,destination,md5old, md5new;
2304         item.SetId(currentselection);
2305         item.SetColumn(FINISHED_NAME);
2306         item.SetMask(wxLIST_MASK_DATA|wxLIST_MASK_STATE|wxLIST_MASK_TEXT|wxLIST_MASK_IMAGE);
2307         list->GetItem(item);
2308 
2309         config->SetPath(FINISHED_REG);
2310         config->SetPath(item.GetText());
2311 
2312         name = wxEmptyString;
2313         config->Read(NAME_REG,&name);
2314 
2315         destination = wxEmptyString;
2316         config->Read(DESTINATION_REG,&destination);
2317         #ifdef WXDFAST_PORTABLE
2318         {
2319             #ifdef __WXMSW__
2320             wxFileName destinationtmp(destination);
2321             if (destinationtmp.GetVolume().Upper() == wxT("PORTABLE"))
2322             {
2323                 destinationtmp.SetVolume(wxGetApp().programvolume);
2324                 destination = destinationtmp.GetFullPath();
2325             }
2326             #endif
2327         }
2328         #endif
2329         if (destination.Mid(destination.Length()-1,1) != SEPARATOR_DIR)
2330             destination = destination + SEPARATOR_DIR;
2331 
2332         md5old = wxEmptyString;
2333         config->Read(MD5_REG,&md5old);
2334 
2335         if (::wxFileExists(destination + name))
2336         {
2337             this->active = FALSE;
2338             wxProgressDialog *waitbox = new wxProgressDialog(_("Checking file's MD5..."),_("Checking file's MD5..."));
2339             waitbox->Update(10);
2340             wxFileName filemd5 = wxFileName(destination + name);
2341             wxMD5 md5(filemd5);
2342             md5new = md5.GetDigest(TRUE); //TELL TO GETDIGETS THAT IS THE MAIN THREAD
2343             waitbox->Update(100);
2344             if (md5new == md5old)
2345                 wxMessageBox(_("The file was verified successfully."), _("Success..."), wxOK | wxICON_INFORMATION,this);
2346             else
2347             {
2348                 wxString msg;
2349                 msg = _("The MD5 calculated previously is different from the current one.");
2350                 msg = msg + _("\nOld MD5 =\t\t") + md5old;
2351                 msg = msg + _("\nCurrent MD5 =\t") + md5new;
2352                 wxMessageBox(msg, _("Error..."), wxOK | wxICON_ERROR,this);
2353             }
2354             delete waitbox;
2355             this->active = TRUE;
2356         }
2357         else
2358             wxMessageBox(_("File not found."), _("Error..."), wxOK | wxICON_ERROR,this);
2359         delete config;
2360     }
2361 }
2362 
OnOpenDestination(wxCommandEvent & event)2363 void mMainFrame::OnOpenDestination(wxCommandEvent& event)
2364 {
2365     this->BrowserFile();
2366 }
2367 
OnExportConf(wxCommandEvent & event)2368 void mMainFrame::OnExportConf(wxCommandEvent& event)
2369 {
2370      wxString dir;
2371     dir = wxDirSelector(_("Select the directory:"));
2372     if (dir != wxEmptyString)
2373     {
2374 
2375         if (ExportConf(dir))
2376             wxMessageBox(_("The configuration was exported successfully."), _("Success..."),wxOK|wxICON_INFORMATION,this);
2377         else
2378             wxMessageBox(_("Error exporting configuration."), _("Error..."),wxOK|wxICON_ERROR,this);
2379     }
2380 }
2381 
ExportConf(wxString dir)2382 bool mMainFrame::ExportConf(wxString dir)
2383 {
2384     bool result;
2385     if (dir.Mid(dir.Length()-1,1) != SEPARATOR_DIR)
2386         dir = dir + SEPARATOR_DIR;
2387     wxString source, destination;
2388     #ifdef WXDFAST_PORTABLE
2389         source = wxEmptyString;
2390     #else
2391         source = wxGetHomeDir();
2392         if (source.Mid(source.Length()-1,1) != SEPARATOR_DIR)
2393             source = source + SEPARATOR_DIR;
2394     #endif
2395 
2396     #ifdef __WXMSW__
2397         source = source + DFAST_REG + wxT(".ini");
2398     #else
2399         #ifdef WXDFAST_PORTABLE
2400             source = source + DFAST_REG + wxT(".ini");
2401         #else
2402             source = source + wxT(".") + DFAST_REG;
2403         #endif
2404     #endif
2405     destination = dir + DFAST_REG + wxT(".conf");
2406     wxLogNull noLog;
2407     result = ::wxCopyFile(source,destination,TRUE);
2408     return result;
2409 }
2410 
OnImportConf(wxCommandEvent & event)2411 void mMainFrame::OnImportConf(wxCommandEvent& event)
2412 {
2413      wxFileDialog *dlg;
2414     dlg = new wxFileDialog(this, _("Select the file..."), wxEmptyString, wxEmptyString, wxT("*.conf"));
2415     this->active = FALSE;
2416     if (dlg->ShowModal() == wxID_OK)
2417     {
2418         if (ImportConf(dlg->GetPath()))
2419         {
2420             wxMessageBox(_("The configuration was imported successfully.\nThe program will be restated now for the changes to take effect."), _("Success..."),wxOK|wxICON_INFORMATION,this);
2421             Iconize(TRUE);
2422             Close(TRUE);
2423         }
2424         else
2425             wxMessageBox(_("Error importing configuration."), _("Error..."),wxOK|wxICON_ERROR,this);
2426     }
2427     this->active = TRUE;
2428 }
2429 
ImportConf(wxString path)2430 bool mMainFrame::ImportConf(wxString path)
2431 {
2432     wxString source, destination;
2433     bool result;
2434     source = path;
2435     #ifdef WXDFAST_PORTABLE
2436         destination = wxEmptyString;
2437     #else
2438         destination = wxGetHomeDir();
2439         if (destination.Mid(destination.Length()-1,1) != SEPARATOR_DIR)
2440             destination = destination + SEPARATOR_DIR;
2441     #endif
2442 
2443     #ifdef __WXMSW__
2444         destination = destination + DFAST_REG + wxT(".ini");
2445     #else
2446         #ifdef WXDFAST_PORTABLE
2447         destination = destination + DFAST_REG + wxT(".ini");
2448         #else
2449         destination = destination + wxT(".") + DFAST_REG;
2450         #endif
2451     #endif
2452     wxLogNull noLog;
2453     if (::wxFileExists(destination))
2454         ::wxCopyFile(destination,destination + wxT(".bak"),TRUE);
2455     result = ::wxCopyFile(source,destination,TRUE);
2456     return result;
2457 }
2458 
OnShutdown(wxCommandEvent & event)2459 void mMainFrame::OnShutdown(wxCommandEvent& event)
2460 {
2461     if (menubar->GetMenu(3)->IsChecked(XRCID("menushutdown")))
2462     {
2463         programoptions.shutdown = TRUE;
2464         wxMessageBox(_("Command :\t" ) + programoptions.shutdowncmd,_("Shutdown Command..."),wxOK|wxICON_INFORMATION,this);
2465     }
2466     else
2467         programoptions.shutdown = FALSE;
2468 }
2469 
OnDisconnect(wxCommandEvent & event)2470 void mMainFrame::OnDisconnect(wxCommandEvent& event)
2471 {
2472     if (menubar->GetMenu(3)->IsChecked(XRCID("menudisconnect")))
2473     {
2474         programoptions.disconnect = TRUE;
2475         wxMessageBox(_("Command :\t" ) + programoptions.disconnectcmd,_("Disconnect Command..."),wxOK|wxICON_INFORMATION,this);
2476     }
2477     else
2478         programoptions.disconnect = FALSE;
2479 }
2480 
OnOptions(wxCommandEvent & event)2481 void mMainFrame::OnOptions(wxCommandEvent& event)
2482 {
2483 
2484     mBoxOptions dlg;
2485     wxXmlResource::Get()->LoadDialog(&dlg, this, wxT("boxoptions"));
2486     unsigned int i,j;
2487     int oldgraphheight = programoptions.graphheight;
2488 
2489     XRCCTRL(dlg, "spinattempts", wxSpinCtrl)->SetValue(programoptions.attempts);
2490     XRCCTRL(dlg, "spinattemptstime", wxSpinCtrl)->SetValue(programoptions.attemptstime);
2491     XRCCTRL(dlg, "spinsimultaneous", wxSpinCtrl)->SetValue(programoptions.simultaneous);
2492     XRCCTRL(dlg, "edtshutdown",wxTextCtrl)->SetValue(programoptions.shutdowncmd);
2493     XRCCTRL(dlg, "edtdisconnect",wxTextCtrl)->SetValue(programoptions.disconnectcmd);
2494     XRCCTRL(dlg, "chkclosedialog",wxCheckBox)->SetValue(programoptions.closedialog);
2495     XRCCTRL(dlg, "chkshutdown",wxCheckBox)->SetValue(programoptions.alwaysshutdown);
2496     XRCCTRL(dlg, "chkdisconnect",wxCheckBox)->SetValue(programoptions.alwaysdisconnect);
2497     XRCCTRL(dlg, "chkrememberboxnewoptions",wxCheckBox)->SetValue(programoptions.rememberboxnewoptions);
2498     XRCCTRL(dlg, "edtdestination",wxTextCtrl)->SetValue(programoptions.destination);
2499     XRCCTRL(dlg, "edtbrowserpath",wxTextCtrl)->SetValue(programoptions.browserpath);
2500     XRCCTRL(dlg, "edtfilemanagerpath",wxTextCtrl)->SetValue(programoptions.filemanagerpath);
2501 
2502     #ifdef WXDFAST_PORTABLE
2503     XRCCTRL(dlg, "optdefaulttemp",wxRadioButton)->Enable(false);
2504     XRCCTRL(dlg, "optusertemp",wxRadioButton)->Enable(false);
2505     XRCCTRL(dlg, "edttemppath",wxTextCtrl)->Enable(false);
2506     #endif
2507     if (programoptions.downloadpartsdefaultdir.IsEmpty())
2508         XRCCTRL(dlg, "optdefaulttemp",wxRadioButton)->SetValue(TRUE);
2509     else
2510         XRCCTRL(dlg, "optusertemp",wxRadioButton)->SetValue(TRUE);
2511     XRCCTRL(dlg, "edttemppath",wxTextCtrl)->SetValue(programoptions.downloadpartsdefaultdir);
2512 
2513     XRCCTRL(dlg, "spintimerinterval",wxSpinCtrl)->SetValue(programoptions.timerupdateinterval);
2514     XRCCTRL(dlg, "spinreadbuffersize",wxSpinCtrl)->SetValue(programoptions.readbuffersize);
2515     XRCCTRL(dlg, "spingraphpoints",wxSpinCtrl)->SetValue(programoptions.graphhowmanyvalues);
2516     XRCCTRL(dlg, "spingraphrefreshrate",wxSpinCtrl)->SetValue(programoptions.graphrefreshtime);
2517     XRCCTRL(dlg, "spingraphmaxvalue",wxSpinCtrl)->SetValue(programoptions.graphscale);
2518     XRCCTRL(dlg, "spingraphtextarea",wxSpinCtrl)->SetValue(programoptions.graphtextarea);
2519     XRCCTRL(dlg, "spingraphheight",wxSpinCtrl)->SetValue(programoptions.graphheight);
2520     XRCCTRL(dlg, "spingraphfontsize",wxSpinCtrl)->SetValue(programoptions.graphspeedfontsize);
2521     XRCCTRL(dlg, "spingraphlinewidth",wxSpinCtrl)->SetValue(programoptions.graphlinewidth);
2522     XRCCTRL(dlg, "chkrestoremainframe",wxCheckBox)->SetValue(programoptions.restoremainframe);
2523     XRCCTRL(dlg, "chkhidemainframe",wxCheckBox)->SetValue(programoptions.hidemainframe);
2524     XRCCTRL(dlg, "chkcheckforupdates",wxCheckBox)->SetValue(programoptions.checkforupdates);
2525     XRCCTRL(dlg, "chkgraphshow",wxCheckBox)->SetValue(programoptions.graphshow);
2526     XRCCTRL(dlg, "graphpanelback", mBoxOptionsColorPanel)->colour = programoptions.graphbackcolor;
2527     XRCCTRL(dlg, "graphpanelgrid", mBoxOptionsColorPanel)->colour = programoptions.graphgridcolor;
2528     XRCCTRL(dlg, "graphpanelline", mBoxOptionsColorPanel)->colour = programoptions.graphlinecolor;
2529     XRCCTRL(dlg, "graphpanelfont", mBoxOptionsColorPanel)->colour = programoptions.graphfontcolor;
2530     XRCCTRL(dlg, "chkactivatescheduling",wxCheckBox)->SetValue(programoptions.activatescheduling);
2531     XRCCTRL(dlg, "edtstartdate",wxTextCtrl)->SetValue(programoptions.startdatetime.Format(wxT("%Y/%m/%d")));
2532     XRCCTRL(dlg, "edtfinishdate",wxTextCtrl)->SetValue(programoptions.finishdatetime.Format(wxT("%Y/%m/%d")));
2533     XRCCTRL(dlg, "spinstarthour",wxSpinCtrl)->SetValue(programoptions.startdatetime.GetHour());
2534     XRCCTRL(dlg, "spinstartminute",wxSpinCtrl)->SetValue(programoptions.startdatetime.GetMinute());
2535     XRCCTRL(dlg, "spinfinishhour",wxSpinCtrl)->SetValue(programoptions.finishdatetime.GetHour());
2536     XRCCTRL(dlg, "spinfinishminute",wxSpinCtrl)->SetValue(programoptions.finishdatetime.GetMinute());
2537     for (i=0; i<7;i++)
2538         XRCCTRL(dlg, "comboweekdays",wxComboBox)->Append(
2539                                         wxGetTranslation(days[i]));
2540     XRCCTRL(dlg, "comboweekdays",wxComboBox)->SetValue(wxGetTranslation(days[0]));
2541     for (i=0;i<MAX_SCHEDULE_EXCEPTIONS;i++)
2542     {
2543         if (programoptions.scheduleexceptions[i].isactive)
2544         {
2545             wxString temp = programoptions.scheduleexceptions[i].start + wxT(" | ") +
2546                             programoptions.scheduleexceptions[i].finish + wxT(" | ") +
2547                             XRCCTRL(dlg, "comboweekdays",wxComboBox)->GetString(programoptions.scheduleexceptions[i].day);
2548             XRCCTRL(dlg, "lstexceptionlist",wxListBox)->InsertItems(1,&temp,0);
2549         }
2550     }
2551     if (programoptions.bandwidthoption == 1)
2552         XRCCTRL(dlg, "optbandwidthindependently", wxRadioButton)->SetValue(TRUE);
2553     else if (programoptions.bandwidthoption == 2)
2554         XRCCTRL(dlg, "optbandwidthcustom", wxRadioButton)->SetValue(TRUE);
2555     else
2556         XRCCTRL(dlg, "optbandwidthunlimited", wxRadioButton)->SetValue(TRUE);
2557     XRCCTRL(dlg, "spinbandwithcustom", wxSpinCtrl)->SetValue(programoptions.bandwidth);
2558     XRCCTRL(dlg, "chkproxy",wxCheckBox)->SetValue(programoptions.proxy);
2559     XRCCTRL(dlg, "edtproxyserver",wxTextCtrl)->SetValue(programoptions.proxy_server);
2560     XRCCTRL(dlg, "edtproxyport",wxTextCtrl)->SetValue(programoptions.proxy_port);
2561     if (!programoptions.proxy_username.IsEmpty())
2562     {
2563         XRCCTRL(dlg, "edtproxyusername",wxTextCtrl)->SetValue(programoptions.proxy_username);
2564         XRCCTRL(dlg, "edtproxypassword",wxTextCtrl)->SetValue(wxT("#NOPASSWORD#"));
2565     }
2566 
2567 
2568     this->active = FALSE;
2569     if (dlg.ShowModal() == XRCID("btnoptionsave"))
2570     {
2571         wxProgressDialog *waitbox = new wxProgressDialog(_("Updating the configuration..."),_("Updating and saving the configuration..."),100,NULL,wxPD_AUTO_HIDE | wxPD_APP_MODAL|wxPD_CAN_ABORT|wxPD_ELAPSED_TIME);
2572         waitbox->Update(0);
2573         #ifndef DISABLE_MUTEX
2574         mutex_programoptions->Lock();
2575         #endif
2576 
2577         programoptions.attempts = XRCCTRL(dlg, "spinattempts", wxSpinCtrl)->GetValue();
2578         programoptions.attemptstime = XRCCTRL(dlg, "spinattemptstime", wxSpinCtrl)->GetValue();
2579         programoptions.simultaneous = XRCCTRL(dlg, "spinsimultaneous", wxSpinCtrl)->GetValue();
2580         programoptions.shutdowncmd = XRCCTRL(dlg, "edtshutdown",wxTextCtrl)->GetValue();
2581         programoptions.disconnectcmd = XRCCTRL(dlg, "edtdisconnect",wxTextCtrl)->GetValue();
2582         programoptions.closedialog = XRCCTRL(dlg, "chkclosedialog",wxCheckBox)->GetValue();
2583         programoptions.alwaysshutdown = XRCCTRL(dlg, "chkshutdown",wxCheckBox)->GetValue();
2584         programoptions.alwaysdisconnect = XRCCTRL(dlg, "chkdisconnect",wxCheckBox)->GetValue();
2585         programoptions.rememberboxnewoptions = XRCCTRL(dlg, "chkrememberboxnewoptions",wxCheckBox)->GetValue();
2586         if (programoptions.destination != XRCCTRL(dlg, "edtdestination",wxTextCtrl)->GetValue())
2587         {
2588             programoptions.destination = XRCCTRL(dlg, "edtdestination",wxTextCtrl)->GetValue();
2589             programoptions.lastdestination = programoptions.destination;
2590         }
2591         programoptions.browserpath = XRCCTRL(dlg, "edtbrowserpath",wxTextCtrl)->GetValue();
2592         programoptions.filemanagerpath = XRCCTRL(dlg, "edtfilemanagerpath",wxTextCtrl)->GetValue();
2593 
2594         if (XRCCTRL(dlg, "optdefaulttemp",wxRadioButton)->GetValue())
2595             programoptions.downloadpartsdefaultdir = wxEmptyString;
2596         else
2597             programoptions.downloadpartsdefaultdir = XRCCTRL(dlg, "edttemppath",wxTextCtrl)->GetValue();
2598 
2599         programoptions.timerupdateinterval = XRCCTRL(dlg, "spintimerinterval",wxSpinCtrl)->GetValue();
2600         programoptions.readbuffersize = XRCCTRL(dlg, "spinreadbuffersize",wxSpinCtrl)->GetValue();
2601         programoptions.restoremainframe = XRCCTRL(dlg, "chkrestoremainframe",wxCheckBox)->GetValue();
2602         programoptions.hidemainframe = XRCCTRL(dlg, "chkhidemainframe",wxCheckBox)->GetValue();
2603         programoptions.checkforupdates = XRCCTRL(dlg, "chkcheckforupdates",wxCheckBox)->GetValue();
2604         programoptions.graphshow = XRCCTRL(dlg, "chkgraphshow",wxCheckBox)->GetValue();
2605         programoptions.graphhowmanyvalues = XRCCTRL(dlg, "spingraphpoints",wxSpinCtrl)->GetValue();
2606         programoptions.graphrefreshtime = XRCCTRL(dlg, "spingraphrefreshrate",wxSpinCtrl)->GetValue();
2607         programoptions.graphscale = XRCCTRL(dlg, "spingraphmaxvalue",wxSpinCtrl)->GetValue();
2608         programoptions.graphtextarea = XRCCTRL(dlg, "spingraphtextarea",wxSpinCtrl)->GetValue();
2609         programoptions.graphheight = XRCCTRL(dlg, "spingraphheight",wxSpinCtrl)->GetValue();
2610         programoptions.graphspeedfontsize = XRCCTRL(dlg, "spingraphfontsize",wxSpinCtrl)->GetValue();
2611         programoptions.graphlinewidth = XRCCTRL(dlg, "spingraphlinewidth",wxSpinCtrl)->GetValue();
2612         programoptions.graphbackcolor = XRCCTRL(dlg, "graphpanelback", mBoxOptionsColorPanel)->colour;
2613         programoptions.graphgridcolor = XRCCTRL(dlg, "graphpanelgrid", mBoxOptionsColorPanel)->colour;
2614         programoptions.graphlinecolor = XRCCTRL(dlg, "graphpanelline", mBoxOptionsColorPanel)->colour;
2615         programoptions.graphfontcolor = XRCCTRL(dlg, "graphpanelfont", mBoxOptionsColorPanel)->colour;
2616         programoptions.activatescheduling = FALSE;
2617         programoptions.startdatetime.ParseDate(XRCCTRL(dlg, "edtstartdate",wxTextCtrl)->GetValue());
2618         programoptions.startdatetime.SetHour(XRCCTRL(dlg, "spinstarthour",wxSpinCtrl)->GetValue());
2619         programoptions.startdatetime.SetMinute(XRCCTRL(dlg, "spinstartminute",wxSpinCtrl)->GetValue());
2620         programoptions.finishdatetime.ParseDate(XRCCTRL(dlg, "edtfinishdate",wxTextCtrl)->GetValue());
2621         programoptions.finishdatetime.SetHour(XRCCTRL(dlg, "spinfinishhour",wxSpinCtrl)->GetValue());
2622         programoptions.finishdatetime.SetMinute(XRCCTRL(dlg, "spinfinishminute",wxSpinCtrl)->GetValue());
2623         waitbox->Update(20);
2624         for (i=0;i<MAX_SCHEDULE_EXCEPTIONS;i++)
2625         {
2626             if (i < XRCCTRL(dlg, "lstexceptionlist",wxListBox)->GetCount())
2627             {
2628                 wxString temp = XRCCTRL(dlg, "lstexceptionlist",wxListBox)->GetString(i);
2629                 programoptions.scheduleexceptions[i].newstart = temp.Mid(0,5);
2630                 programoptions.scheduleexceptions[i].newfinish = temp.Mid(8,5);
2631                 for (j = 0;j <7;j++)
2632                     if (temp.Mid(16) == wxGetTranslation(days[j]))
2633                     {
2634                         programoptions.scheduleexceptions[i].newday = j;
2635                         break;
2636                     }
2637             }
2638             else
2639             {
2640                 programoptions.scheduleexceptions[i].newstart = wxEmptyString;
2641                 programoptions.scheduleexceptions[i].newfinish = wxEmptyString;
2642                 programoptions.scheduleexceptions[i].newday = 0;
2643             }
2644             mApplication::Configurations(WRITE,OPT_SCHED_SCHEDULEEXCEPTION_ISACTIVE_REG+MyUtilFunctions::int2wxstr(i), programoptions.scheduleexceptions[i].isactive);
2645             mApplication::Configurations(WRITE,OPT_SCHED_SCHEDULEEXCEPTION_START_REG+MyUtilFunctions::int2wxstr(i), programoptions.scheduleexceptions[i].start);
2646             mApplication::Configurations(WRITE,OPT_SCHED_SCHEDULEEXCEPTION_FINISH_REG+MyUtilFunctions::int2wxstr(i), programoptions.scheduleexceptions[i].finish);
2647             mApplication::Configurations(WRITE,OPT_SCHED_SCHEDULEEXCEPTION_DAY_REG+MyUtilFunctions::int2wxstr(i), programoptions.scheduleexceptions[i].day);
2648         }
2649         programoptions.scheduleexceptionschanged = TRUE;
2650         if ((XRCCTRL(dlg, "chkactivatescheduling",wxCheckBox)->GetValue()) && (programoptions.startdatetime < programoptions.finishdatetime))
2651             programoptions.activatescheduling = TRUE;
2652         else
2653             programoptions.activatescheduling = FALSE;
2654 
2655         if (XRCCTRL(dlg, "optbandwidthindependently", wxRadioButton)->GetValue())
2656         {
2657             programoptions.bandwidthoption = 1;
2658             if (statusbar)
2659             {
2660                 wxString temp = _("Band control");
2661                 temp += wxT(": ");
2662                 temp += _("Per Download");
2663                 statusbar->SetStatusText(temp,2);
2664             }
2665         }
2666         else if (XRCCTRL(dlg, "optbandwidthcustom", wxRadioButton)->GetValue())
2667         {
2668             programoptions.bandwidthoption = 2;
2669             programoptions.bandwidth = XRCCTRL(dlg, "spinbandwithcustom", wxSpinCtrl)->GetValue();
2670             if (statusbar)
2671             {
2672                 wxString temp = _("Band control");
2673                 temp += wxT(": ");
2674                 temp += _("Active");
2675                 temp += wxT(" (") + MyUtilFunctions::int2wxstr(programoptions.bandwidth) + wxT(" kB/s)");
2676                 statusbar->SetStatusText(temp,2);
2677             }
2678         }
2679         else
2680         {
2681             programoptions.bandwidthoption = 0;
2682             if (statusbar)
2683             {
2684                 wxString temp = _("Band control");
2685                 temp += wxT(": ");
2686                 temp += _("Unlimited");
2687                 statusbar->SetStatusText(temp,2);
2688             }
2689         }
2690         programoptions.proxy = XRCCTRL(dlg, "chkproxy",wxCheckBox)->GetValue();
2691         if (programoptions.proxy)
2692         {
2693             programoptions.proxy_server = XRCCTRL(dlg, "edtproxyserver",wxTextCtrl)->GetValue();
2694             programoptions.proxy_port = XRCCTRL(dlg, "edtproxyport",wxTextCtrl)->GetValue();
2695             programoptions.proxy_username = XRCCTRL(dlg, "edtproxyusername",wxTextCtrl)->GetValue();
2696             if (!programoptions.proxy_username.IsEmpty())
2697             {
2698                 if (XRCCTRL(dlg, "edtproxypassword",wxTextCtrl)->GetValue() != wxT("#NOPASSWORD#"))
2699                     programoptions.proxy_authstring = MyUtilFunctions::GenerateAuthString(programoptions.proxy_username,
2700                                                                         XRCCTRL(dlg, "edtproxypassword",wxTextCtrl)->GetValue());
2701             }
2702             else
2703                 programoptions.proxy_authstring = wxEmptyString;
2704         }
2705         else
2706         {
2707             programoptions.proxy_username = wxEmptyString;
2708             programoptions.proxy_authstring = wxEmptyString;
2709         }
2710 
2711         waitbox->Update(50);
2712         mApplication::Configurations(WRITE,OPT_DIALOG_CLOSE_REG,programoptions.closedialog);
2713         mApplication::Configurations(WRITE,OPT_REMEMBER_BOXNEW_OPTIONS_REG,programoptions.rememberboxnewoptions);
2714         mApplication::Configurations(WRITE,OPT_DESTINATION_REG,programoptions.destination);
2715         mApplication::Configurations(WRITE,OPT_BROWSER_PATH_REG,programoptions.browserpath);
2716         mApplication::Configurations(WRITE,OPT_FILE_MANAGER_PATH_REG,programoptions.filemanagerpath);
2717         mApplication::Configurations(WRITE,OPT_DOWNLOAD_PARTS_DEFAULT_DIR_REG,programoptions.downloadpartsdefaultdir);
2718         mApplication::Configurations(WRITE,OPT_ATTEMPTS_REG,programoptions.attempts);
2719         mApplication::Configurations(WRITE,OPT_ATTEMPTS_TIME_REG,programoptions.attemptstime);
2720         mApplication::Configurations(WRITE,OPT_SIMULTANEOUS_REG,programoptions.simultaneous);
2721         mApplication::Configurations(WRITE,OPT_SHUTDOWN_REG,programoptions.alwaysshutdown);
2722         mApplication::Configurations(WRITE,OPT_DISCONNECT_REG,programoptions.alwaysdisconnect);
2723         mApplication::Configurations(WRITE,OPT_SHUTDOWN_CMD_REG,programoptions.shutdowncmd);
2724         mApplication::Configurations(WRITE,OPT_DISCONNECT_CMD_REG,programoptions.disconnectcmd);
2725         mApplication::Configurations(WRITE,OPT_TIMERINTERVAL_REG,programoptions.timerupdateinterval);
2726         mApplication::Configurations(WRITE,OPT_READBUFFERSIZE_REG,programoptions.readbuffersize);
2727         mApplication::Configurations(WRITE,OPT_RESTORE_MAINFRAME_REG, programoptions.restoremainframe);
2728         mApplication::Configurations(WRITE,OPT_HIDE_MAINFRAME_REG, programoptions.hidemainframe);
2729         mApplication::Configurations(WRITE,OPT_CHECK_FOR_UPDATES_REG, programoptions.checkforupdates);
2730         mApplication::Configurations(WRITE,OPT_GRAPH_SHOW_REG,programoptions.graphshow);
2731         mApplication::Configurations(WRITE,OPT_GRAPH_HOWMANYVALUES_REG, programoptions.graphhowmanyvalues);
2732         mApplication::Configurations(WRITE,OPT_GRAPH_REFRESHTIME_REG, programoptions.graphrefreshtime);
2733         mApplication::Configurations(WRITE,OPT_GRAPH_SCALE_REG, programoptions.graphscale);
2734         mApplication::Configurations(WRITE,OPT_GRAPH_TEXTAREA_REG, programoptions.graphtextarea);
2735         mApplication::Configurations(WRITE,OPT_GRAPH_HEIGHT_REG, programoptions.graphheight);
2736         mApplication::Configurations(WRITE,OPT_GRAPH_SPEEDFONTSIZE_REG, programoptions.graphspeedfontsize);
2737         mApplication::Configurations(WRITE,OPT_GRAPH_LINEWIDTH_REG, programoptions.graphlinewidth);
2738         waitbox->Update(70);
2739         {
2740             wxString red,green,blue;
2741             red.Printf(wxT("%.3d"), programoptions.graphbackcolor.Red());
2742             green.Printf(wxT("%.3d"), programoptions.graphbackcolor.Green());
2743             blue.Printf(wxT("%.3d"), programoptions.graphbackcolor.Blue());
2744             mApplication::Configurations(WRITE,OPT_GRAPH_COLORBACK_REG, red + wxT("-") + green + wxT("-") + blue);
2745         }
2746         {
2747             wxString red,green,blue;
2748             red.Printf(wxT("%.3d"), programoptions.graphgridcolor.Red());
2749             green.Printf(wxT("%.3d"), programoptions.graphgridcolor.Green());
2750             blue.Printf(wxT("%.3d"), programoptions.graphgridcolor.Blue());
2751             mApplication::Configurations(WRITE,OPT_GRAPH_COLORGRID_REG, red + wxT("-") + green + wxT("-") + blue);
2752         }
2753         {
2754             wxString red,green,blue;
2755             red.Printf(wxT("%.3d"), programoptions.graphlinecolor.Red());
2756             green.Printf(wxT("%.3d"), programoptions.graphlinecolor.Green());
2757             blue.Printf(wxT("%.3d"), programoptions.graphlinecolor.Blue());
2758             mApplication::Configurations(WRITE,OPT_GRAPH_COLORLINE_REG, red + wxT("-") + green + wxT("-") + blue);
2759         }
2760         {
2761             wxString red,green,blue;
2762             red.Printf(wxT("%.3d"), programoptions.graphfontcolor.Red());
2763             green.Printf(wxT("%.3d"), programoptions.graphfontcolor.Green());
2764             blue.Printf(wxT("%.3d"), programoptions.graphfontcolor.Blue());
2765             mApplication::Configurations(WRITE,OPT_GRAPH_COLORFONT_REG, red + wxT("-") + green + wxT("-") + blue);
2766         }
2767         waitbox->Update(90);
2768         mApplication::Configurations(WRITE,OPT_SCHED_ACTIVATESCHEDULING_REG, programoptions.activatescheduling);
2769         mApplication::Configurations(WRITE,OPT_SCHED_STARTDATETIME_REG, (long)programoptions.startdatetime.GetTicks());
2770         mApplication::Configurations(WRITE,OPT_SCHED_FINISHDATETIME_REG, (long)programoptions.finishdatetime.GetTicks());
2771         mApplication::Configurations(WRITE,OPT_BAND_WIDTH_OPTION_REG, programoptions.bandwidthoption);
2772         mApplication::Configurations(WRITE,OPT_BAND_WIDTH_GENERAL_REG, programoptions.bandwidth);
2773         mApplication::Configurations(WRITE,OPT_PROXY_REG,programoptions.proxy);
2774         mApplication::Configurations(WRITE,OPT_PROXY_SERVER_REG,programoptions.proxy_server);
2775         mApplication::Configurations(WRITE,OPT_PROXY_PORT_REG,programoptions.proxy_port);
2776         mApplication::Configurations(WRITE,OPT_PROXY_USERNAME_REG,programoptions.proxy_username);
2777         mApplication::Configurations(WRITE,OPT_PROXY_AUTHSTRING_REG,programoptions.proxy_authstring);
2778 
2779         ShowHideResizeGraph(oldgraphheight); //VERIFY IF THE GRAPH SIZE AND STATUS CHANGED
2780 
2781         waitbox->Update(100);
2782         delete waitbox;
2783         #ifndef DISABLE_MUTEX
2784         mutex_programoptions->Unlock();
2785         #endif
2786     }
2787     this->active = TRUE;
2788 }
2789 
OnSite(wxCommandEvent & event)2790 void mMainFrame::OnSite(wxCommandEvent& event)
2791 {
2792     if (::wxFileExists(programoptions.browserpath))
2793         ::wxExecute(programoptions.browserpath + wxT(" \"http://dfast.sourceforge.net\""));
2794     else
2795     {
2796         wxMessageBox(_("Unable to find the browser.\nGo to \"Options\" and specify a valid one."),
2797                 _("Error..."),wxOK | wxICON_ERROR, this);
2798     }
2799 }
2800 
OnBug(wxCommandEvent & event)2801 void mMainFrame::OnBug(wxCommandEvent& event)
2802 {
2803     if (::wxFileExists(programoptions.browserpath))
2804         ::wxExecute(programoptions.browserpath + wxT(" \"http://dfast.sourceforge.net/reportbugs.php\""));
2805     else
2806     {
2807         wxMessageBox(_("Unable to find the browser.\nGo to \"Options\" and specify a valid one."),
2808                 _("Error..."),wxOK | wxICON_ERROR, this);
2809     }
2810 }
2811 
OnDonate(wxCommandEvent & event)2812 void mMainFrame::OnDonate(wxCommandEvent& event)
2813 {
2814     if (::wxFileExists(programoptions.browserpath))
2815         ::wxExecute(programoptions.browserpath + wxT(" \"http://dfast.sourceforge.net/donate.php\""));
2816     else
2817     {
2818         wxMessageBox(_("Unable to find the browser.\nGo to \"Options\" and specify a valid one."),
2819                 _("Error..."),wxOK | wxICON_ERROR, this);
2820     }
2821 }
2822 
OnAbout(wxCommandEvent & WXUNUSED (event))2823 void mMainFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
2824 {
2825     wxDialog dlg;
2826     wxXmlResource::Get()->LoadDialog(&dlg, this, wxT("boxabout"));
2827     wxString aboutstring;
2828     aboutstring  = _("Version: ") + VERSION + wxT("\n");
2829     aboutstring += _("Author: ");
2830     aboutstring += wxT("Max Magalhães Velasques\n\n");
2831     aboutstring += _("I'd like to thank the following contributors for their help:\n");
2832     aboutstring += wxT("Anthony Brian");
2833     aboutstring += _(" - several tips and donations\n");
2834     aboutstring += wxT("Erno Szabados");
2835     aboutstring += _(" - Ripstop theme\n\n");
2836     aboutstring += _("Visit our website:\n");
2837     aboutstring += wxT("http://dfast.sourceforge.net");
2838     aboutstring += wxT("\n\n");
2839     aboutstring += _("Help to improve the program!\n");
2840     aboutstring += _("Donate to this project!");
2841 
2842     XRCCTRL(dlg, "wxdfastabouttext",wxTextCtrl)->SetValue(aboutstring);
2843 
2844     dlg.ShowModal();
2845     if (programoptions.checkforupdates)
2846         CheckNewRelease();
2847 }
2848 
OnExit(wxCommandEvent & event)2849 void mMainFrame::OnExit(wxCommandEvent& event)
2850 {
2851    Close();
2852 }
2853 
OnClose(wxCloseEvent & event)2854 void mMainFrame::OnClose(wxCloseEvent& event)
2855 {
2856     int closedialog = programoptions.closedialog;
2857     if (event.CanVeto())
2858     {
2859         if ((closedialog) && (this->IsShown()))
2860         {
2861             wxMessageDialog *dlg = new wxMessageDialog(this, _("Do you want to close the program?"),_("Close..."),
2862                         wxYES_NO | wxICON_QUESTION);
2863             if (dlg)
2864             {
2865                 dlg->Centre(wxBOTH);
2866                 this->active = FALSE;
2867                 if (dlg->ShowModal() == wxID_YES)
2868                 {
2869                     this->active = TRUE;
2870                     event.Skip();
2871                     dlg->Destroy();
2872                 }
2873                 else
2874                 {
2875                     this->active = TRUE;
2876                     event.Veto();
2877                     dlg->Destroy();
2878                     return ;
2879                 }
2880             }
2881         }
2882         else
2883         {
2884             event.Skip();
2885         }
2886     }
2887     else
2888         event.Skip();
2889     mtimer->Stop();
2890     wxCommandEvent stopwithoutsavingstopstatus;
2891     stopwithoutsavingstopstatus.SetString(STOPWITHOUTSAVINGSTOPSTATUS);
2892     OnStopAll(stopwithoutsavingstopstatus);
2893 }
2894 
OnToolLeftClick(wxCommandEvent & event)2895 void mMainFrame::OnToolLeftClick(wxCommandEvent& event)
2896 {
2897     int id = event.GetId();
2898     if (id == XRCID("toolnew"))
2899     {
2900         OnNew(event);
2901     }
2902     else if (id == XRCID("toolremove"))
2903     {
2904         OnRemove(event);
2905     }
2906     else if (id == XRCID("toolschedule"))
2907     {
2908         OnSchedule(event);
2909     }
2910     else if (id == XRCID("toolstart"))
2911     {
2912         OnStart(event);
2913     }
2914     else if (id == XRCID("toolstop"))
2915     {
2916         OnStop(event);
2917     }
2918     else if (id == XRCID("toolstartall"))
2919     {
2920         OnStartAll(event);
2921     }
2922     else if (id == XRCID("toolstopall"))
2923     {
2924         OnStopAll(event);
2925     }
2926     else if (id == XRCID("toolup"))
2927     {
2928         OnUpDown(TRUE);
2929     }
2930     else if (id == XRCID("tooldown"))
2931     {
2932         OnUpDown(FALSE);
2933     }
2934     else if (id == XRCID("toolproperties"))
2935     {
2936         OnProperties(event);
2937     }
2938     else if (id == XRCID("toolclose"))
2939     {
2940         OnExit(event);
2941     }
2942 }
2943 
OnToolMouseMove(wxCommandEvent & event)2944 void mMainFrame::OnToolMouseMove(wxCommandEvent& event)
2945 {
2946     if (!statusbar)
2947         return;
2948     int selection = event.GetSelection();
2949     if (selection == XRCID("toolnew"))
2950     {
2951         statusbar->SetStatusText(_("Add new download"));
2952     }
2953     else if (selection == XRCID("toolremove"))
2954     {
2955         statusbar->SetStatusText(_("Remove the selected download"));
2956     }
2957     else if (selection == XRCID("toolschedule"))
2958     {
2959         statusbar->SetStatusText(_("Mark the selected download as scheduled"));
2960     }
2961     else if (selection == XRCID("toolstart"))
2962     {
2963         statusbar->SetStatusText(_("Start the selected download"));
2964     }
2965     else if (selection == XRCID("toolstop"))
2966     {
2967         statusbar->SetStatusText(_("Stop the selected download"));
2968     }
2969     else if (selection == XRCID("toolstartall"))
2970     {
2971         statusbar->SetStatusText(_("Start all downloads"));
2972     }
2973     else if (selection == XRCID("toolstopall"))
2974     {
2975         statusbar->SetStatusText(_("Stop all downloads"));
2976     }
2977     else if (selection == XRCID("toolup"))
2978     {
2979         statusbar->SetStatusText(_("Raise in one level the selected download in the queue"));
2980     }
2981     else if (selection == XRCID("tooldown"))
2982     {
2983         statusbar->SetStatusText(_("Lower in one level the selected download in the queue"));
2984     }
2985     else if (selection == XRCID("toolproperties"))
2986     {
2987         statusbar->SetStatusText(_("Show the properties of the selected download"));
2988     }
2989     else if (selection == XRCID("toolclose"))
2990     {
2991         statusbar->SetStatusText(_("Close the program"));
2992     }
2993     else
2994         statusbar->SetStatusText(this->defaultstatusbarmessage);
2995 }
2996 
BrowserFile()2997 void mMainFrame::BrowserFile()
2998 {
2999     int selection;
3000     mFinishedList *list = XRCCTRL(*this, "finishedlist",mFinishedList );
3001     if ((selection = list->GetCurrentLastSelection()) >= 0)
3002     {
3003         list->SetCurrentSelection(selection);
3004         #ifdef WXDFAST_PORTABLE
3005         wxFileConfig *config = new wxFileConfig(DFAST_REG, wxEmptyString, DFAST_REG + wxT(".ini"), wxEmptyString,
3006                                                 wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_RELATIVE_PATH);
3007         #else
3008         wxFileConfig *config = new wxFileConfig(DFAST_REG);
3009         #endif
3010         wxString filepath;
3011         config->SetPath(FINISHED_REG);
3012         wxListItem item;
3013         item.SetId(selection);
3014         item.SetColumn(FINISHED_NAME);
3015         item.SetMask(wxLIST_MASK_DATA|wxLIST_MASK_STATE|wxLIST_MASK_TEXT|wxLIST_MASK_IMAGE);
3016         list->GetItem(item);
3017         config->SetPath(item.GetText());
3018         filepath = wxEmptyString;
3019         config->Read(DESTINATION_REG,&filepath);
3020         #ifdef WXDFAST_PORTABLE
3021         {
3022             #ifdef __WXMSW__
3023             wxFileName destinationtmp(filepath);
3024             if (destinationtmp.GetVolume().Upper() == wxT("PORTABLE"))
3025             {
3026                 destinationtmp.SetVolume(wxGetApp().programvolume);
3027                 filepath = destinationtmp.GetFullPath();
3028             }
3029             #endif
3030         }
3031         #endif
3032         delete config;
3033         ::wxExecute(programoptions.filemanagerpath + wxT(" \"") + filepath + wxT("\""));
3034     }
3035 }
3036 
OnOpenURL(wxCommandEvent & event)3037 void mMainFrame::OnOpenURL(wxCommandEvent& event)
3038 {
3039     if (wxMessageBox(_("You have downloaded a HTML file.\nOpen this file in your browser?"),
3040                     _("Continue..."),wxYES | wxNO | wxICON_QUESTION, this) == wxYES)
3041     {
3042         if (::wxFileExists(programoptions.browserpath))
3043             ::wxExecute(programoptions.browserpath + wxT(" \"") + event.GetString() + wxT("\""));
3044         else
3045         {
3046             wxMessageBox(_("Unable to find the browser.\nGo to \"Options\" and specify a valid one."),
3047                     _("Error..."),wxOK | wxICON_ERROR, this);
3048         }
3049     }
3050 }
3051 
OnShutdownEvent(wxCommandEvent & event)3052 void mMainFrame::OnShutdownEvent(wxCommandEvent& event)
3053 {
3054     wxStopWatch waittime;
3055     waittime.Start();
3056     wxProgressDialog *waitbox = new wxProgressDialog(_("Shutting down the computer..."),_("The computer will shut down in seconds..."),30000,NULL,wxPD_AUTO_HIDE | wxPD_APP_MODAL|wxPD_CAN_ABORT|wxPD_REMAINING_TIME);
3057     while ((waittime.Time() < 30000) && (waitbox->Update(waittime.Time())))
3058         wxMilliSleep(200);
3059     delete waitbox;
3060     if (waittime.Time() >= 30000)
3061     {
3062         if (this->IsShown())
3063         {
3064             wxCommandEvent iconizeevent;
3065             taskbaricon->OnHide(iconizeevent);
3066         }
3067         wxMilliSleep(200);
3068         ::wxExecute(programoptions.shutdowncmd);
3069     }
3070 }
3071 
OnDisconnectEvent(wxCommandEvent & event)3072 void mMainFrame::OnDisconnectEvent(wxCommandEvent& event)
3073 {
3074     wxStopWatch waittime;
3075     waittime.Start();
3076     wxProgressDialog *waitbox = new wxProgressDialog(_("Disconnecting from the Internet..."),_("The Internet connection will be closed in seconds..."),30000,NULL,wxPD_AUTO_HIDE | wxPD_APP_MODAL|wxPD_CAN_ABORT|wxPD_REMAINING_TIME);
3077     while ((waitbox->Update(waittime.Time())) && (waittime.Time() < 30000))
3078         wxMilliSleep(200);
3079     delete waitbox;
3080     if (waittime.Time() >= 30000)
3081         ::wxExecute(programoptions.disconnectcmd);
3082 }
3083 
OnExecuteEvent(wxCommandEvent & event)3084 void mMainFrame::OnExecuteEvent(wxCommandEvent& event)
3085 {
3086     ::wxExecute(event.GetString());
3087 }
3088 
UpdateListItemField(mDownloadFile * current)3089 bool mMainFrame::UpdateListItemField(mDownloadFile *current)
3090 {
3091     mInProgressList* list01 = XRCCTRL(*this, "inprogresslist",mInProgressList );
3092     bool result = FALSE;
3093     if (current)
3094     {
3095         if (!current->WaitingForSplit())
3096         {
3097             int i,parts;
3098             current->totalsizecompleted = 0;
3099 
3100             for (i=0; i < current->GetNumberofParts(); i++)
3101                 current->totalsizecompleted += current->sizecompleted[i];
3102             if (current->totalspeed > 0)
3103                 current->timeremaining = wxLongLong(0l,1000l)*(current->totalsize - current->totalsizecompleted)/wxLongLong(0l,current->totalspeed);
3104             if (current->totalsize > 0)
3105                 current->SetProgress((int)(100*( MyUtilFunctions::wxlonglongtodouble(current->totalsizecompleted)) / ( MyUtilFunctions::wxlonglongtodouble(current->totalsize))));
3106 
3107             if ((!current->IsSplitted()) && (current->GetStatus() == STATUS_ACTIVE))
3108                 parts = 1;
3109             else
3110                 parts = current->GetNumberofParts();
3111 
3112             int proportion = 100/parts;
3113             for (int i = 0; i < parts;i++)
3114             {
3115                 if (current->totalsize > 0)
3116                 {
3117                     if (i == (parts-1))
3118                     {
3119                         current->percentualparts[i] = (100 - ((parts-1)*proportion))-(int)(100*(MyUtilFunctions::wxlonglongtodouble(current->size[i] -
3120                                                       current->sizecompleted[i]) / MyUtilFunctions::wxlonglongtodouble(current->totalsize)));
3121                     }
3122                     else
3123                     {
3124                         current->percentualparts[i] = (proportion)-(int)(100*(MyUtilFunctions::wxlonglongtodouble(current->size[i] -
3125                                                       current->sizecompleted[i]) / MyUtilFunctions::wxlonglongtodouble(current->totalsize)));
3126                     }
3127                 }
3128                 else
3129                     current->percentualparts[i] = 0;
3130             }
3131             result = TRUE;
3132         }
3133         list01->Insert(current,wxGetApp().downloadlist.IndexOf(current));
3134     }
3135     return result;
3136 }
3137 
CheckNewRelease()3138 void mMainFrame::CheckNewRelease()
3139 {
3140     mCheckNewReleaseThread *thread = new mCheckNewReleaseThread();
3141     if ( thread->Create() != wxTHREAD_NO_ERROR )
3142     {
3143         wxMessageBox(_("Error creating thread!"));
3144     }
3145     else
3146     {
3147         if ( thread->Run() != wxTHREAD_NO_ERROR )
3148         {
3149             wxMessageBox(_("Error starting thread!"));
3150         }
3151     }
3152 }
3153 
OnNewRelease(wxCommandEvent & event)3154 void mMainFrame::OnNewRelease(wxCommandEvent& event)
3155 {
3156     programoptions.currentrelease = event.GetString();
3157     mApplication::Configurations(WRITE,OPT_CURRENT_RELEASE,programoptions.currentrelease);
3158 
3159     this->defaultstatusbarmessage = _("NEW RELEASE: ");
3160     this->defaultstatusbarmessage += wxT("wxDownload Fast ");
3161     this->defaultstatusbarmessage += programoptions.currentrelease + _(" is available.");
3162 
3163     wxMessageBox(wxT("wxDownload Fast ") + programoptions.currentrelease + _(" is available.") + wxT("\n") + _("Visit http://dfast.sourceforge.net for more informations."));
3164 }
3165 
OnFilePreview(wxCommandEvent & event)3166 void mMainFrame::OnFilePreview(wxCommandEvent& event)
3167 {
3168     mInProgressList *list = XRCCTRL(*this, "inprogresslist",mInProgressList );
3169     int currentselection;
3170     if ((currentselection = list->GetCurrentLastSelection()) >= 0)
3171     {
3172         wxFileName tempdestination;
3173         int lastpiece;
3174         wxLogNull nolog;
3175         mDownloadFile *currentfile = wxGetApp().downloadlist.Item(currentselection)->GetData();
3176         list->SetCurrentSelection(currentselection);
3177         if ((!currentfile->IsSplitted()) && (currentfile->GetStatus() == STATUS_ACTIVE))
3178             lastpiece = 0;
3179         else
3180             lastpiece = currentfile->GetNumberofParts()-1;
3181 
3182         tempdestination.Assign(currentfile->GetTemporaryDestination() + wxT("/"));
3183         tempdestination.SetFullName(PREFIX + currentfile->GetName() + EXT + MyUtilFunctions::int2wxstr(lastpiece));
3184         if (tempdestination.FileExists())
3185         {
3186             wxZipInputStream *zip = new wxZipInputStream(*(new wxFileInputStream(tempdestination.GetFullPath())));
3187             if (zip)
3188             {
3189                 wxZipEntry *currentzipentry;
3190                 if ((currentzipentry = zip->GetNextEntry()))
3191                 {
3192                     wxArrayString array;
3193                     do
3194                     {
3195                         if (currentzipentry->IsDir())
3196                             array.Add(currentzipentry->GetName() + wxT("/"));
3197                         else
3198                             array.Add(currentzipentry->GetName());
3199                     }while ((currentzipentry = zip->GetNextEntry()));
3200                     array.Sort();
3201                     wxSingleChoiceDialog dlg(this,_("List of files in Zip archive:"),_("Zip Preview"),array);
3202                     dlg.ShowModal();
3203                 }
3204                 else
3205                     wxMessageBox(_("Unable to extract zip file content!"),_("Error...") ,wxOK | wxICON_ERROR,this);
3206             }
3207             else
3208                 wxMessageBox(_("Unable to extract zip file content!"),_("Error...") ,wxOK | wxICON_ERROR,this);
3209         }
3210         else
3211             wxMessageBox(_("File not found."),_("Error...") ,wxOK | wxICON_ERROR,this);
3212     }
3213 }
3214 
OnNewDownloadEvent(wxCommandEvent & event)3215 void mMainFrame::OnNewDownloadEvent(wxCommandEvent& event)
3216 {
3217     mDownloadFile *file = (mDownloadFile *)event.GetClientObject();
3218     NewDownload(file->GetUrlArray(),file->GetDestination(),event.GetInt(),file->GetNumberofParts(),file->GetUser(),
3219                 file->GetPassword(),file->GetReferenceURL(),file->GetComments(),file->GetCommand(),programoptions.laststartoption,programoptions.lastontopoption, false,false);
3220 }
3221