1 /**
2     This file is part of SpringLobby,
3     Copyright (C) 2007-2010
4 
5     SpringLobby is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License version 2 as published by
7     the Free Software Foundation.
8 
9     springsettings is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License
15     along with SpringLobby.  If not, see <http://www.gnu.org/licenses/>.
16 **/
17 
18 
19 #ifndef SPRINGLOBBY_HEADERGUARD_PRDOWNLOADER_H
20 #define SPRINGLOBBY_HEADERGUARD_PRDOWNLOADER_H
21 
22 #include <string>
23 #include <queue>
24 #include <list>
25 
26 #include "lib/src/Downloader/Download.h"
27 #include "utils/globalevents.h"
28 
29 class IDownloader;
30 
31 namespace LSL
32 {
33 class WorkerThread;
34 }
35 
36 namespace P2P
37 {
38 enum FileStatus {
39 	not_stored	= 0, /// file is not on disk and not downloading
40 	queued		= 1, /// file is not on disk and queued for download
41 	leeching	= 2, /// file is being downloaded
42 	paused		= 3, /// file currently not downloading but has valid handle
43 	complete	= 4  /// file is on disk / dl completed
44 };
45 }
46 
47 struct DownloadInfo {
48 	P2P::FileStatus downloadstatus;
49 	std::string name;
50 	int numcopies;//TODO remove
51 	double progress;
52 	double inspeed;
53 	double eta;
54 	double filesize;
55 };
56 
57 class PrDownloader: public wxEvtHandler, public GlobalEvent
58 {
59 public:
60 	PrDownloader();
61 	~PrDownloader();
62 
63 	void ClearFinished();
64 	void UpdateSettings();
65 	void RemoveTorrentByName( const std::string& name );
66 	//! returns true if name found and added to dl list
67 	int GetDownload( const std::string& category, const std::string& name );
68 	void SetIngameStatus( bool ingame );
69 	void OnSpringStarted(wxCommandEvent& data);
70 	void OnSpringTerminated(wxCommandEvent& data);
71 	static std::string GetEngineCat();
72 
73 private:
74 	//! searches given loaders for filename and pushes fitting workitems into dl_thread
75 	int Get(std::list<IDownloader*> loaders, const std::string& name, IDownload::category cat );
76 	std::list<IDownloader*> m_game_loaders;
77 	std::list<IDownloader*> m_map_loaders;
78 	LSL::WorkerThread* m_dl_thread;
79 
80 	friend class SearchItem;
81 };
82 
83 PrDownloader& prDownloader();
84 
85 #endif // PRDOWNLOADER_H
86