summaryrefslogtreecommitdiffstats
path: root/archivecontroller.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'archivecontroller.cpp')
-rw-r--r--archivecontroller.cpp142
1 files changed, 141 insertions, 1 deletions
diff --git a/archivecontroller.cpp b/archivecontroller.cpp
index 32528aa..855e1bb 100644
--- a/archivecontroller.cpp
+++ b/archivecontroller.cpp
@@ -5,11 +5,24 @@
2 of the License, or (at your option) any later version.
*/
+#include <QSettings>
+#include <QProcess>
+#include <QFileInfo>
+#include <QMessageBox>
+#include <QInputDialog>
+
#include "archivecontroller.h"
#include "archivemodel.h"
#include "archiveview.h"
+#include "pictureviewer2.h"
+#include "smglobals.h"
+#include "helper.h"
-ArchiveController::ArchiveController(QObject *parent) : QObject(parent) {}
+ArchiveController::ArchiveController(QObject *parent) : QObject(parent) {
+ if(parent){
+ mParentWidget = qobject_cast<QWidget*>(this->parent());
+ }
+}
void ArchiveController::setArchiveView(ArchiveTree *atree, ArchiveProxy *aproxy){
mArchiveTree = atree;
@@ -20,6 +33,7 @@ void ArchiveController::setArchiveView(ArchiveTree *atree, ArchiveProxy *aproxy)
void ArchiveController::setArchiveFiles(ArchiveFiles *afiles, ArchiveFilesProxy *afilesproxy){
mArchiveFiles = afiles;
mArchiveFilesProxy = afilesproxy;
+ mFileSelection = mArchiveFiles->selectionModel();
}
void ArchiveController::setModels(ArchiveModel *amodel, ArchiveFilesModel *afilesmodel){
@@ -29,6 +43,108 @@ void ArchiveController::setModels(ArchiveModel *amodel, ArchiveFilesModel *afile
void ArchiveController::init(){
connect(mArchiveSelection, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(treeSelectionChanged(QItemSelection,QItemSelection)));
+ connect(mArchiveFiles, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(fileDoubleClicked(QModelIndex)));
+}
+
+void ArchiveController::playSelectedFiles(){
+ QModelIndexList sel = mFileSelection->selectedRows();
+ QStringList files;
+ foreach(QModelIndex i, sel){
+ if(i.data(ArchiveFilesModel::FileTypeRole).toInt() == ArchiveFilesModel::Movie){
+ QString fullPath = i.data(ArchiveFilesModel::FullPathRole).toString();
+ QFileInfo fi(fullPath);
+ if(fi.exists()){
+ files << fullPath;
+ }
+ }
+ }
+ if(!files.isEmpty()){
+ QPair<QString, QStringList> playerData = Helper::programData("movieviewer");
+ QStringList args = playerData.second;
+ args << files;
+ QProcess::startDetached(playerData.first, args);
+ }
+}
+
+void ArchiveController::editQuality(){
+ QModelIndexList sel = mFileSelection->selectedRows(ArchiveFilesModel::Quality);
+ if(sel.isEmpty()){
+ return;
+ }
+ bool ok;
+ int quality = QInputDialog::getInt(mParentWidget, tr("Set Quality"), tr("Quality"), 7, 1, 10, 1, &ok);
+ if(ok){
+ foreach(QModelIndex i, sel){
+ QModelIndex real = mArchiveFilesProxy->mapToSource(i);
+ if(mArchiveFilesModel->isMovie(real)){
+ mArchiveFilesModel->setData(real, quality, ArchiveFilesModel::QualityRole);
+ }
+ }
+ }
+}
+
+void ArchiveController::editDvdNo(){
+ QModelIndexList sel = mFileSelection->selectedRows(ArchiveFilesModel::DvdNo);
+ if(sel.isEmpty()){
+ return;
+ }
+ bool ok;
+ int dvdNo = QInputDialog::getInt(mParentWidget, tr("Set DVD no."), tr("Number (-1 for local)"), mArchiveFilesModel->nextDvd(), -1, 1024 * 1024, 1, &ok);
+ if(ok){
+ foreach(QModelIndex i, sel){
+ QModelIndex real = mArchiveFilesProxy->mapToSource(i);
+ if(mArchiveFilesModel->isMovie(real)){
+ mArchiveFilesModel->setData(real, dvdNo, ArchiveFilesModel::DvdNoRole);
+ }
+ }
+ }
+}
+
+void ArchiveController::editFileType(){
+ QModelIndexList sel = mFileSelection->selectedRows(ArchiveFilesModel::FileType);
+ if(sel.isEmpty()){
+ return;
+ }
+ bool ok;
+ QStringList types = QStringList() << tr("Movie") << tr("Front Cover") << tr("Back Cover") << tr("General Cover");
+ QString item = QInputDialog::getItem(mParentWidget, tr("Set file type"), tr("Type:"), types, 0, false, &ok);
+ if(ok && !item.isEmpty()){
+ int newType = 0;
+ if(item == tr("Movie")){
+ newType = ArchiveFilesModel::Movie;
+ }else if(item == tr("Front Cover")){
+ newType = ArchiveFilesModel::FrontCover;
+ }else if(item == tr("Back Cover")){
+ newType = ArchiveFilesModel::BackCover;
+ }else if(item == tr("General Cover")){
+ newType = ArchiveFilesModel::GeneralCover;
+ }
+ if(newType){
+ foreach(QModelIndex i, sel){
+ QModelIndex real = mArchiveFilesProxy->mapToSource(i);
+ mArchiveFilesModel->setData(real, newType, ArchiveFilesModel::FileTypeRole);
+ }
+ mArchiveFilesModel->refresh();
+ mArchiveFiles->expandAll();
+ }
+ }
+}
+
+void ArchiveController::editFileNo(){
+ QModelIndexList sel = mFileSelection->selectedRows(ArchiveFilesModel::FileNumber);
+ if(sel.isEmpty()){
+ return;
+ }
+ bool ok;
+ int fileNo = QInputDialog::getInt(mParentWidget, tr("Set DVD no."), tr("Number (-1 for none)"), -1, -1, 1024 * 1024, 1, &ok);
+ if(ok){
+ foreach(QModelIndex i, sel){
+ QModelIndex real = mArchiveFilesProxy->mapToSource(i);
+ if(mArchiveFilesModel->isMovie(real)){
+ mArchiveFilesModel->setData(real, fileNo, ArchiveFilesModel::FileNumberRole);
+ }
+ }
+ }
}
void ArchiveController::treeSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected){
@@ -46,6 +162,30 @@ void ArchiveController::treeSelectionChanged(const QItemSelection &selected, con
mArchiveFiles->expandAll();
}
+void ArchiveController::fileDoubleClicked(const QModelIndex &idx){
+ if(!idx.isValid()){
+ return;
+ }
+ int type = idx.data(ArchiveFilesModel::FileTypeRole).toInt();
+ if(type == ArchiveFilesModel::Movie){
+ QString fullPath = idx.data(ArchiveFilesModel::FullPathRole).toString();
+ QFileInfo fi(fullPath);
+ if(!fi.exists()){
+ QString msg = QString(tr("%1 not available!")).arg(idx.data(ArchiveFilesModel::FilenameRole).toString());
+ QMessageBox::critical(mParentWidget, tr("Error"), msg);
+ return;
+ }
+ QPair<QString, QStringList> playerData = Helper::programData("movieviewer");
+ QStringList args = playerData.second;
+ args << idx.data(ArchiveFilesModel::FullPathRole).toString();
+ QProcess::startDetached(playerData.first, args);
+ return;
+ }
+ PictureViewer2 *pv = SmGlobals::instance()->pictureViewer();
+ pv->setFile(idx.data(ArchiveFilesModel::FullPathRole).toString());
+ pv->show();
+}
+
QModelIndexList ArchiveController::mapToSource(const QSortFilterProxyModel *proxy, const QModelIndexList idxs) const{
QModelIndexList retval;
foreach(QModelIndex idx, idxs){