File indexing completed on 2025-01-05 04:24:22
0001 #include "downloadsmanager.h" 0002 #include <QDebug> 0003 0004 DownloadsManager::DownloadsManager(QObject *parent) : QObject(parent) 0005 ,m_model(new DownloadsModel(this)) 0006 { 0007 0008 } 0009 0010 DownloadsManager &DownloadsManager::instance() 0011 { 0012 static DownloadsManager instance; 0013 return instance; 0014 } 0015 0016 void DownloadsManager::add(DownloadItem *download) 0017 { 0018 0019 qDebug() << "ADD NEW DOWNLOAD"; 0020 m_downloads << download; 0021 Q_EMIT newDownload(QVariant::fromValue(download)); 0022 } 0023 0024 void DownloadsManager::remove(int index) 0025 { 0026 if(index < 0 || index >= m_downloads.count()) 0027 return; 0028 0029 m_downloads.at(index)->cancel(); 0030 m_downloads.erase(m_downloads.begin() + index); 0031 } 0032 0033 DownloadItem *DownloadsManager::item(int index) 0034 { 0035 if(index < 0 || index >= m_downloads.count()) 0036 return nullptr; 0037 0038 return m_downloads.at(index); 0039 } 0040 0041 int DownloadsManager::count() const 0042 { 0043 return m_downloads.count(); 0044 } 0045 0046 DownloadsManager::~DownloadsManager() 0047 { 0048 // qDeleteAll(m_downloads); 0049 } 0050 0051 DownloadsModel *DownloadsManager::model() const 0052 { 0053 return m_model; 0054 }