Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/editexecutablesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ EditExecutablesDialog::EditExecutablesDialog(OrganizerCore& oc, int sel,
connect(ui->useApplicationIcon, &QCheckBox::toggled, [&] {
save();
});
connect(ui->minimizeToSystemTray, &QCheckBox::toggled, [&] {
save();
});
connect(ui->hide, &QCheckBox::toggled, [&] {
save();
});
Expand Down Expand Up @@ -382,6 +385,8 @@ void EditExecutablesDialog::clearEdits()
ui->configureLibraries->setEnabled(false);
ui->useApplicationIcon->setEnabled(false);
ui->useApplicationIcon->setChecked(false);
ui->minimizeToSystemTray->setEnabled(false);
ui->minimizeToSystemTray->setChecked(false);
ui->hide->setEnabled(false);
ui->hide->setChecked(false);

Expand All @@ -398,6 +403,7 @@ void EditExecutablesDialog::setEdits(const Executable& e)
ui->steamAppID->setEnabled(!e.steamAppID().isEmpty());
ui->steamAppID->setText(e.steamAppID());
ui->useApplicationIcon->setChecked(e.usesOwnIcon());
ui->minimizeToSystemTray->setChecked(e.minimizeToSystemTray());
ui->hide->setChecked(e.hide());

m_lastGoodTitle = e.title();
Expand Down Expand Up @@ -443,6 +449,7 @@ void EditExecutablesDialog::setEdits(const Executable& e)
ui->useApplicationIcon->setEnabled(true);
ui->createFilesInMod->setEnabled(true);
ui->forceLoadLibraries->setEnabled(true);
ui->minimizeToSystemTray->setEnabled(true);
ui->hide->setEnabled(true);
}

Expand Down Expand Up @@ -503,6 +510,12 @@ void EditExecutablesDialog::save()
e->flags(e->flags() & (~Executable::UseApplicationIcon));
}

if (ui->minimizeToSystemTray->isChecked()) {
e->flags(e->flags() | Executable::MinimizeToSystemTray);
} else {
e->flags(e->flags() & (~Executable::MinimizeToSystemTray));
}

if (ui->hide->isChecked()) {
e->flags(e->flags() | Executable::Hide);
} else {
Expand Down
13 changes: 13 additions & 0 deletions src/editexecutablesdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,19 @@ Right now the only case I know of where this needs to be overwritten is for the
<string>Use application's icon for desktop shortcuts</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="minimizeToSystemTray">
<property name="toolTip">
<string>Mod Organizer will minimize to the system tray while this executable is running. It will reappear after it finishes.</string>
</property>
<property name="whatsThis">
<string>Mod Organizer will minimize to the system tray while this executable is running. It will reappear after it finishes.</string>
</property>
<property name="text">
<string>Minimize to system tray while running</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="hide">
Expand Down
25 changes: 17 additions & 8 deletions src/executableslist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ void ExecutablesList::load(const MOBase::IPluginGame* game, const Settings& s)
if (map["ownicon"].toBool())
flags |= Executable::UseApplicationIcon;

if (map["minimizeToSystemTray"].toBool())
flags |= Executable::MinimizeToSystemTray;

if (map["hide"].toBool())
flags |= Executable::Hide;

Expand Down Expand Up @@ -114,14 +117,15 @@ void ExecutablesList::store(Settings& s)
for (const auto& item : *this) {
std::map<QString, QVariant> map;

map["title"] = item.title();
map["toolbar"] = item.isShownOnToolbar();
map["ownicon"] = item.usesOwnIcon();
map["hide"] = item.hide();
map["binary"] = item.binaryInfo().filePath();
map["arguments"] = item.arguments();
map["workingDirectory"] = item.workingDirectory();
map["steamAppID"] = item.steamAppID();
map["title"] = item.title();
map["toolbar"] = item.isShownOnToolbar();
map["ownicon"] = item.usesOwnIcon();
map["hide"] = item.hide();
map["binary"] = item.binaryInfo().filePath();
map["arguments"] = item.arguments();
map["workingDirectory"] = item.workingDirectory();
map["steamAppID"] = item.steamAppID();
map["minimizeToSystemTray"] = item.minimizeToSystemTray();

v.push_back(std::move(map));
}
Expand Down Expand Up @@ -464,6 +468,11 @@ bool Executable::usesOwnIcon() const
return m_flags.testFlag(UseApplicationIcon);
}

bool Executable::minimizeToSystemTray() const
{
return m_flags.testFlag(MinimizeToSystemTray);
}

bool Executable::hide() const
{
return m_flags.testFlag(Hide);
Expand Down
8 changes: 5 additions & 3 deletions src/executableslist.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ class Executable
public:
enum Flag
{
ShowInToolbar = 0x02,
UseApplicationIcon = 0x04,
Hide = 0x08
ShowInToolbar = 0x02,
UseApplicationIcon = 0x04,
Hide = 0x08,
MinimizeToSystemTray = 0x16
};

Q_DECLARE_FLAGS(Flags, Flag);
Expand Down Expand Up @@ -74,6 +75,7 @@ class Executable
bool isShownOnToolbar() const;
void setShownOnToolbar(bool state);
bool usesOwnIcon() const;
bool minimizeToSystemTray() const;
bool hide() const;

void mergeFrom(const Executable& other);
Expand Down
20 changes: 19 additions & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "shared/appconfig.h"
#include "spawn.h"
#include "statusbar.h"
#include "systemtraymanager.h"
#include <bsainvalidation.h>
#include <dataarchives.h>
#include <safewritefile.h>
Expand Down Expand Up @@ -238,7 +239,8 @@ MainWindow::MainWindow(Settings& settings, OrganizerCore& organizerCore,
m_PluginContainer(pluginContainer),
m_ArchiveListWriter(std::bind(&MainWindow::saveArchiveList, this)),
m_LinkToolbar(nullptr), m_LinkDesktop(nullptr), m_LinkStartMenu(nullptr),
m_NumberOfProblems(0), m_ProblemsCheckRequired(false)
m_SystemTrayManager(nullptr), m_NumberOfProblems(0),
m_ProblemsCheckRequired(false)
{
// disables incredibly slow menu fade in effect that looks and feels like crap.
// this was only happening to users with the windows
Expand All @@ -265,6 +267,8 @@ MainWindow::MainWindow(Settings& settings, OrganizerCore& organizerCore,
languageChange(settings.interface().language());
ui->statusBar->setup(ui, settings);

m_SystemTrayManager = new SystemTrayManager(this, ui->logDock);

{
auto& ni = NexusInterface::instance();

Expand Down Expand Up @@ -477,6 +481,12 @@ MainWindow::MainWindow(Settings& settings, OrganizerCore& organizerCore,
m_Tutorial.expose("espList", m_OrganizerCore.pluginList());

m_OrganizerCore.setUserInterface(this);
m_OrganizerCore.onFinishedRun([=](const QString, unsigned int) {
if (isHidden()) {
m_SystemTrayManager->restoreFromSystemTray();
}
});

connect(m_OrganizerCore.modList(), &ModList::showMessage, [=](auto&& message) {
showMessage(message);
});
Expand Down Expand Up @@ -1697,6 +1707,10 @@ void MainWindow::startExeAction()
action->setEnabled(true);
});

if (itor->minimizeToSystemTray()) {
m_SystemTrayManager->minimizeToSystemTray();
}

m_OrganizerCore.processRunner()
.setFromExecutable(*itor)
.setWaitForCompletion(ProcessRunner::TriggerRefresh)
Expand Down Expand Up @@ -2271,6 +2285,10 @@ void MainWindow::on_startButton_clicked()
ui->startButton->setEnabled(true);
});

if (selectedExecutable->minimizeToSystemTray()) {
m_SystemTrayManager->minimizeToSystemTray();
}

m_OrganizerCore.processRunner()
.setFromExecutable(*selectedExecutable)
.setWaitForCompletion(ProcessRunner::TriggerRefresh)
Expand Down
3 changes: 3 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "modlistsortproxy.h"
#include "plugincontainer.h"
#include "shared/fileregisterfwd.h"
#include "systemtraymanager.h"

class Executable;
class CategoryFactory;
Expand Down Expand Up @@ -310,6 +311,8 @@ private slots:
QAction* m_LinkDesktop;
QAction* m_LinkStartMenu;

SystemTrayManager* m_SystemTrayManager;

// icon set by the stylesheet, used to remember its original appearance
// when painting the count
QIcon m_originalNotificationIcon;
Expand Down
77 changes: 77 additions & 0 deletions src/systemtraymanager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
Copyright (C) 2012 Sebastian Herbord. All rights reserved.

This file is part of Mod Organizer.

Mod Organizer is free 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.

Mod Organizer 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 Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
*/

#include "systemtraymanager.h"

#include <QAction>
#include <QDockWidget>
#include <QIcon>
#include <QMainWindow>
#include <QMenu>
#include <QSystemTrayIcon>

SystemTrayManager::SystemTrayManager(QMainWindow* parent, QDockWidget* logDock)
: m_Parent(parent), m_LogDock(logDock),
m_SystemTrayIcon(new QSystemTrayIcon(QIcon(":/MO/gui/app_icon"), m_Parent))
{
m_SystemTrayIcon->setToolTip(tr("Mod Organizer"));

connect(m_SystemTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this,
SLOT(on_systemTrayIcon_activated(QSystemTrayIcon::ActivationReason)));

auto* exitAction = new QAction(tr("Exit"), m_SystemTrayIcon);
connect(exitAction, &QAction::triggered, m_Parent, &QMainWindow::close);

auto* trayMenu = new QMenu(m_Parent);
trayMenu->addAction(exitAction);

m_SystemTrayIcon->setContextMenu(trayMenu);
}

void SystemTrayManager::minimizeToSystemTray()
{
m_SystemTrayIcon->show();
m_Parent->hide();

if (m_LogDock->isFloating() && m_LogDock->isVisible()) {
m_LogDock->hide();
}
}

void SystemTrayManager::restoreFromSystemTray()
{
m_SystemTrayIcon->hide();

m_Parent->showNormal();
m_Parent->raise();
m_Parent->activateWindow();

if (m_LogDock->isFloating() && m_LogDock->isHidden()) {
m_LogDock->show();
}
}

void SystemTrayManager::on_systemTrayIcon_activated(
QSystemTrayIcon::ActivationReason reason)
{
if (m_Parent->isHidden() && reason == QSystemTrayIcon::Trigger) {
// left click
restoreFromSystemTray();
}
}
48 changes: 48 additions & 0 deletions src/systemtraymanager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Copyright (C) 2012 Sebastian Herbord. All rights reserved.

This file is part of Mod Organizer.

Mod Organizer is free 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.

Mod Organizer 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 Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef SYSTEMTRAYMANAGER_H
#define SYSTEMTRAYMANAGER_H

#include <QDockWidget>
#include <QMainWindow>
#include <QObject>
#include <QSystemTrayIcon>

class SystemTrayManager : public QObject
{
Q_OBJECT

public:
explicit SystemTrayManager(QMainWindow* parent, QDockWidget* logDock);

void minimizeToSystemTray();
void restoreFromSystemTray();

private:
QMainWindow* m_Parent;
QDockWidget* m_LogDock;

QSystemTrayIcon* m_SystemTrayIcon;

private slots:
void on_systemTrayIcon_activated(QSystemTrayIcon::ActivationReason reason);
};

#endif // SYSTEMTRAYMANAGER_H