summaryrefslogtreecommitdiffstats
path: root/archivefilewidget.cpp
diff options
context:
space:
mode:
authoram <am@f440f766-f032-0410-8965-dc7d17de2ca0>2009-07-17 17:36:23 +0000
committeram <am@f440f766-f032-0410-8965-dc7d17de2ca0>2009-07-17 17:36:23 +0000
commita477a1998c03bc0e7251463aff5486e3c0872d23 (patch)
tree1de3c2d32f1f1811a7dcc2058bfaf26c18f7e296 /archivefilewidget.cpp
parent1b1e48aa11c4518e100004dac594540e6024fa68 (diff)
downloadSheMov-a477a1998c03bc0e7251463aff5486e3c0872d23.tar.gz
SheMov-a477a1998c03bc0e7251463aff5486e3c0872d23.tar.bz2
SheMov-a477a1998c03bc0e7251463aff5486e3c0872d23.zip
Huge changes:
-Created an application icon and one for archives -implemented database configuration dialog -implemented listeditor -implemented covereditor -implemented md5sum helper -implemented archivefilewidget -Debugging spree: fixed SQL-statements and ListModel git-svn-id: file:///var/svn/repos2/shemov/trunk@389 f440f766-f032-0410-8965-dc7d17de2ca0
Diffstat (limited to 'archivefilewidget.cpp')
-rw-r--r--archivefilewidget.cpp192
1 files changed, 192 insertions, 0 deletions
diff --git a/archivefilewidget.cpp b/archivefilewidget.cpp
new file mode 100644
index 0000000..8d7555c
--- /dev/null
+++ b/archivefilewidget.cpp
@@ -0,0 +1,192 @@
+/*
+ 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 <QTextEdit>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QFont>
+#include <QComboBox>
+#include <QPushButton>
+#include <QSpinBox>
+#include <QColor>
+#include <QLocale>
+#include <QFileInfo>
+
+#include <QDebug>
+
+#include "archivefilewidget.h"
+#include "moviemodel.h"
+#include "listmodel.h"
+#include "helper.h"
+
+ArchiveFileWidget::ArchiveFileWidget(MovieModel *model, QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f) , mModel(model){
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+
+ //selected files
+ QLabel *l1 = new QLabel(tr("Selected files:"));
+ mFiles = new QTextEdit;
+ mFiles->setReadOnly(true);
+ mFiles->setFont(QFont("Courier new"));
+ mFiles->setTextColor(QColor(Qt::red));
+ mainLayout->addWidget(l1);
+ mainLayout->addWidget(mFiles);
+
+ //genre combobox
+ QHBoxLayout *genreLayout = new QHBoxLayout;
+ QLabel *l2 = new QLabel(tr("Select genre"));
+ mGenre = new QComboBox;
+ genreLayout->addWidget(l2);
+ 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);
+
+ //quality and movie title
+ QHBoxLayout *qualityTitleLayout = new QHBoxLayout;
+ QLabel *l4 = new QLabel(tr("Select quality"));
+ mQuality = new QSpinBox;
+ mQuality->setMinimum(0);
+ mQuality->setMaximum(10);
+ QLabel *l5 = new QLabel(tr("Set movie title"));
+ mTitle = new QLineEdit;
+ qualityTitleLayout->addWidget(l4);
+ qualityTitleLayout->addWidget(mQuality);
+ qualityTitleLayout->addWidget(l5);
+ qualityTitleLayout->addWidget(mTitle);
+ mainLayout->addLayout(qualityTitleLayout);
+
+ //archive button layout
+ QHBoxLayout *archiveButtonLayout = new QHBoxLayout;
+ mArchive = new QPushButton(tr("Archive"));
+ connect(mArchive, SIGNAL(clicked()), this, SIGNAL(archive()));
+ archiveButtonLayout->addStretch();
+ archiveButtonLayout->addWidget(mArchive);
+ mainLayout->addLayout(archiveButtonLayout);
+
+ setLayout(mainLayout);
+}
+
+void ArchiveFileWidget::setMovieModel(MovieModel *model){
+ mModel = model;
+}
+
+void ArchiveFileWidget::setGenreModel(ListModel *model){
+ mGenreModel = model;
+ mGenre->setModel(mGenreModel);
+}
+
+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 tableStart("<html><body><table><th><td>Filename</td><td>Size</td><td>MD5-Sum</td><td>Mime type</td></th>");
+ mFiles->append(tableStart);
+ QLocale l;
+ 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);
+ mFiles->append(row);
+ mMd5Sums.insert(f, md5);
+ }
+ QString tableEnd("</table></body></html>");
+ mFiles->append(tableEnd);
+}
+
+const QList<int> ArchiveFileWidget::actorIds() const{
+ QHash<QString, int>::const_iterator i = mActorIdMap.constBegin();
+ QList<int> retval;
+ while(i != mActorIdMap.constEnd()){
+ retval << i.value();
+ }
+ return retval;
+}
+
+int ArchiveFileWidget::genreId() const{
+ QString selectedGenre = mGenre->currentText();
+ QModelIndex idx = mGenreModel->index(selectedGenre);
+ int retval(-1);
+ if(idx.isValid()){
+ retval = mGenreModel->data(idx, ListModel::IdRole).toInt();
+ }else{
+ qDebug() << "genreId: invalid";
+ }
+ return retval;
+}
+
+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();
+ 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());
+ mSelectedActors->append(s);
+ ++i;
+ }
+ mSelectedActors->append("</ul></body></html>");
+}
+