summaryrefslogtreecommitdiffstats
path: root/filestreemodel.h
blob: 0ff7043859c3f25119fba82ce944da16fdacb28d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
  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 FILESTREEMODEL_H
#define FILESTREEMODEL_H

#include <QSqlDatabase>
#include <QList>
#include <QHash>
#include <QMap>
#include <QColor>
#include <QIcon>

#include "smtreemodel.h"

class QSqlQuery;
class SeriesTreeModel;

class FilesTreeModel : public SmTreeModel {
	Q_OBJECT
	public:
		enum CustomRoles { FileNameRole = Qt::UserRole + 1, FullPathRole = Qt::UserRole + 2, SizeRole = Qt::UserRole + 3, DvdNoRole = Qt::UserRole + 4,  SizeDisplayRole = Qt::UserRole + 5, FileTypeRole = Qt::UserRole + 6, Md5SumRole = Qt::UserRole + 7, PartNoRole = Qt::UserRole + 8, SeriesPartIdRole = Qt::UserRole + 9, QualityRole = Qt::UserRole + 10, FilesIdRole = Qt::UserRole + 11, SeriesPartRole = Qt::UserRole + 12, DisplayNameRole = Qt::UserRole + 13, SizeDurationRole = Qt::UserRole + 14, SeriesNameRole = Qt::UserRole + 15, FavoriteRole = Qt::UserRole + 16 };
		enum FileTypes { Movie = 1, FrontCover = 2, BackCover = 3, GeneralCover = 4 };
		enum Fields { FileName = 0, PartNo = 1, SizeDisplay = 2, Quality = 3, DvdNo = 4, FullPath = 5, Size = 6, FileType = 7, Md5Sum = 8, SeriesPartId = 9, FilesId = 10, SeriesPart = 11, DisplayName = 12, SizeDuration = 13, SeriesName = 14, Favorite = 15 };
		explicit FilesTreeModel(QStringList &headers, QObject *parent = 0);
		const QHash<int, QString> fileTypes() const { return mFileTypes; }
		const QHash<int, QString> coverTypes() const { return mCoverTypes; }
		const QHash<QString, int> editableColumns() const { return mEditableColumns; }
		int mode() const { return mMode; }
		~FilesTreeModel();

		//data + flags
		void setIds(const QList<int> &seriesPartIds);
		void setMode(int mode) { mMode = mode; }
		QVariant data(const QModelIndex &index, int role) const;
		bool setData(const QModelIndex &index, const QVariant &value, int role);
		Qt::ItemFlags flags(const QModelIndex &index) const;
		QHash<QString, QString> filesBySeriesPartId(int seriesPartId) const;
		QList<QMap<QString, QString> > streamInfo(const QModelIndex &idx) const;
		QList<QMap<QString, QString> > streamInfo(const QString &path) const;
		QMap<QString, QString> pictureInfo(const QString &path) const;
		QMap<QString, QString> pictureInfo(const QModelIndex &idx) const;
		QMap<QString, QString> pictureMetaInfo(const QModelIndex &idx);
		int fileType(const QString &md5sum) const;
		QModelIndexList fileSizeLessThan(quint64 size, quint16 limit = 1) const;

		//file manipulation
		bool addFile(const QString &fullPath, int type, int quality, int filePart, int seriesPartId, int dvd = -1);
		bool deleteFile(const QModelIndex &file);
		bool deleteFiles(const QModelIndexList &files);

		//misc
		void readCache();
		void writeCache();

	public slots:
		void readSettings();

	private:
		//functions
		void populate(QSqlQuery &filesQuery);

		//database
		QSqlDatabase mDb;
		QSqlQuery *mUpdateDvdQuery;
		QSqlQuery *mUpdateQualityQuery;
		QSqlQuery *mUpdatePartNoQuery;
		QSqlQuery *mUpdateFileTypeQuery;
		QSqlQuery *mInsertFileQuery;
		QSqlQuery *mFilesQuery;
		QSqlQuery *mDeleteFileQuery;
		QSqlQuery *mFileTypeQuery;
		QString mFileSizeLessThanQueryTemplate;

		//misc
		QHash<int, QString> mFileTypes;
		QHash<int, QString> mCoverTypes;
		QHash<QString, QString> mPicsDurationCache;
		QHash<QString, int> mEditableColumns;
		SeriesTreeModel *mSeriesModel;
		int mMode;
		const int mMagic;
		QColor mLocalColor;
		QColor mArchivedColor;
		QColor mFavoriteColor;
		qint64 mDvdSize;
};

#endif // FILESTREEMODEL_H