예제 #1
0
void DownloadManager::save()
{
    QString path = QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/";
    QDir dir;
    if(!dir.mkpath(path))
    {
        return;
    }
    QFile file(path + "downloads");
    if(!file.open(QIODevice::WriteOnly))
    {
        return;
    }
    QByteArray array;
    for(int i = count() - 1; i >= 0; i--)
    {
        DownloadItem * item = m_items.at(i);
        if(!item->isFinished())
        {
            array += item->from().toString().toUtf8();
            array += "\n";
            array += item->to().toString().toUtf8();
            array += "\n";
        }
    }
    file.write(array);
    file.close();
}
예제 #2
0
void DownloadManager::clearFinished()
{
    for(int i = count() - 1; i >= 0; i--)
    {
        DownloadItem * item = m_items.at(i);
        if(item->isFinished())
        {
            beginRemoveRows(QModelIndex(), i, i);
            item->deleteLater();
            m_items.removeAt(i);
            endRemoveRows();
            emit itemDeleted(i);
        }
    }
}