summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2014-02-06 18:53:53 +0100
committerArno <am@disconnect.de>2014-02-06 18:53:53 +0100
commite0b8f04b18ababa819e2e0f019c76dcca971b51a (patch)
tree58a1b0143fc6f06111cf21717fa9b43f932114cd
parente07de4e0a1bd56aab8f4ee81d6db252e442c3d7a (diff)
downloadSheMov-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 :)
-rw-r--r--archivebrowser.cpp35
-rw-r--r--archivebrowser.h34
-rw-r--r--archivebrowsermodel.cpp120
-rw-r--r--archivebrowsermodel.h31
-rw-r--r--archiveview.cpp1
-rw-r--r--shemov.cpp7
-rw-r--r--shemov.h2
-rw-r--r--shemov.pro8
-rw-r--r--smglobals.cpp5
9 files changed, 241 insertions, 2 deletions
diff --git a/archivebrowser.cpp b/archivebrowser.cpp
new file mode 100644
index 0000000..5eda9d6
--- /dev/null
+++ b/archivebrowser.cpp
@@ -0,0 +1,35 @@
+/*
+ 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 <QVBoxLayout>
+#include <QSortFilterProxyModel>
+
+#include "archivebrowser.h"
+#include "archivebrowsermodel.h"
+#include "smtreeview.h"
+#include "smglobals.h"
+#include "delegates.h"
+
+ArchiveBrowser::ArchiveBrowser(QWidget *parent) : QWidget(parent){
+ //prep
+ mModel = static_cast<ArchiveBrowserModel*>(SmGlobals::instance()->model("BrowserModel"));
+ mProxy = new QSortFilterProxyModel;
+ mProxy->setSourceModel(mModel);
+ mTree = new SmTreeView;
+ mTree->setModel(mProxy);
+ mTree->setColumnHidden(ArchiveBrowserModel::GenericId, true);
+ mTree->setColumnHidden(ArchiveBrowserModel::NodeType, true);
+ mTree->setSortingEnabled(true);
+ mTree->setItemDelegateForColumn(ArchiveBrowserModel::TotalSize, new SizeDelegate(this));
+ mTree->setItemDelegateForColumn(ArchiveBrowserModel::FileType, new FileTypeDelegate(this));
+ mTree->setSelectionMode(QAbstractItemView::ExtendedSelection);
+
+ //make widget
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(mTree);
+ setLayout(mainLayout);
+}
diff --git a/archivebrowser.h b/archivebrowser.h
new file mode 100644
index 0000000..cd43415
--- /dev/null
+++ b/archivebrowser.h
@@ -0,0 +1,34 @@
+/*
+ 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.
+*/
+
+#ifndef ARCHIVEBROWSER_H
+#define ARCHIVEBROWSER_H
+
+#include <QWidget>
+
+#include "smtreeview.h"
+
+class ArchiveBrowserModel;
+class SmTreeView;
+class QSortFilterProxyModel;
+
+class ArchiveBrowser : public QWidget {
+ Q_OBJECT
+ public:
+ explicit ArchiveBrowser(QWidget *parent = 0);
+
+ signals:
+
+ public slots:
+
+ private:
+ SmTreeView *mTree;
+ ArchiveBrowserModel *mModel;
+ QSortFilterProxyModel *mProxy;
+};
+
+#endif // ARCHIVEBROWSER_H
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);
+}
diff --git a/archivebrowsermodel.h b/archivebrowsermodel.h
new file mode 100644
index 0000000..3b7fc14
--- /dev/null
+++ b/archivebrowsermodel.h
@@ -0,0 +1,31 @@
+/*
+ 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.
+*/
+
+#ifndef ARCHIVEBROWSERMODEL_H
+#define ARCHIVEBROWSERMODEL_H
+
+#include <QSqlDatabase>
+
+#include "smtreemodel.h"
+
+class ArchiveBrowserModel : public SmTreeModel {
+ Q_OBJECT
+ public:
+ enum CustomRoles { NameRole = Qt::UserRole + 1, GenericIdRole = Qt::UserRole + 2, NodeTypeRole = Qt::UserRole + 3, TotalSizeRole = Qt::UserRole + 4, QualityRole = 5, FileTypeRole = Qt::UserRole + 6, FullPathRole = Qt::UserRole + 7 };
+ enum Fields { Name = 0, GenericId = 1, NodeType = 2, TotalSize = 3, Quality = 4, FileType = 5, FullPath = 6 };
+ enum NodeTypes { SeriesPartNode = 1, FileNode = 2 };
+ explicit ArchiveBrowserModel(const QStringList &headers, QObject *parent = 0);
+ virtual QVariant data(const QModelIndex &index, int role) const;
+ virtual Qt::ItemFlags flags(const QModelIndex &index) const;
+
+ private:
+ void populate();
+ int mNumFields;
+ QSqlDatabase mDb;
+};
+
+#endif // ARCHIVEBROWSERMODEL_H
diff --git a/archiveview.cpp b/archiveview.cpp
index b551357..8df9bb6 100644
--- a/archiveview.cpp
+++ b/archiveview.cpp
@@ -31,6 +31,7 @@
#include "delegates.h"
#include "smglobals.h"
#include "helper.h"
+#include "delegates.h"
ArchiveView::ArchiveView(QWidget *parent) : QWidget(parent) {
QSettings s;
diff --git a/shemov.cpp b/shemov.cpp
index 437a38b..cae9ee1 100644
--- a/shemov.cpp
+++ b/shemov.cpp
@@ -35,6 +35,7 @@
#include "smdirmodel.h"
#include "archiveview.h"
#include "archivecontroller.h"
+#include "archivebrowser.h"
SheMov::SheMov(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags), mOpenWithGroupFS(0), mOpenWithGroupAV(0) {
//application icon
@@ -76,6 +77,12 @@ SheMov::SheMov(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, fla
connect(mPicWidget->picView(), SIGNAL(selectedSize(qint64)), this, SLOT(setSize(qint64)));
PictureViewer2 *picViewer = SmGlobals::instance()->pictureViewer();
+ //archivebrower
+ splash.showMessage(tr("Creating Archive Browser..."), Qt::AlignHCenter, Qt::yellow);
+ qApp->processEvents();
+ ArchiveBrowser *mArchiveBrowser = new ArchiveBrowser;
+ mTab->addTab(mArchiveBrowser, tr("Archive Browser"));
+
//newmoviewizard + dbanalyzer + newpicsdialog
splash.showMessage(tr("Creating misc. Dialogs..."), Qt::AlignHCenter, Qt::yellow);
qApp->processEvents();
diff --git a/shemov.h b/shemov.h
index fdbc5a9..58562c0 100644
--- a/shemov.h
+++ b/shemov.h
@@ -21,6 +21,7 @@ class PicturesWidget;
class SmTreeModel;
class NewPicsDialog;
class ArchiveView;
+class ArchiveBrowser;
class SheMov : public QMainWindow {
Q_OBJECT
@@ -187,5 +188,6 @@ class SheMov : public QMainWindow {
NewPicsDialog *mNewPicsDialog;
PicturesWidget *mPicWidget;
ArchiveView *mArchive;
+ ArchiveBrowser *mArchiveBrowser;
};
#endif
diff --git a/shemov.pro b/shemov.pro
index e6c6436..07c6a14 100644
--- a/shemov.pro
+++ b/shemov.pro
@@ -41,7 +41,9 @@ SOURCES = main.cpp \
archivemodel.cpp \
archiveview.cpp \
archivecontroller.cpp \
- delegates.cpp
+ delegates.cpp \
+ archivebrowser.cpp \
+ archivebrowsermodel.cpp
HEADERS = \
filesystemdirproxy.h \
filesystemwidget.h \
@@ -78,6 +80,8 @@ HEADERS = \
archivemodel.h \
archiveview.h \
archivecontroller.h \
- delegates.h
+ delegates.h \
+ archivebrowser.h \
+ archivebrowsermodel.h
LIBS += -lmagic -lXfixes -lX11
RESOURCES = shemov.qrc
diff --git a/smglobals.cpp b/smglobals.cpp
index cd03cc4..58c6d98 100644
--- a/smglobals.cpp
+++ b/smglobals.cpp
@@ -29,6 +29,7 @@
#include "picfilesmodel.h"
#include "configurationdialog.h"
#include "archivecontroller.h"
+#include "archivebrowsermodel.h"
SmGlobals *SmGlobals::mInstance = 0;
@@ -95,6 +96,10 @@ QAbstractItemModel *SmGlobals::model(const QString &which){
QStringList headers = QStringList() << tr("Series") << tr("Series ID") << tr("Series part ID") << tr("Part") << tr("Type") << tr("Favorite") << tr("Subtitle") << tr("Count");
ArchiveModel *model = new ArchiveModel(headers);
mModels.insert(which, model);
+ }else if(which == "BrowserModel"){
+ QStringList headers = QStringList() << tr("Name") << tr("Generic Id") << tr("Node Type") << tr("Size") << tr("Quality") << tr("File Type") << tr("Full Path");
+ ArchiveBrowserModel *model = new ArchiveBrowserModel(headers);
+ mModels.insert(which, model);
}
return mModels.contains(which) ? mModels.value(which) : 0;
}