-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
remotedesktopsmodel.h
95 lines (81 loc) · 2.45 KB
/
remotedesktopsmodel.h
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
/*
SPDX-FileCopyrightText: 2008 Urs Wolfer <[email protected]>
SPDX-FileCopyrightText: 2009 Tony Murray <[email protected]>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef REMOTEDESKTOPSMODEL_H
#define REMOTEDESKTOPSMODEL_H
#include "bookmarkmanager.h"
#include <QAbstractTableModel>
#include <QDateTime>
#ifdef BUILD_ZEROCONF
namespace KDNSSD
{
class ServiceBrowser;
}
#endif
struct RemoteDesktop {
public:
enum Source {
None = 0x0,
Bookmarks = 0x1,
History = 0x2,
Zeroconf = 0x4
};
Q_DECLARE_FLAGS(Sources, Source)
QString title;
QString url;
QDateTime lastConnected;
QDateTime created;
int visits;
RemoteDesktop::Source source;
bool favorite;
bool operator<(const RemoteDesktop &rd) const
{
if (lastConnected == rd.lastConnected)
return url < rd.url;
return rd.lastConnected < lastConnected; // seems backward but gets the desired result
}
bool operator==(const RemoteDesktop &rd) const
{
return url == rd.url;
}
};
class RemoteDesktopsModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit RemoteDesktopsModel(QObject *parent, KBookmarkManager *manager);
~RemoteDesktopsModel() override;
enum DisplayItems {
Favorite,
Title,
LastConnected,
VisitCount,
Created,
Source
};
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
private:
QList<RemoteDesktop> remoteDesktops;
QString getLastConnectedString(QDateTime lastConnected, bool fuzzy = false) const;
void removeAllItemsFromSources(RemoteDesktop::Sources sources);
void buildModelFromBookmarkGroup(const KBookmarkGroup &group);
KBookmarkManager *m_manager;
#ifdef BUILD_ZEROCONF
KDNSSD::ServiceBrowser *zeroconfBrowser;
QHash<QString, QString> m_protocols;
#endif
private Q_SLOTS:
void bookmarksChanged();
#ifdef BUILD_ZEROCONF
void servicesChanged();
#endif
};
Q_DECLARE_OPERATORS_FOR_FLAGS(RemoteDesktop::Sources)
#endif