KTitleWidget for AddTracker-Dialog
[kdenetwork.git] / krdc / mainwindow.cpp
blob0d3f9670232081299a36cd198786ab1e723aaaea
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 "specialkeysdialog.h"
32 #ifdef BUILD_RDP
33 #include "rdpview.h"
34 #endif
35 #ifdef BUILD_NX
36 #include "nxview.h"
37 #endif
38 #ifdef BUILD_VNC
39 #include "vncview.h"
40 #endif
42 #include <KAction>
43 #include <KActionCollection>
44 #include <KActionMenu>
45 #include <KApplication>
46 #include <KEditToolBar>
47 #include <KIcon>
48 #include <KLocale>
49 #include <KMenuBar>
50 #include <KMessageBox>
51 #include <KNotifyConfigWidget>
52 #include <KPushButton>
53 #include <KShortcut>
54 #include <KShortcutsDialog>
55 #include <KStatusBar>
56 #include <KTabWidget>
57 #include <KToggleAction>
58 #include <KUrlNavigator>
60 #include <QClipboard>
61 #include <QCloseEvent>
62 #include <QDesktopWidget>
63 #include <QLabel>
64 #include <QLayout>
65 #include <QScrollArea>
66 #include <QTimer>
67 #include <QToolButton>
68 #include <QToolTip>
70 MainWindow::MainWindow(QWidget *parent)
71 : KXmlGuiWindow(parent),
72 m_fullscreenWindow(0),
73 m_toolBar(0),
74 m_topBottomBorder(0),
75 m_leftRightBorder(0),
76 m_currentRemoteView(-1),
77 m_showStartPage(false)
79 setupActions();
81 createGUI("krdcui.rc");
83 setStandardToolBarMenuEnabled(true);
85 m_tabWidget = new KTabWidget(this);
86 m_tabWidget->setMinimumSize(600, 400);
87 setCentralWidget(m_tabWidget);
89 connect(m_tabWidget, SIGNAL(currentChanged(int)), SLOT(tabChanged(int)));
91 statusBar()->showMessage(i18n("KDE Remote Desktop Client started"));
93 updateActionStatus(); // disable remote view actions
95 if (Settings::showStartPage())
96 createStartPage();
98 setAutoSaveSettings(); // e.g toolbar position, mainwindow size, ...
100 if (Settings::rememberSessions()) // give some time to create and show the window first
101 QTimer::singleShot(100, this, SLOT(restoreOpenSessions()));
104 MainWindow::~MainWindow()
108 void MainWindow::setupActions()
110 QAction *vncConnectionAction = actionCollection()->addAction("new_vnc_connection");
111 vncConnectionAction->setText(i18n("New VNC Connection..."));
112 vncConnectionAction->setIcon(KIcon("network-connect"));
113 connect(vncConnectionAction, SIGNAL(triggered()), SLOT(newVncConnection()));
114 #ifndef BUILD_VNC
115 vncConnectionAction->setVisible(false);
116 #endif
118 QAction *nxConnectionAction = actionCollection()->addAction("new_nx_connection");
119 nxConnectionAction->setText(i18n("New NX Connection..."));
120 nxConnectionAction->setIcon(KIcon("network-connect"));
121 connect(nxConnectionAction, SIGNAL(triggered()), SLOT(newNxConnection()));
122 #ifndef BUILD_NX
123 nxConnectionAction->setVisible(false);
124 #endif
126 QAction *rdpConnectionAction = actionCollection()->addAction("new_rdp_connection");
127 rdpConnectionAction->setText(i18n("New RDP Connection..."));
128 rdpConnectionAction->setIcon(KIcon("network-connect"));
129 connect(rdpConnectionAction, SIGNAL(triggered()), SLOT(newRdpConnection()));
130 #ifndef BUILD_RDP
131 rdpConnectionAction->setVisible(false);
132 #endif
134 QAction *screenshotAction = actionCollection()->addAction("take_screenshot");
135 screenshotAction->setText(i18n("Copy Screenshot to Clipboard"));
136 screenshotAction->setIcon(KIcon("ksnapshot"));
137 connect(screenshotAction, SIGNAL(triggered()), SLOT(takeScreenshot()));
139 QAction *fullscreenAction = actionCollection()->addAction("switch_fullscreen");
140 fullscreenAction->setText(i18n("Switch to Fullscreen Mode"));
141 fullscreenAction->setIcon(KIcon("view-fullscreen"));
142 connect(fullscreenAction, SIGNAL(triggered()), SLOT(switchFullscreen()));
144 QAction *viewOnlyAction = actionCollection()->addAction("view_only");
145 viewOnlyAction->setCheckable(true);
146 viewOnlyAction->setText(i18n("View Only"));
147 viewOnlyAction->setIcon(KIcon("document-preview"));
148 connect(viewOnlyAction, SIGNAL(triggered(bool)), SLOT(viewOnly(bool)));
150 QAction *logoutAction = actionCollection()->addAction("logout");
151 logoutAction->setText(i18n("Log Out"));
152 logoutAction->setIcon(KIcon("system-log-out"));
153 connect(logoutAction, SIGNAL(triggered()), SLOT(logout()));
155 QAction *showLocalCursorAction = actionCollection()->addAction("show_local_cursor");
156 showLocalCursorAction->setCheckable(true);
157 showLocalCursorAction->setIcon(KIcon("input-mouse"));
158 showLocalCursorAction->setText(i18n("Show Local Cursor"));
159 connect(showLocalCursorAction, SIGNAL(triggered(bool)), SLOT(showLocalCursor(bool)));
161 QAction *specialKeysDialogAction = actionCollection()->addAction("special_keys_dialog");
162 specialKeysDialogAction->setIcon(KIcon("configure-shortcuts"));
163 specialKeysDialogAction->setText(i18n("Open Special Keys Dialog..."));
164 connect(specialKeysDialogAction, SIGNAL(triggered()), SLOT(specialKeyDialog()));
166 QAction *quitAction = KStandardAction::quit(this, SLOT(quit()), actionCollection());
167 actionCollection()->addAction("quit", quitAction);
168 QAction *preferencesAction = KStandardAction::preferences(this, SLOT(preferences()), actionCollection());
169 actionCollection()->addAction("preferences", preferencesAction);
170 QAction *configToolbarAction = KStandardAction::configureToolbars(this, SLOT(configureToolbars()), actionCollection());
171 actionCollection()->addAction("configure_toolbars", configToolbarAction);
172 QAction *keyBindingsAction = KStandardAction::keyBindings(this, SLOT(configureKeys()), actionCollection());
173 actionCollection()->addAction("configure_keys", keyBindingsAction);
174 QAction *cinfigNotifyAction = KStandardAction::configureNotifications(this, SLOT(configureNotifications()), actionCollection());
175 cinfigNotifyAction->setVisible(false);
176 actionCollection()->addAction("configure_notifications", cinfigNotifyAction);
177 m_menubarAction = KStandardAction::showMenubar(this, SLOT(showMenubar()), actionCollection());
178 m_menubarAction->setChecked(!menuBar()->isHidden());
179 actionCollection()->addAction("settings_showmenubar", m_menubarAction);
181 QString initialProtocol;
182 #ifdef BUILD_RDP
183 initialProtocol = "rdp";
184 #endif
185 #ifdef BUILD_NX
186 initialProtocol = "nx";
187 #endif
188 #ifdef BUILD_VNC
189 initialProtocol = "vnc";
190 #endif
192 m_addressNavigator = new KUrlNavigator(0, KUrl(initialProtocol + "://"), this);
193 m_addressNavigator->setCustomProtocols(QStringList()
194 #ifdef BUILD_VNC
195 << "vnc"
196 #endif
197 #ifdef BUILD_NX
198 << "nx"
199 #endif
200 #ifdef BUILD_RDP
201 << "rdp"
202 #endif
204 m_addressNavigator->setUrlEditable(Settings::normalUrlInputLine());
205 connect(m_addressNavigator, SIGNAL(returnPressed()), SLOT(newConnection()));
207 QLabel *addressLabel = new QLabel(i18n("Remote desktop:"), this);
209 QWidget *addressWidget = new QWidget(this);
210 QHBoxLayout *addressLayout = new QHBoxLayout(addressWidget);
211 addressLayout->setMargin(0);
212 addressLayout->addWidget(addressLabel);
213 addressLayout->addWidget(m_addressNavigator, 1);
215 KAction *addressLineAction = new KAction(i18nc("Title for remote address input action", "Address"), this);
216 actionCollection()->addAction("address_line", addressLineAction);
217 addressLineAction->setDefaultWidget(addressWidget);
219 QAction *gotoAction = actionCollection()->addAction("goto_address");
220 gotoAction->setText(i18n("Goto Address"));
221 gotoAction->setIcon(KIcon("go-jump-locationbar"));
222 connect(gotoAction, SIGNAL(triggered()), SLOT(newConnection()));
224 KActionMenu *bookmarkMenu = new KActionMenu(i18n("Bookmarks"), actionCollection());
225 m_bookmarkManager = new BookmarkManager(actionCollection(), bookmarkMenu->menu(), this);
226 actionCollection()->addAction("bookmark" , bookmarkMenu);
227 connect(m_bookmarkManager, SIGNAL(openUrl(KUrl)), SLOT(newConnection(KUrl)));
230 void MainWindow::restoreOpenSessions()
232 QStringList list = Settings::openSessions();
233 QStringList::Iterator it = list.begin();
234 QStringList::Iterator end = list.end();
235 while (it != end) {
236 newConnection(*it);
237 ++it;
241 void MainWindow::newConnection(const KUrl &newUrl, bool switchFullscreenWhenConnected)
243 m_switchFullscreenWhenConnected = switchFullscreenWhenConnected;
245 KUrl url = newUrl.isEmpty() ? m_addressNavigator->uncommittedUrl() : newUrl;
247 if (!url.isValid() || (url.host().isEmpty() && url.port() < 0)
248 || !url.path().isEmpty()) {
249 KMessageBox::error(this,
250 i18n("The entered address does not have the required form."),
251 i18n("Malformed URL"));
252 return;
255 m_addressNavigator->setUrl(KUrl(url.scheme().toLower() + "://"));
257 QScrollArea *scrollArea = createScrollArea(m_tabWidget, 0);
259 RemoteView *view;
261 #ifdef BUILD_VNC
262 if (url.scheme().toLower() == "vnc") {
263 view = new VncView(scrollArea, url);
264 } else
265 #endif
267 #ifdef BUILD_NX
268 if (url.scheme().toLower() == "nx") {
269 view = new NxView(scrollArea, url);
270 } else
271 #endif
273 #ifdef BUILD_RDP
274 if (url.scheme().toLower() == "rdp") {
275 view = new RdpView(scrollArea, url);
276 } else
277 #endif
279 KMessageBox::error(this,
280 i18n("The entered address cannot be handled."),
281 i18n("Unusable URL"));
282 return;
285 connect(view, SIGNAL(changeSize(int, int)), this, SLOT(resizeTabWidget(int, int)));
286 connect(view, SIGNAL(statusChanged(RemoteView::RemoteStatus)), this, SLOT(statusChanged(RemoteView::RemoteStatus)));
288 m_remoteViewList.append(view);
290 view->resize(0, 0);
292 scrollArea->setWidget(m_remoteViewList.at(m_tabWidget->count() - (m_showStartPage ? 1 : 0)));
294 int newIndex = m_tabWidget->addTab(scrollArea, KIcon("krdc"), url.prettyUrl(KUrl::RemoveTrailingSlash));
295 m_tabWidget->setCurrentIndex(newIndex);
297 view->start();
300 void MainWindow::resizeTabWidget(int w, int h)
302 kDebug(5010) << "tabwidget resize: w: " << w << ", h: " << h;
304 if (m_topBottomBorder == 0) { // the values are not cached yet
305 QScrollArea *tmp = qobject_cast<QScrollArea *>(m_tabWidget->currentWidget());
307 m_leftRightBorder = m_tabWidget->width() - m_tabWidget->currentWidget()->width() + (2 * tmp->frameWidth());
308 m_topBottomBorder = m_tabWidget->height() - m_tabWidget->currentWidget()->height() + (2 * tmp->frameWidth());
310 kDebug(5010) << "tabwidget border: w: " << m_leftRightBorder << ", h: " << m_topBottomBorder;
313 int newTabWidth = w + m_leftRightBorder;
314 int newTabHeight = h + m_topBottomBorder;
316 QSize newWindowSize = size() - m_tabWidget->size() + QSize(newTabWidth, newTabHeight);
318 QSize desktopSize = QSize(QApplication::desktop()->availableGeometry().width(),
319 QApplication::desktop()->availableGeometry().height());
321 if ((newWindowSize.height() >= desktopSize.height()) || (newWindowSize.width() >= desktopSize.width())) {
322 kDebug(5010) << "remote desktop needs more place than available -> show window maximized";
323 showMaximized();
324 QCoreApplication::processEvents();
325 return;
328 //WORKAROUND: QTabWidget resize problem. Let's see if there is a clean solution for this issue.
329 m_tabWidget->setMinimumSize(newTabWidth, newTabHeight);
330 m_tabWidget->adjustSize();
331 QCoreApplication::processEvents();
332 m_tabWidget->setMinimumSize(500, 400);
335 void MainWindow::statusChanged(RemoteView::RemoteStatus status)
337 kDebug(5010) << status;
339 // the remoteview is already deleted, so don't show it; otherwise it would crash
340 if (status == RemoteView::Disconnecting || status == RemoteView::Disconnected)
341 return;
343 QString host = m_remoteViewList.at(m_currentRemoteView)->host();
345 QString iconName = "krdc";
346 QString message;
348 switch (status) {
349 case RemoteView::Connecting:
350 iconName = "network-connect";
351 message = i18n("Connecting to %1", host);
352 break;
353 case RemoteView::Authenticating:
354 iconName = "dialog-password";
355 message = i18n("Authenticating at %1", host);
356 break;
357 case RemoteView::Preparing:
358 iconName = "view-history";
359 message = i18n("Preparing connection to %1", host);
360 break;
361 case RemoteView::Connected:
362 iconName = "krdc";
363 message = i18n("Connected to %1", host);
365 // when started with command line fullscreen argument
366 if (m_switchFullscreenWhenConnected) {
367 m_switchFullscreenWhenConnected = false;
368 switchFullscreen();
371 m_bookmarkManager->addHistoryBookmark();
373 break;
374 default:
375 iconName = "krdc";
376 message = QString();
379 m_tabWidget->setTabIcon(m_tabWidget->currentIndex(), KIcon(iconName));
380 statusBar()->showMessage(message);
383 void MainWindow::takeScreenshot()
385 QPixmap snapshot = QPixmap::grabWidget(m_remoteViewList.at(m_currentRemoteView));
387 QApplication::clipboard()->setPixmap(snapshot);
390 void MainWindow::switchFullscreen()
392 kDebug(5010);
394 if (m_fullscreenWindow) {
395 show();
396 restoreGeometry(m_mainWindowGeometry);
398 m_fullscreenWindow->setWindowState(0);
399 m_fullscreenWindow->hide();
401 QScrollArea *scrollArea = createScrollArea(m_tabWidget, m_remoteViewList.at(m_currentRemoteView));
403 int currentTab = m_tabWidget->currentIndex();
404 m_tabWidget->insertTab(currentTab, scrollArea, m_tabWidget->tabIcon(currentTab), m_tabWidget->tabText(currentTab));
405 m_tabWidget->removeTab(m_tabWidget->currentIndex());
406 m_tabWidget->setCurrentIndex(currentTab);
408 resizeTabWidget(m_remoteViewList.at(m_currentRemoteView)->sizeHint().width(),
409 m_remoteViewList.at(m_currentRemoteView)->sizeHint().height());
411 if (m_toolBar) {
412 m_toolBar->hideAndDestroy();
413 m_toolBar = 0;
416 actionCollection()->action("switch_fullscreen")->setIcon(KIcon("view-fullscreen"));
417 actionCollection()->action("switch_fullscreen")->setText(i18n("Switch to Fullscreen Mode"));
419 m_fullscreenWindow->deleteLater();
421 m_fullscreenWindow = 0;
422 } else {
423 m_fullscreenWindow = new QWidget(this, Qt::Window);
424 m_fullscreenWindow->setWindowTitle(i18nc("window title when in fullscreen mode (for example displayed in tasklist)",
425 "KDE Remote Desktop Client (Fullscreen)"));
427 QScrollArea *scrollArea = createScrollArea(m_fullscreenWindow, m_remoteViewList.at(m_currentRemoteView));
428 scrollArea->setFrameShape(QFrame::NoFrame);
430 QVBoxLayout *fullscreenLayout = new QVBoxLayout(m_fullscreenWindow);
431 fullscreenLayout->setMargin(0);
432 fullscreenLayout->addWidget(scrollArea);
434 MinimizePixel *minimizePixel = new MinimizePixel(m_fullscreenWindow);
435 connect(minimizePixel, SIGNAL(rightClicked()), m_fullscreenWindow, SLOT(showMinimized()));
437 m_fullscreenWindow->show();
439 m_fullscreenWindow->setWindowState(Qt::WindowFullScreen);
441 // show the toolbar after we have switched to fullscreen mode
442 QTimer::singleShot(100, this, SLOT(showRemoteViewToolbar()));
444 m_mainWindowGeometry = saveGeometry();
445 hide();
449 QScrollArea *MainWindow::createScrollArea(QWidget *parent, RemoteView *remoteView)
451 QScrollArea *scrollArea = new QScrollArea(parent);
452 scrollArea->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
454 QPalette palette = scrollArea->palette();
455 palette.setColor(QPalette::Dark, Settings::backgroundColor());
456 scrollArea->setPalette(palette);
458 scrollArea->setBackgroundRole(QPalette::Dark);
459 scrollArea->setWidget(remoteView);
461 return scrollArea;
464 void MainWindow::logout()
466 kDebug(5010);
468 if (m_fullscreenWindow) { // first close fullscreen view
469 switchFullscreen();
472 QWidget *tmp = m_tabWidget->currentWidget();
474 m_remoteViewList.removeAt(m_currentRemoteView);
476 m_tabWidget->removeTab(m_tabWidget->currentIndex());
478 tmp->deleteLater();
480 updateActionStatus();
483 void MainWindow::showLocalCursor(bool showLocalCursor)
485 kDebug(5010) << showLocalCursor;
487 m_remoteViewList.at(m_currentRemoteView)->showDotCursor(showLocalCursor ? RemoteView::CursorOn : RemoteView::CursorOff);
490 void MainWindow::viewOnly(bool viewOnly)
492 kDebug(5010) << viewOnly;
494 m_remoteViewList.at(m_currentRemoteView)->setViewOnly(viewOnly);
497 void MainWindow::specialKeyDialog()
499 kDebug(5010);
501 SpecialKeysDialog dialog(this, m_remoteViewList.at(m_currentRemoteView));
502 dialog.exec();
505 void MainWindow::showRemoteViewToolbar()
507 kDebug(5010);
509 if (!m_toolBar) {
510 actionCollection()->action("switch_fullscreen")->setIcon(KIcon("view-restore"));
511 actionCollection()->action("switch_fullscreen")->setText(i18n("Switch to Window Mode"));
513 m_toolBar = new FloatingToolBar(m_fullscreenWindow, m_fullscreenWindow);
514 m_toolBar->setSide(FloatingToolBar::Top);
515 m_toolBar->addAction(actionCollection()->action("switch_fullscreen"));
517 QAction *minimizeAction = new QAction(m_toolBar);
518 minimizeAction->setIcon(KIcon("window-suppressed"));
519 minimizeAction->setText(i18n("Minimize Fullscreen Window"));
520 connect(minimizeAction, SIGNAL(triggered()), m_fullscreenWindow, SLOT(showMinimized()));
521 m_toolBar->addAction(minimizeAction);
523 m_toolBar->addAction(actionCollection()->action("take_screenshot"));
524 m_toolBar->addAction(actionCollection()->action("view_only"));
525 m_toolBar->addAction(actionCollection()->action("show_local_cursor"));
526 m_toolBar->addAction(actionCollection()->action("special_keys_dialog"));
527 m_toolBar->addAction(actionCollection()->action("logout"));
529 QAction *stickToolBarAction = new QAction(m_toolBar);
530 stickToolBarAction->setCheckable(true);
531 stickToolBarAction->setIcon(KIcon("object-locked"));
532 stickToolBarAction->setText(i18n("Stick Toolbar"));
533 connect(stickToolBarAction, SIGNAL(triggered(bool)), m_toolBar, SLOT(setSticky(bool)));
534 m_toolBar->addAction(stickToolBarAction);
537 m_toolBar->showAndAnimate();
540 void MainWindow::updateActionStatus()
542 kDebug(5010) << m_tabWidget->currentIndex();
544 bool enabled;
546 if ((m_showStartPage && (m_tabWidget->currentIndex() == 0)) ||
547 (!m_showStartPage && (m_tabWidget->currentIndex() < 0)))
548 enabled = false;
549 else
550 enabled = true;
552 actionCollection()->action("switch_fullscreen")->setEnabled(enabled);
553 actionCollection()->action("take_screenshot")->setEnabled(enabled);
554 actionCollection()->action("view_only")->setEnabled(enabled);
555 actionCollection()->action("special_keys_dialog")->setEnabled(enabled);
556 actionCollection()->action("logout")->setEnabled(enabled);
558 bool viewOnlyChecked = false;
559 if (m_currentRemoteView >= 0)
560 viewOnlyChecked = enabled && m_remoteViewList.at(m_currentRemoteView)->viewOnly();
561 actionCollection()->action("view_only")->setChecked(viewOnlyChecked);
563 bool showLocalCursorChecked = false;
564 if (m_currentRemoteView >= 0)
565 showLocalCursorChecked = enabled && m_remoteViewList.at(m_currentRemoteView)->dotCursorState() == RemoteView::CursorOn;
566 actionCollection()->action("show_local_cursor")->setChecked(showLocalCursorChecked);
568 bool showLocalCursorVisible = false;
569 if (m_currentRemoteView >= 0)
570 showLocalCursorVisible = enabled && m_remoteViewList.at(m_currentRemoteView)->supportsLocalCursor();
571 actionCollection()->action("show_local_cursor")->setVisible(showLocalCursorVisible);
574 void MainWindow::preferences()
576 // An instance of your dialog could be already created and could be
577 // cached, in which case you want to display the cached dialog
578 // instead of creating another one
579 if (PreferencesDialog::showDialog("preferences"))
580 return;
582 // KConfigDialog didn't find an instance of this dialog, so lets
583 // create it:
584 PreferencesDialog *dialog = new PreferencesDialog(this, Settings::self());
586 // User edited the configuration - update your local copies of the
587 // configuration data
588 connect(dialog, SIGNAL(settingsChanged(const QString&)),
589 this, SLOT(updateConfiguration()));
591 dialog->show();
594 void MainWindow::updateConfiguration()
596 m_addressNavigator->setUrlEditable(Settings::normalUrlInputLine());
598 if (Settings::showStartPage() && !m_showStartPage)
599 createStartPage();
600 else if (!Settings::showStartPage() && m_showStartPage) {
601 m_tabWidget->removeTab(0);
602 m_showStartPage = false;
604 updateActionStatus();
606 // update the scroll areas background color
607 for (int i = (m_showStartPage ? 1 : 0); i < m_tabWidget->count(); i++) {
608 QPalette palette = m_tabWidget->widget(i)->palette();
609 palette.setColor(QPalette::Dark, Settings::backgroundColor());
610 m_tabWidget->widget(i)->setPalette(palette);
614 void MainWindow::quit()
616 close();
619 void MainWindow::configureNotifications()
621 KNotifyConfigWidget::configure(this);
624 void MainWindow::configureKeys()
626 KShortcutsDialog::configure(actionCollection());
629 void MainWindow::configureToolbars()
631 KEditToolBar edit(actionCollection());
632 connect(&edit, SIGNAL(newToolbarConfig()), this, SLOT(newToolbarConfig()));
633 edit.exec();
636 void MainWindow::showMenubar()
638 if (m_menubarAction->isChecked())
639 menuBar()->show();
640 else
641 menuBar()->hide();
644 void MainWindow::closeEvent(QCloseEvent *event)
646 if (KMessageBox::warningYesNoCancel(this,
647 i18n("Are you sure you want to close the KDE Remote Desktop Client?"),
648 i18n("Confirm Quit"),
649 KStandardGuiItem::yes(), KStandardGuiItem::no(), KStandardGuiItem::cancel(),
650 "AskBeforeExit") == KMessageBox::Yes) {
652 if (Settings::rememberSessions()) { // remember open remote views for next startup
653 QStringList list;
654 for (int i = (m_showStartPage ? 1 : 0); i < m_tabWidget->count(); i++) {
655 kDebug(5010) << m_remoteViewList.at(i - 1)->url();
656 list.append(m_remoteViewList.at(i - 1)->url().prettyUrl(KUrl::RemoveTrailingSlash));
658 Settings::setOpenSessions(list);
661 Settings::self()->writeConfig();
663 event->accept();
664 } else
665 event->ignore();
668 void MainWindow::tabChanged(int index)
670 kDebug(5010) << index;
672 m_currentRemoteView = index - (m_showStartPage ? 1 : 0);
674 QString tabTitle = m_tabWidget->tabText(index).remove('&');
676 setCaption(tabTitle == i18n("Start Page") ? QString() : tabTitle);
678 updateActionStatus();
681 void MainWindow::createStartPage()
683 m_showStartPage = true;
685 QWidget *startWidget = new QWidget(this);
686 startWidget->setStyleSheet("QWidget { background-color: palette(base) }");
688 QVBoxLayout *startLayout = new QVBoxLayout(startWidget);
690 QLabel *headerLabel = new QLabel(this);
691 headerLabel->setText(i18n("<h1>KDE Remote Desktop Client</h1><br /><br />What would you like to do?<br />"));
693 QLabel *headerIconLabel = new QLabel(this);
694 headerIconLabel->setPixmap(KIcon("krdc").pixmap(128));
696 QHBoxLayout *headerLayout = new QHBoxLayout;
697 headerLayout->setMargin(20);
698 headerLayout->addWidget(headerLabel, 1, Qt::AlignTop);
699 headerLayout->addWidget(headerIconLabel);
701 KPushButton *vncConnectButton = new KPushButton(this);
702 vncConnectButton->setStyleSheet("KPushButton { padding: 12px; margin: 10px; }");
703 vncConnectButton->setIcon(KIcon(actionCollection()->action("new_vnc_connection")->icon()));
704 vncConnectButton->setText(i18n("Connect to a VNC Remote Desktop"));
705 connect(vncConnectButton, SIGNAL(clicked()), SLOT(newVncConnection()));
706 #ifndef BUILD_VNC
707 vncConnectButton->setVisible(false);
708 #endif
710 KPushButton *nxConnectButton = new KPushButton(this);
711 nxConnectButton->setStyleSheet("KPushButton { padding: 12px; margin: 10px; }");
712 nxConnectButton->setIcon(KIcon(actionCollection()->action("new_nx_connection")->icon()));
713 nxConnectButton->setText(i18n("Connect to a NX Remote Desktop"));
714 connect(nxConnectButton, SIGNAL(clicked()), SLOT(newNxConnection()));
715 #ifndef BUILD_NX
716 nxConnectButton->setVisible(false);
717 #endif
719 KPushButton *rdpConnectButton = new KPushButton(this);
720 rdpConnectButton->setStyleSheet("KPushButton { padding: 12px; margin: 10px; }");
721 rdpConnectButton->setIcon(KIcon(actionCollection()->action("new_rdp_connection")->icon()));
722 rdpConnectButton->setText(i18n("Connect to a Windows Remote Desktop (RDP)"));
723 connect(rdpConnectButton, SIGNAL(clicked()), SLOT(newRdpConnection()));
724 #ifndef BUILD_RDP
725 rdpConnectButton->setVisible(false);
726 #endif
728 startLayout->addLayout(headerLayout);
729 startLayout->addWidget(vncConnectButton);
730 startLayout->addWidget(nxConnectButton);
731 startLayout->addWidget(rdpConnectButton);
732 startLayout->addStretch();
734 m_tabWidget->insertTab(0, startWidget, KIcon("krdc"), i18n("Start Page"));
737 void MainWindow::newVncConnection()
739 m_addressNavigator->setUrl(KUrl("vnc://"));
740 m_addressNavigator->setFocus();
742 QToolTip::showText(m_addressNavigator->pos() + pos() + QPoint(m_addressNavigator->width(),
743 m_addressNavigator->height() + 20),
744 i18n("<html>Enter the address here.<br />"
745 "<i>Example: vncserver:1 (host:port / screen)</i></html>"), this);
748 void MainWindow::newNxConnection()
750 m_addressNavigator->setUrl(KUrl("nx://"));
751 m_addressNavigator->setFocus();
753 QToolTip::showText(m_addressNavigator->pos() + pos() + QPoint(m_addressNavigator->width(),
754 m_addressNavigator->height() + 20),
755 i18n("<html>Enter the address here.<br />"
756 "<i>Example: nxserver (host)</i></html>"), this);
759 void MainWindow::newRdpConnection()
761 m_addressNavigator->setUrl(KUrl("rdp://"));
762 m_addressNavigator->setFocus();
764 QToolTip::showText(m_addressNavigator->pos() + pos() + QPoint(m_addressNavigator->width(),
765 m_addressNavigator->height() + 20),
766 i18n("<html>Enter the address here. Port is optional.<br />"
767 "<i>Example: rdpserver:3389 (host:port)</i></html>"), this);
770 QList<RemoteView *> MainWindow::remoteViewList() const
772 return m_remoteViewList;
775 int MainWindow::currentRemoteView() const
777 return m_currentRemoteView;
780 #include "mainwindow.moc"