Skip to content
Open
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
16 changes: 16 additions & 0 deletions src/downloadmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include <QHttp2Configuration>
#include <QInputDialog>
#include <QMessageBox>
#include <QSystemTrayIcon>
#include <QTextDocument>
#include <QTimer>

Expand Down Expand Up @@ -1365,7 +1366,11 @@ QString DownloadManager::getDisplayName(int index) const
}

DownloadInfo* info = m_ActiveDownloads.at(index);
return displayNameByInfo(info);
}

QString DownloadManager::displayNameByInfo(const DownloadInfo* info) const
{
QTextDocument doc;
if (!info->m_FileInfo->name.isEmpty()) {
doc.setHtml(info->m_FileInfo->name);
Expand Down Expand Up @@ -1789,6 +1794,11 @@ void DownloadManager::nxmDescriptionAvailable(QString, int, QVariant userData,
info->m_FileInfo->modName = doc.toPlainText();
if (info->m_FileInfo->fileID != 0) {
setState(info, STATE_READY);
if (m_OrganizerCore->settings().interface().showDownloadNotifications()) {
m_OrganizerCore->showNotification(
tr("Download complete"),
tr("%1 is ready to be installed.").arg(displayNameByInfo(info)));
}
} else {
setState(info, STATE_FETCHINGFILEINFO);
}
Expand Down Expand Up @@ -2278,6 +2288,12 @@ void DownloadManager::downloadFinished(int index)
emit showMessage(tr("Download failed: %1 (%2)")
.arg(reply->errorString())
.arg(reply->error()));
if (m_OrganizerCore->settings().interface().showDownloadNotifications()) {
m_OrganizerCore->showNotification(
tr("Download failed"),
tr("%1 failed to download.").arg(displayNameByInfo(info)),
QSystemTrayIcon::MessageIcon::Critical);
}
}
error = true;
setState(info, STATE_ERROR);
Expand Down
2 changes: 2 additions & 0 deletions src/downloadmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,8 @@ private slots:

DownloadInfo* downloadInfoByID(unsigned int id);

QString displayNameByInfo(const DownloadInfo* info) const;

void removePending(QString gameName, int modID, int fileID);

static QString getFileTypeString(int fileType);
Expand Down
5 changes: 5 additions & 0 deletions src/iuserinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "modinfodialogfwd.h"
#include <QMainWindow>
#include <QMenu>
#include <QSystemTrayIcon>
#include <delayedfilewriter.h>
#include <ipluginmodpage.h>
#include <iplugintool.h>
Expand All @@ -27,6 +28,10 @@ class IUserInterface
virtual MOBase::DelayedFileWriterBase& archivesWriter() = 0;

virtual QMainWindow* mainWindow() = 0;

virtual void showNotification(const QString& title, const QString& message,
QSystemTrayIcon::MessageIcon icon =
QSystemTrayIcon::MessageIcon::Information) = 0;
};

#endif // IUSERINTERFACE_H
7 changes: 7 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include <QShortcut>
#include <QSize>
#include <QSizePolicy>
#include <QSystemTrayIcon>
#include <QTime>
#include <QTimer>
#include <QToolButton>
Expand Down Expand Up @@ -2259,6 +2260,12 @@ QMainWindow* MainWindow::mainWindow()
return this;
}

void MainWindow::showNotification(const QString& title, const QString& message,
QSystemTrayIcon::MessageIcon icon)
{
m_SystemTrayManager->showNotification(title, message, icon);
}

void MainWindow::on_tabWidget_currentChanged(int index)
{
QWidget* currentWidget = ui->tabWidget->widget(index);
Expand Down
5 changes: 5 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class DirectoryEntry;
#include <QProcess>
#include <QString>
#include <QStringList>
#include <QSystemTrayIcon>
#include <QTime>
#include <QTimer>
#include <QVariant>
Expand Down Expand Up @@ -156,6 +157,10 @@ class MainWindow : public QMainWindow, public IUserInterface
return m_ArchiveListWriter;
}

void showNotification(const QString& title, const QString& message,
QSystemTrayIcon::MessageIcon icon =
QSystemTrayIcon::MessageIcon::Information) override;

public slots:
void refresherProgress(const DirectoryRefreshProgress* p);

Expand Down
9 changes: 9 additions & 0 deletions src/organizercore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <QMessageBox>
#include <QNetworkInterface>
#include <QProcess>
#include <QSystemTrayIcon>
#include <QTimer>
#include <QUrl>
#include <QWidget>
Expand Down Expand Up @@ -539,6 +540,14 @@ std::wstring OrganizerCore::getGlobalCoreDumpPath()
return {};
}

void OrganizerCore::showNotification(const QString& message, const QString& title,
QSystemTrayIcon::MessageIcon icon)
{
if (m_UserInterface) {
m_UserInterface->showNotification(message, title, icon);
}
}

void OrganizerCore::setCurrentProfile(const QString& profileName)
{
if ((m_CurrentProfile != nullptr) && (profileName == m_CurrentProfile->name())) {
Expand Down
5 changes: 5 additions & 0 deletions src/organizercore.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QSettings>
#include <QString>
#include <QStringList>
#include <QSystemTrayIcon>
#include <QThread>
#include <QVariant>

Expand Down Expand Up @@ -360,6 +361,10 @@ class OrganizerCore : public QObject, public MOBase::IPluginDiagnose
static void setGlobalCoreDumpType(env::CoreDumpTypes type);
static std::wstring getGlobalCoreDumpPath();

void showNotification(
const QString& title, const QString& message,
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon::Information);

public:
MOBase::IModRepositoryBridge* createNexusBridge() const;
QString profileName() const;
Expand Down
10 changes: 10 additions & 0 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2263,6 +2263,16 @@ void InterfaceSettings::setHideDownloadsAfterInstallation(bool b)
set(m_Settings, "Settings", "autohide_downloads", b);
}

bool InterfaceSettings::showDownloadNotifications() const
{
return get<bool>(m_Settings, "Settings", "download_notifications", false);
}

void InterfaceSettings::setShowDownloadNotifications(bool b)
{
set(m_Settings, "Settings", "download_notifications", b);
}

bool InterfaceSettings::hideAPICounter() const
{
return get<bool>(m_Settings, "Settings", "hide_api_counter", false);
Expand Down
5 changes: 5 additions & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,11 @@ class InterfaceSettings
bool hideDownloadsAfterInstallation() const;
void setHideDownloadsAfterInstallation(bool b);

// whether to show notifications when downloads complete or fail
//
bool showDownloadNotifications() const;
void setShowDownloadNotifications(bool b);

// whether the API counter should be hidden
//
bool hideAPICounter() const;
Expand Down
17 changes: 15 additions & 2 deletions src/settingsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,19 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="showDownloadNotificationsBox">
<property name="toolTip">
<string>Show notifications when downloads complete or fail.</string>
</property>
<property name="whatsThis">
<string>Show notifications when downloads complete or fail.</string>
</property>
<property name="text">
<string>Show notifications for completed or failed downloads</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand All @@ -178,10 +191,10 @@
<item>
<widget class="QCheckBox" name="checkForUpdates">
<property name="toolTip">
<string>Check for Mod Organizer updates on Github on startup.</string>
<string>Check for Mod Organizer updates on GitHub on startup.</string>
</property>
<property name="whatsThis">
<string>Check for Mod Organizer updates on Github on startup.</string>
<string>Check for Mod Organizer updates on GitHub on startup.</string>
</property>
<property name="text">
<string>Check for updates</string>
Expand Down
4 changes: 4 additions & 0 deletions src/settingsdialoggeneral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ GeneralSettingsTab::GeneralSettingsTab(Settings& s, SettingsDialog& d)
ui->showMetaBox->setChecked(settings().interface().metaDownloads());
ui->hideDownloadInstallBox->setChecked(
settings().interface().hideDownloadsAfterInstallation());
ui->showDownloadNotificationsBox->setChecked(
settings().interface().showDownloadNotifications());

// updates
ui->checkForUpdates->setChecked(settings().checkForUpdates());
Expand Down Expand Up @@ -64,6 +66,8 @@ void GeneralSettingsTab::update()
settings().interface().setMetaDownloads(ui->showMetaBox->isChecked());
settings().interface().setHideDownloadsAfterInstallation(
ui->hideDownloadInstallBox->isChecked());
settings().interface().setShowDownloadNotifications(
ui->showDownloadNotificationsBox->isChecked());

// updates
settings().setCheckForUpdates(ui->checkForUpdates->isChecked());
Expand Down
11 changes: 8 additions & 3 deletions src/systemtraymanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include <QIcon>
#include <QMainWindow>
#include <QMenu>
#include <QString>
#include <QSystemTrayIcon>

SystemTrayManager::SystemTrayManager(QMainWindow* parent, QDockWidget* logDock)
Expand All @@ -42,11 +43,11 @@ SystemTrayManager::SystemTrayManager(QMainWindow* parent, QDockWidget* logDock)
trayMenu->addAction(exitAction);

m_SystemTrayIcon->setContextMenu(trayMenu);
m_SystemTrayIcon->show();
}

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

if (m_LogDock->isFloating() && m_LogDock->isVisible()) {
Expand All @@ -56,8 +57,6 @@ void SystemTrayManager::minimizeToSystemTray()

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

m_Parent->showNormal();
m_Parent->raise();
m_Parent->activateWindow();
Expand All @@ -67,6 +66,12 @@ void SystemTrayManager::restoreFromSystemTray()
}
}

void SystemTrayManager::showNotification(const QString& title, const QString& message,
QSystemTrayIcon::MessageIcon icon)
{
m_SystemTrayIcon->showMessage(title, message, icon);
}

void SystemTrayManager::on_systemTrayIcon_activated(
QSystemTrayIcon::ActivationReason reason)
{
Expand Down
6 changes: 6 additions & 0 deletions src/systemtraymanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#define SYSTEMTRAYMANAGER_H

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

class SystemTrayManager : public QObject
Expand All @@ -35,6 +37,10 @@ class SystemTrayManager : public QObject
void minimizeToSystemTray();
void restoreFromSystemTray();

void showNotification(
const QString& title, const QString& message,
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon::Information);

private:
QMainWindow* m_Parent;
QDockWidget* m_LogDock;
Expand Down