1 /*************************************************************************** 2 * Copyright (C) 2005-2007 by Joris Guisson * 3 * joris.guisson@gmail.com * 4 * * 5 * This program is free software; you can redistribute it and/or modify * 6 * it under the terms of the GNU General Public License as published by * 7 * the Free Software Foundation; either version 2 of the License, or * 8 * (at your option) any later version. * 9 * * 10 * This program is distributed in the hope that it will be useful, * 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 * GNU General Public License for more details. * 14 * * 15 * You should have received a copy of the GNU General Public License * 16 * along with this program; if not, write to the * 17 * Free Software Foundation, Inc., * 18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 19 ***************************************************************************/ 20 #include "monitor.h" 21 22 #include <interfaces/peerinterface.h> 23 #include <interfaces/torrentinterface.h> 24 #include <interfaces/torrentfileinterface.h> 25 #include <interfaces/chunkdownloadinterface.h> 26 #include "peerview.h" 27 #include "chunkdownloadview.h" 28 #include "fileview.h" 29 30 using namespace bt; 31 32 namespace kt 33 { 34 Monitor(bt::TorrentInterface * tc,PeerView * pv,ChunkDownloadView * cdv,FileView * fv)35 Monitor::Monitor(bt::TorrentInterface* tc,PeerView* pv,ChunkDownloadView* cdv,FileView* fv) 36 : tc(tc),pv(pv),cdv(cdv),fv(fv) 37 { 38 if (tc) 39 tc->setMonitor(this); 40 } 41 42 ~Monitor()43 Monitor::~Monitor() 44 { 45 if (tc) 46 tc->setMonitor(nullptr); 47 } 48 49 downloadRemoved(bt::ChunkDownloadInterface * cd)50 void Monitor::downloadRemoved(bt::ChunkDownloadInterface* cd) 51 { 52 if (cdv) 53 cdv->downloadRemoved(cd); 54 } 55 downloadStarted(bt::ChunkDownloadInterface * cd)56 void Monitor::downloadStarted(bt::ChunkDownloadInterface* cd) 57 { 58 if (cdv) 59 cdv->downloadAdded(cd); 60 } 61 peerAdded(bt::PeerInterface * peer)62 void Monitor::peerAdded(bt::PeerInterface* peer) 63 { 64 if (pv) 65 pv->peerAdded(peer); 66 } 67 peerRemoved(bt::PeerInterface * peer)68 void Monitor::peerRemoved(bt::PeerInterface* peer) 69 { 70 if (pv) 71 pv->peerRemoved(peer); 72 } 73 stopped()74 void Monitor::stopped() 75 { 76 if (pv) 77 pv->removeAll(); 78 if (cdv) 79 cdv->removeAll(); 80 } 81 destroyed()82 void Monitor::destroyed() 83 { 84 if (pv) 85 pv->removeAll(); 86 if (cdv) 87 cdv->removeAll(); 88 tc = nullptr; 89 } 90 filePercentageChanged(bt::TorrentFileInterface * file,float percentage)91 void Monitor::filePercentageChanged(bt::TorrentFileInterface* file,float percentage) 92 { 93 if (fv) 94 fv->filePercentageChanged(file,percentage); 95 } 96 filePreviewChanged(bt::TorrentFileInterface * file,bool preview)97 void Monitor::filePreviewChanged(bt::TorrentFileInterface* file,bool preview) 98 { 99 if (fv) 100 fv->filePreviewChanged(file,preview); 101 } 102 } 103