diff options
author | Arno <am@disconnect.de> | 2014-02-06 18:53:53 +0100 |
---|---|---|
committer | Arno <am@disconnect.de> | 2014-02-06 18:53:53 +0100 |
commit | e0b8f04b18ababa819e2e0f019c76dcca971b51a (patch) | |
tree | 58a1b0143fc6f06111cf21717fa9b43f932114cd /archivebrowsermodel.cpp | |
parent | e07de4e0a1bd56aab8f4ee81d6db252e442c3d7a (diff) | |
download | SheMov-e0b8f04b18ababa819e2e0f019c76dcca971b51a.tar.gz SheMov-e0b8f04b18ababa819e2e0f019c76dcca971b51a.tar.bz2 SheMov-e0b8f04b18ababa819e2e0f019c76dcca971b51a.zip |
First version of Archive Browser
First try to reimplement "Move to archive" in another way.
Implement an archive browser showing only Series with local parts in
another tab. This part works for now :)
Diffstat (limited to 'archivebrowsermodel.cpp')
-rw-r--r-- | archivebrowsermodel.cpp | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/archivebrowsermodel.cpp b/archivebrowsermodel.cpp new file mode 100644 index 0000000..26dc438 --- /dev/null +++ b/archivebrowsermodel.cpp @@ -0,0 +1,120 @@ +/* + 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 <QSqlQuery> + +#include "archivebrowsermodel.h" +#include "smtreeitem.h" +#include "helper.h" + +ArchiveBrowserModel::ArchiveBrowserModel(const QStringList &headers, QObject *parent) : SmTreeModel(headers, parent), mNumFields(7) { + mDb = QSqlDatabase::database("treedb"); + populate(); +} + +QVariant ArchiveBrowserModel::data(const QModelIndex &index, int role) const { + SmTreeItem *item = itemAt(index); + int col = index.column(); + if(role == Qt::DisplayRole && index.column() == 0){ + return item->data(Name); + } + if(role == NameRole){ + return item->data(Name); + } + if(role == GenericIdRole){ + return item->data(GenericId); + } + if(role == NodeTypeRole){ + return item->data(NodeType); + } + if(role == TotalSizeRole){ + return item->data(TotalSize); + } + if(role == QualityRole){ + return item->data(Quality); + } + if(role == FileTypeRole){ + return item->data(FileType); + } + if(role == FullPathRole){ + return item->data(FullPath); + } + if(role == Qt::ForegroundRole){ + if(col == TotalSize){ + qint64 s = item->data(TotalSize).toDouble(); + QColor retval = Qt::green; + if(s > Q_INT64_C(1024 * 1024 * 1024 * 2)){ + retval = Qt::cyan; + } + if(s > Q_INT64_C(1024 * 1024 * 1024 * 4)){ + retval = Qt::red; + } + return retval; + } + if(col == Quality){ + int q = item->data(Quality).toInt(); + QColor retval = Qt::green; + if(q < 8){ + retval = Qt::red; + } + return retval; + } + } + if(role == Qt::TextAlignmentRole){ + if(col == TotalSize || col == Quality){ + int retval = Qt::AlignRight | Qt::AlignVCenter; + return retval; + } + } + return SmTreeModel::data(index, role); +} + +Qt::ItemFlags ArchiveBrowserModel::flags(const QModelIndex &index) const{ + SmTreeItem *item = itemAt(index); + int nt = item->data(NodeType).toInt(); + if(nt == FileNode){ + return Qt::ItemIsEnabled; + } + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + +void ArchiveBrowserModel::populate(){ + SmTreeItem *rootItem = new SmTreeItem(mNumFields); + QSqlQuery localFilesQ(mDb); + localFilesQ.prepare("SELECT tfilename, bisize, sifiletype, siquality, cmd5sum FROM files WHERE iseriespart_id = :sid ORDER BY sifiletype"); + QSqlQuery localQ = QSqlQuery("SELECT DISTINCT(series.iseries_id), tseries_name, seriesparts.iseriespart, seriesparts.tsubtitle, seriesparts.iseriesparts_id FROM series LEFT JOIN seriesparts ON series.iseries_id = seriesparts.iseries_id LEFT JOIN files ON seriesparts.iseriesparts_id = files.iseriespart_id WHERE files.sifiletype = 1 AND files.idvd < 1 ORDER BY tseries_name ASC", mDb); + while(localQ.next()){ + QList<QVariant> serPartData; + QString name; + if(localQ.value(2).toInt() > 0){ + name = QString("%1 %2").arg(localQ.value(1).toString()).arg(QString::number(localQ.value(2).toInt())); + }else{ + name = QString("%1 - %2").arg(localQ.value(1).toString()).arg(localQ.value(3).toString()); + } + serPartData << name << localQ.value(4) << SeriesPartNode << QVariant() << QVariant() << QVariant() << QString(); + SmTreeItem *seriesItem = new SmTreeItem(serPartData, rootItem); + rootItem->appendChild(seriesItem); + localFilesQ.bindValue(":sid", localQ.value(4)); + localFilesQ.exec(); + qint64 totalSize = 0; + int quality = -1; + while(localFilesQ.next()){ + QList<QVariant> fileData; + fileData << localFilesQ.value(0) << QVariant() << FileNode << localFilesQ.value(1) << localFilesQ.value(3) << localFilesQ.value(2) << Helper::createArchivePath(localFilesQ.value(0).toString(), localFilesQ.value(4).toString()); + totalSize += localFilesQ.value(1).toDouble(); + if(localFilesQ.value(2) == 1){ //this is a movie file, no need for another enum + quality = localFilesQ.value(3).toInt(); + } + SmTreeItem *fileItem = new SmTreeItem(fileData, seriesItem); + seriesItem->appendChild(fileItem); + } + seriesItem->setData(Quality, quality); + seriesItem->setData(TotalSize, totalSize); + } + setRoot(rootItem); +} |