summaryrefslogtreecommitdiffstats
path: root/coverarchiveeditor.cpp
diff options
context:
space:
mode:
authoram <am@f440f766-f032-0410-8965-dc7d17de2ca0>2009-07-22 18:44:02 +0000
committeram <am@f440f766-f032-0410-8965-dc7d17de2ca0>2009-07-22 18:44:02 +0000
commit0e3e202c90e3ccb80310087409936c00189f0cea (patch)
treea4a38c32e761f024e2dfad6a59097cff15472b9e /coverarchiveeditor.cpp
parent84ed109c159dcbd0c9395717d54599e902060b26 (diff)
downloadSheMov-0e3e202c90e3ccb80310087409936c00189f0cea.tar.gz
SheMov-0e3e202c90e3ccb80310087409936c00189f0cea.tar.bz2
SheMov-0e3e202c90e3ccb80310087409936c00189f0cea.zip
-Finished CoverArchiveEditor (finally, don't like that piece of code, too complicated)
-It's now possible to manually add a movie w/o a file -Some usability fixes git-svn-id: file:///var/svn/repos2/shemov/trunk@394 f440f766-f032-0410-8965-dc7d17de2ca0
Diffstat (limited to 'coverarchiveeditor.cpp')
-rw-r--r--coverarchiveeditor.cpp182
1 files changed, 182 insertions, 0 deletions
diff --git a/coverarchiveeditor.cpp b/coverarchiveeditor.cpp
new file mode 100644
index 0000000..f8f21b6
--- /dev/null
+++ b/coverarchiveeditor.cpp
@@ -0,0 +1,182 @@
+/*
+ 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 <QGridLayout>
+#include <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QPushButton>
+#include <QComboBox>
+#include <QLabel>
+#include <QModelIndex>
+#include <QApplication>
+#include <QFileDialog>
+#include <QFileInfo>
+#include <QSettings>
+
+#include <algorithm>
+
+#include "coverarchiveeditor.h"
+#include "moviemodel.h"
+#include "coveritem.h"
+#include "helper.h"
+
+CoverArchiveEditor::CoverArchiveEditor(MovieModel *model, QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f), mModel(model){
+ QGridLayout *grid = new QGridLayout;
+
+ //front cover
+ QLabel *l1 = new QLabel(tr("Set &front cover"));
+ mFront = new QComboBox;
+ l1->setBuddy(mFront);
+ grid->addWidget(l1, 0, 0);
+ grid->addWidget(mFront, 0, 1);
+
+ //back cover
+ QLabel *l2 = new QLabel(tr("Set &back cover"));
+ mBack = new QComboBox;
+ l2->setBuddy(mBack);
+ grid->addWidget(l2, 1, 0);
+ grid->addWidget(mBack, 1, 1);
+
+ //general cover
+ QLabel *l3 = new QLabel(tr("Set &general cover"));
+ mCovers = new QComboBox;
+ l3->setBuddy(mCovers);
+ grid->addWidget(l3, 2, 0);
+ grid->addWidget(mCovers, 2, 1);
+
+ //buttons
+ QHBoxLayout *buttonLayout = new QHBoxLayout;
+ mAddCover = new QPushButton(tr("Add cover..."));
+ connect(mAddCover, SIGNAL(clicked()), this, SLOT(addCover()));
+ mUpdate = new QPushButton(tr("Update"));
+ connect(mUpdate, SIGNAL(clicked()), this, SLOT(accept()));
+ mClose = new QPushButton(tr("Close"));
+ connect(mClose, SIGNAL(clicked()), this, SLOT(reject()));
+ buttonLayout->addStretch();
+ buttonLayout->addWidget(mAddCover);
+ buttonLayout->addWidget(mUpdate);
+ buttonLayout->addWidget(mClose);
+
+ //main layout
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addLayout(grid);
+ mainLayout->addLayout(buttonLayout);
+
+ setLayout(mainLayout);
+}
+
+void CoverArchiveEditor::setMovie(const QModelIndex &movie){
+ mCoverList = mModel->data(movie, MovieModel::CoverRole).toList();
+ mMovId = mModel->data(movie, MovieModel::IdRole).toInt();
+ QString title = QString(tr("%1 - Cover edit for %2")).arg(qApp->applicationName()).arg(movie.data().toString());
+ setWindowTitle(title);
+ QStringList files("-");
+ foreach(QVariant c, mCoverList){
+ CoverItem item = c.value<CoverItem>();
+ files << item.fileName();
+ }
+ mFront->addItems(files);
+ QList<QVariant>::const_iterator it;
+ int idx(-1);
+ it = std::find_if(mCoverList.constBegin(), mCoverList.constEnd(), std::bind2nd(CoverItem::findType(), "front"));
+ QString fn;
+ if(it != mCoverList.constEnd()){
+ fn = it->value<CoverItem>().fileName();
+ idx = mFront->findText(fn);
+ if(idx != -1){
+ mFront->setCurrentIndex(idx);
+ }
+ }
+ mBack->addItems(files);
+ it = std::find_if(mCoverList.constBegin(), mCoverList.constEnd(), std::bind2nd(CoverItem::findType(), "back"));
+ if(it != mCoverList.constEnd()){
+ fn = it->value<CoverItem>().fileName();
+ idx = mBack->findText(fn);
+ if(idx != -1){
+ mBack->setCurrentIndex(idx);
+ }
+ }
+ mCovers->addItems(files);
+ it = std::find_if(mCoverList.constBegin(), mCoverList.constEnd(), std::bind2nd(CoverItem::findType(), "general"));
+ if(it != mCoverList.constEnd()){
+ fn = it->value<CoverItem>().fileName();
+ idx = mCovers->findText(fn);
+ if(idx != -1){
+ mCovers->setCurrentIndex(idx);
+ }
+ }
+}
+
+void CoverArchiveEditor::accept(){
+ QList<CoverItem> items;
+ QString fn;
+ CoverItem item;
+ fn = mFront->currentText();
+ item = realItem(fn, "front");
+ if(item != CoverItem()){
+ items << item;
+ }
+ fn = mBack->currentText();
+ item = realItem(fn, "back");
+ if(item != CoverItem()){
+ items << item;
+ }
+ fn = mCovers->currentText();
+ item = realItem(fn, "general");
+ if(item != CoverItem()){
+ items << item;
+ }
+ mModel->setCovers(mMovId, items);
+}
+
+void CoverArchiveEditor::addCover(){
+ QSettings s;
+ QString startDir = s.value("ui/selectstartup").toString();
+ QStringList files = QFileDialog::getOpenFileNames(this, "Select covers to add...", startDir);
+ QStringList addItems;
+ foreach(QString f, files){
+ mAddedCovers << f;
+ QFileInfo info(f);
+ addItems << info.fileName();
+ }
+ mFront->addItems(addItems);
+ mBack->addItems(addItems);
+ mCovers->addItems(addItems);
+}
+
+CoverItem CoverArchiveEditor::coverItem(const QString &path, const QString &type) const{
+ QString md5 = Helper::md5Sum(path);
+ QString newPath = Helper::moveToArchive(path, md5);
+ return CoverItem(newPath, type, md5);
+}
+
+CoverItem CoverArchiveEditor::realItem(const QString &filename, const QString &type) const{
+ QList<QVariant>::const_iterator initCit = std::find_if(mCoverList.constBegin(), mCoverList.constEnd(), std::bind2nd(CoverItem::findFilename(), filename));
+ //got it, have to convert it to the right type
+ if(initCit != mCoverList.constEnd()){
+ CoverItem i = initCit->value<CoverItem>();
+ i.setType(type);
+ return i;
+ //an added item
+ }else{
+ QList<QString>::const_iterator ait = std::find_if(mAddedCovers.constBegin(), mAddedCovers.constEnd(), std::bind2nd(Helper::StringListContains(), filename));
+ //maybe an unset item
+ if(ait == mAddedCovers.constEnd()){
+ QList<QVariant>::const_iterator oit = std::find_if(mCoverList.constBegin(), mCoverList.constEnd(), std::bind2nd(CoverItem::findType(), type));
+ if(oit != mCoverList.constEnd()){
+ CoverItem oldItem = oit->value<CoverItem>();
+ //remove it from fs
+ Helper::removeFromArchive(oldItem.fileName(), oldItem.md5());
+ }
+ return CoverItem();
+ }
+ CoverItem i = coverItem((*ait), type);
+ return i;
+ }
+ return CoverItem();
+}
+