diff options
| author | Andrea Diamantini <adjam7@gmail.com> | 2009-01-20 17:58:46 +0100 | 
|---|---|---|
| committer | Andrea Diamantini <adjam7@gmail.com> | 2009-01-20 17:58:46 +0100 | 
| commit | adeda3f2a1e2fc229edfa387527b102adbea646a (patch) | |
| tree | b066afe328a8f5851a489abad240c1313dfe86c7 | |
| parent | Ported Cookie system to KCOnfigXT. (diff) | |
| download | rekonq-adeda3f2a1e2fc229edfa387527b102adbea646a.tar.xz | |
Removed QtDemoBrowser download manager. Working on rekonq's own..
| -rw-r--r-- | src/downloaditem.ui | 134 | ||||
| -rw-r--r-- | src/downloadmanager.cpp | 544 | ||||
| -rw-r--r-- | src/downloadmanager.h | 142 | ||||
| -rw-r--r-- | src/downloads.ui | 83 | 
4 files changed, 0 insertions, 903 deletions
| diff --git a/src/downloaditem.ui b/src/downloaditem.ui deleted file mode 100644 index 4a0a0fd9..00000000 --- a/src/downloaditem.ui +++ /dev/null @@ -1,134 +0,0 @@ -<ui version="4.0" > - <class>DownloadItem</class> - <widget class="QWidget" name="DownloadItem" > -  <property name="geometry" > -   <rect> -    <x>0</x> -    <y>0</y> -    <width>423</width> -    <height>110</height> -   </rect> -  </property> -  <property name="windowTitle" > -   <string>Form</string> -  </property> -  <layout class="QHBoxLayout" name="horizontalLayout" > -   <property name="margin" > -    <number>0</number> -   </property> -   <item> -    <widget class="QLabel" name="fileIcon" > -     <property name="sizePolicy" > -      <sizepolicy vsizetype="Minimum" hsizetype="Minimum" > -       <horstretch>0</horstretch> -       <verstretch>0</verstretch> -      </sizepolicy> -     </property> -     <property name="text" > -      <string>Ico</string> -     </property> -    </widget> -   </item> -   <item> -    <layout class="QVBoxLayout" name="verticalLayout_2" > -     <item> -      <widget class="SqueezeLabel" native="1" name="fileNameLabel" > -       <property name="sizePolicy" > -        <sizepolicy vsizetype="Preferred" hsizetype="Expanding" > -         <horstretch>0</horstretch> -         <verstretch>0</verstretch> -        </sizepolicy> -       </property> -       <property name="text" stdset="0" > -        <string>Filename</string> -       </property> -      </widget> -     </item> -     <item> -      <widget class="QProgressBar" name="progressBar" > -       <property name="value" > -        <number>0</number> -       </property> -      </widget> -     </item> -     <item> -      <widget class="SqueezeLabel" native="1" name="downloadInfoLabel" > -       <property name="sizePolicy" > -        <sizepolicy vsizetype="Preferred" hsizetype="Minimum" > -         <horstretch>0</horstretch> -         <verstretch>0</verstretch> -        </sizepolicy> -       </property> -       <property name="text" stdset="0" > -        <string/> -       </property> -      </widget> -     </item> -    </layout> -   </item> -   <item> -    <layout class="QVBoxLayout" name="verticalLayout" > -     <item> -      <spacer name="verticalSpacer" > -       <property name="orientation" > -        <enum>Qt::Vertical</enum> -       </property> -       <property name="sizeHint" stdset="0" > -        <size> -         <width>17</width> -         <height>1</height> -        </size> -       </property> -      </spacer> -     </item> -     <item> -      <widget class="QPushButton" name="tryAgainButton" > -       <property name="enabled" > -        <bool>false</bool> -       </property> -       <property name="text" > -        <string>Try Again</string> -       </property> -      </widget> -     </item> -     <item> -      <widget class="QPushButton" name="stopButton" > -       <property name="text" > -        <string>Stop</string> -       </property> -      </widget> -     </item> -     <item> -      <widget class="QPushButton" name="openButton" > -       <property name="text" > -        <string>Open</string> -       </property> -      </widget> -     </item> -     <item> -      <spacer name="verticalSpacer_2" > -       <property name="orientation" > -        <enum>Qt::Vertical</enum> -       </property> -       <property name="sizeHint" stdset="0" > -        <size> -         <width>17</width> -         <height>5</height> -        </size> -       </property> -      </spacer> -     </item> -    </layout> -   </item> -  </layout> - </widget> - <customwidgets> -  <customwidget> -   <class>SqueezeLabel</class> -   <extends>QWidget</extends> -   <header>squeezelabel.h</header> -  </customwidget> - </customwidgets> - <resources/> - <connections/> -</ui> diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp deleted file mode 100644 index df990c7b..00000000 --- a/src/downloadmanager.cpp +++ /dev/null @@ -1,544 +0,0 @@ -/* ============================================================ - * - * This file is a part of the rekonq project - * - * Copyright (C) 2007-2008 Trolltech ASA. All rights reserved - * Copyright (C) 2008 by Andrea Diamantini <adjam7 at gmail dot com> - * - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; - * either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the - * GNU General Public License for more details. - * - * ============================================================ */ - - -// Local includes -#include "downloadmanager.h" -#include "autosaver.h" -#include "browserapplication.h" -#include "networkaccessmanager.h" - -// generic includes -#include <math.h> - -// Qt Includes -#include <QMetaEnum> -#include <QSettings> -#include <QDesktopServices> -#include <QFileDialog> -#include <QHeaderView> -#include <QFileIconProvider> -#include <QDebug> -#include <QWebSettings> - -/*! -    DownloadItem is a widget that is displayed in the download manager list. -    It moves the data from the QNetworkReply into the QFile as well -    as update the information/progressbar and report errors. - */ -DownloadItem::DownloadItem(QNetworkReply *reply, bool requestFileName, QWidget *parent) -    : QWidget(parent) -    , m_reply(reply) -    , m_requestFileName(requestFileName) -    , m_bytesReceived(0) -{ -    setupUi(this); -    QPalette p = downloadInfoLabel->palette(); -    p.setColor(QPalette::Text, Qt::darkGray); -    downloadInfoLabel->setPalette(p); -    progressBar->setMaximum(0); -    tryAgainButton->hide(); -    connect(stopButton, SIGNAL(clicked()), this, SLOT(stop())); -    connect(openButton, SIGNAL(clicked()), this, SLOT(open())); -    connect(tryAgainButton, SIGNAL(clicked()), this, SLOT(tryAgain())); - -    init(); -} - -void DownloadItem::init() -{ -    if (!m_reply) -        return; - -    // attach to the m_reply -    m_url = m_reply->url(); -    m_reply->setParent(this); -    connect(m_reply, SIGNAL(readyRead()), this, SLOT(downloadReadyRead())); -    connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(error(QNetworkReply::NetworkError))); -    connect(m_reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64))); -    connect(m_reply, SIGNAL(metaDataChanged()), this, SLOT(metaDataChanged())); -    connect(m_reply, SIGNAL(finished()), this, SLOT(finished())); - -    // reset info -    downloadInfoLabel->clear(); -    progressBar->setValue(0); -    getFileName(); - -    // start timer for the download estimation -    m_downloadTime.start(); - -    if (m_reply->error() != QNetworkReply::NoError) { -        error(m_reply->error()); -        finished(); -    } -} - -void DownloadItem::getFileName() -{ -    QSettings settings; -    settings.beginGroup(QLatin1String("downloadmanager")); -    QString defaultLocation = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation); -    QString downloadDirectory = settings.value(QLatin1String("downloadDirectory"), defaultLocation).toString(); -    if (!downloadDirectory.isEmpty()) -        downloadDirectory += QLatin1Char('/'); - -    QString defaultFileName = saveFileName(downloadDirectory); -    QString fileName = defaultFileName; -    if (m_requestFileName) { -        fileName = QFileDialog::getSaveFileName(this, i18n("Save File"), defaultFileName); -        if (fileName.isEmpty()) { -            m_reply->close(); -            fileNameLabel->setText( i18n("Download canceled: ") + QFileInfo(defaultFileName).fileName()); -            return; -        } -    } -    m_output.setFileName(fileName); -    fileNameLabel->setText(QFileInfo(m_output.fileName()).fileName()); -    if (m_requestFileName) -        downloadReadyRead(); -} - -QString DownloadItem::saveFileName(const QString &directory) const -{ -    // Move this function into QNetworkReply to also get file name sent from the server -    QString path = m_url.path(); -    QFileInfo info(path); -    QString baseName = info.completeBaseName(); -    QString endName = info.suffix(); - -    if (baseName.isEmpty()) { -        baseName = QLatin1String("unnamed_download"); -        qDebug() << "DownloadManager:: downloading unknown file:" << m_url; -    } -    QString name = directory + baseName + QLatin1Char('.') + endName; -    if (QFile::exists(name)) { -        // already exists, don't overwrite -        int i = 1; -        do { -            name = directory + baseName + QLatin1Char('-') + QString::number(i++) + QLatin1Char('.') + endName; -        } while (QFile::exists(name)); -    } -    return name; -} - - -void DownloadItem::stop() -{ -    setUpdatesEnabled(false); -    stopButton->setEnabled(false); -    stopButton->hide(); -    tryAgainButton->setEnabled(true); -    tryAgainButton->show(); -    setUpdatesEnabled(true); -    m_reply->abort(); -} - -void DownloadItem::open() -{ -    QFileInfo info(m_output); -    QUrl url = QUrl::fromLocalFile(info.absolutePath()); -    QDesktopServices::openUrl(url); -} - -void DownloadItem::tryAgain() -{ -    if (!tryAgainButton->isEnabled()) -        return; - -    tryAgainButton->setEnabled(false); -    tryAgainButton->setVisible(false); -    stopButton->setEnabled(true); -    stopButton->setVisible(true); -    progressBar->setVisible(true); - -    QNetworkReply *r = BrowserApplication::networkAccessManager()->get(QNetworkRequest(m_url)); -    if (m_reply) -        m_reply->deleteLater(); -    if (m_output.exists()) -        m_output.remove(); -    m_reply = r; -    init(); -    emit statusChanged(); -} - -void DownloadItem::downloadReadyRead() -{ -    if (m_requestFileName && m_output.fileName().isEmpty()) -        return; -    if (!m_output.isOpen()) { -        // in case someone else has already put a file there -        if (!m_requestFileName) -            getFileName(); -        if (!m_output.open(QIODevice::WriteOnly)) { -            downloadInfoLabel->setText( i18n("Error opening save file: ") +  m_output.errorString() ); -            stopButton->click(); -            emit statusChanged(); -            return; -        } -        emit statusChanged(); -    } -    if (-1 == m_output.write(m_reply->readAll())) { -        downloadInfoLabel->setText( i18n("Error saving: ") + m_output.errorString() ); -        stopButton->click(); -    } -} - -void DownloadItem::error(QNetworkReply::NetworkError) -{ -    qDebug() << "DownloadItem::error" << m_reply->errorString() << m_url; -    downloadInfoLabel->setText( i18n("Network Error: ") + m_reply->errorString() ); -    tryAgainButton->setEnabled(true); -    tryAgainButton->setVisible(true); -} - -void DownloadItem::metaDataChanged() -{ -    qDebug() << "DownloadItem::metaDataChanged: not handled."; -} - -void DownloadItem::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) -{ -    m_bytesReceived = bytesReceived; -    if (bytesTotal == -1) { -        progressBar->setValue(0); -        progressBar->setMaximum(0); -    } else { -        progressBar->setValue(bytesReceived); -        progressBar->setMaximum(bytesTotal); -    } -    updateInfoLabel(); -} - -void DownloadItem::updateInfoLabel() -{ -    if (m_reply->error() == QNetworkReply::NoError) -        return; - -    qint64 bytesTotal = progressBar->maximum(); -    bool running = !downloadedSuccessfully(); - -    // update info label -    double speed = m_bytesReceived * 1000.0 / m_downloadTime.elapsed(); -    double timeRemaining = ((double)(bytesTotal - m_bytesReceived)) / speed; -    QString timeRemainingString = i18n("seconds"); -    if (timeRemaining > 60) { -        timeRemaining = timeRemaining / 60; -        timeRemainingString = i18n("minutes"); -    } -    timeRemaining = floor(timeRemaining); - -    // When downloading the eta should never be 0 -    if (timeRemaining == 0) -        timeRemaining = 1; - -    QString info; -    if (running) { -        QString remaining; -        if (bytesTotal != 0) -            remaining = i18n("- %1 %2 remaining", timeRemaining, timeRemainingString ); -            info = dataString(m_bytesReceived) + i18n("of") + bytesTotal == 0 ? "?" : dataString(bytesTotal) + "(" + dataString((int)speed) + "/sec)" + QString(remaining); -    } else { -        if (m_bytesReceived == bytesTotal) -            info = dataString(m_output.size()); -        else -            info = dataString(m_bytesReceived) + i18n("of") + dataString(bytesTotal) + i18n(" - Stopped"); -    } -    downloadInfoLabel->setText(info); -} - -QString DownloadItem::dataString(int size) const -{ -    QString unit; -    if (size < 1024) { -        unit = i18n("bytes"); -    } else if (size < 1024*1024) { -        size /= 1024; -        unit = i18n("kB"); -    } else { -        size /= 1024*1024; -        unit = i18n("MB"); -    } -    return QString(QLatin1String("%1 %2")).arg(size).arg(unit); -} - -bool DownloadItem::downloading() const -{ -    return (progressBar->isVisible()); -} - -bool DownloadItem::downloadedSuccessfully() const -{ -    return (stopButton->isHidden() && tryAgainButton->isHidden()); -} - -void DownloadItem::finished() -{ -    progressBar->hide(); -    stopButton->setEnabled(false); -    stopButton->hide(); -    m_output.close(); -    updateInfoLabel(); -    emit statusChanged(); -} - -/*! -    DownloadManager is a Dialog that contains a list of DownloadItems - -    It is a basic download manager.  It only downloads the file, doesn't do BitTorrent, -    extract zipped files or anything fancy. -  */ -DownloadManager::DownloadManager(QWidget *parent) -    : QDialog(parent) -    , m_autoSaver(new AutoSaver(this)) -    , m_manager(BrowserApplication::networkAccessManager()) -    , m_iconProvider(0) -    , m_removePolicy(Never) -{ -    setupUi(this); -    downloadsView->setShowGrid(false); -    downloadsView->verticalHeader()->hide(); -    downloadsView->horizontalHeader()->hide(); -    downloadsView->setAlternatingRowColors(true); -    downloadsView->horizontalHeader()->setStretchLastSection(true); -    m_model = new DownloadModel(this); -    downloadsView->setModel(m_model); -    connect(cleanupButton, SIGNAL(clicked()), this, SLOT(cleanup())); -    load(); -} - -DownloadManager::~DownloadManager() -{ -    m_autoSaver->changeOccurred(); -    m_autoSaver->saveIfNeccessary(); -    if (m_iconProvider) -        delete m_iconProvider; -} - -int DownloadManager::activeDownloads() const -{ -    int count = 0; -    for (int i = 0; i < m_downloads.count(); ++i) { -        if (m_downloads.at(i)->stopButton->isEnabled()) -            ++count; -    } -    return count; -} - -void DownloadManager::download(const QNetworkRequest &request, bool requestFileName) -{ -    if (request.url().isEmpty()) -        return; -    handleUnsupportedContent(m_manager->get(request), requestFileName); -} - -void DownloadManager::handleUnsupportedContent(QNetworkReply *reply, bool requestFileName) -{ -    if (!reply || reply->url().isEmpty()) -        return; -    QVariant header = reply->header(QNetworkRequest::ContentLengthHeader); -    bool ok; -    int size = header.toInt(&ok); -    if (ok && size == 0) -        return; - -    qDebug() << "DownloadManager::handleUnsupportedContent" << reply->url() << "requestFileName" << requestFileName; -    DownloadItem *item = new DownloadItem(reply, requestFileName, this); -    addItem(item); -} - -void DownloadManager::addItem(DownloadItem *item) -{ -    connect(item, SIGNAL(statusChanged()), this, SLOT(updateRow())); -    int row = m_downloads.count(); -    m_model->beginInsertRows(QModelIndex(), row, row); -    m_downloads.append(item); -    m_model->endInsertRows(); -    updateItemCount(); -    if (row == 0) -        show(); -    downloadsView->setIndexWidget(m_model->index(row, 0), item); -    QIcon icon = style()->standardIcon(QStyle::SP_FileIcon); -    item->fileIcon->setPixmap(icon.pixmap(48, 48)); -    downloadsView->setRowHeight(row, item->sizeHint().height()); -} - -void DownloadManager::updateRow() -{ -    DownloadItem *item = qobject_cast<DownloadItem*>(sender()); -    int row = m_downloads.indexOf(item); -    if (-1 == row) -        return; -    if (!m_iconProvider) -        m_iconProvider = new QFileIconProvider(); -    QIcon icon = m_iconProvider->icon(item->m_output.fileName()); -    if (icon.isNull()) -        icon = style()->standardIcon(QStyle::SP_FileIcon); -    item->fileIcon->setPixmap(icon.pixmap(48, 48)); -    downloadsView->setRowHeight(row, item->minimumSizeHint().height()); - -    bool remove = false; -    QWebSettings *globalSettings = QWebSettings::globalSettings(); -    if (!item->downloading() -        && globalSettings->testAttribute(QWebSettings::PrivateBrowsingEnabled)) -        remove = true; - -    if (item->downloadedSuccessfully() -        && removePolicy() == DownloadManager::SuccessFullDownload) { -        remove = true; -    } -    if (remove) -        m_model->removeRow(row); - -    cleanupButton->setEnabled(m_downloads.count() - activeDownloads() > 0); -} - -DownloadManager::RemovePolicy DownloadManager::removePolicy() const -{ -    return m_removePolicy; -} - -void DownloadManager::setRemovePolicy(RemovePolicy policy) -{ -    if (policy == m_removePolicy) -        return; -    m_removePolicy = policy; -    m_autoSaver->changeOccurred(); -} - -void DownloadManager::save() const -{ -    QSettings settings; -    settings.beginGroup(QLatin1String("downloadmanager")); -    QMetaEnum removePolicyEnum = staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("RemovePolicy")); -    settings.setValue(QLatin1String("removeDownloadsPolicy"), QLatin1String(removePolicyEnum.valueToKey(m_removePolicy))); -    settings.setValue(QLatin1String("size"), size()); -    if (m_removePolicy == Exit) -        return; - -    for (int i = 0; i < m_downloads.count(); ++i) { -        QString key = QString(QLatin1String("download_%1_")).arg(i); -        settings.setValue(key + QLatin1String("url"), m_downloads[i]->m_url); -        settings.setValue(key + QLatin1String("location"), QFileInfo(m_downloads[i]->m_output).filePath()); -        settings.setValue(key + QLatin1String("done"), m_downloads[i]->downloadedSuccessfully()); -    } -    int i = m_downloads.count(); -    QString key = QString(QLatin1String("download_%1_")).arg(i); -    while (settings.contains(key + QLatin1String("url"))) { -        settings.remove(key + QLatin1String("url")); -        settings.remove(key + QLatin1String("location")); -        settings.remove(key + QLatin1String("done")); -        key = QString(QLatin1String("download_%1_")).arg(++i); -    } -} - -void DownloadManager::load() -{ -    QSettings settings; -    settings.beginGroup(QLatin1String("downloadmanager")); -    QSize size = settings.value(QLatin1String("size")).toSize(); -    if (size.isValid()) -        resize(size); -    QByteArray value = settings.value(QLatin1String("removeDownloadsPolicy"), QLatin1String("Never")).toByteArray(); -    QMetaEnum removePolicyEnum = staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("RemovePolicy")); -    m_removePolicy = removePolicyEnum.keyToValue(value) == -1 ? -                        Never : -                        static_cast<RemovePolicy>(removePolicyEnum.keyToValue(value)); - -    int i = 0; -    QString key = QString(QLatin1String("download_%1_")).arg(i); -    while (settings.contains(key + QLatin1String("url"))) { -        QUrl url = settings.value(key + QLatin1String("url")).toUrl(); -        QString fileName = settings.value(key + QLatin1String("location")).toString(); -        bool done = settings.value(key + QLatin1String("done"), true).toBool(); -        if (!url.isEmpty() && !fileName.isEmpty()) { -            DownloadItem *item = new DownloadItem(0, this); -            item->m_output.setFileName(fileName); -            item->fileNameLabel->setText(QFileInfo(item->m_output.fileName()).fileName()); -            item->m_url = url; -            item->stopButton->setVisible(false); -            item->stopButton->setEnabled(false); -            item->tryAgainButton->setVisible(!done); -            item->tryAgainButton->setEnabled(!done); -            item->progressBar->setVisible(!done); -            addItem(item); -        } -        key = QString(QLatin1String("download_%1_")).arg(++i); -    } -    cleanupButton->setEnabled(m_downloads.count() - activeDownloads() > 0); -} - -void DownloadManager::cleanup() -{ -    if (m_downloads.isEmpty()) -        return; -    m_model->removeRows(0, m_downloads.count()); -    updateItemCount(); -    if (m_downloads.isEmpty() && m_iconProvider) { -        delete m_iconProvider; -        m_iconProvider = 0; -    } -    m_autoSaver->changeOccurred(); -} - -void DownloadManager::updateItemCount() -{ -    int count = m_downloads.count(); -    itemCount->setText(count == 1 ? i18n("1 Download") : QString(count) + i18n(" Downloads") ); -} - -DownloadModel::DownloadModel(DownloadManager *downloadManager, QObject *parent) -    : QAbstractListModel(parent) -    , m_downloadManager(downloadManager) -{ -} - -QVariant DownloadModel::data(const QModelIndex &index, int role) const -{ -    if (index.row() < 0 || index.row() >= rowCount(index.parent())) -        return QVariant(); -    if (role == Qt::ToolTipRole) -        if (!m_downloadManager->m_downloads.at(index.row())->downloadedSuccessfully()) -            return m_downloadManager->m_downloads.at(index.row())->downloadInfoLabel->text(); -    return QVariant(); -} - -int DownloadModel::rowCount(const QModelIndex &parent) const -{ -    return (parent.isValid()) ? 0 : m_downloadManager->m_downloads.count(); -} - -bool DownloadModel::removeRows(int row, int count, const QModelIndex &parent) -{ -    if (parent.isValid()) -        return false; - -    int lastRow = row + count - 1; -    for (int i = lastRow; i >= row; --i) { -        if (m_downloadManager->m_downloads.at(i)->downloadedSuccessfully() -            || m_downloadManager->m_downloads.at(i)->tryAgainButton->isEnabled()) { -            beginRemoveRows(parent, i, i); -            m_downloadManager->m_downloads.takeAt(i)->deleteLater(); -            endRemoveRows(); -        } -    } -    m_downloadManager->m_autoSaver->changeOccurred(); -    return true; -} - diff --git a/src/downloadmanager.h b/src/downloadmanager.h deleted file mode 100644 index 1a2e5d30..00000000 --- a/src/downloadmanager.h +++ /dev/null @@ -1,142 +0,0 @@ -/* ============================================================ - * - * This file is a part of the rekonq project - * - * Copyright (C) 2007-2008 Trolltech ASA. All rights reserved - * Copyright (C) 2008 by Andrea Diamantini <adjam7 at gmail dot com> - * - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; - * either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the - * GNU General Public License for more details. - * - * ============================================================ */ - - -#ifndef DOWNLOADMANAGER_H -#define DOWNLOADMANAGER_H - -#include "ui_downloads.h" -#include "ui_downloaditem.h" - -#include <QNetworkReply> -#include <QFile> -#include <QTime> - - -class DownloadItem : public QWidget, public Ui_DownloadItem -{ -    Q_OBJECT - -signals: -    void statusChanged(); - -public: -    DownloadItem(QNetworkReply *reply = 0, bool requestFileName = false, QWidget *parent = 0); -    bool downloading() const; -    bool downloadedSuccessfully() const; - -    QUrl m_url; - -    QFile m_output; -    QNetworkReply *m_reply; - -private slots: -    void stop(); -    void tryAgain(); -    void open(); - -    void downloadReadyRead(); -    void error(QNetworkReply::NetworkError code); -    void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); -    void metaDataChanged(); -    void finished(); - -private: -    void getFileName(); -    void init(); -    void updateInfoLabel(); -    QString dataString(int size) const; - -    QString saveFileName(const QString &directory) const; - -    bool m_requestFileName; -    qint64 m_bytesReceived; -    QTime m_downloadTime; -}; - -class AutoSaver; -class DownloadModel; -QT_BEGIN_NAMESPACE -class QFileIconProvider; -QT_END_NAMESPACE - -class DownloadManager : public QDialog, public Ui_DownloadDialog -{ -    Q_OBJECT -    Q_PROPERTY(RemovePolicy removePolicy READ removePolicy WRITE setRemovePolicy) -    Q_ENUMS(RemovePolicy) - -public: -    enum RemovePolicy { -        Never, -        Exit, -        SuccessFullDownload -    }; - -    DownloadManager(QWidget *parent = 0); -    ~DownloadManager(); -    int activeDownloads() const; - -    RemovePolicy removePolicy() const; -    void setRemovePolicy(RemovePolicy policy); - -public slots: -    void download(const QNetworkRequest &request, bool requestFileName = false); -    inline void download(const QUrl &url, bool requestFileName = false) -        { download(QNetworkRequest(url), requestFileName); } -    void handleUnsupportedContent(QNetworkReply *reply, bool requestFileName = false); -    void cleanup(); - -private slots: -    void save() const; -    void updateRow(); - -private: -    void addItem(DownloadItem *item); -    void updateItemCount(); -    void load(); - -    AutoSaver *m_autoSaver; -    DownloadModel *m_model; -    QNetworkAccessManager *m_manager; -    QFileIconProvider *m_iconProvider; -    QList<DownloadItem*> m_downloads; -    RemovePolicy m_removePolicy; -    friend class DownloadModel; -}; - -class DownloadModel : public QAbstractListModel -{ -    friend class DownloadManager; -    Q_OBJECT - -public: -    DownloadModel(DownloadManager *downloadManager, QObject *parent = 0); -    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; -    int rowCount(const QModelIndex &parent = QModelIndex()) const; -    bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); - -private: -    DownloadManager *m_downloadManager; - -}; - -#endif // DOWNLOADMANAGER_H - diff --git a/src/downloads.ui b/src/downloads.ui deleted file mode 100644 index a2e25693..00000000 --- a/src/downloads.ui +++ /dev/null @@ -1,83 +0,0 @@ -<ui version="4.0" > - <class>DownloadDialog</class> - <widget class="QDialog" name="DownloadDialog" > -  <property name="geometry" > -   <rect> -    <x>0</x> -    <y>0</y> -    <width>332</width> -    <height>252</height> -   </rect> -  </property> -  <property name="windowTitle" > -   <string>Downloads</string> -  </property> -  <layout class="QGridLayout" name="gridLayout" > -   <property name="margin" > -    <number>0</number> -   </property> -   <property name="spacing" > -    <number>0</number> -   </property> -   <item row="0" column="0" colspan="3" > -    <widget class="EditTableView" name="downloadsView" /> -   </item> -   <item row="1" column="0" > -    <layout class="QHBoxLayout" name="horizontalLayout" > -     <item> -      <widget class="QPushButton" name="cleanupButton" > -       <property name="enabled" > -        <bool>false</bool> -       </property> -       <property name="text" > -        <string>Clean up</string> -       </property> -      </widget> -     </item> -     <item> -      <spacer> -       <property name="orientation" > -        <enum>Qt::Horizontal</enum> -       </property> -       <property name="sizeHint" stdset="0" > -        <size> -         <width>58</width> -         <height>24</height> -        </size> -       </property> -      </spacer> -     </item> -    </layout> -   </item> -   <item row="1" column="1" > -    <widget class="QLabel" name="itemCount" > -     <property name="text" > -      <string>0 Items</string> -     </property> -    </widget> -   </item> -   <item row="1" column="2" > -    <spacer name="horizontalSpacer" > -     <property name="orientation" > -      <enum>Qt::Horizontal</enum> -     </property> -     <property name="sizeHint" stdset="0" > -      <size> -       <width>148</width> -       <height>20</height> -      </size> -     </property> -    </spacer> -   </item> -  </layout> - </widget> - <customwidgets> -  <customwidget> -   <class>EditTableView</class> -   <extends>QTableView</extends> -   <header>edittableview.h</header> -  </customwidget> - </customwidgets> - <resources/> - <connections/> -</ui> | 
