2023-02-11 20:49:42 +00:00
|
|
|
// This file Copyright © 2009-2023 Mnemosyne LLC.
|
2022-08-08 18:05:39 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
#pragma once
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2022-01-13 02:13:58 +00:00
|
|
|
#include <ctime>
|
2020-11-08 19:54:40 +00:00
|
|
|
#include <memory>
|
2020-09-08 03:52:29 +00:00
|
|
|
#include <unordered_set>
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QApplication>
|
2021-10-24 23:52:50 +00:00
|
|
|
#include <QRegularExpression>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QTimer>
|
2010-11-25 03:00:25 +00:00
|
|
|
#include <QTranslator>
|
2023-04-23 02:11:16 +00:00
|
|
|
#include <QWeakPointer>
|
2010-08-01 18:55:04 +00:00
|
|
|
|
2021-12-14 08:43:27 +00:00
|
|
|
#include <libtransmission/tr-macros.h>
|
2023-04-23 02:11:16 +00:00
|
|
|
#include <libtransmission/favicon-cache.h>
|
2021-12-14 08:43:27 +00:00
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
#include "Typedefs.h"
|
2020-09-08 03:52:29 +00:00
|
|
|
#include "Utils.h" // std::hash<QString>
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2010-08-01 18:55:04 +00:00
|
|
|
class AddData;
|
2022-11-15 16:25:12 +00:00
|
|
|
class MainWindow;
|
2009-04-09 18:55:47 +00:00
|
|
|
class Prefs;
|
|
|
|
class Session;
|
2019-11-12 23:13:42 +00:00
|
|
|
class Torrent;
|
2009-04-09 18:55:47 +00:00
|
|
|
class TorrentModel;
|
|
|
|
class WatchDir;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
class Application : public QApplication
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-01-26 01:19:54 +00:00
|
|
|
Q_OBJECT
|
2020-08-11 18:11:55 +00:00
|
|
|
TR_DISABLE_COPY_MOVE(Application)
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
public:
|
|
|
|
Application(int& argc, char** argv);
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-11-08 19:54:40 +00:00
|
|
|
void raise() const;
|
2021-10-23 14:26:28 +00:00
|
|
|
bool notifyApp(QString const& title, QString const& body, QStringList const& actions = {}) const;
|
2010-04-27 03:10:32 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
QString const& intern(QString const& in)
|
|
|
|
{
|
|
|
|
return *interned_strings_.insert(in).first;
|
|
|
|
}
|
|
|
|
|
2023-04-23 02:11:16 +00:00
|
|
|
[[nodiscard]] QPixmap find_favicon(QString const& sitename) const
|
|
|
|
{
|
|
|
|
auto const key = sitename.toStdString();
|
|
|
|
auto const* const icon = favicon_cache_.find(key);
|
|
|
|
return icon != nullptr ? *icon : QPixmap{};
|
|
|
|
}
|
|
|
|
|
|
|
|
void load_favicon(QString const& url)
|
|
|
|
{
|
|
|
|
auto weak_self = QPointer<Application>{ this };
|
|
|
|
|
|
|
|
favicon_cache_.load(
|
|
|
|
url.toStdString(),
|
|
|
|
[weak_self = std::move(weak_self)](QPixmap const* /*favicon_or_nullptr*/)
|
|
|
|
{
|
|
|
|
if (!weak_self.isNull())
|
|
|
|
{
|
|
|
|
weak_self.data()->faviconsChanged();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void faviconsChanged();
|
2015-06-12 22:12:12 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
public slots:
|
2020-11-08 19:54:40 +00:00
|
|
|
void addTorrent(AddData const&) const;
|
|
|
|
void addTorrent(QString const&) const;
|
2010-07-25 17:16:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
private slots:
|
2020-11-08 19:54:40 +00:00
|
|
|
void consentGiven(int result) const;
|
|
|
|
void onSessionSourceChanged() const;
|
2022-09-08 23:26:18 +00:00
|
|
|
void onTorrentsAdded(torrent_ids_t const& torrent_ids) const;
|
|
|
|
void onTorrentsCompleted(torrent_ids_t const& torrent_ids) const;
|
|
|
|
void onTorrentsEdited(torrent_ids_t const& torrent_ids) const;
|
|
|
|
void onTorrentsNeedInfo(torrent_ids_t const& torrent_ids) const;
|
2020-11-08 19:54:40 +00:00
|
|
|
void refreshPref(int key) const;
|
2019-11-12 23:13:42 +00:00
|
|
|
void refreshTorrents();
|
2020-11-08 19:54:40 +00:00
|
|
|
void saveGeometry() const;
|
2021-10-23 14:26:28 +00:00
|
|
|
#ifdef QT_DBUS_LIB
|
|
|
|
void onNotificationActionInvoked(quint32 notification_id, QString action_key);
|
|
|
|
#endif
|
2019-11-09 14:44:40 +00:00
|
|
|
|
|
|
|
private:
|
2020-11-08 19:54:40 +00:00
|
|
|
void maybeUpdateBlocklist() const;
|
2019-11-09 14:44:40 +00:00
|
|
|
void loadTranslations();
|
2019-11-12 01:37:05 +00:00
|
|
|
QStringList getNames(torrent_ids_t const& ids) const;
|
2020-11-02 01:13:32 +00:00
|
|
|
void quitLater() const;
|
2021-10-23 14:26:28 +00:00
|
|
|
void notifyTorrentAdded(Torrent const*) const;
|
2010-04-27 03:10:32 +00:00
|
|
|
|
2020-11-08 19:54:40 +00:00
|
|
|
std::unique_ptr<Prefs> prefs_;
|
|
|
|
std::unique_ptr<Session> session_;
|
|
|
|
std::unique_ptr<TorrentModel> model_;
|
|
|
|
std::unique_ptr<MainWindow> window_;
|
|
|
|
std::unique_ptr<WatchDir> watch_dir_;
|
2020-05-27 21:53:12 +00:00
|
|
|
QTimer model_timer_;
|
|
|
|
QTimer stats_timer_;
|
|
|
|
QTimer session_timer_;
|
|
|
|
time_t last_full_update_time_ = {};
|
|
|
|
QTranslator qt_translator_;
|
|
|
|
QTranslator app_translator_;
|
2023-04-23 02:11:16 +00:00
|
|
|
|
|
|
|
FaviconCache<QPixmap> favicon_cache_;
|
2020-08-15 15:42:51 +00:00
|
|
|
|
2020-11-02 01:13:32 +00:00
|
|
|
QString const config_name_ = QStringLiteral("transmission");
|
|
|
|
QString const display_name_ = QStringLiteral("transmission-qt");
|
2020-09-08 03:52:29 +00:00
|
|
|
|
|
|
|
std::unordered_set<QString> interned_strings_;
|
2021-10-24 23:52:50 +00:00
|
|
|
|
|
|
|
#ifdef QT_DBUS_LIB
|
|
|
|
QString const fdo_notifications_service_name_ = QStringLiteral("org.freedesktop.Notifications");
|
|
|
|
QString const fdo_notifications_path_ = QStringLiteral("/org/freedesktop/Notifications");
|
|
|
|
QString const fdo_notifications_interface_name_ = QStringLiteral("org.freedesktop.Notifications");
|
|
|
|
QRegularExpression const start_now_regex_;
|
|
|
|
#endif
|
2009-04-09 18:55:47 +00:00
|
|
|
};
|
|
|
|
|
2022-02-08 03:56:04 +00:00
|
|
|
#define trApp dynamic_cast<Application*>(Application::instance())
|