]> granicus.if.org Git - transmission/commitdiff
(qt) merge together the two 'add url/magnet link' dialogs.
authorJordan Lee <jordan@transmissionbt.com>
Sat, 9 Feb 2013 23:11:17 +0000 (23:11 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Sat, 9 Feb 2013 23:11:17 +0000 (23:11 +0000)
qt/app.cc
qt/mainwin.cc
qt/mainwin.h
qt/options.cc
qt/options.h

index abd92a2e803d173abd1f2afbc90513e6eb481227..f6381febb6c1ee2b3dedde7c8d76f9f1dd073c9d 100644 (file)
--- a/qt/app.cc
+++ b/qt/app.cc
@@ -442,14 +442,6 @@ MyApp :: addTorrent (const AddData& addme)
     {
       mySession->addTorrent (addme);
     }
-  else if (addme.type == addme.URL)
-    {
-      myWindow->openURL (addme.url.toString ());
-    }
-  else if (addme.type == addme.MAGNET)
-    {
-      myWindow->openURL (addme.magnet);
-    }
   else
     {
       Options * o = new Options (*mySession, *myPrefs, addme, myWindow);
index 660819497e5614d12bed4eb4c019be254ad1a0c1..5eddbd781cf17212a8145f8d4a0789c0bef3cfb9 100644 (file)
@@ -1189,22 +1189,7 @@ TrMainWindow :: openURL ()
   if (!AddData::isSupported (str))
     str.clear ();
 
-  openURL (str);
-}
-
-void
-TrMainWindow :: openURL (QString url)
-{
-  bool ok;
-  const QString key = QInputDialog::getText (this,
-                                             tr ("Open Link"),
-                                             tr ("Open URL or Magnet Link"),
-                                             QLineEdit::Normal,
-                                             url,
-                                             &ok,
-                                             Qt::WindowStaysOnTopHint);
-  if (ok && !key.isEmpty ())
-    mySession.addTorrent (key);
+  addTorrent (str);
 }
 
 void
@@ -1215,19 +1200,26 @@ TrMainWindow :: addTorrents (const QStringList& filenames)
 }
 
 void
-TrMainWindow :: addTorrent (const QString& filename)
+TrMainWindow :: addTorrent (const AddData& addMe)
 {
-  if (!myFileDialogOptionsCheck->isChecked ())
-    {
-      mySession.addTorrent (filename);
-      QApplication :: alert (this);
-    }
+  bool show_options_dialog;
+
+  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, filename, this);
+      Options * o = new Options (mySession, myPrefs, addMe, this);
       o->show ();
       QApplication :: alert (o);
     }
+  else
+    {
+      mySession.addTorrent (addMe);
+      QApplication :: alert (this);
+    }
 }
 
 void
index 1b1b0988c6234061ae750dcc1c8c5c6faf9912c5..1c09d54441e349fd59f8ee6b88cf96afb6d807f2 100644 (file)
@@ -33,6 +33,7 @@ extern "C" {
 #include "torrent-filter.h"
 #include "ui_mainwin.h"
 
+class AddData;
 class ActionDelegator;
 class Prefs;
 class Details;
@@ -93,9 +94,6 @@ class TrMainWindow: public QMainWindow
     void updateNetworkIcon ();
     QWidgetList myHidden;
 
-  public slots:
-    void openURL (QString);
-
   private slots:
     void onPrefsDestroyed ();
     void openPreferences ();
@@ -173,7 +171,7 @@ class TrMainWindow: public QMainWindow
     void queueMoveDown ();
     void queueMoveBottom ();
     void reannounceSelected ();
-    void addTorrent (const QString& filename);
+    void addTorrent (const AddData& addMe);
     void onNetworkTimer ();
 
   private:
index 65f52946dcaa37074498ddd4aec4ac3cc920dc02..17385a15d624a4b28d818080a545c78eb651e1e4 100644 (file)
@@ -86,17 +86,26 @@ Options :: Options (Session& session, const Prefs& prefs, const AddData& addme,
   mySession (session),
   myAdd (addme),
   myHaveInfo (false),
+  mySourceButton (0),
+  mySourceEdit (0),
   myDestinationButton (0),
+  myDestinationEdit (0),
   myVerifyButton (0),
   myVerifyFile (0),
   myVerifyHash (QCryptographicHash::Sha1),
   myEditTimer (this)
 {
-  setWindowTitle (tr ("Open Torrent"));
   QFontMetrics fontMetrics (font ());
   QGridLayout * layout = new QGridLayout (this);
   int row = 0;
 
+  QString title;
+  if (myAdd.type == AddData::FILENAME)
+    title = tr ("Open Torrent from File");
+  else
+    title = tr ("Open Torrent from URL or Magnet Link");
+  setWindowTitle (title);
+
   myEditTimer.setInterval (2000);
   myEditTimer.setSingleShot (true);
   connect (&myEditTimer, SIGNAL (timeout ()), this, SLOT (onDestinationEditedIdle ()));
@@ -105,23 +114,35 @@ Options :: Options (Session& session, const Prefs& prefs, const AddData& addme,
   QIcon fileIcon = style ()->standardIcon (QStyle::SP_FileIcon);
   const QPixmap filePixmap = fileIcon.pixmap (iconSize);
 
-  QPushButton * p;
-  int width = fontMetrics.size (0, QString::fromAscii ("This is a pretty long torrent filename indeed.torrent")).width ();
-  QLabel * l = new QLabel (tr ("&Torrent file:"));
+  QLabel * l = new QLabel (tr ("&Source:"));
   layout->addWidget (l, row, 0, Qt::AlignLeft);
-  p = myFileButton =  new QPushButton;
-  p->setIcon (filePixmap);
-  p->setMinimumWidth (width);
-  p->setStyleSheet (QString::fromAscii ("text-align: left; padding-left: 5; padding-right: 5"));
-  p->installEventFilter (this);
 
-  layout->addWidget (p, row, 1);
-  l->setBuddy (p);
-  connect (p, SIGNAL (clicked (bool)), this, SLOT (onFilenameClicked ()));
+  QWidget * w;
+  QPushButton * p;
+
+  if (myAdd.type == AddData::FILENAME)
+    {
+      p = mySourceButton =  new QPushButton;
+      p->setIcon (filePixmap);
+      p->setStyleSheet (QString::fromAscii ("text-align: left; padding-left: 5; padding-right: 5"));
+      p->installEventFilter (this);
+      w = p;
+      connect (p, SIGNAL (clicked (bool)), this, SLOT (onFilenameClicked ()));
+    }
+  else
+    {
+      QLineEdit * e = mySourceEdit = new QLineEdit;
+      e->setText (myAdd.readableName());
+      e->setCursorPosition (0);
+      e->selectAll ();
+      w = e;
+      connect (e, SIGNAL(editingFinished()), this, SLOT(onSourceEditingFinished()));
+    }
 
-  const QFileIconProvider iconProvider;
-  const QIcon folderIcon = iconProvider.icon (QFileIconProvider::Folder);
-  const QPixmap folderPixmap = folderIcon.pixmap (iconSize);
+  const int width = fontMetrics.size (0, QString::fromAscii ("This is a pretty long torrent filename indeed.torrent")).width ();
+  w->setMinimumWidth (width);
+  layout->addWidget (w, row, 1);
+  l->setBuddy (w);
 
   l = new QLabel (tr ("&Destination folder:"));
   layout->addWidget (l, ++row, 0, Qt::AlignLeft);
@@ -130,7 +151,11 @@ Options :: Options (Session& session, const Prefs& prefs, const AddData& addme,
 
   if (session.isLocal ())
     {
-      myDestination.setPath (downloadDir);
+      const QFileIconProvider iconProvider;
+      const QIcon folderIcon = iconProvider.icon (QFileIconProvider::Folder);
+      const QPixmap folderPixmap = folderIcon.pixmap (iconSize);
+
+      myLocalDestination.setPath (downloadDir);
       p = myDestinationButton = new QPushButton;
       p->setIcon (folderPixmap);
       p->setStyleSheet ("text-align: left; padding-left: 5; padding-right: 5");
@@ -163,7 +188,7 @@ Options :: Options (Session& session, const Prefs& prefs, const AddData& addme,
   m->addItem (tr ("Low"),    TR_PRI_LOW);
   m->setCurrentIndex (1); // Normal
   myPriorityCombo = m;
-  l = new QLabel (tr ("Torrent &priority:"));
+  l = new QLabel (tr ("&Priority:"));
   l->setBuddy (m);
   layout->addWidget (l, ++row, 0, Qt::AlignLeft);
   layout->addWidget (m, row, 1);
@@ -175,7 +200,7 @@ Options :: Options (Session& session, const Prefs& prefs, const AddData& addme,
     }
 
   QCheckBox * c;
-  c = myStartCheck = new QCheckBox (tr ("&Start when added"));
+  c = myStartCheck = new QCheckBox (tr ("S&tart when added"));
   c->setChecked (prefs.getBool (Prefs :: START));
   layout->addWidget (c, ++row, 0, 1, 2, Qt::AlignLeft);
 
@@ -223,40 +248,35 @@ Options :: refreshButton (QPushButton * p, const QString& text, int width)
 }
 
 void
-Options :: refreshFileButton (int width)
+Options :: refreshSource (int width)
 {
-  QString text;
+  QString text = myAdd.readableName ();
 
-  switch (myAdd.type)
-    {
-      case AddData::FILENAME: text = QFileInfo (myAdd.filename).completeBaseName (); break;
-      case AddData::URL:      text = myAdd.url.toString (); break;
-      case AddData::MAGNET:   text = myAdd.magnet; break;
-      default:                break;
-    }
+  if (mySourceButton)
+    refreshButton (mySourceButton, text, width);
 
-  refreshButton (myFileButton, text, width);
+  if (mySourceEdit)
+    mySourceEdit->setText (text);
 }
 
 void
 Options :: refreshDestinationButton (int width)
 {
   if (myDestinationButton != 0)
-    refreshButton (myDestinationButton, myDestination.absolutePath (), width);
+    refreshButton (myDestinationButton, myLocalDestination.absolutePath (), width);
 }
 
 
 bool
 Options :: eventFilter (QObject * o, QEvent * event)
 {
-  if (o==myFileButton && event->type () == QEvent::Resize)
+  if (event->type() == QEvent::Resize)
     {
-      refreshFileButton (dynamic_cast<QResizeEvent*> (event)->size ().width ());
-    }
+      if (o == mySourceButton)
+        refreshSource (dynamic_cast<QResizeEvent*> (event)->size ().width ());
 
-  if (o==myDestinationButton && event->type () == QEvent::Resize)
-    {
-      refreshDestinationButton (dynamic_cast<QResizeEvent*> (event)->size ().width ());
+      else if (o == myDestinationButton)
+        refreshDestinationButton (dynamic_cast<QResizeEvent*> (event)->size ().width ());
     }
 
   return false;
@@ -307,6 +327,7 @@ Options :: reload ()
   tr_ctorFree (ctor);
 
   myTree->clear ();
+  myTree->setVisible (myHaveInfo && (myInfo.fileCount>0));
   myFiles.clear ();
   myPriorities.clear ();
   myWanted.clear ();
@@ -361,9 +382,10 @@ Options :: onAccepted ()
 
   // "download-dir"
   if (myDestinationButton)
-    downloadDir = myDestination.absolutePath ();
+    downloadDir = myLocalDestination.absolutePath ();
   else
     downloadDir = myDestinationEdit->text ();
+
   tr_variantDictAddStr (args, TR_KEY_download_dir, downloadDir.toUtf8 ().constData ());
 
   // "metainfo"
@@ -461,15 +483,21 @@ Options :: onFilesSelected (const QStringList& files)
   if (files.size () == 1)
     {
       myAdd.set (files.at (0));
-      refreshFileButton ();
+      refreshSource ();
       reload ();
     }
 }
 
+void
+Options :: onSourceEditingFinished ()
+{
+  myAdd.set (mySourceEdit->text());
+}
+
 void
 Options :: onDestinationClicked ()
 {
-  QFileDialog * d = new QFileDialog (this, tr ("Select Destination"), myDestination.absolutePath ());
+  QFileDialog * d = new QFileDialog (this, tr ("Select Destination"), myLocalDestination.absolutePath ());
   d->setFileMode (QFileDialog::Directory);
   d->setAttribute (Qt::WA_DeleteOnClose);
   connect (d, SIGNAL (filesSelected (const QStringList&)), this, SLOT (onDestinationsSelected (const QStringList&)));
@@ -483,7 +511,7 @@ Options :: onDestinationsSelected (const QStringList& destinations)
     {
       const QString& destination (destinations.first ());
       myFreespaceLabel->setPath (destination);
-      myDestination.setPath (destination);
+      myLocalDestination.setPath (destination);
       refreshDestinationButton ();
     }
 }
@@ -499,7 +527,7 @@ Options :: onDestinationEdited (const QString& text)
 void
 Options :: onDestinationEditedIdle ()
 {
-  myFreespaceLabel->setPath (myDestinationEdit->text ());
+  myFreespaceLabel->setPath (myDestinationEdit->text());
 }
 
 /***
@@ -552,7 +580,7 @@ Options :: onTimeout ()
 
   if (!myVerifyFilePos && !myVerifyFile.isOpen ())
     {
-      const QFileInfo fileInfo (myDestination, QString::fromUtf8 (file->name));
+      const QFileInfo fileInfo (myLocalDestination, QString::fromUtf8 (file->name));
       myVerifyFile.setFileName (fileInfo.absoluteFilePath ());
       myVerifyFile.open (QIODevice::ReadOnly);
     }
@@ -620,10 +648,10 @@ Options :: onTimeout ()
         {
           // did the user accidentally specify the child directory instead of the parent?
           const QStringList tokens = QString (file->name).split ('/');
-          if (!tokens.empty () && myDestination.dirName ()==tokens.at (0))
+          if (!tokens.empty () && myLocalDestination.dirName ()==tokens.at (0))
             {
               // move up one directory and try again
-              myDestination.cdUp ();
+              myLocalDestination.cdUp ();
               refreshDestinationButton (-1);
               onVerify ();
               done = false;
index f3cb42154f030b625eda47483c018e8d43354993..6e446bb4f8e33c51ddd34a6422b7ae4e5bcae5a4 100644 (file)
@@ -71,7 +71,7 @@ class Options: public QDialog
   private:
     void reload ();
     void clearInfo ();
-    void refreshFileButton (int width=-1);
+    void refreshSource (int width=-1);
     void refreshDestinationButton (int width=-1);
     void refreshButton (QPushButton *, const QString&, int width=-1);
     bool eventFilter (QObject *, QEvent *);
@@ -85,6 +85,7 @@ class Options: public QDialog
     void onFilenameClicked ();
     void onDestinationClicked ();
     void onFilesSelected (const QStringList&);
+    void onSourceEditingFinished ();
     void onDestinationsSelected (const QStringList&);
     void onDestinationEdited (const QString&);
     void onDestinationEditedIdle ();
@@ -92,7 +93,7 @@ class Options: public QDialog
   private:
     Session& mySession;
     AddData myAdd;
-    QDir myDestination;
+    QDir myLocalDestination;
     bool myHaveInfo;
     tr_info myInfo;
     FileTreeView * myTree;
@@ -100,7 +101,8 @@ class Options: public QDialog
     QCheckBox * myStartCheck;
     QCheckBox * myTrashCheck;
     QComboBox * myPriorityCombo;
-    QPushButton * myFileButton;
+    QPushButton * mySourceButton;
+    QLineEdit * mySourceEdit;
     QPushButton * myDestinationButton;
     QLineEdit * myDestinationEdit;
     QPushButton * myVerifyButton;