--- /dev/null
+/*
+ * Copyright (c) 20015 APTX
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "subtitlesearchtab.h"
+#include "ui_subtitlesearchtab.h"
+
+#include <QSqlQueryModel>
+
+#include "database.h"
+#include "mylist.h"
+
+using namespace LocalMyList;
+
+SubtitleSearchTab::SubtitleSearchTab(QWidget *parent) :
+ AbstractTabBase(parent),
+ ui(new Ui::SubtitleSearchTab)
+{
+ ui->setupUi(this);
+ m_label = name();
+}
+
+SubtitleSearchTab::~SubtitleSearchTab()
+{
+ delete ui;
+}
+
+QString SubtitleSearchTab::staticId()
+{
+ return "subtitle_search";
+}
+
+QString SubtitleSearchTab::name()
+{
+ return tr("Subtitle Search");
+}
+
+void SubtitleSearchTab::init()
+{
+ model = new QSqlQueryModel(this);
+ ui->view->setModel(model);
+}
+
+void SubtitleSearchTab::on_input_returnPressed()
+{
+ QString query;
+ QString text = ui->input->text();
+
+ if (text.isEmpty())
+ {
+ model->setQuery(QSqlQuery());
+ return;
+ }
+
+ query = toSearchQuery(text);
+
+ QSqlQuery &q = MyList::instance()->database()->prepare(R"(
+ SELECT f.fid, a.title_romaji, e.type::text || e.epno::text AS epno, s.start_time, s.name, s.line FROM subtitle.subtitle s
+ JOIN file f ON f.fid = s.fid
+ JOIN episode e ON e.eid = f.eid
+ JOIN anime a ON a.aid = f.aid
+ WHERE s.line ILIKE :query
+ LIMIT :limit
+ )");
+ q.bindValue(":query", query);
+ q.bindValue(":limit", 100);
+ MyList::instance()->database()->exec(q);
+ model->setQuery(q);
+
+ model->setHeaderData(0, Qt::Horizontal, tr("fid"));
+ model->setHeaderData(1, Qt::Horizontal, tr("Anime Title"));
+ model->setHeaderData(2, Qt::Horizontal, tr("Episode"));
+ model->setHeaderData(3, Qt::Horizontal, tr("Time"));
+ model->setHeaderData(4, Qt::Horizontal, tr("Character"));
+ model->setHeaderData(5, Qt::Horizontal, tr("Line"));
+
+ ui->view->setColumnHidden(0, true);
+
+ ui->view->resizeColumnsToContents();
+}
+
+void SubtitleSearchTab::on_view_clicked(const QModelIndex &index)
+{
+ int fid = model->data(model->index(index.row(), 0)).toInt();
+ OpenFileData ofd = MyList::instance()->database()->openFile(fid);
+ MyList::instance()->playFile(ofd);
+}
--- /dev/null
+/*
+ * Copyright (c) 20015 APTX
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef SUBTITLESEARCHTAB_H
+#define SUBTITLESEARCHTAB_H
+
+#include "../abstracttab.h"
+
+namespace Ui {
+class SubtitleSearchTab;
+}
+
+class QSqlQueryModel;
+
+class SubtitleSearchTab : public AbstractTabBase<SubtitleSearchTab>
+{
+ Q_OBJECT
+
+public:
+ explicit SubtitleSearchTab(QWidget *parent = 0);
+ ~SubtitleSearchTab();
+
+ static QString staticId();
+ static QString name();
+
+ void init() override;
+
+
+private slots:
+ void on_input_returnPressed();
+
+ void on_view_clicked(const QModelIndex &index);
+
+private:
+ Ui::SubtitleSearchTab *ui;
+
+ QSqlQueryModel *model;
+};
+
+#endif // SUBTITLESEARCHTAB_H
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>SubtitleSearchTab</class>
+ <widget class="QWidget" name="SubtitleSearchTab">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="FilterLineEdit" name="input">
+ <property name="text">
+ <string/>
+ </property>
+ <property name="placeholderText">
+ <string>Type to search for subtitles (Search starts after 3 non-special characters)</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QTableView" name="view"/>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>FilterLineEdit</class>
+ <extends>QLineEdit</extends>
+ <header>filterlineedit.h</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>