static const int INTERVAL_MSEC = 15000;
}
-FreespaceLabel::FreespaceLabel (Session & session,
- const QString & path,
- QWidget * parent):
+FreespaceLabel::FreespaceLabel (QWidget * parent):
QLabel (parent),
- mySession (session),
+ mySession (nullptr),
myTag (-1),
myTimer (this)
{
- myTimer.setSingleShot (false);
+ myTimer.setSingleShot (true);
myTimer.setInterval (INTERVAL_MSEC);
- myTimer.start ();
- connect (&myTimer, SIGNAL(timeout()), this, SLOT(onTimer()));
+ connect (&myTimer, SIGNAL (timeout ()), this, SLOT (onTimer ()));
+}
+
+void
+FreespaceLabel::setSession (Session& session)
+{
+ if (mySession == &session)
+ return;
+
+ if (mySession != nullptr)
+ disconnect (mySession, nullptr, this, nullptr);
- connect (&mySession, SIGNAL(executed(int64_t, QString, tr_variant *)),
- this, SLOT(onSessionExecuted(int64_t, QString, tr_variant *)));
+ mySession = &session;
- setPath (path);
+ connect (mySession, SIGNAL (executed (int64_t, QString, tr_variant *)),
+ this, SLOT (onSessionExecuted (int64_t, QString, tr_variant *)));
+
+ onTimer ();
}
void
void
FreespaceLabel::onTimer ()
{
- const int64_t tag = mySession.getUniqueTag ();
+ myTimer.stop ();
+
+ if (mySession == nullptr || myPath.isEmpty ())
+ return;
+
+ const int64_t tag = mySession->getUniqueTag ();
const QByteArray myPathUtf8 = myPath.toUtf8 ();
myTag = tag;
tr_variantDictAddInt (&top, TR_KEY_tag, tag);
tr_variant * args = tr_variantDictAddDict (&top, TR_KEY_arguments, 1);
tr_variantDictAddStr (args, TR_KEY_path, myPathUtf8.constData());
- mySession.exec (&top);
+ mySession->exec (&top);
tr_variantFree (&top);
}
tr_variantDictFindStr (arguments, TR_KEY_path, &path, &len);
str = QString::fromUtf8 (path, len);
setToolTip (str);
+
+ myTimer.start ();
}
l = new QLabel (tr ("&Destination folder:"));
layout->addWidget (l, ++row, 0, Qt::AlignLeft);
const QString downloadDir (prefs.getString (Prefs::DOWNLOAD_DIR));
- myFreespaceLabel = new FreespaceLabel (mySession, downloadDir, this);
+ myFreespaceLabel = new FreespaceLabel (this);
+ myFreespaceLabel->setSession (mySession);
+ myFreespaceLabel->setPath (downloadDir);
if (session.isLocal ())
{
hig->addRow (tr ("Save to &Location:"), b);
const QString downloadDir (myPrefs.getString(Prefs::DOWNLOAD_DIR));
- l = myFreespaceLabel = new FreespaceLabel (mySession, downloadDir, this);
+ l = myFreespaceLabel = new FreespaceLabel (this);
+ myFreespaceLabel->setSession (mySession);
+ myFreespaceLabel->setPath (downloadDir);
QHBoxLayout * h = new QHBoxLayout ();
h->addStretch (1);
h->addWidget (l);