32 #include <QApplication>
33 #include <QCommandLineParser>
35 #include <QDesktopWidget>
38 #include "audio/audio.h"
39 #include <vpx/vpx_image.h>
42 #include <QActionGroup>
44 #include <QSignalMapper>
56 Q_DECLARE_OPAQUE_POINTER(ToxAV*)
58 static Nexus* nexus{
nullptr};
86 qDebug() <<
"Starting up";
89 qRegisterMetaType<Status::Status>(
"Status::Status");
90 qRegisterMetaType<vpx_image>(
"vpx_image");
91 qRegisterMetaType<uint8_t>(
"uint8_t");
92 qRegisterMetaType<uint16_t>(
"uint16_t");
93 qRegisterMetaType<uint32_t>(
"uint32_t");
94 qRegisterMetaType<const int16_t*>(
"const int16_t*");
95 qRegisterMetaType<int32_t>(
"int32_t");
96 qRegisterMetaType<int64_t>(
"int64_t");
97 qRegisterMetaType<size_t>(
"size_t");
98 qRegisterMetaType<QPixmap>(
"QPixmap");
99 qRegisterMetaType<Profile*>(
"Profile*");
100 qRegisterMetaType<ToxAV*>(
"ToxAV*");
101 qRegisterMetaType<ToxFile>(
"ToxFile");
102 qRegisterMetaType<ToxFile::FileDirection>(
"ToxFile::FileDirection");
103 qRegisterMetaType<std::shared_ptr<VideoFrame>>(
"std::shared_ptr<VideoFrame>");
104 qRegisterMetaType<ToxPk>(
"ToxPk");
105 qRegisterMetaType<ToxId>(
"ToxId");
106 qRegisterMetaType<ToxPk>(
"GroupId");
107 qRegisterMetaType<ToxPk>(
"ContactId");
108 qRegisterMetaType<GroupInvite>(
"GroupInvite");
109 qRegisterMetaType<ReceiptNum>(
"ReceiptNum");
110 qRegisterMetaType<RowId>(
"RowId");
111 qRegisterMetaType<uint64_t>(
"uint64_t");
112 qRegisterMetaType<ExtensionSet>(
"ExtensionSet");
114 qApp->setQuitOnLastWindowClosed(
false);
118 globalMenuBar =
new QMenuBar();
119 dockMenu =
new QMenu(globalMenuBar);
121 viewMenu = globalMenuBar->addMenu(QString());
123 windowMenu = globalMenuBar->addMenu(QString());
124 globalMenuBar->addAction(windowMenu->menuAction());
126 fullscreenAction = viewMenu->addAction(QString());
127 fullscreenAction->setShortcut(QKeySequence::FullScreen);
128 connect(fullscreenAction, &QAction::triggered,
this, &Nexus::toggleFullscreen);
130 minimizeAction = windowMenu->addAction(QString());
131 minimizeAction->setShortcut(Qt::CTRL + Qt::Key_M);
132 connect(minimizeAction, &QAction::triggered, [
this]() {
133 minimizeAction->setEnabled(
false);
134 QApplication::focusWindow()->showMinimized();
137 windowMenu->addSeparator();
138 frontAction = windowMenu->addAction(QString());
139 connect(frontAction, &QAction::triggered,
this, &Nexus::bringAllToFront);
141 QAction* quitAction =
new QAction(globalMenuBar);
142 quitAction->setMenuRole(QAction::QuitRole);
143 connect(quitAction, &QAction::triggered, qApp, &QApplication::quit);
164 QCoreApplication::sendPostedEvents(
nullptr, QEvent::DeferredDelete);
170 int returnval = loginScreen.exec();
171 if (returnval == QDialog::Rejected) {
196 if (this->settings) {
200 if (this->settings) {
247 Qt::BlockingQueuedConnection);
346 void Nexus::retranslateUi()
348 viewMenu->menuAction()->setText(tr(
"View",
"OS X Menu bar"));
349 windowMenu->menuAction()->setText(tr(
"Window",
"OS X Menu bar"));
350 minimizeAction->setText(tr(
"Minimize",
"OS X Menu bar"));
351 frontAction->setText((tr(
"Bring All to Front",
"OS X Menu bar")));
354 void Nexus::onWindowStateChanged(Qt::WindowStates state)
356 minimizeAction->setEnabled(QApplication::activeWindow() !=
nullptr);
358 if (QApplication::activeWindow() !=
nullptr && sender() == QApplication::activeWindow()) {
359 if (state & Qt::WindowFullScreen)
360 minimizeAction->setEnabled(
false);
362 if (state & Qt::WindowFullScreen)
363 fullscreenAction->setText(tr(
"Exit Fullscreen"));
365 fullscreenAction->setText(tr(
"Enter Fullscreen"));
370 updateWindowsStates();
373 void Nexus::updateWindows()
375 updateWindowsArg(
nullptr);
378 void Nexus::updateWindowsArg(QWindow* closedWindow)
380 QWindowList windowList = QApplication::topLevelWindows();
381 delete windowActions;
382 windowActions =
new QActionGroup(
this);
384 windowMenu->addSeparator();
387 if (!dockMenu->actions().isEmpty())
388 dockLast = dockMenu->actions().first();
392 QWindow* activeWindow;
394 if (QApplication::activeWindow())
395 activeWindow = QApplication::activeWindow()->windowHandle();
397 activeWindow =
nullptr;
399 for (
int i = 0; i < windowList.size(); ++i) {
400 if (closedWindow == windowList[i])
403 QAction* action = windowActions->addAction(windowList[i]->title());
404 action->setCheckable(
true);
405 action->setChecked(windowList[i] == activeWindow);
406 connect(action, &QAction::triggered, [=] { onOpenWindow(windowList[i]); });
407 windowMenu->addAction(action);
408 dockMenu->insertAction(dockLast, action);
411 if (dockLast && !dockLast->isSeparator())
412 dockMenu->insertSeparator(dockLast);
415 void Nexus::updateWindowsClosed()
417 updateWindowsArg(
static_cast<QWidget*
>(sender())->windowHandle());
420 void Nexus::updateWindowsStates()
423 QWindowList windowList = QApplication::topLevelWindows();
425 for (QWindow* window : windowList) {
426 if (!(window->windowState() & Qt::WindowMinimized)) {
432 frontAction->setEnabled(exists);
435 void Nexus::onOpenWindow(QObject*
object)
437 QWindow* window =
static_cast<QWindow*
>(object);
439 if (window->windowState() & QWindow::Minimized)
440 window->showNormal();
443 window->requestActivate();
446 void Nexus::toggleFullscreen()
448 QWidget* window = QApplication::activeWindow();
450 if (window->isFullScreen())
451 window->showNormal();
453 window->showFullScreen();
456 void Nexus::bringAllToFront()
458 QWindowList windowList = QApplication::topLevelWindows();
459 QWindow* focused = QApplication::focusWindow();
461 for (QWindow* window : windowList)