summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--editfiledialog.cpp124
-rw-r--r--editfiledialog.h38
-rw-r--r--moviewidget.cpp16
-rw-r--r--moviewidget.h3
-rw-r--r--shemov.pro6
5 files changed, 184 insertions, 3 deletions
diff --git a/editfiledialog.cpp b/editfiledialog.cpp
new file mode 100644
index 0000000..15d4836
--- /dev/null
+++ b/editfiledialog.cpp
@@ -0,0 +1,124 @@
+/*
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version
+ 2 of the License, or (at your option) any later version.
+*/
+
+#include <QLineEdit>
+#include <QComboBox>
+#include <QFormLayout>
+#include <QGroupBox>
+#include <QIntValidator>
+#include <QHBoxLayout>
+#include <QGridLayout>
+#include <QPushButton>
+#include <QVBoxLayout>
+#include <QSqlDatabase>
+#include <QSqlQuery>
+
+#include "editfiledialog.h"
+#include "smglobals.h"
+#include "helper.h"
+
+EditFileDialog::EditFileDialog(QWidget *parent) : QDialog(parent){
+ mFiletypeMap = SmGlobals::instance()->filetypeMap();
+ setupGui();
+ setWindowTitle(tr("Edit file..."));
+}
+
+void EditFileDialog::setupGui(){
+ mFileName = new QLineEdit;
+ mFileName->setReadOnly(true);
+ mMd5Sum = new QLineEdit;
+ mMd5Sum->setReadOnly(true);
+ mMd5Sum->setFont(QFont("courier"));
+ QFormLayout *lineEditL = new QFormLayout;
+ lineEditL->addRow(tr("Filename"), mFileName);
+ lineEditL->addRow(tr("MD5"), mMd5Sum);
+ QGroupBox *dvdNoGB = new QGroupBox(tr("DVD No."));
+ mDvdNo= new QLineEdit;
+ QIntValidator *validator = new QIntValidator;
+ mDvdNo->setValidator(validator);
+ QHBoxLayout *dvdNoGBL = new QHBoxLayout;
+ dvdNoGBL->addWidget(mDvdNo);
+ dvdNoGB->setLayout(dvdNoGBL);
+ QGroupBox *qualityGB = new QGroupBox(tr("Quality"));
+ mQuality = new QLineEdit;
+ mQuality->setValidator(validator);
+ QHBoxLayout *qualityGBL = new QHBoxLayout;
+ qualityGBL->addWidget(mQuality);
+ qualityGB->setLayout(qualityGBL);
+ QGroupBox *durationGB = new QGroupBox(tr("Duration"));
+ mDuration = new QLineEdit;
+ QHBoxLayout *durationGBL = new QHBoxLayout;
+ durationGBL->addWidget(mDuration);
+ durationGB->setLayout(durationGBL);
+ QGroupBox *fileTypeGB = new QGroupBox(tr("Filetype"));
+ mFileType = new QComboBox;
+ QStringList fileTypes = mFiletypeMap.values();
+ std::sort(fileTypes.begin(), fileTypes.end());
+ mFileType->addItems(fileTypes);
+ QHBoxLayout *fileTypeGBL = new QHBoxLayout;
+ fileTypeGBL->addWidget(mFileType);
+ fileTypeGB->setLayout(fileTypeGBL);
+ QGridLayout *propertyGrid = new QGridLayout;
+ propertyGrid->addWidget(dvdNoGB, 0, 0);
+ propertyGrid->addWidget(qualityGB, 0, 1);
+ propertyGrid->addWidget(durationGB, 1, 0);
+ propertyGrid->addWidget(fileTypeGB, 1, 1);
+ QPushButton *updateB = new QPushButton(tr("Update!"));
+ connect(updateB, &QPushButton::clicked, this, &EditFileDialog::accept);
+ QPushButton *cancelB = new QPushButton(tr("Cancel"));
+ connect(cancelB, &QPushButton::clicked, this, &EditFileDialog::reject);
+ QHBoxLayout *buttonLayout = new QHBoxLayout;
+ buttonLayout->addStretch();
+ buttonLayout->addWidget(updateB);
+ buttonLayout->addWidget(cancelB);
+ buttonLayout->addStretch();
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addLayout(lineEditL);
+ mainLayout->addLayout(propertyGrid);
+ mainLayout->addLayout(buttonLayout);
+ setLayout(mainLayout);
+ setMinimumWidth(640);
+}
+
+void EditFileDialog::initDlg(QString md5sum, QString fullPath){
+ QSqlDatabase db = QSqlDatabase::database("treedb");
+ QSqlQuery dataQ(db);
+ dataQ.prepare("SELECT idvd, sifiletype, siquality, tfilename FROM files WHERE cmd5sum = :md5");
+ dataQ.bindValue(":md5", md5sum);
+ dataQ.exec();
+ while(dataQ.next()){
+ int dvdNo = dataQ.value(0).toInt();
+ if(dvdNo == 0){
+ dvdNo = -1;
+ }
+ mDvdNo->setText(QString::number(dvdNo));
+ mQuality->setText(QString::number(dataQ.value(2).toInt()));
+ int fileType = dataQ.value(1).toInt();
+ mFileType->setCurrentText(mFiletypeMap.value(fileType));
+ mFileName->setText(dataQ.value(3).toString());
+ }
+ mMd5Sum->setText(md5sum);
+ QVariantMap ffmpegMap = Helper::ffmpegData(fullPath);
+ mDurationSecs = ffmpegMap.value("duration").toDouble();
+ QString durString = Helper::durationFromSecs(mDurationSecs);
+ mDuration->setText(durString);
+}
+
+void EditFileDialog::accept(){
+ QSqlDatabase db = QSqlDatabase::database("treedb");
+ QSqlQuery updateQ(db);
+ updateQ.prepare("UPDATE files SET sifiletype = :ft, siquality = :fq, idvd = :dvd, iduration = :dur WHERE cmd5sum = :md5");
+ updateQ.bindValue(":md5", mMd5Sum->text());
+ updateQ.bindValue(":fq", mQuality->text().toInt());
+ updateQ.bindValue(":dvd", mDvdNo->text().toInt());
+ updateQ.bindValue(":dur", mDurationSecs);
+ QString fileType = mFileType->currentText();
+ int ft = mFiletypeMap.key(fileType);
+ updateQ.bindValue(":ft", ft);
+ updateQ.exec();
+ QDialog::accept();
+}
diff --git a/editfiledialog.h b/editfiledialog.h
new file mode 100644
index 0000000..e4f91ae
--- /dev/null
+++ b/editfiledialog.h
@@ -0,0 +1,38 @@
+/*
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version
+ 2 of the License, or (at your option) any later version.
+*/
+
+#ifndef EDITFILEDIALOG_H
+#define EDITFILEDIALOG_H
+
+#include <QDialog>
+#include <QHash>
+
+class QLineEdit;
+class QComboBox;
+
+class EditFileDialog : public QDialog {
+ Q_OBJECT
+ public:
+ explicit EditFileDialog(QWidget *parent = nullptr);
+ void initDlg(QString md5sum, QString fullPath);
+
+ public slots:
+ virtual void accept();
+
+ private:
+ void setupGui();
+ QLineEdit *mFileName;
+ QLineEdit *mMd5Sum;
+ QLineEdit *mDvdNo;
+ QLineEdit *mQuality;
+ QLineEdit *mDuration;
+ QComboBox *mFileType;
+ QHash<int, QString> mFiletypeMap;
+ int mDurationSecs;
+};
+
+#endif // EDITFILEDIALOG_H
diff --git a/moviewidget.cpp b/moviewidget.cpp
index 526f25d..878977e 100644
--- a/moviewidget.cpp
+++ b/moviewidget.cpp
@@ -19,12 +19,15 @@
#include "moviewidget.h"
#include "smview.h"
#include "moviepropertiesdialog.h"
+#include "editfiledialog.h"
#include "helper.h"
#include "smglobals.h"
MovieWidget::MovieWidget(QWidget *parent) : QWidget(parent){
mPropDlg = new MoviePropertiesDialog(this);
+ mEditFileDlg = new EditFileDialog(this);
connect(mPropDlg, &MoviePropertiesDialog::accepted, this, &MovieWidget::refresh);
+ connect(mEditFileDlg, &EditFileDialog::accepted, this, &MovieWidget::topSelectionChanged);
setPalette(qApp->palette());
setupWidget();
}
@@ -109,6 +112,8 @@ void MovieWidget::setupWidget(){
connect(mBottomView, &SmView::doubleClicked, this, &MovieWidget::bottomDoubleClicked);
QAction *playSelectedA = new QAction(QIcon(":/spreadingpants.png"), tr("Play selected..."), this);
connect(playSelectedA, &QAction::triggered, this, &MovieWidget::playSelected);
+ QAction *editFileA = new QAction(QIcon(":/huge_bra.png"), tr("Edit file..."), this);
+ connect(editFileA, &QAction::triggered, this, &MovieWidget::editFile);
QAction *filenameToClipA = new QAction(tr("Filename to clip"), this);
connect(filenameToClipA, &QAction::triggered, [=] { copyToClipboard(FilenameRole); });
QAction *fullpathToClipA = new QAction(tr("Full path to clip"), this);
@@ -116,7 +121,7 @@ void MovieWidget::setupWidget(){
QAction *md5ToClipA = new QAction(tr("MD5 to clip"), this);
connect(md5ToClipA, &QAction::triggered, [=] { copyToClipboard(MD5SumRole); });
- mBottomView->addActions(QList<QAction*>() << playSelectedA << Helper::createSeparator(this) << filenameToClipA << fullpathToClipA << md5ToClipA);
+ mBottomView->addActions(QList<QAction*>() << playSelectedA << Helper::createSeparator(this) << editFileA << Helper::createSeparator(this) << filenameToClipA << fullpathToClipA << md5ToClipA);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(topWL);
@@ -451,6 +456,15 @@ void MovieWidget::copyToClipboard(int role){
clip->setText(selected.first().data(role).toString());
}
+void MovieWidget::editFile(){
+ QModelIndexList selected = mBottomView->selectionModel()->selectedRows();
+ if(selected.isEmpty()){
+ return;
+ }
+ mEditFileDlg->initDlg(selected.first().data(MD5SumRole).toString(), selected.first().data(FullPathRole).toString());
+ mEditFileDlg->exec();
+}
+
void MovieWidget::forwardSelection(int by){
int cur = mSelectionCB->currentIndex();
if(cur + by >= mSelectionCB->count()){
diff --git a/moviewidget.h b/moviewidget.h
index 7c23c3b..c30c63d 100644
--- a/moviewidget.h
+++ b/moviewidget.h
@@ -10,6 +10,7 @@ class QSortFilterProxyModel;
class QStandardItemModel;
class SmView;
class MoviePropertiesDialog;
+class EditFileDialog;
class MovieWidget : public QWidget {
Q_OBJECT
@@ -33,6 +34,7 @@ class MovieWidget : public QWidget {
void topDoubleClicked(const QModelIndex &idx);
void playSelected();
void copyToClipboard(int role);
+ void editFile();
void forwardSelection(int by);
private:
@@ -46,6 +48,7 @@ class MovieWidget : public QWidget {
QSortFilterProxyModel *mBottomProxy;
QStandardItemModel *mBottomModel;
MoviePropertiesDialog *mPropDlg;
+ EditFileDialog *mEditFileDlg;
};
#endif // MOVIEWIDGET_H
diff --git a/shemov.pro b/shemov.pro
index baa8137..38916a6 100644
--- a/shemov.pro
+++ b/shemov.pro
@@ -47,7 +47,8 @@ SOURCES = main.cpp \
moviewidget.cpp \
smview.cpp \
moviepropertiesdialog.cpp \
- sminputdialog.cpp
+ sminputdialog.cpp \
+ editfiledialog.cpp
HEADERS = \
shemov.h \
helper.h \
@@ -89,7 +90,8 @@ HEADERS = \
moviewidget.h \
smview.h \
moviepropertiesdialog.h \
- sminputdialog.h
+ sminputdialog.h \
+ editfiledialog.h
LIBS += -lmagic -lXfixes -lX11 -lMagick++-6.Q16HDRI
INCLUDEPATH += /usr/include/ImageMagick-6/
RESOURCES = shemov.qrc