Skip to content

Commit 6a606b6

Browse files
Add setting to show notifications when downloads complete or fail
1 parent 4da0bff commit 6a606b6

13 files changed

+98
-5
lines changed

src/downloadmanager.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
4242
#include <QHttp2Configuration>
4343
#include <QInputDialog>
4444
#include <QMessageBox>
45+
#include <QSystemTrayIcon>
4546
#include <QTextDocument>
4647
#include <QTimer>
4748

@@ -1365,7 +1366,11 @@ QString DownloadManager::getDisplayName(int index) const
13651366
}
13661367

13671368
DownloadInfo* info = m_ActiveDownloads.at(index);
1369+
return displayNameByInfo(info);
1370+
}
13681371

1372+
QString DownloadManager::displayNameByInfo(const DownloadInfo* info) const
1373+
{
13691374
QTextDocument doc;
13701375
if (!info->m_FileInfo->name.isEmpty()) {
13711376
doc.setHtml(info->m_FileInfo->name);
@@ -1789,6 +1794,11 @@ void DownloadManager::nxmDescriptionAvailable(QString, int, QVariant userData,
17891794
info->m_FileInfo->modName = doc.toPlainText();
17901795
if (info->m_FileInfo->fileID != 0) {
17911796
setState(info, STATE_READY);
1797+
if (m_OrganizerCore->settings().interface().showDownloadNotifications()) {
1798+
m_OrganizerCore->showNotification(
1799+
tr("Download complete"),
1800+
tr("%1 is ready to be installed.").arg(displayNameByInfo(info)));
1801+
}
17921802
} else {
17931803
setState(info, STATE_FETCHINGFILEINFO);
17941804
}
@@ -2278,6 +2288,12 @@ void DownloadManager::downloadFinished(int index)
22782288
emit showMessage(tr("Download failed: %1 (%2)")
22792289
.arg(reply->errorString())
22802290
.arg(reply->error()));
2291+
if (m_OrganizerCore->settings().interface().showDownloadNotifications()) {
2292+
m_OrganizerCore->showNotification(
2293+
tr("Download failed"),
2294+
tr("%1 failed to download.").arg(displayNameByInfo(info)),
2295+
QSystemTrayIcon::MessageIcon::Critical);
2296+
}
22812297
}
22822298
error = true;
22832299
setState(info, STATE_ERROR);

src/downloadmanager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,8 @@ private slots:
588588

589589
DownloadInfo* downloadInfoByID(unsigned int id);
590590

591+
QString displayNameByInfo(const DownloadInfo* info) const;
592+
591593
void removePending(QString gameName, int modID, int fileID);
592594

593595
static QString getFileTypeString(int fileType);

src/iuserinterface.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "modinfodialogfwd.h"
55
#include <QMainWindow>
66
#include <QMenu>
7+
#include <QSystemTrayIcon>
78
#include <delayedfilewriter.h>
89
#include <ipluginmodpage.h>
910
#include <iplugintool.h>
@@ -27,6 +28,10 @@ class IUserInterface
2728
virtual MOBase::DelayedFileWriterBase& archivesWriter() = 0;
2829

2930
virtual QMainWindow* mainWindow() = 0;
31+
32+
virtual void showNotification(const QString& title, const QString& message,
33+
QSystemTrayIcon::MessageIcon icon =
34+
QSystemTrayIcon::MessageIcon::Information) = 0;
3035
};
3136

3237
#endif // IUSERINTERFACE_H

src/mainwindow.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
139139
#include <QShortcut>
140140
#include <QSize>
141141
#include <QSizePolicy>
142+
#include <QSystemTrayIcon>
142143
#include <QTime>
143144
#include <QTimer>
144145
#include <QToolButton>
@@ -2259,6 +2260,12 @@ QMainWindow* MainWindow::mainWindow()
22592260
return this;
22602261
}
22612262

2263+
void MainWindow::showNotification(const QString& title, const QString& message,
2264+
QSystemTrayIcon::MessageIcon icon)
2265+
{
2266+
m_SystemTrayManager->showNotification(title, message, icon);
2267+
}
2268+
22622269
void MainWindow::on_tabWidget_currentChanged(int index)
22632270
{
22642271
QWidget* currentWidget = ui->tabWidget->widget(index);

src/mainwindow.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class DirectoryEntry;
7878
#include <QProcess>
7979
#include <QString>
8080
#include <QStringList>
81+
#include <QSystemTrayIcon>
8182
#include <QTime>
8283
#include <QTimer>
8384
#include <QVariant>
@@ -156,6 +157,10 @@ class MainWindow : public QMainWindow, public IUserInterface
156157
return m_ArchiveListWriter;
157158
}
158159

160+
void showNotification(const QString& title, const QString& message,
161+
QSystemTrayIcon::MessageIcon icon =
162+
QSystemTrayIcon::MessageIcon::Information) override;
163+
159164
public slots:
160165
void refresherProgress(const DirectoryRefreshProgress* p);
161166

src/organizercore.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include <QMessageBox>
4747
#include <QNetworkInterface>
4848
#include <QProcess>
49+
#include <QSystemTrayIcon>
4950
#include <QTimer>
5051
#include <QUrl>
5152
#include <QWidget>
@@ -539,6 +540,14 @@ std::wstring OrganizerCore::getGlobalCoreDumpPath()
539540
return {};
540541
}
541542

543+
void OrganizerCore::showNotification(const QString& message, const QString& title,
544+
QSystemTrayIcon::MessageIcon icon)
545+
{
546+
if (m_UserInterface) {
547+
m_UserInterface->showNotification(message, title, icon);
548+
}
549+
}
550+
542551
void OrganizerCore::setCurrentProfile(const QString& profileName)
543552
{
544553
if ((m_CurrentProfile != nullptr) && (profileName == m_CurrentProfile->name())) {

src/organizercore.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <QSettings>
99
#include <QString>
1010
#include <QStringList>
11+
#include <QSystemTrayIcon>
1112
#include <QThread>
1213
#include <QVariant>
1314

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

364+
void showNotification(
365+
const QString& title, const QString& message,
366+
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon::Information);
367+
363368
public:
364369
MOBase::IModRepositoryBridge* createNexusBridge() const;
365370
QString profileName() const;

src/settings.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,6 +2263,16 @@ void InterfaceSettings::setHideDownloadsAfterInstallation(bool b)
22632263
set(m_Settings, "Settings", "autohide_downloads", b);
22642264
}
22652265

2266+
bool InterfaceSettings::showDownloadNotifications() const
2267+
{
2268+
return get<bool>(m_Settings, "Settings", "download_notifications", false);
2269+
}
2270+
2271+
void InterfaceSettings::setShowDownloadNotifications(bool b)
2272+
{
2273+
set(m_Settings, "Settings", "download_notifications", b);
2274+
}
2275+
22662276
bool InterfaceSettings::hideAPICounter() const
22672277
{
22682278
return get<bool>(m_Settings, "Settings", "hide_api_counter", false);

src/settings.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,11 @@ class InterfaceSettings
653653
bool hideDownloadsAfterInstallation() const;
654654
void setHideDownloadsAfterInstallation(bool b);
655655

656+
// whether to show notifications when downloads complete or fail
657+
//
658+
bool showDownloadNotifications() const;
659+
void setShowDownloadNotifications(bool b);
660+
656661
// whether the API counter should be hidden
657662
//
658663
bool hideAPICounter() const;

src/settingsdialog.ui

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,19 @@
166166
</property>
167167
</widget>
168168
</item>
169+
<item>
170+
<widget class="QCheckBox" name="showDownloadNotificationsBox">
171+
<property name="toolTip">
172+
<string>Show notifications when downloads complete or fail.</string>
173+
</property>
174+
<property name="whatsThis">
175+
<string>Show notifications when downloads complete or fail.</string>
176+
</property>
177+
<property name="text">
178+
<string>Show notifications for completed or failed downloads</string>
179+
</property>
180+
</widget>
181+
</item>
169182
</layout>
170183
</widget>
171184
</item>
@@ -178,10 +191,10 @@
178191
<item>
179192
<widget class="QCheckBox" name="checkForUpdates">
180193
<property name="toolTip">
181-
<string>Check for Mod Organizer updates on Github on startup.</string>
194+
<string>Check for Mod Organizer updates on GitHub on startup.</string>
182195
</property>
183196
<property name="whatsThis">
184-
<string>Check for Mod Organizer updates on Github on startup.</string>
197+
<string>Check for Mod Organizer updates on GitHub on startup.</string>
185198
</property>
186199
<property name="text">
187200
<string>Check for updates</string>

0 commit comments

Comments
 (0)