From fe066f144c54c67207e0edfd5303d0b68288e066 Mon Sep 17 00:00:00 2001 From: daniel-Jones Date: Fri, 19 Jan 2018 17:28:36 +1030 Subject: initial project in working state --- horriblesubs-rss.pro | 34 ++++++++++++++ main.cpp | 11 +++++ mainwindow.cpp | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++ mainwindow.h | 39 ++++++++++++++++ mainwindow.ui | 111 +++++++++++++++++++++++++++++++++++++++++++++ uiexample.png | Bin 0 -> 135895 bytes 6 files changed, 320 insertions(+) create mode 100644 horriblesubs-rss.pro create mode 100644 main.cpp create mode 100644 mainwindow.cpp create mode 100644 mainwindow.h create mode 100644 mainwindow.ui create mode 100644 uiexample.png diff --git a/horriblesubs-rss.pro b/horriblesubs-rss.pro new file mode 100644 index 0000000..628e64f --- /dev/null +++ b/horriblesubs-rss.pro @@ -0,0 +1,34 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2018-01-19T08:12:43 +# +#------------------------------------------------- + +QT += core gui network xml + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = horriblesubs-rss +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + + +SOURCES += \ + main.cpp \ + mainwindow.cpp + +HEADERS += \ + mainwindow.h + +FORMS += \ + mainwindow.ui diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..b48f94e --- /dev/null +++ b/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..15e22f3 --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,125 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + //ui->table_view->horizontalHeader()-> + //setSectionResizeMode(QHeaderView::Stretch); // enable column resizing + QPalette palette; // palette for table + palette.setColor(QPalette::Highlight, + ui->table_view-> + palette().color(QPalette::Base)); + palette.setColor(QPalette::HighlightedText, + ui->table_view->palette().color( + QPalette::Text)); + ui->table_view->setPalette(palette); // set table color palette + QString rssfile = "rss.txt"; // rss file to read and store to + if (getfile("http://horriblesubs.info/rss.php?res=720" + ,rssfile)) // download rss file + ui->status_bar->showMessage( + "RSS feed downloaded"); // download complete + else + ui->status_bar-> + showMessage("Cannot download RSS feed");// download fail + parserss(rssfile); // fail or complete, try and parse file +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +bool MainWindow::getfile(QString url, QString dest) +{ + bool success; // return bool + if (QFile::exists(dest)) + QFile::remove(dest); // remove rss file if already exists + QNetworkReply *reply = http.get(QNetworkRequest( + url)); // network reply + QObject::connect(reply, SIGNAL(finished()), + &loop, SLOT(quit())); // connect finish signal to quit + loop.exec(); // exec loop + QFile file(dest); + file.open(QIODevice::WriteOnly); // open file for writing + file.write(reply->readAll()); // write reply data to file + delete reply; // delete replt object + if (QFile::exists(dest) && file.size() > 0) // this is a terrible way to do this + success = true; // file downloaded successfully + else + success = false; // download failed + return success; +} + +bool MainWindow::parserss(QString rssfile) +{ + QDomDocument doc; // xml parser + QFile file(rssfile); // rss file + if (!file.open(QIODevice::ReadOnly) || + !doc.setContent(&file)) + return false; // file not opened + QDomNodeList title = + doc.elementsByTagName("item"); // item tag + qDebug() << title.size(); + for (int i = 0; i < title.size(); i++) // iterate over every item + { + QDomNode n = title.item(i); // current title + QDomElement title = + n.firstChildElement("title"); // get title + QDomElement link = + n.firstChildElement("link"); // get link to current item + QDomElement date = + n.firstChildElement("pubDate"); // get pub date + addtolist(title.text(), + date.text(), link.text()); // add current item to list + } + return true; +} + +void MainWindow::addtolist(QString title, QString date, QString link) +{ + int i = ui->table_view->rowCount(); // get row count + ui->table_view->insertRow(i); // insert new row for item + ui->table_view->setItem + (i, 1, new QTableWidgetItem("title")); // add title item + ui->table_view->setItem + (i, 2, new QTableWidgetItem("date")); // add date item + ui->table_view->setItem + (i, 3, new QTableWidgetItem("link")); // add link item + ui->table_view->setItem + (i, 0, new QTableWidgetItem("grab")); // add grab item + + ui->table_view->item(i,1)->setText(title); // add title text + ui->table_view->item(i,2)->setText(date); // add date test + ui->table_view->item(i,3)->setText(link); // add link text + QTableWidgetItem *checkbox = + new QTableWidgetItem(); // create checkbox item + checkbox->setCheckState(Qt::Unchecked); // set checkbox state + ui->table_view->setItem(i, 0, checkbox); // place checkbox inside row +} + +void MainWindow::on_get_button_clicked() +{ + int x = ui->table_view->rowCount(); // get row count + for (int i = 0; i < x; i++) // iterate over each item in the table + { + if (ui->table_view->item(i, 0)-> // check if checkbox.. checked + checkState() == 2) // checked is Qt::CheckState(Checked) (2) + { + openclient( + ui->table_view->item(i, 3) + ->text()); // call open client with the magnet url + } + } +} + +void MainWindow::openclient(QString magnet) +{ + QProcess *process = new QProcess(); // create process + QString program = "/usr/bin/transmission-qt"; // this is built for transmission + QStringList arg; // argument list + arg.append(magnet); // append magnet to arg + process->start(program, arg); // start process +} diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..5392033 --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,39 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Ui { + class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + + public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +private slots: + void on_get_button_clicked(); + +private: + Ui::MainWindow *ui; + bool getfile(QString url, QString dest); + QNetworkAccessManager http; + QEventLoop loop; + bool parserss(QString rssfile); + void addtolist(QString title, QString date, QString link); + void openclient(QString magnet); + +}; + +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000..3c3ea11 --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,111 @@ + + + MainWindow + + + + 0 + 0 + 400 + 300 + + + + HorribleSubs RSS + + + + + + + + + get + + + + + + + + + true + + + false + + + false + + + false + + + + grab + + + + + title + + + + + date + + + + + link + + + + + + + + + + 0 + 0 + 400 + 20 + + + + + &menu + + + + + + + + + &exit + + + + + + + + menuBar + triggered(QAction*) + MainWindow + close() + + + 33 + 6 + + + 95 + 64 + + + + + diff --git a/uiexample.png b/uiexample.png new file mode 100644 index 0000000..202eea3 Binary files /dev/null and b/uiexample.png differ -- cgit v1.2.3