summaryrefslogtreecommitdiffstats
path: root/seriestreewidget.h
blob: f68e10c0cab408752687b0c10cc0df0ffa3b2346 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
  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 SERIESTREEWIDGET_H
#define SERIESTREEWIDGET_H

#include <QWidget>
#include <QTreeView>
#include <QSortFilterProxyModel>
#include <QSqlDatabase>
#include <QHash>
#include <QPersistentModelIndex>

#include "smdialog.h"

class QLineEdit;
class QPushButton;
class QSortFilterProxyModel;
class QComboBox;
class QEvent;
class QLabel;
class QCompleter;
class QStringListModel;
class QSqlQuery;
class QThread;
class QCheckBox;
class QSpinBox;
class SeriesTreeModel;
class SeriesTreeView;
class SeriesTreeSortModel;
class HoverWindow;
class FilesTreeModel;
class AddCoverDialog;
class HoverWindow;
class CompleterProducer;

class SeriesTreeWidget : public QWidget {
	Q_OBJECT
	public:
		enum FilterMode { FilterSeries = 1, FilterActor = 2, FilterGenre = 3, FilterSize = 4, FilterQuality = 5, FilterFileName = 6, FilterDvdNo = 7 };
		explicit SeriesTreeWidget(QWidget *parent = 0);
		virtual ~SeriesTreeWidget();
		SeriesTreeView *seriesTree() { return mView; }
		SeriesTreeSortModel *seriesProxy() { return mProxy; }
		int filterMode() const { return mFilterMode; }

	public slots:
		void newSeries();
		void seriesAdded(const QString seriesName, int seriesPart, bool resort = true);
		void toggleFavorite();
		void deleteFromSeries();
		void readSettings();
		void writeSettings();
		void expandCurrent();
		void addCover();
		void setFilterMode(int mode);
		void filter();
		void filterFavorites(bool checked);
		void expandItems(const QStringList &items = QStringList());

	private slots:
		void clearFilter();
		void resort();
		void itemExpanded(const QModelIndex &);
		void itemCollaped(const QModelIndex &);
		void editItem();
		void producerFinished(QStringListModel *model);

	signals:
		void filesReload();

	private:
		QLineEdit *mFilterEdit;
		QPushButton *mFilter;
		QPushButton *mClear;
		SeriesTreeView *mView;
		SeriesTreeSortModel *mProxy;
		SeriesTreeModel *mModel;
		AddCoverDialog *mCoverDialog;
		QStringList mExpandedItems;
		int mFilterMode;
		QCompleter *mFilterCompleter;
		QThread *mCompleterProducerThread;
		CompleterProducer *mCompleterProducer;
		QString mOldFilterText;
};

class SeriesTreeView : public QTreeView {
	Q_OBJECT
	public:
		explicit SeriesTreeView(QWidget *parent = 0);

	public slots:
		void readSettings();

	protected:
		virtual void contextMenuEvent(QContextMenuEvent *e);
		virtual bool event(QEvent *event);

	private:
		bool exitHover(bool exitVal = true);
		QStringList children(const QModelIndex &idx) const;
		QModelIndex mCurHover;
		HoverWindow *mHoverWin;
		bool mHover;
		qint16 mCursorOffset;
};


class SeriesTreeSortModel : public QSortFilterProxyModel {
	Q_OBJECT
	public:
		SeriesTreeSortModel(QObject *parent = 0);
		~SeriesTreeSortModel() {}
		bool acceptedByFilter(int source_row, const QModelIndex &parent) const { return filterAcceptsRow(source_row, parent); }

	protected:
		virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
		virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
};

class AddCoverDialog : public SmDialog {
	Q_OBJECT
	public:
		explicit AddCoverDialog(QWidget *parent = 0, Qt::WindowFlags f = 0);
		const QString file() const;
		int fileType() const { return mCurrentType; }

	private slots:
		void selectFile();
		void typeChanged(const QString &type);

	private:
		QLineEdit *mFile;
		QComboBox *mFileType;
		QPushButton *mSelectFile;
		QPushButton *mOk;
		QPushButton *mCancel;
		QString mLastOpenedDir;
		int mCurrentType;
		FilesTreeModel *mFilesModel;
};

class EditSeriesDialog : public QDialog {
	Q_OBJECT
	public:
		explicit EditSeriesDialog(const QModelIndex &idx, QWidget *parent = 0);

	public slots:
		void accept();

	private slots:
		void hasPartNoStateChanged(int state);

	private:
		QLineEdit *mTitle;
		QLineEdit *mSubtitle;
		QCheckBox *mFavorite;
		QCheckBox *mHasPartNo;
		QSpinBox *mPartNo;
		QPushButton *mOk;
		QPushButton *mCancel;
		const QPersistentModelIndex mIdx;
};

class CompleterProducer : public QObject {
	Q_OBJECT
	public:
		CompleterProducer(int Mode = SeriesTreeWidget::FilterSeries, QObject *parent = 0);
		~CompleterProducer();

	public slots:
		void produce();
		void setMode(int mode) { mMode = mode; }

	signals:
		void done(QStringListModel *model);

	private:
		QStringListModel *mModel;
		int mMode;
		QSqlDatabase mDb;
		QSqlQuery *mSeriesQuery;
		QSqlQuery *mActorsQuery;
		QSqlQuery *mGenresQuery;
		QSqlQuery *mSizeQuery;
		QSqlQuery *mQualityQuery;
		QSqlQuery *mFileNameQuery;
		QSqlQuery *mDvdNoQuery;
		QHash<int, QSqlQuery*> mQueryHash;
};

#endif