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#ifndef MAINWINDOW_H
26#define MAINWINDOW_H
27
28#include "remoteview.h"
29#include "remoteviewfactory.h"
30
31#include <KService>
32#include <KXmlGuiWindow>
33
34class KComboBox;
35class KLineEdit;
36class KPushButton;
37class KToggleAction;
38class KTabWidget;
39
40class BookmarkManager;
41class FloatingToolBar;
42class RemoteDesktopsModel;
43class RemoteView;
44class SystemTrayIcon;
45class TabbedViewWidget;
46
47class QScrollArea;
48class QModelIndex;
49class QTableView;
50
51#ifdef TELEPATHY_SUPPORT
52class TubesManager;
53#endif
54
55class MainWindow : public KXmlGuiWindow
56{
57 Q_OBJECT
58public:
59 explicit MainWindow(QWidget *parent = 0);
60 ~MainWindow();
61
62 QMap<QWidget *, RemoteView *> remoteViewList() const;
63 QList<RemoteViewFactory *> remoteViewFactoriesList() const;
64 RemoteView* currentRemoteView() const;
65
66public slots:
67 void newConnection(const KUrl &newUrl = KUrl(), bool switchFullscreenWhenConnected = false, const QString &tabName = QString());
68
69protected:
70 virtual void closeEvent(QCloseEvent *event);
71 bool eventFilter(QObject *obj, QEvent *event); // checks for close events on fs window
72 virtual void saveProperties(KConfigGroup &group);
73 void saveHostPrefs();
74 void saveHostPrefs(RemoteView *view);
75
76private slots:
77 void restoreOpenSessions();
78 void quit(bool systemEvent = false);
79 void preferences();
80 void configureNotifications();
81 void showMenubar();
82 void resizeTabWidget(int w, int h);
83 void statusChanged(RemoteView::RemoteStatus status);
84 void showRemoteViewToolbar();
85 void takeScreenshot();
86 void switchFullscreen();
87 void disconnectHost();
88 void closeTab(QWidget *widget);
89 void openTabSettings(QWidget *widget);
90 void tabContextMenu(QWidget *widget, const QPoint &point);
91 void viewOnly(bool viewOnly);
92 void showLocalCursor(bool showLocalCursor);
93 void grabAllKeys(bool grabAllKeys);
94 void scale(bool scale);
95 void updateActionStatus();
96 void updateConfiguration();
97 void tabChanged(int index);
98 QWidget* newConnectionWidget();
99 void newConnectionPage(bool clearInput = true);
100 void openFromRemoteDesktopsModel(const QModelIndex &index);
101 void createDockWidget();
102 void showConnectionContextMenu(const QPoint &pos);
103 void saveConnectionListSort(const int logicalindex, const Qt::SortOrder order);
104
105private:
106 void setupActions();
107 void loadAllPlugins();
108 RemoteViewFactory *createPluginFromService(const KService::Ptr &service);
109 void showSettingsDialog(const QString &url);
110 QScrollArea *createScrollArea(QWidget *parent, RemoteView *remoteView);
111 KUrl getInputUrl();
112
113 QWidget *m_fullscreenWindow;
114 QByteArray m_mainWindowGeometry;
115
116 KToggleAction *m_menubarAction;
117 TabbedViewWidget *m_tabWidget;
118 KComboBox *m_protocolInput;
119 KLineEdit *m_addressInput;
120
121 FloatingToolBar *m_toolBar;
122
123 BookmarkManager *m_bookmarkManager;
124
125 QMap<QWidget *, RemoteView *> m_remoteViewMap;
126 QMap<int, RemoteViewFactory *> m_remoteViewFactories;
127
128 int m_currentRemoteView;
129 bool m_switchFullscreenWhenConnected;
130
131 SystemTrayIcon *m_systemTrayIcon;
132 QTableView *m_dockWidgetTableView;
133 QTableView *m_newConnectionTableView;
134 RemoteDesktopsModel *m_remoteDesktopsModel;
135#ifdef TELEPATHY_SUPPORT
136 TubesManager *m_tubesManager;
137#endif
138 QWidget *m_newConnectionWidget;
139};
140
141#include <QApplication>
142#include <QDesktopWidget>
143#include <QMouseEvent>
144
145class MinimizePixel : public QWidget
146{
147 Q_OBJECT
148public:
149 explicit MinimizePixel(QWidget *parent)
150 : QWidget(parent) {
151 setFixedSize(1, 1);
152 move(QApplication::desktop()->screenGeometry().width() - 1, 0);
153 }
154
155signals:
156 void rightClicked();
157
158protected:
159 void mousePressEvent(QMouseEvent *event) {
160 if (event->button() == Qt::RightButton)
161 emit rightClicked();
162 }
163};
164
165#include <QScrollArea>
166
167class RemoteViewScrollArea : public QScrollArea
168{
169 Q_OBJECT
170public:
171 explicit RemoteViewScrollArea(QWidget *parent)
172 : QScrollArea(parent) {
173 }
174
175signals:
176 void resized(int w, int h);
177
178protected:
179 void resizeEvent(QResizeEvent *event) {
180 QScrollArea::resizeEvent(event);
181 emit resized(width() - 2*frameWidth(), height() - 2*frameWidth());
182 }
183};
184
185#endif
186