ed2ksearch.cpp

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2004-2005 Alo Sarv <madcat_@users.sourceforge.net>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  */
00018 
00019 #include <hn/hnprec.h>
00020 #include "ed2ksearch.h"
00021 #include <hn/log.h>
00022 #include <hn/metadb.h>
00023 #include <hn/metadata.h>
00024 #include <hn/fileslist.h>
00025 #include <hn/sharedfile.h>
00026 
00027 ED2KSearchResult::ED2KSearchResult(
00028         Hash<ED2KHash> h, const std::string &name, uint32_t size
00029 ) : SearchResult(name, size), m_hash(h) {}
00030 
00031 void ED2KSearchResult::download() {
00032         logDebug(
00033                 boost::format("Starting download %s Hash: %s")
00034                 % getName() % m_hash.decode()
00035         );
00036         SharedFile *sf = MetaDb::instance().findSharedFile(m_hash);
00037         if (sf && sf->isPartial()) {
00038                 logMsg(
00039                         boost::format(
00040                                 "You are already attempting to download %s"
00041                         ) % sf->getName()
00042                 );
00043                 return;
00044         } else if (sf) {
00045                 logMsg(
00046                         boost::format("You already have file %s")
00047                         % sf->getName()
00048                 );
00049                 return;
00050         }
00051 
00052         MetaData *md = new MetaData(getSize());
00053         md->addFileName(getName());
00054         ED2KHashSet *hs = new ED2KHashSet(m_hash);
00055         md->addHashSet(hs);
00056         MetaDb::instance().push(md);
00057         FilesList::instance().createDownload(getName(), md);
00058 }