summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--horriblesubs-rss.pro34
-rw-r--r--main.cpp11
-rw-r--r--mainwindow.cpp125
-rw-r--r--mainwindow.h39
-rw-r--r--mainwindow.ui111
-rw-r--r--uiexample.pngbin0 -> 135895 bytes
6 files changed, 320 insertions, 0 deletions
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 <QApplication>
+
+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 <QMainWindow>
+#include <QEventLoop>
+#include <QNetworkAccessManager>
+#include <QNetworkReply>
+#include <QFile>
+#include <QDomDocument>
+#include <QCheckBox>
+#include <QProcess>
+
+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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>HorribleSubs RSS</string>
+ </property>
+ <widget class="QWidget" name="main_widget">
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="1" column="0">
+ <layout class="QFormLayout" name="button_form">
+ <item row="0" column="0">
+ <widget class="QPushButton" name="get_button">
+ <property name="text">
+ <string>get</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="0" column="0">
+ <widget class="QTableWidget" name="table_view">
+ <property name="showGrid">
+ <bool>true</bool>
+ </property>
+ <attribute name="horizontalHeaderHighlightSections">
+ <bool>false</bool>
+ </attribute>
+ <attribute name="verticalHeaderVisible">
+ <bool>false</bool>
+ </attribute>
+ <attribute name="verticalHeaderHighlightSections">
+ <bool>false</bool>
+ </attribute>
+ <column>
+ <property name="text">
+ <string>grab</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>title</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>date</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>link</string>
+ </property>
+ </column>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menuBar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>20</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menumenu">
+ <property name="title">
+ <string>&amp;menu</string>
+ </property>
+ <addaction name="actionexit"/>
+ </widget>
+ <addaction name="menumenu"/>
+ </widget>
+ <widget class="QStatusBar" name="status_bar"/>
+ <action name="actionexit">
+ <property name="text">
+ <string>&amp;exit</string>
+ </property>
+ </action>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>menuBar</sender>
+ <signal>triggered(QAction*)</signal>
+ <receiver>MainWindow</receiver>
+ <slot>close()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>33</x>
+ <y>6</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>95</x>
+ <y>64</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/uiexample.png b/uiexample.png
new file mode 100644
index 0000000..202eea3
--- /dev/null
+++ b/uiexample.png
Binary files differ