From 8ab990b7c6fb5348b09f451878a80e2c70695876 Mon Sep 17 00:00:00 2001 From: Arno Date: Fri, 19 Aug 2016 17:51:10 +0200 Subject: Added torrent support The BEncode parser is loosely based on this: https://github.com/jif/Bencode/blob/master/bencode.cpp Not perfect, but enough to display all the essential data in the shiny new TorrentDisplay dialog. --- shemovcleaner.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'shemovcleaner.cpp') diff --git a/shemovcleaner.cpp b/shemovcleaner.cpp index 9625db1..beb5baf 100644 --- a/shemovcleaner.cpp +++ b/shemovcleaner.cpp @@ -22,6 +22,8 @@ #include "shemovcleaner.h" #include "filesorter.h" +#include "torrentparser.h" +#include "torrentdisplay.h" ShemovCleaner::ShemovCleaner(QWidget *parent) : QMainWindow(parent){ QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL", "shemovdb"); @@ -76,10 +78,13 @@ void ShemovCleaner::setupGui(){ connect(mDelete, SIGNAL(clicked()), this, SLOT(deleteFiles())); mMove = new QPushButton(tr("Move...")); connect(mMove, SIGNAL(clicked()), this, SLOT(moveFiles())); + mInfo = new QPushButton(tr("Torrent...")); + connect(mInfo, SIGNAL(clicked()), this, SLOT(torrentInfo())); QHBoxLayout *buttonL2 = new QHBoxLayout; buttonL2->addStretch(); buttonL2->addWidget(mMove); buttonL2->addWidget(mDelete); + buttonL2->addWidget(mInfo); buttonL2->addStretch(); QWidget *mainWidget = new QWidget; @@ -94,6 +99,7 @@ void ShemovCleaner::setupGui(){ setCentralWidget(mainWidget); createStatusbar(); + mTorrentDisplay = new TorrentDisplay(this); connect(mFileView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(fileSelectionChanged(QItemSelection,QItemSelection))); } @@ -189,6 +195,21 @@ void ShemovCleaner::moveFiles(){ } } +void ShemovCleaner::torrentInfo(){ + QModelIndexList sel = mFileView->selectionModel()->selectedRows(1); + if(sel.isEmpty()){ + return; + } + QString fn = sel.first().data(Qt::UserRole + 1).toString(); + TorrentParser p(fn, this); + QList tData = p.parse(); + tData.removeAll(QVariant()); + tData.removeAll(0); + mTorrentDisplay->setData(tData); + mTorrentDisplay->show(); + return; +} + void ShemovCleaner::selectDir(){ QString dir = QFileDialog::getExistingDirectory(this, tr("Select directory"), QDir::homePath()); mDir->setText(QDir::toNativeSeparators(dir)); -- cgit v1.2.3-70-g09d2