1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2008 Urs Wolfer <uwolfer @ kde.org> |
4 | ** Copyright (C) 2009 Tony Murray <murraytony@gmail.com> |
5 | ** |
6 | ** This file is part of KDE. |
7 | ** |
8 | ** This program is free software; you can redistribute it and/or modify |
9 | ** it under the terms of the GNU General Public License as published by |
10 | ** the Free Software Foundation; either version 2 of the License, or |
11 | ** (at your option) any later version. |
12 | ** |
13 | ** This program is distributed in the hope that it will be useful, |
14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | ** GNU General Public License for more details. |
17 | ** |
18 | ** You should have received a copy of the GNU General Public License |
19 | ** along with this program; see the file COPYING. If not, write to |
20 | ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 | ** Boston, MA 02110-1301, USA. |
22 | ** |
23 | ****************************************************************************/ |
24 | |
25 | #ifndef REMOTEDESKTOPSMODEL_H |
26 | #define REMOTEDESKTOPSMODEL_H |
27 | |
28 | #include <QAbstractTableModel> |
29 | #include <KDateTime> |
30 | |
31 | #ifdef BUILD_ZEROCONF |
32 | #include <dnssd/servicebrowser.h> |
33 | #endif |
34 | |
35 | class KBookmarkGroup; |
36 | class KBookmarkManager; |
37 | |
38 | struct RemoteDesktop { |
39 | public: |
40 | enum Source { None = 0x0, Bookmarks = 0x1, History = 0x2, Zeroconf = 0x4 }; |
41 | Q_DECLARE_FLAGS(Sources, Source) |
42 | QString title; |
43 | QString url; |
44 | KDateTime lastConnected; |
45 | KDateTime created; |
46 | int visits; |
47 | RemoteDesktop::Source source; |
48 | bool favorite; |
49 | bool operator<(const RemoteDesktop &rd) const { |
50 | if (lastConnected == rd.lastConnected) |
51 | return url < rd.url; |
52 | return rd.lastConnected < lastConnected; // seems backward but gets the desired result |
53 | } |
54 | bool operator==(const RemoteDesktop &rd) const { |
55 | return url == rd.url; |
56 | } |
57 | }; |
58 | |
59 | class RemoteDesktopsModel : public QAbstractTableModel |
60 | { |
61 | Q_OBJECT |
62 | |
63 | public: |
64 | explicit RemoteDesktopsModel(QObject *parent); |
65 | ~RemoteDesktopsModel(); |
66 | |
67 | enum DisplayItems { Favorite, Title, LastConnected, VisitCount, Created, Source }; |
68 | int rowCount(const QModelIndex &parent = QModelIndex()) const; |
69 | int columnCount(const QModelIndex &parent = QModelIndex()) const; |
70 | Qt::ItemFlags flags(const QModelIndex &index) const; |
71 | bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); |
72 | QVariant data(const QModelIndex &index, int role) const; |
73 | QVariant (int section, Qt::Orientation orientation, |
74 | int role = Qt::DisplayRole) const; |
75 | |
76 | private: |
77 | QList<RemoteDesktop> remoteDesktops; |
78 | QString getLastConnectedString(KDateTime lastConnected, bool fuzzy = false) const; |
79 | void removeAllItemsFromSources(RemoteDesktop::Sources sources); |
80 | void buildModelFromBookmarkGroup(const KBookmarkGroup &group); |
81 | KBookmarkManager *m_manager; |
82 | |
83 | #ifdef BUILD_ZEROCONF |
84 | DNSSD::ServiceBrowser *zeroconfBrowser; |
85 | QHash<QString, QString> m_protocols; |
86 | #endif |
87 | |
88 | private slots: |
89 | void bookmarksChanged(); |
90 | #ifdef BUILD_ZEROCONF |
91 | void servicesChanged(); |
92 | #endif |
93 | }; |
94 | |
95 | Q_DECLARE_OPERATORS_FOR_FLAGS(RemoteDesktop::Sources) |
96 | |
97 | #endif |
98 | |