⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 searching.h

📁 Last change: 2008-02-03 This is the source code of KCeasy。
💻 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 SearchingH
#define SearchingH

#include <list>

#include "istring.h"
#include "CriticalSection.h"
#include "MetaData.h"
#include "GiftCommand.h"
#include "User.h"
#include "Hash.h"
//#include "Engine.h"
//---------------------------------------------------------------------------

namespace KCeasyEngine {

using std::list;

typedef enum
{
    SRAny,
    SRAudio,
    SRVideo,
    SRImage,
    SRDocument,
    SRSoftware,
    SRSource,
    SRUser,
    SRTorrent
} TSearchRealm;

class TSearchResult
{
friend class TSearch;
friend class TEngine;
public:

    void* GetUData() { return UData; }
    void SetUData(void* NUData) { UData = NUData; }

    string SourceId;        // uniquely identifies the source (e.g. a http url)
    const THashSet* GetHashes() const { return Hashes; }
    const TUser* GetUser() const { return User; }

    string GetMagnetStr() const;

    string FileName;
    string FileDir;
    unsigned int FileSize;
    string MimeType;
    TFileType FileType;
    int Availability;
    string Network;

    TMetaData MetaData;

private:
    TSearchResult();
    ~TSearchResult();

    bool IsBannedByWord(const list<string>& Words);
    bool IsBannedByExtension(const list<string>& Extensions);

    void* UData;
    THashSet* Hashes;
    TUser* User;
};

class TSearch
{
friend class TEngine;
friend class TDownload;
public:
    typedef list<TSearchResult*>::iterator TResultIterator;
    typedef enum { New, Searching, Finished } TSearchState;

    // Non-localized strings of realms
    static const char* RealmToString(TSearchRealm Realm);
    static const TSearchRealm StringToRealm(const char* Str);

    bool Start(); // commence search using the data specified in the constructor, may be called multiple times
    bool Cancel(); // cancel running query
//    void Remove() { Engine->RemoveSearch(this); }
    bool IsInternal() { return Internal; }
    TSearchState GetState() { return State; }
    int NoOfResults() { return Results.size(); }
    unsigned int GetGiftId() { return GiftId; }
    const string& GetQuery() { return Query; }
    TSearchRealm GetRealm() { return Realm; }
    const string& GetNetwork() { return Network; }
    const TMetaData* GetMetaData() { return &MetaData; }
    bool GetWordBan() { return BanWords; }
    bool GetExtensionBan() { return BanExtensions; }
    int GetBannedResults() { return BannedResults; }

    void LockResults() { ResultsCritSec.Enter(); }
    void ReleaseResults() { ResultsCritSec.Leave(); }
    TResultIterator GetResultsBegin() { return Results.begin(); }
    TResultIterator GetResultsEnd() { return Results.end(); }

    void* GetUData() { return UData; }
    void SetUData(void* NUData) { UData = NUData; }

private:
    TSearch(TEngine* ParentEngine, const string& NQuery,
            TSearchRealm NRealm = SRAny, const string& NNetwork = "",
            const TMetaData& NMetaData = TMetaData(),
            bool BanWords = false, bool BanExtenions = false,
            bool Intern = false);
    ~TSearch();

    bool ProcessItem(TGiftCommand* Cmd);

    list<TSearchResult*> ResultCache; // cached results yet to be sent to ui
    int ReceivedResults; // cache for number of received results
    void CommitCachedResults(); // send cached items to ui

    TEngine* Engine;
    void* UData; // user data
    unsigned int GiftId;
    bool Internal; // true if this search is internal to the engine and the front end is not send events about it
    TSearchState State;

    string Query;
    TSearchRealm Realm;
    string Network;
    TMetaData MetaData;

    int BannedResults; // number of results dropped because they contained banned words or extensions
    bool BanWords;
    bool BanExtensions;

    list<TSearchResult*> Results;
    TCriticalSection ResultsCritSec;
};

} // namespace KCeasyEngine

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -