diff options
author | am <am@f440f766-f032-0410-8965-dc7d17de2ca0> | 2009-11-06 16:52:04 +0000 |
---|---|---|
committer | am <am@f440f766-f032-0410-8965-dc7d17de2ca0> | 2009-11-06 16:52:04 +0000 |
commit | cb094b007ec5b7c197a7df502a778a2ce919128f (patch) | |
tree | 2add8b0593fddcdd84e902c466d8885f59d5147c | |
parent | c9497f0e16ad13493f59b835016d46d919378f6d (diff) | |
download | SheMov-cb094b007ec5b7c197a7df502a778a2ce919128f.tar.gz SheMov-cb094b007ec5b7c197a7df502a778a2ce919128f.tar.bz2 SheMov-cb094b007ec5b7c197a7df502a778a2ce919128f.zip |
-made burnDir configurable via ConfigurationDialog
-revamped archivedialog to make it more intuitive
-added simple listModel without database access (should be renamed)
-actorlist in archivedialog now is a QTreeView
-changed mFileList in achiveFileWidget
git-svn-id: file:///var/svn/repos2/shemov/trunk@421 f440f766-f032-0410-8965-dc7d17de2ca0
-rw-r--r-- | actormodel.cpp | 110 | ||||
-rw-r--r-- | actormodel.h | 37 | ||||
-rw-r--r-- | actorwidget.cpp | 65 | ||||
-rw-r--r-- | actorwidget.h | 41 | ||||
-rw-r--r-- | archivefilewidget.cpp | 99 | ||||
-rw-r--r-- | archivefilewidget.h | 12 | ||||
-rw-r--r-- | archiveviewwidget.cpp | 12 | ||||
-rw-r--r-- | configurationdialog.cpp | 7 | ||||
-rw-r--r-- | configurationdialog.h | 1 | ||||
-rw-r--r-- | shemov.pro | 8 |
10 files changed, 296 insertions, 96 deletions
diff --git a/actormodel.cpp b/actormodel.cpp new file mode 100644 index 0000000..3f07f3d --- /dev/null +++ b/actormodel.cpp @@ -0,0 +1,110 @@ +/* + 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 <QIcon> + +#include "actormodel.h" + +ActorModel::ActorModel() {}; + +QModelIndex ActorModel::index(int row, int column, const QModelIndex &) const { + if((column != 0) || (row >= mItems.size()) || row < 0){ + return QModelIndex(); + } + return createIndex(row, 0, 0); +} + +QModelIndex ActorModel::index(const QVariant &item) const { + if(item == QVariant()){ + return QModelIndex(); + } + QString sItem = item.toString(); + for(int i = 0; i < mItems.size(); ++i){ + if(mItems.at(i) == sItem){ + return createIndex(i, 0, 0); + } + } + return QModelIndex(); +} + +int ActorModel::rowCount(const QModelIndex &) const { + return mItems.size(); +} + +QVariant ActorModel::data(const QModelIndex &index, int role) const { + if(!index.isValid() || (index.column() > 0) || (index.row() > mItems.size())){ + return QVariant(); + } + switch (role) { + case Qt::DisplayRole: + return mItems.at(index.row()); + break; + case Qt::DecorationRole: + return QIcon(":/dildo.png"); + break; + } + return QVariant(); +} + +bool ActorModel::insertRows(int row, int count, const QModelIndex &){ + beginInsertRows(QModelIndex(), row, row + count - 1); + for(int i = row; i < (row + count); ++i){ + mItems.insert(i, QString()); + } + endInsertRows(); + return true; +} + +bool ActorModel::removeRows(int row, int count, const QModelIndex &){ + if((row > mItems.size()) || ((row + count) > mItems.size())){ + return false; + } + beginRemoveRows(QModelIndex(), row, row + (count - 1)); + for(int i = row; i < (row + count); ++i){ + mItems.removeAt(i); + } + endRemoveRows(); + return true; +} + +bool ActorModel::setData(const QModelIndex &idx, const QVariant &data, int role){ + if(!idx.isValid() || (idx.column() != 0) || (role != Qt::EditRole)){ + return false; + } + mItems[idx.row()] = data.toString(); + qSort(mItems); + dataChanged(index(0, 0), index((mItems.size() - 1), 0)); + return true; +} + +bool ActorModel::addItem(const QVariant &data){ + if(mItems.contains(data.toString())){ + return false; + } + bool success = false; + if(insertRows(0, 1, QModelIndex())){ + QModelIndex idx = index(0, 0); + if(idx.isValid()){ + success = setData(idx, data, Qt::EditRole); + } + } + return success; +} + +bool ActorModel::removeItem(const QVariant &data){ + QModelIndex idx = index(data); + if(!idx.isValid()){ + return false; + } + bool retval = removeRows(idx.row(), 1, QModelIndex()); + return retval; +} + +void ActorModel::clear() { + removeRows(0, mItems.size(), QModelIndex()); +} + diff --git a/actormodel.h b/actormodel.h new file mode 100644 index 0000000..9f15423 --- /dev/null +++ b/actormodel.h @@ -0,0 +1,37 @@ +/* + 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 ACTORMODEL_H +#define ACTORMODEL_H + +#include <QAbstractItemModel> +#include <QList> + +class ActorModel : public QAbstractItemModel { + public: + ActorModel(); + ~ActorModel() {}; + QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const; + QModelIndex index(const QVariant &item) const; + QModelIndex parent(const QModelIndex &) const { return QModelIndex(); }; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &) const { return 1; }; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + bool insertRows(int row, int count, const QModelIndex &parent); + bool removeRows(int row, int count, const QModelIndex &parent); + bool setData(const QModelIndex &idx, const QVariant &data, int role = Qt::EditRole); + bool addItem(const QVariant &data); + bool removeItem(const QVariant &data); + void clear(); + const QList<QString> items() const { return mItems; }; + + private: + QList<QString> mItems; +}; + +#endif + diff --git a/actorwidget.cpp b/actorwidget.cpp new file mode 100644 index 0000000..a62331e --- /dev/null +++ b/actorwidget.cpp @@ -0,0 +1,65 @@ +/* + 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 <QVBoxLayout> +#include <QHBoxLayout> +#include <QPushButton> +#include <QTreeView> +#include <QLabel> + +#include <QDebug> + +#include "actorwidget.h" +#include "actormodel.h" + +ActorWidget::ActorWidget(QWidget *parent) : QWidget(parent) { + QVBoxLayout *mainLayout = new QVBoxLayout; + + QLabel *l1 = new QLabel(tr("Actors")); + + mModel = new ActorModel; + mView = new QTreeView; + mView->setModel(mModel); + mView->setRootIsDecorated(false); + mView->setSelectionMode(QAbstractItemView::ExtendedSelection); + mView->setHeaderHidden(true); + + QHBoxLayout *buttonLayout = new QHBoxLayout; + mRemoveActor = new QPushButton(tr("&Remove selected")); + connect(mRemoveActor, SIGNAL(clicked()), this, SLOT(removeActor())); + mClearAll = new QPushButton(tr("Remove &all")); + connect(mClearAll, SIGNAL(clicked()), this, SLOT(clear())); + buttonLayout->addStretch(); + buttonLayout->addWidget(mClearAll); + buttonLayout->addWidget(mRemoveActor); + + mainLayout->addWidget(l1); + mainLayout->addWidget(mView); + mainLayout->addLayout(buttonLayout); + + setLayout(mainLayout); +} + +const QStringList ActorWidget::actors(){ + return mModel->items(); +} + +void ActorWidget::addActor(const QString &actor) { + mModel->addItem(actor); +} + +void ActorWidget::clear() { + mModel->clear(); +} + +void ActorWidget::removeActor() { + QModelIndexList idxs = mView->selectionModel()->selectedRows(); + foreach(QModelIndex idx, idxs){ + mModel->removeItem(idx.data()); + } +} + diff --git a/actorwidget.h b/actorwidget.h new file mode 100644 index 0000000..fec8b25 --- /dev/null +++ b/actorwidget.h @@ -0,0 +1,41 @@ +/* + 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 ACTORWIDGET_H +#define ACTORWIDGET_H + +#include <QWidget> +#include <QMap> + +class QPushButton; +class QHBoxLayout; +class QTreeView; +class ActorModel; + +class ActorWidget : public QWidget { + Q_OBJECT + public: + ActorWidget(QWidget *parent = 0); + ~ActorWidget() {}; + const QStringList actors(); + + public slots: + void addActor(const QString &actor); + void clear(); + + private slots: + void removeActor(); + + private: + QPushButton *mRemoveActor; + QPushButton *mClearAll; + QTreeView *mView; + ActorModel *mModel; +}; + +#endif + diff --git a/archivefilewidget.cpp b/archivefilewidget.cpp index 4f4ba0c..f9ca5f8 100644 --- a/archivefilewidget.cpp +++ b/archivefilewidget.cpp @@ -15,6 +15,7 @@ #include <QColor> #include <QLocale> #include <QFileInfo> +#include <QScrollArea> #include <QDebug> @@ -22,6 +23,7 @@ #include "moviemodel.h" #include "listmodel.h" #include "helper.h" +#include "actorwidget.h" ArchiveFileWidget::ArchiveFileWidget(MovieModel *model, QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f) , mModel(model){ QVBoxLayout *mainLayout = new QVBoxLayout; @@ -32,6 +34,8 @@ ArchiveFileWidget::ArchiveFileWidget(MovieModel *model, QWidget *parent, Qt::Win mFiles->setReadOnly(true); mFiles->setFont(QFont("Courier new")); mFiles->setTextColor(QColor(Qt::red)); + QScrollArea *sa = new QScrollArea; + sa->setWidget(mFiles); mainLayout->addWidget(l1); mainLayout->addWidget(mFiles); @@ -43,31 +47,9 @@ ArchiveFileWidget::ArchiveFileWidget(MovieModel *model, QWidget *parent, Qt::Win genreLayout->addWidget(mGenre); mainLayout->addLayout(genreLayout); - //actors combobox - QHBoxLayout *actorsLayout = new QHBoxLayout; - QLabel *l3 = new QLabel(tr("Select actors")); - mActors = new QComboBox; - actorsLayout->addWidget(l3); - actorsLayout->addWidget(mActors); - mainLayout->addLayout(actorsLayout); - - //selected actors - mSelectedActors = new QTextEdit; - mSelectedActors->setReadOnly(true); - mSelectedActors->setFont(QFont("Courier new")); - mSelectedActors->setTextColor(QColor(Qt::red)); - mainLayout->addWidget(mSelectedActors); - - //actors buttons - QHBoxLayout *actorButtonLayout = new QHBoxLayout; - mAddActor = new QPushButton(tr("&Add actor")); - connect(mAddActor, SIGNAL(clicked()), this, SLOT(addActor())); - mRemoveActor = new QPushButton(tr("&Remove actor")); - connect(mRemoveActor, SIGNAL(clicked()), this, SLOT(removeActor())); - actorButtonLayout->addStretch(); - actorButtonLayout->addWidget(mAddActor); - actorButtonLayout->addWidget(mRemoveActor); - mainLayout->addLayout(actorButtonLayout); + //actors + mActorWidget = new ActorWidget; + mainLayout->addWidget(mActorWidget); //quality and movie title QHBoxLayout *qualityTitleLayout = new QHBoxLayout; @@ -119,38 +101,37 @@ void ArchiveFileWidget::setGenreModel(ListModel *model){ void ArchiveFileWidget::setActorsModel(ListModel *model){ mActorsModel = model; - mActors->setModel(mActorsModel); } void ArchiveFileWidget::setFiles(const QStringList &files){ mFileList = files; mFiles->clear(); mMd5Sums.clear(); - mActorIdMap.clear(); - QString html("<html><body style=\"color:#CD0003\"><table border=\"2\" cellspacing=\"5\" cellspacing=\"5\"><tr><th>Filename</th><th>Size</th><th>MD5-Sum</th><th>Mime type</th></tr>"); QLocale l; + QString html("<html><body style=\"color:#cd0003\">"); foreach(QString f, files){ QFileInfo info(f); qint64 size = info.size(); QString md5 = Helper::md5Sum(f); QString filename = info.fileName(); QString mimeType = Helper::mimeType(f); - QString row = QString("<tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td></tr>").arg(filename).arg(l.toString(size)).arg(md5).arg(mimeType); - html.append(row); + QString file = QString("<p>%1</p><ul><li>Size: %2</li><li>MD5-Sum: %3</li><li>Mime Type: %4</li></ul>").arg(filename).arg(l.toString(size)).arg(md5).arg(mimeType); + html.append(file); mMd5Sums.insert(f, md5); } - html.append("</table></body></html>"); + html.append("</body></html>"); mFiles->setHtml(html); - mSelectedActors->clear(); + mActorWidget->clear(); mTitle->clear(); } const QList<int> ArchiveFileWidget::actorIds() const{ - QHash<QString, int>::const_iterator i = mActorIdMap.constBegin(); QList<int> retval; - while(i != mActorIdMap.constEnd()){ - retval << i.value(); - ++i; + foreach(const QString s, mActorWidget->actors()){ + QModelIndex idx = mActorsModel->index(s); + if(idx.isValid()){ + retval << idx.data(ListModel::IdRole).toInt(); + } } return retval; } @@ -168,11 +149,7 @@ int ArchiveFileWidget::genreId() const{ } void ArchiveFileWidget::setActor(const QString &actor){ - int idx = mActors->findText(actor); - if(idx != -1){ - mActors->setCurrentIndex(idx); - addActor(); - } + mActorWidget->addActor(actor); } void ArchiveFileWidget::setQuality(int quality){ @@ -191,43 +168,3 @@ void ArchiveFileWidget::setPartNo(int partno){ mPartNo->setValue(partno); } -void ArchiveFileWidget::addActor(){ - QString selectedActor = mActors->currentText(); - if(!selectedActor.isEmpty() && !mActorIdMap.contains(selectedActor)){ - QModelIndex idx = mActorsModel->index(selectedActor); - if(idx.isValid()){ - int id = mActorsModel->data(idx, ListModel::IdRole).toInt(); - mActorIdMap.insert(selectedActor, id); - createActorList(); - QString message = QString(tr("Added actor %1 to actor list")).arg(selectedActor); - emit statusbarMessage(message); - }else{ - qDebug() << "addActor: invalid!"; - } - } -} - -void ArchiveFileWidget::removeActor(){ - QString selectedActor = mActors->currentText(); - if(!selectedActor.isEmpty()){ - mActorIdMap.remove(selectedActor); - createActorList(); - QString message = QString(tr("Removed actor %1 from actor list")).arg(selectedActor); - emit statusbarMessage(message); - } -} - -void ArchiveFileWidget::createActorList(){ - mSelectedActors->clear(); - QString html("<html><body style=\"color:#CD0003\"><ul>"); - mSelectedActors->append("<html><body><ul>"); - QHash<QString, int>::const_iterator i = mActorIdMap.constBegin(); - while(i != mActorIdMap.constEnd()){ - QString s = QString("<li>%1</li>").arg(i.key()); - html.append(s); - ++i; - } - html.append("</ul></body></html>"); - mSelectedActors->setHtml(html); -} - diff --git a/archivefilewidget.h b/archivefilewidget.h index 339c66d..5470460 100644 --- a/archivefilewidget.h +++ b/archivefilewidget.h @@ -20,6 +20,7 @@ class QPushButton; class QStringList; class MovieModel; class ListModel; +class ActorWidget; class ArchiveFileWidget : public QWidget { Q_OBJECT @@ -49,28 +50,19 @@ class ArchiveFileWidget : public QWidget { void setSeriesNo(int seriesno); void setPartNo(int partno); - private slots: - void addActor(); - void removeActor(); - private: - void createActorList(); MovieModel *mModel; ListModel *mGenreModel; ListModel *mActorsModel; QTextEdit *mFiles; - QTextEdit *mSelectedActors; + ActorWidget *mActorWidget; QComboBox *mGenre; - QComboBox *mActors; - QPushButton *mAddActor; - QPushButton *mRemoveActor; QSpinBox *mQuality; QSpinBox *mSeriesNo; QSpinBox *mPartNo; QLineEdit *mTitle; QStringList mFileList; QHash<QString, QString> mMd5Sums; - QHash<QString, int> mActorIdMap; }; #endif diff --git a/archiveviewwidget.cpp b/archiveviewwidget.cpp index e94a4ef..810b133 100644 --- a/archiveviewwidget.cpp +++ b/archiveviewwidget.cpp @@ -193,13 +193,19 @@ void ArchiveViewWidget::moveBurn(){ return; } QSettings s; - QString destBase = QString("%1/%2").arg(s.value("paths/start").toString()).arg(tr("burn")); + QString burnDir = s.value("paths/burn").toString(); + if(burnDir.isEmpty()){ + QMessageBox::critical(this, tr("Error"), tr("Directory for burning not set. Please configure it in Configure->Paths.")); + return; + + } + QString destBase = QString("%1/%2").arg(burnDir).arg(tr("burn")); QFileInfo dbi(destBase); if(!dbi.exists()){ - QDir bd(s.value("paths/start").toString()); + QDir bd(s.value("ui/selectstartup").toString()); bool success = bd.mkdir(tr("burn")); if(!success){ - QString msg = QString("Failed to create dir %1 in %2").arg(s.value("paths/start").toString()).arg(tr("burn")); + QString msg = QString("Failed to create dir %1 in %2").arg(s.value("ui/selectstartup").toString()).arg(tr("burn")); emit statusbarMessage(msg); return; } diff --git a/configurationdialog.cpp b/configurationdialog.cpp index 021d40b..617a52e 100644 --- a/configurationdialog.cpp +++ b/configurationdialog.cpp @@ -86,6 +86,11 @@ ConfigurationDialog::ConfigurationDialog(QWidget *parent, Qt::WindowFlags f) : Q pathButtonLayout->addWidget(mAddPath); pathButtonLayout->addWidget(mRemovePath); pathGrid->addLayout(pathButtonLayout, 9, 1); + QLabel *l10 = new QLabel(tr("Burn Directory")); + mBurnDir = new QLineEdit; + mBurnDir->setCompleter(fsCompleter); + pathGrid->addWidget(l10, 10, 0); + pathGrid->addWidget(mBurnDir, 10, 1); pathWidget->setLayout(pathGrid); mTab->addTab(pathWidget, tr("Paths")); @@ -237,6 +242,7 @@ void ConfigurationDialog::readSettings(){ mArchivePaths->addItems(extractPaths); mPaths = extractPaths; mArchiveDir->setText(s.value("paths/archivedir").toString()); + mBurnDir->setText(s.value("paths/burn").toString()); //read ui QStringList expandPaths = s.value("ui/expandpaths").toStringList(); @@ -272,6 +278,7 @@ void ConfigurationDialog::writeSettings(){ s.setValue("paths/archiverargs", aArgs); s.setValue("paths/extractpaths", mPaths); s.setValue("paths/archivedir", mArchiveDir->text()); + s.setValue("paths/burn", mBurnDir->text()); //write ui s.setValue("ui/expandpaths", mEPaths); diff --git a/configurationdialog.h b/configurationdialog.h index 9b11a49..d5b1eda 100644 --- a/configurationdialog.h +++ b/configurationdialog.h @@ -51,6 +51,7 @@ class ConfigurationDialog : public QDialog { QLineEdit *mExtractPath; QLineEdit *mExpandPath; QLineEdit *mArchiveDir; + QLineEdit *mBurnDir; QLineEdit *mDatabaseHost; QLineEdit *mDatabaseName; QLineEdit *mDatabaseUsername; @@ -30,7 +30,9 @@ archiveddelegate.cpp \ coverarchiveeditor.cpp \ textenterdialog.cpp \ moviepropertiesdialog.cpp \ -statisticsdialog.cpp +statisticsdialog.cpp \ +actorwidget.cpp \ +actormodel.cpp HEADERS = listitem.h \ listmodel.h \ movieitem.h \ @@ -59,7 +61,9 @@ archiveddelegate.h \ coverarchiveeditor.h \ textenterdialog.h \ moviepropertiesdialog.h \ -statisticsdialog.h +statisticsdialog.h \ +actorwidget.h \ +actormodel.h LIBS += -lmagic LIBS += -lcryptopp INCLUDEPATH += /usr/include/cryptopp |