Changeset 14002


Ignore:
Timestamp:
Feb 9, 2013, 11:11:17 PM (8 years ago)
Author:
jordan
Message:

(qt) merge together the two 'add url/magnet link' dialogs.

Location:
trunk/qt
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/app.cc

    r13869 r14002  
    443443      mySession->addTorrent (addme);
    444444    }
    445   else if (addme.type == addme.URL)
    446     {
    447       myWindow->openURL (addme.url.toString ());
    448     }
    449   else if (addme.type == addme.MAGNET)
    450     {
    451       myWindow->openURL (addme.magnet);
    452     }
    453445  else
    454446    {
  • trunk/qt/mainwin.cc

    r13991 r14002  
    11901190    str.clear ();
    11911191
    1192   openURL (str);
    1193 }
    1194 
    1195 void
    1196 TrMainWindow :: openURL (QString url)
    1197 {
    1198   bool ok;
    1199   const QString key = QInputDialog::getText (this,
    1200                                              tr ("Open Link"),
    1201                                              tr ("Open URL or Magnet Link"),
    1202                                              QLineEdit::Normal,
    1203                                              url,
    1204                                              &ok,
    1205                                              Qt::WindowStaysOnTopHint);
    1206   if (ok && !key.isEmpty ())
    1207     mySession.addTorrent (key);
     1192  addTorrent (str);
    12081193}
    12091194
     
    12161201
    12171202void
    1218 TrMainWindow :: addTorrent (const QString& filename)
    1219 {
    1220   if (!myFileDialogOptionsCheck->isChecked ())
    1221     {
    1222       mySession.addTorrent (filename);
    1223       QApplication :: alert (this);
    1224     }
     1203TrMainWindow :: addTorrent (const AddData& addMe)
     1204{
     1205  bool show_options_dialog;
     1206
     1207  if (myFileDialogOptionsCheck)
     1208    show_options_dialog = myFileDialogOptionsCheck->isChecked ();
    12251209  else
    1226     {
    1227       Options * o = new Options (mySession, myPrefs, filename, this);
     1210    show_options_dialog = myPrefs.getBool (Prefs::OPTIONS_PROMPT);
     1211
     1212  if (show_options_dialog)
     1213    {
     1214      Options * o = new Options (mySession, myPrefs, addMe, this);
    12281215      o->show ();
    12291216      QApplication :: alert (o);
     1217    }
     1218  else
     1219    {
     1220      mySession.addTorrent (addMe);
     1221      QApplication :: alert (this);
    12301222    }
    12311223}
  • trunk/qt/mainwin.h

    r13991 r14002  
    3434#include "ui_mainwin.h"
    3535
     36class AddData;
    3637class ActionDelegator;
    3738class Prefs;
     
    9394    void updateNetworkIcon ();
    9495    QWidgetList myHidden;
    95 
    96   public slots:
    97     void openURL (QString);
    9896
    9997  private slots:
     
    174172    void queueMoveBottom ();
    175173    void reannounceSelected ();
    176     void addTorrent (const QString& filename);
     174    void addTorrent (const AddData& addMe);
    177175    void onNetworkTimer ();
    178176
  • trunk/qt/options.cc

    r14001 r14002  
    8787  myAdd (addme),
    8888  myHaveInfo (false),
     89  mySourceButton (0),
     90  mySourceEdit (0),
    8991  myDestinationButton (0),
     92  myDestinationEdit (0),
    9093  myVerifyButton (0),
    9194  myVerifyFile (0),
     
    9396  myEditTimer (this)
    9497{
    95   setWindowTitle (tr ("Open Torrent"));
    9698  QFontMetrics fontMetrics (font ());
    9799  QGridLayout * layout = new QGridLayout (this);
    98100  int row = 0;
    99101
     102  QString title;
     103  if (myAdd.type == AddData::FILENAME)
     104    title = tr ("Open Torrent from File");
     105  else
     106    title = tr ("Open Torrent from URL or Magnet Link");
     107  setWindowTitle (title);
     108
    100109  myEditTimer.setInterval (2000);
    101110  myEditTimer.setSingleShot (true);
     
    106115  const QPixmap filePixmap = fileIcon.pixmap (iconSize);
    107116
     117  QLabel * l = new QLabel (tr ("&Source:"));
     118  layout->addWidget (l, row, 0, Qt::AlignLeft);
     119
     120  QWidget * w;
    108121  QPushButton * p;
    109   int width = fontMetrics.size (0, QString::fromAscii ("This is a pretty long torrent filename indeed.torrent")).width ();
    110   QLabel * l = new QLabel (tr ("&Torrent file:"));
    111   layout->addWidget (l, row, 0, Qt::AlignLeft);
    112   p = myFileButton =  new QPushButton;
    113   p->setIcon (filePixmap);
    114   p->setMinimumWidth (width);
    115   p->setStyleSheet (QString::fromAscii ("text-align: left; padding-left: 5; padding-right: 5"));
    116   p->installEventFilter (this);
    117 
    118   layout->addWidget (p, row, 1);
    119   l->setBuddy (p);
    120   connect (p, SIGNAL (clicked (bool)), this, SLOT (onFilenameClicked ()));
    121 
    122   const QFileIconProvider iconProvider;
    123   const QIcon folderIcon = iconProvider.icon (QFileIconProvider::Folder);
    124   const QPixmap folderPixmap = folderIcon.pixmap (iconSize);
     122
     123  if (myAdd.type == AddData::FILENAME)
     124    {
     125      p = mySourceButton =  new QPushButton;
     126      p->setIcon (filePixmap);
     127      p->setStyleSheet (QString::fromAscii ("text-align: left; padding-left: 5; padding-right: 5"));
     128      p->installEventFilter (this);
     129      w = p;
     130      connect (p, SIGNAL (clicked (bool)), this, SLOT (onFilenameClicked ()));
     131    }
     132  else
     133    {
     134      QLineEdit * e = mySourceEdit = new QLineEdit;
     135      e->setText (myAdd.readableName());
     136      e->setCursorPosition (0);
     137      e->selectAll ();
     138      w = e;
     139      connect (e, SIGNAL(editingFinished()), this, SLOT(onSourceEditingFinished()));
     140    }
     141
     142  const int width = fontMetrics.size (0, QString::fromAscii ("This is a pretty long torrent filename indeed.torrent")).width ();
     143  w->setMinimumWidth (width);
     144  layout->addWidget (w, row, 1);
     145  l->setBuddy (w);
    125146
    126147  l = new QLabel (tr ("&Destination folder:"));
     
    131152  if (session.isLocal ())
    132153    {
    133       myDestination.setPath (downloadDir);
     154      const QFileIconProvider iconProvider;
     155      const QIcon folderIcon = iconProvider.icon (QFileIconProvider::Folder);
     156      const QPixmap folderPixmap = folderIcon.pixmap (iconSize);
     157
     158      myLocalDestination.setPath (downloadDir);
    134159      p = myDestinationButton = new QPushButton;
    135160      p->setIcon (folderPixmap);
     
    164189  m->setCurrentIndex (1); // Normal
    165190  myPriorityCombo = m;
    166   l = new QLabel (tr ("Torrent &priority:"));
     191  l = new QLabel (tr ("&Priority:"));
    167192  l->setBuddy (m);
    168193  layout->addWidget (l, ++row, 0, Qt::AlignLeft);
     
    176201
    177202  QCheckBox * c;
    178   c = myStartCheck = new QCheckBox (tr ("&Start when added"));
     203  c = myStartCheck = new QCheckBox (tr ("S&tart when added"));
    179204  c->setChecked (prefs.getBool (Prefs :: START));
    180205  layout->addWidget (c, ++row, 0, 1, 2, Qt::AlignLeft);
     
    224249
    225250void
    226 Options :: refreshFileButton (int width)
    227 {
    228   QString text;
    229 
    230   switch (myAdd.type)
    231     {
    232       case AddData::FILENAME: text = QFileInfo (myAdd.filename).completeBaseName (); break;
    233       case AddData::URL:      text = myAdd.url.toString (); break;
    234       case AddData::MAGNET:   text = myAdd.magnet; break;
    235       default:                break;
    236     }
    237 
    238   refreshButton (myFileButton, text, width);
     251Options :: refreshSource (int width)
     252{
     253  QString text = myAdd.readableName ();
     254
     255  if (mySourceButton)
     256    refreshButton (mySourceButton, text, width);
     257
     258  if (mySourceEdit)
     259    mySourceEdit->setText (text);
    239260}
    240261
     
    243264{
    244265  if (myDestinationButton != 0)
    245     refreshButton (myDestinationButton, myDestination.absolutePath (), width);
     266    refreshButton (myDestinationButton, myLocalDestination.absolutePath (), width);
    246267}
    247268
     
    250271Options :: eventFilter (QObject * o, QEvent * event)
    251272{
    252   if (o==myFileButton && event->type () == QEvent::Resize)
    253     {
    254       refreshFileButton (dynamic_cast<QResizeEvent*> (event)->size ().width ());
    255     }
    256 
    257   if (o==myDestinationButton && event->type () == QEvent::Resize)
    258     {
    259       refreshDestinationButton (dynamic_cast<QResizeEvent*> (event)->size ().width ());
     273  if (event->type() == QEvent::Resize)
     274    {
     275      if (o == mySourceButton)
     276        refreshSource (dynamic_cast<QResizeEvent*> (event)->size ().width ());
     277
     278      else if (o == myDestinationButton)
     279        refreshDestinationButton (dynamic_cast<QResizeEvent*> (event)->size ().width ());
    260280    }
    261281
     
    308328
    309329  myTree->clear ();
     330  myTree->setVisible (myHaveInfo && (myInfo.fileCount>0));
    310331  myFiles.clear ();
    311332  myPriorities.clear ();
     
    362383  // "download-dir"
    363384  if (myDestinationButton)
    364     downloadDir = myDestination.absolutePath ();
     385    downloadDir = myLocalDestination.absolutePath ();
    365386  else
    366387    downloadDir = myDestinationEdit->text ();
     388
    367389  tr_variantDictAddStr (args, TR_KEY_download_dir, downloadDir.toUtf8 ().constData ());
    368390
     
    462484    {
    463485      myAdd.set (files.at (0));
    464       refreshFileButton ();
     486      refreshSource ();
    465487      reload ();
    466488    }
     
    468490
    469491void
     492Options :: onSourceEditingFinished ()
     493{
     494  myAdd.set (mySourceEdit->text());
     495}
     496
     497void
    470498Options :: onDestinationClicked ()
    471499{
    472   QFileDialog * d = new QFileDialog (this, tr ("Select Destination"), myDestination.absolutePath ());
     500  QFileDialog * d = new QFileDialog (this, tr ("Select Destination"), myLocalDestination.absolutePath ());
    473501  d->setFileMode (QFileDialog::Directory);
    474502  d->setAttribute (Qt::WA_DeleteOnClose);
     
    484512      const QString& destination (destinations.first ());
    485513      myFreespaceLabel->setPath (destination);
    486       myDestination.setPath (destination);
     514      myLocalDestination.setPath (destination);
    487515      refreshDestinationButton ();
    488516    }
     
    500528Options :: onDestinationEditedIdle ()
    501529{
    502   myFreespaceLabel->setPath (myDestinationEdit->text ());
     530  myFreespaceLabel->setPath (myDestinationEdit->text());
    503531}
    504532
     
    553581  if (!myVerifyFilePos && !myVerifyFile.isOpen ())
    554582    {
    555       const QFileInfo fileInfo (myDestination, QString::fromUtf8 (file->name));
     583      const QFileInfo fileInfo (myLocalDestination, QString::fromUtf8 (file->name));
    556584      myVerifyFile.setFileName (fileInfo.absoluteFilePath ());
    557585      myVerifyFile.open (QIODevice::ReadOnly);
     
    621649          // did the user accidentally specify the child directory instead of the parent?
    622650          const QStringList tokens = QString (file->name).split ('/');
    623           if (!tokens.empty () && myDestination.dirName ()==tokens.at (0))
     651          if (!tokens.empty () && myLocalDestination.dirName ()==tokens.at (0))
    624652            {
    625653              // move up one directory and try again
    626               myDestination.cdUp ();
     654              myLocalDestination.cdUp ();
    627655              refreshDestinationButton (-1);
    628656              onVerify ();
  • trunk/qt/options.h

    r14001 r14002  
    7272    void reload ();
    7373    void clearInfo ();
    74     void refreshFileButton (int width=-1);
     74    void refreshSource (int width=-1);
    7575    void refreshDestinationButton (int width=-1);
    7676    void refreshButton (QPushButton *, const QString&, int width=-1);
     
    8686    void onDestinationClicked ();
    8787    void onFilesSelected (const QStringList&);
     88    void onSourceEditingFinished ();
    8889    void onDestinationsSelected (const QStringList&);
    8990    void onDestinationEdited (const QString&);
     
    9394    Session& mySession;
    9495    AddData myAdd;
    95     QDir myDestination;
     96    QDir myLocalDestination;
    9697    bool myHaveInfo;
    9798    tr_info myInfo;
     
    101102    QCheckBox * myTrashCheck;
    102103    QComboBox * myPriorityCombo;
    103     QPushButton * myFileButton;
     104    QPushButton * mySourceButton;
     105    QLineEdit * mySourceEdit;
    104106    QPushButton * myDestinationButton;
    105107    QLineEdit * myDestinationEdit;
Note: See TracChangeset for help on using the changeset viewer.