Commit f938c780 authored by Urs Wolfer's avatar Urs Wolfer

Initial implementation of a remote desktops dock widget. This widget allows...

Initial implementation of a remote desktops dock widget. This widget allows quick access to bookmarks, recent connected desktops and zeroconf deteced remote services.
Work in progress, hidden by default.
Also fix a problem with showing / hiding the zeroconf tab in some cases.

svn path=/trunk/KDE/kdenetwork/krdc/; revision=788579
parent ac182d16
......@@ -53,6 +53,8 @@ set(krdc_SRCS ${krdc_zeroconf_SRCS} ${krdc_rdp_SRCS} ${krdc_vnc_SRCS}
config/preferencesdialog.cpp
floatingtoolbar.cpp
bookmarkmanager.cpp
remotedesktopsitem.cpp
remotedesktopsmodel.cpp
systemtrayicon.cpp
remoteview.cpp
mainwindow.cpp
......
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<gui name="krdc" version="1">
<gui name="krdc" version="2">
<MenuBar>
<Menu noMerge="1" name="file"><text>&amp;File</text>
<Action name="new_vnc_connection" />
......@@ -20,6 +20,7 @@
</Menu>
<Action name="bookmark" />
<Menu name="settings"><text>&amp;Settings</text>
<Action name="remote_desktop_dockwidget" />
<Separator/>
<Action name="configure_notifications" />
<Action name="configure_keys" />
......
......@@ -28,6 +28,7 @@
#include "config/preferencesdialog.h"
#include "floatingtoolbar.h"
#include "bookmarkmanager.h"
#include "remotedesktopsmodel.h"
#include "systemtrayicon.h"
#ifdef BUILD_RDP
#include "rdpview.h"
......@@ -64,12 +65,15 @@
#include <QClipboard>
#include <QCloseEvent>
#include <QDesktopWidget>
#include <QDockWidget>
#include <QHeaderView>
#include <QLabel>
#include <QLayout>
#include <QScrollArea>
#include <QTimer>
#include <QToolButton>
#include <QToolTip>
#include <QTreeView>
MainWindow::MainWindow(QWidget *parent)
: KXmlGuiWindow(parent),
......@@ -85,14 +89,28 @@ MainWindow::MainWindow(QWidget *parent)
{
setupActions();
createGUI("krdcui.rc");
setStandardToolBarMenuEnabled(true);
m_tabWidget = new KTabWidget(this);
m_tabWidget->setMinimumSize(600, 400);
setCentralWidget(m_tabWidget);
QDockWidget *remoteDesktopsDockWidget = new QDockWidget(this);
remoteDesktopsDockWidget->setObjectName("remoteDesktopsDockWidget");
remoteDesktopsDockWidget->setWindowTitle("Remote desktops");
actionCollection()->addAction("remote_desktop_dockwidget",
remoteDesktopsDockWidget->toggleViewAction());
QTreeView *remoteDesktopsTreeView = new QTreeView(remoteDesktopsDockWidget);
remoteDesktopsTreeView->setModel(new RemoteDesktopsModel(this));
remoteDesktopsTreeView->header()->hide();
connect(remoteDesktopsTreeView, SIGNAL(doubleClicked(const QModelIndex &)),
SLOT(openFromDockWidget(const QModelIndex &)));
remoteDesktopsDockWidget->setWidget(remoteDesktopsTreeView);
addDockWidget(Qt::LeftDockWidgetArea, remoteDesktopsDockWidget);
createGUI("krdcui.rc");
if (Settings::systemTrayIcon()) {
m_systemTrayIcon = new SystemTrayIcon(this);
m_systemTrayIcon->setVisible(true);
......@@ -111,6 +129,8 @@ MainWindow::MainWindow(QWidget *parent)
if (Settings::rememberSessions()) // give some time to create and show the window first
QTimer::singleShot(100, this, SLOT(restoreOpenSessions()));
remoteDesktopsDockWidget->setVisible(false); //TODO: remove when fully implemented
}
MainWindow::~MainWindow()
......@@ -326,6 +346,14 @@ void MainWindow::newConnection(const KUrl &newUrl, bool switchFullscreenWhenConn
view->start();
}
void MainWindow::openFromDockWidget(const QModelIndex &index)
{
KUrl url(index.data().toString());
kDebug(5010) << url;
if (url.isValid())
newConnection(url);
}
void MainWindow::resizeTabWidget(int w, int h)
{
kDebug(5010) << "tabwidget resize: w: " << w << ", h: " << h;
......@@ -864,16 +892,16 @@ void MainWindow::createZeroconfPage()
connect(zp, SIGNAL(closeZeroconfPage()), this, SLOT(closeZeroconfPage()));
m_zeroconfTabIndex = m_tabWidget->addTab(zp, KIcon("krdc"), i18n("Browse Local Network"));
m_tabWidget->setCurrentIndex(m_zeroconfTabIndex);
tabChanged(m_zeroconfTabIndex);
#endif
}
void MainWindow::closeZeroconfPage()
{
#ifdef BUILD_ZEROCONF
m_showZeroconfPage = false;
QWidget* oldZw = m_tabWidget->currentWidget();
m_tabWidget->removeTab(m_zeroconfTabIndex);
m_showZeroconfPage = false;
m_zeroconfTabIndex = -1;
oldZw->deleteLater();
#endif
}
......
......@@ -37,6 +37,7 @@ class FloatingToolBar;
class RemoteView;
class SystemTrayIcon;
class QScrollArea;
class QModelIndex;
class MainWindow : public KXmlGuiWindow
{
......@@ -80,6 +81,7 @@ private slots:
void newRdpConnection();
void createZeroconfPage();
void closeZeroconfPage();
void openFromDockWidget(const QModelIndex &index);
private:
void setupActions();
......
/****************************************************************************
**
** Copyright (C) 2008 Urs Wolfer <uwolfer @ kde.org>
**
** 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.
**
****************************************************************************/
#include <QStringList>
#include "remotedesktopsitem.h"
RemoteDesktopsItem::RemoteDesktopsItem(const QList<QVariant> &data, RemoteDesktopsItem *parent)
{
parentItem = parent;
itemData = data;
}
RemoteDesktopsItem::~RemoteDesktopsItem()
{
qDeleteAll(childItems);
}
void RemoteDesktopsItem::appendChild(RemoteDesktopsItem *item)
{
childItems.append(item);
}
RemoteDesktopsItem *RemoteDesktopsItem::child(int row)
{
return childItems.value(row);
}
int RemoteDesktopsItem::childCount() const
{
return childItems.count();
}
int RemoteDesktopsItem::columnCount() const
{
return itemData.count();
}
QVariant RemoteDesktopsItem::data(int column) const
{
return itemData.value(column);
}
RemoteDesktopsItem *RemoteDesktopsItem::parent()
{
return parentItem;
}
int RemoteDesktopsItem::row() const
{
if (parentItem)
return parentItem->childItems.indexOf(const_cast<RemoteDesktopsItem*>(this));
return 0;
}
/****************************************************************************
**
** Copyright (C) 2008 Urs Wolfer <uwolfer @ kde.org>
**
** 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 REMOTEDESKTOPSITEM_H
#define REMOTEDESKTOPSITEM_H
#include <QList>
#include <QVariant>
class RemoteDesktopsItem
{
public:
RemoteDesktopsItem(const QList<QVariant> &data, RemoteDesktopsItem *parent = 0);
~RemoteDesktopsItem();
void appendChild(RemoteDesktopsItem *child);
RemoteDesktopsItem *child(int row);
int childCount() const;
int columnCount() const;
QVariant data(int column) const;
int row() const;
RemoteDesktopsItem *parent();
private:
QList<RemoteDesktopsItem*> childItems;
QList<QVariant> itemData;
RemoteDesktopsItem *parentItem;
};
#endif
/****************************************************************************
**
** Copyright (C) 2008 Urs Wolfer <uwolfer @ kde.org>
**
** 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.
**
****************************************************************************/
#include "remotedesktopsmodel.h"
#include "remotedesktopsitem.h"
#include <KBookmarkManager>
#include <KStandardDirs>
#include <KDebug>
RemoteDesktopsModel::RemoteDesktopsModel(QObject *parent)
: QAbstractItemModel(parent)
{
QList<QVariant> rootData;
rootData << "Remote desktops";
rootItem = new RemoteDesktopsItem(rootData);
QString file = KStandardDirs::locateLocal("data", "krdc/bookmarks.xml");
m_manager = KBookmarkManager::managerForFile(file, "krdc");
m_manager->setUpdate(true);
KBookmarkGroup root = m_manager->root();
KBookmark bm = root.first();
while (!bm.isNull()) {
rootItem->appendChild(new RemoteDesktopsItem(QList<QVariant>() << bm.text(), rootItem));
bm = root.next(bm);
}
RemoteDesktopsItem *localNetwork = new RemoteDesktopsItem(QList<QVariant>() << "Local Network", rootItem);
rootItem->appendChild(localNetwork);
localNetwork->appendChild(new RemoteDesktopsItem(QList<QVariant>() << "...", localNetwork));
}
RemoteDesktopsModel::~RemoteDesktopsModel()
{
}
int RemoteDesktopsModel::columnCount(const QModelIndex &parent) const
{
if (parent.isValid())
return static_cast<RemoteDesktopsItem*>(parent.internalPointer())->columnCount();
else
return rootItem->columnCount();
}
QVariant RemoteDesktopsModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role != Qt::DisplayRole)
return QVariant();
RemoteDesktopsItem *item = static_cast<RemoteDesktopsItem*>(index.internalPointer());
return item->data(index.column());
}
Qt::ItemFlags RemoteDesktopsModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return 0;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
QVariant RemoteDesktopsModel::headerData(int section, Qt::Orientation orientation,
int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
return rootItem->data(section);
return QVariant();
}
QModelIndex RemoteDesktopsModel::index(int row, int column, const QModelIndex &parent) const
{
if (!hasIndex(row, column, parent))
return QModelIndex();
RemoteDesktopsItem *parentItem;
if (!parent.isValid())
parentItem = rootItem;
else
parentItem = static_cast<RemoteDesktopsItem*>(parent.internalPointer());
RemoteDesktopsItem *childItem = parentItem->child(row);
if (childItem)
return createIndex(row, column, childItem);
else
return QModelIndex();
}
QModelIndex RemoteDesktopsModel::parent(const QModelIndex &index) const
{
if (!index.isValid())
return QModelIndex();
RemoteDesktopsItem *childItem = static_cast<RemoteDesktopsItem*>(index.internalPointer());
RemoteDesktopsItem *parentItem = childItem->parent();
if (parentItem == rootItem)
return QModelIndex();
return createIndex(parentItem->row(), 0, parentItem);
}
int RemoteDesktopsModel::rowCount(const QModelIndex &parent) const
{
RemoteDesktopsItem *parentItem;
if (parent.column() > 0)
return 0;
if (!parent.isValid())
parentItem = rootItem;
else
parentItem = static_cast<RemoteDesktopsItem*>(parent.internalPointer());
return parentItem->childCount();
}
#include "remotedesktopsmodel.moc"
/****************************************************************************
**
** Copyright (C) 2008 Urs Wolfer <uwolfer @ kde.org>
**
** 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 <QAbstractItemModel>
class KBookmarkManager;
class RemoteDesktopsItem;
class RemoteDesktopsModel : public QAbstractItemModel
{
Q_OBJECT
public:
RemoteDesktopsModel(QObject *parent);
~RemoteDesktopsModel();
QVariant data(const QModelIndex &index, int role) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
private:
KBookmarkManager *m_manager;
RemoteDesktopsItem *rootItem;
};
#endif
......@@ -274,7 +274,6 @@ public slots:
* Enables/disables grabbing all possible keys.
* @param grabAllKeys true to enable, false to disable.
* Default is false.
* @see supportsScaling()
* @see grabAllKeys()
*/
virtual void setGrabAllKeys(bool grabAllKeys);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment