File indexing completed on 2024-04-14 04:53:31

0001 /*
0002     SPDX-FileCopyrightText: 2007-2013 Urs Wolfer <uwolfer@kde.org>
0003     SPDX-FileCopyrightText: 2009-2010 Tony Murray <murraytony@gmail.com>
0004     SPDX-FileCopyrightText: 2021 RafaƂ Lalik <rafallalik@gmail.com>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef MAINWINDOW_H
0010 #define MAINWINDOW_H
0011 
0012 #include "remoteview.h"
0013 #include "remoteviewfactory.h"
0014 
0015 #include <KXmlGuiWindow>
0016 
0017 class KComboBox;
0018 class KLineEdit;
0019 class KPushButton;
0020 class KToggleAction;
0021 class KTabWidget;
0022 
0023 class BookmarkManager;
0024 class FloatingToolBar;
0025 class RemoteDesktopsModel;
0026 class RemoteView;
0027 class SystemTrayIcon;
0028 class TabbedViewWidget;
0029 
0030 class QScrollArea;
0031 class QModelIndex;
0032 class QTableView;
0033 
0034 #ifdef TELEPATHY_SUPPORT
0035 class TubesManager;
0036 #endif
0037 
0038 class MainWindow : public KXmlGuiWindow
0039 {
0040     Q_OBJECT
0041 public:
0042     explicit MainWindow(QWidget *parent = nullptr);
0043     ~MainWindow() override;
0044 
0045     QMap<QWidget *, RemoteView *> remoteViewList() const;
0046     QList<RemoteViewFactory *> remoteViewFactoriesList() const;
0047     RemoteView *currentRemoteView() const;
0048 
0049 public Q_SLOTS:
0050     void newConnection(const QUrl &newUrl = QUrl(), bool switchFullscreenWhenConnected = false, const QString &tabName = QString());
0051     void setFactor(int scale);
0052 
0053 protected:
0054     void closeEvent(QCloseEvent *event) override;
0055     bool eventFilter(QObject *obj, QEvent *event) override; // checks for close events on fs window
0056     void saveProperties(KConfigGroup &group) override;
0057     void saveHostPrefs();
0058     void saveHostPrefs(RemoteView *view);
0059 
0060 private Q_SLOTS:
0061     void restoreOpenSessions();
0062     void quit(bool systemEvent = false);
0063     void preferences();
0064     void configureNotifications();
0065     void showMenubar();
0066     void resizeTabWidget(int w, int h);
0067     void statusChanged(RemoteView::RemoteStatus status);
0068     void showRemoteViewToolbar();
0069     void takeScreenshot();
0070     void switchFullscreen();
0071     void disconnectHost();
0072     void closeTab(int index);
0073     void openTabSettings(int index);
0074     void tabContextMenu(const QPoint &point);
0075     void viewOnly(bool viewOnly);
0076     void showLocalCursor(bool showLocalCursor);
0077     void grabAllKeys(bool grabAllKeys);
0078     void scale(bool scale);
0079     void updateActionStatus();
0080     void updateConfiguration();
0081     void tabChanged(int index);
0082     QWidget *newConnectionWidget();
0083     void newConnectionPage(bool clearInput = true);
0084     void openFromRemoteDesktopsModel(const QModelIndex &index);
0085     void selectFromRemoteDesktopsModel(const QModelIndex &index);
0086     void createDockWidget();
0087     void showConnectionContextMenu(const QPoint &pos);
0088     void saveConnectionListSort(const int logicalindex, const Qt::SortOrder order);
0089 
0090 private:
0091     void setupActions();
0092     void loadAllPlugins();
0093     void showSettingsDialog(const QString &url);
0094     QScrollArea *createScrollArea(QWidget *parent, RemoteView *remoteView);
0095     QUrl getInputUrl();
0096 
0097     QWidget *m_fullscreenWindow;
0098     QByteArray m_mainWindowGeometry;
0099 
0100     KToggleAction *m_menubarAction;
0101     TabbedViewWidget *m_tabWidget;
0102     KComboBox *m_protocolInput;
0103     KLineEdit *m_addressInput;
0104 
0105     FloatingToolBar *m_toolBar;
0106 
0107     BookmarkManager *m_bookmarkManager;
0108 
0109     QMap<QWidget *, RemoteView *> m_remoteViewMap;
0110     QMap<int, RemoteViewFactory *> m_remoteViewFactories;
0111 
0112     int m_currentRemoteView;
0113     bool m_switchFullscreenWhenConnected;
0114 
0115     SystemTrayIcon *m_systemTrayIcon;
0116     QTableView *m_dockWidgetTableView;
0117     QTableView *m_newConnectionTableView;
0118     RemoteDesktopsModel *m_remoteDesktopsModel;
0119     QWidget *m_newConnectionWidget;
0120 
0121 Q_SIGNALS:
0122     void scaleUpdated(bool scale); // scale state has changed
0123     void factorUpdated(int factor); // factor havlue has changed
0124 };
0125 
0126 #include <QApplication>
0127 #include <QMouseEvent>
0128 #include <QScreen>
0129 
0130 class MinimizePixel : public QWidget
0131 {
0132     Q_OBJECT
0133 public:
0134     explicit MinimizePixel(QWidget *parent)
0135         : QWidget(parent)
0136     {
0137         setFixedSize(1, 1);
0138         move(screen()->geometry().width() - 1, 0);
0139     }
0140 
0141 Q_SIGNALS:
0142     void rightClicked();
0143 
0144 protected:
0145     void mousePressEvent(QMouseEvent *event) override
0146     {
0147         if (event->button() == Qt::RightButton)
0148             Q_EMIT rightClicked();
0149     }
0150 };
0151 
0152 #include <QScrollArea>
0153 
0154 class RemoteViewScrollArea : public QScrollArea
0155 {
0156     Q_OBJECT
0157 public:
0158     explicit RemoteViewScrollArea(QWidget *parent)
0159         : QScrollArea(parent)
0160     {
0161     }
0162 
0163 Q_SIGNALS:
0164     void resized(int w, int h);
0165 
0166 protected:
0167     void resizeEvent(QResizeEvent *event) override
0168     {
0169         QScrollArea::resizeEvent(event);
0170         Q_EMIT resized(width() - 2 * frameWidth(), height() - 2 * frameWidth());
0171     }
0172 };
0173 
0174 #endif