• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

krdc

  • sources
  • kde-4.12
  • kdenetwork
  • krdc
mainwindow.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2007 - 2013 Urs Wolfer <uwolfer @ kde.org>
4 ** Copyright (C) 2009 - 2010 Tony Murray <murraytony @ gmail.com>
5 **
6 ** This file is part of KDE.
7 **
8 ** This program is free software; you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License as published by
10 ** the Free Software Foundation; either version 2 of the License, or
11 ** (at your option) any later version.
12 **
13 ** This program is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with this program; see the file COPYING. If not, write to
20 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 ** Boston, MA 02110-1301, USA.
22 **
23 ****************************************************************************/
24 
25 #include "mainwindow.h"
26 
27 #include "remoteview.h"
28 #include "settings.h"
29 #include "config/preferencesdialog.h"
30 #include "floatingtoolbar.h"
31 #include "bookmarkmanager.h"
32 #include "connectiondelegate.h"
33 #include "remotedesktopsmodel.h"
34 #include "systemtrayicon.h"
35 #include "tabbedviewwidget.h"
36 #include "hostpreferences.h"
37 
38 #ifdef TELEPATHY_SUPPORT
39 #include "tubesmanager.h"
40 #endif
41 
42 #include <KAction>
43 #include <KActionCollection>
44 #include <KActionMenu>
45 #include <KComboBox>
46 #include <KIcon>
47 #include <KInputDialog>
48 #include <KLineEdit>
49 #include <KLocale>
50 #include <KMenu>
51 #include <KMenuBar>
52 #include <KMessageBox>
53 #include <KNotifyConfigWidget>
54 #include <KPluginInfo>
55 #include <KPushButton>
56 #include <KStatusBar>
57 #include <KToggleAction>
58 #include <KToggleFullScreenAction>
59 #include <KServiceTypeTrader>
60 
61 #include <QClipboard>
62 #include <QDockWidget>
63 #include <QFontMetrics>
64 #include <QGroupBox>
65 #include <QHBoxLayout>
66 #include <QHeaderView>
67 #include <QLabel>
68 #include <QLayout>
69 #include <QScrollArea>
70 #include <QSortFilterProxyModel>
71 #include <QTableView>
72 #include <QTimer>
73 #include <QToolBar>
74 #include <QVBoxLayout>
75 
76 MainWindow::MainWindow(QWidget *parent)
77  : KXmlGuiWindow(parent),
78  m_fullscreenWindow(0),
79  m_protocolInput(0),
80  m_addressInput(0),
81  m_toolBar(0),
82  m_currentRemoteView(-1),
83  m_systemTrayIcon(0),
84  m_dockWidgetTableView(0),
85  m_newConnectionTableView(0),
86 #ifdef TELEPATHY_SUPPORT
87  m_tubesManager(0),
88 #endif
89  m_newConnectionWidget(0)
90 {
91  loadAllPlugins();
92 
93  setupActions();
94 
95  setStandardToolBarMenuEnabled(true);
96 
97  m_tabWidget = new TabbedViewWidget(this);
98  m_tabWidget->setMovable(true);
99  m_tabWidget->setTabPosition((KTabWidget::TabPosition) Settings::tabPosition());
100 
101 #if QT_VERSION >= 0x040500
102  m_tabWidget->setTabsClosable(Settings::tabCloseButton());
103 #else
104  m_tabWidget->setCloseButtonEnabled(Settings::tabCloseButton());
105 #endif
106 
107  connect(m_tabWidget, SIGNAL(closeRequest(QWidget*)), SLOT(closeTab(QWidget*)));
108 
109  if (Settings::tabMiddleClick())
110  connect(m_tabWidget, SIGNAL(mouseMiddleClick(QWidget*)), SLOT(closeTab(QWidget*)));
111 
112  connect(m_tabWidget, SIGNAL(mouseDoubleClick(QWidget*)), SLOT(openTabSettings(QWidget*)));
113  connect(m_tabWidget, SIGNAL(contextMenu(QWidget*,QPoint)), SLOT(tabContextMenu(QWidget*,QPoint)));
114 
115  m_tabWidget->setMinimumSize(600, 400);
116  setCentralWidget(m_tabWidget);
117 
118  createDockWidget();
119 
120  setupGUI(ToolBar | Keys | Save | Create);
121 
122  if (Settings::systemTrayIcon()) {
123  m_systemTrayIcon = new SystemTrayIcon(this);
124  if(m_fullscreenWindow) m_systemTrayIcon->setAssociatedWidget(m_fullscreenWindow);
125  }
126 
127  connect(m_tabWidget, SIGNAL(currentChanged(int)), SLOT(tabChanged(int)));
128 
129  if (Settings::showStatusBar())
130  statusBar()->showMessage(i18n("KDE Remote Desktop Client started"));
131 
132  updateActionStatus(); // disable remote view actions
133 
134  if (Settings::openSessions().count() == 0) // just create a new connection tab if there are no open sessions
135  m_tabWidget->addTab(newConnectionWidget(), i18n("New Connection"));
136 
137  if (Settings::rememberSessions()) // give some time to create and show the window first
138  QTimer::singleShot(100, this, SLOT(restoreOpenSessions()));
139 }
140 
141 MainWindow::~MainWindow()
142 {
143 }
144 
145 void MainWindow::setupActions()
146 {
147  QAction *connectionAction = actionCollection()->addAction("new_connection");
148  connectionAction->setText(i18n("New Connection"));
149  connectionAction->setIcon(KIcon("network-connect"));
150  connect(connectionAction, SIGNAL(triggered()), SLOT(newConnectionPage()));
151 
152  QAction *screenshotAction = actionCollection()->addAction("take_screenshot");
153  screenshotAction->setText(i18n("Copy Screenshot to Clipboard"));
154  screenshotAction->setIconText(i18n("Screenshot"));
155  screenshotAction->setIcon(KIcon("ksnapshot"));
156  connect(screenshotAction, SIGNAL(triggered()), SLOT(takeScreenshot()));
157 
158  KAction *fullscreenAction = actionCollection()->addAction("switch_fullscreen"); // note: please do not switch to KStandardShortcut unless you know what you are doing (see history of this file)
159  fullscreenAction->setText(i18n("Switch to Full Screen Mode"));
160  fullscreenAction->setIconText(i18n("Full Screen"));
161  fullscreenAction->setIcon(KIcon("view-fullscreen"));
162  fullscreenAction->setShortcut(KStandardShortcut::fullScreen());
163  connect(fullscreenAction, SIGNAL(triggered()), SLOT(switchFullscreen()));
164 
165  QAction *viewOnlyAction = actionCollection()->addAction("view_only");
166  viewOnlyAction->setCheckable(true);
167  viewOnlyAction->setText(i18n("View Only"));
168  viewOnlyAction->setIcon(KIcon("document-preview"));
169  connect(viewOnlyAction, SIGNAL(triggered(bool)), SLOT(viewOnly(bool)));
170 
171  KAction *disconnectAction = actionCollection()->addAction("disconnect");
172  disconnectAction->setText(i18n("Disconnect"));
173  disconnectAction->setIcon(KIcon("network-disconnect"));
174  disconnectAction->setShortcut(QKeySequence::Close);
175  connect(disconnectAction, SIGNAL(triggered()), SLOT(disconnectHost()));
176 
177  QAction *showLocalCursorAction = actionCollection()->addAction("show_local_cursor");
178  showLocalCursorAction->setCheckable(true);
179  showLocalCursorAction->setIcon(KIcon("input-mouse"));
180  showLocalCursorAction->setText(i18n("Show Local Cursor"));
181  showLocalCursorAction->setIconText(i18n("Local Cursor"));
182  connect(showLocalCursorAction, SIGNAL(triggered(bool)), SLOT(showLocalCursor(bool)));
183 
184  QAction *grabAllKeysAction = actionCollection()->addAction("grab_all_keys");
185  grabAllKeysAction->setCheckable(true);
186  grabAllKeysAction->setIcon(KIcon("configure-shortcuts"));
187  grabAllKeysAction->setText(i18n("Grab All Possible Keys"));
188  grabAllKeysAction->setIconText(i18n("Grab Keys"));
189  connect(grabAllKeysAction, SIGNAL(triggered(bool)), SLOT(grabAllKeys(bool)));
190 
191  QAction *scaleAction = actionCollection()->addAction("scale");
192  scaleAction->setCheckable(true);
193  scaleAction->setIcon(KIcon("zoom-fit-best"));
194  scaleAction->setText(i18n("Scale Remote Screen to Fit Window Size"));
195  scaleAction->setIconText(i18n("Scale"));
196  connect(scaleAction, SIGNAL(triggered(bool)), SLOT(scale(bool)));
197 
198  KStandardAction::quit(this, SLOT(quit()), actionCollection());
199  KStandardAction::preferences(this, SLOT(preferences()), actionCollection());
200  QAction *configNotifyAction = KStandardAction::configureNotifications(this, SLOT(configureNotifications()), actionCollection());
201  configNotifyAction->setVisible(false);
202  m_menubarAction = KStandardAction::showMenubar(this, SLOT(showMenubar()), actionCollection());
203  m_menubarAction->setChecked(!menuBar()->isHidden());
204 
205  KActionMenu *bookmarkMenu = new KActionMenu(i18n("Bookmarks"), actionCollection());
206  m_bookmarkManager = new BookmarkManager(actionCollection(), bookmarkMenu->menu(), this);
207  actionCollection()->addAction("bookmark" , bookmarkMenu);
208  connect(m_bookmarkManager, SIGNAL(openUrl(KUrl)), SLOT(newConnection(KUrl)));
209 }
210 
211 void MainWindow::loadAllPlugins()
212 {
213  const KService::List offers = KServiceTypeTrader::self()->query("KRDC/Plugin");
214 
215  KConfigGroup conf(KGlobal::config(), "Plugins");
216 
217  for (int i = 0; i < offers.size(); i++) {
218  KService::Ptr offer = offers[i];
219 
220  RemoteViewFactory *remoteView;
221 
222  KPluginInfo description(offer);
223  description.load(conf);
224 
225  const bool selected = description.isPluginEnabled();
226 
227  if (selected) {
228  if ((remoteView = createPluginFromService(offer)) != 0) {
229  kDebug(5010) << "### Plugin " + description.name() + " found ###";
230  kDebug(5010) << "# Version:" << description.version();
231  kDebug(5010) << "# Description:" << description.comment();
232  kDebug(5010) << "# Author:" << description.author();
233  const int sorting = offer->property("X-KDE-KRDC-Sorting").toInt();
234  kDebug(5010) << "# Sorting:" << sorting;
235 
236  m_remoteViewFactories.insert(sorting, remoteView);
237  } else {
238  kDebug(5010) << "Error loading KRDC plugin (" << (offers[i])->library() << ')';
239  }
240  } else {
241  kDebug(5010) << "# Plugin " + description.name() + " found, however it's not activated, skipping...";
242  continue;
243  }
244  }
245 
246 #ifdef TELEPATHY_SUPPORT
247  /* Start tube handler */
248  m_tubesManager = new TubesManager(this);
249  connect(m_tubesManager, SIGNAL(newConnection(KUrl)), SLOT(newConnection(KUrl)));
250 #endif
251 }
252 
253 RemoteViewFactory *MainWindow::createPluginFromService(const KService::Ptr &service)
254 {
255  //try to load the specified library
256  KPluginFactory *factory = KPluginLoader(service->library()).factory();
257 
258  if (!factory) {
259  kError(5010) << "KPluginFactory could not load the plugin:" << service->library();
260  return 0;
261  }
262 
263  RemoteViewFactory *plugin = factory->create<RemoteViewFactory>();
264 
265  return plugin;
266 }
267 
268 void MainWindow::restoreOpenSessions()
269 {
270  const QStringList list = Settings::openSessions();
271  QStringList::ConstIterator it = list.begin();
272  QStringList::ConstIterator end = list.end();
273  while (it != end) {
274  newConnection(*it);
275  ++it;
276  }
277 }
278 
279 KUrl MainWindow::getInputUrl()
280 {
281  return KUrl(m_protocolInput->currentText() + "://" + m_addressInput->text());
282 }
283 
284 void MainWindow::newConnection(const KUrl &newUrl, bool switchFullscreenWhenConnected, const QString &tabName)
285 {
286  m_switchFullscreenWhenConnected = switchFullscreenWhenConnected;
287 
288  const KUrl url = newUrl.isEmpty() ? getInputUrl() : newUrl;
289 
290  if (!url.isValid() || (url.host().isEmpty() && url.port() < 0)
291  || (!url.path().isEmpty() && url.path() != QLatin1String("/"))) {
292  KMessageBox::error(this,
293  i18n("The entered address does not have the required form.\n Syntax: [username@]host[:port]"),
294  i18n("Malformed URL"));
295  return;
296  }
297 
298  if (m_protocolInput && m_addressInput) {
299  int index = m_protocolInput->findText(url.protocol());
300  if (index>=0) m_protocolInput->setCurrentIndex(index);
301  m_addressInput->setText(url.authority());
302  }
303 
304  RemoteView *view = 0;
305  KConfigGroup configGroup = Settings::self()->config()->group("hostpreferences").group(url.prettyUrl(KUrl::RemoveTrailingSlash));
306 
307  foreach(RemoteViewFactory *factory, m_remoteViewFactories) {
308  if (factory->supportsUrl(url)) {
309  view = factory->createView(this, url, configGroup);
310  kDebug(5010) << "Found plugin to handle url (" + url.url() + "): " + view->metaObject()->className();
311  break;
312  }
313  }
314 
315  if (!view) {
316  KMessageBox::error(this,
317  i18n("The entered address cannot be handled."),
318  i18n("Unusable URL"));
319  return;
320  }
321 
322  // Configure the view
323  HostPreferences* prefs = view->hostPreferences();
324  if (! prefs->showDialogIfNeeded(this)) {
325  delete view;
326  return;
327  }
328 
329  view->showDotCursor(prefs->showLocalCursor() ? RemoteView::CursorOn : RemoteView::CursorOff);
330  view->setViewOnly(prefs->viewOnly());
331  if (! switchFullscreenWhenConnected) view->enableScaling(prefs->windowedScale());
332 
333  connect(view, SIGNAL(framebufferSizeChanged(int,int)), this, SLOT(resizeTabWidget(int,int)));
334  connect(view, SIGNAL(statusChanged(RemoteView::RemoteStatus)), this, SLOT(statusChanged(RemoteView::RemoteStatus)));
335  connect(view, SIGNAL(disconnected()), this, SLOT(disconnectHost()));
336 
337  view->winId(); // native widget workaround for bug 253365
338  QScrollArea *scrollArea = createScrollArea(m_tabWidget, view);
339 
340  const int indexOfNewConnectionWidget = m_tabWidget->indexOf(m_newConnectionWidget);
341  if (indexOfNewConnectionWidget >= 0)
342  m_tabWidget->removeTab(indexOfNewConnectionWidget);
343 
344  const int newIndex = m_tabWidget->addTab(scrollArea, KIcon("krdc"), tabName.isEmpty() ? url.prettyUrl(KUrl::RemoveTrailingSlash) : tabName);
345  m_tabWidget->setCurrentIndex(newIndex);
346  m_remoteViewMap.insert(m_tabWidget->widget(newIndex), view);
347  tabChanged(newIndex); // force to update m_currentRemoteView (tabChanged is not emitted when start page has been disabled)
348 
349  view->start();
350 }
351 
352 void MainWindow::openFromRemoteDesktopsModel(const QModelIndex &index)
353 {
354  const QString urlString = index.data(10001).toString();
355  const QString nameString = index.data(10003).toString();
356  if (!urlString.isEmpty()) {
357  const KUrl url(urlString);
358  // first check if url has already been opened; in case show the tab
359  foreach (QWidget *widget, m_remoteViewMap.keys()) {
360  if (m_remoteViewMap.value(widget)->url() == url) {
361  m_tabWidget->setCurrentWidget(widget);
362  return;
363  }
364  }
365 
366  newConnection(url, false, nameString);
367  }
368 }
369 
370 void MainWindow::resizeTabWidget(int w, int h)
371 {
372  kDebug(5010) << "tabwidget resize, view size: w: " << w << ", h: " << h;
373  if (m_fullscreenWindow) {
374  kDebug(5010) << "in fullscreen mode, refusing to resize";
375  return;
376  }
377 
378  const QSize viewSize = QSize(w,h);
379  QDesktopWidget *desktop = QApplication::desktop();
380 
381  if (Settings::fullscreenOnConnect()) {
382  int currentScreen = desktop->screenNumber(this);
383  const QSize screenSize = desktop->screenGeometry(currentScreen).size();
384 
385  if (screenSize == viewSize) {
386  kDebug(5010) << "screen size equal to target view size -> switch to fullscreen mode";
387  switchFullscreen();
388  return;
389  }
390  }
391 
392  if (Settings::resizeOnConnect()) {
393  QWidget* currentWidget = m_tabWidget->currentWidget();
394  const QSize newWindowSize = size() - currentWidget->frameSize() + viewSize;
395 
396  const QSize desktopSize = desktop->availableGeometry().size();
397  kDebug(5010) << "new window size: " << newWindowSize << " available space:" << desktopSize;
398 
399  if ((newWindowSize.width() >= desktopSize.width()) || (newWindowSize.height() >= desktopSize.height())) {
400  kDebug(5010) << "remote desktop needs more space than available -> show window maximized";
401  setWindowState(windowState() | Qt::WindowMaximized);
402  return;
403  }
404 
405  resize(newWindowSize);
406  }
407 }
408 
409 void MainWindow::statusChanged(RemoteView::RemoteStatus status)
410 {
411  kDebug(5010) << status;
412 
413  // the remoteview is already deleted, so don't show it; otherwise it would crash
414  if (status == RemoteView::Disconnecting || status == RemoteView::Disconnected)
415  return;
416 
417  RemoteView *view = qobject_cast<RemoteView*>(QObject::sender());
418  const QString host = view->host();
419 
420  QString iconName = "krdc";
421  QString message;
422 
423  switch (status) {
424  case RemoteView::Connecting:
425  iconName = "network-connect";
426  message = i18n("Connecting to %1", host);
427  break;
428  case RemoteView::Authenticating:
429  iconName = "dialog-password";
430  message = i18n("Authenticating at %1", host);
431  break;
432  case RemoteView::Preparing:
433  iconName = "view-history";
434  message = i18n("Preparing connection to %1", host);
435  break;
436  case RemoteView::Connected:
437  iconName = "krdc";
438  message = i18n("Connected to %1", host);
439 
440  if (view->grabAllKeys() != view->hostPreferences()->grabAllKeys()) {
441  view->setGrabAllKeys(view->hostPreferences()->grabAllKeys());
442  updateActionStatus();
443  }
444 
445  // when started with command line fullscreen argument
446  if (m_switchFullscreenWhenConnected) {
447  m_switchFullscreenWhenConnected = false;
448  switchFullscreen();
449  }
450 
451  if (Settings::rememberHistory()) {
452  m_bookmarkManager->addHistoryBookmark(view);
453  }
454 
455  break;
456  default:
457  break;
458  }
459 
460  m_tabWidget->setTabIcon(m_tabWidget->indexOf(view), KIcon(iconName));
461  if (Settings::showStatusBar())
462  statusBar()->showMessage(message);
463 }
464 
465 void MainWindow::takeScreenshot()
466 {
467  const QPixmap snapshot = currentRemoteView()->takeScreenshot();
468 
469  QApplication::clipboard()->setPixmap(snapshot);
470 }
471 
472 void MainWindow::switchFullscreen()
473 {
474  kDebug(5010);
475 
476  if (m_fullscreenWindow) {
477  // Leaving full screen mode
478  m_fullscreenWindow->setWindowState(0);
479  m_fullscreenWindow->hide();
480 
481  m_tabWidget->setTabBarHidden(m_tabWidget->count() <= 1 && !Settings::showTabBar());
482  m_tabWidget->setDocumentMode(false);
483  setCentralWidget(m_tabWidget);
484 
485  show();
486  restoreGeometry(m_mainWindowGeometry);
487  if (m_systemTrayIcon) m_systemTrayIcon->setAssociatedWidget(this);
488 
489  foreach (RemoteView * view, m_remoteViewMap.values()) {
490  view->enableScaling(view->hostPreferences()->windowedScale());
491  }
492 
493  if (m_toolBar) {
494  m_toolBar->hideAndDestroy();
495  m_toolBar->deleteLater();
496  m_toolBar = 0;
497  }
498 
499  actionCollection()->action("switch_fullscreen")->setIcon(KIcon("view-fullscreen"));
500  actionCollection()->action("switch_fullscreen")->setText(i18n("Switch to Full Screen Mode"));
501  actionCollection()->action("switch_fullscreen")->setIconText(i18n("Full Screen"));
502 
503  m_fullscreenWindow->deleteLater();
504  m_fullscreenWindow = 0;
505  } else {
506  // Entering full screen mode
507  m_fullscreenWindow = new QWidget(this, Qt::Window);
508  m_fullscreenWindow->setWindowTitle(i18nc("window title when in full screen mode (for example displayed in tasklist)",
509  "KDE Remote Desktop Client (Full Screen)"));
510 
511  m_mainWindowGeometry = saveGeometry();
512 
513  m_tabWidget->setTabBarHidden(true);
514  m_tabWidget->setDocumentMode(true);
515 
516  foreach(RemoteView *currentView, m_remoteViewMap) {
517  currentView->enableScaling(currentView->hostPreferences()->fullscreenScale());
518  }
519 
520  QVBoxLayout *fullscreenLayout = new QVBoxLayout(m_fullscreenWindow);
521  fullscreenLayout->setContentsMargins(QMargins(0, 0, 0, 0));
522  fullscreenLayout->addWidget(m_tabWidget);
523 
524  KToggleFullScreenAction::setFullScreen(m_fullscreenWindow, true);
525 
526  MinimizePixel *minimizePixel = new MinimizePixel(m_fullscreenWindow);
527  minimizePixel->winId(); // force it to be a native widget (prevents problem with QX11EmbedContainer)
528  connect(minimizePixel, SIGNAL(rightClicked()), m_fullscreenWindow, SLOT(showMinimized()));
529  m_fullscreenWindow->installEventFilter(this);
530 
531  m_fullscreenWindow->show();
532  hide(); // hide after showing the new window so it stays on the same screen
533 
534  if (m_systemTrayIcon) m_systemTrayIcon->setAssociatedWidget(m_fullscreenWindow);
535  showRemoteViewToolbar();
536  }
537  if (m_tabWidget->currentWidget() == m_newConnectionWidget) {
538  m_addressInput->setFocus();
539  }
540 }
541 
542 QScrollArea *MainWindow::createScrollArea(QWidget *parent, RemoteView *remoteView)
543 {
544  RemoteViewScrollArea *scrollArea = new RemoteViewScrollArea(parent);
545  scrollArea->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
546 
547  connect(scrollArea, SIGNAL(resized(int,int)), remoteView, SLOT(scaleResize(int,int)));
548 
549  QPalette palette = scrollArea->palette();
550  palette.setColor(QPalette::Dark, Settings::backgroundColor());
551  scrollArea->setPalette(palette);
552 
553  scrollArea->setBackgroundRole(QPalette::Dark);
554  scrollArea->setFrameStyle(QFrame::NoFrame);
555 
556  scrollArea->setWidget(remoteView);
557 
558  return scrollArea;
559 }
560 
561 void MainWindow::disconnectHost()
562 {
563  kDebug(5010);
564 
565  RemoteView *view = qobject_cast<RemoteView*>(QObject::sender());
566 
567  QWidget *widgetToDelete;
568  if (view) {
569  widgetToDelete = (QWidget*) view->parent()->parent();
570  m_remoteViewMap.remove(m_remoteViewMap.key(view));
571  } else {
572  widgetToDelete = m_tabWidget->currentWidget();
573  view = currentRemoteView();
574  m_remoteViewMap.remove(m_remoteViewMap.key(view));
575  }
576 
577  saveHostPrefs(view);
578  view->startQuitting(); // some deconstructors can't properly quit, so quit early
579  m_tabWidget->removePage(widgetToDelete);
580  widgetToDelete->deleteLater();
581 #ifdef TELEPATHY_SUPPORT
582  m_tubesManager->closeTube(view->url());
583 #endif
584 
585  // if closing the last connection, create new connection tab
586  if (m_tabWidget->count() == 0) {
587  newConnectionPage(false);
588  }
589 
590  // if the newConnectionWidget is the only tab and we are fullscreen, switch to window mode
591  if (m_fullscreenWindow && m_tabWidget->count() == 1 && m_tabWidget->currentWidget() == m_newConnectionWidget) {
592  switchFullscreen();
593  }
594 }
595 
596 void MainWindow::closeTab(QWidget *widget)
597 {
598  bool isNewConnectionPage = widget == m_newConnectionWidget;
599 
600  if (!isNewConnectionPage) {
601  RemoteView *view = m_remoteViewMap.value(widget);
602  m_remoteViewMap.remove(m_remoteViewMap.key(view));
603  view->startQuitting();
604 #ifdef TELEPATHY_SUPPORT
605  m_tubesManager->closeTube(view->url());
606 #endif
607  widget->deleteLater();
608  }
609 
610  m_tabWidget->removePage(widget);
611 
612  // if closing the last connection, create new connection tab
613  if (m_tabWidget->count() == 0) {
614  newConnectionPage(false);
615  }
616 
617  // if the newConnectionWidget is the only tab and we are fullscreen, switch to window mode
618  if (m_fullscreenWindow && m_tabWidget->count() == 1 && m_tabWidget->currentWidget() == m_newConnectionWidget) {
619  switchFullscreen();
620  }
621 }
622 
623 void MainWindow::openTabSettings(QWidget *widget)
624 {
625  RemoteViewScrollArea *scrollArea = qobject_cast<RemoteViewScrollArea*>(widget);
626  if (!scrollArea) return;
627  RemoteView *view = qobject_cast<RemoteView*>(scrollArea->widget());
628  if (!view) return;
629 
630  const QString url = view->url().url();
631  kDebug(5010) << url;
632 
633  showSettingsDialog(url);
634 }
635 
636 void MainWindow::showSettingsDialog(const QString &url)
637 {
638  HostPreferences *prefs = 0;
639 
640  foreach(RemoteViewFactory *factory, remoteViewFactoriesList()) {
641  if (factory->supportsUrl(url)) {
642  prefs = factory->createHostPreferences(Settings::self()->config()->group("hostpreferences").group(url), this);
643  if (prefs) {
644  kDebug(5010) << "Found plugin to handle url (" + url + "): " + prefs->metaObject()->className();
645  } else {
646  kDebug(5010) << "Found plugin to handle url (" + url + "), but plugin does not provide preferences";
647  }
648  }
649  }
650 
651  if (prefs) {
652  prefs->setShownWhileConnected(true);
653  prefs->showDialog(this);
654  } else {
655  KMessageBox::error(this,
656  i18n("The selected host cannot be handled."),
657  i18n("Unusable URL"));
658  }
659 }
660 
661 void MainWindow::showConnectionContextMenu(const QPoint &pos)
662 {
663  // QTableView does not take headers into account when it does mapToGlobal(), so calculate the offset
664  QPoint offset = QPoint(m_newConnectionTableView->verticalHeader()->size().width(),
665  m_newConnectionTableView->horizontalHeader()->size().height());
666  QModelIndex index = m_newConnectionTableView->indexAt(pos);
667 
668  if (!index.isValid())
669  return;
670 
671  const QString url = index.data(10001).toString();
672  const QString title = index.model()->index(index.row(), RemoteDesktopsModel::Title).data(Qt::DisplayRole).toString();
673  const QString source = index.model()->index(index.row(), RemoteDesktopsModel::Source).data(Qt::DisplayRole).toString();
674 
675  KMenu *menu = new KMenu(m_newConnectionTableView);
676  menu->addTitle(url);
677 
678  QAction *connectAction = menu->addAction(KIcon("network-connect"), i18n("Connect"));
679  QAction *renameAction = menu->addAction(KIcon("edit-rename"), i18n("Rename"));
680  QAction *settingsAction = menu->addAction(KIcon("configure"), i18n("Settings"));
681  QAction *deleteAction = menu->addAction(KIcon("edit-delete"), i18n("Delete"));
682 
683  // not very clean, but it works,
684  if (!(source == i18nc("Where each displayed link comes from", "Bookmarks") ||
685  source == i18nc("Where each displayed link comes from", "History"))) {
686  renameAction->setEnabled(false);
687  deleteAction->setEnabled(false);
688  }
689 
690  QAction *selectedAction = menu->exec(m_newConnectionTableView->mapToGlobal(pos + offset));
691 
692  if (selectedAction == connectAction) {
693  openFromRemoteDesktopsModel(index);
694  } else if (selectedAction == renameAction) {
695  //TODO: use inline editor if possible
696  bool ok = false;
697  const QString newTitle = KInputDialog::getText(i18n("Rename %1", title), i18n("Rename %1 to", title), "", &ok, this);
698  if (ok && !newTitle.isEmpty()) {
699  BookmarkManager::updateTitle(m_bookmarkManager->getManager(), url, newTitle);
700  }
701  } else if (selectedAction == settingsAction) {
702  showSettingsDialog(url);
703  } else if (selectedAction == deleteAction) {
704 
705  if (KMessageBox::warningContinueCancel(this, i18n("Are you sure you want to delete %1?", url), i18n("Delete %1", title),
706  KStandardGuiItem::del()) == KMessageBox::Continue) {
707  BookmarkManager::removeByUrl(m_bookmarkManager->getManager(), url);
708  }
709  }
710 
711  menu->deleteLater();
712 }
713 
714 void MainWindow::tabContextMenu(QWidget *widget, const QPoint &point)
715 {
716  RemoteViewScrollArea *scrollArea = qobject_cast<RemoteViewScrollArea*>(widget);
717  if (!scrollArea) return;
718  RemoteView *view = qobject_cast<RemoteView*>(scrollArea->widget());
719  if (!view) return;
720 
721  const QString url = view->url().prettyUrl(KUrl::RemoveTrailingSlash);
722  kDebug(5010) << url;
723 
724  KMenu *menu = new KMenu(this);
725  menu->addTitle(url);
726  QAction *bookmarkAction = menu->addAction(KIcon("bookmark-new"), i18n("Add Bookmark"));
727  QAction *closeAction = menu->addAction(KIcon("tab-close"), i18n("Close Tab"));
728  QAction *selectedAction = menu->exec(point);
729  if (selectedAction) {
730  if (selectedAction == closeAction) {
731  closeTab(widget);
732  } else if (selectedAction == bookmarkAction) {
733  m_bookmarkManager->addManualBookmark(url, url);
734  }
735  }
736  menu->deleteLater();
737 }
738 
739 void MainWindow::showLocalCursor(bool showLocalCursor)
740 {
741  kDebug(5010) << showLocalCursor;
742 
743  RemoteView* view = currentRemoteView();
744  view->showDotCursor(showLocalCursor ? RemoteView::CursorOn : RemoteView::CursorOff);
745  view->hostPreferences()->setShowLocalCursor(showLocalCursor);
746  saveHostPrefs(view);
747 }
748 
749 void MainWindow::viewOnly(bool viewOnly)
750 {
751  kDebug(5010) << viewOnly;
752 
753  RemoteView* view = currentRemoteView();
754  view->setViewOnly(viewOnly);
755  view->hostPreferences()->setViewOnly(viewOnly);
756  saveHostPrefs(view);
757 }
758 
759 void MainWindow::grabAllKeys(bool grabAllKeys)
760 {
761  kDebug(5010);
762 
763  RemoteView* view = currentRemoteView();
764  view->setGrabAllKeys(grabAllKeys);
765  view->hostPreferences()->setGrabAllKeys(grabAllKeys);
766  saveHostPrefs(view);
767 }
768 
769 void MainWindow::scale(bool scale)
770 {
771  kDebug(5010);
772 
773  RemoteView* view = currentRemoteView();
774  view->enableScaling(scale);
775  if (m_fullscreenWindow)
776  view->hostPreferences()->setFullscreenScale(scale);
777  else
778  view->hostPreferences()->setWindowedScale(scale);
779 
780  saveHostPrefs(view);
781 }
782 
783 void MainWindow::showRemoteViewToolbar()
784 {
785  kDebug(5010);
786 
787  if (!m_toolBar) {
788  actionCollection()->action("switch_fullscreen")->setIcon(KIcon("view-restore"));
789  actionCollection()->action("switch_fullscreen")->setText(i18n("Switch to Window Mode"));
790  actionCollection()->action("switch_fullscreen")->setIconText(i18n("Window Mode"));
791 
792  m_toolBar = new FloatingToolBar(m_fullscreenWindow, m_fullscreenWindow);
793  m_toolBar->winId(); // force it to be a native widget (prevents problem with QX11EmbedContainer)
794  m_toolBar->setSide(FloatingToolBar::Top);
795 
796  KComboBox *sessionComboBox = new KComboBox(m_toolBar);
797  sessionComboBox->setStyleSheet("QComboBox:!editable{background:transparent;}");
798  sessionComboBox->setModel(m_tabWidget->getModel());
799  sessionComboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
800  sessionComboBox->setCurrentIndex(m_tabWidget->currentIndex());
801  connect(sessionComboBox, SIGNAL(activated(int)), m_tabWidget, SLOT(setCurrentIndex(int)));
802  connect(m_tabWidget, SIGNAL(currentChanged(int)), sessionComboBox, SLOT(setCurrentIndex(int)));
803  m_toolBar->addWidget(sessionComboBox);
804 
805  QToolBar *buttonBox = new QToolBar(m_toolBar);
806 
807  buttonBox->addAction(actionCollection()->action("new_connection"));
808  buttonBox->addAction(actionCollection()->action("switch_fullscreen"));
809 
810  QAction *minimizeAction = new QAction(m_toolBar);
811  minimizeAction->setIcon(KIcon("go-down"));
812  minimizeAction->setText(i18n("Minimize Full Screen Window"));
813  connect(minimizeAction, SIGNAL(triggered()), m_fullscreenWindow, SLOT(showMinimized()));
814  buttonBox->addAction(minimizeAction);
815 
816  buttonBox->addAction(actionCollection()->action("take_screenshot"));
817  buttonBox->addAction(actionCollection()->action("view_only"));
818  buttonBox->addAction(actionCollection()->action("show_local_cursor"));
819  buttonBox->addAction(actionCollection()->action("grab_all_keys"));
820  buttonBox->addAction(actionCollection()->action("scale"));
821  buttonBox->addAction(actionCollection()->action("disconnect"));
822  buttonBox->addAction(actionCollection()->action("file_quit"));
823 
824  QAction *stickToolBarAction = new QAction(m_toolBar);
825  stickToolBarAction->setCheckable(true);
826  stickToolBarAction->setIcon(KIcon("object-locked"));
827  stickToolBarAction->setText(i18n("Stick Toolbar"));
828  connect(stickToolBarAction, SIGNAL(triggered(bool)), m_toolBar, SLOT(setSticky(bool)));
829  buttonBox->addAction(stickToolBarAction);
830 
831  m_toolBar->addWidget(buttonBox);
832  }
833 }
834 
835 void setActionStatus(QAction* action, bool enabled, bool visible, bool checked)
836 {
837  action->setEnabled(enabled);
838  action->setVisible(visible);
839  action->setChecked(checked);
840 }
841 
842 void MainWindow::updateActionStatus()
843 {
844  kDebug(5010) << m_tabWidget->currentIndex();
845 
846  bool enabled = true;
847 
848  if (m_tabWidget->currentWidget() == m_newConnectionWidget)
849  enabled = false;
850 
851  RemoteView* view = (m_currentRemoteView >= 0 && enabled) ? currentRemoteView() : 0;
852 
853  actionCollection()->action("take_screenshot")->setEnabled(enabled);
854  actionCollection()->action("disconnect")->setEnabled(enabled);
855 
856  setActionStatus(actionCollection()->action("view_only"),
857  enabled,
858  true,
859  view ? view->viewOnly() : false);
860 
861  setActionStatus(actionCollection()->action("show_local_cursor"),
862  enabled,
863  view ? view->supportsLocalCursor() : false,
864  view ? view->dotCursorState() == RemoteView::CursorOn : false);
865 
866  setActionStatus(actionCollection()->action("scale"),
867  enabled,
868  view ? view->supportsScaling() : false,
869  view ? view->scaling() : false);
870 
871  setActionStatus(actionCollection()->action("grab_all_keys"),
872  enabled,
873  enabled,
874  view ? view->grabAllKeys() : false);
875 }
876 
877 void MainWindow::preferences()
878 {
879  // An instance of your dialog could be already created and could be
880  // cached, in which case you want to display the cached dialog
881  // instead of creating another one
882  if (PreferencesDialog::showDialog("preferences"))
883  return;
884 
885  // KConfigDialog didn't find an instance of this dialog, so lets
886  // create it:
887  PreferencesDialog *dialog = new PreferencesDialog(this, Settings::self());
888 
889  // User edited the configuration - update your local copies of the
890  // configuration data
891  connect(dialog, SIGNAL(settingsChanged(QString)),
892  this, SLOT(updateConfiguration()));
893 
894  dialog->show();
895 }
896 
897 void MainWindow::updateConfiguration()
898 {
899  if (!Settings::showStatusBar())
900  statusBar()->deleteLater();
901  else
902  statusBar()->showMessage(""); // force creation of statusbar
903 
904  m_tabWidget->setTabBarHidden((m_tabWidget->count() <= 1 && !Settings::showTabBar()) || m_fullscreenWindow);
905  m_tabWidget->setTabPosition((KTabWidget::TabPosition) Settings::tabPosition());
906 #if QT_VERSION >= 0x040500
907  m_tabWidget->setTabsClosable(Settings::tabCloseButton());
908 #else
909  m_tabWidget->setCloseButtonEnabled(Settings::tabCloseButton());
910 #endif
911  disconnect(m_tabWidget, SIGNAL(mouseMiddleClick(QWidget*)), this, SLOT(closeTab(QWidget*))); // just be sure it is not connected twice
912  if (Settings::tabMiddleClick())
913  connect(m_tabWidget, SIGNAL(mouseMiddleClick(QWidget*)), SLOT(closeTab(QWidget*)));
914 
915  if (Settings::systemTrayIcon() && !m_systemTrayIcon) {
916  m_systemTrayIcon = new SystemTrayIcon(this);
917  if(m_fullscreenWindow) m_systemTrayIcon->setAssociatedWidget(m_fullscreenWindow);
918  } else if (m_systemTrayIcon) {
919  delete m_systemTrayIcon;
920  m_systemTrayIcon = 0;
921  }
922 
923  // update the scroll areas background color
924  for (int i = 0; i < m_tabWidget->count(); ++i) {
925  QPalette palette = m_tabWidget->widget(i)->palette();
926  palette.setColor(QPalette::Dark, Settings::backgroundColor());
927  m_tabWidget->widget(i)->setPalette(palette);
928  }
929 
930  // Send update configuration message to all views
931  foreach (RemoteView *view, m_remoteViewMap.values()) {
932  view->updateConfiguration();
933  }
934 
935 }
936 
937 void MainWindow::quit(bool systemEvent)
938 {
939  const bool haveRemoteConnections = !m_remoteViewMap.isEmpty();
940  if (systemEvent || !haveRemoteConnections || KMessageBox::warningContinueCancel(this,
941  i18n("Are you sure you want to quit the KDE Remote Desktop Client?"),
942  i18n("Confirm Quit"),
943  KStandardGuiItem::quit(), KStandardGuiItem::cancel(),
944  "DoNotAskBeforeExit") == KMessageBox::Continue) {
945 
946  if (Settings::rememberSessions()) { // remember open remote views for next startup
947  QStringList list;
948  foreach (RemoteView *view, m_remoteViewMap.values()) {
949  kDebug(5010) << view->url();
950  list.append(view->url().prettyUrl(KUrl::RemoveTrailingSlash));
951  }
952  Settings::setOpenSessions(list);
953  }
954 
955  saveHostPrefs();
956 
957  foreach (RemoteView *view, m_remoteViewMap.values()) {
958  view->startQuitting();
959  }
960 
961  Settings::self()->writeConfig();
962 
963  qApp->quit();
964  }
965 }
966 
967 void MainWindow::configureNotifications()
968 {
969  KNotifyConfigWidget::configure(this);
970 }
971 
972 void MainWindow::showMenubar()
973 {
974  if (m_menubarAction->isChecked())
975  menuBar()->show();
976  else
977  menuBar()->hide();
978 }
979 
980 bool MainWindow::eventFilter(QObject *obj, QEvent *event)
981 {
982  // check for close events from the fullscreen window.
983  if (obj == m_fullscreenWindow && event->type() == QEvent::Close) {
984  quit(true);
985  }
986  // allow other events to pass through.
987  return QObject::eventFilter(obj, event);
988 }
989 
990 void MainWindow::closeEvent(QCloseEvent *event)
991 {
992  if (event->spontaneous()) { // Returns true if the event originated outside the application (a system event); otherwise returns false.
993  event->ignore();
994  if (Settings::systemTrayIcon()) {
995  hide(); // just hide the mainwindow, keep it in systemtray
996  } else {
997  quit();
998  }
999  } else {
1000  quit(true);
1001  }
1002 }
1003 
1004 void MainWindow::saveProperties(KConfigGroup &group)
1005 {
1006  kDebug(5010);
1007  KMainWindow::saveProperties(group);
1008  saveHostPrefs();
1009 }
1010 
1011 
1012 void MainWindow::saveHostPrefs()
1013 {
1014  foreach (RemoteView *view, m_remoteViewMap.values()) {
1015  saveHostPrefs(view);
1016  view->startQuitting();
1017  }
1018 }
1019 
1020 void MainWindow::saveHostPrefs(RemoteView* view)
1021 {
1022  // should saving this be a user option?
1023  if (view && view->scaling()) {
1024  QSize viewSize = m_tabWidget->currentWidget()->size();
1025  kDebug(5010) << "saving window size:" << viewSize;
1026  view->hostPreferences()->setWidth(viewSize.width());
1027  view->hostPreferences()->setHeight(viewSize.height());
1028  }
1029 
1030  Settings::self()->config()->sync();
1031 }
1032 
1033 void MainWindow::tabChanged(int index)
1034 {
1035  kDebug(5010) << index;
1036 
1037  m_tabWidget->setTabBarHidden((m_tabWidget->count() <= 1 && !Settings::showTabBar()) || m_fullscreenWindow);
1038 
1039  m_currentRemoteView = index;
1040 
1041  if (m_tabWidget->currentWidget() == m_newConnectionWidget) {
1042  m_currentRemoteView = -1;
1043  if(m_addressInput) m_addressInput->setFocus();
1044  }
1045 
1046  const QString tabTitle = m_tabWidget->tabText(index).remove('&');
1047  setCaption(tabTitle == i18n("New Connection") ? QString() : tabTitle);
1048 
1049  updateActionStatus();
1050 }
1051 
1052 QWidget* MainWindow::newConnectionWidget()
1053 {
1054  if (m_newConnectionWidget)
1055  return m_newConnectionWidget;
1056 
1057  m_newConnectionWidget = new QWidget(this);
1058 
1059  QVBoxLayout *startLayout = new QVBoxLayout(m_newConnectionWidget);
1060  startLayout->setContentsMargins(QMargins(8, 12, 8, 4));
1061 
1062  QLabel *headerLabel = new QLabel(m_newConnectionWidget);
1063  headerLabel->setText(i18n("<h1>KDE Remote Desktop Client</h1><br />Enter or select the address of the desktop you would like to connect to."));
1064 
1065  QLabel *headerIconLabel = new QLabel(m_newConnectionWidget);
1066  headerIconLabel->setPixmap(KIcon("krdc").pixmap(80));
1067 
1068  QHBoxLayout *headerLayout = new QHBoxLayout;
1069  headerLayout->addWidget(headerLabel, 1, Qt::AlignTop);
1070  headerLayout->addWidget(headerIconLabel);
1071  startLayout->addLayout(headerLayout);
1072 
1073  QSortFilterProxyModel *remoteDesktopsModelProxy = new QSortFilterProxyModel(this);
1074  remoteDesktopsModelProxy->setSourceModel(m_remoteDesktopsModel);
1075  remoteDesktopsModelProxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
1076  remoteDesktopsModelProxy->setFilterRole(10002);
1077 
1078  {
1079  QHBoxLayout *connectLayout = new QHBoxLayout;
1080 
1081  QLabel *addressLabel = new QLabel(i18n("Connect to:"), m_newConnectionWidget);
1082  m_protocolInput = new KComboBox(m_newConnectionWidget);
1083  m_addressInput = new KLineEdit(m_newConnectionWidget);
1084  m_addressInput->setClearButtonShown(true);
1085  m_addressInput->setClickMessage(i18n("Type here to connect to an address and filter the list."));
1086  connect(m_addressInput, SIGNAL(textChanged(QString)), remoteDesktopsModelProxy, SLOT(setFilterFixedString(QString)));
1087 
1088  foreach(RemoteViewFactory *factory, m_remoteViewFactories) {
1089  m_protocolInput->addItem(factory->scheme());
1090  }
1091 
1092  connect(m_addressInput, SIGNAL(returnPressed()), SLOT(newConnection()));
1093  m_addressInput->setToolTip(i18n("Type an IP or DNS Name here. Clear the line to get a list of connection methods."));
1094 
1095  KPushButton *connectButton = new KPushButton(m_newConnectionWidget);
1096  connectButton->setToolTip(i18n("Goto Address"));
1097  connectButton->setIcon(KIcon("go-jump-locationbar"));
1098  connect(connectButton, SIGNAL(clicked()), SLOT(newConnection()));
1099 
1100  connectLayout->addWidget(addressLabel);
1101  connectLayout->addWidget(m_protocolInput);
1102  connectLayout->addWidget(m_addressInput, 1);
1103  connectLayout->addWidget(connectButton);
1104  connectLayout->setContentsMargins(QMargins(0, 6, 0, 10));
1105  startLayout->addLayout(connectLayout);
1106  }
1107 
1108  {
1109  m_newConnectionTableView = new QTableView(m_newConnectionWidget);
1110  m_newConnectionTableView->setModel(remoteDesktopsModelProxy);
1111 
1112  // set up the view so it looks nice
1113  m_newConnectionTableView->setItemDelegate(new ConnectionDelegate(m_newConnectionTableView));
1114  m_newConnectionTableView->setShowGrid(false);
1115  m_newConnectionTableView->setSelectionMode(QAbstractItemView::NoSelection);
1116  m_newConnectionTableView->verticalHeader()->hide();
1117  m_newConnectionTableView->verticalHeader()->setDefaultSectionSize(
1118  m_newConnectionTableView->fontMetrics().height() + 3);
1119  m_newConnectionTableView->horizontalHeader()->setStretchLastSection(true);
1120  m_newConnectionTableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
1121  m_newConnectionTableView->setAlternatingRowColors(true);
1122  // set up sorting and actions (double click open, right click custom menu)
1123  m_newConnectionTableView->setSortingEnabled(true);
1124  m_newConnectionTableView->sortByColumn(Settings::connectionListSortColumn(), Qt::SortOrder(Settings::connectionListSortOrder()));
1125  connect(m_newConnectionTableView->horizontalHeader(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)),
1126  SLOT(saveConnectionListSort(int,Qt::SortOrder)));
1127  connect(m_newConnectionTableView, SIGNAL(doubleClicked(QModelIndex)),
1128  SLOT(openFromRemoteDesktopsModel(QModelIndex)));
1129  m_newConnectionTableView->setContextMenuPolicy(Qt::CustomContextMenu);
1130  connect(m_newConnectionTableView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showConnectionContextMenu(QPoint)));
1131 
1132  startLayout->addWidget(m_newConnectionTableView);
1133  }
1134 
1135  return m_newConnectionWidget;
1136 }
1137 
1138 void MainWindow::saveConnectionListSort(const int logicalindex, const Qt::SortOrder order)
1139 {
1140  Settings::setConnectionListSortColumn(logicalindex);
1141  Settings::setConnectionListSortOrder(order);
1142  Settings::self()->writeConfig();
1143 }
1144 
1145 void MainWindow::newConnectionPage(bool clearInput)
1146 {
1147  const int indexOfNewConnectionWidget = m_tabWidget->indexOf(m_newConnectionWidget);
1148  if (indexOfNewConnectionWidget >= 0)
1149  m_tabWidget->setCurrentIndex(indexOfNewConnectionWidget);
1150  else {
1151  const int index = m_tabWidget->addTab(newConnectionWidget(), i18n("New Connection"));
1152  m_tabWidget->setCurrentIndex(index);
1153  }
1154  if(clearInput) {
1155  m_addressInput->clear();
1156  } else {
1157  m_addressInput->selectAll();
1158  }
1159  m_addressInput->setFocus();
1160 }
1161 
1162 QMap<QWidget *, RemoteView *> MainWindow::remoteViewList() const
1163 {
1164  return m_remoteViewMap;
1165 }
1166 
1167 QList<RemoteViewFactory *> MainWindow::remoteViewFactoriesList() const
1168 {
1169  return m_remoteViewFactories.values();
1170 }
1171 
1172 RemoteView* MainWindow::currentRemoteView() const
1173 {
1174  if (m_currentRemoteView >= 0) {
1175  return m_remoteViewMap.value(m_tabWidget->widget(m_currentRemoteView));
1176  } else {
1177  return 0;
1178  }
1179 }
1180 
1181 void MainWindow::createDockWidget()
1182 {
1183  QDockWidget *remoteDesktopsDockWidget = new QDockWidget(this);
1184  QWidget *remoteDesktopsDockLayoutWidget = new QWidget(remoteDesktopsDockWidget);
1185  QVBoxLayout *remoteDesktopsDockLayout = new QVBoxLayout(remoteDesktopsDockLayoutWidget);
1186  remoteDesktopsDockWidget->setObjectName("remoteDesktopsDockWidget"); // required for saving position / state
1187  remoteDesktopsDockWidget->setWindowTitle(i18n("Remote Desktops"));
1188  QFontMetrics fontMetrics(remoteDesktopsDockWidget->font());
1189  remoteDesktopsDockWidget->setMinimumWidth(fontMetrics.width("vnc://192.168.100.100:6000"));
1190  actionCollection()->addAction("remote_desktop_dockwidget",
1191  remoteDesktopsDockWidget->toggleViewAction());
1192 
1193  m_dockWidgetTableView = new QTableView(remoteDesktopsDockLayoutWidget);
1194  m_remoteDesktopsModel = new RemoteDesktopsModel(this);
1195  QSortFilterProxyModel *remoteDesktopsModelProxy = new QSortFilterProxyModel(this);
1196  remoteDesktopsModelProxy->setSourceModel(m_remoteDesktopsModel);
1197  remoteDesktopsModelProxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
1198  remoteDesktopsModelProxy->setFilterRole(10002);
1199  m_dockWidgetTableView->setModel(remoteDesktopsModelProxy);
1200 
1201  m_dockWidgetTableView->setShowGrid(false);
1202  m_dockWidgetTableView->verticalHeader()->hide();
1203  m_dockWidgetTableView->verticalHeader()->setDefaultSectionSize(
1204  m_dockWidgetTableView->fontMetrics().height() + 2);
1205  m_dockWidgetTableView->horizontalHeader()->hide();
1206  m_dockWidgetTableView->horizontalHeader()->setStretchLastSection(true);
1207  // hide all columns, then show the one we want
1208  for (int i=0; i < remoteDesktopsModelProxy->columnCount(); i++) {
1209  m_dockWidgetTableView->hideColumn(i);
1210  }
1211  m_dockWidgetTableView->showColumn(RemoteDesktopsModel::Title);
1212  m_dockWidgetTableView->sortByColumn(RemoteDesktopsModel::Title, Qt::AscendingOrder);
1213 
1214  connect(m_dockWidgetTableView, SIGNAL(doubleClicked(QModelIndex)),
1215  SLOT(openFromRemoteDesktopsModel(QModelIndex)));
1216 
1217  KLineEdit *filterLineEdit = new KLineEdit(remoteDesktopsDockLayoutWidget);
1218  filterLineEdit->setClickMessage(i18n("Filter"));
1219  filterLineEdit->setClearButtonShown(true);
1220  connect(filterLineEdit, SIGNAL(textChanged(QString)), remoteDesktopsModelProxy, SLOT(setFilterFixedString(QString)));
1221  remoteDesktopsDockLayout->addWidget(filterLineEdit);
1222  remoteDesktopsDockLayout->addWidget(m_dockWidgetTableView);
1223  remoteDesktopsDockWidget->setWidget(remoteDesktopsDockLayoutWidget);
1224  addDockWidget(Qt::LeftDockWidgetArea, remoteDesktopsDockWidget);
1225 }
1226 
1227 #include "mainwindow.moc"
HostPreferences::setShownWhileConnected
void setShownWhileConnected(bool connected)
If connected is true, a message is shown that settings might only apply after a reconnect.
Definition: hostpreferences.cpp:234
MainWindow::saveProperties
virtual void saveProperties(KConfigGroup &group)
Definition: mainwindow.cpp:1004
Settings::connectionListSortColumn
static int connectionListSortColumn()
Get ConnectionListSortColumn.
Definition: settings.h:334
TabbedViewWidget::removeTab
void removeTab(int index)
Definition: tabbedviewwidget.cpp:164
RemoteView::takeScreenshot
virtual QPixmap takeScreenshot()
Definition: remoteview.cpp:160
setActionStatus
void setActionStatus(QAction *action, bool enabled, bool visible, bool checked)
Definition: mainwindow.cpp:835
RemoteView::CursorOff
Never show local cursor, only the remote one.
Definition: remoteview.h:86
HostPreferences::windowedScale
bool windowedScale()
Whether scaling is enabled when session is not full screen.
Definition: hostpreferences.cpp:119
RemoteView::RemoteStatus
RemoteStatus
State of the connection.
Definition: remoteview.h:108
PreferencesDialog
Definition: preferencesdialog.h:32
FloatingToolBar::Top
Definition: floatingtoolbar.h:46
RemoteView::showDotCursor
virtual void showDotCursor(DotCursorState state)
Sets the state of the dot cursor, if supported by the backend.
Definition: remoteview.cpp:165
MainWindow::saveHostPrefs
void saveHostPrefs()
Definition: mainwindow.cpp:1012
bookmarkmanager.h
FloatingToolBar::hideAndDestroy
void hideAndDestroy()
Definition: floatingtoolbar.cpp:168
HostPreferences::setWindowedScale
void setWindowedScale(bool scale)
Definition: hostpreferences.cpp:124
ConnectionDelegate
Definition: connectiondelegate.h:29
hostpreferences.h
Settings::setConnectionListSortColumn
static void setConnectionListSortColumn(int v)
Set ConnectionListSortColumn.
Definition: settings.h:324
RemoteView::supportsScaling
virtual bool supportsScaling() const
Checks whether the backend supports scaling.
Definition: remoteview.cpp:91
HostPreferences::showDialog
bool showDialog(QWidget *parent)
Show the configuration dialog.
Definition: hostpreferences.cpp:177
Settings::resizeOnConnect
static bool resizeOnConnect()
Get ResizeOnConnect.
Definition: settings.h:125
Settings::setOpenSessions
static void setOpenSessions(const QStringList &v)
Set Sessions.
Definition: settings.h:58
tubesmanager.h
QWidget
HostPreferences::grabAllKeys
bool grabAllKeys()
Definition: hostpreferences.cpp:129
MainWindow::closeEvent
virtual void closeEvent(QCloseEvent *event)
Definition: mainwindow.cpp:990
BookmarkManager::getManager
KBookmarkManager * getManager()
Definition: bookmarkmanager.cpp:167
Settings::openSessions
static QStringList openSessions()
Get Sessions.
Definition: settings.h:68
MainWindow::newConnection
void newConnection(const KUrl &newUrl=KUrl(), bool switchFullscreenWhenConnected=false, const QString &tabName=QString())
Definition: mainwindow.cpp:284
TabbedViewWidget::addTab
int addTab(QWidget *page, const QString &label)
Definition: tabbedviewwidget.cpp:122
QObject
HostPreferences::fullscreenScale
bool fullscreenScale()
Whether scaling is enabled when session is full screen.
Definition: hostpreferences.cpp:109
Settings::systemTrayIcon
static bool systemTrayIcon()
Get SystemTrayIcon.
Definition: settings.h:201
TubesManager
Definition: tubesmanager.h:32
QScrollArea
RemoteDesktopsModel::Title
Definition: remotedesktopsmodel.h:67
RemoteView::CursorOn
Always show local cursor (and the remote one).
Definition: remoteview.h:85
MinimizePixel
Definition: mainwindow.h:145
MainWindow::currentRemoteView
RemoteView * currentRemoteView() const
Definition: mainwindow.cpp:1172
Settings::tabMiddleClick
static bool tabMiddleClick()
Get TabMiddleClick.
Definition: settings.h:258
RemoteView::grabAllKeys
virtual bool grabAllKeys()
Checks whether grabbing all possible keys is enabled.
Definition: remoteview.cpp:143
RemoteView
Generic widget that displays a remote framebuffer.
Definition: remoteview.h:59
RemoteView::scaling
virtual bool scaling() const
Checks whether the widget is in scale mode.
Definition: remoteview.cpp:175
systemtrayicon.h
HostPreferences::setShowLocalCursor
void setShowLocalCursor(bool show)
Definition: hostpreferences.cpp:144
Settings::self
static Settings * self()
Definition: settings.cpp:17
floatingtoolbar.h
RemoteView::Disconnecting
Definition: remoteview.h:113
RemoteViewFactory::createHostPreferences
virtual HostPreferences * createHostPreferences(KConfigGroup configGroup, QWidget *parent)=0
Returns a new HostPreferences implementing object or 0 if no settings are available.
KXmlGuiWindow
FloatingToolBar
A toolbar widget that slides in from a side.
Definition: floatingtoolbar.h:38
RemoteDesktopsModel
Definition: remotedesktopsmodel.h:59
tabbedviewwidget.h
QToolBar
preferencesdialog.h
HostPreferences::setGrabAllKeys
void setGrabAllKeys(bool grab)
Definition: hostpreferences.cpp:134
RemoteView::dotCursorState
virtual DotCursorState dotCursorState() const
Returns the state of the local cursor.
Definition: remoteview.cpp:170
mainwindow.h
MainWindow::MainWindow
MainWindow(QWidget *parent=0)
Definition: mainwindow.cpp:76
RemoteView::hostPreferences
virtual HostPreferences * hostPreferences()=0
Returns the current host preferences of this view.
HostPreferences::setWidth
void setWidth(int width)
Definition: hostpreferences.cpp:98
RemoteViewFactory::scheme
virtual QString scheme() const =0
Returns the supported scheme.
BookmarkManager::updateTitle
static void updateTitle(KBookmarkManager *manager, const QString &url, const QString &title)
Definition: bookmarkmanager.cpp:209
RemoteView::Connecting
Definition: remoteview.h:109
Settings::backgroundColor
static QColor backgroundColor()
Get BackgroundColor.
Definition: settings.h:163
RemoteView::setViewOnly
virtual void setViewOnly(bool viewOnly)
Enables/disables the view-only mode.
Definition: remoteview.cpp:138
RemoteView::setGrabAllKeys
virtual void setGrabAllKeys(bool grabAllKeys)
Enables/disables grabbing all possible keys.
Definition: remoteview.cpp:148
RemoteViewScrollArea
Definition: mainwindow.h:167
RemoteView::url
KUrl url()
Definition: remoteview.cpp:193
TabbedViewWidget
Definition: tabbedviewwidget.h:51
BookmarkManager::addManualBookmark
void addManualBookmark(const QString &url, const QString &text)
Definition: bookmarkmanager.cpp:161
TabbedViewWidget::getModel
TabbedViewWidgetModel * getModel()
Definition: tabbedviewwidget.cpp:117
Settings::showTabBar
static bool showTabBar()
Get ShowTabBar.
Definition: settings.h:296
remotedesktopsmodel.h
Settings::connectionListSortOrder
static int connectionListSortOrder()
Get ConnectionListSortOrder.
Definition: settings.h:353
RemoteView::viewOnly
virtual bool viewOnly()
Checks whether the view is in view-only mode.
Definition: remoteview.cpp:133
HostPreferences
Definition: hostpreferences.h:42
RemoteView::Authenticating
Definition: remoteview.h:110
Settings::rememberHistory
static bool rememberHistory()
Get RememberHistory.
Definition: settings.h:49
settings.h
HostPreferences::setFullscreenScale
void setFullscreenScale(bool scale)
Definition: hostpreferences.cpp:114
RemoteView::enableScaling
virtual void enableScaling(bool scale)
Called to enable or disable scaling.
Definition: remoteview.cpp:180
SystemTrayIcon
Definition: systemtrayicon.h:31
RemoteView::startQuitting
virtual void startQuitting()
Initiate the disconnection.
Definition: remoteview.cpp:111
RemoteView::updateConfiguration
virtual void updateConfiguration()
Called when the configuration is changed.
Definition: remoteview.cpp:125
Settings::fullscreenOnConnect
static bool fullscreenOnConnect()
Get FullscreenOnConnect.
Definition: settings.h:144
RemoteView::supportsLocalCursor
virtual bool supportsLocalCursor() const
Checks whether the backend supports the concept of local cursors.
Definition: remoteview.cpp:96
HostPreferences::setViewOnly
void setViewOnly(bool view)
Definition: hostpreferences.cpp:154
HostPreferences::viewOnly
bool viewOnly()
Definition: hostpreferences.cpp:149
Settings::tabPosition
static int tabPosition()
Get TabPosition.
Definition: settings.h:277
RemoteView::host
virtual QString host()
Definition: remoteview.cpp:101
RemoteViewFactory::supportsUrl
virtual bool supportsUrl(const KUrl &url) const =0
Returns true if the provided url is supported by the current plugin.
RemoteView::start
virtual bool start()=0
Initialize the view (for example by showing configuration dialogs to the user) and start connecting...
BookmarkManager::removeByUrl
static void removeByUrl(KBookmarkManager *manager, const QString &url, bool ignoreHistory=false, const QString updateTitle=QString())
Definition: bookmarkmanager.cpp:189
Settings::rememberSessions
static bool rememberSessions()
Get RememberSessions.
Definition: settings.h:30
RemoteDesktopsModel::Source
Definition: remotedesktopsmodel.h:67
remoteview.h
connectiondelegate.h
MainWindow::~MainWindow
~MainWindow()
Definition: mainwindow.cpp:141
FloatingToolBar::setSide
void setSide(Side side)
Definition: floatingtoolbar.cpp:132
BookmarkManager::addHistoryBookmark
void addHistoryBookmark(RemoteView *view)
Definition: bookmarkmanager.cpp:66
Settings::showStatusBar
static bool showStatusBar()
Get ShowStatusBar.
Definition: settings.h:315
RemoteViewFactory::createView
virtual RemoteView * createView(QWidget *parent, const KUrl &url, KConfigGroup configGroup)=0
Returns a new RemoteView implementing object.
RemoteViewFactory
Factory to be implemented by any plugin.
Definition: remoteviewfactory.h:52
TabbedViewWidget::removePage
void removePage(QWidget *page)
Definition: tabbedviewwidget.cpp:156
HostPreferences::setHeight
void setHeight(int height)
Definition: hostpreferences.cpp:87
RemoteView::Disconnected
Definition: remoteview.h:114
HostPreferences::showDialogIfNeeded
bool showDialogIfNeeded(QWidget *parent)
Show the configuration dialog if needed, ie.
Definition: hostpreferences.cpp:159
MainWindow::remoteViewFactoriesList
QList< RemoteViewFactory * > remoteViewFactoriesList() const
Definition: mainwindow.cpp:1167
RemoteView::Connected
Definition: remoteview.h:112
MainWindow::eventFilter
bool eventFilter(QObject *obj, QEvent *event)
Definition: mainwindow.cpp:980
HostPreferences::showLocalCursor
bool showLocalCursor()
Definition: hostpreferences.cpp:139
Settings::setConnectionListSortOrder
static void setConnectionListSortOrder(int v)
Set ConnectionListSortOrder.
Definition: settings.h:343
Settings::tabCloseButton
static bool tabCloseButton()
Get TabCloseButton.
Definition: settings.h:239
RemoteView::Preparing
Definition: remoteview.h:111
MainWindow::remoteViewList
QMap< QWidget *, RemoteView * > remoteViewList() const
Definition: mainwindow.cpp:1162
BookmarkManager
Definition: bookmarkmanager.h:36
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:54:04 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

krdc

Skip menu "krdc"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal