summaryrefslogtreecommitdiffstats
path: root/seriestreemodel.h
blob: 67be97c16b020be65872fee15c5623a427947fb0 (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
/*
  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 SERIESTREEMODEL_H
#define SERIESTREEMODEL_H

#include <QSqlDatabase>
#include <QFileInfoList>
#include <QList>

#include "smtreemodel.h"

class QSqlQuery;

class SeriesTreeModel : public SmTreeModel {
	Q_OBJECT
	public:
		enum CustomRoles { NameRole = Qt::UserRole + 1, SeriesIdRole = Qt::UserRole + 2, SeriesPartIdRole = Qt::UserRole + 3, SeriesPartRole = Qt::UserRole + 4, TypeRole = Qt::UserRole + 5 };
		enum Fields { Name = 0, SeriesId = 1, SeriesPartId = 2, SeriesPart = 3, Type = 4 };
		enum Types { Series, Part, NewSeries };
		explicit SeriesTreeModel(QStringList &headers, QObject *parent = 0);
		~SeriesTreeModel();

		//data + flags
		Qt::ItemFlags flags(const QModelIndex &index) const;
		QVariant data(const QModelIndex &index, int role) const;
		bool setData(const QModelIndex &index, const QVariant &value, int role);
		QList<QVariant> childrenColumnList(const QModelIndex &parent, int column) const;

		//find
		QModelIndex findValue(const QVariant &value, const QModelIndex &parent = QModelIndex(), int column = 0) const;
		QFileInfoList findFiles(const QModelIndex &where) const;
		QFileInfoList findMovies(const QModelIndexList &from) const;

		//delete
		bool deleteFromSeries(const QModelIndex &what);

	signals:
		void needResort();

	private:
		void populate();
		bool mergeSeries(const QModelIndex &from, const QModelIndex &to);
		bool renameSeries(const QModelIndex &source, const QVariant &value);
		bool setNewSeries(const QModelIndex &source, const QVariant &value);
		QSqlDatabase mDb;
		QSqlQuery *mSeriesPartsQuery;
		QSqlQuery *mUpdateSeriesIdQuery;
		QSqlQuery *mUpdateSeriesNameQuery;
		QSqlQuery *mDeleteSeriesQuery;
		QSqlQuery *mDeleteSeriesPartQuery;
		QSqlQuery *mSeriesInsertQuery;
		QSqlQuery *mSeriesFilesQuery;
		QSqlQuery *mSeriesPartFilesQuery;
};

#endif // SERIESTREEMODEL_H