BaseDialog (parent),
mySession (session),
myAdd (addme),
+ myIsLocal (mySession.isLocal ()),
myHaveInfo (false),
- myVerifyButton (nullptr),
+ myVerifyButton (new QPushButton (tr ("&Verify Local Data"), this)),
myVerifyFile (nullptr),
myVerifyHash (QCryptographicHash::Sha1),
myEditTimer (this)
ui.freeSpaceLabel->setSession (mySession);
ui.freeSpaceLabel->setPath (downloadDir);
- if (session.isLocal ())
- {
- ui.destinationStack->setCurrentWidget (ui.destinationButton);
- ui.destinationButton->setMode (PathButton::DirectoryMode);
- ui.destinationButton->setTitle (tr ("Select Destination"));
- ui.destinationButton->setPath (downloadDir);
- myLocalDestination = downloadDir;
- connect (ui.destinationButton, SIGNAL (pathChanged (QString)), this, SLOT (onDestinationChanged ()));
- }
- else
- {
- ui.destinationStack->setCurrentWidget (ui.destinationEdit);
- ui.destinationEdit->setText (downloadDir);
- ui.freeSpaceLabel->setPath (downloadDir);
- connect (ui.destinationEdit, SIGNAL (textEdited (QString)), &myEditTimer, SLOT (start ()));
- connect (ui.destinationEdit, SIGNAL (editingFinished ()), this, SLOT (onDestinationChanged ()));
- }
+ ui.destinationButton->setMode (PathButton::DirectoryMode);
+ ui.destinationButton->setTitle (tr ("Select Destination"));
+ ui.destinationButton->setPath (downloadDir);
+ ui.destinationEdit->setText (downloadDir);
- ui.destinationStack->setFixedHeight (ui.destinationStack->currentWidget ()->sizeHint ().height ());
- ui.destinationLabel->setBuddy (ui.destinationStack->currentWidget ());
+ if (myIsLocal)
+ myLocalDestination = downloadDir;
+
+ connect (ui.destinationButton, SIGNAL (pathChanged (QString)), this, SLOT (onDestinationChanged ()));
+ connect (ui.destinationEdit, SIGNAL (textEdited (QString)), &myEditTimer, SLOT (start ()));
+ connect (ui.destinationEdit, SIGNAL (editingFinished ()), this, SLOT (onDestinationChanged ()));
ui.filesView->setEditable (false);
- if (!session.isLocal ())
- ui.filesView->hideColumn (2); // hide the % done, since we've no way of knowing
ui.priorityCombo->addItem (tr ("High"), TR_PRI_HIGH);
ui.priorityCombo->addItem (tr ("Normal"), TR_PRI_NORMAL);
ui.priorityCombo->addItem (tr ("Low"), TR_PRI_LOW);
ui.priorityCombo->setCurrentIndex (1); // Normal
- if (session.isLocal ())
- {
- myVerifyButton = new QPushButton (tr ("&Verify Local Data"), this);
- ui.dialogButtons->addButton (myVerifyButton, QDialogButtonBox::ActionRole);
- connect (myVerifyButton, SIGNAL (clicked (bool)), this, SLOT (onVerify ()));
- }
+ ui.dialogButtons->addButton (myVerifyButton, QDialogButtonBox::ActionRole);
+ connect (myVerifyButton, SIGNAL (clicked (bool)), this, SLOT (onVerify ()));
ui.startCheck->setChecked (prefs.getBool (Prefs::START));
ui.trashCheck->setChecked (prefs.getBool (Prefs::TRASH_ORIGINAL));
connect (&myVerifyTimer, SIGNAL (timeout ()), this, SLOT (onTimeout ()));
+ connect (&mySession, SIGNAL (sessionUpdated ()), SLOT (onSessionUpdated ()));
+
+ updateWidgetsLocality ();
reload ();
}
const bool haveFilesToShow = myHaveInfo && myInfo.fileCount > 0;
ui.filesView->setVisible (haveFilesToShow);
- if (myVerifyButton != nullptr)
- myVerifyButton->setVisible (haveFilesToShow);
+ myVerifyButton->setEnabled (haveFilesToShow);
layout ()->setSizeConstraint (haveFilesToShow ? QLayout::SetDefaultConstraint : QLayout::SetFixedSize);
if (myHaveInfo)
ui.filesView->update (myFiles);
}
+void
+OptionsDialog::updateWidgetsLocality ()
+{
+ ui.destinationStack->setCurrentWidget (myIsLocal ? static_cast<QWidget*> (ui.destinationButton) : ui.destinationEdit);
+ ui.destinationStack->setFixedHeight (ui.destinationStack->currentWidget ()->sizeHint ().height ());
+ ui.destinationLabel->setBuddy (ui.destinationStack->currentWidget ());
+
+ // hide the % done when non-local, since we've no way of knowing
+ (ui.filesView->*(myIsLocal ? &QTreeView::showColumn : &QTreeView::hideColumn)) (2);
+
+ myVerifyButton->setVisible (myIsLocal);
+}
+
+void
+OptionsDialog::onSessionUpdated ()
+{
+ const bool isLocal = mySession.isLocal ();
+ if (myIsLocal != isLocal)
+ {
+ myIsLocal = isLocal;
+ updateWidgetsLocality ();
+ }
+}
+
void
OptionsDialog::onPriorityChanged (const QSet<int>& fileIndices, int priority)
{
private:
void reload ();
+ void updateWidgetsLocality ();
void clearInfo ();
void clearVerify ();
void onSourceChanged ();
void onDestinationChanged ();
+ void onSessionUpdated ();
+
private:
Session& mySession;
AddData myAdd;
Ui::OptionsDialog ui;
+ bool myIsLocal;
QDir myLocalDestination;
bool myHaveInfo;
tr_info myInfo;
void
PrefsDialog::initDownloadingTab ()
{
- if (mySession.isLocal ())
- {
- ui.watchDirStack->setCurrentWidget (ui.watchDirButton);
- ui.downloadDirStack->setCurrentWidget (ui.downloadDirButton);
- ui.incompleteDirStack->setCurrentWidget (ui.incompleteDirButton);
- ui.completionScriptStack->setCurrentWidget (ui.completionScriptButton);
-
- ui.watchDirButton->setMode (PathButton::DirectoryMode);
- ui.downloadDirButton->setMode (PathButton::DirectoryMode);
- ui.incompleteDirButton->setMode (PathButton::DirectoryMode);
- ui.completionScriptButton->setMode (PathButton::FileMode);
-
- ui.watchDirButton->setTitle (tr ("Select Watch Directory"));
- ui.downloadDirButton->setTitle (tr ("Select Destination"));
- ui.incompleteDirButton->setTitle (tr ("Select Incomplete Directory"));
- ui.completionScriptButton->setTitle (tr ("Select \"Torrent Done\" Script"));
- }
- else
- {
- ui.watchDirStack->setCurrentWidget (ui.watchDirEdit);
- ui.downloadDirStack->setCurrentWidget (ui.downloadDirEdit);
- ui.incompleteDirStack->setCurrentWidget (ui.incompleteDirEdit);
- ui.completionScriptStack->setCurrentWidget (ui.completionScriptEdit);
- }
+ ui.watchDirButton->setMode (PathButton::DirectoryMode);
+ ui.downloadDirButton->setMode (PathButton::DirectoryMode);
+ ui.incompleteDirButton->setMode (PathButton::DirectoryMode);
+ ui.completionScriptButton->setMode (PathButton::FileMode);
- ui.watchDirStack->setFixedHeight (ui.watchDirStack->currentWidget ()->sizeHint ().height ());
- ui.downloadDirStack->setFixedHeight (ui.downloadDirStack->currentWidget ()->sizeHint ().height ());
- ui.incompleteDirStack->setFixedHeight (ui.incompleteDirStack->currentWidget ()->sizeHint ().height ());
- ui.completionScriptStack->setFixedHeight (ui.completionScriptStack->currentWidget ()->sizeHint ().height ());
+ ui.watchDirButton->setTitle (tr ("Select Watch Directory"));
+ ui.downloadDirButton->setTitle (tr ("Select Destination"));
+ ui.incompleteDirButton->setTitle (tr ("Select Incomplete Directory"));
+ ui.completionScriptButton->setTitle (tr ("Select \"Torrent Done\" Script"));
ui.watchDirStack->setMinimumWidth (200);
- ui.downloadDirLabel->setBuddy (ui.downloadDirStack->currentWidget ());
-
ui.downloadDirFreeSpaceLabel->setSession (mySession);
ui.downloadDirFreeSpaceLabel->setPath (myPrefs.getString (Prefs::DOWNLOAD_DIR));
linkWidgetToPref (ui.watchDirCheck, Prefs::DIR_WATCH_ENABLED);
- linkWidgetToPref (ui.watchDirStack->currentWidget (), Prefs::DIR_WATCH);
+ linkWidgetToPref (ui.watchDirButton, Prefs::DIR_WATCH);
+ linkWidgetToPref (ui.watchDirEdit, Prefs::DIR_WATCH);
linkWidgetToPref (ui.showTorrentOptionsDialogCheck, Prefs::OPTIONS_PROMPT);
linkWidgetToPref (ui.startAddedTorrentsCheck, Prefs::START);
linkWidgetToPref (ui.trashTorrentFileCheck, Prefs::TRASH_ORIGINAL);
- linkWidgetToPref (ui.downloadDirStack->currentWidget (), Prefs::DOWNLOAD_DIR);
+ linkWidgetToPref (ui.downloadDirButton, Prefs::DOWNLOAD_DIR);
+ linkWidgetToPref (ui.downloadDirEdit, Prefs::DOWNLOAD_DIR);
linkWidgetToPref (ui.downloadQueueSizeSpin, Prefs::DOWNLOAD_QUEUE_SIZE);
linkWidgetToPref (ui.queueStalledMinutesSpin, Prefs::QUEUE_STALLED_MINUTES);
linkWidgetToPref (ui.renamePartialFilesCheck, Prefs::RENAME_PARTIAL_FILES);
linkWidgetToPref (ui.incompleteDirCheck, Prefs::INCOMPLETE_DIR_ENABLED);
- linkWidgetToPref (ui.incompleteDirStack->currentWidget (), Prefs::INCOMPLETE_DIR);
+ linkWidgetToPref (ui.incompleteDirButton, Prefs::INCOMPLETE_DIR);
+ linkWidgetToPref (ui.incompleteDirEdit, Prefs::INCOMPLETE_DIR);
linkWidgetToPref (ui.completionScriptCheck, Prefs::SCRIPT_TORRENT_DONE_ENABLED);
- linkWidgetToPref (ui.completionScriptStack->currentWidget (), Prefs::SCRIPT_TORRENT_DONE_FILENAME);
+ linkWidgetToPref (ui.completionScriptButton, Prefs::SCRIPT_TORRENT_DONE_FILENAME);
+ linkWidgetToPref (ui.completionScriptEdit, Prefs::SCRIPT_TORRENT_DONE_FILENAME);
ColumnResizer * cr (new ColumnResizer (this));
cr->addLayout (ui.addingSectionLayout);
connect (ui.queueStalledMinutesSpin, SIGNAL (valueChanged (int)), SLOT (onQueueStalledMinutesChanged ()));
+ updateDownloadingWidgetsLocality ();
onQueueStalledMinutesChanged ();
}
+void
+PrefsDialog::updateDownloadingWidgetsLocality ()
+{
+ ui.watchDirStack->setCurrentWidget (myIsLocal ? static_cast<QWidget*> (ui.watchDirButton) : ui.watchDirEdit);
+ ui.downloadDirStack->setCurrentWidget (myIsLocal ? static_cast<QWidget*> (ui.downloadDirButton) : ui.downloadDirEdit);
+ ui.incompleteDirStack->setCurrentWidget (myIsLocal ? static_cast<QWidget*> (ui.incompleteDirButton) : ui.incompleteDirEdit);
+ ui.completionScriptStack->setCurrentWidget (myIsLocal ? static_cast<QWidget*> (ui.completionScriptButton) : ui.completionScriptEdit);
+
+ ui.watchDirStack->setFixedHeight (ui.watchDirStack->currentWidget ()->sizeHint ().height ());
+ ui.downloadDirStack->setFixedHeight (ui.downloadDirStack->currentWidget ()->sizeHint ().height ());
+ ui.incompleteDirStack->setFixedHeight (ui.incompleteDirStack->currentWidget ()->sizeHint ().height ());
+ ui.completionScriptStack->setFixedHeight (ui.completionScriptStack->currentWidget ()->sizeHint ().height ());
+
+ ui.downloadDirLabel->setBuddy (ui.downloadDirStack->currentWidget ());
+}
+
/***
****
***/
BaseDialog (parent),
mySession (session),
myPrefs (prefs),
- myIsServer (session.isServer ())
+ myIsServer (session.isServer ()),
+ myIsLocal (mySession.isLocal ())
{
ui.setupUi (this);
void
PrefsDialog::sessionUpdated ()
{
+ const bool isLocal = mySession.isLocal ();
+ if (myIsLocal != isLocal)
+ {
+ myIsLocal = isLocal;
+ updateDownloadingWidgetsLocality ();
+ }
+
updateBlocklistLabel ();
}
bool updateWidgetValue (QWidget * widget, int prefKey);
void linkWidgetToPref (QWidget * widget, int prefKey);
void updateBlocklistLabel ();
+ void updateDownloadingWidgetsLocality ();
void setPref (int key, const QVariant& v);
Ui::PrefsDialog ui;
- key2widget_t myWidgets;
const bool myIsServer;
+ bool myIsLocal;
+
+ key2widget_t myWidgets;
QWidgetList myWebWidgets;
QWidgetList myWebAuthWidgets;
QWidgetList myWebWhitelistWidgets;
#include <QTextStream>
#include <libtransmission/transmission.h>
+#include <libtransmission/session-id.h>
#include <libtransmission/utils.h> // tr_free
#include <libtransmission/variant.h>
myConfigDir (configDir),
myPrefs (prefs),
myBlocklistSize (-1),
- mySession (0)
+ mySession (0),
+ myIsDefinitelyLocalSession (true)
{
myStats.ratio = TR_RATIO_NA;
myStats.uploadedBytes = 0;
bool
Session::isLocal () const
{
+ if (!mySessionId.isEmpty ())
+ return myIsDefinitelyLocalSession;
return myRpc.isLocal ();
}
if (tr_variantDictFindStr (d, TR_KEY_version, &str, NULL) && (mySessionVersion != QString::fromUtf8 (str)))
mySessionVersion = QString::fromUtf8 (str);
+ if (tr_variantDictFindStr (d, TR_KEY_session_id, &str, NULL))
+ {
+ const QString sessionId = QString::fromUtf8 (str);
+ if (mySessionId != sessionId)
+ {
+ mySessionId = sessionId;
+ myIsDefinitelyLocalSession = rand() % 2; // tr_session_id_is_local (str);
+ }
+ }
+ else
+ {
+ mySessionId.clear ();
+ }
+
//std::cerr << "Session::updateInfo end" << std::endl;
connect (&myPrefs, SIGNAL (changed (int)), this, SLOT (updatePref (int)));
tr_session_stats myStats;
tr_session_stats myCumulativeStats;
QString mySessionVersion;
+ QString mySessionId;
+ bool myIsDefinitelyLocalSession;
RpcClient myRpc;
};