(trunk, qt) #5487 'Qt client crash when using Open URL action' -- fixed.

This commit is contained in:
Jordan Lee 2013-09-14 22:50:25 +00:00
parent da317c441d
commit 6593a47493
2 changed files with 32 additions and 29 deletions

View File

@ -14,6 +14,7 @@
#include <iostream> #include <iostream>
#include <QtGui> #include <QtGui>
#include <QCheckBox>
#include <QProxyStyle> #include <QProxyStyle>
#include <QLabel> #include <QLabel>
#include <QFileDialog> #include <QFileDialog>
@ -106,7 +107,6 @@ TrMainWindow :: TrMainWindow (Session& session, Prefs& prefs, TorrentModel& mode
myAboutDialog (new AboutDialog (this)), myAboutDialog (new AboutDialog (this)),
myStatsDialog (new StatsDialog (session, this)), myStatsDialog (new StatsDialog (session, this)),
myDetailsDialog (0), myDetailsDialog (0),
myFileDialogOptionsCheck (0),
myFilterModel (prefs), myFilterModel (prefs),
myTorrentDelegate (new TorrentDelegate (this)), myTorrentDelegate (new TorrentDelegate (this)),
myTorrentDelegateMin (new TorrentDelegateMin (this)), myTorrentDelegateMin (new TorrentDelegateMin (this)),
@ -1154,6 +1154,8 @@ TrMainWindow :: refreshPref (int key)
**** ****
***/ ***/
#define SHOW_OPTIONS_CHECKBOX_NAME "show-options-checkbox"
void void
TrMainWindow :: newTorrent () TrMainWindow :: newTorrent ()
{ {
@ -1164,24 +1166,24 @@ TrMainWindow :: newTorrent ()
void void
TrMainWindow :: openTorrent () TrMainWindow :: openTorrent ()
{ {
QFileDialog * myFileDialog; QFileDialog * d;
myFileDialog = new QFileDialog (this, d = new QFileDialog (this,
tr ("Open Torrent"), tr ("Open Torrent"),
myPrefs.getString (Prefs::OPEN_DIALOG_FOLDER), myPrefs.getString (Prefs::OPEN_DIALOG_FOLDER),
tr ("Torrent Files (*.torrent);;All Files (*.*)")); tr ("Torrent Files (*.torrent);;All Files (*.*)"));
myFileDialog->setFileMode (QFileDialog::ExistingFiles); d->setFileMode (QFileDialog::ExistingFiles);
myFileDialog->setAttribute (Qt::WA_DeleteOnClose); d->setAttribute (Qt::WA_DeleteOnClose);
QCheckBox * button = new QCheckBox (tr ("Show &options dialog")); QCheckBox * b = new QCheckBox (tr ("Show &options dialog"));
button->setChecked (myPrefs.getBool (Prefs::OPTIONS_PROMPT)); b->setChecked (myPrefs.getBool (Prefs::OPTIONS_PROMPT));
QGridLayout * layout = dynamic_cast<QGridLayout*> (myFileDialog->layout ()); b->setObjectName (SHOW_OPTIONS_CHECKBOX_NAME);
layout->addWidget (button, layout->rowCount (), 0, 1, -1, Qt::AlignLeft); QGridLayout * l = dynamic_cast<QGridLayout*> (d->layout ());
myFileDialogOptionsCheck = button; l->addWidget (b, l->rowCount (), 0, 1, -1, Qt::AlignLeft);
connect (myFileDialog, SIGNAL (filesSelected (const QStringList&)), connect (d, SIGNAL (filesSelected (const QStringList&)),
this, SLOT (addTorrents (const QStringList&))); this, SLOT (addTorrents (const QStringList&)));
myFileDialog->show (); d->show ();
} }
void void
@ -1195,27 +1197,30 @@ TrMainWindow :: openURL ()
if (!AddData::isSupported (str)) if (!AddData::isSupported (str))
str.clear (); str.clear ();
addTorrent (str); addTorrent (str, true);
} }
void void
TrMainWindow :: addTorrents (const QStringList& filenames) TrMainWindow :: addTorrents (const QStringList& filenames)
{ {
bool showOptions = myPrefs.getBool (Prefs::OPTIONS_PROMPT);
const QFileDialog * const fileDialog = qobject_cast<const QFileDialog*> (sender ());
if (fileDialog != NULL)
{
const QCheckBox * const b = fileDialog->findChild<const QCheckBox*> (SHOW_OPTIONS_CHECKBOX_NAME);
if (b != NULL)
showOptions = b->isChecked ();
}
foreach (const QString& filename, filenames) foreach (const QString& filename, filenames)
addTorrent (filename); addTorrent (filename, showOptions);
} }
void void
TrMainWindow :: addTorrent (const AddData& addMe) TrMainWindow :: addTorrent (const AddData& addMe, bool showOptions)
{ {
bool show_options_dialog; if (showOptions)
if (myFileDialogOptionsCheck)
show_options_dialog = myFileDialogOptionsCheck->isChecked ();
else
show_options_dialog = myPrefs.getBool (Prefs::OPTIONS_PROMPT);
if (show_options_dialog)
{ {
Options * o = new Options (mySession, myPrefs, addMe, this); Options * o = new Options (mySession, myPrefs, addMe, this);
o->show (); o->show ();

View File

@ -14,7 +14,6 @@
#define MAIN_WINDOW_H #define MAIN_WINDOW_H
#include <ctime> #include <ctime>
#include <QCheckBox>
#include <QLineEdit> #include <QLineEdit>
#include <QIcon> #include <QIcon>
#include <QMainWindow> #include <QMainWindow>
@ -64,7 +63,6 @@ class TrMainWindow: public QMainWindow
QDialog * myAboutDialog; QDialog * myAboutDialog;
QDialog * myStatsDialog; QDialog * myStatsDialog;
Details * myDetailsDialog; Details * myDetailsDialog;
QCheckBox * myFileDialogOptionsCheck;
QSystemTrayIcon myTrayIcon; QSystemTrayIcon myTrayIcon;
TorrentFilter myFilterModel; TorrentFilter myFilterModel;
TorrentDelegate * myTorrentDelegate; TorrentDelegate * myTorrentDelegate;
@ -172,11 +170,11 @@ class TrMainWindow: public QMainWindow
void queueMoveDown (); void queueMoveDown ();
void queueMoveBottom (); void queueMoveBottom ();
void reannounceSelected (); void reannounceSelected ();
void addTorrent (const AddData& addMe);
void onNetworkTimer (); void onNetworkTimer ();
private: private:
void clearSelection (); void clearSelection ();
void addTorrent (const AddData& addMe, bool showOptions);
public slots: public slots:
void setToolbarVisible (bool); void setToolbarVisible (bool);