1 
2 /***************************************************************************
3  *  mainframe.h
4  *
5  *  Wed Sep  6 22:19:52 2006
6  *  Copyright  2006  liubin,China
7  *  Email multiget@gmail.com
8  ****************************************************************************/
9 
10 /*
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24  */
25 
26 
27 
28 #ifndef _MAINFRAME_H
29 #define _MAINFRAME_H
30 #include "common.h"
31 
32 #include <wx/wx.h>
33 #include <wx/splitter.h>
34 #include <wx/msgdlg.h>
35 #include <wx/statusbr.h>
36 #include <wx/sound.h>
37 #include <pthread.h>
38 DECLARE_EVENT_TYPE( mgID_TIMER, -1 )
39 DECLARE_EVENT_TYPE( mgEVT_TASK_FINISH, -1 )
40 DECLARE_EVENT_TYPE( mgEVT_URL_NOTICE, -1 )
41 DECLARE_EVENT_TYPE( mgEVT_CMD_NOTICE, -1 )  //cmdline task
42 DECLARE_EVENT_TYPE( mgID_NEW_TASK, -1 )
43 DECLARE_EVENT_TYPE( mgID_START_TASK, -1 )
44 DECLARE_EVENT_TYPE( mgID_STOP_TASK, -1 )
45 DECLARE_EVENT_TYPE( mgID_CANCEL_TASK, -1 )
46 DECLARE_EVENT_TYPE( mgID_MOVEUP_TASK, -1 )
47 DECLARE_EVENT_TYPE( mgID_MOVEDOWN_TASK, -1 )
48 DECLARE_EVENT_TYPE( mgID_OPTION_CONFIG, -1 )
49 //DECLARE_EVENT_TYPE( mgEVT_TASK_FINISH, -1 )
50 //DECLARE_EVENT_TYPE( mgID_NEW_TASK, -1 )
51 DECLARE_EVENT_TYPE( mgID_SUBTHREAD, -1 );
52 DECLARE_EVENT_TYPE( mgID_ADDTHREAD, -1 );
53 DECLARE_EVENT_TYPE( mgID_RELOAD, -1 );
54 DECLARE_EVENT_TYPE( mgID_VIEW_LANG, -1 )
55 DECLARE_EVENT_TYPE( mgID_VIEW_LANG_EN_UTF8, -1 )
56 DECLARE_EVENT_TYPE( mgID_VIEW_LANG_CN_UTF8, -1 )
57 DECLARE_EVENT_TYPE( mgID_VIEW_LANG_GB18030, -1 )
58 DECLARE_EVENT_TYPE( mgID_VIEW_LANG_TW_BIG5, -1 )
59 DECLARE_EVENT_TYPE( mgID_VIEW_LANG_TW_UTF8, -1 )
60 DECLARE_EVENT_TYPE( mgID_VIEW_LANG_DE_UTF8, -1 )
61 
62 DECLARE_EVENT_TYPE( mgID_VIEW_TOOLBAR, -1 );
63 DECLARE_EVENT_TYPE( mgID_VIEW_TOOLBAR_SIZE16, -1 )
64 DECLARE_EVENT_TYPE( mgID_VIEW_TOOLBAR_SIZE24, -1 )
65 DECLARE_EVENT_TYPE( mgID_VIEW_TOOLBAR_SIZE32, -1 )
66 
67 DECLARE_EVENT_TYPE( mgID_VIEW_STATUSBAR, -1 );
68 DECLARE_EVENT_TYPE( mgID_OPTION_PROXY, -1 );
69 DECLARE_EVENT_TYPE( mgID_OPTION_PROPERTY, -1 );
70 
71 DECLARE_EVENT_TYPE( mgID_FILE_SAVECONFIG, -1 );
72 DECLARE_EVENT_TYPE( mgID_FILE_SAVETASK, -1 );
73 DECLARE_EVENT_TYPE( mgID_FILE_SAVEPROXY, -1 );
74 DECLARE_EVENT_TYPE( mgID_HELP_VISITHOME, -1 );
75 //
76 
77 class CRightDownSplitter;
78 
79 class CTaskManager;
80 
81 class CLeftTree;
82 
83 class CTaskList;
84 
85 class CMeterToolBar;
86 
87 class CMeterCtrl;
88 
89 class CFloatWin;
90 
91 class CSysTray;
92 
93 class CHideWin;
94 
95 class CMgConfig;
96 
97 class CNewTaskDlg;
98 
99 class CPropertyDlg;
100 //#ifndef __WXX11__
101 //class CDropUrl;
102 //#endif
103 static const long TOOLBAR_STYLE = wxTB_FLAT | wxTB_DOCKABLE ;
104 //static long TOOLBAR_SIZE  = 16;
105 //wxTB_HORIZONTAL|wxTB_FLAT|wxTB_TEXT
106 //wxTB_FLAT | wxTB_HORZ_TEXT
107 //wxTB_HORIZONTAL|wxTB_FLAT
108 
109 class MainFrame : public wxFrame
110 {
111 
112     friend class CSysTray;
113 
114     friend class CHideWin;
115 
116     friend class CTaskList;
117 
118     friend class CPropertyDlg;
119 
120 public:
121     // Constructor
122     MainFrame( const wxString& title );
123     virtual ~MainFrame();
124 
125     void OnSelectTask( int taskid );
126     void OnSelectType( _TASK_TYPE type );
127     int AddNewTask( std::string url, int threadnum = 0, bool autorun = true );
128     int StartTask( int ntask );
129     _TaskAttr* GetCurrentTask();
130     void OnShowModeSwitch( int mode );
131     void OnDropURL( wxString url );
GetFloatWin()132     CFloatWin* GetFloatWin()
133     {
134         return m_FloatWin;
135     };
136 
137     bool IsMonitorClip();
138     void MonitorClip( bool mo );
139     void StartAllTask();
140     void StopAllTask();
141     void OnAbout( wxCommandEvent& event );
142     void SwitchShowDropWin();
143     int	GetProxyCount();
144     _ProxyAttr& GetProxy( int seq );
145     void RemoveProxy( wxString name );
146     bool AddProxy( int type, wxString name, wxString server, int port, wxString user, wxString pass );
147     bool GetProxyByName( std::string name, int& type, std::string& server, int& port, std::string& user, std::string& pass );
148 
149 protected:
150     void SysTrayExitNotice();
151     void OnQuit( wxCommandEvent& event );
152     void OnConfig( wxCommandEvent& event );
153     void OnTimer( wxTimerEvent& event );
154     void OnSize( wxSizeEvent& event );
155     void OnClose( wxCloseEvent& event );
156     void OnMaximize( wxMaximizeEvent& event );
157 //    void OnDestroy( wxWindowDestroyEvent& );
158 //    void OnFocus( wxFocusEvent& );
159 //    void OnLostFocus( wxFocusEvent& );
160     void OnTaskFinish( wxCommandEvent& event );
161     void OnUrlNotice( wxCommandEvent& event );
162     void OnCmdNotice( wxCommandEvent& event );
163     void OnNewTask( wxCommandEvent& event );
164     void OnStartTask( wxCommandEvent& event );
165     void OnCancelTask( wxCommandEvent& event );
166     void OnStopTask( wxCommandEvent& event );
167     void OnProperty( wxCommandEvent& event );
168     void OnIncreaseThread( wxCommandEvent& event );
169     void OnDecreaseThread( wxCommandEvent& event );
170     void OnMoveDown( wxCommandEvent& event );
171     void OnMoveUp( wxCommandEvent& event );
172     void OnReloadFile( wxCommandEvent& event );
173     void OnWindowCreate( wxWindowCreateEvent& event );
174     void OnLangEnUtf8( wxCommandEvent& );
175     void OnLangCnUtf8( wxCommandEvent& );
176     void OnLangCn18030( wxCommandEvent& );
177     void OnLangTwBig5( wxCommandEvent& );
178     void OnLangTwUtf8( wxCommandEvent& );
179     void OnLangDeUtf8(wxCommandEvent& );
180     void UpdateMenuText();
181     void OnIconize( wxIconizeEvent& event );
182     void UpdateTaskList();
183     void UpdateRightDown();
184     void DynamicLang();
185     void ScheduleTask();
186     void OnStatusBar( wxCommandEvent& event );
187     void OnToolbarSize16( wxCommandEvent& );
188     void OnToolbarSize24( wxCommandEvent& );
189     void OnToolbarSize32( wxCommandEvent& );
190     void OnProxySetting( wxCommandEvent& );
191 
192 	void OnSaveConfig(wxCommandEvent& event);
193 	void OnSaveProxy(wxCommandEvent& event);
194 	void OnSaveTask(wxCommandEvent& event);
195 	void OnVisitHome(wxCommandEvent& event);
196 
197     void UpdateStatusBar();
198     void InitStatusBar();
199     void PlaySound( bool success );
200     void CreateSound( wxSound& snd, bool success );
201     void FileMd5( _TaskAttr& task );
202     std::string GetTempFileName( std::string url );
203     void UpdateTaskList( int ntask );
204     int GetFileType( std::string sname );
205     bool IsUrlExist( std::string url );
206     _TASK_TYPE GetStatusByFileType( int type );
207     _TaskAttr* GetTask( int taskid );
208     void AddBatchTask(
209         std::string mailurl,
210         std::string refer,
211         std::string savepath,
212         std::string rename,
213         int threadnum,
214         bool runnow,
215         int retry,
216         int retrywait,
217         std::string sock,
218         std::string ftp,
219         std::string http,
220         bool automd5,
221         int mirrorcount,
222         std::string mir[] );
223 
224 private:
225     bool ReadTaskDB();
226     bool SaveTaskDB();
227     bool SaveProxyDB();
228     bool ReadProxyDB();
229     bool ReadConfig();
230     bool SaveConfig();
231     int GetNewTaskID();
232 
233     void InitFileTypeList();
234     bool CompareExtName( std::string sname, std::string ext );
235     void UpdateToolBar();
236     void UpdateToolText();
237     void StopTask( int taskid );
238     void RecordSavePath( std::string path );
239     void DeleteTaskFromTaskList( int taskid );
240     bool MoveFile( std::string mgfile, std::string destpath , std::string& renamestr );
241     void SwapTaskTable( int task1, int task2 );
242     void InitToolBar();
243     void InitMenuBar();
244     void InitSpliter();
245     void InitMeterBar();
246 	bool CheckLocale(_MGLANG lang);
247 	void CheckLangMenu(_MGLANG lang);
248 	void NoLangSupport();
249     //void CheckTempDir();
250     void DoNewTask( wxString url, wxString refer = wxT( "" ), wxString savepath = wxT( "" ), wxString savefile = wxT( "" ) );
251 
252     _TASK_TYPE m_nCurrentShowType;
253 
254 
255     wxSplitterWindow	*m_vspliter;
256     wxSplitterWindow	*m_hspliter;
257     CRightDownSplitter	*m_vsubspliter;
258 
259     CTaskList	*m_tasklist;
260     CLeftTree *m_lefttree;
261     CTaskManager *m_TaskManager;
262 
263     CFloatWin	*m_FloatWin;
264     CSysTray	*m_SysTray;
265     CHideWin	*m_HideWin;
266     CNewTaskDlg *m_NewTaskDlg;
267     CPropertyDlg *m_PropertyDlg;
268     //	bool		m_bMonitorClip;
269     //#ifndef __WXX11__
270     //    CDropUrl	*m_DropUrl;
271     //#endif
272 
273     wxToolBar *m_ToolBar;	//main toolbar
274 
275     CMeterCtrl *m_MeterBar; //speed bar
276 
277     wxMenuBar *m_MenuBar;	//main menu
278 	wxMenu 		*m_lang;	//lang menu
279     //all task list
280     std::vector<_TaskAttr> m_AllTaskList;
281     //proxy list
282     std::vector<_ProxyAttr> m_AllProxyList;
283 
284     //filename ext
285     std::vector<std::string> m_FileTypeList[ 10 ];
286 
287 
288 
289     int m_nTaskID;
290     int m_nCurrentSelectTaskID;
291     wxTimer m_Timer;
292 
293     bool m_bShowStatusBar;
294     long TOOLBAR_SIZE ;
295 
296     int m_nWinSizeW;
297     int m_nWinSizeH;
298 
299     pthread_mutex_t m_TaskMutex;
300 
301     DECLARE_EVENT_TABLE()
302 
303 };
304 
305 
306 
307 #endif
308