Skip to content

Commit

Permalink
Merge branch 'trac5348-misidentification-of-local-session'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedld committed Oct 3, 2016
2 parents 1ce80c1 + 981ef30 commit 687662d
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 67 deletions.
72 changes: 42 additions & 30 deletions qt/OptionsDialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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));
Expand All @@ -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 ();
}

Expand Down Expand Up @@ -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)
Expand All @@ -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)
{
Expand Down
4 changes: 4 additions & 0 deletions qt/OptionsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class OptionsDialog: public BaseDialog

private:
void reload ();
void updateWidgetsLocality ();
void clearInfo ();
void clearVerify ();

Expand All @@ -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;
Expand Down
77 changes: 42 additions & 35 deletions qt/PrefsDialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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->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);
Expand All @@ -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 ());
}

/***
****
***/
Expand All @@ -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);

Expand Down Expand Up @@ -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 ();
}

Expand Down
5 changes: 4 additions & 1 deletion qt/PrefsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
20 changes: 19 additions & 1 deletion qt/Session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -346,6 +348,8 @@ Session::isServer () const
bool
Session::isLocal () const
{
if (!mySessionId.isEmpty ())
return myIsDefinitelyLocalSession;
return myRpc.isLocal ();
}

Expand Down Expand Up @@ -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)));

Expand Down
2 changes: 2 additions & 0 deletions qt/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class Session: public QObject
tr_session_stats myStats;
tr_session_stats myCumulativeStats;
QString mySessionVersion;
QString mySessionId;
bool myIsDefinitelyLocalSession;
RpcClient myRpc;
};

0 comments on commit 687662d

Please sign in to comment.