From: APTX Date: Sat, 23 Jan 2016 15:10:10 +0000 (+0100) Subject: Add Subtitle search tab. X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;h=8e79466e0002a925b43804262c1a61737dccb3b2;p=localmylist.git Add Subtitle search tab. --- diff --git a/localmylist-management/localmylist-management.pro b/localmylist-management/localmylist-management.pro index d620ff4..b015615 100644 --- a/localmylist-management/localmylist-management.pro +++ b/localmylist-management/localmylist-management.pro @@ -38,7 +38,8 @@ SOURCES += main.cpp\ codeeditor.cpp \ dynamicmodelfiltermodel.cpp \ dynamicmodelview.cpp \ - dynamicmodelitemdelegate.cpp + dynamicmodelitemdelegate.cpp \ + tabs/subtitlesearchtab.cpp HEADERS += mainwindow.h \ databaseconnectiondialog.h \ @@ -67,7 +68,8 @@ HEADERS += mainwindow.h \ codeeditor.h \ dynamicmodelfiltermodel.h \ dynamicmodelview.h \ - dynamicmodelitemdelegate.h + dynamicmodelitemdelegate.h \ + tabs/subtitlesearchtab.h FORMS += mainwindow.ui \ databaseconnectiondialog.ui \ @@ -82,7 +84,8 @@ FORMS += mainwindow.ui \ tabs/dynamicmodeltab.ui \ tabs/pathmappingtab.ui \ tabs/hosttab.ui \ - tabs/watcheddirectoriestab.ui + tabs/watcheddirectoriestab.ui \ + tabs/subtitlesearchtab.ui RESOURCES += resources.qrc diff --git a/localmylist-management/registertabs.cpp b/localmylist-management/registertabs.cpp index 2115be5..2340d47 100644 --- a/localmylist-management/registertabs.cpp +++ b/localmylist-management/registertabs.cpp @@ -10,6 +10,7 @@ #include "tabs/pathmappingtab.h" #include "tabs/watcheddirectoriestab.h" #include "tabs/hosttab.h" +#include "tabs/subtitlesearchtab.h" void registerTabs() { @@ -24,4 +25,5 @@ void registerTabs() TabWidget::registerTab(); TabWidget::registerTab(); TabWidget::registerTab(); + TabWidget::registerTab(); } diff --git a/localmylist-management/tabs/subtitlesearchtab.cpp b/localmylist-management/tabs/subtitlesearchtab.cpp new file mode 100644 index 0000000..3f0c43a --- /dev/null +++ b/localmylist-management/tabs/subtitlesearchtab.cpp @@ -0,0 +1,111 @@ +/* + * 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 + +#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); +} diff --git a/localmylist-management/tabs/subtitlesearchtab.h b/localmylist-management/tabs/subtitlesearchtab.h new file mode 100644 index 0000000..74c8c47 --- /dev/null +++ b/localmylist-management/tabs/subtitlesearchtab.h @@ -0,0 +1,65 @@ +/* + * 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 +{ + 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 diff --git a/localmylist-management/tabs/subtitlesearchtab.ui b/localmylist-management/tabs/subtitlesearchtab.ui new file mode 100644 index 0000000..e159f1e --- /dev/null +++ b/localmylist-management/tabs/subtitlesearchtab.ui @@ -0,0 +1,50 @@ + + + SubtitleSearchTab + + + + 0 + 0 + 400 + 300 + + + + Form + + + + 0 + + + 0 + + + 0 + + + + + + + + Type to search for subtitles (Search starts after 3 non-special characters) + + + + + + + + + + + FilterLineEdit + QLineEdit +
filterlineedit.h
+
+
+ + +
diff --git a/localmylist/localmylist_resources.qrc b/localmylist/localmylist_resources.qrc new file mode 100644 index 0000000..3cf3436 --- /dev/null +++ b/localmylist/localmylist_resources.qrc @@ -0,0 +1,5 @@ + + + share/schema/schema.sql + +