summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--archiveitemcoveredit.cpp214
-rw-r--r--archiveitemcoveredit.h54
-rw-r--r--shemov.pro6
3 files changed, 272 insertions, 2 deletions
diff --git a/archiveitemcoveredit.cpp b/archiveitemcoveredit.cpp
new file mode 100644
index 0000000..41672d7
--- /dev/null
+++ b/archiveitemcoveredit.cpp
@@ -0,0 +1,214 @@
+/*
+ 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 <QLabel>
+#include <QVBoxLayout>
+#include <QGridLayout>
+#include <QSignalMapper>
+#include <QLineEdit>
+#include <QPushButton>
+#include <QCheckBox>
+#include <QFileDialog>
+#include <QSettings>
+#include <QSettings>
+#include <QFileInfo>
+
+#include <algorithm>
+
+#include "archiveitemcoveredit.h"
+#include "pictureviewer.h"
+#include "coveritem.h"
+#include "helper.h"
+
+ArchiveItemCoverEdit::ArchiveItemCoverEdit(QWidget *parent) : QWidget(parent) {
+ //Widget setup
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mPicViewer = new PictureViewer;
+ QSignalMapper *viewMapper = new QSignalMapper(this);
+ QSignalMapper *browseMapper = new QSignalMapper(this);
+ QSignalMapper *unlockMapper = new QSignalMapper(this);
+ QGridLayout *coverLayout = new QGridLayout;
+
+ //Warning
+ QLabel *descriptionLabel = new QLabel(tr("Edit covers of movie - if the movie already has covers you have to unlock the specific cover for changing it. Then click browse to select a new cover. WARNING: The old cover will be deleted from archive if you submit the changes!"));
+ descriptionLabel->setBackgroundRole(QPalette::Light);
+ descriptionLabel->setFrameStyle(QFrame::Box);
+ mainLayout->addWidget(descriptionLabel);
+
+ //Front cover
+ QLabel *frontCoverLabel = new QLabel(tr("Front cover"));
+ coverLayout->addWidget(frontCoverLabel, 0, 0);
+ mFrontCover = new QLineEdit;
+ mInitialValue.insert(mFrontCover, QString());
+ coverLayout->addWidget(mFrontCover);
+ mBrowseFront = new QPushButton(tr("Browse..."));
+ connect(mBrowseFront, SIGNAL(clicked()), browseMapper, SLOT(map()));
+ browseMapper->setMapping(mBrowseFront, mFrontCover);
+ coverLayout->addWidget(mBrowseFront, 0, 1);
+ mViewFront = new QPushButton(tr("View"));
+ connect(mViewFront, SIGNAL(clicked()), viewMapper, SLOT(map()));
+ viewMapper->setMapping(mViewFront, mFrontCover);
+ coverLayout->addWidget(mViewFront, 0, 2);
+ mUnlockFront = new QCheckBox;
+ mCheckboxTexts.insert(mUnlockFront, qMakePair(tr("Unlock front cover"), tr("Reset and lock front cover")));
+ mUnlockFront->setText(mCheckboxTexts.value(mUnlockFront).first);
+ mLineEditMapping.insert(mFrontCover, mUnlockFront);
+ mBrowseMap.insert(mUnlockFront, mBrowseFront);
+ connect(mUnlockFront, SIGNAL(stateChanged(int)), unlockMapper, SLOT(map()));
+ unlockMapper->setMapping(mUnlockFront, mFrontCover);
+ coverLayout->addWidget(mUnlockFront, 1, 1, 0, 2, Qt::AlignRight);
+
+ //Back cover
+ QLabel *backCoverLabel = new QLabel(tr("Back cover"));
+ coverLayout->addWidget(backCoverLabel, 2, 0);
+ mBackCover = new QLineEdit;
+ mInitialValue.insert(mBackCover, QString());
+ coverLayout->addWidget(mBackCover);
+ mBrowseBack = new QPushButton(tr("Browse..."));
+ connect(mBrowseBack, SIGNAL(clicked()), browseMapper, SLOT(map()));
+ browseMapper->setMapping(mBrowseBack, mBackCover);
+ coverLayout->addWidget(mBrowseBack, 2, 1);
+ mViewBack = new QPushButton(tr("View"));
+ connect(mViewBack, SIGNAL(clicked()), viewMapper, SLOT(map()));
+ viewMapper->setMapping(mViewBack, mBackCover);
+ coverLayout->addWidget(mViewBack, 2, 2);
+ mUnlockBack = new QCheckBox;
+ mCheckboxTexts.insert(mUnlockBack, qMakePair(tr("Unlock back cover"), tr("Reset and lock back cover")));
+ mUnlockBack->setText(mCheckboxTexts.value(mUnlockBack).first);
+ mLineEditMapping.insert(mBackCover, mUnlockBack);
+ mBrowseMap.insert(mUnlockBack, mBrowseBack);
+ connect(mUnlockBack, SIGNAL(stateChanged(int)), unlockMapper, SLOT(map()));
+ unlockMapper->setMapping(mUnlockBack, mBackCover);
+ coverLayout->addWidget(mUnlockBack, 3, 1, 0, 2, Qt::AlignRight);
+
+ //General cover
+ QLabel *generalCoverLabel = new QLabel(tr("General cover"));
+ coverLayout->addWidget(generalCoverLabel, 4, 0);
+ mGeneralCover = new QLineEdit;
+ mInitialValue.insert(mGeneralCover, QString());
+ coverLayout->addWidget(mGeneralCover);
+ mBrowseGeneral = new QPushButton(tr("Browse..."));
+ connect(mBrowseGeneral, SIGNAL(clicked()), browseMapper, SLOT(map()));
+ browseMapper->setMapping(mBrowseGeneral, mGeneralCover);
+ coverLayout->addWidget(mBrowseGeneral, 4, 1);
+ mViewGeneral = new QPushButton(tr("View"));
+ connect(mViewGeneral, SIGNAL(clicked()), viewMapper, SLOT(map()));
+ viewMapper->setMapping(mViewGeneral, mGeneralCover);
+ coverLayout->addWidget(mViewGeneral, 4, 2);
+ mUnlockGeneral = new QCheckBox;
+ mCheckboxTexts.insert(mUnlockGeneral, qMakePair(tr("Unlock general cover"), tr("Reset and lock general cover")));
+ mUnlockGeneral->setText(mCheckboxTexts.value(mUnlockGeneral).first);
+ mLineEditMapping.insert(mGeneralCover, mUnlockGeneral);
+ mBrowseMap.insert(mUnlockGeneral, mBrowseGeneral);
+ connect(mUnlockGeneral, SIGNAL(stateChanged(int)), unlockMapper, SLOT(map()));
+ unlockMapper->setMapping(mUnlockGeneral, mGeneralCover);
+ coverLayout->addWidget(mUnlockGeneral, 5, 1, 0, 2, Qt::AlignRight);
+
+ //Connect QSignalMappers
+ connect(unlockMapper, SIGNAL(mapped(QWidget*)), this, SLOT(unlock(QWidget*)));
+ connect(browseMapper, SIGNAL(mapped(QWidget*)), this, SLOT(browse(QWidget*)));
+ connect(viewMapper, SIGNAL(mapped(QWidget*)), this, SLOT(view(QWidget*)));
+
+ //Setup Widget
+ mainLayout->addLayout(coverLayout);
+ setLayout(mainLayout);
+}
+
+void ArchiveItemCoverEdit::setCovers(const QList<QVariant> &covers){
+ QList<QVariant>::const_iterator it;
+
+ //Set front cover
+ it = std::find_if(covers.constBegin(), covers.constEnd(), std::bind2nd(CoverItem::findType(), "front"));
+ QString initialValue;
+ if(it != covers.constEnd()){
+ initialValue = it->value<CoverItem>().fileName();
+ }
+ mFrontCover->setText(initialValue);
+ mInitialValue[mFrontCover] = initialValue;
+ initialValue.clear();
+ mUnlockFront->setChecked(true);
+
+ //Set back cover
+ it = std::find_if(covers.constBegin(), covers.constEnd(), std::bind2nd(CoverItem::findType(), "back"));
+ if(it != covers.constEnd()){
+ initialValue = it->value<CoverItem>().fileName();
+ }
+ mBackCover->setText(initialValue);
+ mInitialValue[mBackCover] = initialValue;
+ initialValue.clear();
+ mUnlockBack->setChecked(true);
+
+ //Set general cover
+ it = std::find_if(covers.constBegin(), covers.constEnd(), std::bind2nd(CoverItem::findType(), "general"));
+ if(it != covers.constEnd()){
+ initialValue = it->value<CoverItem>().fileName();
+ }
+ mGeneralCover->setText(initialValue);
+ mInitialValue[mGeneralCover] = initialValue;
+ initialValue.clear();
+ mUnlockGeneral->setChecked(true);
+}
+
+QList<QVariant> ArchiveItemCoverEdit::covers() const {
+ QList<QVariant> retval;
+ QString frontCover = mFrontCover->text();
+ if(!frontCover.isEmpty()){
+ QString md5Sum = Helper::md5Sum(frontCover);
+ retval << QVariant::fromValue(CoverItem(frontCover, "front", md5Sum));
+ }
+ QString backCover = mBackCover->text();
+ if(!backCover.isEmpty()){
+ QString md5Sum = Helper::md5Sum(backCover);
+ retval << QVariant::fromValue(CoverItem(backCover, "back", md5Sum));
+ }
+ QString generalCover = mGeneralCover->text();
+ if(!generalCover.isEmpty()){
+ QString md5Sum = Helper::md5Sum(generalCover);
+ retval << QVariant::fromValue(CoverItem(generalCover, "general", md5Sum));
+ }
+ return retval;
+}
+
+void ArchiveItemCoverEdit::unlock(QWidget *lineEdit){
+ QLineEdit *editor = static_cast<QLineEdit*>(lineEdit);
+ Q_ASSERT(editor);
+ QCheckBox *checkBox = mLineEditMapping.value(editor);
+ if(!checkBox->isChecked()){
+ editor->setEnabled(true);
+ mBrowseMap.value(checkBox)->setEnabled(true);
+ checkBox->setText(mCheckboxTexts.value(checkBox).second);
+ }else{
+ editor->setText(mInitialValue.value(editor));
+ editor->setEnabled(false);
+ mBrowseMap.value(checkBox)->setEnabled(false);
+ checkBox->setText(mCheckboxTexts.value(checkBox).first);
+ }
+}
+
+void ArchiveItemCoverEdit::browse(QWidget *lineEdit){
+ QLineEdit *editor = static_cast<QLineEdit*>(lineEdit);
+ Q_ASSERT(editor);
+ if(mLastOpenedDir.isEmpty()){
+ QSettings s;
+ mLastOpenedDir = s.value("paths/selecteddir", QDir::homePath()).toString();
+ }
+ QString cover = QFileDialog::getOpenFileName(this, "Select cover", mLastOpenedDir);
+ editor->setText(cover);
+ if(!cover.isEmpty()){
+ QFileInfo fi(cover);
+ mLastOpenedDir = fi.absoluteFilePath();
+ }
+}
+
+void ArchiveItemCoverEdit::view(QWidget *lineEdit){
+ QLineEdit *editor = static_cast<QLineEdit*>(lineEdit);
+ Q_ASSERT(editor);
+ QString file = editor->text();
+ if(!file.isEmpty()){
+ mPicViewer->showPic(file, false);
+ }
+}
diff --git a/archiveitemcoveredit.h b/archiveitemcoveredit.h
new file mode 100644
index 0000000..7f91a49
--- /dev/null
+++ b/archiveitemcoveredit.h
@@ -0,0 +1,54 @@
+/*
+ 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 ARCHIVEITEMCOVEREDIT_H
+#define ARCHIVEITEMCOVEREDIT_H
+
+#include <QWidget>
+#include <QHash>
+#include <QPair>
+#include <QList>
+
+class QLineEdit;
+class QPushButton;
+class QCheckBox;
+class PictureViewer;
+
+class ArchiveItemCoverEdit : public QWidget {
+ Q_OBJECT
+ public:
+ explicit ArchiveItemCoverEdit(QWidget *parent = 0);
+ void setCovers(const QList<QVariant> &covers);
+ QList<QVariant> covers() const;
+
+ private slots:
+ void unlock(QWidget *lineEdit);
+ void browse(QWidget *lineEdit);
+ void view(QWidget *lineEdit);
+
+ private:
+ QLineEdit *mFrontCover;
+ QLineEdit *mBackCover;
+ QLineEdit *mGeneralCover;
+ QPushButton *mBrowseFront;
+ QPushButton *mBrowseBack;
+ QPushButton *mBrowseGeneral;
+ QPushButton *mViewFront;
+ QPushButton *mViewBack;
+ QPushButton *mViewGeneral;
+ QCheckBox *mUnlockFront;
+ QCheckBox *mUnlockBack;
+ QCheckBox *mUnlockGeneral;
+ QHash<QLineEdit*, QCheckBox*> mLineEditMapping;
+ QHash<QLineEdit*, QString> mInitialValue;
+ QHash<QCheckBox*, QPair<QString, QString> > mCheckboxTexts;
+ QHash<QCheckBox*, QPushButton*> mBrowseMap;
+ QString mLastOpenedDir;
+ PictureViewer *mPicViewer;
+};
+
+#endif
diff --git a/shemov.pro b/shemov.pro
index cbdb1aa..a6090c3 100644
--- a/shemov.pro
+++ b/shemov.pro
@@ -45,7 +45,8 @@ SOURCES = main.cpp \
moviemodelsingleton.cpp \
pictureviewer.cpp \
pictureviewerinfoitem.cpp \
- archiveiteminfoedit.cpp
+ archiveiteminfoedit.cpp \
+ archiveitemcoveredit.cpp
HEADERS = listitem.h \
listmodel.h \
movieitem.h \
@@ -86,6 +87,7 @@ HEADERS = listitem.h \
moviemodelsingleton.h \
pictureviewer.h \
pictureviewerinfoitem.h \
- archiveiteminfoedit.h
+ archiveiteminfoedit.h \
+ archiveitemcoveredit.h
LIBS += -lmagic
RESOURCES = shemov.qrc