-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremotedesktopsmodel.h
More file actions
97 lines (84 loc) · 3.24 KB
/
remotedesktopsmodel.h
File metadata and controls
97 lines (84 loc) · 3.24 KB
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
/****************************************************************************
**
** Copyright (C) 2008 Urs Wolfer <uwolfer @ kde.org>
** Copyright (C) 2009 Tony Murray <murraytony@gmail.com>
**
** This file is part of KDE.
**
** 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.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; see the file COPYING. If not, write to
** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
** Boston, MA 02110-1301, USA.
**
****************************************************************************/
#ifndef REMOTEDESKTOPSMODEL_H
#define REMOTEDESKTOPSMODEL_H
#include "bookmarkmanager.h"
#include <QAbstractTableModel>
#include <QDateTime>
#ifdef BUILD_ZEROCONF
#include <DNSSD/RemoteService>
#include <DNSSD/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