Commit 95f03d3a authored by Urs Wolfer's avatar Urs Wolfer

Implement feature to filter dock widget.

FEATURE:174912

svn path=/trunk/KDE/kdenetwork/krdc/; revision=988128
parent f894b6f4
......@@ -43,6 +43,7 @@
#include <KComboBox>
#include <KEditToolBar>
#include <KIcon>
#include <KLineEdit>
#include <KLocale>
#include <KMenu>
#include <KMenuBar>
......@@ -69,6 +70,7 @@
#include <QLabel>
#include <QLayout>
#include <QScrollArea>
#include <QSortFilterProxyModel>
#include <QTimer>
#include <QToolButton>
#include <QToolTip>
......@@ -113,16 +115,24 @@ MainWindow::MainWindow(QWidget *parent)
setCentralWidget(m_tabWidget);
QDockWidget *remoteDesktopsDockWidget = new QDockWidget(this);
QWidget *remoteDesktopsDockLayoutWidget = new QWidget(remoteDesktopsDockWidget);
QVBoxLayout *remoteDesktopsDockLayout = new QVBoxLayout(remoteDesktopsDockLayoutWidget);
remoteDesktopsDockWidget->setObjectName("remoteDesktopsDockWidget"); // required for saving position / state
remoteDesktopsDockWidget->setWindowTitle(i18n("Remote Desktops"));
QFontMetrics fontMetrics(remoteDesktopsDockWidget->font());
remoteDesktopsDockWidget->setMinimumWidth(fontMetrics.width("vnc://192.168.100.100:6000"));
actionCollection()->addAction("remote_desktop_dockwidget",
remoteDesktopsDockWidget->toggleViewAction());
m_remoteDesktopsTreeView = new QTreeView(remoteDesktopsDockWidget);
m_remoteDesktopsTreeView = new QTreeView(remoteDesktopsDockLayoutWidget);
RemoteDesktopsModel *remoteDesktopsModel = new RemoteDesktopsModel(this);
m_remoteDesktopsModelProxy = new QSortFilterProxyModel(this);
m_remoteDesktopsModelProxy->setSourceModel(remoteDesktopsModel);
m_remoteDesktopsModelProxy->setFilterKeyColumn(0);
m_remoteDesktopsModelProxy->setFilterRole(10002);
connect(remoteDesktopsModel, SIGNAL(modelReset()), this, SLOT(expandTreeViewItems()));
m_remoteDesktopsTreeView->setModel(remoteDesktopsModel);
m_remoteDesktopsTreeView->setModel(m_remoteDesktopsModelProxy);
m_remoteDesktopsTreeView->header()->hide();
m_remoteDesktopsTreeView->expandAll();
m_remoteDesktopsTreeView->setItemsExpandable(false);
......@@ -130,7 +140,13 @@ MainWindow::MainWindow(QWidget *parent)
connect(m_remoteDesktopsTreeView, SIGNAL(doubleClicked(const QModelIndex &)),
SLOT(openFromDockWidget(const QModelIndex &)));
remoteDesktopsDockWidget->setWidget(m_remoteDesktopsTreeView);
KLineEdit *filterLineEdit = new KLineEdit(remoteDesktopsDockLayoutWidget);
filterLineEdit->setClickMessage(i18n("Filter"));
filterLineEdit->setClearButtonShown(true);
connect(filterLineEdit, SIGNAL(textChanged(const QString &)), SLOT(updateFilter(const QString &)));
remoteDesktopsDockLayout->addWidget(filterLineEdit);
remoteDesktopsDockLayout->addWidget(m_remoteDesktopsTreeView);
remoteDesktopsDockWidget->setWidget(remoteDesktopsDockLayoutWidget);
addDockWidget(Qt::LeftDockWidgetArea, remoteDesktopsDockWidget);
createGUI("krdcui.rc");
......@@ -1134,4 +1150,9 @@ void MainWindow::expandTreeViewItems()
metaObject()->invokeMethod(m_remoteDesktopsTreeView, "expandAll", Qt::QueuedConnection);
}
void MainWindow::updateFilter(const QString &text)
{
m_remoteDesktopsModelProxy->setFilterRegExp(QRegExp("IGNORE|" + text, Qt::CaseInsensitive, QRegExp::RegExp));
}
#include "mainwindow.moc"
......@@ -43,6 +43,7 @@ class ZeroconfPage;
class QScrollArea;
class QModelIndex;
class QSortFilterProxyModel;
class QTreeView;
class MainWindow : public KXmlGuiWindow
......@@ -94,12 +95,13 @@ private slots:
void closeZeroconfPage();
void openFromDockWidget(const QModelIndex &index);
void expandTreeViewItems();
void updateFilter(const QString &text);
private:
void setupActions();
void loadAllPlugins();
RemoteViewFactory *createPluginFromService(const KService::Ptr &service);
QScrollArea *createScrollArea(QWidget *parent, RemoteView *remoteView);
QWidget *m_fullscreenWindow;
......@@ -126,6 +128,7 @@ private:
SystemTrayIcon *m_systemTrayIcon;
ZeroconfPage *m_zeroconfPage;
QTreeView *m_remoteDesktopsTreeView;
QSortFilterProxyModel *m_remoteDesktopsModelProxy;
};
#include <QApplication>
......
......@@ -81,24 +81,30 @@ QVariant RemoteDesktopsModel::data(const QModelIndex &index, int role) const
return QVariant();
RemoteDesktopsItem *item = static_cast<RemoteDesktopsItem*>(index.internalPointer());
const QString currentItemString = item->data(1).toString();
switch (role) {
case Qt::DisplayRole:
case Qt::ToolTipRole:
return item->data(index.column());
case Qt::DecorationRole:
if (!item->data(1).toString().isEmpty()) // contains an url
if (!currentItemString.isEmpty()) // contains an url
return KIcon("krdc");
#if 0
else if (item->data(1).toString() == "Local Network")
else if (currentItemString == "Local Network")
return KIcon("network-workgroup");
#endif
else if (item->data(1).toString() == "...")
else if (currentItemString == "...")
return KIcon("view-history");
else
return KIcon("folder-bookmarks");
case 10001: //url for dockwidget
return item->data(1);
return currentItemString;
case 10002: //filter
if (!currentItemString.isEmpty())
return currentItemString + item->data(0).toString(); // return both uservisible and data
else
return "IGNORE";
default:
return QVariant();
}
......
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