transmission/qt/DetailsDialog.h

146 lines
4.0 KiB
C
Raw Normal View History

// 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),
// 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
#pragma once
2009-04-09 18:55:47 +00:00
#include <map>
#include <memory>
#include <unordered_set>
2009-04-09 18:55:47 +00:00
#include <QString>
#include <QTimer>
#include <libtransmission/tr-macros.h>
#include "BaseDialog.h"
#include "Session.h"
#include "Typedefs.h"
#include "ui_DetailsDialog.h"
#include "ui_TrackersDialog.h"
2009-04-09 18:55:47 +00:00
class QTreeWidgetItem;
2015-06-12 22:12:12 +00:00
class Prefs;
2009-04-09 18:55:47 +00:00
class Session;
class Torrent;
class TorrentModel;
class TrackerDelegate;
class TrackerModel;
class TrackerModelFilter;
2009-04-09 18:55:47 +00:00
class DetailsDialog : public BaseDialog
2009-04-09 18:55:47 +00:00
{
Q_OBJECT
TR_DISABLE_COPY_MOVE(DetailsDialog)
public:
DetailsDialog(Session&, Prefs&, TorrentModel const&, QWidget* parent = nullptr);
~DetailsDialog() override;
2015-06-12 22:12:12 +00:00
void setIds(torrent_ids_t const& ids);
2015-06-12 22:12:12 +00:00
// QWidget
QSize sizeHint() const override
{
return QSize{ 440, 460 };
}
private:
void initPeersTab();
void initTrackerTab();
void initInfoTab();
void initFilesTab() const;
void initOptionsTab();
void setEnabled(bool);
private slots:
void refreshModel();
void refreshPref(int key);
void refreshUI();
void onTorrentsEdited(torrent_ids_t const& ids);
void onTorrentsChanged(torrent_ids_t const& ids, Torrent::fields_t const& fields);
void onSessionCalled(Session::Tag tag);
2015-06-12 22:12:12 +00:00
// Tracker tab
void onTrackerSelectionChanged();
void onAddTrackerClicked();
void onEditTrackersClicked();
void onRemoveTrackerClicked();
void onShowTrackerScrapesToggled(bool);
void onShowBackupTrackersToggled(bool);
void onTrackerListEdited(QString);
2015-06-12 22:12:12 +00:00
// Files tab
void onFilePriorityChanged(file_indices_t const& file_indices, int);
void onFileWantedChanged(file_indices_t const& file_indices, bool);
void onPathEdited(QString const& old_path, QString const& new_name);
void onOpenRequested(QString const& path) const;
2015-06-12 22:12:12 +00:00
// Options tab
void onBandwidthPriorityChanged(int);
void onHonorsSessionLimitsToggled(bool);
void onDownloadLimitedToggled(bool);
void onSpinBoxEditingFinished();
void onUploadLimitedToggled(bool);
void onRatioModeChanged(int);
void onIdleModeChanged(int);
void onIdleLimitChanged();
private:
/* When a torrent property is edited in the details dialog (e.g.
file priority, speed limits, etc.), don't update those UI fields
until we know the server has processed the request. This keeps
the UI from appearing to undo the change if we receive a refresh
that was already in-flight _before_ the property was edited. */
bool canEdit() const
{
return std::empty(pending_changes_tags_);
}
std::unordered_set<Session::Tag> pending_changes_tags_;
QMetaObject::Connection pending_changes_connection_;
template<typename T>
void torrentSet(torrent_ids_t const& ids, tr_quark key, T val)
{
auto const tag = session_.torrentSet(ids, key, val);
pending_changes_tags_.insert(tag);
if (!pending_changes_connection_)
{
pending_changes_connection_ = connect(&session_, &Session::sessionCalled, this, &DetailsDialog::onSessionCalled);
}
}
template<typename T>
void torrentSet(tr_quark key, T val)
{
torrentSet(ids_, key, val);
}
Session& session_;
Prefs& prefs_;
TorrentModel const& model_;
2015-06-12 22:12:12 +00:00
Ui::DetailsDialog ui_ = {};
Ui::TrackersDialog trackers_ui_ = {};
2015-06-12 22:12:12 +00:00
torrent_ids_t ids_;
QTimer model_timer_;
QTimer ui_debounce_timer_;
2015-06-12 22:12:12 +00:00
std::shared_ptr<TrackerModel> tracker_model_;
std::shared_ptr<TrackerModelFilter> tracker_filter_;
std::shared_ptr<TrackerDelegate> tracker_delegate_;
2015-06-12 22:12:12 +00:00
std::map<QString, QTreeWidgetItem*> peers_;
QIcon const icon_encrypted_ = QIcon(QStringLiteral(":/icons/encrypted.svg"));
QIcon const icon_unencrypted_ = {};
static int prev_tab_index_;
2009-04-09 18:55:47 +00:00
};