mirror of
https://invent.kde.org/network/krdc
synced 2024-07-05 17:29:34 +00:00
Format the code according to KDE coding style and add a commit hook to ensure it stays that way. This is common practice among other KDE projects
84 lines
2.4 KiB
C++
84 lines
2.4 KiB
C++
/*
|
|
SPDX-FileCopyrightText: 2008 Urs Wolfer <uwolfer@kde.org>
|
|
SPDX-FileCopyrightText: 2009 Tony Murray <murraytony@gmail.com>
|
|
|
|
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
|