summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2010-06-26 17:16:12 +0200
committerArno <am@disconnect.de>2010-06-26 17:16:12 +0200
commit8dc808a3bd6a8156db4f68e6faaaaae6a0534195 (patch)
tree36d0d4f09903884cb96ad290ce52ccfe2d105819
parent0b807eba97e65bf9e25f83387826ef2579b79c90 (diff)
downloadSheMov-8dc808a3bd6a8156db4f68e6faaaaae6a0534195.tar.gz
SheMov-8dc808a3bd6a8156db4f68e6faaaaae6a0534195.tar.bz2
SheMov-8dc808a3bd6a8156db4f68e6faaaaae6a0534195.zip
Implemented playing a movie on doubleclick
Movie files are played in the default player when double clicking on a movie, but not when doubleclicking on a series. The latter invokes the edit event on the series. Don't yet know if this is a good thing or not. Changes on the way there: 1. new helper function for finding the right player. Still need to fix FileSystemWidget to also use the Helper::function. It's a simple copy & paste from there. 2. added function SeriesTreeModel::findSortedMovies. It returns a QFileInfoList sorted by seriespart and fileno.
-rw-r--r--archivetreeview.cpp28
-rw-r--r--archivetreeview.h1
-rw-r--r--helper.cpp25
-rw-r--r--helper.h4
-rw-r--r--seriestreemodel.cpp17
-rw-r--r--seriestreemodel.h2
-rw-r--r--seriestreewidget.cpp4
-rw-r--r--seriestreewidget.h1
8 files changed, 82 insertions, 0 deletions
diff --git a/archivetreeview.cpp b/archivetreeview.cpp
index d77f8e3..ec58fb4 100644
--- a/archivetreeview.cpp
+++ b/archivetreeview.cpp
@@ -12,6 +12,10 @@
#include <QItemSelectionModel>
#include <QAbstractItemModel>
#include <QItemSelection>
+#include <QFileInfoList>
+#include <QSettings>
+#include <QHash>
+#include <QProcess>
#include "archivetreeview.h"
#include "smmodelsingleton.h"
@@ -22,6 +26,7 @@
#include "seriestreemodel.h"
#include "mappingtablewidget.h"
#include "mappingtablemodel.h"
+#include "helper.h"
ArchiveTreeView::ArchiveTreeView(QWidget *parent) : QWidget(parent){
// models
@@ -32,6 +37,7 @@ ArchiveTreeView::ArchiveTreeView(QWidget *parent) : QWidget(parent){
mSeriesWidget = new SeriesTreeWidget;
QItemSelectionModel *selModel = mSeriesWidget->seriesTree()->selectionModel();
connect(selModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(currentChanged(QItemSelection,QItemSelection)));
+ connect(mSeriesWidget->seriesTree(), SIGNAL(doubleClicked(QModelIndex)), this, SLOT(playSelected()));
mSeriesModel = static_cast<SeriesTreeModel*>(SmModelSingleton::instance()->model("SeriesModel"));
// files view
@@ -130,3 +136,25 @@ void ArchiveTreeView::setMappingItems(QList<int>seriesPartIds, MappingTableModel
widget->setCurrentId(-1);
}
}
+
+void ArchiveTreeView::playSelected(){
+ QModelIndexList selected = mSeriesWidget->seriesTree()->selectionModel()->selectedRows();
+ if(selected.isEmpty()){
+ return;
+ }
+ QStringList files;
+ foreach(QModelIndex idx, selected){
+ QModelIndex real = mSeriesWidget->mapToSource(idx);
+ QFileInfoList movies = mSeriesModel->findSortedMovies(real);
+ foreach(QFileInfo fi, movies){
+ if(!files.contains(fi.absoluteFilePath())){
+ files << fi.absoluteFilePath();
+ }
+ }
+ }
+ QPair<QString, QStringList> progData = Helper::programData("movieviewer");
+ QString program = progData.first;
+ QStringList args = progData.second;
+ args << files;
+ QProcess::startDetached(program, args);
+}
diff --git a/archivetreeview.h b/archivetreeview.h
index 13dc88a..b978791 100644
--- a/archivetreeview.h
+++ b/archivetreeview.h
@@ -32,6 +32,7 @@ class ArchiveTreeView : public QWidget
private slots:
void currentChanged(const QItemSelection &selected, const QItemSelection &deselected);
void setMappingItems(const QList<int> seriesPartIds, MappingTableModel *model, MappingTableWidget *widget);
+ void playSelected();
private:
//widgets
diff --git a/helper.cpp b/helper.cpp
index d03c383..7b49695 100644
--- a/helper.cpp
+++ b/helper.cpp
@@ -11,6 +11,8 @@
#include <QFile>
#include <QSettings>
#include <QCryptographicHash>
+#include <QHash>
+#include <QSettings>
#include "helper.h"
@@ -117,6 +119,29 @@ namespace Helper {
return retval;
}
+ QPair<QString, QStringList> programData(const QString &prefix, const QString &preferred){
+ QSettings s;
+ QString section = QString("programs_%1").arg(prefix);
+ QHash<QString, QVariant> data = s.value(QString("%1/data").arg(section)).toHash();
+ if(data.isEmpty()){
+ return QPair<QString, QStringList>();
+ }
+ QHash<QString, QVariant> programData;
+ if(!preferred.isEmpty()){
+ if(data.keys().contains(preferred)){
+ programData = data.value(preferred).toHash();
+ return qMakePair(programData.value("path").toString(), programData.value("args").toStringList());
+ }
+ return QPair<QString, QStringList>();
+ }
+ QString defaultProg = s.value(QString("%1/default").arg(section)).toString();
+ if(defaultProg.isEmpty()){
+ return QPair<QString, QStringList>();
+ }
+ programData = data.value(defaultProg).toHash();
+ return qMakePair(programData.value("path").toString(), programData.value("args").toStringList());
+ }
+
bool StringListContains::operator()(const QString s, const QString &part) const {
return s.contains(part);
}
diff --git a/helper.h b/helper.h
index 90a1ad6..62919bb 100644
--- a/helper.h
+++ b/helper.h
@@ -8,6 +8,9 @@
#ifndef HELPER_H
#define HELPER_H
+#include <QPair>
+#include <QStringList>
+
#include <magic.h>
class QString;
@@ -19,6 +22,7 @@ namespace Helper {
const QString moveToArchive(const QString &path, const QString &md5);
bool removeFromArchive(const QString &filename, const QString &md5);
const QString createArchivePath(const QString &path, const QString &md5, bool withMd5 = false);
+ QPair<QString, QStringList> programData(const QString &prefix, const QString &preferred = QString());
class StringListContains : public std::binary_function<QString, QString, bool> {
public:
bool operator()(const QString s, const QString &part) const;
diff --git a/seriestreemodel.cpp b/seriestreemodel.cpp
index 2cda1d0..aa35731 100644
--- a/seriestreemodel.cpp
+++ b/seriestreemodel.cpp
@@ -34,6 +34,8 @@ SeriesTreeModel::SeriesTreeModel(QStringList &headers, QObject *parent) : SmTree
mSeriesFilesQuery->prepare("SELECT files.tfilename, files.cmd5sum FROM series, seriesparts, files WHERE series.iseries_id = :id AND series.iseries_id = seriesparts.iseries_id AND seriesparts.iseriesparts_id = files.iseriespart_id");
mSeriesPartFilesQuery = new QSqlQuery(mDb);
mSeriesPartFilesQuery->prepare("SELECT files.tfilename, files.cmd5sum FROM seriesparts, files WHERE seriesparts.iseriesparts_id = :id AND seriesparts.iseriesparts_id = files.iseriespart_id");
+ mSortedMovieListQuery = new QSqlQuery(mDb);
+ mSortedMovieListQuery->prepare("SELECT files.tfilename, files.cmd5sum FROM series, seriesparts, files WHERE series.iseries_id = :id AND seriesparts.iseries_id = series.iseries_id AND seriesparts.iseriesparts_id = files.iseriespart_id AND files.sifiletype = 1 ORDER BY seriesparts.iseriespart, files.sifileno");
populate();
}
@@ -212,6 +214,21 @@ QFileInfoList SeriesTreeModel::findMovies(const QModelIndexList &from) const{
return retval;
}
+QFileInfoList SeriesTreeModel::findSortedMovies(const QModelIndex &from) const{
+ if(!from.isValid()){
+ return QFileInfoList();
+ }
+ QFileInfoList retval;
+ int seriesPartId = from.data(SeriesPartIdRole).toInt();
+ mSortedMovieListQuery->bindValue(":id", seriesPartId);
+ if(mSortedMovieListQuery->exec()){
+ while(mSortedMovieListQuery->next()){
+ QString path = Helper::createArchivePath(mSortedMovieListQuery->value(0).toString(), mSortedMovieListQuery->value(1).toString());
+ retval << QFileInfo(path);
+ }
+ }
+ return retval;
+}
bool SeriesTreeModel::deleteFromSeries(const QModelIndex &what){
int nodeType = what.data(TypeRole).toInt();
diff --git a/seriestreemodel.h b/seriestreemodel.h
index 67be97c..81c6d6a 100644
--- a/seriestreemodel.h
+++ b/seriestreemodel.h
@@ -35,6 +35,7 @@ class SeriesTreeModel : public SmTreeModel {
QModelIndex findValue(const QVariant &value, const QModelIndex &parent = QModelIndex(), int column = 0) const;
QFileInfoList findFiles(const QModelIndex &where) const;
QFileInfoList findMovies(const QModelIndexList &from) const;
+ QFileInfoList findSortedMovies(const QModelIndex &from) const;
//delete
bool deleteFromSeries(const QModelIndex &what);
@@ -56,6 +57,7 @@ class SeriesTreeModel : public SmTreeModel {
QSqlQuery *mSeriesInsertQuery;
QSqlQuery *mSeriesFilesQuery;
QSqlQuery *mSeriesPartFilesQuery;
+ QSqlQuery *mSortedMovieListQuery;
};
#endif // SERIESTREEMODEL_H
diff --git a/seriestreewidget.cpp b/seriestreewidget.cpp
index a8e13d4..fdc9770 100644
--- a/seriestreewidget.cpp
+++ b/seriestreewidget.cpp
@@ -68,6 +68,10 @@ QModelIndexList SeriesTreeWidget::mapToSource(const QModelIndexList &indexes) co
return retval;
}
+QModelIndex SeriesTreeWidget::mapToSource(const QModelIndex &index) const{
+ return mProxy->mapToSource(index);
+}
+
void SeriesTreeWidget::newSeries(){
QList<QVariant> data;
data << tr("<New series>") << QVariant() << QVariant() << QVariant() << SeriesTreeModel::NewSeries;
diff --git a/seriestreewidget.h b/seriestreewidget.h
index bfeedf6..0db8873 100644
--- a/seriestreewidget.h
+++ b/seriestreewidget.h
@@ -25,6 +25,7 @@ class SeriesTreeWidget : public QWidget {
explicit SeriesTreeWidget(QWidget *parent = 0);
SeriesTreeView *seriesTree() { return mView; }
QModelIndexList mapToSource(const QModelIndexList &indexes) const;
+ QModelIndex mapToSource(const QModelIndex &index) const;
public slots:
void newSeries();