1 /****************************************************************************
3 ** Copyright (C) 2007 Urs Wolfer <uwolfer @ kde.org>
5 ** This file is part of KDE.
7 ** This program is free software; you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License as published by
9 ** the Free Software Foundation; either version 2 of the License, or
10 ** (at your option) any later version.
12 ** This program is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ** GNU General Public License for more details.
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program; see the file COPYING. If not, write to
19 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 ** Boston, MA 02110-1301, USA.
22 ****************************************************************************/
24 #include "mainwindow.h"
26 #include "remoteview.h"
28 #include "config/preferencesdialog.h"
29 #include "floatingtoolbar.h"
30 #include "bookmarkmanager.h"
31 #include "remotedesktopsmodel.h"
32 #include "systemtrayicon.h"
43 #include "zeroconfpage.h"
47 #include <KActionCollection>
48 #include <KActionMenu>
49 #include <KApplication>
51 #include <KEditToolBar>
55 #include <KMessageBox>
56 #include <KNotifyConfigWidget>
57 #include <KPushButton>
59 #include <KShortcutsDialog>
62 #include <KToggleAction>
63 #include <KToggleFullScreenAction>
64 #include <KUrlNavigator>
67 #include <QCloseEvent>
68 #include <QDesktopWidget>
69 #include <QDockWidget>
70 #include <QHeaderView>
73 #include <QScrollArea>
75 #include <QToolButton>
79 MainWindow::MainWindow(QWidget
*parent
)
80 : KXmlGuiWindow(parent
),
81 m_fullscreenWindow(0),
85 m_currentRemoteView(-1),
86 m_showStartPage(false),
92 setStandardToolBarMenuEnabled(true);
94 m_tabWidget
= new KTabWidget(this);
95 m_tabWidget
->setMinimumSize(600, 400);
96 setCentralWidget(m_tabWidget
);
98 QDockWidget
*remoteDesktopsDockWidget
= new QDockWidget(this);
99 remoteDesktopsDockWidget
->setObjectName("remoteDesktopsDockWidget");
100 remoteDesktopsDockWidget
->setWindowTitle("Remote desktops");
101 actionCollection()->addAction("remote_desktop_dockwidget",
102 remoteDesktopsDockWidget
->toggleViewAction());
103 QTreeView
*remoteDesktopsTreeView
= new QTreeView(remoteDesktopsDockWidget
);
104 remoteDesktopsTreeView
->setModel(new RemoteDesktopsModel(this));
105 remoteDesktopsTreeView
->header()->hide();
106 connect(remoteDesktopsTreeView
, SIGNAL(doubleClicked(const QModelIndex
&)),
107 SLOT(openFromDockWidget(const QModelIndex
&)));
109 remoteDesktopsDockWidget
->setWidget(remoteDesktopsTreeView
);
110 addDockWidget(Qt::LeftDockWidgetArea
, remoteDesktopsDockWidget
);
112 createGUI("krdcui.rc");
114 if (Settings::systemTrayIcon()) {
115 m_systemTrayIcon
= new SystemTrayIcon(this);
116 m_systemTrayIcon
->setVisible(true);
119 connect(m_tabWidget
, SIGNAL(currentChanged(int)), SLOT(tabChanged(int)));
121 statusBar()->showMessage(i18n("KDE Remote Desktop Client started"));
123 updateActionStatus(); // disable remote view actions
125 if (Settings::showStartPage())
128 setAutoSaveSettings(); // e.g toolbar position, mainwindow size, ...
130 if (Settings::rememberSessions()) // give some time to create and show the window first
131 QTimer::singleShot(100, this, SLOT(restoreOpenSessions()));
133 remoteDesktopsDockWidget
->setVisible(false); //TODO: remove when fully implemented
136 MainWindow::~MainWindow()
140 void MainWindow::setupActions()
142 QAction
*vncConnectionAction
= actionCollection()->addAction("new_vnc_connection");
143 vncConnectionAction
->setText(i18n("New VNC Connection..."));
144 vncConnectionAction
->setIcon(KIcon("network-connect"));
145 connect(vncConnectionAction
, SIGNAL(triggered()), SLOT(newVncConnection()));
147 vncConnectionAction
->setVisible(false);
150 QAction
*nxConnectionAction
= actionCollection()->addAction("new_nx_connection");
151 nxConnectionAction
->setText(i18n("New NX Connection..."));
152 nxConnectionAction
->setIcon(KIcon("network-connect"));
153 connect(nxConnectionAction
, SIGNAL(triggered()), SLOT(newNxConnection()));
155 nxConnectionAction
->setVisible(false);
158 QAction
*rdpConnectionAction
= actionCollection()->addAction("new_rdp_connection");
159 rdpConnectionAction
->setText(i18n("New RDP Connection..."));
160 rdpConnectionAction
->setIcon(KIcon("network-connect"));
161 connect(rdpConnectionAction
, SIGNAL(triggered()), SLOT(newRdpConnection()));
163 rdpConnectionAction
->setVisible(false);
166 QAction
*zeroconfAction
= actionCollection()->addAction("zeroconf_page");
167 zeroconfAction
->setText(i18n("Browse Remote Desktop Services on Local Network..."));
168 zeroconfAction
->setIcon(KIcon("network-connect"));
169 connect(zeroconfAction
, SIGNAL(triggered()), SLOT(createZeroconfPage()));
170 #ifndef BUILD_ZEROCONF
171 zeroconfAction
->setVisible(false);
175 QAction
*screenshotAction
= actionCollection()->addAction("take_screenshot");
176 screenshotAction
->setText(i18n("Copy Screenshot to Clipboard"));
177 screenshotAction
->setIcon(KIcon("ksnapshot"));
178 connect(screenshotAction
, SIGNAL(triggered()), SLOT(takeScreenshot()));
180 QAction
*fullscreenAction
= actionCollection()->addAction("switch_fullscreen");
181 fullscreenAction
->setText(i18n("Switch to Fullscreen Mode"));
182 fullscreenAction
->setIcon(KIcon("view-fullscreen"));
183 connect(fullscreenAction
, SIGNAL(triggered()), SLOT(switchFullscreen()));
185 QAction
*viewOnlyAction
= actionCollection()->addAction("view_only");
186 viewOnlyAction
->setCheckable(true);
187 viewOnlyAction
->setText(i18n("View Only"));
188 viewOnlyAction
->setIcon(KIcon("document-preview"));
189 connect(viewOnlyAction
, SIGNAL(triggered(bool)), SLOT(viewOnly(bool)));
191 QAction
*logoutAction
= actionCollection()->addAction("logout");
192 logoutAction
->setText(i18n("Log Out"));
193 logoutAction
->setIcon(KIcon("system-log-out"));
194 connect(logoutAction
, SIGNAL(triggered()), SLOT(logout()));
196 QAction
*showLocalCursorAction
= actionCollection()->addAction("show_local_cursor");
197 showLocalCursorAction
->setCheckable(true);
198 showLocalCursorAction
->setIcon(KIcon("input-mouse"));
199 showLocalCursorAction
->setText(i18n("Show Local Cursor"));
200 connect(showLocalCursorAction
, SIGNAL(triggered(bool)), SLOT(showLocalCursor(bool)));
202 QAction
*grabAllKeysAction
= actionCollection()->addAction("grab_all_keys");
203 grabAllKeysAction
->setCheckable(true);
204 grabAllKeysAction
->setIcon(KIcon("configure-shortcuts"));
205 grabAllKeysAction
->setText(i18n("Grab all possible keys"));
206 connect(grabAllKeysAction
, SIGNAL(triggered(bool)), SLOT(grabAllKeys(bool)));
208 QAction
*quitAction
= KStandardAction::quit(this, SLOT(quit()), actionCollection());
209 actionCollection()->addAction("quit", quitAction
);
210 QAction
*preferencesAction
= KStandardAction::preferences(this, SLOT(preferences()), actionCollection());
211 actionCollection()->addAction("preferences", preferencesAction
);
212 QAction
*configToolbarAction
= KStandardAction::configureToolbars(this, SLOT(configureToolbars()), actionCollection());
213 actionCollection()->addAction("configure_toolbars", configToolbarAction
);
214 QAction
*keyBindingsAction
= KStandardAction::keyBindings(this, SLOT(configureKeys()), actionCollection());
215 actionCollection()->addAction("configure_keys", keyBindingsAction
);
216 QAction
*cinfigNotifyAction
= KStandardAction::configureNotifications(this, SLOT(configureNotifications()), actionCollection());
217 cinfigNotifyAction
->setVisible(false);
218 actionCollection()->addAction("configure_notifications", cinfigNotifyAction
);
219 m_menubarAction
= KStandardAction::showMenubar(this, SLOT(showMenubar()), actionCollection());
220 m_menubarAction
->setChecked(!menuBar()->isHidden());
221 actionCollection()->addAction("settings_showmenubar", m_menubarAction
);
223 QString initialProtocol
;
225 initialProtocol
= "rdp";
228 initialProtocol
= "nx";
231 initialProtocol
= "vnc";
234 m_addressNavigator
= new KUrlNavigator(0, KUrl(initialProtocol
+ "://"), this);
235 m_addressNavigator
->setCustomProtocols(QStringList()
246 m_addressNavigator
->setUrlEditable(Settings::normalUrlInputLine());
247 connect(m_addressNavigator
, SIGNAL(returnPressed()), SLOT(newConnection()));
249 QLabel
*addressLabel
= new QLabel(i18n("Remote desktop:"), this);
251 QWidget
*addressWidget
= new QWidget(this);
252 QHBoxLayout
*addressLayout
= new QHBoxLayout(addressWidget
);
253 addressLayout
->setMargin(0);
254 addressLayout
->addWidget(addressLabel
);
255 addressLayout
->addWidget(m_addressNavigator
, 1);
257 KAction
*addressLineAction
= new KAction(i18nc("Title for remote address input action", "Address"), this);
258 actionCollection()->addAction("address_line", addressLineAction
);
259 addressLineAction
->setDefaultWidget(addressWidget
);
261 QAction
*gotoAction
= actionCollection()->addAction("goto_address");
262 gotoAction
->setText(i18n("Goto Address"));
263 gotoAction
->setIcon(KIcon("go-jump-locationbar"));
264 connect(gotoAction
, SIGNAL(triggered()), SLOT(newConnection()));
266 KActionMenu
*bookmarkMenu
= new KActionMenu(i18n("Bookmarks"), actionCollection());
267 m_bookmarkManager
= new BookmarkManager(actionCollection(), bookmarkMenu
->menu(), this);
268 actionCollection()->addAction("bookmark" , bookmarkMenu
);
269 connect(m_bookmarkManager
, SIGNAL(openUrl(KUrl
)), SLOT(newConnection(KUrl
)));
272 void MainWindow::restoreOpenSessions()
274 QStringList list
= Settings::openSessions();
275 QStringList::Iterator it
= list
.begin();
276 QStringList::Iterator end
= list
.end();
283 void MainWindow::newConnection(const KUrl
&newUrl
, bool switchFullscreenWhenConnected
)
285 m_switchFullscreenWhenConnected
= switchFullscreenWhenConnected
;
287 KUrl url
= newUrl
.isEmpty() ? m_addressNavigator
->uncommittedUrl() : newUrl
;
289 if (!url
.isValid() || (url
.host().isEmpty() && url
.port() < 0)
290 || !url
.path().isEmpty()) {
291 KMessageBox::error(this,
292 i18n("The entered address does not have the required form."),
293 i18n("Malformed URL"));
297 m_addressNavigator
->setUrl(KUrl(url
.scheme().toLower() + "://"));
299 QScrollArea
*scrollArea
= createScrollArea(m_tabWidget
, 0);
304 if (url
.scheme().toLower() == "vnc") {
305 view
= new VncView(scrollArea
, url
);
310 if (url
.scheme().toLower() == "nx") {
311 view
= new NxView(scrollArea
, url
);
316 if (url
.scheme().toLower() == "rdp") {
317 view
= new RdpView(scrollArea
, url
);
321 KMessageBox::error(this,
322 i18n("The entered address cannot be handled."),
323 i18n("Unusable URL"));
327 connect(view
, SIGNAL(changeSize(int, int)), this, SLOT(resizeTabWidget(int, int)));
328 connect(view
, SIGNAL(statusChanged(RemoteView::RemoteStatus
)), this, SLOT(statusChanged(RemoteView::RemoteStatus
)));
330 m_remoteViewList
.append(view
);
334 int numNonRemoteView
= 0;
340 scrollArea
->setWidget(m_remoteViewList
.at(m_remoteViewList
.count() - 1));
342 int newIndex
= m_tabWidget
->addTab(scrollArea
, KIcon("krdc"), url
.prettyUrl(KUrl::RemoveTrailingSlash
));
343 m_tabWidget
->setCurrentIndex(newIndex
);
344 tabChanged(newIndex
); // force to update m_currentRemoteView (tabChanged is not emitted when start page has been disabled)
349 void MainWindow::openFromDockWidget(const QModelIndex
&index
)
351 KUrl
url(index
.data().toString());
357 void MainWindow::resizeTabWidget(int w
, int h
)
359 kDebug(5010) << "tabwidget resize: w: " << w
<< ", h: " << h
;
361 if (m_topBottomBorder
== 0) { // the values are not cached yet
362 QScrollArea
*tmp
= qobject_cast
<QScrollArea
*>(m_tabWidget
->currentWidget());
364 m_leftRightBorder
= m_tabWidget
->width() - m_tabWidget
->currentWidget()->width() + (2 * tmp
->frameWidth());
365 m_topBottomBorder
= m_tabWidget
->height() - m_tabWidget
->currentWidget()->height() + (2 * tmp
->frameWidth());
367 kDebug(5010) << "tabwidget border: w: " << m_leftRightBorder
<< ", h: " << m_topBottomBorder
;
370 int newTabWidth
= w
+ m_leftRightBorder
;
371 int newTabHeight
= h
+ m_topBottomBorder
;
373 QSize newWindowSize
= size() - m_tabWidget
->size() + QSize(newTabWidth
, newTabHeight
);
375 QSize desktopSize
= QSize(QApplication::desktop()->availableGeometry().width(),
376 QApplication::desktop()->availableGeometry().height());
378 if ((newWindowSize
.height() >= desktopSize
.height()) || (newWindowSize
.width() >= desktopSize
.width())) {
379 kDebug(5010) << "remote desktop needs more place than available -> show window maximized";
380 setWindowState(windowState() | Qt::WindowMaximized
);
384 //WORKAROUND: QTabWidget resize problem. Let's see if there is a clean solution for this issue.
385 m_tabWidget
->setMinimumSize(newTabWidth
, newTabHeight
);
386 m_tabWidget
->adjustSize();
387 QCoreApplication::processEvents();
388 m_tabWidget
->setMinimumSize(500, 400);
391 void MainWindow::statusChanged(RemoteView::RemoteStatus status
)
393 kDebug(5010) << status
;
395 // the remoteview is already deleted, so don't show it; otherwise it would crash
396 if (status
== RemoteView::Disconnecting
|| status
== RemoteView::Disconnected
)
399 QString host
= m_remoteViewList
.at(m_currentRemoteView
)->host();
401 QString iconName
= "krdc";
405 case RemoteView::Connecting
:
406 iconName
= "network-connect";
407 message
= i18n("Connecting to %1", host
);
409 case RemoteView::Authenticating
:
410 iconName
= "dialog-password";
411 message
= i18n("Authenticating at %1", host
);
413 case RemoteView::Preparing
:
414 iconName
= "view-history";
415 message
= i18n("Preparing connection to %1", host
);
417 case RemoteView::Connected
:
419 message
= i18n("Connected to %1", host
);
421 // when started with command line fullscreen argument
422 if (m_switchFullscreenWhenConnected
) {
423 m_switchFullscreenWhenConnected
= false;
427 m_bookmarkManager
->addHistoryBookmark();
435 m_tabWidget
->setTabIcon(m_tabWidget
->currentIndex(), KIcon(iconName
));
436 statusBar()->showMessage(message
);
439 void MainWindow::takeScreenshot()
441 QPixmap snapshot
= QPixmap::grabWidget(m_remoteViewList
.at(m_currentRemoteView
));
443 QApplication::clipboard()->setPixmap(snapshot
);
446 void MainWindow::switchFullscreen()
450 if (m_fullscreenWindow
) {
452 restoreGeometry(m_mainWindowGeometry
);
454 m_fullscreenWindow
->setWindowState(0);
455 m_fullscreenWindow
->hide();
457 QScrollArea
*scrollArea
= createScrollArea(m_tabWidget
, m_remoteViewList
.at(m_currentRemoteView
));
459 int currentTab
= m_tabWidget
->currentIndex();
460 m_tabWidget
->insertTab(currentTab
, scrollArea
, m_tabWidget
->tabIcon(currentTab
), m_tabWidget
->tabText(currentTab
));
461 m_tabWidget
->removeTab(m_tabWidget
->currentIndex());
462 m_tabWidget
->setCurrentIndex(currentTab
);
464 resizeTabWidget(m_remoteViewList
.at(m_currentRemoteView
)->sizeHint().width(),
465 m_remoteViewList
.at(m_currentRemoteView
)->sizeHint().height());
468 m_toolBar
->hideAndDestroy();
473 actionCollection()->action("switch_fullscreen")->setIcon(KIcon("view-fullscreen"));
474 actionCollection()->action("switch_fullscreen")->setText(i18n("Switch to Fullscreen Mode"));
476 m_fullscreenWindow
->deleteLater();
478 m_fullscreenWindow
= 0;
480 m_fullscreenWindow
= new QWidget(this, Qt::Window
);
481 m_fullscreenWindow
->setWindowTitle(i18nc("window title when in fullscreen mode (for example displayed in tasklist)",
482 "KDE Remote Desktop Client (Fullscreen)"));
484 QScrollArea
*scrollArea
= createScrollArea(m_fullscreenWindow
, m_remoteViewList
.at(m_currentRemoteView
));
485 scrollArea
->setFrameShape(QFrame::NoFrame
);
487 QVBoxLayout
*fullscreenLayout
= new QVBoxLayout(m_fullscreenWindow
);
488 fullscreenLayout
->setMargin(0);
489 fullscreenLayout
->addWidget(scrollArea
);
491 MinimizePixel
*minimizePixel
= new MinimizePixel(m_fullscreenWindow
);
492 connect(minimizePixel
, SIGNAL(rightClicked()), m_fullscreenWindow
, SLOT(showMinimized()));
494 m_fullscreenWindow
->show();
496 KToggleFullScreenAction::setFullScreen(m_fullscreenWindow
, true);
498 // show the toolbar after we have switched to fullscreen mode
499 QTimer::singleShot(100, this, SLOT(showRemoteViewToolbar()));
501 m_mainWindowGeometry
= saveGeometry();
506 QScrollArea
*MainWindow::createScrollArea(QWidget
*parent
, RemoteView
*remoteView
)
508 QScrollArea
*scrollArea
= new QScrollArea(parent
);
509 scrollArea
->setAlignment(Qt::AlignHCenter
| Qt::AlignVCenter
);
511 QPalette palette
= scrollArea
->palette();
512 palette
.setColor(QPalette::Dark
, Settings::backgroundColor());
513 scrollArea
->setPalette(palette
);
515 scrollArea
->setBackgroundRole(QPalette::Dark
);
516 scrollArea
->setWidget(remoteView
);
521 void MainWindow::logout()
525 if (m_fullscreenWindow
) { // first close fullscreen view
529 QWidget
*tmp
= m_tabWidget
->currentWidget();
531 m_remoteViewList
.removeAt(m_currentRemoteView
);
533 m_tabWidget
->removeTab(m_tabWidget
->currentIndex());
538 void MainWindow::showLocalCursor(bool showLocalCursor
)
540 kDebug(5010) << showLocalCursor
;
542 m_remoteViewList
.at(m_currentRemoteView
)->showDotCursor(showLocalCursor
? RemoteView::CursorOn
: RemoteView::CursorOff
);
545 void MainWindow::viewOnly(bool viewOnly
)
547 kDebug(5010) << viewOnly
;
549 m_remoteViewList
.at(m_currentRemoteView
)->setViewOnly(viewOnly
);
552 void MainWindow::grabAllKeys(bool grabAllKeys
)
556 m_remoteViewList
.at(m_currentRemoteView
)->setGrabAllKeys(grabAllKeys
);
559 void MainWindow::showRemoteViewToolbar()
564 actionCollection()->action("switch_fullscreen")->setIcon(KIcon("view-restore"));
565 actionCollection()->action("switch_fullscreen")->setText(i18n("Switch to Window Mode"));
567 m_toolBar
= new FloatingToolBar(m_fullscreenWindow
, m_fullscreenWindow
);
568 m_toolBar
->setSide(FloatingToolBar::Top
);
570 QLabel
*hostLabel
= new QLabel(m_remoteViewList
.at(m_currentRemoteView
)->url().prettyUrl(KUrl::RemoveTrailingSlash
), m_toolBar
);
571 hostLabel
->setMargin(4);
572 QFont
font(hostLabel
->font());
574 hostLabel
->setFont(font
);
575 m_toolBar
->addWidget(hostLabel
);
577 #if 0 //TODO: implement functionality
578 KComboBox
*sessionComboBox
= new KComboBox(m_toolBar
);
579 sessionComboBox
->setEditable(false);
580 sessionComboBox
->addItem(i18n("Switch to..."));
581 for (int i
= 0; i
< m_remoteViewList
.count(); i
++) {
582 sessionComboBox
->addItem(m_remoteViewList
.at(i
)->url().prettyUrl(KUrl::RemoveTrailingSlash
));
584 sessionComboBox
->setVisible(m_remoteViewList
.count() > 1); // just show it if there are sessions to switch
585 m_toolBar
->addWidget(sessionComboBox
);
588 m_toolBar
->addAction(actionCollection()->action("switch_fullscreen"));
590 QAction
*minimizeAction
= new QAction(m_toolBar
);
591 minimizeAction
->setIcon(KIcon("window-suppressed"));
592 minimizeAction
->setText(i18n("Minimize Fullscreen Window"));
593 connect(minimizeAction
, SIGNAL(triggered()), m_fullscreenWindow
, SLOT(showMinimized()));
594 m_toolBar
->addAction(minimizeAction
);
596 m_toolBar
->addAction(actionCollection()->action("take_screenshot"));
597 m_toolBar
->addAction(actionCollection()->action("view_only"));
598 m_toolBar
->addAction(actionCollection()->action("show_local_cursor"));
599 m_toolBar
->addAction(actionCollection()->action("grab_all_keys"));
600 m_toolBar
->addAction(actionCollection()->action("logout"));
602 QAction
*stickToolBarAction
= new QAction(m_toolBar
);
603 stickToolBarAction
->setCheckable(true);
604 stickToolBarAction
->setIcon(KIcon("object-locked"));
605 stickToolBarAction
->setText(i18n("Stick Toolbar"));
606 connect(stickToolBarAction
, SIGNAL(triggered(bool)), m_toolBar
, SLOT(setSticky(bool)));
607 m_toolBar
->addAction(stickToolBarAction
);
610 m_toolBar
->showAndAnimate();
613 void MainWindow::updateActionStatus()
615 kDebug(5010) << m_tabWidget
->currentIndex();
619 if ((m_showStartPage
&& (m_tabWidget
->currentIndex() == 0)) ||
620 #ifdef BUILD_ZEROCONF
621 (m_zeroconfPage
&& (m_tabWidget
->currentIndex() == m_tabWidget
->indexOf(m_zeroconfPage
))) ||
623 (!m_showStartPage
&& (m_tabWidget
->currentIndex() < 0)))
628 actionCollection()->action("switch_fullscreen")->setEnabled(enabled
);
629 actionCollection()->action("take_screenshot")->setEnabled(enabled
);
630 actionCollection()->action("view_only")->setEnabled(enabled
);
631 actionCollection()->action("grab_all_keys")->setEnabled(enabled
);
632 actionCollection()->action("logout")->setEnabled(enabled
);
634 bool viewOnlyChecked
= false;
635 if (m_currentRemoteView
>= 0)
636 viewOnlyChecked
= enabled
&& m_remoteViewList
.at(m_currentRemoteView
)->viewOnly();
637 actionCollection()->action("view_only")->setChecked(viewOnlyChecked
);
639 bool showLocalCursorChecked
= false;
640 if (m_currentRemoteView
>= 0)
641 showLocalCursorChecked
= enabled
&& m_remoteViewList
.at(m_currentRemoteView
)->dotCursorState() == RemoteView::CursorOn
;
642 actionCollection()->action("show_local_cursor")->setChecked(showLocalCursorChecked
);
644 bool showLocalCursorVisible
= false;
645 if (m_currentRemoteView
>= 0)
646 showLocalCursorVisible
= enabled
&& m_remoteViewList
.at(m_currentRemoteView
)->supportsLocalCursor();
647 actionCollection()->action("show_local_cursor")->setVisible(showLocalCursorVisible
);
650 void MainWindow::preferences()
652 // An instance of your dialog could be already created and could be
653 // cached, in which case you want to display the cached dialog
654 // instead of creating another one
655 if (PreferencesDialog::showDialog("preferences"))
658 // KConfigDialog didn't find an instance of this dialog, so lets
660 PreferencesDialog
*dialog
= new PreferencesDialog(this, Settings::self());
662 // User edited the configuration - update your local copies of the
663 // configuration data
664 connect(dialog
, SIGNAL(settingsChanged(const QString
&)),
665 this, SLOT(updateConfiguration()));
670 void MainWindow::updateConfiguration()
672 m_addressNavigator
->setUrlEditable(Settings::normalUrlInputLine());
674 if (Settings::systemTrayIcon() && !m_systemTrayIcon
) {
675 m_systemTrayIcon
= new SystemTrayIcon(this);
676 m_systemTrayIcon
->setVisible(true);
677 } else if (m_systemTrayIcon
) {
678 delete m_systemTrayIcon
;
679 m_systemTrayIcon
= 0;
682 if (Settings::showStartPage() && !m_showStartPage
)
684 else if (!Settings::showStartPage() && m_showStartPage
) {
685 m_tabWidget
->removeTab(0);
686 m_showStartPage
= false;
688 updateActionStatus();
690 // update the scroll areas background color
691 int numNonRemoteView
= 0;
696 for (int i
= numNonRemoteView
; i
< m_tabWidget
->count(); i
++) {
697 QPalette palette
= m_tabWidget
->widget(i
)->palette();
698 palette
.setColor(QPalette::Dark
, Settings::backgroundColor());
699 m_tabWidget
->widget(i
)->setPalette(palette
);
703 void MainWindow::quit()
705 if (KMessageBox::warningContinueCancel(this,
706 i18n("Are you sure you want to quit the KDE Remote Desktop Client?"),
707 i18n("Confirm Quit"),
708 KStandardGuiItem::quit(), KStandardGuiItem::cancel(),
709 "DoNotAskBeforeExit") == KMessageBox::Continue
) {
711 if (Settings::rememberSessions()) { // remember open remote views for next startup
713 for (int i
= 0; i
< m_remoteViewList
.count(); i
++) {
714 kDebug(5010) << m_remoteViewList
.at(i
)->url();
715 list
.append(m_remoteViewList
.at(i
)->url().prettyUrl(KUrl::RemoveTrailingSlash
));
717 Settings::setOpenSessions(list
);
720 Settings::self()->writeConfig();
726 void MainWindow::configureNotifications()
728 KNotifyConfigWidget::configure(this);
731 void MainWindow::configureKeys()
733 KShortcutsDialog::configure(actionCollection());
736 void MainWindow::configureToolbars()
738 KEditToolBar
edit(actionCollection());
739 connect(&edit
, SIGNAL(newToolbarConfig()), this, SLOT(newToolbarConfig()));
743 void MainWindow::showMenubar()
745 if (m_menubarAction
->isChecked())
751 void MainWindow::closeEvent(QCloseEvent
*event
)
755 if (Settings::systemTrayIcon()) {
756 hide(); // just hide the mainwindow, keep it in systemtray
762 void MainWindow::tabChanged(int index
)
764 kDebug(5010) << index
;
766 int numNonRemoteView
= 0;
772 m_currentRemoteView
= index
- numNonRemoteView
;
774 QString tabTitle
= m_tabWidget
->tabText(index
).remove('&');
776 setCaption(tabTitle
== i18n("Start Page") ? QString() : tabTitle
);
778 updateActionStatus();
781 void MainWindow::createStartPage()
783 m_showStartPage
= true;
785 QWidget
*startWidget
= new QWidget(this);
786 startWidget
->setStyleSheet("QWidget { background-color: palette(base) }");
788 QVBoxLayout
*startLayout
= new QVBoxLayout(startWidget
);
790 QLabel
*headerLabel
= new QLabel(this);
791 headerLabel
->setText(i18n("<h1>KDE Remote Desktop Client</h1><br /><br />What would you like to do?<br />"));
793 QLabel
*headerIconLabel
= new QLabel(this);
794 headerIconLabel
->setPixmap(KIcon("krdc").pixmap(128));
796 QHBoxLayout
*headerLayout
= new QHBoxLayout
;
797 headerLayout
->setMargin(20);
798 headerLayout
->addWidget(headerLabel
, 1, Qt::AlignTop
);
799 headerLayout
->addWidget(headerIconLabel
);
801 KPushButton
*vncConnectButton
= new KPushButton(this);
802 vncConnectButton
->setStyleSheet("KPushButton { padding: 12px; margin: 10px; }");
803 vncConnectButton
->setIcon(KIcon(actionCollection()->action("new_vnc_connection")->icon()));
804 vncConnectButton
->setText(i18n("Connect to a VNC Remote Desktop"));
805 connect(vncConnectButton
, SIGNAL(clicked()), SLOT(newVncConnection()));
807 vncConnectButton
->setVisible(false);
810 KPushButton
*nxConnectButton
= new KPushButton(this);
811 nxConnectButton
->setStyleSheet("KPushButton { padding: 12px; margin: 10px; }");
812 nxConnectButton
->setIcon(KIcon(actionCollection()->action("new_nx_connection")->icon()));
813 nxConnectButton
->setText(i18n("Connect to a NX Remote Desktop"));
814 connect(nxConnectButton
, SIGNAL(clicked()), SLOT(newNxConnection()));
816 nxConnectButton
->setVisible(false);
819 KPushButton
*rdpConnectButton
= new KPushButton(this);
820 rdpConnectButton
->setStyleSheet("KPushButton { padding: 12px; margin: 10px; }");
821 rdpConnectButton
->setIcon(KIcon(actionCollection()->action("new_rdp_connection")->icon()));
822 rdpConnectButton
->setText(i18n("Connect to a Windows Remote Desktop (RDP)"));
823 connect(rdpConnectButton
, SIGNAL(clicked()), SLOT(newRdpConnection()));
825 rdpConnectButton
->setVisible(false);
828 KPushButton
*zeroconfButton
= new KPushButton(this);
829 zeroconfButton
->setStyleSheet("KPushButton { padding: 12px; margin: 10px; }");
830 zeroconfButton
->setIcon(KIcon(actionCollection()->action("zeroconf_page")->icon()));
831 zeroconfButton
->setText(i18n("Browse Remote Desktop Services on Local Network"));
832 connect(zeroconfButton
, SIGNAL(clicked()), SLOT(createZeroconfPage()));
833 #ifndef BUILD_ZEROCONF
834 zeroconfButton
->setVisible(false);
837 startLayout
->addLayout(headerLayout
);
838 startLayout
->addWidget(vncConnectButton
);
839 startLayout
->addWidget(nxConnectButton
);
840 startLayout
->addWidget(rdpConnectButton
);
841 startLayout
->addWidget(zeroconfButton
);
842 startLayout
->addStretch();
844 m_tabWidget
->insertTab(0, startWidget
, KIcon("krdc"), i18n("Start Page"));
847 void MainWindow::newVncConnection()
849 m_addressNavigator
->setUrl(KUrl("vnc://"));
850 m_addressNavigator
->setFocus();
852 QToolTip::showText(m_addressNavigator
->pos() + pos() + QPoint(m_addressNavigator
->width(),
853 m_addressNavigator
->height() + 20),
854 i18n("<html>Enter the address here.<br />"
855 "<i>Example: vncserver:1 (host:port / screen)</i></html>"), this);
858 void MainWindow::newNxConnection()
860 m_addressNavigator
->setUrl(KUrl("nx://"));
861 m_addressNavigator
->setFocus();
863 QToolTip::showText(m_addressNavigator
->pos() + pos() + QPoint(m_addressNavigator
->width(),
864 m_addressNavigator
->height() + 20),
865 i18n("<html>Enter the address here.<br />"
866 "<i>Example: nxserver (host)</i></html>"), this);
869 void MainWindow::newRdpConnection()
871 m_addressNavigator
->setUrl(KUrl("rdp://"));
872 m_addressNavigator
->setFocus();
874 QToolTip::showText(m_addressNavigator
->pos() + pos() + QPoint(m_addressNavigator
->width(),
875 m_addressNavigator
->height() + 20),
876 i18n("<html>Enter the address here. Port is optional.<br />"
877 "<i>Example: rdpserver:3389 (host:port)</i></html>"), this);
880 void MainWindow::createZeroconfPage()
882 #ifdef BUILD_ZEROCONF
886 m_zeroconfPage
= new ZeroconfPage(this);
887 connect(m_zeroconfPage
, SIGNAL(newConnection(const KUrl
, bool)), this, SLOT(newConnection(const KUrl
, bool)));
888 connect(m_zeroconfPage
, SIGNAL(closeZeroconfPage()), this, SLOT(closeZeroconfPage()));
889 int zeroconfTabIndex
= m_tabWidget
->insertTab(m_showStartPage
? 1 : 0, m_zeroconfPage
, KIcon("krdc"), i18n("Browse Local Network"));
890 m_tabWidget
->setCurrentIndex(zeroconfTabIndex
);
894 void MainWindow::closeZeroconfPage()
896 #ifdef BUILD_ZEROCONF
897 int index
= m_tabWidget
->indexOf(m_zeroconfPage
);
898 m_tabWidget
->removeTab(index
);
899 m_zeroconfPage
->deleteLater();
901 tabChanged(index
); // force update again because m_zeroconfPage was not null before
905 QList
<RemoteView
*> MainWindow::remoteViewList() const
907 return m_remoteViewList
;
910 int MainWindow::currentRemoteView() const
912 return m_currentRemoteView
;
915 #include "mainwindow.moc"