qBittorrent
TorrentFileGuard Class Reference

#include <torrentfileguard.h>

Inheritance diagram for TorrentFileGuard:
Collaboration diagram for TorrentFileGuard:

Public Types

enum  AutoDeleteMode : int { Never , IfAdded , Always }
 

Public Member Functions

 TorrentFileGuard (const QString &path={})
 
 ~TorrentFileGuard ()
 
void markAsAddedToSession ()
 marks the torrent file as loaded (added) into the BitTorrent::Session More...
 
void setAutoRemove (bool remove) noexcept
 Cancels or re-enables deferred file deletion. More...
 

Static Public Member Functions

static AutoDeleteMode autoDeleteMode ()
 
static void setAutoDeleteMode (AutoDeleteMode mode)
 

Private Member Functions

 TorrentFileGuard (const QString &path, AutoDeleteMode mode)
 
- Private Member Functions inherited from FileGuard
 FileGuard (const QString &path={})
 
 ~FileGuard ()
 
void setAutoRemove (bool remove) noexcept
 Cancels or re-enables deferred file deletion. More...
 

Static Private Member Functions

static SettingValue< AutoDeleteMode > & autoDeleteModeSetting ()
 

Private Attributes

AutoDeleteMode m_mode
 
bool m_wasAdded
 

Detailed Description

Reads settings for .torrent files from preferences and sets the file guard up accordingly

Definition at line 53 of file torrentfileguard.h.

Member Enumeration Documentation

◆ AutoDeleteMode

Enumerator
Never 
IfAdded 
Always 

Definition at line 65 of file torrentfileguard.h.

Constructor & Destructor Documentation

◆ TorrentFileGuard() [1/2]

TorrentFileGuard::TorrentFileGuard ( const QString &  path = {})
explicit

Definition at line 58 of file torrentfileguard.cpp.

60 {
61 }
static AutoDeleteMode autoDeleteMode()

◆ ~TorrentFileGuard()

TorrentFileGuard::~TorrentFileGuard ( )

Definition at line 63 of file torrentfileguard.cpp.

64 {
65  if (!m_wasAdded && (m_mode != Always))
66  setAutoRemove(false);
67 }
AutoDeleteMode m_mode
void setAutoRemove(bool remove) noexcept
Cancels or re-enables deferred file deletion.

References Always, m_mode, m_wasAdded, and setAutoRemove().

Here is the call graph for this function:

◆ TorrentFileGuard() [2/2]

TorrentFileGuard::TorrentFileGuard ( const QString &  path,
const TorrentFileGuard::AutoDeleteMode  mode 
)
private

Definition at line 51 of file torrentfileguard.cpp.

52  : FileGuard {mode != Never ? path : QString()}
53  , m_mode {mode}
54  , m_wasAdded {false}
55 {
56 }
Utility class to defer file deletion.

Member Function Documentation

◆ autoDeleteMode()

TorrentFileGuard::AutoDeleteMode TorrentFileGuard::autoDeleteMode ( )
static

Definition at line 74 of file torrentfileguard.cpp.

75 {
76  return autoDeleteModeSetting().get(AutoDeleteMode::Never);
77 }
static SettingValue< AutoDeleteMode > & autoDeleteModeSetting()

References autoDeleteModeSetting().

Referenced by AddNewTorrentDialog::AddNewTorrentDialog(), OptionsDialog::loadOptions(), and AppController::preferencesAction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ autoDeleteModeSetting()

SettingValue< TorrentFileGuard::AutoDeleteMode > & TorrentFileGuard::autoDeleteModeSetting ( )
staticprivate

Definition at line 84 of file torrentfileguard.cpp.

85 {
86  static SettingValue<AutoDeleteMode> setting {"Core/AutoDeleteAddedTorrentFile"};
87  return setting;
88 }

Referenced by autoDeleteMode(), and setAutoDeleteMode().

Here is the caller graph for this function:

◆ markAsAddedToSession()

void TorrentFileGuard::markAsAddedToSession ( )

marks the torrent file as loaded (added) into the BitTorrent::Session

Definition at line 69 of file torrentfileguard.cpp.

70 {
71  m_wasAdded = true;
72 }

References m_wasAdded.

◆ setAutoDeleteMode()

void TorrentFileGuard::setAutoDeleteMode ( TorrentFileGuard::AutoDeleteMode  mode)
static

Definition at line 79 of file torrentfileguard.cpp.

80 {
81  autoDeleteModeSetting() = mode;
82 }

References autoDeleteModeSetting().

Referenced by OptionsDialog::saveOptions(), and AppController::setPreferencesAction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setAutoRemove()

void FileGuard::setAutoRemove
noexcept

Cancels or re-enables deferred file deletion.

Definition at line 44 of file torrentfileguard.cpp.

41 {
42  m_remove = remove;
43 }

Referenced by ~TorrentFileGuard().

Here is the caller graph for this function:

Member Data Documentation

◆ m_mode

AutoDeleteMode TorrentFileGuard::m_mode
private

Definition at line 81 of file torrentfileguard.h.

Referenced by ~TorrentFileGuard().

◆ m_wasAdded

bool TorrentFileGuard::m_wasAdded
private

Definition at line 82 of file torrentfileguard.h.

Referenced by markAsAddedToSession(), and ~TorrentFileGuard().


The documentation for this class was generated from the following files: