Warning, file /network/krdc/remotedesktopsmodel.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2008 Urs Wolfer <uwolfer@kde.org> 0003 SPDX-FileCopyrightText: 2009 Tony Murray <murraytony@gmail.com> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef REMOTEDESKTOPSMODEL_H 0009 #define REMOTEDESKTOPSMODEL_H 0010 0011 #include "bookmarkmanager.h" 0012 0013 #include <QAbstractTableModel> 0014 #include <QDateTime> 0015 0016 #ifdef BUILD_ZEROCONF 0017 namespace KDNSSD { 0018 class ServiceBrowser; 0019 } 0020 #endif 0021 0022 struct RemoteDesktop { 0023 public: 0024 enum Source { None = 0x0, Bookmarks = 0x1, History = 0x2, Zeroconf = 0x4 }; 0025 Q_DECLARE_FLAGS(Sources, Source) 0026 QString title; 0027 QString url; 0028 QDateTime lastConnected; 0029 QDateTime created; 0030 int visits; 0031 RemoteDesktop::Source source; 0032 bool favorite; 0033 bool operator<(const RemoteDesktop &rd) const { 0034 if (lastConnected == rd.lastConnected) 0035 return url < rd.url; 0036 return rd.lastConnected < lastConnected; // seems backward but gets the desired result 0037 } 0038 bool operator==(const RemoteDesktop &rd) const { 0039 return url == rd.url; 0040 } 0041 }; 0042 0043 class RemoteDesktopsModel : public QAbstractTableModel 0044 { 0045 Q_OBJECT 0046 0047 public: 0048 explicit RemoteDesktopsModel(QObject *parent, KBookmarkManager *manager); 0049 ~RemoteDesktopsModel() override; 0050 0051 enum DisplayItems { Favorite, Title, LastConnected, VisitCount, Created, Source }; 0052 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0053 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 0054 Qt::ItemFlags flags(const QModelIndex &index) const override; 0055 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; 0056 QVariant data(const QModelIndex &index, int role) const override; 0057 QVariant headerData(int section, Qt::Orientation orientation, 0058 int role = Qt::DisplayRole) const override; 0059 0060 private: 0061 QList<RemoteDesktop> remoteDesktops; 0062 QString getLastConnectedString(QDateTime lastConnected, bool fuzzy = false) const; 0063 void removeAllItemsFromSources(RemoteDesktop::Sources sources); 0064 void buildModelFromBookmarkGroup(const KBookmarkGroup &group); 0065 KBookmarkManager *m_manager; 0066 0067 #ifdef BUILD_ZEROCONF 0068 KDNSSD::ServiceBrowser *zeroconfBrowser; 0069 QHash<QString, QString> m_protocols; 0070 #endif 0071 0072 private Q_SLOTS: 0073 void bookmarksChanged(); 0074 #ifdef BUILD_ZEROCONF 0075 void servicesChanged(); 0076 #endif 0077 }; 0078 0079 Q_DECLARE_OPERATORS_FOR_FLAGS(RemoteDesktop::Sources) 0080 0081 #endif