tell the truth
[kdenetwork.git] / krdc / mainwindow.cpp
blob27b0365bd62cac474abbaec17d08befc1ccab22a
1 /****************************************************************************
2 **
3 ** Copyright (C) 2007 Urs Wolfer <uwolfer @ kde.org>
4 **
5 ** This file is part of KDE.
6 **
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"
27 #include "settings.h"
28 #include "config/preferencesdialog.h"
29 #include "floatingtoolbar.h"
30 #include "bookmarkmanager.h"
31 #include "systemtrayicon.h"
32 #include "specialkeysdialog.h"
33 #ifdef BUILD_RDP
34 #include "rdpview.h"
35 #endif
36 #ifdef BUILD_NX
37 #include "nxview.h"
38 #endif
39 #ifdef BUILD_VNC
40 #include "vncview.h"
41 #endif
43 #include <KAction>
44 #include <KActionCollection>
45 #include <KActionMenu>
46 #include <KApplication>
47 #include <KEditToolBar>
48 #include <KIcon>
49 #include <KLocale>
50 #include <KMenuBar>
51 #include <KMessageBox>
52 #include <KNotifyConfigWidget>
53 #include <KPushButton>
54 #include <KShortcut>
55 #include <KShortcutsDialog>
56 #include <KStatusBar>
57 #include <KTabWidget>
58 #include <KToggleAction>
59 #include <KUrlNavigator>
61 #include <QClipboard>
62 #include <QCloseEvent>
63 #include <QDesktopWidget>
64 #include <QLabel>
65 #include <QLayout>
66 #include <QScrollArea>
67 #include <QTimer>
68 #include <QToolButton>
69 #include <QToolTip>
71 MainWindow::MainWindow(QWidget *parent)
72 : KXmlGuiWindow(parent),
73 m_fullscreenWindow(0),
74 m_toolBar(0),
75 m_topBottomBorder(0),
76 m_leftRightBorder(0),
77 m_currentRemoteView(-1),
78 m_showStartPage(false),
79 m_systemTrayIcon(0)
81 setupActions();
83 createGUI("krdcui.rc");
85 setStandardToolBarMenuEnabled(true);
87 m_tabWidget = new KTabWidget(this);
88 m_tabWidget->setMinimumSize(600, 400);
89 setCentralWidget(m_tabWidget);
91 if (Settings::systemTrayIcon()) {
92 m_systemTrayIcon = new SystemTrayIcon(this);
93 m_systemTrayIcon->setVisible(true);
96 connect(m_tabWidget, SIGNAL(currentChanged(int)), SLOT(tabChanged(int)));
98 statusBar()->showMessage(i18n("KDE Remote Desktop Client started"));
100 updateActionStatus(); // disable remote view actions
102 if (Settings::showStartPage())
103 createStartPage();
105 setAutoSaveSettings(); // e.g toolbar position, mainwindow size, ...
107 if (Settings::rememberSessions()) // give some time to create and show the window first
108 QTimer::singleShot(100, this, SLOT(restoreOpenSessions()));
111 MainWindow::~MainWindow()
115 void MainWindow::setupActions()
117 QAction *vncConnectionAction = actionCollection()->addAction("new_vnc_connection");
118 vncConnectionAction->setText(i18n("New VNC Connection..."));
119 vncConnectionAction->setIcon(KIcon("network-connect"));
120 connect(vncConnectionAction, SIGNAL(triggered()), SLOT(newVncConnection()));
121 #ifndef BUILD_VNC
122 vncConnectionAction->setVisible(false);
123 #endif
125 QAction *nxConnectionAction = actionCollection()->addAction("new_nx_connection");
126 nxConnectionAction->setText(i18n("New NX Connection..."));
127 nxConnectionAction->setIcon(KIcon("network-connect"));
128 connect(nxConnectionAction, SIGNAL(triggered()), SLOT(newNxConnection()));
129 #ifndef BUILD_NX
130 nxConnectionAction->setVisible(false);
131 #endif
133 QAction *rdpConnectionAction = actionCollection()->addAction("new_rdp_connection");
134 rdpConnectionAction->setText(i18n("New RDP Connection..."));
135 rdpConnectionAction->setIcon(KIcon("network-connect"));
136 connect(rdpConnectionAction, SIGNAL(triggered()), SLOT(newRdpConnection()));
137 #ifndef BUILD_RDP
138 rdpConnectionAction->setVisible(false);
139 #endif
141 QAction *screenshotAction = actionCollection()->addAction("take_screenshot");
142 screenshotAction->setText(i18n("Copy Screenshot to Clipboard"));
143 screenshotAction->setIcon(KIcon("ksnapshot"));
144 connect(screenshotAction, SIGNAL(triggered()), SLOT(takeScreenshot()));
146 QAction *fullscreenAction = actionCollection()->addAction("switch_fullscreen");
147 fullscreenAction->setText(i18n("Switch to Fullscreen Mode"));
148 fullscreenAction->setIcon(KIcon("view-fullscreen"));
149 connect(fullscreenAction, SIGNAL(triggered()), SLOT(switchFullscreen()));
151 QAction *viewOnlyAction = actionCollection()->addAction("view_only");
152 viewOnlyAction->setCheckable(true);
153 viewOnlyAction->setText(i18n("View Only"));
154 viewOnlyAction->setIcon(KIcon("document-preview"));
155 connect(viewOnlyAction, SIGNAL(triggered(bool)), SLOT(viewOnly(bool)));
157 QAction *logoutAction = actionCollection()->addAction("logout");
158 logoutAction->setText(i18n("Log Out"));
159 logoutAction->setIcon(KIcon("system-log-out"));
160 connect(logoutAction, SIGNAL(triggered()), SLOT(logout()));
162 QAction *showLocalCursorAction = actionCollection()->addAction("show_local_cursor");
163 showLocalCursorAction->setCheckable(true);
164 showLocalCursorAction->setIcon(KIcon("input-mouse"));
165 showLocalCursorAction->setText(i18n("Show Local Cursor"));
166 connect(showLocalCursorAction, SIGNAL(triggered(bool)), SLOT(showLocalCursor(bool)));
168 QAction *specialKeysDialogAction = actionCollection()->addAction("special_keys_dialog");
169 specialKeysDialogAction->setIcon(KIcon("configure-shortcuts"));
170 specialKeysDialogAction->setText(i18n("Open Special Keys Dialog..."));
171 connect(specialKeysDialogAction, SIGNAL(triggered()), SLOT(specialKeyDialog()));
173 QAction *quitAction = KStandardAction::quit(this, SLOT(quit()), actionCollection());
174 actionCollection()->addAction("quit", quitAction);
175 QAction *preferencesAction = KStandardAction::preferences(this, SLOT(preferences()), actionCollection());
176 actionCollection()->addAction("preferences", preferencesAction);
177 QAction *configToolbarAction = KStandardAction::configureToolbars(this, SLOT(configureToolbars()), actionCollection());
178 actionCollection()->addAction("configure_toolbars", configToolbarAction);
179 QAction *keyBindingsAction = KStandardAction::keyBindings(this, SLOT(configureKeys()), actionCollection());
180 actionCollection()->addAction("configure_keys", keyBindingsAction);
181 QAction *cinfigNotifyAction = KStandardAction::configureNotifications(this, SLOT(configureNotifications()), actionCollection());
182 cinfigNotifyAction->setVisible(false);
183 actionCollection()->addAction("configure_notifications", cinfigNotifyAction);
184 m_menubarAction = KStandardAction::showMenubar(this, SLOT(showMenubar()), actionCollection());
185 m_menubarAction->setChecked(!menuBar()->isHidden());
186 actionCollection()->addAction("settings_showmenubar", m_menubarAction);
188 QString initialProtocol;
189 #ifdef BUILD_RDP
190 initialProtocol = "rdp";
191 #endif
192 #ifdef BUILD_NX
193 initialProtocol = "nx";
194 #endif
195 #ifdef BUILD_VNC
196 initialProtocol = "vnc";
197 #endif
199 m_addressNavigator = new KUrlNavigator(0, KUrl(initialProtocol + "://"), this);
200 m_addressNavigator->setCustomProtocols(QStringList()
201 #ifdef BUILD_VNC
202 << "vnc"
203 #endif
204 #ifdef BUILD_NX
205 << "nx"
206 #endif
207 #ifdef BUILD_RDP
208 << "rdp"
209 #endif
211 m_addressNavigator->setUrlEditable(Settings::normalUrlInputLine());
212 connect(m_addressNavigator, SIGNAL(returnPressed()), SLOT(newConnection()));
214 QLabel *addressLabel = new QLabel(i18n("Remote desktop:"), this);
216 QWidget *addressWidget = new QWidget(this);
217 QHBoxLayout *addressLayout = new QHBoxLayout(addressWidget);
218 addressLayout->setMargin(0);
219 addressLayout->addWidget(addressLabel);
220 addressLayout->addWidget(m_addressNavigator, 1);
222 KAction *addressLineAction = new KAction(i18nc("Title for remote address input action", "Address"), this);
223 actionCollection()->addAction("address_line", addressLineAction);
224 addressLineAction->setDefaultWidget(addressWidget);
226 QAction *gotoAction = actionCollection()->addAction("goto_address");
227 gotoAction->setText(i18n("Goto Address"));
228 gotoAction->setIcon(KIcon("go-jump-locationbar"));
229 connect(gotoAction, SIGNAL(triggered()), SLOT(newConnection()));
231 KActionMenu *bookmarkMenu = new KActionMenu(i18n("Bookmarks"), actionCollection());
232 m_bookmarkManager = new BookmarkManager(actionCollection(), bookmarkMenu->menu(), this);
233 actionCollection()->addAction("bookmark" , bookmarkMenu);
234 connect(m_bookmarkManager, SIGNAL(openUrl(KUrl)), SLOT(newConnection(KUrl)));
237 void MainWindow::restoreOpenSessions()
239 QStringList list = Settings::openSessions();
240 QStringList::Iterator it = list.begin();
241 QStringList::Iterator end = list.end();
242 while (it != end) {
243 newConnection(*it);
244 ++it;
248 void MainWindow::newConnection(const KUrl &newUrl, bool switchFullscreenWhenConnected)
250 m_switchFullscreenWhenConnected = switchFullscreenWhenConnected;
252 KUrl url = newUrl.isEmpty() ? m_addressNavigator->uncommittedUrl() : newUrl;
254 if (!url.isValid() || (url.host().isEmpty() && url.port() < 0)
255 || !url.path().isEmpty()) {
256 KMessageBox::error(this,
257 i18n("The entered address does not have the required form."),
258 i18n("Malformed URL"));
259 return;
262 m_addressNavigator->setUrl(KUrl(url.scheme().toLower() + "://"));
264 QScrollArea *scrollArea = createScrollArea(m_tabWidget, 0);
266 RemoteView *view;
268 #ifdef BUILD_VNC
269 if (url.scheme().toLower() == "vnc") {
270 view = new VncView(scrollArea, url);
271 } else
272 #endif
274 #ifdef BUILD_NX
275 if (url.scheme().toLower() == "nx") {
276 view = new NxView(scrollArea, url);
277 } else
278 #endif
280 #ifdef BUILD_RDP
281 if (url.scheme().toLower() == "rdp") {
282 view = new RdpView(scrollArea, url);
283 } else
284 #endif
286 KMessageBox::error(this,
287 i18n("The entered address cannot be handled."),
288 i18n("Unusable URL"));
289 return;
292 connect(view, SIGNAL(changeSize(int, int)), this, SLOT(resizeTabWidget(int, int)));
293 connect(view, SIGNAL(statusChanged(RemoteView::RemoteStatus)), this, SLOT(statusChanged(RemoteView::RemoteStatus)));
295 m_remoteViewList.append(view);
297 view->resize(0, 0);
299 scrollArea->setWidget(m_remoteViewList.at(m_tabWidget->count() - (m_showStartPage ? 1 : 0)));
301 int newIndex = m_tabWidget->addTab(scrollArea, KIcon("krdc"), url.prettyUrl(KUrl::RemoveTrailingSlash));
302 m_tabWidget->setCurrentIndex(newIndex);
303 tabChanged(newIndex); // force to update m_currentRemoteView (tabChanged is not emitted when start page has been disabled)
305 view->start();
308 void MainWindow::resizeTabWidget(int w, int h)
310 kDebug(5010) << "tabwidget resize: w: " << w << ", h: " << h;
312 if (m_topBottomBorder == 0) { // the values are not cached yet
313 QScrollArea *tmp = qobject_cast<QScrollArea *>(m_tabWidget->currentWidget());
315 m_leftRightBorder = m_tabWidget->width() - m_tabWidget->currentWidget()->width() + (2 * tmp->frameWidth());
316 m_topBottomBorder = m_tabWidget->height() - m_tabWidget->currentWidget()->height() + (2 * tmp->frameWidth());
318 kDebug(5010) << "tabwidget border: w: " << m_leftRightBorder << ", h: " << m_topBottomBorder;
321 int newTabWidth = w + m_leftRightBorder;
322 int newTabHeight = h + m_topBottomBorder;
324 QSize newWindowSize = size() - m_tabWidget->size() + QSize(newTabWidth, newTabHeight);
326 QSize desktopSize = QSize(QApplication::desktop()->availableGeometry().width(),
327 QApplication::desktop()->availableGeometry().height());
329 if ((newWindowSize.height() >= desktopSize.height()) || (newWindowSize.width() >= desktopSize.width())) {
330 kDebug(5010) << "remote desktop needs more place than available -> show window maximized";
331 showMaximized();
332 QCoreApplication::processEvents();
333 return;
336 //WORKAROUND: QTabWidget resize problem. Let's see if there is a clean solution for this issue.
337 m_tabWidget->setMinimumSize(newTabWidth, newTabHeight);
338 m_tabWidget->adjustSize();
339 QCoreApplication::processEvents();
340 m_tabWidget->setMinimumSize(500, 400);
343 void MainWindow::statusChanged(RemoteView::RemoteStatus status)
345 kDebug(5010) << status;
347 // the remoteview is already deleted, so don't show it; otherwise it would crash
348 if (status == RemoteView::Disconnecting || status == RemoteView::Disconnected)
349 return;
351 QString host = m_remoteViewList.at(m_currentRemoteView)->host();
353 QString iconName = "krdc";
354 QString message;
356 switch (status) {
357 case RemoteView::Connecting:
358 iconName = "network-connect";
359 message = i18n("Connecting to %1", host);
360 break;
361 case RemoteView::Authenticating:
362 iconName = "dialog-password";
363 message = i18n("Authenticating at %1", host);
364 break;
365 case RemoteView::Preparing:
366 iconName = "view-history";
367 message = i18n("Preparing connection to %1", host);
368 break;
369 case RemoteView::Connected:
370 iconName = "krdc";
371 message = i18n("Connected to %1", host);
373 // when started with command line fullscreen argument
374 if (m_switchFullscreenWhenConnected) {
375 m_switchFullscreenWhenConnected = false;
376 switchFullscreen();
379 m_bookmarkManager->addHistoryBookmark();
381 break;
382 default:
383 iconName = "krdc";
384 message = QString();
387 m_tabWidget->setTabIcon(m_tabWidget->currentIndex(), KIcon(iconName));
388 statusBar()->showMessage(message);
391 void MainWindow::takeScreenshot()
393 QPixmap snapshot = QPixmap::grabWidget(m_remoteViewList.at(m_currentRemoteView));
395 QApplication::clipboard()->setPixmap(snapshot);
398 void MainWindow::switchFullscreen()
400 kDebug(5010);
402 if (m_fullscreenWindow) {
403 show();
404 restoreGeometry(m_mainWindowGeometry);
406 m_fullscreenWindow->setWindowState(0);
407 m_fullscreenWindow->hide();
409 QScrollArea *scrollArea = createScrollArea(m_tabWidget, m_remoteViewList.at(m_currentRemoteView));
411 int currentTab = m_tabWidget->currentIndex();
412 m_tabWidget->insertTab(currentTab, scrollArea, m_tabWidget->tabIcon(currentTab), m_tabWidget->tabText(currentTab));
413 m_tabWidget->removeTab(m_tabWidget->currentIndex());
414 m_tabWidget->setCurrentIndex(currentTab);
416 resizeTabWidget(m_remoteViewList.at(m_currentRemoteView)->sizeHint().width(),
417 m_remoteViewList.at(m_currentRemoteView)->sizeHint().height());
419 if (m_toolBar) {
420 m_toolBar->hideAndDestroy();
421 m_toolBar = 0;
424 actionCollection()->action("switch_fullscreen")->setIcon(KIcon("view-fullscreen"));
425 actionCollection()->action("switch_fullscreen")->setText(i18n("Switch to Fullscreen Mode"));
427 m_fullscreenWindow->deleteLater();
429 m_fullscreenWindow = 0;
430 } else {
431 m_fullscreenWindow = new QWidget(this, Qt::Window);
432 m_fullscreenWindow->setWindowTitle(i18nc("window title when in fullscreen mode (for example displayed in tasklist)",
433 "KDE Remote Desktop Client (Fullscreen)"));
435 QScrollArea *scrollArea = createScrollArea(m_fullscreenWindow, m_remoteViewList.at(m_currentRemoteView));
436 scrollArea->setFrameShape(QFrame::NoFrame);
438 QVBoxLayout *fullscreenLayout = new QVBoxLayout(m_fullscreenWindow);
439 fullscreenLayout->setMargin(0);
440 fullscreenLayout->addWidget(scrollArea);
442 MinimizePixel *minimizePixel = new MinimizePixel(m_fullscreenWindow);
443 connect(minimizePixel, SIGNAL(rightClicked()), m_fullscreenWindow, SLOT(showMinimized()));
445 m_fullscreenWindow->show();
447 m_fullscreenWindow->setWindowState(Qt::WindowFullScreen);
449 // show the toolbar after we have switched to fullscreen mode
450 QTimer::singleShot(100, this, SLOT(showRemoteViewToolbar()));
452 m_mainWindowGeometry = saveGeometry();
453 hide();
457 QScrollArea *MainWindow::createScrollArea(QWidget *parent, RemoteView *remoteView)
459 QScrollArea *scrollArea = new QScrollArea(parent);
460 scrollArea->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
462 QPalette palette = scrollArea->palette();
463 palette.setColor(QPalette::Dark, Settings::backgroundColor());
464 scrollArea->setPalette(palette);
466 scrollArea->setBackgroundRole(QPalette::Dark);
467 scrollArea->setWidget(remoteView);
469 return scrollArea;
472 void MainWindow::logout()
474 kDebug(5010);
476 if (m_fullscreenWindow) { // first close fullscreen view
477 switchFullscreen();
480 QWidget *tmp = m_tabWidget->currentWidget();
482 m_remoteViewList.removeAt(m_currentRemoteView);
484 m_tabWidget->removeTab(m_tabWidget->currentIndex());
486 tmp->deleteLater();
488 updateActionStatus();
491 void MainWindow::showLocalCursor(bool showLocalCursor)
493 kDebug(5010) << showLocalCursor;
495 m_remoteViewList.at(m_currentRemoteView)->showDotCursor(showLocalCursor ? RemoteView::CursorOn : RemoteView::CursorOff);
498 void MainWindow::viewOnly(bool viewOnly)
500 kDebug(5010) << viewOnly;
502 m_remoteViewList.at(m_currentRemoteView)->setViewOnly(viewOnly);
505 void MainWindow::specialKeyDialog()
507 kDebug(5010);
509 SpecialKeysDialog dialog(this, m_remoteViewList.at(m_currentRemoteView));
510 dialog.exec();
513 void MainWindow::showRemoteViewToolbar()
515 kDebug(5010);
517 if (!m_toolBar) {
518 actionCollection()->action("switch_fullscreen")->setIcon(KIcon("view-restore"));
519 actionCollection()->action("switch_fullscreen")->setText(i18n("Switch to Window Mode"));
521 m_toolBar = new FloatingToolBar(m_fullscreenWindow, m_fullscreenWindow);
522 m_toolBar->setSide(FloatingToolBar::Top);
523 m_toolBar->addAction(actionCollection()->action("switch_fullscreen"));
525 QAction *minimizeAction = new QAction(m_toolBar);
526 minimizeAction->setIcon(KIcon("window-suppressed"));
527 minimizeAction->setText(i18n("Minimize Fullscreen Window"));
528 connect(minimizeAction, SIGNAL(triggered()), m_fullscreenWindow, SLOT(showMinimized()));
529 m_toolBar->addAction(minimizeAction);
531 m_toolBar->addAction(actionCollection()->action("take_screenshot"));
532 m_toolBar->addAction(actionCollection()->action("view_only"));
533 m_toolBar->addAction(actionCollection()->action("show_local_cursor"));
534 m_toolBar->addAction(actionCollection()->action("special_keys_dialog"));
535 m_toolBar->addAction(actionCollection()->action("logout"));
537 QAction *stickToolBarAction = new QAction(m_toolBar);
538 stickToolBarAction->setCheckable(true);
539 stickToolBarAction->setIcon(KIcon("object-locked"));
540 stickToolBarAction->setText(i18n("Stick Toolbar"));
541 connect(stickToolBarAction, SIGNAL(triggered(bool)), m_toolBar, SLOT(setSticky(bool)));
542 m_toolBar->addAction(stickToolBarAction);
545 m_toolBar->showAndAnimate();
548 void MainWindow::updateActionStatus()
550 kDebug(5010) << m_tabWidget->currentIndex();
552 bool enabled;
554 if ((m_showStartPage && (m_tabWidget->currentIndex() == 0)) ||
555 (!m_showStartPage && (m_tabWidget->currentIndex() < 0)))
556 enabled = false;
557 else
558 enabled = true;
560 actionCollection()->action("switch_fullscreen")->setEnabled(enabled);
561 actionCollection()->action("take_screenshot")->setEnabled(enabled);
562 actionCollection()->action("view_only")->setEnabled(enabled);
563 actionCollection()->action("special_keys_dialog")->setEnabled(enabled);
564 actionCollection()->action("logout")->setEnabled(enabled);
566 bool viewOnlyChecked = false;
567 if (m_currentRemoteView >= 0)
568 viewOnlyChecked = enabled && m_remoteViewList.at(m_currentRemoteView)->viewOnly();
569 actionCollection()->action("view_only")->setChecked(viewOnlyChecked);
571 bool showLocalCursorChecked = false;
572 if (m_currentRemoteView >= 0)
573 showLocalCursorChecked = enabled && m_remoteViewList.at(m_currentRemoteView)->dotCursorState() == RemoteView::CursorOn;
574 actionCollection()->action("show_local_cursor")->setChecked(showLocalCursorChecked);
576 bool showLocalCursorVisible = false;
577 if (m_currentRemoteView >= 0)
578 showLocalCursorVisible = enabled && m_remoteViewList.at(m_currentRemoteView)->supportsLocalCursor();
579 actionCollection()->action("show_local_cursor")->setVisible(showLocalCursorVisible);
582 void MainWindow::preferences()
584 // An instance of your dialog could be already created and could be
585 // cached, in which case you want to display the cached dialog
586 // instead of creating another one
587 if (PreferencesDialog::showDialog("preferences"))
588 return;
590 // KConfigDialog didn't find an instance of this dialog, so lets
591 // create it:
592 PreferencesDialog *dialog = new PreferencesDialog(this, Settings::self());
594 // User edited the configuration - update your local copies of the
595 // configuration data
596 connect(dialog, SIGNAL(settingsChanged(const QString&)),
597 this, SLOT(updateConfiguration()));
599 dialog->show();
602 void MainWindow::updateConfiguration()
604 m_addressNavigator->setUrlEditable(Settings::normalUrlInputLine());
606 if (Settings::systemTrayIcon() && !m_systemTrayIcon) {
607 m_systemTrayIcon = new SystemTrayIcon(this);
608 m_systemTrayIcon->setVisible(true);
609 } else if (m_systemTrayIcon) {
610 delete m_systemTrayIcon;
611 m_systemTrayIcon = 0;
614 if (Settings::showStartPage() && !m_showStartPage)
615 createStartPage();
616 else if (!Settings::showStartPage() && m_showStartPage) {
617 m_tabWidget->removeTab(0);
618 m_showStartPage = false;
620 updateActionStatus();
622 // update the scroll areas background color
623 for (int i = (m_showStartPage ? 1 : 0); i < m_tabWidget->count(); i++) {
624 QPalette palette = m_tabWidget->widget(i)->palette();
625 palette.setColor(QPalette::Dark, Settings::backgroundColor());
626 m_tabWidget->widget(i)->setPalette(palette);
630 void MainWindow::quit()
632 if (KMessageBox::warningYesNoCancel(this,
633 i18n("Are you sure you want to close the KDE Remote Desktop Client?"),
634 i18n("Confirm Quit"),
635 KStandardGuiItem::yes(), KStandardGuiItem::no(), KStandardGuiItem::cancel(),
636 "DoNotAskBeforeExit") == KMessageBox::Yes) {
638 if (Settings::rememberSessions()) { // remember open remote views for next startup
639 QStringList list;
640 for (int i = 0; i < m_remoteViewList.count(); i++) {
641 kDebug(5010) << m_remoteViewList.at(i)->url();
642 list.append(m_remoteViewList.at(i)->url().prettyUrl(KUrl::RemoveTrailingSlash));
644 Settings::setOpenSessions(list);
647 Settings::self()->writeConfig();
649 qApp->quit();
653 void MainWindow::configureNotifications()
655 KNotifyConfigWidget::configure(this);
658 void MainWindow::configureKeys()
660 KShortcutsDialog::configure(actionCollection());
663 void MainWindow::configureToolbars()
665 KEditToolBar edit(actionCollection());
666 connect(&edit, SIGNAL(newToolbarConfig()), this, SLOT(newToolbarConfig()));
667 edit.exec();
670 void MainWindow::showMenubar()
672 if (m_menubarAction->isChecked())
673 menuBar()->show();
674 else
675 menuBar()->hide();
678 void MainWindow::closeEvent(QCloseEvent *event)
680 event->ignore();
682 if (Settings::systemTrayIcon()) {
683 hide(); // just hide the mainwindow, keep it in systemtray
684 } else {
685 quit();
689 void MainWindow::tabChanged(int index)
691 kDebug(5010) << index;
693 m_currentRemoteView = index - (m_showStartPage ? 1 : 0);
695 QString tabTitle = m_tabWidget->tabText(index).remove('&');
697 setCaption(tabTitle == i18n("Start Page") ? QString() : tabTitle);
699 updateActionStatus();
702 void MainWindow::createStartPage()
704 m_showStartPage = true;
706 QWidget *startWidget = new QWidget(this);
707 startWidget->setStyleSheet("QWidget { background-color: palette(base) }");
709 QVBoxLayout *startLayout = new QVBoxLayout(startWidget);
711 QLabel *headerLabel = new QLabel(this);
712 headerLabel->setText(i18n("<h1>KDE Remote Desktop Client</h1><br /><br />What would you like to do?<br />"));
714 QLabel *headerIconLabel = new QLabel(this);
715 headerIconLabel->setPixmap(KIcon("krdc").pixmap(128));
717 QHBoxLayout *headerLayout = new QHBoxLayout;
718 headerLayout->setMargin(20);
719 headerLayout->addWidget(headerLabel, 1, Qt::AlignTop);
720 headerLayout->addWidget(headerIconLabel);
722 KPushButton *vncConnectButton = new KPushButton(this);
723 vncConnectButton->setStyleSheet("KPushButton { padding: 12px; margin: 10px; }");
724 vncConnectButton->setIcon(KIcon(actionCollection()->action("new_vnc_connection")->icon()));
725 vncConnectButton->setText(i18n("Connect to a VNC Remote Desktop"));
726 connect(vncConnectButton, SIGNAL(clicked()), SLOT(newVncConnection()));
727 #ifndef BUILD_VNC
728 vncConnectButton->setVisible(false);
729 #endif
731 KPushButton *nxConnectButton = new KPushButton(this);
732 nxConnectButton->setStyleSheet("KPushButton { padding: 12px; margin: 10px; }");
733 nxConnectButton->setIcon(KIcon(actionCollection()->action("new_nx_connection")->icon()));
734 nxConnectButton->setText(i18n("Connect to a NX Remote Desktop"));
735 connect(nxConnectButton, SIGNAL(clicked()), SLOT(newNxConnection()));
736 #ifndef BUILD_NX
737 nxConnectButton->setVisible(false);
738 #endif
740 KPushButton *rdpConnectButton = new KPushButton(this);
741 rdpConnectButton->setStyleSheet("KPushButton { padding: 12px; margin: 10px; }");
742 rdpConnectButton->setIcon(KIcon(actionCollection()->action("new_rdp_connection")->icon()));
743 rdpConnectButton->setText(i18n("Connect to a Windows Remote Desktop (RDP)"));
744 connect(rdpConnectButton, SIGNAL(clicked()), SLOT(newRdpConnection()));
745 #ifndef BUILD_RDP
746 rdpConnectButton->setVisible(false);
747 #endif
749 startLayout->addLayout(headerLayout);
750 startLayout->addWidget(vncConnectButton);
751 startLayout->addWidget(nxConnectButton);
752 startLayout->addWidget(rdpConnectButton);
753 startLayout->addStretch();
755 m_tabWidget->insertTab(0, startWidget, KIcon("krdc"), i18n("Start Page"));
758 void MainWindow::newVncConnection()
760 m_addressNavigator->setUrl(KUrl("vnc://"));
761 m_addressNavigator->setFocus();
763 QToolTip::showText(m_addressNavigator->pos() + pos() + QPoint(m_addressNavigator->width(),
764 m_addressNavigator->height() + 20),
765 i18n("<html>Enter the address here.<br />"
766 "<i>Example: vncserver:1 (host:port / screen)</i></html>"), this);
769 void MainWindow::newNxConnection()
771 m_addressNavigator->setUrl(KUrl("nx://"));
772 m_addressNavigator->setFocus();
774 QToolTip::showText(m_addressNavigator->pos() + pos() + QPoint(m_addressNavigator->width(),
775 m_addressNavigator->height() + 20),
776 i18n("<html>Enter the address here.<br />"
777 "<i>Example: nxserver (host)</i></html>"), this);
780 void MainWindow::newRdpConnection()
782 m_addressNavigator->setUrl(KUrl("rdp://"));
783 m_addressNavigator->setFocus();
785 QToolTip::showText(m_addressNavigator->pos() + pos() + QPoint(m_addressNavigator->width(),
786 m_addressNavigator->height() + 20),
787 i18n("<html>Enter the address here. Port is optional.<br />"
788 "<i>Example: rdpserver:3389 (host:port)</i></html>"), this);
791 QList<RemoteView *> MainWindow::remoteViewList() const
793 return m_remoteViewList;
796 int MainWindow::currentRemoteView() const
798 return m_currentRemoteView;
801 #include "mainwindow.moc"