Commit d3333f9a authored by Urs Wolfer's avatar Urs Wolfer

Improve dockwidget and enabled it by default (bookmark part). Network part...

Improve dockwidget and enabled it by default (bookmark part). Network part disabled for now because it is not ready yet.

svn path=/trunk/KDE/kdenetwork/krdc/; revision=807463
parent b0dbdb96
......@@ -99,12 +99,14 @@ MainWindow::MainWindow(QWidget *parent)
setCentralWidget(m_tabWidget);
QDockWidget *remoteDesktopsDockWidget = new QDockWidget(this);
remoteDesktopsDockWidget->setObjectName("remoteDesktopsDockWidget");
remoteDesktopsDockWidget->setWindowTitle("Remote desktops");
remoteDesktopsDockWidget->setObjectName("remoteDesktopsDockWidget"); // required for saving position / state
remoteDesktopsDockWidget->setWindowTitle(i18n("Remote desktops"));
actionCollection()->addAction("remote_desktop_dockwidget",
remoteDesktopsDockWidget->toggleViewAction());
QTreeView *remoteDesktopsTreeView = new QTreeView(remoteDesktopsDockWidget);
remoteDesktopsTreeView->setModel(new RemoteDesktopsModel(this));
RemoteDesktopsModel *remoteDesktopsModel = new RemoteDesktopsModel(this);
connect(remoteDesktopsModel, SIGNAL(modelReset()), remoteDesktopsTreeView, SLOT(expandAll()));
remoteDesktopsTreeView->setModel(remoteDesktopsModel);
remoteDesktopsTreeView->header()->hide();
remoteDesktopsTreeView->expandAll();
connect(remoteDesktopsTreeView, SIGNAL(doubleClicked(const QModelIndex &)),
......@@ -133,8 +135,6 @@ 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()
......
......@@ -73,3 +73,8 @@ int RemoteDesktopsItem::row() const
return 0;
}
void RemoteDesktopsItem::clearChildren()
{
childItems.clear();
}
......@@ -41,6 +41,7 @@ public:
QVariant data(int column) const;
int row() const;
RemoteDesktopsItem *parent();
void clearChildren();
private:
QList<RemoteDesktopsItem*> childItems;
......
......@@ -29,32 +29,44 @@
#include <KIcon>
#include <KStandardDirs>
#include <KDebug>
#include <KLocale>
#include <KProcess>
RemoteDesktopsModel::RemoteDesktopsModel(QObject *parent)
: QAbstractItemModel(parent)
{
QList<QVariant> rootData;
rootData << "Remote desktops";
rootItem = new RemoteDesktopsItem(rootData);
rootItem = new RemoteDesktopsItem(QList<QVariant>() << "Remote desktops");
QString file = KStandardDirs::locateLocal("data", "krdc/bookmarks.xml");
m_manager = KBookmarkManager::managerForFile(file, "krdc");
m_manager->setUpdate(true);
connect(m_manager, SIGNAL(changed(const QString &, const QString &)), SLOT(changed()));
buildModelFromBookmarkGroup(m_manager->root(), rootItem);
RemoteDesktopsItem *localNetwork = new RemoteDesktopsItem(QList<QVariant>() << "Local Network", rootItem);
#if 0
localNetworkItem = new RemoteDesktopsItem(QList<QVariant>() << "Local Network", rootItem);
rootItem->appendChild(localNetworkItem);
scanLocalNetwork();
rootItem->appendChild(localNetwork);
localNetwork->appendChild(new RemoteDesktopsItem(QList<QVariant>() << "...", localNetwork));
localNetworkItem->appendChild(new RemoteDesktopsItem(QList<QVariant>() << "...", localNetworkItem));
#endif
}
RemoteDesktopsModel::~RemoteDesktopsModel()
{
}
void RemoteDesktopsModel::changed()
{
kDebug(5010);
rootItem->clearChildren();
buildModelFromBookmarkGroup(m_manager->root(), rootItem);
reset();
}
int RemoteDesktopsModel::columnCount(const QModelIndex &parent) const
{
if (parent.isValid())
......@@ -76,8 +88,10 @@ QVariant RemoteDesktopsModel::data(const QModelIndex &index, int role) const
case Qt::DecorationRole:
if (item->data(index.column()).toString().contains("://")) //TODO: clean impl
return KIcon("krdc");
#if 0
else if (item->data(index.column()).toString() == "Local Network") //TODO: clean impl
return KIcon("network-workgroup");
#endif
else if (item->data(index.column()).toString() == "...") //TODO: clean impl
return KIcon("view-history");
else
......@@ -165,4 +179,42 @@ void RemoteDesktopsModel::buildModelFromBookmarkGroup(const KBookmarkGroup &grou
}
}
#if 0
void RemoteDesktopsModel::scanLocalNetwork()
{
m_scanProcess = new KProcess(this);
m_scanProcess->setOutputChannelMode(KProcess::SeparateChannels);
QStringList args(QStringList() << "-vv" << "-PN" << "-p5901" << "192.168.1.0-255");
connect(m_scanProcess, SIGNAL(readyReadStandardOutput()),
SLOT(readInput()));
m_scanProcess->setProgram("nmap", args);
m_scanProcess->start();
}
void RemoteDesktopsModel::readInput()
{
// we do not know if the output array ends in the middle of an utf-8 sequence
m_output += m_scanProcess->readAllStandardOutput();
int pos;
while ((pos = m_output.indexOf('\n')) != -1) {
QString line = QString::fromLocal8Bit(m_output, pos + 1);
m_output.remove(0, pos + 1);
if (line.contains("open port")) {
kDebug(5010) << line;
QString ip(line.mid(line.lastIndexOf(' ') + 1));
ip = ip.left(ip.length() - 1);
QString port(line.left(line.indexOf('/')));
port = port.mid(port.lastIndexOf(' ') + 1);
RemoteDesktopsItem *item = new RemoteDesktopsItem(QList<QVariant>() << "vnc://" + ip + ':' + port, localNetworkItem);
localNetworkItem->appendChild(item);
emit dataChanged(QModelIndex(), QModelIndex());
}
}
}
#endif
#include "remotedesktopsmodel.moc"
......@@ -30,6 +30,9 @@ class KBookmarkGroup;
class KBookmarkManager;
class RemoteDesktopsItem;
class KProcess;
class QByteArray;
class RemoteDesktopsModel : public QAbstractItemModel
{
Q_OBJECT
......@@ -50,9 +53,23 @@ public:
private:
void buildModelFromBookmarkGroup(const KBookmarkGroup &group, RemoteDesktopsItem *item);
void scanLocalNetwork();
KBookmarkManager *m_manager;
RemoteDesktopsItem *rootItem;
#if 0
RemoteDesktopsItem *localNetworkItem;
KProcess *m_scanProcess;
QString m_strBt;
QByteArray m_output;
#endif
private slots:
void changed();
#if 0
void readInput();
#endif
};
#endif
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