diff options
author | Arno <am@disconnect.de> | 2010-07-24 17:15:00 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2010-07-24 17:15:00 +0200 |
commit | ad322157891cec53a7b660629d7c244e75df81d5 (patch) | |
tree | 0ffbc54d683f6e8c4925b669bb1732ac52cae0de /smglobals.cpp | |
parent | b465c59cce7418968f268b9888a8236be281fda5 (diff) | |
download | SheMov-ad322157891cec53a7b660629d7c244e75df81d5.tar.gz SheMov-ad322157891cec53a7b660629d7c244e75df81d5.tar.bz2 SheMov-ad322157891cec53a7b660629d7c244e75df81d5.zip |
Act on doubleClick in FileTreeWidget
When doubleclicking a picture in FileTreeWidget the pictureViewer
is shown. Doubleclicking a movie file launches the default movie
player.
Since PictureViewer is now used in FileSystemWidget and
ArchiveTreeView a global instance is needed. The appropriate place
for this is a singleton. Since we already had a singleton for
QAbstractItemModels I renamed it to SmGlobals and added a function
to return a PictureViewer object. Renaming it was quite easy
thanks to QtCreator's ability to rename variable names.
Diffstat (limited to 'smglobals.cpp')
-rw-r--r-- | smglobals.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/smglobals.cpp b/smglobals.cpp new file mode 100644 index 0000000..61530d1 --- /dev/null +++ b/smglobals.cpp @@ -0,0 +1,83 @@ +/* + 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 <QSqlDatabase> +#include <QAbstractItemModel> +#include <QStringList> +#include <QMessageBox> +#include <QSettings> + +#include "smglobals.h" +#include "seriestreemodel.h" +#include "filestreemodel.h" +#include "mappingtablemodel.h" +#include "pictureviewer.h" + +SmGlobals *SmGlobals::mInstance = 0; + +SmGlobals::~SmGlobals(){ + foreach(QAbstractItemModel *model, mModels.values()){ + delete model; + } + QSqlDatabase::removeDatabase("treedb"); +} + +SmGlobals *SmGlobals::instance(){ + if(!mInstance){ + mInstance = new SmGlobals; + if(!QSqlDatabase::contains("treedb")){ + QSettings s; + QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL", "treedb"); + db.setHostName(s.value("database/hostname").toString()); + db.setUserName(s.value("database/dbuser").toString()); + db.setPassword(s.value("database/dbpass").toString()); + db.setDatabaseName(s.value("database/dbname").toString()); + if(!db.open()){ + QMessageBox::critical(0, tr("Error"), tr("Could not open database. Please configure it and restart program.")); + } + } + } + return mInstance; +} + +QAbstractItemModel *SmGlobals::model(const QString &which){ + if(which == "SeriesModel"){ + if(!mModels.contains(which)){ + QStringList headers = QStringList() << tr("Series") << tr("Series ID") << tr("Series part ID") << tr("Part") << tr("Type"); + SeriesTreeModel *model = new SeriesTreeModel(headers); + mModels.insert(which, model); + } + }else if(which == "FilesModel"){ + if(!mModels.contains(which)){ + QStringList headers = QStringList() << tr("Name") << tr("Part") << tr("Size") << tr("Qual.") << tr("Dvd") << tr("Full Path") << tr("Size") << tr("Type") << tr("Md5 sum") << tr("Series part ID") << tr("File ID"); + FilesTreeModel *model = new FilesTreeModel(headers); + mModels.insert(which, model); + } + }else if(which == "actors"){ + if(!mModels.contains(which)){ + QStringList headers = QStringList() << tr("Actor") << tr("Id"); + MappingTableModel *model = new MappingTableModel(headers, "actors"); + mModels.insert(which, model); + } + }else if(which == "genres"){ + if(!mModels.contains(which)){ + QStringList headers = QStringList() << tr("Genre") << tr("Id"); + MappingTableModel *model = new MappingTableModel(headers, "genres"); + mModels.insert(which, model); + } + } + return mModels.contains(which) ? mModels.value(which) : 0; +} + +PictureViewer *SmGlobals::pictureViewer() { + if(!mPictureViewer){ + mPictureViewer = new PictureViewer; + } + return mPictureViewer; +} + +SmGlobals::SmGlobals() : mPictureViewer(0) {} |