2015-06-06 09:40:08 +08:00
|
|
|
/*
|
2019-06-24 22:01:18 +08:00
|
|
|
Copyright © 2014-2019 by The qTox Project Contributors
|
2015-06-06 09:40:08 +08:00
|
|
|
|
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
|
|
|
qTox is libre software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
qTox is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2015-02-06 19:28:49 +08:00
|
|
|
#include "nexus.h"
|
2017-02-26 19:52:45 +08:00
|
|
|
#include "persistence/settings.h"
|
2016-12-19 10:26:26 +08:00
|
|
|
#include "src/core/core.h"
|
|
|
|
#include "src/core/coreav.h"
|
2017-08-27 15:13:14 +08:00
|
|
|
#include "src/model/groupinvite.h"
|
2019-04-22 15:54:15 +08:00
|
|
|
#include "src/model/status.h"
|
2017-02-26 19:52:45 +08:00
|
|
|
#include "src/persistence/profile.h"
|
2016-12-19 10:26:26 +08:00
|
|
|
#include "src/widget/widget.h"
|
2015-05-14 10:46:28 +08:00
|
|
|
#include "video/camerasource.h"
|
2015-02-07 02:01:31 +08:00
|
|
|
#include "widget/gui.h"
|
2015-06-04 07:30:17 +08:00
|
|
|
#include "widget/loginscreen.h"
|
2017-02-26 19:52:45 +08:00
|
|
|
#include <QApplication>
|
2019-08-16 22:55:29 +08:00
|
|
|
#include <QCommandLineParser>
|
2015-02-06 19:28:49 +08:00
|
|
|
#include <QDebug>
|
2017-02-26 19:52:45 +08:00
|
|
|
#include <QDesktopWidget>
|
|
|
|
#include <QThread>
|
2015-06-04 07:30:17 +08:00
|
|
|
#include <cassert>
|
2019-06-24 07:15:33 +08:00
|
|
|
#include <src/audio/audio.h>
|
2019-06-29 19:14:38 +08:00
|
|
|
#include <vpx/vpx_image.h>
|
2015-02-06 19:28:49 +08:00
|
|
|
|
2015-07-09 20:43:19 +08:00
|
|
|
#ifdef Q_OS_MAC
|
2015-07-30 07:46:19 +08:00
|
|
|
#include <QActionGroup>
|
2017-02-26 19:52:45 +08:00
|
|
|
#include <QMenuBar>
|
2015-07-30 07:46:19 +08:00
|
|
|
#include <QSignalMapper>
|
2017-02-26 19:52:45 +08:00
|
|
|
#include <QWindow>
|
2015-07-09 20:43:19 +08:00
|
|
|
#endif
|
|
|
|
|
2016-07-27 06:21:22 +08:00
|
|
|
/**
|
2016-08-01 16:20:56 +08:00
|
|
|
* @class Nexus
|
|
|
|
*
|
|
|
|
* This class is in charge of connecting various systems together
|
|
|
|
* and forwarding signals appropriately to the right objects,
|
|
|
|
* it is in charge of starting the GUI and the Core.
|
|
|
|
*/
|
2016-07-27 06:21:22 +08:00
|
|
|
|
2015-10-08 06:52:05 +08:00
|
|
|
Q_DECLARE_OPAQUE_POINTER(ToxAV*)
|
|
|
|
|
2015-02-07 02:38:08 +08:00
|
|
|
static Nexus* nexus{nullptr};
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
Nexus::Nexus(QObject* parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, profile{nullptr}
|
|
|
|
, widget{nullptr}
|
2018-06-30 18:10:46 +08:00
|
|
|
{}
|
2015-02-06 19:28:49 +08:00
|
|
|
|
|
|
|
Nexus::~Nexus()
|
|
|
|
{
|
|
|
|
delete widget;
|
2017-02-17 12:55:23 +08:00
|
|
|
widget = nullptr;
|
2015-06-04 17:42:49 +08:00
|
|
|
delete profile;
|
2017-02-17 12:55:23 +08:00
|
|
|
profile = nullptr;
|
2019-06-24 07:15:33 +08:00
|
|
|
emit saveGlobal();
|
2015-07-09 20:43:19 +08:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
delete globalMenuBar;
|
|
|
|
#endif
|
2015-02-06 19:28:49 +08:00
|
|
|
}
|
|
|
|
|
2016-07-27 06:21:22 +08:00
|
|
|
/**
|
2016-08-01 16:20:56 +08:00
|
|
|
* @brief Sets up invariants and calls showLogin
|
|
|
|
*
|
|
|
|
* Hides the login screen and shows the GUI for the given profile.
|
|
|
|
* Will delete the current GUI, if it exists.
|
|
|
|
*/
|
2015-02-06 19:28:49 +08:00
|
|
|
void Nexus::start()
|
|
|
|
{
|
2015-05-11 20:54:03 +08:00
|
|
|
qDebug() << "Starting up";
|
2015-02-06 19:28:49 +08:00
|
|
|
|
|
|
|
// Setup the environment
|
2019-04-22 15:54:15 +08:00
|
|
|
qRegisterMetaType<Status::Status>("Status::Status");
|
2015-02-06 19:28:49 +08:00
|
|
|
qRegisterMetaType<vpx_image>("vpx_image");
|
|
|
|
qRegisterMetaType<uint8_t>("uint8_t");
|
|
|
|
qRegisterMetaType<uint16_t>("uint16_t");
|
2015-04-20 05:12:44 +08:00
|
|
|
qRegisterMetaType<uint32_t>("uint32_t");
|
2015-02-06 19:28:49 +08:00
|
|
|
qRegisterMetaType<const int16_t*>("const int16_t*");
|
|
|
|
qRegisterMetaType<int32_t>("int32_t");
|
|
|
|
qRegisterMetaType<int64_t>("int64_t");
|
2020-03-18 01:05:48 +08:00
|
|
|
qRegisterMetaType<size_t>("size_t");
|
2015-02-06 19:28:49 +08:00
|
|
|
qRegisterMetaType<QPixmap>("QPixmap");
|
2015-06-06 21:54:58 +08:00
|
|
|
qRegisterMetaType<Profile*>("Profile*");
|
2015-10-08 06:52:05 +08:00
|
|
|
qRegisterMetaType<ToxAV*>("ToxAV*");
|
2015-02-06 19:28:49 +08:00
|
|
|
qRegisterMetaType<ToxFile>("ToxFile");
|
|
|
|
qRegisterMetaType<ToxFile::FileDirection>("ToxFile::FileDirection");
|
2015-05-14 10:46:28 +08:00
|
|
|
qRegisterMetaType<std::shared_ptr<VideoFrame>>("std::shared_ptr<VideoFrame>");
|
2017-01-04 11:46:15 +08:00
|
|
|
qRegisterMetaType<ToxPk>("ToxPk");
|
2016-12-30 19:46:11 +08:00
|
|
|
qRegisterMetaType<ToxId>("ToxId");
|
2019-04-12 04:38:37 +08:00
|
|
|
qRegisterMetaType<ToxPk>("GroupId");
|
|
|
|
qRegisterMetaType<ToxPk>("ContactId");
|
2017-08-27 15:13:14 +08:00
|
|
|
qRegisterMetaType<GroupInvite>("GroupInvite");
|
2019-04-12 04:38:37 +08:00
|
|
|
qRegisterMetaType<ReceiptNum>("ReceiptNum");
|
|
|
|
qRegisterMetaType<RowId>("RowId");
|
2015-02-06 19:28:49 +08:00
|
|
|
|
2018-02-22 05:23:55 +08:00
|
|
|
qApp->setQuitOnLastWindowClosed(false);
|
|
|
|
|
2015-07-09 20:43:19 +08:00
|
|
|
#ifdef Q_OS_MAC
|
2018-01-09 02:49:06 +08:00
|
|
|
// TODO: still needed?
|
2020-03-17 18:29:55 +08:00
|
|
|
globalMenuBar = new QMenuBar();
|
2015-07-30 07:46:19 +08:00
|
|
|
dockMenu = new QMenu(globalMenuBar);
|
2015-07-09 20:43:19 +08:00
|
|
|
|
2015-07-30 07:46:19 +08:00
|
|
|
viewMenu = globalMenuBar->addMenu(QString());
|
|
|
|
|
|
|
|
windowMenu = globalMenuBar->addMenu(QString());
|
2015-07-09 20:43:19 +08:00
|
|
|
globalMenuBar->addAction(windowMenu->menuAction());
|
|
|
|
|
2015-07-30 07:46:19 +08:00
|
|
|
fullscreenAction = viewMenu->addAction(QString());
|
|
|
|
fullscreenAction->setShortcut(QKeySequence::FullScreen);
|
|
|
|
connect(fullscreenAction, &QAction::triggered, this, &Nexus::toggleFullscreen);
|
|
|
|
|
|
|
|
minimizeAction = windowMenu->addAction(QString());
|
2015-07-09 20:43:19 +08:00
|
|
|
minimizeAction->setShortcut(Qt::CTRL + Qt::Key_M);
|
2017-02-26 19:52:45 +08:00
|
|
|
connect(minimizeAction, &QAction::triggered, [this]() {
|
2015-07-30 07:46:19 +08:00
|
|
|
minimizeAction->setEnabled(false);
|
2015-07-09 20:43:19 +08:00
|
|
|
QApplication::focusWindow()->showMinimized();
|
|
|
|
});
|
2015-07-30 07:46:19 +08:00
|
|
|
|
|
|
|
windowMenu->addSeparator();
|
|
|
|
frontAction = windowMenu->addAction(QString());
|
|
|
|
connect(frontAction, &QAction::triggered, this, &Nexus::bringAllToFront);
|
2015-07-09 20:43:19 +08:00
|
|
|
|
|
|
|
QAction* quitAction = new QAction(globalMenuBar);
|
|
|
|
quitAction->setMenuRole(QAction::QuitRole);
|
|
|
|
connect(quitAction, &QAction::triggered, qApp, &QApplication::quit);
|
|
|
|
|
2015-07-30 07:46:19 +08:00
|
|
|
retranslateUi();
|
|
|
|
#endif
|
2018-01-09 02:49:06 +08:00
|
|
|
showMainGUI();
|
2015-06-04 07:30:17 +08:00
|
|
|
}
|
|
|
|
|
2016-07-27 06:21:22 +08:00
|
|
|
/**
|
2016-08-01 16:20:56 +08:00
|
|
|
* @brief Hides the main GUI, delete the profile, and shows the login screen
|
|
|
|
*/
|
2019-06-24 07:15:33 +08:00
|
|
|
int Nexus::showLogin(const QString& profileName)
|
2015-06-04 07:30:17 +08:00
|
|
|
{
|
2015-06-04 17:56:19 +08:00
|
|
|
delete widget;
|
|
|
|
widget = nullptr;
|
|
|
|
|
|
|
|
delete profile;
|
|
|
|
profile = nullptr;
|
|
|
|
|
2019-06-24 07:15:33 +08:00
|
|
|
LoginScreen loginScreen{profileName};
|
|
|
|
connectLoginScreen(loginScreen);
|
2018-01-09 02:49:06 +08:00
|
|
|
|
2019-09-04 21:19:02 +08:00
|
|
|
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
|
|
|
|
|
2019-06-24 07:15:33 +08:00
|
|
|
// TODO(kriby): Move core out of profile
|
|
|
|
// This is awkward because the core is in the profile
|
|
|
|
// The connection order ensures profile will be ready for bootstrap for now
|
|
|
|
connect(this, &Nexus::currentProfileChanged, this, &Nexus::bootstrapWithProfile);
|
|
|
|
int returnval = loginScreen.exec();
|
2019-10-17 01:49:30 +08:00
|
|
|
if (returnval == QDialog::Rejected) {
|
|
|
|
// Kriby: This will terminate the main application loop, necessary until we refactor
|
|
|
|
// away the split startup/return to login behavior.
|
|
|
|
qApp->quit();
|
|
|
|
}
|
2019-06-24 07:15:33 +08:00
|
|
|
disconnect(this, &Nexus::currentProfileChanged, this, &Nexus::bootstrapWithProfile);
|
|
|
|
return returnval;
|
|
|
|
}
|
|
|
|
|
2019-06-29 19:14:38 +08:00
|
|
|
void Nexus::bootstrapWithProfile(Profile* p)
|
2019-06-24 07:15:33 +08:00
|
|
|
{
|
|
|
|
// kriby: This is a hack until a proper controller is written
|
|
|
|
|
|
|
|
profile = p;
|
2018-01-09 02:49:06 +08:00
|
|
|
|
|
|
|
if (profile) {
|
2019-06-24 07:15:33 +08:00
|
|
|
audioControl = std::unique_ptr<IAudioControl>(Audio::makeAudio(*settings));
|
|
|
|
assert(audioControl != nullptr);
|
|
|
|
profile->getCore()->getAv()->setAudio(*audioControl);
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Nexus::setSettings(Settings* settings)
|
|
|
|
{
|
|
|
|
if (this->settings) {
|
|
|
|
QObject::disconnect(this, &Nexus::saveGlobal, this->settings, &Settings::saveGlobal);
|
2018-01-09 02:49:06 +08:00
|
|
|
}
|
2019-06-24 07:15:33 +08:00
|
|
|
this->settings = settings;
|
|
|
|
if (this->settings) {
|
|
|
|
QObject::connect(this, &Nexus::saveGlobal, this->settings, &Settings::saveGlobal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Nexus::connectLoginScreen(const LoginScreen& loginScreen)
|
|
|
|
{
|
|
|
|
// TODO(kriby): Move connect sequences to a controller class object instead
|
|
|
|
|
|
|
|
// Nexus -> LoginScreen
|
|
|
|
QObject::connect(this, &Nexus::profileLoaded, &loginScreen, &LoginScreen::onProfileLoaded);
|
|
|
|
QObject::connect(this, &Nexus::profileLoadFailed, &loginScreen, &LoginScreen::onProfileLoadFailed);
|
|
|
|
// LoginScreen -> Nexus
|
|
|
|
QObject::connect(&loginScreen, &LoginScreen::createNewProfile, this, &Nexus::onCreateNewProfile);
|
|
|
|
QObject::connect(&loginScreen, &LoginScreen::loadProfile, this, &Nexus::onLoadProfile);
|
|
|
|
// LoginScreen -> Settings
|
2019-06-24 07:37:35 +08:00
|
|
|
QObject::connect(&loginScreen, &LoginScreen::autoLoginChanged, settings, &Settings::setAutoLogin);
|
|
|
|
QObject::connect(&loginScreen, &LoginScreen::autoLoginChanged, settings, &Settings::saveGlobal);
|
2019-06-24 07:15:33 +08:00
|
|
|
// Settings -> LoginScreen
|
|
|
|
QObject::connect(settings, &Settings::autoLoginChanged, &loginScreen,
|
|
|
|
&LoginScreen::onAutoLoginChanged);
|
2015-06-04 07:30:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Nexus::showMainGUI()
|
|
|
|
{
|
2019-06-24 07:15:33 +08:00
|
|
|
// TODO(kriby): Rewrite as view-model connect sequence only, add to a controller class object
|
2015-06-04 07:30:17 +08:00
|
|
|
assert(profile);
|
|
|
|
|
2015-02-19 04:22:03 +08:00
|
|
|
// Create GUI
|
2019-06-29 19:14:38 +08:00
|
|
|
widget = new Widget(*audioControl);
|
2015-02-19 04:22:03 +08:00
|
|
|
|
2015-02-06 19:28:49 +08:00
|
|
|
// Start GUI
|
2015-02-19 04:22:03 +08:00
|
|
|
widget->init();
|
2015-02-07 02:01:31 +08:00
|
|
|
GUI::getInstance();
|
2015-02-06 19:28:49 +08:00
|
|
|
|
2015-04-26 03:05:29 +08:00
|
|
|
// Zetok protection
|
|
|
|
// There are small instants on startup during which no
|
|
|
|
// profile is loaded but the GUI could still receive events,
|
|
|
|
// e.g. between two modal windows. Disable the GUI to prevent that.
|
|
|
|
GUI::setEnabled(false);
|
|
|
|
|
2015-02-06 19:28:49 +08:00
|
|
|
// Connections
|
2017-05-07 03:59:46 +08:00
|
|
|
connect(profile, &Profile::selfAvatarChanged, widget, &Widget::onSelfAvatarLoaded);
|
|
|
|
|
2019-06-24 18:34:26 +08:00
|
|
|
connect(profile, &Profile::coreChanged, widget, &Widget::onCoreChanged);
|
2017-05-06 20:35:54 +08:00
|
|
|
|
2018-06-27 15:22:24 +08:00
|
|
|
connect(profile, &Profile::failedToStart, widget, &Widget::onFailedToStartCore,
|
2017-02-26 19:52:45 +08:00
|
|
|
Qt::BlockingQueuedConnection);
|
2019-06-24 18:34:26 +08:00
|
|
|
|
2018-06-27 15:22:24 +08:00
|
|
|
connect(profile, &Profile::badProxy, widget, &Widget::onBadProxyCore, Qt::BlockingQueuedConnection);
|
2015-02-06 19:28:49 +08:00
|
|
|
|
2015-06-04 07:30:17 +08:00
|
|
|
profile->startCore();
|
2018-06-26 21:55:21 +08:00
|
|
|
|
|
|
|
GUI::setEnabled(true);
|
2015-02-06 19:28:49 +08:00
|
|
|
}
|
|
|
|
|
2016-07-27 06:21:22 +08:00
|
|
|
/**
|
2016-08-01 16:20:56 +08:00
|
|
|
* @brief Returns the singleton instance.
|
|
|
|
*/
|
2015-02-06 19:28:49 +08:00
|
|
|
Nexus& Nexus::getInstance()
|
|
|
|
{
|
2015-02-07 02:38:08 +08:00
|
|
|
if (!nexus)
|
|
|
|
nexus = new Nexus;
|
2015-04-24 19:01:50 +08:00
|
|
|
|
2015-02-07 02:38:08 +08:00
|
|
|
return *nexus;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Nexus::destroyInstance()
|
|
|
|
{
|
|
|
|
delete nexus;
|
|
|
|
nexus = nullptr;
|
2015-02-06 19:28:49 +08:00
|
|
|
}
|
|
|
|
|
2016-07-27 06:21:22 +08:00
|
|
|
/**
|
2016-08-01 16:20:56 +08:00
|
|
|
* @brief Get core instance.
|
|
|
|
* @return nullptr if not started, core instance otherwise.
|
|
|
|
*/
|
2015-02-06 19:28:49 +08:00
|
|
|
Core* Nexus::getCore()
|
|
|
|
{
|
2015-06-04 07:30:17 +08:00
|
|
|
Nexus& nexus = getInstance();
|
|
|
|
if (!nexus.profile)
|
|
|
|
return nullptr;
|
2016-07-07 18:10:53 +08:00
|
|
|
|
2015-06-04 07:30:17 +08:00
|
|
|
return nexus.profile->getCore();
|
|
|
|
}
|
|
|
|
|
2016-07-27 06:21:22 +08:00
|
|
|
/**
|
2016-08-01 16:20:56 +08:00
|
|
|
* @brief Get current user profile.
|
|
|
|
* @return nullptr if not started, profile otherwise.
|
|
|
|
*/
|
2015-06-04 07:30:17 +08:00
|
|
|
Profile* Nexus::getProfile()
|
|
|
|
{
|
|
|
|
return getInstance().profile;
|
|
|
|
}
|
|
|
|
|
2016-07-27 06:21:22 +08:00
|
|
|
/**
|
2019-06-24 07:15:33 +08:00
|
|
|
* @brief Creates a new profile and replaces the current one.
|
|
|
|
* @param name New username
|
|
|
|
* @param pass New password
|
|
|
|
*/
|
|
|
|
void Nexus::onCreateNewProfile(const QString& name, const QString& pass)
|
|
|
|
{
|
2019-08-16 22:55:29 +08:00
|
|
|
setProfile(Profile::createProfile(name, pass, *settings, parser));
|
|
|
|
parser = nullptr; // only apply cmdline proxy settings once
|
2019-06-24 07:15:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads an existing profile and replaces the current one.
|
2016-08-01 16:20:56 +08:00
|
|
|
*/
|
2019-06-24 07:15:33 +08:00
|
|
|
void Nexus::onLoadProfile(const QString& name, const QString& pass)
|
2015-06-04 07:30:17 +08:00
|
|
|
{
|
2019-08-16 22:55:29 +08:00
|
|
|
setProfile(Profile::loadProfile(name, pass, *settings, parser));
|
|
|
|
parser = nullptr; // only apply cmdline proxy settings once
|
2019-06-24 07:15:33 +08:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Changes the loaded profile and notifies listeners.
|
|
|
|
* @param p
|
|
|
|
*/
|
2019-06-29 19:14:38 +08:00
|
|
|
void Nexus::setProfile(Profile* p)
|
|
|
|
{
|
2019-06-24 07:15:33 +08:00
|
|
|
if (!p) {
|
|
|
|
emit profileLoadFailed();
|
|
|
|
// Warnings are issued during respective createNew/load calls
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
emit profileLoaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
emit currentProfileChanged(p);
|
2015-02-06 19:28:49 +08:00
|
|
|
}
|
2015-02-07 02:01:31 +08:00
|
|
|
|
2019-08-16 22:55:29 +08:00
|
|
|
void Nexus::setParser(QCommandLineParser* parser)
|
|
|
|
{
|
|
|
|
this->parser = parser;
|
|
|
|
}
|
|
|
|
|
2016-07-27 06:21:22 +08:00
|
|
|
/**
|
2016-08-01 16:20:56 +08:00
|
|
|
* @brief Get desktop GUI widget.
|
|
|
|
* @return nullptr if not started, desktop widget otherwise.
|
|
|
|
*/
|
2015-02-07 02:01:31 +08:00
|
|
|
Widget* Nexus::getDesktopGUI()
|
|
|
|
{
|
|
|
|
return getInstance().widget;
|
|
|
|
}
|
2015-02-16 07:35:27 +08:00
|
|
|
|
2015-07-30 07:46:19 +08:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
void Nexus::retranslateUi()
|
|
|
|
{
|
|
|
|
viewMenu->menuAction()->setText(tr("View", "OS X Menu bar"));
|
|
|
|
windowMenu->menuAction()->setText(tr("Window", "OS X Menu bar"));
|
|
|
|
minimizeAction->setText(tr("Minimize", "OS X Menu bar"));
|
|
|
|
frontAction->setText((tr("Bring All to Front", "OS X Menu bar")));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Nexus::onWindowStateChanged(Qt::WindowStates state)
|
|
|
|
{
|
|
|
|
minimizeAction->setEnabled(QApplication::activeWindow() != nullptr);
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
if (QApplication::activeWindow() != nullptr && sender() == QApplication::activeWindow()) {
|
2015-07-30 07:46:19 +08:00
|
|
|
if (state & Qt::WindowFullScreen)
|
|
|
|
minimizeAction->setEnabled(false);
|
|
|
|
|
|
|
|
if (state & Qt::WindowFullScreen)
|
|
|
|
fullscreenAction->setText(tr("Exit Fullscreen"));
|
|
|
|
else
|
|
|
|
fullscreenAction->setText(tr("Enter Fullscreen"));
|
|
|
|
|
|
|
|
updateWindows();
|
|
|
|
}
|
|
|
|
|
|
|
|
updateWindowsStates();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Nexus::updateWindows()
|
|
|
|
{
|
|
|
|
updateWindowsArg(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Nexus::updateWindowsArg(QWindow* closedWindow)
|
|
|
|
{
|
|
|
|
QWindowList windowList = QApplication::topLevelWindows();
|
|
|
|
delete windowActions;
|
|
|
|
windowActions = new QActionGroup(this);
|
|
|
|
|
|
|
|
windowMenu->addSeparator();
|
|
|
|
|
|
|
|
QAction* dockLast;
|
2016-07-31 22:17:11 +08:00
|
|
|
if (!dockMenu->actions().isEmpty())
|
2015-07-30 07:46:19 +08:00
|
|
|
dockLast = dockMenu->actions().first();
|
|
|
|
else
|
|
|
|
dockLast = nullptr;
|
|
|
|
|
|
|
|
QWindow* activeWindow;
|
|
|
|
|
|
|
|
if (QApplication::activeWindow())
|
|
|
|
activeWindow = QApplication::activeWindow()->windowHandle();
|
|
|
|
else
|
|
|
|
activeWindow = nullptr;
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
for (int i = 0; i < windowList.size(); ++i) {
|
2015-07-30 07:46:19 +08:00
|
|
|
if (closedWindow == windowList[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
QAction* action = windowActions->addAction(windowList[i]->title());
|
|
|
|
action->setCheckable(true);
|
|
|
|
action->setChecked(windowList[i] == activeWindow);
|
2019-08-16 22:55:29 +08:00
|
|
|
connect(action, &QAction::triggered, [=] { onOpenWindow(windowList[i]); });
|
2015-07-30 07:46:19 +08:00
|
|
|
windowMenu->addAction(action);
|
|
|
|
dockMenu->insertAction(dockLast, action);
|
|
|
|
}
|
|
|
|
|
2015-10-23 21:21:47 +08:00
|
|
|
if (dockLast && !dockLast->isSeparator())
|
2015-07-30 07:46:19 +08:00
|
|
|
dockMenu->insertSeparator(dockLast);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Nexus::updateWindowsClosed()
|
|
|
|
{
|
|
|
|
updateWindowsArg(static_cast<QWidget*>(sender())->windowHandle());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Nexus::updateWindowsStates()
|
|
|
|
{
|
|
|
|
bool exists = false;
|
|
|
|
QWindowList windowList = QApplication::topLevelWindows();
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
for (QWindow* window : windowList) {
|
|
|
|
if (!(window->windowState() & Qt::WindowMinimized)) {
|
2015-07-30 07:46:19 +08:00
|
|
|
exists = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
frontAction->setEnabled(exists);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Nexus::onOpenWindow(QObject* object)
|
|
|
|
{
|
|
|
|
QWindow* window = static_cast<QWindow*>(object);
|
|
|
|
|
|
|
|
if (window->windowState() & QWindow::Minimized)
|
|
|
|
window->showNormal();
|
|
|
|
|
|
|
|
window->raise();
|
|
|
|
window->requestActivate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Nexus::toggleFullscreen()
|
|
|
|
{
|
|
|
|
QWidget* window = QApplication::activeWindow();
|
|
|
|
|
|
|
|
if (window->isFullScreen())
|
|
|
|
window->showNormal();
|
|
|
|
else
|
|
|
|
window->showFullScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Nexus::bringAllToFront()
|
|
|
|
{
|
|
|
|
QWindowList windowList = QApplication::topLevelWindows();
|
|
|
|
QWindow* focused = QApplication::focusWindow();
|
|
|
|
|
|
|
|
for (QWindow* window : windowList)
|
|
|
|
window->raise();
|
|
|
|
|
|
|
|
focused->raise();
|
|
|
|
}
|
|
|
|
#endif
|