From 823b19c69da9706806e77ddb0f6467650e97452e Mon Sep 17 00:00:00 2001 From: APTX Date: Tue, 3 Jul 2012 02:53:02 +0200 Subject: [PATCH] Add option to rename files to context menu. --- management-gui/mainwindow.cpp | 59 +++++++++++++++++++++++++++++++++-- management-gui/mainwindow.h | 1 + management-gui/mylistview.cpp | 16 ++++++++-- management-gui/mylistview.h | 3 ++ 4 files changed, 73 insertions(+), 6 deletions(-) diff --git a/management-gui/mainwindow.cpp b/management-gui/mainwindow.cpp index 83ea3f8..acb0528 100644 --- a/management-gui/mainwindow.cpp +++ b/management-gui/mainwindow.cpp @@ -42,9 +42,7 @@ MainWindow::MainWindow(QWidget *parent) : MyList::instance()->database()->connect(); myListModel = new MyListModel(this); - myListFilterModel = new QSortFilterProxyModel(); - myListFilterModel->setSourceModel(myListModel); - ui->myListView->setModel(myListModel); + ui->myListView->setMyListModel(myListModel); ui->myListView->header()->setResizeMode(0, QHeaderView::Stretch); ui->myListView->header()->setStretchLastSection(false); @@ -211,6 +209,61 @@ void MainWindow::on_myListView_openFileRequested(const QModelIndex &index) } +void MainWindow::on_myListView_renameFilesRequested(const QModelIndex &index) +{ + MyListModel::NodeType type = myListModel->type(index); + int id = myListModel->id(index); + + if (!id) + return; + + QString path; + QSqlQuery q(MyList::instance()->database()->connection()); + + QChar typeLetter; + if (type == MyListModel::Anime) + { + q.prepare( + "UPDATE file_location fl SET renamed = NULL, failed_rename = false " + " FROM file f " + " WHERE f.fid = fl.fid AND f.aid = :aid"); + q.bindValue(":aid", id); + + typeLetter = 'a'; + } + else if (type == MyListModel::Episode) + { + q.prepare( + "UPDATE file_location fl SET renamed = NULL, failed_rename = false " + " FROM file f " + " WHERE f.fid = fl.fid AND f.eid = :eid"); + q.bindValue(":eid", id); + + typeLetter = 'e'; + } + else if (type == MyListModel::File) + { + q.prepare( + "UPDATE file_location fl SET renamed = NULL, failed_rename = false " + " WHERE fl.fid = :fid"); + q.bindValue(":fid", id); + + typeLetter = 'f'; + } + else + { + return; + } + + if (!q.exec()) + { + qDebug() << q.lastError(); + return; + } + + ui->statusBar->showMessage(tr("Files for %1%2 scheduled for rename").arg(typeLetter).arg(id)); +} + void MainWindow::on_actionStartUDPCLient_triggered() { MyList::instance()->setupUdpClient(); diff --git a/management-gui/mainwindow.h b/management-gui/mainwindow.h index b83b375..65db390 100644 --- a/management-gui/mainwindow.h +++ b/management-gui/mainwindow.h @@ -45,6 +45,7 @@ private slots: void on_actionClearMyListData_triggered(); void on_actionClearAnimeTitleData_triggered(); void on_myListView_openFileRequested(const QModelIndex &index); + void on_myListView_renameFilesRequested(const QModelIndex &index); void on_actionStartUDPCLient_triggered(); void on_actionRenameFiles_triggered(); void on_actionStartRenameHandler_triggered(); diff --git a/management-gui/mylistview.cpp b/management-gui/mylistview.cpp index 5c647b6..059541d 100644 --- a/management-gui/mylistview.cpp +++ b/management-gui/mylistview.cpp @@ -22,6 +22,8 @@ MyListView::MyListView(QWidget *parent) : connect(markWatchedAction, SIGNAL(triggered()), this, SLOT(markWatched())); aniDBLinkAction = new QAction(tr("Open AniDB Page"), this); connect(aniDBLinkAction, SIGNAL(triggered()), this, SLOT(openAnidbPage())); + renameFilesAction = new QAction(tr("Rename Files Related to Entry"), this); + connect(renameFilesAction, SIGNAL(triggered()), this, SLOT(requestFileRename())); renameTestAction = new QAction(tr("Use For Rename Testing"), this); connect(renameTestAction, SIGNAL(triggered()), this, SLOT(renameTest())); } @@ -49,19 +51,22 @@ void MyListView::showCustomContextMenu(const QPoint &pos) case MyListModel::Anime: aniDBLinkAction->setText(tr("Open AniDB Page (%1%2)").arg('a').arg(id)); actions << aniDBLinkAction - << openNextAction; + << openNextAction + << renameFilesAction; break; case MyListModel::Episode: aniDBLinkAction->setText(tr("Open AniDB Page (%1%2)").arg('e').arg(id)); actions << aniDBLinkAction - << openAction; + << openAction + << renameFilesAction; break; case MyListModel::File: aniDBLinkAction->setText(tr("Open AniDB Page (%1%2)").arg('f').arg(id)); actions << aniDBLinkAction << openAction << markWatchedAction - << renameTestAction; + << renameTestAction + << renameFilesAction; break; } @@ -107,6 +112,11 @@ void MyListView::openAnidbPage() } } +void MyListView::requestFileRename() +{ + emit renameFilesRequested(customContextMenuIndex); +} + void MyListView::renameTest() { int id = myListModel()->id(customContextMenuIndex); diff --git a/management-gui/mylistview.h b/management-gui/mylistview.h index dd85f92..3737979 100644 --- a/management-gui/mylistview.h +++ b/management-gui/mylistview.h @@ -16,6 +16,7 @@ public: signals: void openFileRequested(const QModelIndex &index); + void renameFilesRequested(const QModelIndex &index); void renameTest(int fid); private slots: @@ -24,6 +25,7 @@ private slots: void requestOpenFile(); void markWatched(); void openAnidbPage(); + void requestFileRename(); void renameTest(); private: @@ -35,6 +37,7 @@ private: QAction *markWatchedAction; QAction *aniDBLinkAction; QAction *renameTestAction; + QAction *renameFilesAction; }; #endif // MYLISTVIEW_H -- 2.52.0