📄 downloading.h
字号:
/*
This file is part of KCeasy (http://www.kceasy.com)
Copyright (C) 2002-2004 Markus Kern <mkern@kceasy.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
//---------------------------------------------------------------------------
#ifndef DownloadingH
#define DownloadingH
#include <list>
#include "istring.h"
#include "CriticalSection.h"
#include "Transfer.h"
#include "User.h"
#include "Searching.h"
#include "Engine.h"
//---------------------------------------------------------------------------
namespace KCeasyEngine {
using std::list;
class TDlSource
{
friend class TDownload;
public:
typedef enum { New, Active, Waiting, Timeout, Cancelled, Complete, QueuedRemote, QueuedLocal, Unused, Paused } TDlSourceState;
void* GetUData() { return UData; }
void SetUData(void* NUData) { UData = NUData; }
unsigned int GetTimeLeft();
string SourceId;
TUser* GetUser() { return User; }
string Network;
TDlSourceState State;
string ProtoState; // free form string provided by respective gift plugin
unsigned int Start;
unsigned int Size;
unsigned int Transmitted;
TThroughput Throughput;
private:
TDlSource();
~TDlSource();
bool SetStateStr(const string& StateStr);
TUser* User;
void* UData;
};
class TSearch; // Searching.h
class TSearchResult; // Searching.h
class TDownload
{
friend class TEngine;
friend class TSearch;
public:
typedef list<TDlSource*>::iterator TSourceIterator;
typedef enum { New, Registering, Queued, Paused, Downloading, Verifying, Failed, Completed, Cancelled } TDownloadState;
bool AddSource(const TSearchResult* SearchResult);
bool RemoveSource(TDlSource* Source);
bool FindMoreSources();
bool KeepAlive(); // search more sources if necessary
bool Pause();
bool Resume();
bool Cancel();
unsigned int GetGiftId() { return GiftId; }
TDownloadState GetState() { return State; }
unsigned int GetMaxSources() { return MaxSources; }
void SetMaxSources(unsigned int Max); // 0 = unlimited
unsigned int GetLastActiveTime() { return LastActiveTime; }
bool IsFindingMoreSources() { return SourcesSearch; }
const THashSet* GetHashes() { return Hashes; }
const string& GetNetwork() { return Network; }
const string& GetSaveFileName() { return SaveFileName; }
const string& GetCompletedPath() { return CompletedPath; }
const string& GetIncomingPath() { return IncomingPath; }
unsigned int GetFileSize() { return FileSize; }
unsigned int GetTransmitted() { return Transmitted; }
unsigned int GetThroughput() { return Throughput.GetBps(); }
unsigned int GetTimeLeft() { return GetThroughput() ? ((FileSize - Transmitted) / GetThroughput()) : 0; }
TMetaData& GetMetaData() { return MetaData; }
const string& GetMimeType() { return MimeType; }
TFileType GetFileType() { return FileTypeFromMime(MimeType); }
void LockSources() { SourcesCritSec.Enter(); }
void ReleaseSources() { SourcesCritSec.Leave(); }
TSourceIterator GetSourcesBegin() { return Sources.begin(); }
TSourceIterator GetSourcesEnd() { return Sources.end(); }
unsigned int GetNoOfSources() { return Sources.size(); }
void* GetUData() { return UData; }
void SetUData(void* NUData) { UData = NUData; }
private:
TDownload(TEngine* ParentEngine, const THashSet* NHashes);
~TDownload();
void ClearSources();
bool ProcessAddDownload(TGiftCommand* Cmd);
bool ProcessDelDownload(TGiftCommand* Cmd);
bool ProcessChgDownload(TGiftCommand* Cmd);
bool ProcessAddSource(TGiftCommand* Cmd);
bool ProcessDelSource(TGiftCommand* Cmd);
TEngine* Engine;
void* UData;
unsigned int GiftId;
TSearch* SourcesSearch; // pointer to search used for finding more sources
TDownloadState State;
unsigned int MaxSources; // 0 = unlimited
unsigned int LastActiveTime; // tick count when we were last active
bool Cancelling; // hack to prevent addition of sources to cancelled downloads
THashSet* Hashes;
string Network;
string SaveFileName; // save file name
string CompletedPath;
string IncomingPath;
unsigned int FileSize;
unsigned int Transmitted;
TThroughput Throughput;
TMetaData MetaData;
string MimeType;
list<TDlSource*> Sources;
TCriticalSection SourcesCritSec;
};
} // namespace KCeasyEngine
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -