]> Some of my projects - localmylist.git/commitdiff
Add Subtitle search tab.
authorAPTX <marek321@gmail.com>
Sat, 23 Jan 2016 15:10:10 +0000 (16:10 +0100)
committerAPTX <marek321@gmail.com>
Sat, 23 Jan 2016 15:10:10 +0000 (16:10 +0100)
localmylist-management/localmylist-management.pro
localmylist-management/registertabs.cpp
localmylist-management/tabs/subtitlesearchtab.cpp [new file with mode: 0644]
localmylist-management/tabs/subtitlesearchtab.h [new file with mode: 0644]
localmylist-management/tabs/subtitlesearchtab.ui [new file with mode: 0644]
localmylist/localmylist_resources.qrc [new file with mode: 0644]

index d620ff446187a7084993acb32e3faf655220f250..b0156159e0f222ee67b47ed15e2a6da9ec0666c8 100644 (file)
@@ -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
 
index 2115be5e357fddc85503ca52b478e80bce41d983..2340d474be28a55c278f0a36f53ede25b1a21443 100644 (file)
@@ -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<WatchedDirectoriesTab>();
        TabWidget::registerTab<HostTab>();
        TabWidget::registerTab<MyListTab>();
+       TabWidget::registerTab<SubtitleSearchTab>();
 }
diff --git a/localmylist-management/tabs/subtitlesearchtab.cpp b/localmylist-management/tabs/subtitlesearchtab.cpp
new file mode 100644 (file)
index 0000000..3f0c43a
--- /dev/null
@@ -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 <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);
+}
diff --git a/localmylist-management/tabs/subtitlesearchtab.h b/localmylist-management/tabs/subtitlesearchtab.h
new file mode 100644 (file)
index 0000000..74c8c47
--- /dev/null
@@ -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<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
diff --git a/localmylist-management/tabs/subtitlesearchtab.ui b/localmylist-management/tabs/subtitlesearchtab.ui
new file mode 100644 (file)
index 0000000..e159f1e
--- /dev/null
@@ -0,0 +1,50 @@
+<?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>
diff --git a/localmylist/localmylist_resources.qrc b/localmylist/localmylist_resources.qrc
new file mode 100644 (file)
index 0000000..3cf3436
--- /dev/null
@@ -0,0 +1,5 @@
+<RCC>
+    <qresource prefix="/localmylist">
+        <file alias="schema.sql">share/schema/schema.sql</file>
+    </qresource>
+</RCC>