1 /*
2    Drawpile - a collaborative drawing program.
3 
4    Copyright (C) 2015-2019 Calle Laakkonen
5 
6    Drawpile is free software: you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation, either version 3 of the License, or
9    (at your option) any later version.
10 
11    Drawpile is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15 
16    You should have received a copy of the GNU General Public License
17    along with Drawpile.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 #ifndef LISTSERVERMODEL_H
20 #define LISTSERVERMODEL_H
21 
22 #include <QAbstractListModel>
23 #include <QIcon>
24 
25 namespace sessionlisting {
26 
27 struct ListServer {
28 	QIcon icon;
29 	QString iconName;
30 	QString name;
31 	QString url;
32 	QString description;
33 	bool readonly;
34 	bool publicListings;
35 	bool privateListings;
36 };
37 
38 class ListServerModel : public QAbstractListModel
39 {
40 	Q_OBJECT
41 public:
42 	enum ListServeroles {
43 		UrlRole = Qt::UserRole,
44 		DescriptionRole,
45 		PublicListRole,
46 		PrivateListRole
47 	};
48 
49 	explicit ListServerModel(bool includeReadOnly, QObject *parent=nullptr);
50 
51 	int rowCount(const QModelIndex &parent=QModelIndex()) const override;
52 	QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override;
53 
54 	bool removeRows(int row, int count, const QModelIndex &parent) override;
55 	bool moveRow(const QModelIndex &sourceParent, int sourceRow, const QModelIndex &destinationParent, int destinationChild);
56 
57 	/**
58 	 * @brief Add a new server to the list
59 	 * @return false if an existing item was updated instead of added
60 	 */
61 	bool addServer(const QString &name, const QString &url, const QString &description, bool readonly, bool pub, bool priv);
62 
63 	/**
64 	 * @brief Remove the server with the given URL
65 	 * @return false if no such server was found
66 	 */
67 	bool removeServer(const QString &url);
68 
69 	//!  Set the favicon for the server with the given URL
70 	void setFavicon(const QString &url, const QImage &icon);
71 
72 	//! Get all configured list servers
73 	static QVector<ListServer> listServers(bool includeReadOnly);
74 
75 	//! Load server list from the settings file
76 	void loadServers(bool includeReadOnly);
77 
78 	//! Save (modified) server list. This replaces the existing list
79 	void saveServers() const;
80 
81 private:
82 	QVector<ListServer> m_servers;
83 };
84 
85 }
86 
87 #endif // LISTSERVERMODEL_H
88