feat: add editDate to RPC (#1056)

* feat: add tr_stat.infoDate to note tr_info changes

The last time during this session that any tr_info field changed
(e.g. trackers/filenames edited or magnet torrent got metadata).
RPC clients can monitor this to know when to reload fields which
don't usually change.
This commit is contained in:
Charles Kerr 2019-11-12 17:13:42 -06:00 committed by GitHub
parent c62cb35fd4
commit 44fc571a67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 62 additions and 10 deletions

View File

@ -190,6 +190,7 @@
downloadedEver | number | tr_stat
downloadLimit | number | tr_torrent
downloadLimited | boolean | tr_torrent
editDate | number | tr_stat
error | number | tr_stat
errorString | string | tr_stat
eta | number | tr_stat
@ -806,6 +807,7 @@
| | yes | session-get | new arg "session-id"
| | yes | torrent-get | new arg "labels"
| | yes | torrent-set | new arg "labels"
| | yes | torrent-set | new arg "editDate"
| | yes | torrent-get | new arg "format"

View File

@ -105,6 +105,7 @@ static struct tr_key_struct const my_static[] =
Q("dropped"),
Q("dropped6"),
Q("e"),
Q("editDate"),
Q("encoding"),
Q("encryption"),
Q("error"),

View File

@ -105,6 +105,7 @@ enum
TR_KEY_dropped,
TR_KEY_dropped6,
TR_KEY_e,
TR_KEY_editDate,
TR_KEY_encoding,
TR_KEY_encryption,
TR_KEY_error,

View File

@ -641,6 +641,10 @@ static void initField(tr_torrent* const tor, tr_info const* const inf, tr_stat c
tr_variantInitInt(initme, st->id);
break;
case TR_KEY_editDate:
tr_variantInitInt(initme, st->editDate);
break;
case TR_KEY_isFinished:
tr_variantInitBool(initme, st->finished);
break;

View File

@ -340,6 +340,7 @@ void tr_torrentSetMetadataPiece(tr_torrent* tor, int piece, void const* data, in
tor->isStopping = true;
tor->magnetVerify = true;
tor->startAfterVerify = true;
tr_torrentMarkEdited(tor);
}
else /* drat. */
{

View File

@ -1191,6 +1191,8 @@ void tr_torrentSetDownloadDir(tr_torrent* tor, char const* path)
{
tr_free(tor->downloadDir);
tor->downloadDir = tr_strdup(path);
tr_torrentMarkEdited(tor);
tr_torrentSetDirty(tor);
}
@ -1406,6 +1408,7 @@ tr_stat const* tr_torrentStat(tr_torrent* tor)
s->activityDate = tor->activityDate;
s->addedDate = tor->addedDate;
s->doneDate = tor->doneDate;
s->editDate = tor->editDate;
s->startDate = tor->startDate;
s->secondsSeeding = tor->secondsSeeding;
s->secondsDownloading = tor->secondsDownloading;
@ -2862,6 +2865,7 @@ bool tr_torrentSetAnnounceList(tr_torrent* tor, tr_tracker_info const* trackers_
tor->info.trackerCount = tmpInfo.trackerCount;
tmpInfo.trackers = swap.trackers;
tmpInfo.trackerCount = swap.trackerCount;
tr_torrentMarkEdited(tor);
tr_metainfoFree(&tmpInfo);
tr_variantToFile(&metainfo, TR_VARIANT_FMT_BENC, tor->info.torrent);
@ -4005,6 +4009,7 @@ static void torrentRenamePath(void* vdata)
tor->info.name = tr_strdup(newname);
}
tr_torrentMarkEdited(tor);
tr_torrentSetDirty(tor);
}
}

View File

@ -191,11 +191,12 @@ struct tr_torrent
uint64_t etaULSpeedCalculatedAt;
unsigned int etaULSpeed_Bps;
time_t addedDate;
time_t activityDate;
time_t doneDate;
time_t startDate;
time_t addedDate;
time_t anyDate;
time_t doneDate;
time_t editDate;
time_t startDate;
int secondsDownloading;
int secondsSeeding;
@ -349,6 +350,14 @@ static inline void tr_torrentSetDirty(tr_torrent* tor)
tor->isDirty = true;
}
/* note that the torrent's tr_info just changed */
static inline void tr_torrentMarkEdited(tr_torrent* tor)
{
TR_ASSERT(tr_isTorrent(tor));
tor->editDate = tr_time();
}
uint32_t tr_getBlockSize(uint32_t pieceSize);
/**

View File

@ -1828,6 +1828,12 @@ typedef struct tr_stat
/** The last time we uploaded or downloaded piece data on this torrent. */
time_t activityDate;
/** The last time during this session that a rarely-changing field
changed -- e.g. any tr_info field (trackers, filenames, name)
or download directory. RPC clients can monitor this to know when
to reload fields that rarely change. */
time_t editDate;
/** Number of seconds since the last activity (or since started).
-1 if activity is not seeding or downloading. */
int idleSecs;

View File

@ -399,6 +399,12 @@ void Application::quitLater()
QTimer::singleShot(0, this, SLOT(quit()));
}
void Application::onTorrentsEdited(torrent_ids_t const& ids)
{
// the backend's tr_info has changed, so reload those fields
mySession->initTorrents(ids);
}
QStringList Application::getNames(torrent_ids_t const& ids) const
{
QStringList names;

View File

@ -18,6 +18,7 @@
class AddData;
class Prefs;
class Session;
class Torrent;
class TorrentModel;
class MainWindow;
class WatchDir;
@ -41,11 +42,12 @@ public slots:
private slots:
void consentGiven(int result);
void onSessionSourceChanged();
void refreshPref(int key);
void refreshTorrents();
void onTorrentsAdded(torrent_ids_t const& torrents);
void onTorrentsCompleted(torrent_ids_t const& torrents);
void onTorrentsEdited(torrent_ids_t const& torrents);
void onTorrentsNeedInfo(torrent_ids_t const& torrents);
void refreshPref(int key);
void refreshTorrents();
private:
void maybeUpdateBlocklist();

View File

@ -310,6 +310,12 @@ void DetailsDialog::getNewData()
}
}
void DetailsDialog::onTorrentEdited(torrent_ids_t const& /*ids*/)
{
// FIXME
// refreshDetailInfo({ tor.id() });
}
void DetailsDialog::onTorrentsChanged(torrent_ids_t const& ids)
{
if (myHavePendingRefresh)

View File

@ -59,10 +59,11 @@ private:
private slots:
void refresh();
void refreshPref(int key);
void onTorrentsChanged(torrent_ids_t const& ids);
void onTimer();
void onTorrentEdited(torrent_ids_t const& ids);
void onTorrentsChanged(torrent_ids_t const& ids);
// Tracker tab
void onTrackerSelectionChanged();
void onAddTrackerClicked();

View File

@ -646,10 +646,16 @@ bool Torrent::update(tr_quark const* keys, tr_variant** values, size_t n)
case QVariant::DateTime:
{
int64_t val;
if (tr_variantGetInt(child, &val) && val)
if (tr_variantGetInt(child, &val) && val &&
setTime(property_index, time_t(val)))
{
changed |= setTime(property_index, time_t(val));
changed = true;
if (key == TR_KEY_editDate)
{
// FIXME
// emit torrentEdited(*this);
}
}
break;

View File

@ -180,6 +180,7 @@ public:
PEERS,
BANDWIDTH_PRIORITY,
QUEUE_POSITION,
EDIT_DATE,
//
PROPERTY_COUNT
};

View File

@ -59,6 +59,7 @@ signals:
void torrentsAdded(torrent_ids_t const&);
void torrentsChanged(torrent_ids_t const&);
void torrentsCompleted(torrent_ids_t const&);
void torrentsEdited(torrent_ids_t const&);
void torrentsNeedInfo(torrent_ids_t const&);
private: