Follow project coding style. Issue #2192.

This commit is contained in:
Eugene Shalygin 2016-02-28 02:17:45 +01:00
parent 8e64ffba01
commit f9c2bd3502
6 changed files with 852 additions and 840 deletions

View file

@ -32,7 +32,7 @@
#include <QDebug> #include <QDebug>
#include "downloadedpiecesbar.h" #include "downloadedpiecesbar.h"
DownloadedPiecesBar::DownloadedPiecesBar(QWidget *parent): QWidget(parent) DownloadedPiecesBar::DownloadedPiecesBar(QWidget *parent) : QWidget(parent)
{ {
setToolTip(QString("%1\n%2\n%3").arg(tr("White: Missing pieces")).arg(tr("Green: Partial pieces")).arg(tr("Blue: Completed pieces"))); setToolTip(QString("%1\n%2\n%3").arg(tr("White: Missing pieces")).arg(tr("Green: Partial pieces")).arg(tr("Blue: Completed pieces")));
@ -78,33 +78,28 @@ QVector<float> DownloadedPiecesBar::bitfieldToFloatVector(const QBitArray &vecin
// case when calculated range is (15.2 >= x < 15.7) // case when calculated range is (15.2 >= x < 15.7)
if (x2 == toCMinusOne) { if (x2 == toCMinusOne) {
if (vecin[x2]) { if (vecin[x2])
value += ratio; value += ratio;
}
++x2; ++x2;
} }
// case when (15.2 >= x < 17.8) // case when (15.2 >= x < 17.8)
else { else {
// subcase (15.2 >= x < 16) // subcase (15.2 >= x < 16)
if (x2 != fromR) { if (x2 != fromR) {
if (vecin[x2]) { if (vecin[x2])
value += 1.0 - (fromR - fromC); value += 1.0 - (fromR - fromC);
}
++x2; ++x2;
} }
// subcase (16 >= x < 17) // subcase (16 >= x < 17)
for (; x2 < toCMinusOne; ++x2) { for (; x2 < toCMinusOne; ++x2)
if (vecin[x2]) { if (vecin[x2])
value += 1.0; value += 1.0;
}
}
// subcase (17 >= x < 17.8) // subcase (17 >= x < 17.8)
if (x2 == toCMinusOne) { if (x2 == toCMinusOne) {
if (vecin[x2]) { if (vecin[x2])
value += 1.0 - (toC - toR); value += 1.0 - (toC - toR);
}
++x2; ++x2;
} }
} }
@ -121,7 +116,6 @@ QVector<float> DownloadedPiecesBar::bitfieldToFloatVector(const QBitArray &vecin
return result; return result;
} }
int DownloadedPiecesBar::mixTwoColors(int &rgb1, int &rgb2, float ratio) int DownloadedPiecesBar::mixTwoColors(int &rgb1, int &rgb2, float ratio)
{ {
int r1 = qRed(rgb1); int r1 = qRed(rgb1);
@ -160,12 +154,10 @@ void DownloadedPiecesBar::updateImage()
QVector<float> scaled_pieces_dl = bitfieldToFloatVector(m_downloadedPieces, image2.width()); QVector<float> scaled_pieces_dl = bitfieldToFloatVector(m_downloadedPieces, image2.width());
// filling image // filling image
for (int x = 0; x < scaled_pieces.size(); ++x) for (int x = 0; x < scaled_pieces.size(); ++x) {
{
float pieces2_val = scaled_pieces.at(x); float pieces2_val = scaled_pieces.at(x);
float pieces2_val_dl = scaled_pieces_dl.at(x); float pieces2_val_dl = scaled_pieces_dl.at(x);
if (pieces2_val_dl != 0) if (pieces2_val_dl != 0) {
{
float fill_ratio = pieces2_val + pieces2_val_dl; float fill_ratio = pieces2_val + pieces2_val_dl;
float ratio = pieces2_val_dl / fill_ratio; float ratio = pieces2_val_dl / fill_ratio;
@ -174,8 +166,7 @@ void DownloadedPiecesBar::updateImage()
image2.setPixel(x, 0, mixedColor); image2.setPixel(x, 0, mixedColor);
} }
else else {
{
image2.setPixel(x, 0, m_pieceColors[pieces2_val * 255]); image2.setPixel(x, 0, m_pieceColors[pieces2_val * 255]);
} }
} }
@ -206,17 +197,15 @@ void DownloadedPiecesBar::clear()
update(); update();
} }
void DownloadedPiecesBar::paintEvent(QPaintEvent *) void DownloadedPiecesBar::paintEvent(QPaintEvent*)
{ {
QPainter painter(this); QPainter painter(this);
QRect imageRect(1, 1, width() - 2, height() - 2); QRect imageRect(1, 1, width() - 2, height() - 2);
if (m_image.isNull()) if (m_image.isNull()) {
{
painter.setBrush(Qt::white); painter.setBrush(Qt::white);
painter.drawRect(imageRect); painter.drawRect(imageRect);
} }
else else {
{
if (m_image.width() != imageRect.width()) if (m_image.width() != imageRect.width())
updateImage(); updateImage();
painter.drawImage(imageRect, m_image); painter.drawImage(imageRect, m_image);
@ -239,5 +228,3 @@ void DownloadedPiecesBar::setColors(int background, int border, int complete, in
updateImage(); updateImage();
update(); update();
} }

View file

@ -32,7 +32,6 @@
#include <QDebug> #include <QDebug>
#include "pieceavailabilitybar.h" #include "pieceavailabilitybar.h"
PieceAvailabilityBar::PieceAvailabilityBar(QWidget *parent) PieceAvailabilityBar::PieceAvailabilityBar(QWidget *parent)
: QWidget(parent) : QWidget(parent)
{ {
@ -192,7 +191,7 @@ void PieceAvailabilityBar::clear()
update(); update();
} }
void PieceAvailabilityBar::paintEvent(QPaintEvent *) void PieceAvailabilityBar::paintEvent(QPaintEvent*)
{ {
QPainter painter(this); QPainter painter(this);
QRect imageRect(1, 1, width() - 2, height() - 2); QRect imageRect(1, 1, width() - 2, height() - 2);

View file

@ -76,7 +76,7 @@ public:
void setColors(int background, int border, int available); void setColors(int background, int border, int available);
protected: protected:
void paintEvent(QPaintEvent *); void paintEvent(QPaintEvent*);
}; };
#endif // PIECEAVAILABILITYBAR_H #endif // PIECEAVAILABILITYBAR_H

View file

@ -28,6 +28,8 @@
* Contact : chris@qbittorrent.org * Contact : chris@qbittorrent.org
*/ */
#include "propertieswidget.h"
#include <QDebug> #include <QDebug>
#include <QTimer> #include <QTimer>
#include <QListWidgetItem> #include <QListWidgetItem>
@ -61,10 +63,10 @@
#include "lineedit.h" #include "lineedit.h"
#include "transferlistwidget.h" #include "transferlistwidget.h"
#include "autoexpandabledialog.h" #include "autoexpandabledialog.h"
#include "propertieswidget.h"
PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow* main_window, TransferListWidget *transferList): PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow *main_window, TransferListWidget *transferList)
QWidget(parent), transferList(transferList), main_window(main_window), m_torrent(0) { : QWidget(parent), transferList(transferList), main_window(main_window), m_torrent(0)
{
setupUi(this); setupUi(this);
setAutoFillBackground(true); setAutoFillBackground(true);
@ -88,17 +90,17 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow* main_window, Tra
connect(selectAllButton, SIGNAL(clicked()), PropListModel, SLOT(selectAll())); connect(selectAllButton, SIGNAL(clicked()), PropListModel, SLOT(selectAll()));
connect(selectNoneButton, SIGNAL(clicked()), PropListModel, SLOT(selectNone())); connect(selectNoneButton, SIGNAL(clicked()), PropListModel, SLOT(selectNone()));
connect(filesList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayFilesListMenu(const QPoint&))); connect(filesList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayFilesListMenu(const QPoint&)));
connect(filesList, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(openDoubleClickedFile(const QModelIndex &))); connect(filesList, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(openDoubleClickedFile(const QModelIndex&)));
connect(PropListModel, SIGNAL(filteredFilesChanged()), this, SLOT(filteredFilesChanged())); connect(PropListModel, SIGNAL(filteredFilesChanged()), this, SLOT(filteredFilesChanged()));
connect(listWebSeeds, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayWebSeedListMenu(const QPoint&))); connect(listWebSeeds, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayWebSeedListMenu(const QPoint&)));
connect(transferList, SIGNAL(currentTorrentChanged(BitTorrent::TorrentHandle *const)), this, SLOT(loadTorrentInfos(BitTorrent::TorrentHandle *const))); connect(transferList, SIGNAL(currentTorrentChanged(BitTorrent::TorrentHandle * const)), this, SLOT(loadTorrentInfos(BitTorrent::TorrentHandle * const)));
connect(PropDelegate, SIGNAL(filteredFilesChanged()), this, SLOT(filteredFilesChanged())); connect(PropDelegate, SIGNAL(filteredFilesChanged()), this, SLOT(filteredFilesChanged()));
connect(stackedProperties, SIGNAL(currentChanged(int)), this, SLOT(loadDynamicData())); connect(stackedProperties, SIGNAL(currentChanged(int)), this, SLOT(loadDynamicData()));
connect(BitTorrent::Session::instance(), SIGNAL(torrentSavePathChanged(BitTorrent::TorrentHandle *const)), this, SLOT(updateSavePath(BitTorrent::TorrentHandle *const))); connect(BitTorrent::Session::instance(), SIGNAL(torrentSavePathChanged(BitTorrent::TorrentHandle * const)), this, SLOT(updateSavePath(BitTorrent::TorrentHandle * const)));
connect(BitTorrent::Session::instance(), SIGNAL(torrentMetadataLoaded(BitTorrent::TorrentHandle *const)), this, SLOT(updateTorrentInfos(BitTorrent::TorrentHandle *const))); connect(BitTorrent::Session::instance(), SIGNAL(torrentMetadataLoaded(BitTorrent::TorrentHandle * const)), this, SLOT(updateTorrentInfos(BitTorrent::TorrentHandle * const)));
connect(filesList->header(), SIGNAL(sectionMoved(int, int, int)), this, SLOT(saveSettings())); connect(filesList->header(), SIGNAL(sectionMoved(int,int,int)), this, SLOT(saveSettings()));
connect(filesList->header(), SIGNAL(sectionResized(int, int, int)), this, SLOT(saveSettings())); connect(filesList->header(), SIGNAL(sectionResized(int,int,int)), this, SLOT(saveSettings()));
connect(filesList->header(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), this, SLOT(saveSettings())); connect(filesList->header(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(saveSettings()));
#ifdef QBT_USES_QT5 #ifdef QBT_USES_QT5
// set bar height relative to screen dpi // set bar height relative to screen dpi
@ -133,15 +135,15 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow* main_window, Tra
connect(trackerUpButton, SIGNAL(clicked()), trackerList, SLOT(moveSelectionUp())); connect(trackerUpButton, SIGNAL(clicked()), trackerList, SLOT(moveSelectionUp()));
connect(trackerDownButton, SIGNAL(clicked()), trackerList, SLOT(moveSelectionDown())); connect(trackerDownButton, SIGNAL(clicked()), trackerList, SLOT(moveSelectionDown()));
horizontalLayout_trackers->insertWidget(0, trackerList); horizontalLayout_trackers->insertWidget(0, trackerList);
connect(trackerList->header(), SIGNAL(sectionMoved(int, int, int)), trackerList, SLOT(saveSettings())); connect(trackerList->header(), SIGNAL(sectionMoved(int,int,int)), trackerList, SLOT(saveSettings()));
connect(trackerList->header(), SIGNAL(sectionResized(int, int, int)), trackerList, SLOT(saveSettings())); connect(trackerList->header(), SIGNAL(sectionResized(int,int,int)), trackerList, SLOT(saveSettings()));
connect(trackerList->header(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), trackerList, SLOT(saveSettings())); connect(trackerList->header(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), trackerList, SLOT(saveSettings()));
// Peers list // Peers list
peersList = new PeerListWidget(this); peersList = new PeerListWidget(this);
peerpage_layout->addWidget(peersList); peerpage_layout->addWidget(peersList);
connect(peersList->header(), SIGNAL(sectionMoved(int, int, int)), peersList, SLOT(saveSettings())); connect(peersList->header(), SIGNAL(sectionMoved(int,int,int)), peersList, SLOT(saveSettings()));
connect(peersList->header(), SIGNAL(sectionResized(int, int, int)), peersList, SLOT(saveSettings())); connect(peersList->header(), SIGNAL(sectionResized(int,int,int)), peersList, SLOT(saveSettings()));
connect(peersList->header(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), peersList, SLOT(saveSettings())); connect(peersList->header(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), peersList, SLOT(saveSettings()));
// Speed widget // Speed widget
speedWidget = new SpeedWidget(this); speedWidget = new SpeedWidget(this);
speed_layout->addWidget(speedWidget); speed_layout->addWidget(speedWidget);
@ -168,7 +170,8 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow* main_window, Tra
connect(openHotkeyFile, SIGNAL(activated()), SLOT(openSelectedFile())); connect(openHotkeyFile, SIGNAL(activated()), SLOT(openSelectedFile()));
} }
PropertiesWidget::~PropertiesWidget() { PropertiesWidget::~PropertiesWidget()
{
qDebug() << Q_FUNC_INFO << "ENTER"; qDebug() << Q_FUNC_INFO << "ENTER";
delete refreshTimer; delete refreshTimer;
delete trackerList; delete trackerList;
@ -186,7 +189,8 @@ PropertiesWidget::~PropertiesWidget() {
qDebug() << Q_FUNC_INFO << "EXIT"; qDebug() << Q_FUNC_INFO << "EXIT";
} }
void PropertiesWidget::showPiecesAvailability(bool show) { void PropertiesWidget::showPiecesAvailability(bool show)
{
avail_pieces_lbl->setVisible(show); avail_pieces_lbl->setVisible(show);
pieces_availability->setVisible(show); pieces_availability->setVisible(show);
avail_average_lbl->setVisible(show); avail_average_lbl->setVisible(show);
@ -194,7 +198,8 @@ void PropertiesWidget::showPiecesAvailability(bool show) {
line_2->setVisible(show); line_2->setVisible(show);
} }
void PropertiesWidget::showPiecesDownloaded(bool show) { void PropertiesWidget::showPiecesDownloaded(bool show)
{
downloaded_pieces_lbl->setVisible(show); downloaded_pieces_lbl->setVisible(show);
downloaded_pieces->setVisible(show); downloaded_pieces->setVisible(show);
progress_lbl->setVisible(show); progress_lbl->setVisible(show);
@ -202,22 +207,23 @@ void PropertiesWidget::showPiecesDownloaded(bool show) {
line_2->setVisible(show); line_2->setVisible(show);
} }
void PropertiesWidget::setVisibility(bool visible) { void PropertiesWidget::setVisibility(bool visible)
if (!visible && state == VISIBLE) { {
QSplitter *hSplitter = static_cast<QSplitter*>(parentWidget()); if (!visible && ( state == VISIBLE) ) {
QSplitter *hSplitter = static_cast<QSplitter *>(parentWidget());
stackedProperties->setVisible(false); stackedProperties->setVisible(false);
slideSizes = hSplitter->sizes(); slideSizes = hSplitter->sizes();
hSplitter->handle(1)->setVisible(false); hSplitter->handle(1)->setVisible(false);
hSplitter->handle(1)->setDisabled(true); hSplitter->handle(1)->setDisabled(true);
QList<int> sizes = QList<int>() << hSplitter->geometry().height()-30 << 30; QList<int> sizes = QList<int>() << hSplitter->geometry().height() - 30 << 30;
hSplitter->setSizes(sizes); hSplitter->setSizes(sizes);
state = REDUCED; state = REDUCED;
return; return;
} }
if (visible && state == REDUCED) { if (visible && ( state == REDUCED) ) {
stackedProperties->setVisible(true); stackedProperties->setVisible(true);
QSplitter *hSplitter = static_cast<QSplitter*>(parentWidget()); QSplitter *hSplitter = static_cast<QSplitter *>(parentWidget());
hSplitter->handle(1)->setDisabled(false); hSplitter->handle(1)->setDisabled(false);
hSplitter->handle(1)->setVisible(true); hSplitter->handle(1)->setVisible(true);
hSplitter->setSizes(slideSizes); hSplitter->setSizes(slideSizes);
@ -227,7 +233,8 @@ void PropertiesWidget::setVisibility(bool visible) {
} }
} }
void PropertiesWidget::clear() { void PropertiesWidget::clear()
{
qDebug("Clearing torrent properties"); qDebug("Clearing torrent properties");
save_path->clear(); save_path->clear();
lbl_creationDate->clear(); lbl_creationDate->clear();
@ -271,9 +278,8 @@ BitTorrent::TorrentHandle *PropertiesWidget::getCurrentTorrent() const
void PropertiesWidget::updateSavePath(BitTorrent::TorrentHandle *const torrent) void PropertiesWidget::updateSavePath(BitTorrent::TorrentHandle *const torrent)
{ {
if (m_torrent == torrent) { if (m_torrent == torrent)
save_path->setText(Utils::Fs::toNativePath(m_torrent->savePath())); save_path->setText(Utils::Fs::toNativePath(m_torrent->savePath()));
}
} }
void PropertiesWidget::loadTrackers(BitTorrent::TorrentHandle *const torrent) void PropertiesWidget::loadTrackers(BitTorrent::TorrentHandle *const torrent)
@ -324,59 +330,60 @@ void PropertiesWidget::loadTorrentInfos(BitTorrent::TorrentHandle *const torrent
loadDynamicData(); loadDynamicData();
} }
void PropertiesWidget::readSettings() { void PropertiesWidget::readSettings()
const Preferences* const pref = Preferences::instance(); {
const Preferences *const pref = Preferences::instance();
// Restore splitter sizes // Restore splitter sizes
QStringList sizes_str = pref->getPropSplitterSizes().split(","); QStringList sizes_str = pref->getPropSplitterSizes().split(",");
if (sizes_str.size() == 2) { if (sizes_str.size() == 2) {
slideSizes << sizes_str.first().toInt(); slideSizes << sizes_str.first().toInt();
slideSizes << sizes_str.last().toInt(); slideSizes << sizes_str.last().toInt();
QSplitter *hSplitter = static_cast<QSplitter*>(parentWidget()); QSplitter *hSplitter = static_cast<QSplitter *>(parentWidget());
hSplitter->setSizes(slideSizes); hSplitter->setSizes(slideSizes);
} }
const int current_tab = pref->getPropCurTab(); const int current_tab = pref->getPropCurTab();
const bool visible = pref->getPropVisible(); const bool visible = pref->getPropVisible();
// the following will call saveSettings but shouldn't change any state // the following will call saveSettings but shouldn't change any state
if (!filesList->header()->restoreState(pref->getPropFileListState())) { if (!filesList->header()->restoreState(pref->getPropFileListState()))
filesList->header()->resizeSection(0, 400); //Default filesList->header()->resizeSection(0, 400); // Default
}
m_tabBar->setCurrentIndex(current_tab); m_tabBar->setCurrentIndex(current_tab);
if (!visible) { if (!visible)
setVisibility(false); setVisibility(false);
}
} }
void PropertiesWidget::saveSettings() { void PropertiesWidget::saveSettings()
Preferences* const pref = Preferences::instance(); {
Preferences *const pref = Preferences::instance();
pref->setPropVisible(state==VISIBLE); pref->setPropVisible(state==VISIBLE);
// Splitter sizes // Splitter sizes
QSplitter *hSplitter = static_cast<QSplitter*>(parentWidget()); QSplitter *hSplitter = static_cast<QSplitter *>(parentWidget());
QList<int> sizes; QList<int> sizes;
if (state == VISIBLE) if (state == VISIBLE)
sizes = hSplitter->sizes(); sizes = hSplitter->sizes();
else else
sizes = slideSizes; sizes = slideSizes;
qDebug("Sizes: %d", sizes.size()); qDebug("Sizes: %d", sizes.size());
if (sizes.size() == 2) { if (sizes.size() == 2)
pref->setPropSplitterSizes(QString::number(sizes.first()) + ',' + QString::number(sizes.last())); pref->setPropSplitterSizes(QString::number(sizes.first()) + ',' + QString::number(sizes.last()));
}
pref->setPropFileListState(filesList->header()->saveState()); pref->setPropFileListState(filesList->header()->saveState());
// Remember current tab // Remember current tab
pref->setPropCurTab(m_tabBar->currentIndex()); pref->setPropCurTab(m_tabBar->currentIndex());
} }
void PropertiesWidget::reloadPreferences() { void PropertiesWidget::reloadPreferences()
{
// Take program preferences into consideration // Take program preferences into consideration
peersList->updatePeerHostNameResolutionState(); peersList->updatePeerHostNameResolutionState();
peersList->updatePeerCountryResolutionState(); peersList->updatePeerCountryResolutionState();
} }
void PropertiesWidget::loadDynamicData() { void PropertiesWidget::loadDynamicData()
{
// Refresh only if the torrent handle is valid and if visible // Refresh only if the torrent handle is valid and if visible
if (!m_torrent || (main_window->currentTabWidget() != transferList) || (state != VISIBLE)) return; if (!m_torrent || (main_window->currentTabWidget() != transferList) || (state != VISIBLE)) return;
// Transfer infos // Transfer infos
switch(stackedProperties->currentIndex()) { switch (stackedProperties->currentIndex()) {
case PropTabBar::MAIN_TAB: { case PropTabBar::MAIN_TAB: {
wasted->setText(Utils::Misc::friendlyUnit(m_torrent->wastedSize())); wasted->setText(Utils::Misc::friendlyUnit(m_torrent->wastedSize()));
@ -449,7 +456,7 @@ void PropertiesWidget::loadDynamicData() {
// Progress // Progress
qreal progress = m_torrent->progress() * 100.; qreal progress = m_torrent->progress() * 100.;
progress_lbl->setText(Utils::String::fromDouble(progress, 1)+"%"); progress_lbl->setText(Utils::String::fromDouble(progress, 1) + "%");
downloaded_pieces->setProgress(m_torrent->pieces(), m_torrent->downloadingPieces()); downloaded_pieces->setProgress(m_torrent->pieces(), m_torrent->downloadingPieces());
} }
else { else {
@ -490,7 +497,8 @@ void PropertiesWidget::loadDynamicData() {
} }
} }
void PropertiesWidget::loadUrlSeeds() { void PropertiesWidget::loadUrlSeeds()
{
listWebSeeds->clear(); listWebSeeds->clear();
qDebug("Loading URL seeds"); qDebug("Loading URL seeds");
const QList<QUrl> hc_seeds = m_torrent->urlSeeds(); const QList<QUrl> hc_seeds = m_torrent->urlSeeds();
@ -501,7 +509,8 @@ void PropertiesWidget::loadUrlSeeds() {
} }
} }
void PropertiesWidget::openDoubleClickedFile(const QModelIndex &index) { void PropertiesWidget::openDoubleClickedFile(const QModelIndex &index)
{
if (!index.isValid()) return; if (!index.isValid()) return;
if (!m_torrent || !m_torrent->hasMetadata()) return; if (!m_torrent || !m_torrent->hasMetadata()) return;
if (PropListModel->itemType(index) == TorrentContentModelItem::FileType) if (PropListModel->itemType(index) == TorrentContentModelItem::FileType)
@ -510,7 +519,8 @@ void PropertiesWidget::openDoubleClickedFile(const QModelIndex &index) {
openFolder(index, false); openFolder(index, false);
} }
void PropertiesWidget::openFile(const QModelIndex &index) { void PropertiesWidget::openFile(const QModelIndex &index)
{
int i = PropListModel->getFileIndex(index); int i = PropListModel->getFileIndex(index);
const QDir saveDir(m_torrent->savePath(true)); const QDir saveDir(m_torrent->savePath(true));
const QString filename = m_torrent->filePath(i); const QString filename = m_torrent->filePath(i);
@ -521,7 +531,8 @@ void PropertiesWidget::openFile(const QModelIndex &index) {
Utils::Misc::openPath(file_path); Utils::Misc::openPath(file_path);
} }
void PropertiesWidget::openFolder(const QModelIndex &index, bool containing_folder) { void PropertiesWidget::openFolder(const QModelIndex &index, bool containing_folder)
{
QString absolute_path; QString absolute_path;
// FOLDER // FOLDER
if (PropListModel->itemType(index) == TorrentContentModelItem::FolderType) { if (PropListModel->itemType(index) == TorrentContentModelItem::FolderType) {
@ -529,7 +540,7 @@ void PropertiesWidget::openFolder(const QModelIndex &index, bool containing_fold
QStringList path_items; QStringList path_items;
path_items << index.data().toString(); path_items << index.data().toString();
QModelIndex parent = PropListModel->parent(index); QModelIndex parent = PropListModel->parent(index);
while(parent.isValid()) { while (parent.isValid()) {
path_items.prepend(parent.data().toString()); path_items.prepend(parent.data().toString());
parent = PropListModel->parent(parent); parent = PropListModel->parent(parent);
} }
@ -554,7 +565,8 @@ void PropertiesWidget::openFolder(const QModelIndex &index, bool containing_fold
Utils::Misc::openPath(absolute_path); Utils::Misc::openPath(absolute_path);
} }
void PropertiesWidget::displayFilesListMenu(const QPoint&) { void PropertiesWidget::displayFilesListMenu(const QPoint &)
{
if (!m_torrent) return; if (!m_torrent) return;
QModelIndexList selectedRows = filesList->selectionModel()->selectedRows(0); QModelIndexList selectedRows = filesList->selectionModel()->selectedRows(0);
@ -587,12 +599,15 @@ void PropertiesWidget::displayFilesListMenu(const QPoint&) {
if (!index.isValid()) if (!index.isValid())
return; return;
if (act) { if (act) {
if (act == actOpen) if (act == actOpen) {
openDoubleClickedFile(index); openDoubleClickedFile(index);
else if (act == actOpenContainingFolder) }
else if (act == actOpenContainingFolder) {
openFolder(index, true); openFolder(index, true);
else if (act == actRename) }
else if (act == actRename) {
renameSelectedFile(); renameSelectedFile();
}
else { else {
int prio = prio::NORMAL; int prio = prio::NORMAL;
if (act == actionHigh) if (act == actionHigh)
@ -613,7 +628,8 @@ void PropertiesWidget::displayFilesListMenu(const QPoint&) {
} }
} }
void PropertiesWidget::displayWebSeedListMenu(const QPoint&) { void PropertiesWidget::displayWebSeedListMenu(const QPoint &)
{
if (!m_torrent) return; if (!m_torrent) return;
QMenu seedMenu; QMenu seedMenu;
@ -643,7 +659,8 @@ void PropertiesWidget::displayWebSeedListMenu(const QPoint&) {
} }
} }
void PropertiesWidget::renameSelectedFile() { void PropertiesWidget::renameSelectedFile()
{
const QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(0); const QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(0);
if (selectedIndexes.size() != 1) if (selectedIndexes.size() != 1)
return; return;
@ -667,9 +684,8 @@ void PropertiesWidget::renameSelectedFile() {
const int file_index = PropListModel->getFileIndex(index); const int file_index = PropListModel->getFileIndex(index);
if (!m_torrent || !m_torrent->hasMetadata()) return; if (!m_torrent || !m_torrent->hasMetadata()) return;
QString old_name = m_torrent->filePath(file_index); QString old_name = m_torrent->filePath(file_index);
if (old_name.endsWith(".!qB") && !new_name_last.endsWith(".!qB")) { if (old_name.endsWith(".!qB") && !new_name_last.endsWith(".!qB"))
new_name_last += ".!qB"; new_name_last += ".!qB";
}
QStringList path_items = old_name.split("/"); QStringList path_items = old_name.split("/");
path_items.removeLast(); path_items.removeLast();
path_items << new_name_last; path_items << new_name_last;
@ -706,7 +722,7 @@ void PropertiesWidget::renameSelectedFile() {
QStringList path_items; QStringList path_items;
path_items << index.data().toString(); path_items << index.data().toString();
QModelIndex parent = PropListModel->parent(index); QModelIndex parent = PropListModel->parent(index);
while(parent.isValid()) { while (parent.isValid()) {
path_items.prepend(parent.data().toString()); path_items.prepend(parent.data().toString());
parent = PropListModel->parent(parent); parent = PropListModel->parent(parent);
} }
@ -754,7 +770,7 @@ void PropertiesWidget::renameSelectedFile() {
// Remove old folder // Remove old folder
const QDir old_folder(m_torrent->savePath(true) + "/" + old_path); const QDir old_folder(m_torrent->savePath(true) + "/" + old_path);
int timeout = 10; int timeout = 10;
while(!QDir().rmpath(old_folder.absolutePath()) && timeout > 0) { while (!QDir().rmpath(old_folder.absolutePath()) && timeout > 0) {
// FIXME: We should not sleep here (freezes the UI for 1 second) // FIXME: We should not sleep here (freezes the UI for 1 second)
Utils::Misc::msleep(100); Utils::Misc::msleep(100);
--timeout; --timeout;
@ -763,14 +779,16 @@ void PropertiesWidget::renameSelectedFile() {
} }
} }
void PropertiesWidget::openSelectedFile() { void PropertiesWidget::openSelectedFile()
{
const QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(0); const QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(0);
if (selectedIndexes.size() != 1) if (selectedIndexes.size() != 1)
return; return;
openDoubleClickedFile(selectedIndexes.first()); openDoubleClickedFile(selectedIndexes.first());
} }
void PropertiesWidget::askWebSeed() { void PropertiesWidget::askWebSeed()
{
bool ok; bool ok;
// Ask user for a new url seed // Ask user for a new url seed
const QString url_seed = AutoExpandableDialog::getText(this, tr("New URL seed", "New HTTP source"), const QString url_seed = AutoExpandableDialog::getText(this, tr("New URL seed", "New HTTP source"),
@ -790,7 +808,8 @@ void PropertiesWidget::askWebSeed() {
loadUrlSeeds(); loadUrlSeeds();
} }
void PropertiesWidget::deleteSelectedUrlSeeds() { void PropertiesWidget::deleteSelectedUrlSeeds()
{
const QList<QListWidgetItem *> selectedItems = listWebSeeds->selectedItems(); const QList<QListWidgetItem *> selectedItems = listWebSeeds->selectedItems();
if (selectedItems.isEmpty()) return; if (selectedItems.isEmpty()) return;
@ -803,7 +822,8 @@ void PropertiesWidget::deleteSelectedUrlSeeds() {
loadUrlSeeds(); loadUrlSeeds();
} }
void PropertiesWidget::copySelectedWebSeedsToClipboard() const { void PropertiesWidget::copySelectedWebSeedsToClipboard() const
{
const QList<QListWidgetItem *> selected_items = listWebSeeds->selectedItems(); const QList<QListWidgetItem *> selected_items = listWebSeeds->selectedItems();
if (selected_items.isEmpty()) if (selected_items.isEmpty())
return; return;
@ -815,7 +835,8 @@ void PropertiesWidget::copySelectedWebSeedsToClipboard() const {
QApplication::clipboard()->setText(urls_to_copy.join("\n")); QApplication::clipboard()->setText(urls_to_copy.join("\n"));
} }
void PropertiesWidget::editWebSeed() { void PropertiesWidget::editWebSeed()
{
const QList<QListWidgetItem *> selected_items = listWebSeeds->selectedItems(); const QList<QListWidgetItem *> selected_items = listWebSeeds->selectedItems();
if (selected_items.size() != 1) if (selected_items.size() != 1)
return; return;
@ -841,7 +862,8 @@ void PropertiesWidget::editWebSeed() {
loadUrlSeeds(); loadUrlSeeds();
} }
bool PropertiesWidget::applyPriorities() { bool PropertiesWidget::applyPriorities()
{
qDebug("Saving files priorities"); qDebug("Saving files priorities");
const QVector<int> priorities = PropListModel->model()->getFilePriorities(); const QVector<int> priorities = PropListModel->model()->getFilePriorities();
// Prioritize the files // Prioritize the files
@ -850,17 +872,20 @@ bool PropertiesWidget::applyPriorities() {
return true; return true;
} }
void PropertiesWidget::filteredFilesChanged() { void PropertiesWidget::filteredFilesChanged()
{
if (m_torrent) if (m_torrent)
applyPriorities(); applyPriorities();
} }
void PropertiesWidget::filterText(const QString& filter) { void PropertiesWidget::filterText(const QString &filter)
{
PropListModel->setFilterRegExp(QRegExp(filter, Qt::CaseInsensitive, QRegExp::WildcardUnix)); PropListModel->setFilterRegExp(QRegExp(filter, Qt::CaseInsensitive, QRegExp::WildcardUnix));
if (filter.isEmpty()) { if (filter.isEmpty()) {
filesList->collapseAll(); filesList->collapseAll();
filesList->expand(PropListModel->index(0, 0)); filesList->expand(PropListModel->index(0, 0));
} }
else else {
filesList->expandAll(); filesList->expandAll();
}
} }

View file

@ -55,7 +55,8 @@ class QAction;
class QTimer; class QTimer;
QT_END_NAMESPACE QT_END_NAMESPACE
class PropertiesWidget : public QWidget, private Ui::PropertiesWidget { class PropertiesWidget: public QWidget, private Ui::PropertiesWidget
{
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(PropertiesWidget) Q_DISABLE_COPY(PropertiesWidget)
@ -63,16 +64,16 @@ public:
enum SlideState {REDUCED, VISIBLE}; enum SlideState {REDUCED, VISIBLE};
public: public:
PropertiesWidget(QWidget *parent, MainWindow* main_window, TransferListWidget *transferList); PropertiesWidget(QWidget *parent, MainWindow *main_window, TransferListWidget *transferList);
~PropertiesWidget(); ~PropertiesWidget();
BitTorrent::TorrentHandle *getCurrentTorrent() const; BitTorrent::TorrentHandle *getCurrentTorrent() const;
TrackerList* getTrackerList() const { return trackerList; } TrackerList *getTrackerList() const { return trackerList; }
PeerListWidget* getPeerList() const { return peersList; } PeerListWidget *getPeerList() const { return peersList; }
QTreeView* getFilesList() const { return filesList; } QTreeView *getFilesList() const { return filesList; }
SpeedWidget* getSpeedWidget() const { return speedWidget; } SpeedWidget *getSpeedWidget() const { return speedWidget; }
protected: protected:
QPushButton* getButtonFromIndex(int index); QPushButton *getButtonFromIndex(int index);
bool applyPriorities(); bool applyPriorities();
protected slots: protected slots:
@ -83,8 +84,8 @@ protected slots:
void deleteSelectedUrlSeeds(); void deleteSelectedUrlSeeds();
void copySelectedWebSeedsToClipboard() const; void copySelectedWebSeedsToClipboard() const;
void editWebSeed(); void editWebSeed();
void displayFilesListMenu(const QPoint& pos); void displayFilesListMenu(const QPoint &pos);
void displayWebSeedListMenu(const QPoint& pos); void displayWebSeedListMenu(const QPoint &pos);
void filteredFilesChanged(); void filteredFilesChanged();
void showPiecesDownloaded(bool show); void showPiecesDownloaded(bool show);
void showPiecesAvailability(bool show); void showPiecesAvailability(bool show);
@ -127,7 +128,7 @@ private:
QShortcut *openHotkeyFile; QShortcut *openHotkeyFile;
private slots: private slots:
void filterText(const QString& filter); void filterText(const QString &filter);
void updateSavePath(BitTorrent::TorrentHandle *const torrent); void updateSavePath(BitTorrent::TorrentHandle *const torrent);
}; };