summaryrefslogtreecommitdiffstats
path: root/seriesmetadatamodel.h
blob: 06f8cc75b9aaded9ebce4ee3faa6c94c73edca36 (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
/*
  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 SERIESMETADATAMODEL_H
#define SERIESMETADATAMODEL_H

#include <QSqlDatabase>
#include <QHash>
#include <QWidget>

class QSqlQuery;
class QSpinBox;
class QComboBox;
class QLineEdit;
class QPlainTextEdit;
class QDateEdit;

#include "smtreemodel.h"

class SeriesMetadataModel : public SmTreeModel {
    Q_OBJECT
	public:
		enum CumstomRoles { SeriesPartIdRole = Qt::UserRole + 1, ReleaseYearRole = Qt::UserRole + 2, SourceMediumRole = Qt::UserRole + 3, SubjectRole = Qt::UserRole + 4, ReleaseGroupRole = Qt::UserRole + 5, EncoderOptsRole = Qt::UserRole + 6, CommentRole = Qt::UserRole + 7, PassesRole = Qt::UserRole + 8, AddedRole = Qt::UserRole + 9 };
		enum Fields { SeriesPartId = 0, ReleaseYear = 1, SourceMedium = 2, Subject = 3, ReleaseGroup = 4, EncoderOpts = 5, Comment = 6, Passes = 7, Added = 8 };
		explicit SeriesMetadataModel(const QStringList &headers, QObject *parent = 0);
		virtual ~SeriesMetadataModel();

		//data
		int currentId() const { return mCurrentId; }
		virtual QVariant data(const QModelIndex &index, int role) const;
		const QList<QVariant> dataList(const QModelIndex &index) const;
		const QList<QVariant> fieldList(int field, bool distinct = true) const;
		virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
		virtual bool setData(const QModelIndex &parent, const QVariant &value, int row, int column, int role = Qt::EditRole);

		//misc
		bool hasRecord(int seriesPartId) const;

	public slots:
		void populate(int seriesPartId);
		void update();

	private:
		const int mColumns;
		bool mDataChanged;
		int mCurrentId;
		QSqlDatabase mDb;
		QSqlQuery *mPopulateQuery;
		QSqlQuery *mPresentQuery;
		QSqlQuery *mUpdateQuery;
		QSqlQuery *mInsertQuery;
		QHash<int, QString> mColumnNames;
};

class MetadataWidget : public QWidget {
	Q_OBJECT
	public:
		explicit MetadataWidget(QWidget *parent = 0, Qt::WindowFlags f = 0);
		virtual ~MetadataWidget() {}

	public slots:
		void setSeriesPartId(int id);
		void accept();

	private:
		QSpinBox *mReleaseYear;
		QComboBox *mSourceMedium;
		QComboBox *mReleaseGroup;
		QLineEdit *mSubject;
		QLineEdit *mEncoderOpts;
		QSpinBox *mPasses;
		QPlainTextEdit *mComment;
		QDateEdit *mAdded;
		SeriesMetadataModel *mModel;
};

#endif // SERIESMETADATAMODEL_H