#include "ui_mainwindow.h"
#include <QLabel>
-#include <QSqlTableModel>
+#include <QSqlError>
#include <QFileDialog>
+#include <QDesktopServices>
+#include <QUrl>
#include "mylist.h"
#include "database.h"
{
}
+
+void MainWindow::on_myListView_doubleClicked(const QModelIndex &index)
+{
+ MyListModel::NodeType type = animeModel->type(index);
+ int id = animeModel->id(index);
+
+ if (!id)
+ return;
+
+ QString path;
+ QSqlQuery q(MyList::instance()->database()->connection());
+
+ if (type == MyListModel::Anime)
+ {
+ q.prepare(
+ "SELECT fl.path, e.epno, a.title_romaji, e.title_english FROM file f "
+ " LEFT JOIN anime a ON f.aid = a.aid "
+ " LEFT JOIN episode e ON f.eid = e.eid "
+ " LEFT JOIN file_location fl ON fl.fid = f.fid "
+ " WHERE f.my_watched IS NULL "
+ " AND f.aid = :aid "
+ " AND fl.path IS NOT NULL "
+ " GROUP BY fl.path, a.title_romaji, e.epno, e.title_english "
+ " ORDER BY epno ASC ");
+ q.bindValue(":aid", id);
+ }
+ else if (type == MyListModel::Episode)
+ {
+ q.prepare(
+ "SELECT fl.path FROM file f "
+ " LEFT JOIN file_location fl ON fl.fid = f.fid "
+ " WHERE f.my_watched IS NULL "
+ " AND f.eid = :eid "
+ " AND fl.path IS NOT NULL "
+ " ORDER BY f.version DESC ");
+ q.bindValue(":eid", id);
+ }
+ else if (type == MyListModel::File)
+ {
+ q.prepare(
+ "SELECT fl.path FROM file f "
+ " LEFT JOIN file_location fl ON fl.fid = f.fid "
+ " WHERE f.my_watched IS NULL "
+ " AND f.fid = :fid "
+ " AND fl.path IS NOT NULL ");
+ q.bindValue(":fid", id);
+ }
+ else
+ {
+ return;
+ }
+
+ if (!q.exec())
+ {
+ qDebug() << q.lastError();
+ return;
+ }
+
+ if (!q.next())
+ {
+ ui->statusBar->showMessage(tr("No file found."));
+ return;
+ }
+
+ path = q.value(0).toString();
+
+ QDesktopServices::openUrl(QUrl("file:///" + path, QUrl::TolerantMode));
+ ui->statusBar->showMessage(tr("Openieng file: %1").arg(path));
+
+}
#define MAINWINDOW_H
#include <QMainWindow>
+#include <QModelIndex>
namespace Ui {
class MainWindow;
void on_actionClearAnimeTitleData_triggered();
void on_actionHandlePendingRequests_triggered();
+ void on_myListView_doubleClicked(const QModelIndex &index);
+
private:
Ui::MainWindow *ui;
</rect>
</property>
<property name="windowTitle">
- <string>MainWindow</string>
+ <string>LocalMyList Management</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
- <widget class="QTreeView" name="myListView"/>
+ <widget class="MyListView" name="myListView"/>
</item>
</layout>
</widget>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
+ <customwidgets>
+ <customwidget>
+ <class>MyListView</class>
+ <extends>QTreeView</extends>
+ <header>mylistview.h</header>
+ </customwidget>
+ </customwidgets>
<resources/>
<connections/>
</ui>
SOURCES += main.cpp\
mainwindow.cpp \
- databaseconnectiondialog.cpp
+ databaseconnectiondialog.cpp \
+ mylistview.cpp
HEADERS += mainwindow.h \
- databaseconnectiondialog.h
+ databaseconnectiondialog.h \
+ mylistview.h
FORMS += mainwindow.ui \
databaseconnectiondialog.ui
--- /dev/null
+#include "mylistview.h"
+
+#include "mylistmodel.h"
+
+#include <QMenu>
+
+MyListView::MyListView(QWidget *parent) :
+ QTreeView(parent)
+{
+ setContextMenuPolicy(Qt::CustomContextMenu);
+ connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showCustomContextMenu(QPoint)));
+}
+
+LocalMyList::MyListModel *MyListView::myListModel() const
+{
+ return qobject_cast<LocalMyList::MyListModel *>(model());
+}
+
+void MyListView::showCustomContextMenu(const QPoint &pos)
+{
+ using namespace LocalMyList;
+
+ const QModelIndex idx = indexAt(pos);
+ if (!idx.isValid())
+ return;
+
+ QAction a(tr("Dummyaction r=%1, c=%2").arg(idx.row()).arg(idx.column()), this);
+ MyListModel::NodeType t = myListModel()->type(idx);
+ QAction b(tr("%1 = %2").arg(t == MyListModel::Anime ? "aid" : t == MyListModel::Episode ? "eid" : t == MyListModel::File ? "fid" : "none").arg(myListModel()->id(idx)), this);
+
+ QList<QAction *> actions;
+ actions << &a << &b;
+ QMenu::exec(actions, viewport()->mapToGlobal(pos));
+}
--- /dev/null
+#ifndef MYLISTVIEW_H
+#define MYLISTVIEW_H
+
+#include <QTreeView>
+
+namespace LocalMyList {
+ class MyListModel;
+}
+
+class MyListView : public QTreeView
+{
+ Q_OBJECT
+public:
+ explicit MyListView(QWidget *parent = 0);
+
+private slots:
+ LocalMyList::MyListModel *myListModel() const;
+ void showCustomContextMenu(const QPoint &pos);
+
+};
+
+#endif // MYLISTVIEW_H