mirror of
https://github.com/transmission/transmission
synced 2025-01-01 12:35:22 +00:00
Merge branch 'trac5348-misidentification-of-local-session'
This commit is contained in:
commit
687662d1f1
6 changed files with 113 additions and 67 deletions
|
@ -29,8 +29,9 @@ OptionsDialog::OptionsDialog (Session& session, const Prefs& prefs, const AddDat
|
|||
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)
|
||||
|
@ -76,42 +77,27 @@ OptionsDialog::OptionsDialog (Session& session, const Prefs& prefs, const AddDat
|
|||
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));
|
||||
|
@ -124,6 +110,9 @@ OptionsDialog::OptionsDialog (Session& session, const Prefs& prefs, const AddDat
|
|||
|
||||
connect (&myVerifyTimer, SIGNAL (timeout ()), this, SLOT (onTimeout ()));
|
||||
|
||||
connect (&mySession, SIGNAL (sessionUpdated ()), SLOT (onSessionUpdated ()));
|
||||
|
||||
updateWidgetsLocality ();
|
||||
reload ();
|
||||
}
|
||||
|
||||
|
@ -184,8 +173,7 @@ OptionsDialog::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)
|
||||
|
@ -209,6 +197,30 @@ OptionsDialog::reload ()
|
|||
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)
|
||||
{
|
||||
|
|
|
@ -43,6 +43,7 @@ class OptionsDialog: public BaseDialog
|
|||
|
||||
private:
|
||||
void reload ();
|
||||
void updateWidgetsLocality ();
|
||||
void clearInfo ();
|
||||
void clearVerify ();
|
||||
|
||||
|
@ -56,12 +57,15 @@ class OptionsDialog: public BaseDialog
|
|||
void onSourceChanged ();
|
||||
void onDestinationChanged ();
|
||||
|
||||
void onSessionUpdated ();
|
||||
|
||||
private:
|
||||
Session& mySession;
|
||||
AddData myAdd;
|
||||
|
||||
Ui::OptionsDialog ui;
|
||||
|
||||
bool myIsLocal;
|
||||
QDir myLocalDestination;
|
||||
bool myHaveInfo;
|
||||
tr_info myInfo;
|
||||
|
|
|
@ -467,56 +467,38 @@ PrefsDialog::onQueueStalledMinutesChanged ()
|
|||
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->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.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);
|
||||
|
@ -526,9 +508,26 @@ PrefsDialog::initDownloadingTab ()
|
|||
|
||||
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 ());
|
||||
}
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
@ -537,7 +536,8 @@ PrefsDialog::PrefsDialog (Session& session, Prefs& prefs, QWidget * parent):
|
|||
BaseDialog (parent),
|
||||
mySession (session),
|
||||
myPrefs (prefs),
|
||||
myIsServer (session.isServer ())
|
||||
myIsServer (session.isServer ()),
|
||||
myIsLocal (mySession.isLocal ())
|
||||
{
|
||||
ui.setupUi (this);
|
||||
|
||||
|
@ -597,6 +597,13 @@ PrefsDialog::setPref (int key, const QVariant& v)
|
|||
void
|
||||
PrefsDialog::sessionUpdated ()
|
||||
{
|
||||
const bool isLocal = mySession.isLocal ();
|
||||
if (myIsLocal != isLocal)
|
||||
{
|
||||
myIsLocal = isLocal;
|
||||
updateDownloadingWidgetsLocality ();
|
||||
}
|
||||
|
||||
updateBlocklistLabel ();
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ class PrefsDialog: public BaseDialog
|
|||
bool updateWidgetValue (QWidget * widget, int prefKey);
|
||||
void linkWidgetToPref (QWidget * widget, int prefKey);
|
||||
void updateBlocklistLabel ();
|
||||
void updateDownloadingWidgetsLocality ();
|
||||
|
||||
void setPref (int key, const QVariant& v);
|
||||
|
||||
|
@ -75,8 +76,10 @@ class PrefsDialog: public BaseDialog
|
|||
|
||||
Ui::PrefsDialog ui;
|
||||
|
||||
key2widget_t myWidgets;
|
||||
const bool myIsServer;
|
||||
bool myIsLocal;
|
||||
|
||||
key2widget_t myWidgets;
|
||||
QWidgetList myWebWidgets;
|
||||
QWidgetList myWebAuthWidgets;
|
||||
QWidgetList myWebWhitelistWidgets;
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <QTextStream>
|
||||
|
||||
#include <libtransmission/transmission.h>
|
||||
#include <libtransmission/session-id.h>
|
||||
#include <libtransmission/utils.h> // tr_free
|
||||
#include <libtransmission/variant.h>
|
||||
|
||||
|
@ -254,7 +255,8 @@ Session::Session (const QString& configDir, Prefs& prefs):
|
|||
myConfigDir (configDir),
|
||||
myPrefs (prefs),
|
||||
myBlocklistSize (-1),
|
||||
mySession (0)
|
||||
mySession (0),
|
||||
myIsDefinitelyLocalSession (true)
|
||||
{
|
||||
myStats.ratio = TR_RATIO_NA;
|
||||
myStats.uploadedBytes = 0;
|
||||
|
@ -346,6 +348,8 @@ Session::isServer () const
|
|||
bool
|
||||
Session::isLocal () const
|
||||
{
|
||||
if (!mySessionId.isEmpty ())
|
||||
return myIsDefinitelyLocalSession;
|
||||
return myRpc.isLocal ();
|
||||
}
|
||||
|
||||
|
@ -794,6 +798,20 @@ Session::updateInfo (tr_variant * d)
|
|||
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)));
|
||||
|
||||
|
|
|
@ -128,6 +128,8 @@ class Session: public QObject
|
|||
tr_session_stats myStats;
|
||||
tr_session_stats myCumulativeStats;
|
||||
QString mySessionVersion;
|
||||
QString mySessionId;
|
||||
bool myIsDefinitelyLocalSession;
|
||||
RpcClient myRpc;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue