File indexing completed on 2024-05-05 04:59:13
0001 /*************************************************************************** 0002 * Copyright (C) 2005-2007 by Joris Guisson * 0003 * joris.guisson@gmail.com * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 0019 ***************************************************************************/ 0020 #include "monitor.h" 0021 0022 #include "chunkdownloadview.h" 0023 #include "fileview.h" 0024 #include "peerview.h" 0025 #include <interfaces/chunkdownloadinterface.h> 0026 #include <interfaces/peerinterface.h> 0027 #include <interfaces/torrentfileinterface.h> 0028 #include <interfaces/torrentinterface.h> 0029 0030 using namespace bt; 0031 0032 namespace kt 0033 { 0034 0035 Monitor::Monitor(bt::TorrentInterface *tc, PeerView *pv, ChunkDownloadView *cdv, FileView *fv) 0036 : tc(tc) 0037 , pv(pv) 0038 , cdv(cdv) 0039 , fv(fv) 0040 { 0041 if (tc) 0042 tc->setMonitor(this); 0043 } 0044 0045 Monitor::~Monitor() 0046 { 0047 if (tc) 0048 tc->setMonitor(nullptr); 0049 } 0050 0051 void Monitor::downloadRemoved(bt::ChunkDownloadInterface *cd) 0052 { 0053 if (cdv) 0054 cdv->downloadRemoved(cd); 0055 } 0056 0057 void Monitor::downloadStarted(bt::ChunkDownloadInterface *cd) 0058 { 0059 if (cdv) 0060 cdv->downloadAdded(cd); 0061 } 0062 0063 void Monitor::peerAdded(bt::PeerInterface *peer) 0064 { 0065 if (pv) 0066 pv->peerAdded(peer); 0067 } 0068 0069 void Monitor::peerRemoved(bt::PeerInterface *peer) 0070 { 0071 if (pv) 0072 pv->peerRemoved(peer); 0073 } 0074 0075 void Monitor::stopped() 0076 { 0077 if (pv) 0078 pv->removeAll(); 0079 if (cdv) 0080 cdv->removeAll(); 0081 } 0082 0083 void Monitor::destroyed() 0084 { 0085 if (pv) 0086 pv->removeAll(); 0087 if (cdv) 0088 cdv->removeAll(); 0089 tc = nullptr; 0090 } 0091 0092 void Monitor::filePercentageChanged(bt::TorrentFileInterface *file, float percentage) 0093 { 0094 if (fv) 0095 fv->filePercentageChanged(file, percentage); 0096 } 0097 0098 void Monitor::filePreviewChanged(bt::TorrentFileInterface *file, bool preview) 0099 { 0100 if (fv) 0101 fv->filePreviewChanged(file, preview); 0102 } 0103 }