summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2016-08-20 08:31:29 +0200
committerArno <arno@disconnect.de>2016-08-20 08:31:29 +0200
commitd47427a2d51fcc7f8e1f8926a706e04ff01603ed (patch)
tree22002ee669fbce025aad1782f75733843e3581be
parent8ab990b7c6fb5348b09f451878a80e2c70695876 (diff)
downloadShemovCleaner-d47427a2d51fcc7f8e1f8926a706e04ff01603ed.tar.gz
ShemovCleaner-d47427a2d51fcc7f8e1f8926a706e04ff01603ed.tar.bz2
ShemovCleaner-d47427a2d51fcc7f8e1f8926a706e04ff01603ed.zip
Present torrent files as a tree
A torrent info dictionary has two modes: single and multi files. When in multi-mode, the name-entry is the directory containing the files. Represent it as a tree. During testing I discovered a fatal bug in the torrent parser: If we encounter an invalid string, we have to move mPos forward, else we will loop indefinitely until we're OOM. I also added some icons for folders, files and trackers.
-rw-r--r--butt_plug.pngbin0 -> 993 bytes
-rw-r--r--delete.pngbin0 -> 1333 bytes
-rw-r--r--diaper.pngbin0 -> 1022 bytes
-rw-r--r--folder.pngbin0 -> 1412 bytes
-rw-r--r--shemovcleaner.cpp2
-rw-r--r--shemovcleaner.qrc4
-rw-r--r--torrentdisplay.cpp66
-rw-r--r--torrentdisplay.h7
-rw-r--r--torrentparser.cpp7
-rw-r--r--torrentparser.h2
10 files changed, 60 insertions, 28 deletions
diff --git a/butt_plug.png b/butt_plug.png
new file mode 100644
index 0000000..e00d958
--- /dev/null
+++ b/butt_plug.png
Binary files differ
diff --git a/delete.png b/delete.png
new file mode 100644
index 0000000..351659b
--- /dev/null
+++ b/delete.png
Binary files differ
diff --git a/diaper.png b/diaper.png
new file mode 100644
index 0000000..ecddcd6
--- /dev/null
+++ b/diaper.png
Binary files differ
diff --git a/folder.png b/folder.png
new file mode 100644
index 0000000..53954fa
--- /dev/null
+++ b/folder.png
Binary files differ
diff --git a/shemovcleaner.cpp b/shemovcleaner.cpp
index beb5baf..c50e598 100644
--- a/shemovcleaner.cpp
+++ b/shemovcleaner.cpp
@@ -205,7 +205,7 @@ void ShemovCleaner::torrentInfo(){
QList<QVariant> tData = p.parse();
tData.removeAll(QVariant());
tData.removeAll(0);
- mTorrentDisplay->setData(tData);
+ mTorrentDisplay->setData(tData, sel.first().data().toString());
mTorrentDisplay->show();
return;
}
diff --git a/shemovcleaner.qrc b/shemovcleaner.qrc
index ee75d03..dc6aa2f 100644
--- a/shemovcleaner.qrc
+++ b/shemovcleaner.qrc
@@ -3,5 +3,9 @@
<file>clean_tampon.png</file>
<file>gaping_ass.png</file>
<file>huge_bra.png</file>
+ <file>butt_plug.png</file>
+ <file>delete.png</file>
+ <file>diaper.png</file>
+ <file>folder.png</file>
</qresource>
</RCC>
diff --git a/torrentdisplay.cpp b/torrentdisplay.cpp
index e56343c..11b98b5 100644
--- a/torrentdisplay.cpp
+++ b/torrentdisplay.cpp
@@ -79,7 +79,9 @@ TorrentDisplay::TorrentDisplay(QWidget *parent, Qt::WindowFlags f) : QDialog(par
setWindowTitle(tr("Torrent Info"));
}
-void TorrentDisplay::setData(const QList<QVariant> data) {
+#include <QDebug>
+
+void TorrentDisplay::setData(const QList<QVariant> data, const QString &filename) {
if(data.isEmpty()){
return;
}
@@ -97,26 +99,12 @@ void TorrentDisplay::setData(const QList<QVariant> data) {
QVariantHash infoD = it.value().toHash();
int piece_length = infoD.value("piece length").toInt();
mPieceLength->setText(QString::number(piece_length));
- if(infoD.contains("name")){
- QString fn = infoD.value("name").toString();
- qint64 length = infoD.value("length").toLongLong();
- QStandardItem *i1 = new QStandardItem(fn);
- QStandardItem *i2 = new QStandardItem(QString::number(length));
- i2->setData(length);
- mFileModel->invisibleRootItem()->appendRow(QList<QStandardItem*>() << i1 << i2);
- }
if(infoD.contains("files")){
- QVariantList fList = infoD.value("files").toList();
- foreach(QVariant fn, fList){
- QVariantHash curH = fn.toHash();
- QVariantList path = curH.value("path").toList();
- QStandardItem *i1 = new QStandardItem(path.last().toString());
- qint64 length = curH.value("length").toLongLong();
- QStandardItem *i2 = new QStandardItem(QString::number(length));
- i2->setData(length);
- mFileModel->invisibleRootItem()->appendRow(QList<QStandardItem*>() << i1 << i2);
- }
+ setMulti(infoD, filename);
+ }else{
+ setSingle(infoD, filename);
}
+ mFileView->expandAll();
mFileView->resizeColumnToContents(0);
mFileView->resizeColumnToContents(1);
}
@@ -138,6 +126,7 @@ void TorrentDisplay::setData(const QList<QVariant> data) {
QVariantList l3 = l2.toList();
foreach(QVariant ann, l3){
QStandardItem *i1 = new QStandardItem(ann.toString());
+ i1->setIcon(QIcon(":/butt_plug.png"));
mAnnounceModel->invisibleRootItem()->appendRow(QList<QStandardItem*>() << i1);
}
}
@@ -147,3 +136,42 @@ void TorrentDisplay::setData(const QList<QVariant> data) {
}
}
}
+
+void TorrentDisplay::setMulti(const QVariantHash &data, const QString &filename){
+ QStandardItem *root = mFileModel->invisibleRootItem();
+ QStandardItem *torrentItem = new QStandardItem(filename);
+ torrentItem->setIcon(QIcon(":/huge_bra.png"));
+ root->appendRow(QList<QStandardItem*>() << torrentItem << new QStandardItem());
+ QString folderName = data.value("name").toString();
+ if(folderName.isEmpty()){
+ folderName = "<no folder>";
+ }
+ QStandardItem *folderItem = new QStandardItem(folderName);
+ folderItem->setIcon(QIcon(":/gaping_ass.png"));
+ torrentItem->appendRow(QList<QStandardItem*>() << folderItem << new QStandardItem);
+ QVariantList fileList = data.value("files").toList();
+ foreach(QVariant entry, fileList){
+ QVariantHash e = entry.toHash();
+ QVariantList path = e.value("path").toList();
+ QStandardItem *i1 = new QStandardItem(path.last().toString());
+ i1->setIcon(QIcon(":/huge_bra.png"));
+ qint64 len = e.value("length").toLongLong();
+ QStandardItem *i2 = new QStandardItem(QString::number(len));
+ i2->setData(len);
+ folderItem->appendRow(QList<QStandardItem*>() << i1 << i2);
+ }
+}
+
+void TorrentDisplay::setSingle(const QVariantHash &data, const QString &filename){
+ QStandardItem *root = mFileModel->invisibleRootItem();
+ QStandardItem *torrentItem = new QStandardItem(filename);
+ torrentItem->setIcon(QIcon(":/huge_bra.png"));
+ root->appendRow(QList<QStandardItem*>() << torrentItem << new QStandardItem);
+ QString fn = data.value("name").toString();
+ QStandardItem *i1 = new QStandardItem(fn);
+ i1->setIcon(QIcon(":/huge_bra.png"));
+ qint64 len = data.value("length").toLongLong();
+ QStandardItem *i2 = new QStandardItem(QString::number(len));
+ i2->setData(len);
+ torrentItem->appendRow(QList<QStandardItem*>() << i1 << i2);
+}
diff --git a/torrentdisplay.h b/torrentdisplay.h
index 6305335..4aa01bf 100644
--- a/torrentdisplay.h
+++ b/torrentdisplay.h
@@ -2,6 +2,7 @@
#define TORRENTDISPLAY_H
#include <QDialog>
+#include <QVariant>
class QLineEdit;
class QStandardItemModel;
@@ -11,7 +12,11 @@ class TorrentDisplay : public QDialog {
Q_OBJECT
public:
explicit TorrentDisplay(QWidget *parent = 0, Qt::WindowFlags f = 0);
- void setData(const QList<QVariant> data);
+ void setData(const QList<QVariant> data, const QString &filename);
+
+ private slots:
+ void setMulti(const QVariantHash &data, const QString &filename);
+ void setSingle(const QVariantHash &data, const QString &filename);
private:
QLineEdit *mCreated;
diff --git a/torrentparser.cpp b/torrentparser.cpp
index fc59233..8e09681 100644
--- a/torrentparser.cpp
+++ b/torrentparser.cpp
@@ -2,7 +2,7 @@
#include "torrentparser.h"
-TorrentParser::TorrentParser(const QString file, QObject *parent) : QObject(parent), mFile(file), mPos(0), mOk(true) {}
+TorrentParser::TorrentParser(const QString file, QObject *parent) : QObject(parent), mFile(file), mPos(0) {}
const QList<QVariant> TorrentParser::parse(){
QFile f(mFile);
@@ -41,12 +41,11 @@ const QVariant TorrentParser::parseObject(){
const QByteArray TorrentParser::parseString(){
int lenlen = mData.indexOf(':', mPos) - mPos;
if(lenlen <= 0){
- mOk = false;
+ ++mPos;
return QByteArray();
}
int len = mData.mid(mPos, lenlen).toInt();
if(mPos + len > mData.size()){
- mOk = false;
return QByteArray();
}
mPos = mPos + lenlen + 1;
@@ -82,8 +81,6 @@ const QList<QVariant> TorrentParser::parseList(){
return retval;
}
-
-
const QHash<QString,QVariant> TorrentParser::parseDict(){
QHash<QString,QVariant> retval;
if(mData.at(mPos) != 'd'){
diff --git a/torrentparser.h b/torrentparser.h
index 02129fb..e1f8ef7 100644
--- a/torrentparser.h
+++ b/torrentparser.h
@@ -13,7 +13,6 @@ class TorrentParser : public QObject {
public:
TorrentParser(const QString file, QObject *parent = 0);
const QList<QVariant> parse();
- const QString lastError() const { return mLastError; }
private:
const QVariant parseObject();
@@ -25,7 +24,6 @@ class TorrentParser : public QObject {
QString mLastError;
QByteArray mData;
int mPos;
- bool mOk;
};
#endif // TORRENTPARSER_H