亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專(zhuān)輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? mainwindow.cpp

?? 基于QT4圖形庫(kù)的BT下載客戶(hù)端源碼
?? CPP
?? 第 1 頁(yè) / 共 2 頁(yè)
字號(hào):
/****************************************************************************
**
** Copyright (C) 2004-2006 Trolltech ASA. All rights reserved.
**
** This file is part of the example classes of the Qt Toolkit.
**
** Licensees holding a valid Qt License Agreement may use this file in
** accordance with the rights, responsibilities and obligations
** contained therein.  Please consult your licensing agreement or
** contact sales@trolltech.com if any conditions of this licensing
** agreement are not clear to you.
**
** Further information about Qt licensing is available at:
** http://www.trolltech.com/products/qt/licensing.html or by
** contacting info@trolltech.com.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/

#include <QtGui>

#include "addtorrentdialog.h"
#include "mainwindow.h"
#include "ratecontroller.h"
#include "torrentclient.h"

// TorrentView extends QTreeWidget to allow drag and drop.
class TorrentView : public QTreeWidget
{
    Q_OBJECT
public:
    TorrentView(QWidget *parent = 0);

signals:
    void fileDropped(const QString &fileName);

protected:
    void dragMoveEvent(QDragMoveEvent *event);
    void dropEvent(QDropEvent *event);
};

// TorrentViewDelegate is used to draw the progress bars.
class TorrentViewDelegate : public QItemDelegate
{
    Q_OBJECT
public:
    inline TorrentViewDelegate(MainWindow *mainWindow) : QItemDelegate(mainWindow) {}

    inline void paint(QPainter *painter, const QStyleOptionViewItem &option,
                      const QModelIndex &index ) const
    {
        if (index.column() != 2) {
            QItemDelegate::paint(painter, option, index);
            return;
        }

        // Set up a QStyleOptionProgressBar to precisely mimic the
        // environment of a progress bar.
        QStyleOptionProgressBar progressBarOption;
        progressBarOption.state = QStyle::State_Enabled;
        progressBarOption.direction = QApplication::layoutDirection();
        progressBarOption.rect = option.rect;
        progressBarOption.fontMetrics = QApplication::fontMetrics();
        progressBarOption.minimum = 0;
        progressBarOption.maximum = 100;
        progressBarOption.textAlignment = Qt::AlignCenter;
        progressBarOption.textVisible = true;

        // Set the progress and text values of the style option.
        int progress = qobject_cast<MainWindow *>(parent())->clientForRow(index.row())->progress();
        progressBarOption.progress = progress < 0 ? 0 : progress;
        progressBarOption.text = QString().sprintf("%d%%", progressBarOption.progress);

        // Draw the progress bar onto the view.
        QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
    }
};

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), quitDialog(0), saveChanges(false)
{
    // Initialize some static strings
    QStringList headers;
    headers << tr("Torrent") << tr("Peers/Seeds") << tr("Progress")
            << tr("Down rate") << tr("Up rate") << tr("Status");

    // Main torrent list
    torrentView = new TorrentView(this);
    torrentView->setItemDelegate(new TorrentViewDelegate(this));
    torrentView->setHeaderLabels(headers);
    torrentView->setSelectionBehavior(QAbstractItemView::SelectRows);
    torrentView->setAlternatingRowColors(true);
    torrentView->setRootIsDecorated(false);
    setCentralWidget(torrentView);

    // Set header resize modes and initial section sizes
    QFontMetrics fm = fontMetrics();
    QHeaderView *header = torrentView->header();
    header->resizeSection(0, fm.width("typical-name-for-a-torrent.torrent"));
    header->resizeSection(1, fm.width(headers.at(1) + "  "));
    header->resizeSection(2, fm.width(headers.at(2) + "  "));
    header->resizeSection(3, qMax(fm.width(headers.at(3) + "  "), fm.width(" 1234.0 KB/s ")));
    header->resizeSection(4, qMax(fm.width(headers.at(4) + "  "), fm.width(" 1234.0 KB/s ")));
    header->resizeSection(5, qMax(fm.width(headers.at(5) + "  "), fm.width(tr("Downloading") + "  ")));

    // Create common actions
    QAction *newTorrentAction = new QAction(QIcon(":/icons/bottom.png"), tr("Add &new torrent"), this);
    pauseTorrentAction = new QAction(QIcon(":/icons/player_pause.png"), tr("&Pause torrent"), this);
    removeTorrentAction = new QAction(QIcon(":/icons/player_stop.png"), tr("&Remove torrent"), this);
    
    // File menu
    QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
    fileMenu->addAction(newTorrentAction);
    fileMenu->addAction(pauseTorrentAction);
    fileMenu->addAction(removeTorrentAction);
    fileMenu->addSeparator();
    fileMenu->addAction(QIcon(":/icons/exit.png"), tr("E&xit"), this, SLOT(close()));

    // Help menu
    QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
    helpMenu->addAction(tr("&About"), this, SLOT(about()));
    helpMenu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt()));

    // Top toolbar
    QToolBar *topBar = new QToolBar(tr("Tools"));
    addToolBar(Qt::TopToolBarArea, topBar);
    topBar->setMovable(false);
    topBar->addAction(newTorrentAction);
    topBar->addAction(removeTorrentAction);
    topBar->addAction(pauseTorrentAction);
    topBar->addSeparator();
    downActionTool = topBar->addAction(QIcon(tr(":/icons/1downarrow.png")), tr("Move down"));
    upActionTool = topBar->addAction(QIcon(tr(":/icons/1uparrow.png")), tr("Move up"));

    // Bottom toolbar
    QToolBar *bottomBar = new QToolBar(tr("Rate control"));
    addToolBar(Qt::BottomToolBarArea, bottomBar);
    bottomBar->setMovable(false);
    downloadLimitSlider = new QSlider(Qt::Horizontal);
    downloadLimitSlider->setRange(0, 1000);
    bottomBar->addWidget(new QLabel(tr("Max download:")));
    bottomBar->addWidget(downloadLimitSlider);
    bottomBar->addWidget((downloadLimitLabel = new QLabel(tr("0 KB/s"))));
    downloadLimitLabel->setFixedSize(QSize(fm.width(tr("99999 KB/s")), fm.lineSpacing()));
    bottomBar->addSeparator();
    uploadLimitSlider = new QSlider(Qt::Horizontal);
    uploadLimitSlider->setRange(0, 1000);
    bottomBar->addWidget(new QLabel(tr("Max upload:")));
    bottomBar->addWidget(uploadLimitSlider);
    bottomBar->addWidget((uploadLimitLabel = new QLabel(tr("0 KB/s"))));
    uploadLimitLabel->setFixedSize(QSize(fm.width(tr("99999 KB/s")), fm.lineSpacing()));

    // Set up connections
    connect(torrentView, SIGNAL(itemSelectionChanged()),
            this, SLOT(setActionsEnabled()));
    connect(torrentView, SIGNAL(fileDropped(const QString &)),
            this, SLOT(acceptFileDrop(const QString &)));
    connect(uploadLimitSlider, SIGNAL(valueChanged(int)),
            this, SLOT(setUploadLimit(int)));
    connect(downloadLimitSlider, SIGNAL(valueChanged(int)),
            this, SLOT(setDownloadLimit(int)));
    connect(newTorrentAction, SIGNAL(triggered()),
            this, SLOT(addTorrent()));
    connect(pauseTorrentAction, SIGNAL(triggered()),
            this, SLOT(pauseTorrent()));
    connect(removeTorrentAction, SIGNAL(triggered()),
            this, SLOT(removeTorrent()));
    connect(upActionTool, SIGNAL(triggered(bool)),
            this, SLOT(moveTorrentUp()));
    connect(downActionTool, SIGNAL(triggered(bool)),
            this, SLOT(moveTorrentDown()));

    // Load settings and start
    setWindowTitle(tr("Torrent Client"));
    setActionsEnabled();
    QMetaObject::invokeMethod(this, "loadSettings", Qt::QueuedConnection);
}

QSize MainWindow::sizeHint() const
{
    const QHeaderView *header = torrentView->header();

    // Add up the sizes of all header sections. The last section is
    // stretched, so its size is relative to the size of the width;
    // instead of counting it, we count the size of its largest value.
    int width = fontMetrics().width(tr("Downloading") + "  ");
    for (int i = 0; i < header->count() - 1; ++i)
        width += header->sectionSize(i);

    return QSize(width, QMainWindow::sizeHint().height())
        .expandedTo(QApplication::globalStrut());
}

const TorrentClient *MainWindow::clientForRow(int row) const
{
    // Return the client at the given row.
    return jobs.at(row).client;
}

int MainWindow::rowOfClient(TorrentClient *client) const
{
    // Return the row that displays this client's status, or -1 if the
    // client is not known.
    int row = 0;
    foreach (Job job, jobs) {
        if (job.client == client)
            return row;
        ++row;
    }
    return -1;
}

void MainWindow::loadSettings()
{
    // Load base settings (last working directory, upload/download limits).
    QSettings settings("Trolltech", "Torrent");
    lastDirectory = settings.value("LastDirectory").toString();
    if (lastDirectory.isEmpty())
        lastDirectory = QDir::currentPath();
    int up = settings.value("UploadLimit").toInt();
    int down = settings.value("DownloadLimit").toInt();
    uploadLimitSlider->setValue(up ? up : 170);
    downloadLimitSlider->setValue(down ? down : 550);

    // Resume all previous downloads.
    int size = settings.beginReadArray("Torrents");
    for (int i = 0; i < size; ++i) {
        settings.setArrayIndex(i);
        QByteArray resumeState = settings.value("resumeState").toByteArray();
        QString fileName = settings.value("sourceFileName").toString();
        QString dest = settings.value("destinationFolder").toString();

        if (addTorrent(fileName, dest, resumeState)) {
            TorrentClient *client = jobs.last().client;
            client->setDownloadedBytes(settings.value("downloadedBytes").toLongLong());
            client->setUploadedBytes(settings.value("uploadedBytes").toLongLong());
        }
    }
}

bool MainWindow::addTorrent()
{
    // Show the file dialog, let the user select what torrent to start downloading.
    QString fileName = QFileDialog::getOpenFileName(this, tr("Choose a torrent file"),
                                                    lastDirectory,
                                                    tr("Torrents (*.torrent);;"
                                                       " All files (*.*)"));
    if (fileName.isEmpty())
        return false;
    lastDirectory = QFileInfo(fileName).absolutePath();

    // Show the "Add Torrent" dialog.
    AddTorrentDialog *addTorrentDialog = new AddTorrentDialog(this);
    addTorrentDialog->setTorrent(fileName);
    addTorrentDialog->deleteLater();
    if (!addTorrentDialog->exec())
        return false;

    // Add the torrent to our list of downloads
    addTorrent(fileName, addTorrentDialog->destinationFolder());
    if (!saveChanges) {
        saveChanges = true;
        QTimer::singleShot(1000, this, SLOT(saveSettings()));
    }
    return true;
}

void MainWindow::removeTorrent()
{
    // Find the row of the current item, and find the torrent client
    // for that row.
    int row = torrentView->indexOfTopLevelItem(torrentView->currentItem());
    TorrentClient *client = jobs.at(row).client;

    // Stop the client.
    client->disconnect();
    connect(client, SIGNAL(stopped()), this, SLOT(torrentStopped()));
    client->stop();

    // Remove the row from the view.
    delete torrentView->takeTopLevelItem(row);
    jobs.removeAt(row);
    setActionsEnabled();

    saveChanges = true;
    saveSettings();
}

void MainWindow::torrentStopped()
{
    // Schedule the client for deletion.
    TorrentClient *client = qobject_cast<TorrentClient *>(sender());
    client->deleteLater();

    // If the quit dialog is shown, update its progress.
    if (quitDialog) {
        if (++jobsStopped == jobsToStop)
            quitDialog->close();
    }
}

void MainWindow::torrentError(TorrentClient::Error)
{
    // Delete the client.
    TorrentClient *client = qobject_cast<TorrentClient *>(sender());
    int row = rowOfClient(client);
    QString fileName = jobs.at(row).torrentFileName;
    jobs.removeAt(row);

    // Display the warning.
    QMessageBox::warning(this, tr("Error"),
                         tr("An error occurred while downloading %0: %1")
                         .arg(fileName)
                         .arg(client->errorString()));

    delete torrentView->takeTopLevelItem(row);
    client->deleteLater();
}

bool MainWindow::addTorrent(const QString &fileName, const QString &destinationFolder,
                            const QByteArray &resumeState)
{
    // Check if the torrent is already being downloaded.
    foreach (Job job, jobs) {
        if (job.torrentFileName == fileName && job.destinationDirectory == destinationFolder) {
            QMessageBox::warning(this, tr("Already downloading"),
                                 tr("The torrent file you have selected is "
                                    "already being downloaded."));
            return false;
        }
    }

    // Create a new torrent client and attempt to parse the torrent data.
    TorrentClient *client = new TorrentClient(this);
    if (!client->setTorrent(fileName)) {
        QMessageBox::warning(this, tr("Error"),
                             tr("The torrent file you have selected can not be opened."));
        delete client;
        return false;
    }
    client->setDestinationFolder(destinationFolder);
    client->setDumpedState(resumeState);

    // Setup the client connections.
    connect(client, SIGNAL(stateChanged(TorrentClient::State)), this, SLOT(updateState(TorrentClient::State)));

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲精品久久嫩草网站秘色| 日韩av电影免费观看高清完整版| 欧美日韩激情一区二区三区| 国产在线看一区| 亚洲午夜久久久久久久久久久 | av网站免费线看精品| 日韩av在线发布| 亚洲精品国产a| 国产欧美一区二区在线观看| 91精品久久久久久久久99蜜臂| 成人美女视频在线观看| 麻豆极品一区二区三区| 夜夜嗨av一区二区三区中文字幕 | 欧美美女一区二区在线观看| 国产成人午夜片在线观看高清观看| 亚洲成人精品影院| 亚洲视频图片小说| 国产欧美一区二区在线| 日韩视频免费观看高清完整版| 欧美系列亚洲系列| 91麻豆精品秘密| 国产mv日韩mv欧美| 国产一区二区三区黄视频| 蜜桃一区二区三区在线| 香蕉久久夜色精品国产使用方法| 亚洲欧美激情小说另类| 亚洲欧洲另类国产综合| 中文子幕无线码一区tr| 国产拍欧美日韩视频二区 | 亚洲精品ww久久久久久p站 | 自拍偷自拍亚洲精品播放| 国产午夜亚洲精品羞羞网站| 精品国产精品网麻豆系列| 日韩视频免费观看高清完整版在线观看| 欧美群妇大交群的观看方式 | 亚洲精品一区二区三区香蕉| 欧美一区国产二区| 欧美一区二区三区男人的天堂| 欧美自拍偷拍午夜视频| 色视频一区二区| 欧美亚洲国产一卡| 欧美三级欧美一级| 欧美日韩1234| 91精品在线一区二区| 欧美一级欧美一级在线播放| 日韩视频一区二区在线观看| 欧美哺乳videos| 久久久蜜桃精品| 国产精品美女久久久久久2018| 国产精品第四页| 亚洲激情自拍偷拍| 婷婷中文字幕综合| 久久99国产精品免费网站| 国产美女精品一区二区三区| 国产成人亚洲精品狼色在线| 97久久久精品综合88久久| 色婷婷激情久久| 在线播放中文字幕一区| 欧美成人aa大片| 国产精品理论片在线观看| 亚洲日本电影在线| 视频一区免费在线观看| 久久爱www久久做| 大胆欧美人体老妇| 欧美电影免费观看高清完整版在线| 日韩欧美一区在线| 日本一区二区综合亚洲| 亚洲精品视频免费看| 日韩不卡在线观看日韩不卡视频| 久久国产日韩欧美精品| 波多野结衣视频一区| 欧美视频三区在线播放| 精品国产91乱码一区二区三区| 国产精品美女久久久久久2018| 亚洲线精品一区二区三区 | 午夜不卡在线视频| 国产一区 二区 三区一级| 日本精品免费观看高清观看| 欧美一区2区视频在线观看| 国产亚洲一区二区三区四区| **网站欧美大片在线观看| 午夜精品免费在线观看| 丰满少妇在线播放bd日韩电影| 一本大道久久a久久精品综合| 91精品国产欧美一区二区| 国产精品无人区| 青青青爽久久午夜综合久久午夜| 成人激情小说乱人伦| 51精品久久久久久久蜜臀| 国产精品美女一区二区| 免费欧美日韩国产三级电影| 92精品国产成人观看免费 | 久久一区二区三区四区| 亚洲黄色免费网站| 国产福利一区二区三区在线视频| 欧美在线免费播放| 中文一区二区在线观看| 青青国产91久久久久久| 91久久精品一区二区| 精品国产网站在线观看| 亚洲国产精品一区二区久久| 成人午夜精品在线| 精品毛片乱码1区2区3区 | 岛国一区二区在线观看| 欧美一级高清片| 亚洲在线视频一区| 不卡视频在线观看| 久久久久久久久岛国免费| 丝瓜av网站精品一区二区 | 99久久免费视频.com| 久久免费午夜影院| 日韩成人午夜电影| 欧美三级日韩三级| 一区二区在线观看视频在线观看| 国产91丝袜在线播放0| 欧美电影免费观看高清完整版在线| 亚洲网友自拍偷拍| 日韩视频免费观看高清完整版在线观看| 中文字幕综合网| 成人激情小说乱人伦| 国产片一区二区三区| 韩国欧美国产1区| 日韩欧美亚洲国产精品字幕久久久| 亚洲自拍与偷拍| 色88888久久久久久影院野外| 中文字幕欧美激情| 国产成人三级在线观看| 久久亚洲一区二区三区四区| 久久精品噜噜噜成人av农村| 制服丝袜中文字幕一区| 天堂蜜桃91精品| 欧美日韩精品一二三区| 午夜视频在线观看一区| 欧美性色黄大片| 亚洲第一成年网| 欧美日本一道本| 青青青伊人色综合久久| 欧美一卡二卡在线| 麻豆国产欧美日韩综合精品二区 | 欧美日韩一级黄| 亚洲v精品v日韩v欧美v专区| 欧美日本视频在线| 日本欧美一区二区三区乱码| 日韩区在线观看| 久久99精品久久久| 国产日产欧美一区二区视频| 丁香天五香天堂综合| 国产精品久久久久一区二区三区 | 欧美成人猛片aaaaaaa| 久久精品免费观看| 国产欧美综合在线| 91丨porny丨中文| 亚洲一区二区三区在线| 91精品啪在线观看国产60岁| 蜜桃传媒麻豆第一区在线观看| 精品国产一区二区三区久久影院| 国产激情精品久久久第一区二区 | 国产日韩欧美综合一区| 暴力调教一区二区三区| 亚洲一级片在线观看| 91精品麻豆日日躁夜夜躁| 国产一区二区精品久久99| 国产精品网站在线观看| 欧美专区日韩专区| 久久电影网电视剧免费观看| 国产精品视频一二三| 色婷婷综合久久| 日韩国产欧美在线播放| 久久久久亚洲蜜桃| 91看片淫黄大片一级在线观看| 丝袜美腿亚洲综合| 国产亚洲精品超碰| 欧美三区在线观看| 国产精品正在播放| 樱桃视频在线观看一区| 精品日产卡一卡二卡麻豆| av影院午夜一区| 男人的天堂亚洲一区| 国产精品黄色在线观看| 日韩一区二区三区在线视频| 成人精品视频一区二区三区 | 一区二区久久久久| 26uuu国产一区二区三区| 91伊人久久大香线蕉| 日本美女视频一区二区| 国产精品久久久久一区二区三区共 | 欧美激情一区二区在线| 欧美三级三级三级爽爽爽| 国产麻豆精品视频| 亚洲成人综合视频| 国产区在线观看成人精品| 欧美久久久久久久久| 成人免费视频caoporn| 日本麻豆一区二区三区视频| 亚洲欧美偷拍卡通变态| 久久久久久久久岛国免费| 欧美日韩色一区| 91视视频在线观看入口直接观看www| 麻豆成人91精品二区三区| 亚洲一区二区三区四区在线观看|