Changeset 14204


Ignore:
Timestamp:
Sep 14, 2013, 10:45:04 PM (9 years ago)
Author:
jordan
Message:

copyediting: indentation cleanups

Location:
trunk/qt
Files:
48 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/add-data.cc

    r14177 r14204  
    2121
    2222int
    23 AddData :: set( const QString& key )
     23AddData :: set (const QString& key)
    2424{
    25     if( Utils::isMagnetLink( key ) )
     25  if (Utils::isMagnetLink (key))
    2626    {
    27         magnet = key;
    28         type = MAGNET;
     27      magnet = key;
     28      type = MAGNET;
    2929    }
    30     else if ( Utils::isUriWithSupportedScheme( key ) )
     30  else if  (Utils::isUriWithSupportedScheme (key))
    3131    {
    32         url = key;
    33         type = URL;
     32      url = key;
     33      type = URL;
    3434    }
    35     else if( QFile(key).exists( ) )
     35  else if (QFile(key).exists ())
    3636    {
    37         filename = QDir::fromNativeSeparators( key );
    38         type = FILENAME;
     37      filename = QDir::fromNativeSeparators (key);
     38      type = FILENAME;
    3939
    40         QFile file( key );
    41         file.open( QIODevice::ReadOnly );
    42         metainfo = file.readAll( );
    43         file.close( );
     40      QFile file (key);
     41      file.open (QIODevice::ReadOnly);
     42      metainfo = file.readAll ();
     43      file.close ();
    4444    }
    45     else if( Utils::isHexHashcode( key ) )
     45  else if (Utils::isHexHashcode (key))
    4646    {
    47         magnet = QString::fromUtf8("magnet:?xt=urn:btih:") + key;
    48         type = MAGNET;
     47      magnet = QString::fromUtf8("magnet:?xt=urn:btih:") + key;
     48      type = MAGNET;
    4949    }
    50     else
     50  else
    5151    {
    52         int len;
    53         char * raw = tr_base64_decode( key.toUtf8().constData(), key.toUtf8().size(), &len );
    54         if( raw ) {
    55             metainfo.append( raw, len );
    56             tr_free( raw );
    57             type = METAINFO;
     52      int len;
     53      char * raw = tr_base64_decode (key.toUtf8().constData(), key.toUtf8().size(), &len);
     54      if (raw)
     55        {
     56          metainfo.append (raw, len);
     57          tr_free (raw);
     58          type = METAINFO;
    5859        }
    59         else type = NONE;
     60      else
     61        {
     62          type = NONE;
     63        }
    6064    }
    6165
    62     return type;
     66  return type;
    6367}
    6468
    6569QByteArray
    66 AddData :: toBase64( ) const
     70AddData :: toBase64 () const
    6771{
    68     QByteArray ret;
     72  QByteArray ret;
    6973
    70     if( !metainfo.isEmpty( ) )
     74  if (!metainfo.isEmpty ())
    7175    {
    72         int len = 0;
    73         char * b64 = tr_base64_encode( metainfo.constData(), metainfo.size(), &len );
    74         ret = QByteArray( b64, len );
    75         tr_free( b64 );
     76      int len = 0;
     77      char * b64 = tr_base64_encode (metainfo.constData(), metainfo.size(), &len);
     78      ret = QByteArray (b64, len);
     79      tr_free (b64);
    7680    }
    7781
    78     return ret;
     82  return ret;
    7983}
    8084
    8185QString
    82 AddData :: readableName( ) const
     86AddData :: readableName () const
    8387{
    84     QString ret;
     88  QString ret;
    8589
    86     switch( type )
     90  switch (type)
    8791    {
    88         case FILENAME: ret = filename; break;
     92      case FILENAME:
     93        ret = filename;
     94        break;
    8995
    90         case MAGNET: ret = magnet; break;
     96      case MAGNET:
     97        ret = magnet;
     98        break;
    9199
    92         case URL: ret = url.toString(); break;
     100      case URL:
     101        ret = url.toString();
     102        break;
    93103
    94         case METAINFO: {
    95             tr_info inf;
    96             tr_ctor * ctor = tr_ctorNew( NULL );
    97             tr_ctorSetMetainfo( ctor, (const quint8*)metainfo.constData(), metainfo.size() );
    98             if( tr_torrentParse( ctor, &inf ) == TR_PARSE_OK  ) {
    99                 ret = QString::fromUtf8( inf.name ); // metainfo is required to be UTF-8
    100                 tr_metainfoFree( &inf );
     104      case METAINFO:
     105        {
     106          tr_info inf;
     107          tr_ctor * ctor = tr_ctorNew (NULL);
     108          tr_ctorSetMetainfo (ctor, (const quint8*)metainfo.constData(), metainfo.size());
     109          if (tr_torrentParse (ctor, &inf) == TR_PARSE_OK )
     110            {
     111              ret = QString::fromUtf8 (inf.name); // metainfo is required to be UTF-8
     112              tr_metainfoFree (&inf);
    101113            }
    102             tr_ctorFree( ctor );
    103             break;
     114          tr_ctorFree (ctor);
     115          break;
    104116        }
    105117    }
    106118
    107    return ret;
     119  return ret;
    108120}
  • trunk/qt/add-data.h

    r12212 r14204  
    2020class AddData
    2121{
    22     public:
     22  public:
    2323
    24         enum { NONE, MAGNET, URL, FILENAME, METAINFO };
    25         int type;
     24    enum { NONE, MAGNET, URL, FILENAME, METAINFO };
     25    int type;
    2626
    27         QByteArray metainfo;
    28         QString filename;
    29         QString magnet;
    30         QUrl url;
     27    QByteArray metainfo;
     28    QString filename;
     29    QString magnet;
     30    QUrl url;
    3131
    32     public:
     32  public:
    3333
    34         int set( const QString& );
    35         AddData( const QString& str ) { set(str); }
    36         AddData( ): type(NONE) { }
     34    int set (const QString&);
     35    AddData (const QString& str) { set(str); }
     36    AddData (): type(NONE) {}
    3737
    38         QByteArray toBase64( ) const;
     38    QByteArray toBase64 () const;
     39    QString readableName () const;
    3940
    40         QString readableName( ) const;
     41  public:
    4142
    42     public:
    43 
    44         static bool isSupported( const QString& str ) { return AddData(str).type != NONE; }
     43    static bool isSupported (const QString& str) { return AddData(str).type != NONE; }
    4544};
    4645
  • trunk/qt/dbus-adaptor.cc

    r11280 r14204  
    1515#include "dbus-adaptor.h"
    1616
    17 TrDBusAdaptor :: TrDBusAdaptor( MyApp* app ):
    18     QDBusAbstractAdaptor( app ),
    19     myApp( app )
     17TrDBusAdaptor :: TrDBusAdaptor (MyApp* app):
     18  QDBusAbstractAdaptor (app),
     19  myApp (app)
    2020{
    2121}
    2222
    2323bool
    24 TrDBusAdaptor :: PresentWindow( )
     24TrDBusAdaptor :: PresentWindow ()
    2525{
    26     myApp->raise( );
    27     return true;
     26  myApp->raise ();
     27  return true;
    2828}
    2929
    3030bool
    31 TrDBusAdaptor :: AddMetainfo( const QString& key )
     31TrDBusAdaptor :: AddMetainfo (const QString& key)
    3232{
    33     AddData addme( key );
     33  AddData addme (key);
    3434
    35     if( addme.type != addme.NONE )
    36         myApp->addTorrent( addme );
     35  if (addme.type != addme.NONE)
     36    myApp->addTorrent (addme);
    3737
    38     return true;
     38  return true;
    3939}
  • trunk/qt/dbus-adaptor.h

    r11280 r14204  
    2828  public:
    2929    TrDBusAdaptor( MyApp* );
    30     virtual ~TrDBusAdaptor() { }
     30    virtual ~TrDBusAdaptor() {}
    3131
    3232  public slots:
  • trunk/qt/favicon.cc

    r14163 r14204  
    2828***/
    2929
    30 Favicons :: Favicons( )
     30Favicons :: Favicons ()
    3131{
    32     myNAM = new QNetworkAccessManager( );
    33     connect( myNAM, SIGNAL(finished(QNetworkReply*)), this, SLOT(onRequestFinished(QNetworkReply*)) );
     32  myNAM = new QNetworkAccessManager ();
     33  connect (myNAM, SIGNAL(finished(QNetworkReply*)), this, SLOT(onRequestFinished(QNetworkReply*)));
    3434}
    3535
    36 Favicons :: ~Favicons( )
     36Favicons :: ~Favicons ()
    3737{
    38     delete myNAM;
     38  delete myNAM;
    3939}
    4040
     
    4444
    4545QString
    46 Favicons :: getCacheDir( )
     46Favicons :: getCacheDir ()
    4747{
    48     const QString base =
     48  const QString base =
    4949#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
    50         QDesktopServices::storageLocation( QDesktopServices::CacheLocation );
     50    QDesktopServices::storageLocation (QDesktopServices::CacheLocation);
    5151#else
    52         QStandardPaths::writableLocation( QStandardPaths::CacheLocation );
     52    QStandardPaths::writableLocation (QStandardPaths::CacheLocation);
    5353#endif
    5454
    55     return QDir( base ).absoluteFilePath( "favicons" );
     55  return QDir(base).absoluteFilePath ("favicons");
    5656}
    5757
    5858void
    59 Favicons :: ensureCacheDirHasBeenScanned( )
     59Favicons :: ensureCacheDirHasBeenScanned ()
    6060{
    61     static bool hasBeenScanned = false;
     61  static bool hasBeenScanned = false;
    6262
    63     if( !hasBeenScanned )
     63  if (!hasBeenScanned)
    6464    {
    65         hasBeenScanned = true;
     65      hasBeenScanned = true;
    6666
    67         QDir cacheDir( getCacheDir( ) );
    68         cacheDir.mkpath( cacheDir.absolutePath( ) );
     67      QDir cacheDir (getCacheDir ());
     68      cacheDir.mkpath (cacheDir.absolutePath ());
    6969
    70         QStringList files = cacheDir.entryList( QDir::Files|QDir::Readable );
    71         foreach( QString file, files ) {
    72             QPixmap pixmap;
    73             pixmap.load( cacheDir.absoluteFilePath( file ) );
    74             if( !pixmap.isNull( ) )
    75                 myPixmaps.insert( file, pixmap );
     70      QStringList files = cacheDir.entryList (QDir::Files|QDir::Readable);
     71      foreach (QString file, files)
     72        {
     73          QPixmap pixmap;
     74          pixmap.load (cacheDir.absoluteFilePath (file));
     75          if (!pixmap.isNull ())
     76            myPixmaps.insert (file, pixmap);
    7677        }
    7778    }
     
    7980
    8081QString
    81 Favicons :: getHost( const QUrl& url )
     82Favicons :: getHost (const QUrl& url)
    8283{
    83     QString host = url.host( );
    84     const int first_dot = host.indexOf( '.' );
    85     const int last_dot = host.lastIndexOf( '.' );
     84  QString host = url.host ();
     85  const int first_dot = host.indexOf ('.');
     86  const int last_dot = host.lastIndexOf ('.');
    8687
    87     if( ( first_dot != -1 ) && ( last_dot != -1 ) && ( first_dot != last_dot ) )
    88         host.remove( 0, first_dot + 1 );
     88  if ((first_dot != -1) && (last_dot != -1) &&  (first_dot != last_dot))
     89    host.remove (0, first_dot + 1);
    8990
    90     return host;
     91  return host;
    9192}
    9293
    9394QPixmap
    94 Favicons :: find( const QUrl& url )
     95Favicons :: find (const QUrl& url)
    9596{
    96     return findFromHost( getHost( url ) );
     97  return findFromHost (getHost (url));
    9798}
    9899
    99100namespace
    100101{
    101     const QSize rightSize( 16, 16 );
     102  const QSize rightSize (16, 16);
    102103};
    103104
    104105QPixmap
    105 Favicons :: findFromHost( const QString& host )
     106Favicons :: findFromHost (const QString& host)
    106107{
    107     ensureCacheDirHasBeenScanned( );
     108  ensureCacheDirHasBeenScanned ();
    108109
    109     const QPixmap pixmap = myPixmaps[ host ];
    110     return pixmap.size()==rightSize ? pixmap : pixmap.scaled(rightSize);
     110  const QPixmap pixmap = myPixmaps[ host ];
     111  return pixmap.size()==rightSize ? pixmap : pixmap.scaled(rightSize);
    111112}
    112113
    113114void
    114 Favicons :: add( const QUrl& url )
     115Favicons :: add (const QUrl& url)
    115116{
    116     ensureCacheDirHasBeenScanned( );
     117  ensureCacheDirHasBeenScanned ();
    117118
    118     const QString host = getHost( url );
     119  const QString host = getHost (url);
    119120
    120     if( !myPixmaps.contains( host ) )
     121  if (!myPixmaps.contains (host))
    121122    {
    122         // add a placholder s.t. we only ping the server once per session
    123         QPixmap tmp( rightSize );
    124         tmp.fill( Qt::transparent );
    125         myPixmaps.insert( host, tmp );
     123      // add a placholder s.t. we only ping the server once per session
     124      QPixmap tmp (rightSize);
     125      tmp.fill (Qt::transparent);
     126      myPixmaps.insert (host, tmp);
    126127
    127         // try to download the favicon
    128         const QString path = "http://" + host + "/favicon.";
    129         QStringList suffixes;
    130         suffixes << "ico" << "png" << "gif" << "jpg";
    131         foreach( QString suffix, suffixes )
    132             myNAM->get( QNetworkRequest( path + suffix ) );
     128      // try to download the favicon
     129      const QString path = "http://" + host + "/favicon.";
     130      QStringList suffixes;
     131      suffixes << "ico" << "png" << "gif" << "jpg";
     132      foreach (QString suffix, suffixes)
     133        myNAM->get (QNetworkRequest (path + suffix));
    133134    }
    134135}
    135136
    136137void
    137 Favicons :: onRequestFinished( QNetworkReply * reply )
     138Favicons :: onRequestFinished (QNetworkReply * reply)
    138139{
    139     const QString host = reply->url().host();
     140  const QString host = reply->url().host();
    140141
    141     QPixmap pixmap;
     142  QPixmap pixmap;
    142143
    143     const QByteArray content = reply->readAll( );
    144     if( !reply->error( ) )
    145         pixmap.loadFromData( content );
     144  const QByteArray content = reply->readAll ();
     145  if (!reply->error ())
     146    pixmap.loadFromData (content);
    146147
    147     if( !pixmap.isNull( ) )
     148  if (!pixmap.isNull ())
    148149    {
    149         // save it in memory...
    150         myPixmaps.insert( host, pixmap );
     150      // save it in memory...
     151      myPixmaps.insert (host, pixmap);
    151152
    152         // save it on disk...
    153         QDir cacheDir( getCacheDir( ) );
    154         cacheDir.mkpath( cacheDir.absolutePath( ) );
    155         QFile file( cacheDir.absoluteFilePath( host ) );
    156         file.open( QIODevice::WriteOnly );
    157         file.write( content );
    158         file.close( );
     153      // save it on disk...
     154      QDir cacheDir (getCacheDir ());
     155      cacheDir.mkpath (cacheDir.absolutePath ());
     156      QFile file (cacheDir.absoluteFilePath (host));
     157      file.open (QIODevice::WriteOnly);
     158      file.write (content);
     159      file.close ();
    159160
    160         // notify listeners
    161         emit pixmapReady( host );
     161      // notify listeners
     162      emit pixmapReady (host);
    162163    }
    163164}
  • trunk/qt/favicon.h

    r11092 r14204  
    2525class Favicons: public QObject
    2626{
    27         Q_OBJECT;
     27    Q_OBJECT;
    2828
    29     public:
     29  public:
    3030
    31         static QString getHost( const QUrl& url );
     31    static QString getHost( const QUrl& url );
    3232
    33     public:
     33  public:
    3434
    35         Favicons();
    36         virtual ~Favicons();
     35    Favicons();
     36    virtual ~Favicons();
    3737
    38         /* returns a cached pixmap, or a NULL pixmap if there's no match in the cache */
    39         QPixmap find( const QUrl& url );
     38    // returns a cached pixmap, or a NULL pixmap if there's no match in the cache
     39    QPixmap find (const QUrl& url);
    4040
    41         /* returns a cached pixmap, or a NULL pixmap if there's no match in the cache */
    42         QPixmap findFromHost( const QString& host );
     41    // returns a cached pixmap, or a NULL pixmap if there's no match in the cache
     42    QPixmap findFromHost (const QString& host);
    4343
    44         /* this will emit a signal when (if) the icon becomes ready */
    45         void add( const QUrl& url );
     44    // this will emit a signal when (if) the icon becomes ready
     45    void add (const QUrl& url);
    4646
    47     signals:
     47  signals:
    4848
    49         void pixmapReady( const QString& host );
     49    void pixmapReady (const QString& host);
    5050
    51     private:
     51  private:
    5252
    53         QNetworkAccessManager * myNAM;
    54         QMap<QString,QPixmap> myPixmaps;
     53    QNetworkAccessManager * myNAM;
     54    QMap<QString,QPixmap> myPixmaps;
    5555
    56         QString getCacheDir( );
    57         void ensureCacheDirHasBeenScanned( );
     56    QString getCacheDir ();
     57    void ensureCacheDirHasBeenScanned ();
    5858
    59     private slots:
     59  private slots:
    6060
    61         void onRequestFinished( QNetworkReply * reply );
     61    void onRequestFinished (QNetworkReply * reply);
    6262};
    6363
  • trunk/qt/file-tree.h

    r14196 r14204  
    5252      myHaveSize (0),
    5353      myTotalSize (size),
    54       myFirstUnhashedRow (0) { }
     54      myFirstUnhashedRow (0) {}
    5555
    5656  public:
     
    150150
    151151  public:
    152     FileTreeDelegate (QObject * parent=0): QItemDelegate(parent) { }
    153     virtual ~FileTreeDelegate() { }
     152    FileTreeDelegate (QObject * parent=0): QItemDelegate(parent) {}
     153    virtual ~FileTreeDelegate() {}
    154154
    155155  public:
  • trunk/qt/filterbar.cc

    r14150 r14204  
    591591  QAbstractItemModel * model = myActivityCombo->model ();
    592592
    593   int torrentsPerMode[FilterMode::NUM_MODES] = { };
     593  int torrentsPerMode[FilterMode::NUM_MODES] = {};
    594594  myFilter.countTorrentsPerMode (torrentsPerMode);
    595595
  • trunk/qt/filters.cc

    r12611 r14204  
    1515const QString FilterMode::names[NUM_MODES] =
    1616{
    17     "show-all",
    18     "show-active",
    19     "show-downloading",
    20     "show-seeding",
    21     "show-paused",
    22     "show-finished",
    23     "show-verifying",
    24     "show-error",
     17  "show-all",
     18  "show-active",
     19  "show-downloading",
     20  "show-seeding",
     21  "show-paused",
     22  "show-finished",
     23  "show-verifying",
     24  "show-error",
    2525};
    2626
     
    2828FilterMode :: modeFromName( const QString& name )
    2929{
    30     for( int i=0; i<NUM_MODES; ++i )
    31         if( names[i] == name )
    32             return i;
    33     return FilterMode().mode(); // use the default value
     30  for (int i=0; i<NUM_MODES; ++i)
     31    if( names[i] == name )
     32      return i;
     33
     34  return FilterMode().mode(); // use the default value
    3435}
    3536
    36 const QString SortMode::names[NUM_MODES] = {
    37     "sort-by-activity",
    38     "sort-by-age",
    39     "sort-by-eta",
    40     "sort-by-name",
    41     "sort-by-progress",
    42     "sort-by-queue"
    43     "sort-by-ratio",
    44     "sort-by-size",
    45     "sort-by-state",
    46     "sort-by-id"
     37const QString SortMode::names[NUM_MODES] =
     38{
     39  "sort-by-activity",
     40  "sort-by-age",
     41  "sort-by-eta",
     42  "sort-by-name",
     43  "sort-by-progress",
     44  "sort-by-queue"
     45  "sort-by-ratio",
     46  "sort-by-size",
     47  "sort-by-state",
     48  "sort-by-id"
    4749};
    4850
    4951int
    50 SortMode :: modeFromName( const QString& name )
     52SortMode :: modeFromName (const QString& name)
    5153{
    52     for( int i=0; i<NUM_MODES; ++i )
    53         if( names[i] == name )
    54             return i;
    55     return SortMode().mode(); // use the default value
     54  for (int i=0; i<NUM_MODES; ++i)
     55    if (names[i] == name)
     56      return i;
     57
     58  return SortMode().mode(); // use the default value
    5659}
  • trunk/qt/filters.h

    r12611 r14204  
    2020class FilterMode
    2121{
    22     private:
    23         int myMode;
    24     public:
    25         FilterMode( int mode=SHOW_ALL ): myMode(mode) { }
    26         FilterMode( const QString& name ): myMode(modeFromName(name)) { }
    27         static const QString names[];
    28         enum { SHOW_ALL, SHOW_ACTIVE, SHOW_DOWNLOADING, SHOW_SEEDING, SHOW_PAUSED,
    29                SHOW_FINISHED, SHOW_VERIFYING, SHOW_ERROR, NUM_MODES };
    30         static int modeFromName( const QString& name );
    31         static const QString& nameFromMode( int mode ) { return names[mode]; }
    32         int mode() const { return myMode; }
    33         const QString& name() const { return names[myMode]; }
     22  private:
     23    int myMode;
     24
     25  public:
     26    FilterMode( int mode=SHOW_ALL ): myMode(mode) {}
     27    FilterMode( const QString& name ): myMode(modeFromName(name)) {}
     28    static const QString names[];
     29    enum { SHOW_ALL, SHOW_ACTIVE, SHOW_DOWNLOADING, SHOW_SEEDING, SHOW_PAUSED,
     30           SHOW_FINISHED, SHOW_VERIFYING, SHOW_ERROR, NUM_MODES };
     31    static int modeFromName( const QString& name );
     32    static const QString& nameFromMode( int mode ) { return names[mode]; }
     33    int mode() const { return myMode; }
     34    const QString& name() const { return names[myMode]; }
    3435};
    3536
    3637class SortMode
    3738{
    38     private:
    39         int myMode;
    40     public:
    41         SortMode( int mode=SORT_BY_ID ): myMode(mode) { }
    42         SortMode( const QString& name ): myMode(modeFromName(name)) { }
    43         static const QString names[];
    44         enum { SORT_BY_ACTIVITY, SORT_BY_AGE, SORT_BY_ETA, SORT_BY_NAME,
    45                SORT_BY_PROGRESS, SORT_BY_QUEUE, SORT_BY_RATIO, SORT_BY_SIZE,
    46                SORT_BY_STATE, SORT_BY_ID, NUM_MODES };
    47         static int modeFromName( const QString& name );
    48         static const QString& nameFromMode( int mode );
    49         int mode() const { return myMode; }
    50         const QString& name() const { return names[myMode]; }
     39  private:
     40    int myMode;
     41
     42  public:
     43    SortMode( int mode=SORT_BY_ID ): myMode(mode) {}
     44    SortMode( const QString& name ): myMode(modeFromName(name)) {}
     45    static const QString names[];
     46    enum { SORT_BY_ACTIVITY, SORT_BY_AGE, SORT_BY_ETA, SORT_BY_NAME,
     47           SORT_BY_PROGRESS, SORT_BY_QUEUE, SORT_BY_RATIO, SORT_BY_SIZE,
     48           SORT_BY_STATE, SORT_BY_ID, NUM_MODES };
     49    static int modeFromName( const QString& name );
     50    static const QString& nameFromMode( int mode );
     51    int mode() const { return myMode; }
     52    const QString& name() const { return names[myMode]; }
    5153};
    5254
  • trunk/qt/formatter.cc

    r14185 r14204  
    4242 unitStrings[SPEED][TB] = tr ("TB/s");
    4343 tr_formatter_speed_init (speed_K,
    44                           unitStrings[SPEED][KB].toUtf8 ().constData (),
    45                           unitStrings[SPEED][MB].toUtf8 ().constData (),
    46                           unitStrings[SPEED][GB].toUtf8 ().constData (),
    47                           unitStrings[SPEED][TB].toUtf8 ().constData ());
     44                          unitStrings[SPEED][KB].toUtf8().constData(),
     45                          unitStrings[SPEED][MB].toUtf8().constData(),
     46                          unitStrings[SPEED][GB].toUtf8().constData(),
     47                          unitStrings[SPEED][TB].toUtf8().constData());
    4848
    4949  size_K = 1000;
     
    5454  unitStrings[SIZE][TB] = tr ("TB");
    5555  tr_formatter_size_init (size_K,
    56                           unitStrings[SIZE][KB].toUtf8 ().constData (),
    57                           unitStrings[SIZE][MB].toUtf8 ().constData (),
    58                           unitStrings[SIZE][GB].toUtf8 ().constData (),
    59                           unitStrings[SIZE][TB].toUtf8 ().constData ());
     56                          unitStrings[SIZE][KB].toUtf8().constData(),
     57                          unitStrings[SIZE][MB].toUtf8().constData(),
     58                          unitStrings[SIZE][GB].toUtf8().constData(),
     59                          unitStrings[SIZE][TB].toUtf8().constData());
    6060
    6161  mem_K = 1024;
     
    6666  unitStrings[MEM][TB] = tr ("TiB");
    6767  tr_formatter_mem_init (mem_K,
    68                          unitStrings[MEM][KB].toUtf8 ().constData (),
    69                          unitStrings[MEM][MB].toUtf8 ().constData (),
    70                          unitStrings[MEM][GB].toUtf8 ().constData (),
    71                          unitStrings[MEM][TB].toUtf8 ().constData ());
     68                         unitStrings[MEM][KB].toUtf8().constData(),
     69                         unitStrings[MEM][MB].toUtf8().constData(),
     70                         unitStrings[MEM][GB].toUtf8().constData(),
     71                         unitStrings[MEM][TB].toUtf8().constData());
    7272}
    7373
  • trunk/qt/hig.cc

    r11092 r14204  
    2121
    2222
    23 HIG :: HIG( QWidget * parent ):
    24     QWidget( parent ),
    25     myRow( 0 ),
    26     myHasTall( false ),
    27     myGrid( new QGridLayout( this ) )
    28 {
    29     myGrid->setContentsMargins( PAD_BIG, PAD_BIG, PAD_BIG, PAD_BIG );
    30     myGrid->setHorizontalSpacing( PAD_BIG );
    31     myGrid->setVerticalSpacing( PAD );
    32     myGrid->setColumnStretch ( 1, 1 );
    33 }
    34 
    35 HIG :: ~HIG( )
    36 {
    37     delete myGrid;
     23HIG :: HIG (QWidget * parent):
     24  QWidget (parent),
     25  myRow (0),
     26  myHasTall (false),
     27  myGrid (new QGridLayout (this))
     28{
     29  myGrid->setContentsMargins (PAD_BIG, PAD_BIG, PAD_BIG, PAD_BIG);
     30  myGrid->setHorizontalSpacing (PAD_BIG);
     31  myGrid->setVerticalSpacing (PAD);
     32  myGrid->setColumnStretch  (1, 1);
     33}
     34
     35HIG :: ~HIG ()
     36{
     37  delete myGrid;
    3838}
    3939
     
    4343
    4444void
    45 HIG :: addSectionDivider( )
    46 {
    47     QWidget * w = new QWidget( this );
    48     myGrid->addWidget( w, myRow, 0, 1, 2 );
    49     ++myRow;
    50 }
    51 
    52 void
    53 HIG :: addSectionTitle( const QString& title )
    54 {
    55     QLabel * label = new QLabel( this );
    56     label->setText( title );
    57     label->setStyleSheet( "font: bold" );
    58     label->setAlignment( Qt::AlignLeft|Qt::AlignVCenter );
    59     addSectionTitle( label );
    60 }
    61 
    62 void
    63 HIG :: addSectionTitle( QWidget * w )
    64 {
    65     myGrid->addWidget( w, myRow, 0, 1, 2, Qt::AlignLeft|Qt::AlignVCenter );
    66     ++myRow;
    67 }
    68 
    69 void
    70 HIG :: addSectionTitle( QLayout * l )
    71 {
    72     myGrid->addLayout( l, myRow, 0, 1, 2, Qt::AlignLeft|Qt::AlignVCenter );
    73     ++myRow;
     45HIG :: addSectionDivider ()
     46{
     47  QWidget * w = new QWidget (this);
     48  myGrid->addWidget (w, myRow, 0, 1, 2);
     49  ++myRow;
     50}
     51
     52void
     53HIG :: addSectionTitle (const QString& title)
     54{
     55  QLabel * label = new QLabel (this);
     56  label->setText (title);
     57  label->setStyleSheet ("font: bold");
     58  label->setAlignment (Qt::AlignLeft|Qt::AlignVCenter);
     59  addSectionTitle (label);
     60}
     61
     62void
     63HIG :: addSectionTitle (QWidget * w)
     64{
     65  myGrid->addWidget (w, myRow, 0, 1, 2, Qt::AlignLeft|Qt::AlignVCenter);
     66  ++myRow;
     67}
     68
     69void
     70HIG :: addSectionTitle (QLayout * l)
     71{
     72  myGrid->addLayout (l, myRow, 0, 1, 2, Qt::AlignLeft|Qt::AlignVCenter);
     73  ++myRow;
    7474}
    7575
    7676
    7777QLayout *
    78 HIG :: addRow( QWidget * w )
    79 {
    80     QHBoxLayout * h = new QHBoxLayout( );
    81     h->addSpacing( 18 );
    82     h->addWidget( w );
    83 
    84     QLabel * l;
    85     if( ( l = qobject_cast<QLabel*>(w) ) )
    86       l->setAlignment( Qt::AlignLeft );
    87 
    88     return h;
    89 }
    90 
    91 void
    92 HIG :: addWideControl( QLayout * l )
    93 {
    94     QHBoxLayout * h = new QHBoxLayout( );
    95     h->addSpacing( 18 );
    96     h->addLayout( l );
    97     myGrid->addLayout( h, myRow, 0, 1, 2, Qt::AlignLeft|Qt::AlignVCenter );
    98     ++myRow;
    99 }
    100 
    101 void
    102 HIG :: addWideControl( QWidget * w )
    103 {
    104     QHBoxLayout * h = new QHBoxLayout( );
    105     h->addSpacing( 18 );
    106     h->addWidget( w );
    107     myGrid->addLayout( h, myRow, 0, 1, 2, Qt::AlignLeft|Qt::AlignVCenter );
    108     ++myRow;
     78HIG :: addRow (QWidget * w)
     79{
     80  QHBoxLayout * h = new QHBoxLayout ();
     81  h->addSpacing (18);
     82  h->addWidget (w);
     83
     84  QLabel * l;
     85  if ((l = qobject_cast<QLabel*>(w)))
     86    l->setAlignment (Qt::AlignLeft);
     87
     88  return h;
     89}
     90
     91void
     92HIG :: addWideControl (QLayout * l)
     93{
     94  QHBoxLayout * h = new QHBoxLayout ();
     95  h->addSpacing (18);
     96  h->addLayout (l);
     97  myGrid->addLayout (h, myRow, 0, 1, 2, Qt::AlignLeft|Qt::AlignVCenter);
     98  ++myRow;
     99}
     100
     101void
     102HIG :: addWideControl (QWidget * w)
     103{
     104  QHBoxLayout * h = new QHBoxLayout ();
     105  h->addSpacing (18);
     106  h->addWidget (w);
     107  myGrid->addLayout (h, myRow, 0, 1, 2, Qt::AlignLeft|Qt::AlignVCenter);
     108  ++myRow;
    109109}
    110110
    111111QCheckBox*
    112 HIG :: addWideCheckBox( const QString& text, bool isChecked )
    113 {
    114     QCheckBox * check = new QCheckBox( text, this );
    115     check->setChecked( isChecked );
    116     addWideControl( check );
    117     return check;
    118 }
    119 
    120 void
    121 HIG :: addLabel( QWidget * w )
    122 {
    123     QHBoxLayout * h = new QHBoxLayout( );
    124     h->addSpacing( 18 );
    125     h->addWidget( w );
    126     myGrid->addLayout( h, myRow, 0, 1, 1, Qt::AlignLeft|Qt::AlignVCenter );
     112HIG :: addWideCheckBox (const QString& text, bool isChecked)
     113{
     114  QCheckBox * check = new QCheckBox (text, this);
     115  check->setChecked (isChecked);
     116  addWideControl (check);
     117  return check;
     118}
     119
     120void
     121HIG :: addLabel (QWidget * w)
     122{
     123  QHBoxLayout * h = new QHBoxLayout ();
     124  h->addSpacing (18);
     125  h->addWidget (w);
     126  myGrid->addLayout (h, myRow, 0, 1, 1, Qt::AlignLeft|Qt::AlignVCenter);
    127127}
    128128
    129129QLabel*
    130 HIG :: addLabel( const QString& text )
    131 {
    132     QLabel * label = new QLabel( text, this );
    133     addLabel( label );
    134     return label;
    135 }
    136 
    137 void
    138 HIG :: addTallLabel( QWidget * w )
    139 {
    140     QHBoxLayout * h = new QHBoxLayout( );
    141     h->addSpacing( 18 );
    142     h->addWidget( w );
    143     myGrid->addLayout( h, myRow, 0, 1, 1, Qt::AlignLeft|Qt::AlignTop );
     130HIG :: addLabel (const QString& text)
     131{
     132  QLabel * label = new QLabel (text, this);
     133  addLabel (label);
     134  return label;
     135}
     136
     137void
     138HIG :: addTallLabel (QWidget * w)
     139{
     140  QHBoxLayout * h = new QHBoxLayout ();
     141  h->addSpacing (18);
     142  h->addWidget (w);
     143  myGrid->addLayout (h, myRow, 0, 1, 1, Qt::AlignLeft|Qt::AlignTop);
    144144}
    145145
    146146QLabel*
    147 HIG :: addTallLabel( const QString& text )
    148 {
    149     QLabel * label = new QLabel( text, this );
    150     addTallLabel( label );
    151     return label;
    152 }
    153 
    154 void
    155 HIG :: addControl( QWidget * w )
    156 {
    157     myGrid->addWidget( w, myRow, 1, 1, 1 );
    158 }
    159 
    160 void
    161 HIG :: addControl( QLayout * l )
    162 {
    163     myGrid->addLayout( l, myRow, 1, 1, 1 );
     147HIG :: addTallLabel (const QString& text)
     148{
     149  QLabel * label = new QLabel (text, this);
     150  addTallLabel (label);
     151  return label;
     152}
     153
     154void
     155HIG :: addControl (QWidget * w)
     156{
     157  myGrid->addWidget (w, myRow, 1, 1, 1);
     158}
     159
     160void
     161HIG :: addControl (QLayout * l)
     162{
     163  myGrid->addLayout (l, myRow, 1, 1, 1);
    164164}
    165165
    166166QLabel *
    167 HIG :: addRow( const QString& text, QWidget * control, QWidget * buddy )
    168 {
    169     QLabel * label = addLabel( text );
    170     addControl( control );
    171     label->setBuddy( buddy ? buddy : control );
    172     ++myRow;
    173     return label;
     167HIG :: addRow (const QString& text, QWidget * control, QWidget * buddy)
     168{
     169  QLabel * label = addLabel (text);
     170  addControl (control);
     171  label->setBuddy (buddy ? buddy : control);
     172  ++myRow;
     173  return label;
    174174}
    175175
    176176QLabel *
    177 HIG :: addTallRow( const QString& text, QWidget * control, QWidget * buddy )
    178 {
    179     QLabel* label = addTallLabel( text );
    180     label->setBuddy( buddy ? buddy : control );
    181     addControl( control );
    182     myHasTall = true;
    183     myGrid->setRowStretch ( myRow, 1 );
    184     ++myRow;
    185     return label;
     177HIG :: addTallRow (const QString& text, QWidget * control, QWidget * buddy)
     178{
     179  QLabel* label = addTallLabel (text);
     180  label->setBuddy (buddy ? buddy : control);
     181  addControl (control);
     182  myHasTall = true;
     183  myGrid->setRowStretch  (myRow, 1);
     184  ++myRow;
     185  return label;
    186186}
    187187
    188188QLabel *
    189 HIG :: addRow( const QString& text, QLayout * control, QWidget * buddy )
    190 {
    191     QLabel * label = addLabel( text );
    192     addControl( control );
    193     if( buddy != 0 )
    194         label->setBuddy( buddy );
    195     ++myRow;
    196     return label;
    197 }
    198 
    199 void
    200 HIG :: addRow( QWidget * label, QWidget * control, QWidget * buddy )
    201 {
    202     addLabel( label );
    203     if( control ) {
    204         addControl( control );
    205         QLabel * l = qobject_cast<QLabel*>( label );
    206         if( l != 0 )
    207             l->setBuddy( buddy ? buddy : control );
     189HIG :: addRow (const QString& text, QLayout * control, QWidget * buddy)
     190{
     191  QLabel * label = addLabel (text);
     192  addControl (control);
     193  if (buddy != 0)
     194    label->setBuddy (buddy);
     195  ++myRow;
     196  return label;
     197}
     198
     199void
     200HIG :: addRow (QWidget * label, QWidget * control, QWidget * buddy)
     201{
     202  addLabel (label);
     203
     204  if (control)
     205    {
     206      addControl (control);
     207
     208      QLabel * l = qobject_cast<QLabel*> (label);
     209      if (l != 0)
     210        l->setBuddy (buddy ? buddy : control);
    208211    }
    209     ++myRow;
    210 }
    211 
    212 void
    213 HIG :: addRow( QWidget * label, QLayout * control, QWidget * buddy )
    214 {
    215     addLabel( label );
    216     if( control ) {
    217         addControl( control );
    218         QLabel * l = qobject_cast<QLabel*>( label );
    219         if( l != 0 && buddy != 0 )
    220             l->setBuddy( buddy );
     212
     213  ++myRow;
     214}
     215
     216void
     217HIG :: addRow (QWidget * label, QLayout * control, QWidget * buddy)
     218{
     219  addLabel (label);
     220
     221  if (control)
     222    {
     223      addControl (control);
     224
     225      QLabel * l = qobject_cast<QLabel*> (label);
     226      if (l != 0 && buddy != 0)
     227        l->setBuddy (buddy);
    221228    }
    222     ++myRow;
    223 }
    224 
    225 void
    226 HIG :: finish( )
    227 {
    228     if( !myHasTall ) {
    229         QWidget * w = new QWidget( this );
    230         myGrid->addWidget( w, myRow, 0, 1, 2 );
    231         myGrid->setRowStretch( myRow, 100 );
    232         ++myRow;
     229
     230  ++myRow;
     231}
     232
     233void
     234HIG :: finish ()
     235{
     236  if (!myHasTall)
     237    {
     238      QWidget * w = new QWidget (this);
     239      myGrid->addWidget (w, myRow, 0, 1, 2);
     240      myGrid->setRowStretch (myRow, 100);
     241      ++myRow;
    233242    }
    234243}
  • trunk/qt/hig.h

    r11092 r14204  
    2424class HIG: public QWidget
    2525{
    26         Q_OBJECT
     26    Q_OBJECT
    2727
    28     public:
    29         enum {
    30             PAD_SMALL = 3,
    31             PAD = 6,
    32             PAD_BIG = 12,
    33             PAD_LARGE = PAD_BIG
    34         };
     28  public:
    3529
    36     public:
    37         HIG( QWidget * parent = 0 );
    38         virtual ~HIG( );
     30    enum
     31    {
     32      PAD_SMALL = 3,
     33      PAD = 6,
     34      PAD_BIG = 12,
     35      PAD_LARGE = PAD_BIG
     36    };
    3937
    40     public:
    41         void addSectionDivider( );
    42         void addSectionTitle( const QString& );
    43         void addSectionTitle( QWidget* );
    44         void addSectionTitle( QLayout* );
    45         void addWideControl( QLayout * );
    46         void addWideControl( QWidget * );
    47         QCheckBox* addWideCheckBox( const QString&, bool isChecked );
    48         QLabel* addLabel( const QString& );
    49         QLabel* addTallLabel( const QString& );
    50         void addLabel( QWidget * );
    51         void addTallLabel( QWidget * );
    52         void addControl( QWidget * );
    53         void addControl( QLayout * );
    54         QLabel* addRow( const QString & label, QWidget * control, QWidget * buddy=0 );
    55         QLabel* addRow( const QString & label, QLayout * control, QWidget * buddy );
    56         void addRow( QWidget * label, QWidget * control, QWidget * buddy=0 );
    57         void addRow( QWidget * label, QLayout * control, QWidget * buddy );
    58         QLabel* addTallRow( const QString & label, QWidget * control, QWidget * buddy=0 );
    59         void finish( );
     38  public:
    6039
    61     private:
    62         QLayout* addRow( QWidget* w );
     40    HIG (QWidget * parent = 0);
     41    virtual ~HIG ();
    6342
    64     private:
    65         int myRow;
    66         bool myHasTall;
    67         QGridLayout * myGrid;
     43  public:
     44
     45    void addSectionDivider ();
     46    void addSectionTitle (const QString&);
     47    void addSectionTitle (QWidget*);
     48    void addSectionTitle (QLayout*);
     49    void addWideControl (QLayout *);
     50    void addWideControl (QWidget *);
     51    QCheckBox* addWideCheckBox (const QString&, bool isChecked);
     52    QLabel* addLabel (const QString&);
     53    QLabel* addTallLabel (const QString&);
     54    void addLabel (QWidget *);
     55    void addTallLabel (QWidget *);
     56    void addControl (QWidget *);
     57    void addControl (QLayout *);
     58    QLabel* addRow (const QString & label, QWidget * control, QWidget * buddy=0);
     59    QLabel* addRow (const QString & label, QLayout * control, QWidget * buddy);
     60    void addRow (QWidget * label, QWidget * control, QWidget * buddy=0);
     61    void addRow (QWidget * label, QLayout * control, QWidget * buddy);
     62    QLabel* addTallRow (const QString & label, QWidget * control, QWidget * buddy=0);
     63    void finish ();
     64
     65  private:
     66    QLayout* addRow (QWidget* w);
     67
     68  private:
     69    int myRow;
     70    bool myHasTall;
     71    QGridLayout * myGrid;
    6872};
    6973
  • trunk/qt/make-dialog.cc

    r14200 r14204  
    4747
    4848void
    49 MakeDialog :: onNewDialogDestroyed( QObject * o )
    50 {
    51     Q_UNUSED( o );
    52 
    53     myTimer.stop( );
    54 }
    55 
    56 void
    57 MakeDialog :: onNewButtonBoxClicked( QAbstractButton * button )
    58 {
    59     switch( myNewButtonBox->standardButton( button ) )
    60     {
    61         case QDialogButtonBox::Open:
    62             mySession.addNewlyCreatedTorrent( myTarget, QFileInfo(QString::fromUtf8(myBuilder->top)).dir().path() );
    63             break;
    64         case QDialogButtonBox::Abort:
    65             myBuilder->abortFlag = true;
    66             break;
    67         default: // QDialogButtonBox::Ok:
    68             break;
    69 
    70     }
    71     myNewDialog->deleteLater( );
    72 }
    73 
    74 void
    75 MakeDialog :: onProgress( )
    76 {
    77     // progress bar
    78     const tr_metainfo_builder * b = myBuilder;
    79     const double denom = b->pieceCount ? b->pieceCount : 1;
    80     myNewProgress->setValue( (int) ((100.0 * b->pieceIndex) / denom ) );
    81 
    82     // progress label
    83     const QString top = QString::fromLocal8Bit( myBuilder->top );
    84     const QString base( QFileInfo(top).completeBaseName() );
    85     QString str;
    86     if( !b->isDone )
    87         str = tr( "Creating \"%1\"" ).arg( base );
    88     else if( b->result == TR_MAKEMETA_OK )
    89         str = tr( "Created \"%1\"!" ).arg( base );
    90     else if( b->result == TR_MAKEMETA_URL )
    91         str = tr( "Error: invalid announce URL \"%1\"" ).arg( QString::fromLocal8Bit( b->errfile ) );
    92     else if( b->result == TR_MAKEMETA_CANCELLED )
    93         str = tr( "Cancelled" );
    94     else if( b->result == TR_MAKEMETA_IO_READ )
    95         str = tr( "Error reading \"%1\": %2" ).arg( QString::fromLocal8Bit(b->errfile) ).arg( QString::fromLocal8Bit(strerror(b->my_errno)) );
    96     else if( b->result == TR_MAKEMETA_IO_WRITE )
    97         str = tr( "Error writing \"%1\": %2" ).arg( QString::fromLocal8Bit(b->errfile) ).arg( QString::fromLocal8Bit(strerror(b->my_errno)) );
    98     myNewLabel->setText( str );
    99 
    100     // buttons
    101     (myNewButtonBox->button(QDialogButtonBox::Abort))->setEnabled( !b->isDone );
    102     (myNewButtonBox->button(QDialogButtonBox::Ok))->setEnabled( b->isDone );
    103     (myNewButtonBox->button(QDialogButtonBox::Open))->setEnabled( b->isDone && !b->result );
    104 }
    105 
    106 
    107 void
    108 MakeDialog :: makeTorrent( )
    109 {
    110     if( !myBuilder )
    111         return;
    112 
    113     // get the tiers
    114     int tier = 0;
    115     QVector<tr_tracker_info> trackers;
    116     foreach( QString line, myTrackerEdit->toPlainText().split("\n") ) {
    117         line = line.trimmed( );
    118         if( line.isEmpty( ) )
    119             ++tier;
    120         else {
    121             tr_tracker_info tmp;
    122             tmp.announce = tr_strdup( line.toUtf8().constData( ) );
    123             tmp.tier = tier;
    124             trackers.append( tmp );
     49MakeDialog :: onNewDialogDestroyed (QObject * o)
     50{
     51  Q_UNUSED (o);
     52
     53  myTimer.stop ();
     54}
     55
     56void
     57MakeDialog :: onNewButtonBoxClicked (QAbstractButton * button)
     58{
     59  switch (myNewButtonBox->standardButton (button))
     60    {
     61      case QDialogButtonBox::Open:
     62        mySession.addNewlyCreatedTorrent (myTarget, QFileInfo(QString::fromUtf8(myBuilder->top)).dir().path());
     63        break;
     64
     65      case QDialogButtonBox::Abort:
     66        myBuilder->abortFlag = true;
     67        break;
     68
     69      default: // QDialogButtonBox::Ok:
     70        break;
     71    }
     72
     73  myNewDialog->deleteLater ();
     74}
     75
     76void
     77MakeDialog :: onProgress ()
     78{
     79  // progress bar
     80  const tr_metainfo_builder * b = myBuilder;
     81  const double denom = b->pieceCount ? b->pieceCount : 1;
     82  myNewProgress->setValue ((int) ((100.0 * b->pieceIndex) / denom));
     83
     84  // progress label
     85  const QString top = QString::fromLocal8Bit (myBuilder->top);
     86  const QString base (QFileInfo(top).completeBaseName());
     87  QString str;
     88  if (!b->isDone)
     89    str = tr ("Creating \"%1\"").arg (base);
     90  else if (b->result == TR_MAKEMETA_OK)
     91    str = tr ("Created \"%1\"!").arg (base);
     92  else if (b->result == TR_MAKEMETA_URL)
     93    str = tr ("Error: invalid announce URL \"%1\"").arg (QString::fromLocal8Bit (b->errfile));
     94  else if (b->result == TR_MAKEMETA_CANCELLED)
     95    str = tr ("Cancelled");
     96  else if (b->result == TR_MAKEMETA_IO_READ)
     97    str = tr ("Error reading \"%1\": %2").arg (QString::fromLocal8Bit(b->errfile)).arg (QString::fromLocal8Bit(strerror(b->my_errno)));
     98  else if (b->result == TR_MAKEMETA_IO_WRITE)
     99    str = tr ("Error writing \"%1\": %2").arg (QString::fromLocal8Bit(b->errfile)).arg (QString::fromLocal8Bit(strerror(b->my_errno)));
     100  myNewLabel->setText (str);
     101
     102  // buttons
     103  (myNewButtonBox->button(QDialogButtonBox::Abort))->setEnabled (!b->isDone);
     104  (myNewButtonBox->button(QDialogButtonBox::Ok))->setEnabled (b->isDone);
     105  (myNewButtonBox->button(QDialogButtonBox::Open))->setEnabled (b->isDone && !b->result);
     106}
     107
     108
     109void
     110MakeDialog :: makeTorrent ()
     111{
     112  if (!myBuilder)
     113    return;
     114
     115  // get the tiers
     116  int tier = 0;
     117  QVector<tr_tracker_info> trackers;
     118  foreach (QString line, myTrackerEdit->toPlainText().split("\n"))
     119    {
     120      line = line.trimmed ();
     121      if (line.isEmpty ())
     122        {
     123          ++tier;
    125124        }
    126     }
    127 
    128     // pop up the dialog
    129     QDialog * dialog = new QDialog( this );
    130     dialog->setWindowTitle( tr( "New Torrent" ) );
    131     myNewDialog = dialog;
    132     QVBoxLayout * top = new QVBoxLayout( dialog );
    133     top->addWidget(( myNewLabel = new QLabel));
    134     top->addWidget(( myNewProgress = new QProgressBar ));
    135     QDialogButtonBox * buttons = new QDialogButtonBox( QDialogButtonBox::Ok
    136                                                      | QDialogButtonBox::Open
    137                                                      | QDialogButtonBox::Abort );
    138     myNewButtonBox = buttons;
    139     connect( buttons, SIGNAL(clicked(QAbstractButton*)),
    140              this, SLOT(onNewButtonBoxClicked(QAbstractButton*)) );
    141     top->addWidget( buttons );
    142     onProgress( );
    143     dialog->show( );
    144     connect( dialog, SIGNAL(destroyed(QObject*)),
    145              this, SLOT(onNewDialogDestroyed(QObject*)) );
    146     myTimer.start( 100 );
    147 
    148     // the file to create
    149     const QString path = QString::fromUtf8( myBuilder->top );
    150     const QString torrentName = QFileInfo(path).completeBaseName() + ".torrent";
    151     myTarget = QDir( myDestination ).filePath( torrentName );
    152 
    153     // comment
    154     QString comment;
    155     if( myCommentCheck->isChecked() )
    156         comment = myCommentEdit->text();
    157 
    158     // start making the torrent
    159     tr_makeMetaInfo( myBuilder,
    160                      myTarget.toUtf8().constData(),
    161                      (trackers.isEmpty() ? NULL : trackers.data()),
    162                      trackers.size(),
    163                      (comment.isEmpty() ? NULL : comment.toUtf8().constData()),
    164                      myPrivateCheck->isChecked() );
     125      else
     126        {
     127          tr_tracker_info tmp;
     128          tmp.announce = tr_strdup (line.toUtf8().constData ());
     129          tmp.tier = tier;
     130          trackers.append (tmp);
     131        }
     132    }
     133
     134  // pop up the dialog
     135  QDialog * dialog = new QDialog (this);
     136  dialog->setWindowTitle (tr ("New Torrent"));
     137  myNewDialog = dialog;
     138  QVBoxLayout * top = new QVBoxLayout (dialog);
     139  top->addWidget( (myNewLabel = new QLabel));
     140  top->addWidget( (myNewProgress = new QProgressBar));
     141  QDialogButtonBox * buttons = new QDialogButtonBox (QDialogButtonBox::Ok
     142                                                   | QDialogButtonBox::Open
     143                                                   | QDialogButtonBox::Abort);
     144  myNewButtonBox = buttons;
     145  connect (buttons, SIGNAL(clicked(QAbstractButton*)),
     146           this, SLOT(onNewButtonBoxClicked(QAbstractButton*)));
     147  top->addWidget (buttons);
     148  onProgress ();
     149  dialog->show ();
     150  connect (dialog, SIGNAL(destroyed(QObject*)),
     151           this, SLOT(onNewDialogDestroyed(QObject*)));
     152  myTimer.start (100);
     153
     154  // the file to create
     155  const QString path = QString::fromUtf8 (myBuilder->top);
     156  const QString torrentName = QFileInfo(path).completeBaseName() + ".torrent";
     157  myTarget = QDir (myDestination).filePath (torrentName);
     158
     159  // comment
     160  QString comment;
     161  if (myCommentCheck->isChecked())
     162    comment = myCommentEdit->text();
     163
     164  // start making the torrent
     165  tr_makeMetaInfo (myBuilder,
     166                   myTarget.toUtf8().constData(),
     167                   (trackers.isEmpty() ? NULL : trackers.data()),
     168                   trackers.size(),
     169                   (comment.isEmpty() ? NULL : comment.toUtf8().constData()),
     170                   myPrivateCheck->isChecked());
    165171}
    166172
     
    170176
    171177void
    172 MakeDialog :: onFileClicked( )
    173 {
    174     QFileDialog * d = new QFileDialog( this, tr( "Select File" ) );
    175     d->setFileMode( QFileDialog::ExistingFile );
    176     d->setAttribute( Qt::WA_DeleteOnClose );
    177     connect( d, SIGNAL(filesSelected(const QStringList&)),
    178              this, SLOT(onFileSelected(const QStringList&)) );
    179     d->show( );
    180 }
    181 void
    182 MakeDialog :: onFileSelected( const QStringList& list )
    183 {
    184     if( !list.empty( ) )
    185         onFileSelected( list.front( ) );
    186 }
    187 void
    188 MakeDialog :: onFileSelected( const QString& filename )
    189 {
    190     myFile = Utils::removeTrailingDirSeparator (filename);
    191     myFileButton->setText( QFileInfo(myFile).fileName() );
    192     onSourceChanged( );
    193 }
    194 
    195 void
    196 MakeDialog :: onFolderClicked( )
    197 {
    198     QFileDialog * d = new QFileDialog( this, tr( "Select Folder" ) );
    199     d->setFileMode( QFileDialog::Directory );
    200     d->setOption( QFileDialog::ShowDirsOnly );
    201     d->setAttribute( Qt::WA_DeleteOnClose );
    202     connect( d, SIGNAL(filesSelected(const QStringList&)),
    203              this, SLOT(onFolderSelected(const QStringList&)) );
    204     d->show( );
    205 }
    206 void
    207 MakeDialog :: onFolderSelected( const QStringList& list )
    208 {
    209     if( !list.empty( ) )
    210         onFolderSelected( list.front( ) );
    211 }
    212 void
    213 MakeDialog :: onFolderSelected( const QString& filename )
    214 {
    215     myFolder = Utils::removeTrailingDirSeparator (filename);
    216     myFolderButton->setText( QFileInfo(myFolder).fileName() );
    217     onSourceChanged( );
    218 }
    219 
    220 void
    221 MakeDialog :: onDestinationClicked( )
    222 {
    223     QFileDialog * d = new QFileDialog( this, tr( "Select Folder" ) );
    224     d->setFileMode( QFileDialog::Directory );
    225     d->setOption( QFileDialog::ShowDirsOnly );
    226     d->setAttribute( Qt::WA_DeleteOnClose );
    227     connect( d, SIGNAL(filesSelected(const QStringList&)),
    228              this, SLOT(onDestinationSelected(const QStringList&)) );
    229     d->show( );
    230 }
    231 void
    232 MakeDialog :: onDestinationSelected( const QStringList& list )
    233 {
    234     if( !list.empty( ) )
    235         onDestinationSelected( list.front() );
    236 }
    237 void
    238 MakeDialog :: onDestinationSelected( const QString& filename )
    239 {
    240     myDestination = Utils::removeTrailingDirSeparator (filename);
    241     myDestinationButton->setText( QFileInfo(myDestination).fileName() );
    242 }
    243 
    244 void
    245 MakeDialog :: enableBuddyWhenChecked( QRadioButton * box, QWidget * buddy )
    246 {
    247     connect( box, SIGNAL(toggled(bool)), buddy, SLOT(setEnabled(bool)) );
    248     buddy->setEnabled( box->isChecked( ) );
    249 }
    250 void
    251 MakeDialog :: enableBuddyWhenChecked( QCheckBox * box, QWidget * buddy )
    252 {
    253     connect( box, SIGNAL(toggled(bool)), buddy, SLOT(setEnabled(bool)) );
    254     buddy->setEnabled( box->isChecked( ) );
     178MakeDialog :: onFileClicked ()
     179{
     180  QFileDialog * d = new QFileDialog (this, tr ("Select File"));
     181  d->setFileMode (QFileDialog::ExistingFile);
     182  d->setAttribute (Qt::WA_DeleteOnClose);
     183  connect (d, SIGNAL(filesSelected(const QStringList&)),
     184           this, SLOT(onFileSelected(const QStringList&)));
     185  d->show ();
     186}
     187void
     188MakeDialog :: onFileSelected (const QStringList& list)
     189{
     190  if (!list.empty ())
     191    onFileSelected (list.front ());
     192}
     193void
     194MakeDialog :: onFileSelected (const QString& filename)
     195{
     196  myFile = Utils::removeTrailingDirSeparator (filename);
     197  myFileButton->setText (QFileInfo(myFile).fileName());
     198  onSourceChanged ();
     199}
     200
     201void
     202MakeDialog :: onFolderClicked ()
     203{
     204  QFileDialog * d = new QFileDialog (this, tr ("Select Folder"));
     205  d->setFileMode (QFileDialog::Directory);
     206  d->setOption (QFileDialog::ShowDirsOnly);
     207  d->setAttribute (Qt::WA_DeleteOnClose);
     208  connect (d, SIGNAL(filesSelected(const QStringList&)),
     209           this, SLOT(onFolderSelected(const QStringList&)));
     210  d->show ();
     211}
     212
     213void
     214MakeDialog :: onFolderSelected (const QStringList& list)
     215{
     216  if (!list.empty ())
     217    onFolderSelected (list.front ());
     218}
     219
     220void
     221MakeDialog :: onFolderSelected (const QString& filename)
     222{
     223  myFolder = Utils::removeTrailingDirSeparator (filename);
     224  myFolderButton->setText (QFileInfo(myFolder).fileName());
     225  onSourceChanged ();
     226}
     227
     228void
     229MakeDialog :: onDestinationClicked ()
     230{
     231  QFileDialog * d = new QFileDialog (this, tr ("Select Folder"));
     232  d->setFileMode (QFileDialog::Directory);
     233  d->setOption (QFileDialog::ShowDirsOnly);
     234  d->setAttribute (Qt::WA_DeleteOnClose);
     235  connect (d, SIGNAL(filesSelected(const QStringList&)),
     236           this, SLOT(onDestinationSelected(const QStringList&)));
     237  d->show ();
     238}
     239void
     240MakeDialog :: onDestinationSelected (const QStringList& list)
     241{
     242  if (!list.empty ())
     243    onDestinationSelected (list.front());
     244}
     245void
     246MakeDialog :: onDestinationSelected (const QString& filename)
     247{
     248  myDestination = Utils::removeTrailingDirSeparator (filename);
     249  myDestinationButton->setText (QFileInfo(myDestination).fileName());
     250}
     251
     252void
     253MakeDialog :: enableBuddyWhenChecked (QRadioButton * box, QWidget * buddy)
     254{
     255  connect (box, SIGNAL(toggled(bool)), buddy, SLOT(setEnabled(bool)));
     256  buddy->setEnabled (box->isChecked ());
     257}
     258void
     259MakeDialog :: enableBuddyWhenChecked (QCheckBox * box, QWidget * buddy)
     260{
     261  connect (box, SIGNAL(toggled(bool)), buddy, SLOT(setEnabled(bool)));
     262  buddy->setEnabled (box->isChecked ());
    255263}
    256264
    257265QString
    258 MakeDialog :: getSource( ) const
    259 {
    260     return myFileRadio->isChecked( ) ? myFile : myFolder;
    261 }
    262 
    263 void
    264 MakeDialog :: onButtonBoxClicked( QAbstractButton * button )
    265 {
    266     switch( myButtonBox->standardButton( button ) )
    267     {
    268         case QDialogButtonBox::Ok:
    269             makeTorrent( );
    270             break;
    271 
    272         default: // QDialogButtonBox::Close:
    273             deleteLater( );
    274             break;
     266MakeDialog :: getSource () const
     267{
     268  return myFileRadio->isChecked () ? myFile : myFolder;
     269}
     270
     271void
     272MakeDialog :: onButtonBoxClicked (QAbstractButton * button)
     273{
     274  switch (myButtonBox->standardButton (button))
     275    {
     276      case QDialogButtonBox::Ok:
     277        makeTorrent ();
     278        break;
     279
     280      default: // QDialogButtonBox::Close:
     281        deleteLater ();
     282        break;
    275283    }
    276284}
     
    281289
    282290void
    283 MakeDialog :: onSourceChanged( )
    284 {
    285     if( myBuilder )
    286     {
    287         tr_metaInfoBuilderFree( myBuilder );
    288         myBuilder = 0;
    289     }
    290 
    291     const QString filename = getSource( );
    292     if( !filename.isEmpty( ) )
    293         myBuilder = tr_metaInfoBuilderCreate( filename.toUtf8().constData() );
    294 
    295     QString text;
    296     if( !myBuilder )
    297         text = tr( "<i>No source selected<i>" );
    298     else {
    299         QString files = tr( "%Ln File(s)", 0, myBuilder->fileCount );
    300         QString pieces = tr( "%Ln Piece(s)", 0, myBuilder->pieceCount );
    301         text = tr( "%1 in %2; %3 @ %4" )
    302                  .arg( Formatter::sizeToString( myBuilder->totalSize ) )
    303                  .arg( files )
    304                  .arg( pieces )
    305                  .arg( Formatter::sizeToString( myBuilder->pieceSize ) );
    306     }
    307 
    308     mySourceLabel->setText( text );
     291MakeDialog :: onSourceChanged ()
     292{
     293  if (myBuilder)
     294    {
     295      tr_metaInfoBuilderFree (myBuilder);
     296      myBuilder = 0;
     297    }
     298
     299  const QString filename = getSource ();
     300  if (!filename.isEmpty ())
     301    myBuilder = tr_metaInfoBuilderCreate (filename.toUtf8().constData());
     302
     303  QString text;
     304  if (!myBuilder)
     305    {
     306      text = tr ("<i>No source selected<i>");
     307    }
     308  else
     309    {
     310      QString files = tr ("%Ln File(s)", 0, myBuilder->fileCount);
     311      QString pieces = tr ("%Ln Piece(s)", 0, myBuilder->pieceCount);
     312      text = tr ("%1 in %2; %3 @ %4")
     313               .arg (Formatter::sizeToString (myBuilder->totalSize))
     314               .arg (files)
     315               .arg (pieces)
     316               .arg (Formatter::sizeToString (myBuilder->pieceSize));
     317    }
     318
     319  mySourceLabel->setText (text);
    309320}
    310321
     
    312323// bah, there doesn't seem to be any cleaner way to override
    313324// QPlainTextEdit's default desire to be 12 lines tall
    314 class ShortPlainTextEdit: public QPlainTextEdit {
    315     public:
    316         virtual ~ShortPlainTextEdit( ) { }
    317         ShortPlainTextEdit( QWidget * parent = 0 ): QPlainTextEdit(parent) { }
    318         virtual QSize sizeHint ( ) const { return QSize( 256, 50 ); }
     325class ShortPlainTextEdit: public QPlainTextEdit
     326{
     327  public:
     328    virtual ~ShortPlainTextEdit () {}
     329    ShortPlainTextEdit (QWidget * parent = 0): QPlainTextEdit(parent) {}
     330    virtual QSize sizeHint  () const { return QSize (256, 50); }
    319331};
    320332
    321 MakeDialog :: MakeDialog( Session & session, QWidget * parent ):
    322     QDialog( parent, Qt::Dialog ),
    323     mySession( session ),
    324     myBuilder( 0 )
    325 {
    326     setAcceptDrops( true );
    327 
    328     connect( &myTimer, SIGNAL(timeout()), this, SLOT(onProgress()) );
    329 
    330     setWindowTitle( tr( "New Torrent" ) );
    331     QVBoxLayout * top = new QVBoxLayout( this );
    332     top->setSpacing( HIG :: PAD );
    333 
    334     HIG * hig = new HIG;
    335     hig->setContentsMargins( 0, 0, 0, 0 );
    336     hig->addSectionTitle( tr( "Files" ) );
    337 
    338         QFileIconProvider iconProvider;
    339         const int iconSize( style()->pixelMetric( QStyle::PM_SmallIconSize ) );
    340         const QIcon folderIcon = iconProvider.icon( QFileIconProvider::Folder );
    341         const QPixmap folderPixmap = folderIcon.pixmap( iconSize );
    342         QPushButton * b = new QPushButton;
    343         b->setIcon( folderPixmap );
    344         b->setStyleSheet( QString::fromUtf8( "text-align: left; padding-left: 5; padding-right: 5" ) );
    345         myDestination = QDir::homePath();
    346         b->setText( myDestination );
    347         connect( b, SIGNAL(clicked(bool)),
    348                  this, SLOT(onDestinationClicked(void)) );
    349         myDestinationButton = b;
    350         hig->addRow( tr( "Sa&ve to:" ), b );
    351 
    352         myFolderRadio = new QRadioButton( tr( "Source F&older:" ) );
    353         connect( myFolderRadio, SIGNAL(toggled(bool)),
    354                  this, SLOT(onSourceChanged()) );
    355         myFolderButton = new QPushButton;
    356         myFolderButton->setIcon( folderPixmap );
    357         myFolderButton->setText( tr( "(None)" ) );
    358         myFolderButton->setStyleSheet( QString::fromUtf8( "text-align: left; padding-left: 5; padding-right: 5" ) );
    359         connect( myFolderButton, SIGNAL(clicked(bool)),
    360                  this, SLOT(onFolderClicked(void)) );
    361         hig->addRow( myFolderRadio, myFolderButton );
    362         enableBuddyWhenChecked( myFolderRadio, myFolderButton );
    363 
    364         const QIcon fileIcon = iconProvider.icon( QFileIconProvider::File );
    365         const QPixmap filePixmap = fileIcon.pixmap( iconSize );
    366         myFileRadio = new QRadioButton( tr( "Source &File:" ) );
    367         myFileRadio->setChecked( true );
    368         connect( myFileRadio, SIGNAL(toggled(bool)),
    369                  this, SLOT(onSourceChanged()) );
    370         myFileButton = new QPushButton;
    371         myFileButton->setText( tr( "(None)" ) );
    372         myFileButton->setIcon( filePixmap );
    373         myFileButton->setStyleSheet( QString::fromUtf8( "text-align: left; padding-left: 5; padding-right: 5" ) );
    374         connect( myFileButton, SIGNAL(clicked(bool)),
    375                  this, SLOT(onFileClicked(void)) );
    376         hig->addRow( myFileRadio, myFileButton );
    377         enableBuddyWhenChecked( myFileRadio, myFileButton );
    378 
    379         mySourceLabel = new QLabel( this );
    380         hig->addRow( tr( "" ), mySourceLabel );
    381 
    382     hig->addSectionDivider( );
    383     hig->addSectionTitle( tr( "Properties" ) );
    384 
    385         hig->addWideControl( myTrackerEdit = new ShortPlainTextEdit );
    386         const int height = fontMetrics().size( 0, QString::fromUtf8("\n\n\n\n") ).height( );
    387         myTrackerEdit->setMinimumHeight( height );
    388         hig->addTallRow( tr( "&Trackers:" ), myTrackerEdit );
    389         QLabel * l = new QLabel( tr( "To add a backup URL, add it on the line after the primary URL.\nTo add another primary URL, add it after a blank line." ) );
    390         l->setAlignment( Qt::AlignLeft );
    391         hig->addRow( tr( "" ), l );
    392         myTrackerEdit->resize( 500, height );
    393 
    394         myCommentCheck = new QCheckBox( tr( "Co&mment" ) );
    395         myCommentEdit = new QLineEdit( );
    396         hig->addRow( myCommentCheck, myCommentEdit );
    397         enableBuddyWhenChecked( myCommentCheck, myCommentEdit );
    398 
    399         myPrivateCheck = hig->addWideCheckBox( tr( "&Private torrent" ), false );
    400 
    401     hig->finish( );
    402     top->addWidget( hig, 1 );
    403 
    404     myButtonBox = new QDialogButtonBox( QDialogButtonBox::Ok
    405                                       | QDialogButtonBox::Close );
    406     connect( myButtonBox, SIGNAL(clicked(QAbstractButton*)),
    407              this, SLOT(onButtonBoxClicked(QAbstractButton*)) );
    408 
    409     top->addWidget( myButtonBox );
    410     onSourceChanged( );
    411 }
    412 
    413 MakeDialog :: ~MakeDialog( )
    414 {
    415     if( myBuilder )
    416         tr_metaInfoBuilderFree( myBuilder );
     333MakeDialog :: MakeDialog (Session & session, QWidget * parent):
     334  QDialog (parent, Qt::Dialog),
     335  mySession (session),
     336  myBuilder (0)
     337{
     338  setAcceptDrops (true);
     339
     340  connect (&myTimer, SIGNAL(timeout()), this, SLOT(onProgress()));
     341
     342  setWindowTitle (tr ("New Torrent"));
     343  QVBoxLayout * top = new QVBoxLayout (this);
     344  top->setSpacing (HIG :: PAD);
     345
     346  HIG * hig = new HIG;
     347  hig->setContentsMargins (0, 0, 0, 0);
     348  hig->addSectionTitle (tr ("Files"));
     349
     350    QFileIconProvider iconProvider;
     351    const int iconSize (style()->pixelMetric (QStyle::PM_SmallIconSize));
     352    const QIcon folderIcon = iconProvider.icon (QFileIconProvider::Folder);
     353    const QPixmap folderPixmap = folderIcon.pixmap (iconSize);
     354    QPushButton * b = new QPushButton;
     355    b->setIcon (folderPixmap);
     356    b->setStyleSheet (QString::fromUtf8 ("text-align: left; padding-left: 5; padding-right: 5"));
     357    myDestination = QDir::homePath();
     358    b->setText (myDestination);
     359    connect (b, SIGNAL(clicked(bool)),
     360             this, SLOT(onDestinationClicked(void)));
     361    myDestinationButton = b;
     362    hig->addRow (tr ("Sa&ve to:"), b);
     363
     364    myFolderRadio = new QRadioButton (tr ("Source F&older:"));
     365    connect (myFolderRadio, SIGNAL(toggled(bool)),
     366             this, SLOT(onSourceChanged()));
     367    myFolderButton = new QPushButton;
     368    myFolderButton->setIcon (folderPixmap);
     369    myFolderButton->setText (tr ("(None)"));
     370    myFolderButton->setStyleSheet (QString::fromUtf8 ("text-align: left; padding-left: 5; padding-right: 5"));
     371    connect (myFolderButton, SIGNAL(clicked(bool)),
     372             this, SLOT(onFolderClicked(void)));
     373    hig->addRow (myFolderRadio, myFolderButton);
     374    enableBuddyWhenChecked (myFolderRadio, myFolderButton);
     375
     376    const QIcon fileIcon = iconProvider.icon (QFileIconProvider::File);
     377    const QPixmap filePixmap = fileIcon.pixmap (iconSize);
     378    myFileRadio = new QRadioButton (tr ("Source &File:"));
     379    myFileRadio->setChecked (true);
     380    connect (myFileRadio, SIGNAL(toggled(bool)),
     381             this, SLOT(onSourceChanged()));
     382    myFileButton = new QPushButton;
     383    myFileButton->setText (tr ("(None)"));
     384    myFileButton->setIcon (filePixmap);
     385    myFileButton->setStyleSheet (QString::fromUtf8 ("text-align: left; padding-left: 5; padding-right: 5"));
     386    connect (myFileButton, SIGNAL(clicked(bool)),
     387             this, SLOT(onFileClicked(void)));
     388    hig->addRow (myFileRadio, myFileButton);
     389    enableBuddyWhenChecked (myFileRadio, myFileButton);
     390
     391    mySourceLabel = new QLabel (this);
     392    hig->addRow (tr (""), mySourceLabel);
     393
     394  hig->addSectionDivider ();
     395  hig->addSectionTitle (tr ("Properties"));
     396
     397    hig->addWideControl (myTrackerEdit = new ShortPlainTextEdit);
     398    const int height = fontMetrics().size (0, QString::fromUtf8("\n\n\n\n")).height ();
     399    myTrackerEdit->setMinimumHeight (height);
     400    hig->addTallRow (tr ("&Trackers:"), myTrackerEdit);
     401    QLabel * l = new QLabel (tr ("To add a backup URL, add it on the line after the primary URL.\nTo add another primary URL, add it after a blank line."));
     402    l->setAlignment (Qt::AlignLeft);
     403    hig->addRow (tr (""), l);
     404    myTrackerEdit->resize (500, height);
     405
     406    myCommentCheck = new QCheckBox (tr ("Co&mment"));
     407    myCommentEdit = new QLineEdit ();
     408    hig->addRow (myCommentCheck, myCommentEdit);
     409    enableBuddyWhenChecked (myCommentCheck, myCommentEdit);
     410
     411    myPrivateCheck = hig->addWideCheckBox (tr ("&Private torrent"), false);
     412
     413  hig->finish ();
     414  top->addWidget (hig, 1);
     415
     416  myButtonBox = new QDialogButtonBox (QDialogButtonBox::Ok
     417                                    | QDialogButtonBox::Close);
     418  connect (myButtonBox, SIGNAL(clicked(QAbstractButton*)),
     419           this, SLOT(onButtonBoxClicked(QAbstractButton*)));
     420
     421  top->addWidget (myButtonBox);
     422  onSourceChanged ();
     423}
     424
     425MakeDialog :: ~MakeDialog ()
     426{
     427  if (myBuilder)
     428    tr_metaInfoBuilderFree (myBuilder);
    417429}
    418430
     
    422434
    423435void
    424 MakeDialog :: dragEnterEvent( QDragEnterEvent * event )
    425 {
    426     const QMimeData * mime = event->mimeData( );
    427 
    428     if( mime->urls().size() && QFile(mime->urls().front().path()).exists( ) )
    429         event->acceptProposedAction();
    430 }
    431 
    432 void
    433 MakeDialog :: dropEvent( QDropEvent * event )
    434 {
    435     const QString filename = event->mimeData()->urls().front().path();
    436     const QFileInfo fileInfo( filename );
    437 
    438     if( fileInfo.exists( ) )
    439     {
    440         if( fileInfo.isDir( ) )
     436MakeDialog :: dragEnterEvent (QDragEnterEvent * event)
     437{
     438  const QMimeData * mime = event->mimeData ();
     439
     440  if (mime->urls().size() && QFile(mime->urls().front().path()).exists ())
     441    event->acceptProposedAction();
     442}
     443
     444void
     445MakeDialog :: dropEvent (QDropEvent * event)
     446{
     447  const QString filename = event->mimeData()->urls().front().path();
     448  const QFileInfo fileInfo (filename);
     449
     450  if (fileInfo.exists ())
     451    {
     452      if (fileInfo.isDir ())
    441453        {
    442             myFolderRadio->setChecked( true );
    443             onFolderSelected( filename );
     454          myFolderRadio->setChecked (true);
     455          onFolderSelected (filename );
    444456        }
    445         else // it's a file
     457      else // it's a file
    446458        {
    447             myFileRadio->setChecked( true );
    448             onFileSelected( filename );
     459          myFileRadio->setChecked (true);
     460          onFileSelected (filename);
    449461        }
    450462    }
  • trunk/qt/make-dialog.h

    r14194 r14204  
    3535class MakeDialog: public QDialog
    3636{
    37         Q_OBJECT
     37    Q_OBJECT
    3838
    39     private slots:
    40         void onSourceChanged( );
    41         void onButtonBoxClicked( QAbstractButton* );
    42         void onNewButtonBoxClicked( QAbstractButton* );
    43         void onNewDialogDestroyed( QObject* );
    44         void onProgress( );
     39  private slots:
     40    void onSourceChanged ();
     41    void onButtonBoxClicked (QAbstractButton*);
     42    void onNewButtonBoxClicked (QAbstractButton*);
     43    void onNewDialogDestroyed (QObject*);
     44    void onProgress ();
    4545
    46         void onFolderClicked( );
    47         void onFolderSelected( const QString& );
    48         void onFolderSelected( const QStringList& );
     46    void onFolderClicked ();
     47    void onFolderSelected (const QString&);
     48    void onFolderSelected (const QStringList&);
    4949
    50         void onFileClicked( );
    51         void onFileSelected( const QString& );
    52         void onFileSelected( const QStringList& );
     50    void onFileClicked ();
     51    void onFileSelected (const QString&);
     52    void onFileSelected (const QStringList&);
    5353
    54         void onDestinationClicked( );
    55         void onDestinationSelected( const QString& );
    56         void onDestinationSelected( const QStringList& );
     54    void onDestinationClicked ();
     55    void onDestinationSelected (const QString&);
     56    void onDestinationSelected (const QStringList&);
    5757
    58     private:
    59         void makeTorrent( );
    60         QString getSource( ) const;
    61         void enableBuddyWhenChecked( QCheckBox *, QWidget * );
    62         void enableBuddyWhenChecked( QRadioButton *, QWidget * );
     58  private:
     59    void makeTorrent ();
     60    QString getSource () const;
     61    void enableBuddyWhenChecked (QCheckBox *, QWidget *);
     62    void enableBuddyWhenChecked (QRadioButton *, QWidget *);
    6363
    64     private:
    65         Session& mySession;
    66         QString myDestination;
    67         QString myTarget;
    68         QString myFile;
    69         QString myFolder;
    70         QTimer myTimer;
    71         QRadioButton * myFolderRadio;
    72         QRadioButton * myFileRadio;
    73         QPushButton * myDestinationButton;
    74         QPushButton * myFileButton;
    75         QPushButton * myFolderButton;
    76         QPlainTextEdit * myTrackerEdit;
    77         QCheckBox * myCommentCheck;
    78         QLineEdit * myCommentEdit;
    79         QCheckBox * myPrivateCheck;
    80         QLabel * mySourceLabel;
    81         QDialogButtonBox * myButtonBox;
    82         QProgressBar * myNewProgress;
    83         QLabel * myNewLabel;
    84         QDialogButtonBox * myNewButtonBox;
    85         QDialog * myNewDialog;
    86         struct tr_metainfo_builder * myBuilder;
     64  private:
     65    Session& mySession;
     66    QString myDestination;
     67    QString myTarget;
     68    QString myFile;
     69    QString myFolder;
     70    QTimer myTimer;
     71    QRadioButton * myFolderRadio;
     72    QRadioButton * myFileRadio;
     73    QPushButton * myDestinationButton;
     74    QPushButton * myFileButton;
     75    QPushButton * myFolderButton;
     76    QPlainTextEdit * myTrackerEdit;
     77    QCheckBox * myCommentCheck;
     78    QLineEdit * myCommentEdit;
     79    QCheckBox * myPrivateCheck;
     80    QLabel * mySourceLabel;
     81    QDialogButtonBox * myButtonBox;
     82    QProgressBar * myNewProgress;
     83    QLabel * myNewLabel;
     84    QDialogButtonBox * myNewButtonBox;
     85    QDialog * myNewDialog;
     86    struct tr_metainfo_builder * myBuilder;
    8787
    88     protected:
    89         virtual void dragEnterEvent( QDragEnterEvent * );
    90         virtual void dropEvent( QDropEvent * );
     88  protected:
     89    virtual void dragEnterEvent (QDragEnterEvent *);
     90    virtual void dropEvent (QDropEvent *);
    9191
    92     public:
    93         MakeDialog( Session&, QWidget * parent = 0 );
    94         ~MakeDialog( );
     92  public:
     93    MakeDialog (Session&, QWidget * parent = 0);
     94    ~MakeDialog ();
    9595};
    9696
  • trunk/qt/my-valgrind.sh

    r13722 r14204  
    11#/bin/sh
    22#valgrind --tool=cachegrind ./transmission-qt 2>&1 | tee runlog
    3 valgrind --tool=massif --threshold=0.2 ./transmission-qt 2>&1 | tee runlog
    4 #valgrind --tool=memcheck --leak-check=full --leak-resolution=high --num-callers=48 --log-file=x-valgrind --show-reachable=no ./transmission-qt 2>&1 | tee runlog
     3#valgrind --tool=massif --threshold=0.2 ./transmission-qt 2>&1 | tee runlog
     4valgrind --tool=memcheck --leak-check=full --leak-resolution=high --num-callers=16 --log-file=x-valgrind --show-reachable=no ./transmission-qt 2>&1 | tee runlog
  • trunk/qt/options.cc

    r14200 r14204  
    5757    return;
    5858
    59   if ( (result == "success") && !myDelFile.isEmpty ())
     59  if ((result == "success") && !myDelFile.isEmpty ())
    6060    {
    6161      QFile file (myDelFile);
  • trunk/qt/options.h

    r14185 r14204  
    5151
    5252  public:
    53     FileAdded (int tag, const QString& name): myTag (tag), myName (name) { }
    54     ~FileAdded () { }
     53    FileAdded (int tag, const QString& name): myTag (tag), myName (name) {}
     54    ~FileAdded () {}
    5555    void setFileToDelete (const QString& file) { myDelFile = file; }
    5656
  • trunk/qt/prefs-dialog.cc

    r14178 r14204  
    5151namespace
    5252{
    53     const char * PREF_KEY( "pref-key" );
     53  const char * PREF_KEY ("pref-key");
    5454};
    5555
    5656void
    57 PrefsDialog :: checkBoxToggled( bool checked )
    58 {
    59     const int key( sender( )->property( PREF_KEY ).toInt( ) );
    60     setPref( key, checked );
     57PrefsDialog :: checkBoxToggled (bool checked)
     58{
     59  const int key (sender ()->property (PREF_KEY).toInt ());
     60  setPref (key, checked);
    6161}
    6262
    6363QCheckBox *
    64 PrefsDialog :: checkBoxNew( const QString& text, int key )
    65 {
    66     QCheckBox * box = new QCheckBox( text );
    67     box->setChecked( myPrefs.getBool( key ) );
    68     box->setProperty( PREF_KEY, key );
    69     connect( box, SIGNAL(toggled(bool)), this, SLOT(checkBoxToggled(bool)));
    70     myWidgets.insert( key, box );
    71     return box;
    72 }
    73 
    74 void
    75 PrefsDialog :: enableBuddyWhenChecked( QCheckBox * box, QWidget * buddy )
    76 {
    77     connect( box, SIGNAL(toggled(bool)), buddy, SLOT(setEnabled(bool)) );
    78     buddy->setEnabled( box->isChecked( ) );
     64PrefsDialog :: checkBoxNew (const QString& text, int key)
     65{
     66  QCheckBox * box = new QCheckBox (text);
     67  box->setChecked (myPrefs.getBool (key));
     68  box->setProperty (PREF_KEY, key);
     69  connect (box, SIGNAL(toggled(bool)), this, SLOT(checkBoxToggled(bool)));
     70  myWidgets.insert (key, box);
     71  return box;
     72}
     73
     74void
     75PrefsDialog :: enableBuddyWhenChecked (QCheckBox * box, QWidget * buddy)
     76{
     77  connect (box, SIGNAL(toggled(bool)), buddy, SLOT(setEnabled(bool)));
     78  buddy->setEnabled (box->isChecked ());
    7979}
    8080
     
    8282PrefsDialog :: spinBoxEditingFinished()
    8383{
    84     const QObject * spin = sender();
    85     const int key = spin->property( PREF_KEY ).toInt( );
    86     const QDoubleSpinBox * d = qobject_cast<const QDoubleSpinBox*>( spin );
    87     if( d )
    88         setPref( key, d->value( ) );
    89     else
    90         setPref( key, qobject_cast<const QSpinBox*>(spin)->value( ) );
     84  const QObject * spin = sender();
     85  const int key = spin->property (PREF_KEY).toInt ();
     86  const QDoubleSpinBox * d = qobject_cast<const QDoubleSpinBox*> (spin);
     87
     88  if (d)
     89    setPref (key, d->value ());
     90  else
     91    setPref (key, qobject_cast<const QSpinBox*>(spin)->value ());
    9192}
    9293
    9394QSpinBox *
    94 PrefsDialog :: spinBoxNew( int key, int low, int high, int step )
    95 {
    96     QSpinBox * spin = new QSpinBox( );
    97     spin->setRange( low, high );
    98     spin->setSingleStep( step );
    99     spin->setValue( myPrefs.getInt( key ) );
    100     spin->setProperty( PREF_KEY, key );
    101     connect( spin, SIGNAL(editingFinished()), this, SLOT(spinBoxEditingFinished()));
    102     myWidgets.insert( key, spin );
    103     return spin;
     95PrefsDialog :: spinBoxNew (int key, int low, int high, int step)
     96{
     97  QSpinBox * spin = new QSpinBox ();
     98  spin->setRange (low, high);
     99  spin->setSingleStep (step);
     100  spin->setValue (myPrefs.getInt (key));
     101  spin->setProperty (PREF_KEY, key);
     102  connect (spin, SIGNAL(editingFinished()), this, SLOT(spinBoxEditingFinished()));
     103  myWidgets.insert (key, spin);
     104  return spin;
    104105}
    105106
    106107QDoubleSpinBox *
    107 PrefsDialog :: doubleSpinBoxNew( int key, double low, double high, double step, int decimals )
    108 {
    109     QDoubleSpinBox * spin = new QDoubleSpinBox( );
    110     spin->setRange( low, high );
    111     spin->setSingleStep( step );
    112     spin->setDecimals( decimals );
    113     spin->setValue( myPrefs.getDouble( key ) );
    114     spin->setProperty( PREF_KEY, key );
    115     connect( spin, SIGNAL(editingFinished()), this, SLOT(spinBoxEditingFinished()));
    116     myWidgets.insert( key, spin );
    117     return spin;
    118 }
    119 
    120 void
    121 PrefsDialog :: timeEditingFinished( )
    122 {
    123     QTimeEdit * e = qobject_cast<QTimeEdit*>(sender());
    124     if( e )
     108PrefsDialog :: doubleSpinBoxNew (int key, double low, double high, double step, int decimals)
     109{
     110  QDoubleSpinBox * spin = new QDoubleSpinBox ();
     111  spin->setRange (low, high);
     112  spin->setSingleStep (step);
     113  spin->setDecimals (decimals);
     114  spin->setValue (myPrefs.getDouble (key));
     115  spin->setProperty (PREF_KEY, key);
     116  connect (spin, SIGNAL(editingFinished()), this, SLOT(spinBoxEditingFinished()));
     117  myWidgets.insert (key, spin);
     118  return spin;
     119}
     120
     121void
     122PrefsDialog :: timeEditingFinished ()
     123{
     124  QTimeEdit * e = qobject_cast<QTimeEdit*>(sender());
     125  if (e)
    125126    {
    126         const int key( e->property( PREF_KEY ).toInt( ) );
    127         const QTime time( e->time( ) );
    128         const int seconds( QTime().secsTo( time ) );
    129         setPref( key, seconds / 60 );
     127      const int key (e->property (PREF_KEY).toInt ());
     128      const QTime time (e->time ());
     129      const int seconds (QTime().secsTo (time));
     130      setPref (key, seconds / 60);
    130131    }
    131132}
     133
    132134QTimeEdit*
    133 PrefsDialog :: timeEditNew( int key )
    134 {
    135     const int minutes( myPrefs.getInt( key ) );
    136     QTimeEdit * e = new QTimeEdit( );
    137     e->setDisplayFormat( QString::fromUtf8( "hh:mm" ) );
    138     e->setProperty( PREF_KEY, key );
    139     e->setTime( QTime().addSecs( minutes * 60 ) );
    140     myWidgets.insert( key, e );
    141     connect( e, SIGNAL(editingFinished()), this, SLOT(timeEditingFinished()) );
    142     return e;
    143 }
    144 
    145 void
    146 PrefsDialog :: lineEditingFinished( )
    147 {
    148     QLineEdit * e = qobject_cast<QLineEdit*>(sender());
    149     if( e && e->isModified( ) )
     135PrefsDialog :: timeEditNew (int key)
     136{
     137  const int minutes (myPrefs.getInt (key));
     138  QTimeEdit * e = new QTimeEdit ();
     139  e->setDisplayFormat (QString::fromUtf8 ("hh:mm"));
     140  e->setProperty (PREF_KEY, key);
     141  e->setTime (QTime().addSecs (minutes * 60));
     142  myWidgets.insert (key, e);
     143  connect (e, SIGNAL(editingFinished()), this, SLOT(timeEditingFinished()));
     144  return e;
     145}
     146
     147void
     148PrefsDialog :: lineEditingFinished ()
     149{
     150  QLineEdit * e = qobject_cast<QLineEdit*>(sender());
     151  if (e && e->isModified ())
    150152    {
    151         const int key( e->property( PREF_KEY ).toInt( ) );
    152         const QString text( e->text() );
    153         setPref( key, text );
     153      const int key (e->property (PREF_KEY).toInt ());
     154      const QString text (e->text());
     155      setPref (key, text);
    154156    }
    155157}
     158
    156159QLineEdit*
    157 PrefsDialog :: lineEditNew( int key, int echoMode )
    158 {
    159     QLineEdit * e = new QLineEdit( myPrefs.getString( key ) );
    160     e->setProperty( PREF_KEY, key );
    161     e->setEchoMode( QLineEdit::EchoMode( echoMode ) );
    162     myWidgets.insert( key, e );
    163     connect( e, SIGNAL(editingFinished()), this, SLOT(lineEditingFinished()) );
    164     return e;
     160PrefsDialog :: lineEditNew (int key, int echoMode)
     161{
     162  QLineEdit * e = new QLineEdit (myPrefs.getString (key));
     163  e->setProperty (PREF_KEY, key);
     164  e->setEchoMode (QLineEdit::EchoMode (echoMode));
     165  myWidgets.insert (key, e);
     166  connect (e, SIGNAL(editingFinished()), this, SLOT(lineEditingFinished()));
     167  return e;
    165168}
    166169
     
    170173
    171174QWidget *
    172 PrefsDialog :: createRemoteTab( Session& session )
    173 {
    174     HIG * hig = new HIG( this );
    175     hig->addSectionTitle( tr( "Remote Control" ) );
    176     QWidget * w;
    177     QHBoxLayout * h = new QHBoxLayout( );
    178     QPushButton * b = new QPushButton( tr( "&Open web client" ) );
    179     connect( b, SIGNAL(clicked()), &session, SLOT(launchWebInterface()) );
    180     h->addWidget( b, 0, Qt::AlignRight );
    181     QWidget * l = checkBoxNew( tr( "Allow &remote access" ), Prefs::RPC_ENABLED );
    182     myUnsupportedWhenRemote << l;
    183     hig->addRow( l, h, 0 );
    184     l = hig->addRow( tr( "HTTP &port:" ), w = spinBoxNew( Prefs::RPC_PORT, 0, 65535, 1 ) );
    185     myWebWidgets << l << w;
    186     hig->addWideControl( w = checkBoxNew( tr( "Use &authentication" ), Prefs::RPC_AUTH_REQUIRED ) );
    187     myWebWidgets << w;
    188     l = hig->addRow( tr( "&Username:" ), w = lineEditNew( Prefs::RPC_USERNAME ) );
    189     myWebAuthWidgets << l << w;
    190     l = hig->addRow( tr( "Pass&word:" ), w = lineEditNew( Prefs::RPC_PASSWORD, QLineEdit::Password ) );
    191     myWebAuthWidgets << l << w;
    192     hig->addWideControl( w = checkBoxNew( tr( "Only allow these IP a&ddresses:" ), Prefs::RPC_WHITELIST_ENABLED ) );
    193     myWebWidgets << w;
    194     l = hig->addRow( tr( "Addresses:" ), w = lineEditNew( Prefs::RPC_WHITELIST ) );
    195     myWebWhitelistWidgets << l << w;
    196     myUnsupportedWhenRemote << myWebWidgets << myWebAuthWidgets << myWebWhitelistWidgets;
    197     hig->finish( );
    198     return hig;
     175PrefsDialog :: createRemoteTab (Session& session)
     176{
     177  HIG * hig = new HIG (this);
     178  hig->addSectionTitle (tr ("Remote Control"));
     179  QWidget * w;
     180  QHBoxLayout * h = new QHBoxLayout ();
     181  QPushButton * b = new QPushButton (tr ("&Open web client"));
     182  connect (b, SIGNAL(clicked()), &session, SLOT(launchWebInterface()));
     183  h->addWidget (b, 0, Qt::AlignRight);
     184  QWidget * l = checkBoxNew (tr ("Allow &remote access"), Prefs::RPC_ENABLED);
     185  myUnsupportedWhenRemote << l;
     186  hig->addRow (l, h, 0);
     187  l = hig->addRow (tr ("HTTP &port:"), w = spinBoxNew (Prefs::RPC_PORT, 0, 65535, 1));
     188  myWebWidgets << l << w;
     189  hig->addWideControl (w = checkBoxNew (tr ("Use &authentication"), Prefs::RPC_AUTH_REQUIRED));
     190  myWebWidgets << w;
     191  l = hig->addRow (tr ("&Username:"), w = lineEditNew (Prefs::RPC_USERNAME));
     192  myWebAuthWidgets << l << w;
     193  l = hig->addRow (tr ("Pass&word:"), w = lineEditNew (Prefs::RPC_PASSWORD, QLineEdit::Password));
     194  myWebAuthWidgets << l << w;
     195  hig->addWideControl (w = checkBoxNew (tr ("Only allow these IP a&ddresses:"), Prefs::RPC_WHITELIST_ENABLED));
     196  myWebWidgets << w;
     197  l = hig->addRow (tr ("Addresses:"), w = lineEditNew (Prefs::RPC_WHITELIST));
     198  myWebWhitelistWidgets << l << w;
     199  myUnsupportedWhenRemote << myWebWidgets << myWebAuthWidgets << myWebWhitelistWidgets;
     200  hig->finish ();
     201  return hig;
    199202}
    200203
     
    204207
    205208void
    206 PrefsDialog :: altSpeedDaysEdited( int i )
    207 {
    208     const int value = qobject_cast<QComboBox*>(sender())->itemData(i).toInt();
    209     setPref( Prefs::ALT_SPEED_LIMIT_TIME_DAY, value );
     209PrefsDialog :: altSpeedDaysEdited (int i)
     210{
     211  const int value = qobject_cast<QComboBox*>(sender())->itemData(i).toInt();
     212  setPref (Prefs::ALT_SPEED_LIMIT_TIME_DAY, value);
    210213}
    211214
    212215
    213216QWidget *
    214 PrefsDialog :: createSpeedTab( )
    215 {
    216     QWidget *l, *r;
    217     HIG * hig = new HIG( this );
    218     hig->addSectionTitle( tr( "Speed Limits" ) );
    219     const QString speed_K_str = Formatter::unitStr( Formatter::SPEED, Formatter::KB );
    220 
    221         l = checkBoxNew( tr( "&Upload (%1):" ).arg( speed_K_str ), Prefs::USPEED_ENABLED );
    222         r = spinBoxNew( Prefs::USPEED, 0, INT_MAX, 5 );
    223         hig->addRow( l, r );
    224         enableBuddyWhenChecked( qobject_cast<QCheckBox*>(l), r );
    225 
    226         l = checkBoxNew( tr( "&Download (%1):" ).arg( speed_K_str ), Prefs::DSPEED_ENABLED );
    227         r = spinBoxNew( Prefs::DSPEED, 0, INT_MAX, 5 );
    228         hig->addRow( l, r );
    229         enableBuddyWhenChecked( qobject_cast<QCheckBox*>(l), r );
    230 
    231     hig->addSectionDivider( );
    232     QHBoxLayout * h = new QHBoxLayout;
    233     h->setSpacing( HIG :: PAD );
    234     QLabel * label = new QLabel;
    235     label->setPixmap( QPixmap( QString::fromUtf8( ":/icons/alt-limit-off.png" ) ) );
    236     label->setAlignment( Qt::AlignLeft|Qt::AlignVCenter );
    237     h->addWidget( label );
    238     label = new QLabel( tr( "Alternative Speed Limits" ) );
    239     label->setStyleSheet( QString::fromUtf8( "font: bold" ) );
    240     label->setAlignment( Qt::AlignLeft|Qt::AlignVCenter );
    241     h->addWidget( label );
    242     hig->addSectionTitle( h );
    243 
    244         QString s = tr( "<small>Override normal speed limits manually or at scheduled times</small>" );
    245         hig->addWideControl( new QLabel( s ) );
    246 
    247         s = tr( "U&pload (%1):" ).arg( speed_K_str );
    248         r = spinBoxNew( Prefs :: ALT_SPEED_LIMIT_UP, 0, INT_MAX, 5 );
    249         hig->addRow( s, r );
    250 
    251         s = tr( "Do&wnload (%1):" ).arg( speed_K_str );
    252         r = spinBoxNew( Prefs :: ALT_SPEED_LIMIT_DOWN, 0, INT_MAX, 5 );
    253         hig->addRow( s, r );
    254 
    255         QCheckBox * c = checkBoxNew( tr( "&Scheduled times:" ), Prefs::ALT_SPEED_LIMIT_TIME_ENABLED );
    256         h = new QHBoxLayout( );
    257         h->setSpacing( HIG::PAD );
    258         QWidget * w = timeEditNew( Prefs :: ALT_SPEED_LIMIT_TIME_BEGIN );
    259         h->addWidget( w, 1 );
    260         mySchedWidgets << w;
    261         QLabel * nd = new QLabel( tr("&to") );
    262         h->addWidget( nd );
    263         mySchedWidgets << nd;
    264         w = timeEditNew( Prefs :: ALT_SPEED_LIMIT_TIME_END );
    265         nd->setBuddy( w );
    266         h->addWidget( w, 1 );
    267         mySchedWidgets << w;
    268         hig->addRow( c, h, 0 );
    269 
    270         s = tr( "&On days:" );
    271         QComboBox * box = new QComboBox;
    272         const QIcon noIcon;
    273         box->addItem( noIcon, tr( "Every Day" ), QVariant( TR_SCHED_ALL ) );
    274         box->addItem( noIcon, tr( "Weekdays" ),  QVariant( TR_SCHED_WEEKDAY ) );
    275         box->addItem( noIcon, tr( "Weekends" ),  QVariant( TR_SCHED_WEEKEND ) );
    276         box->addItem( noIcon, tr( "Sunday" ),    QVariant( TR_SCHED_SUN ) );
    277         box->addItem( noIcon, tr( "Monday" ),    QVariant( TR_SCHED_MON ) );
    278         box->addItem( noIcon, tr( "Tuesday" ),   QVariant( TR_SCHED_TUES ) );
    279         box->addItem( noIcon, tr( "Wednesday" ), QVariant( TR_SCHED_WED ) );
    280         box->addItem( noIcon, tr( "Thursday" ),  QVariant( TR_SCHED_THURS ) );
    281         box->addItem( noIcon, tr( "Friday" ),    QVariant( TR_SCHED_FRI ) );
    282         box->addItem( noIcon, tr( "Saturday" ),  QVariant( TR_SCHED_SAT ) );
    283         box->setCurrentIndex( box->findData( myPrefs.getInt( Prefs :: ALT_SPEED_LIMIT_TIME_DAY ) ) );
    284         connect( box, SIGNAL(activated(int)), this, SLOT(altSpeedDaysEdited(int)) );
    285         w = hig->addRow( s, box );
    286         mySchedWidgets << w << box;
    287 
    288     hig->finish( );
    289     return hig;
     217PrefsDialog :: createSpeedTab ()
     218{
     219  QWidget *l, *r;
     220  HIG * hig = new HIG (this);
     221  hig->addSectionTitle (tr ("Speed Limits"));
     222  const QString speed_K_str = Formatter::unitStr (Formatter::SPEED, Formatter::KB);
     223
     224    l = checkBoxNew (tr ("&Upload (%1):").arg (speed_K_str), Prefs::USPEED_ENABLED);
     225    r = spinBoxNew (Prefs::USPEED, 0, INT_MAX, 5);
     226    hig->addRow (l, r);
     227    enableBuddyWhenChecked (qobject_cast<QCheckBox*>(l), r);
     228
     229    l = checkBoxNew (tr ("&Download (%1):").arg (speed_K_str), Prefs::DSPEED_ENABLED);
     230    r = spinBoxNew (Prefs::DSPEED, 0, INT_MAX, 5);
     231    hig->addRow (l, r);
     232    enableBuddyWhenChecked (qobject_cast<QCheckBox*>(l), r);
     233
     234  hig->addSectionDivider ();
     235  QHBoxLayout * h = new QHBoxLayout;
     236  h->setSpacing (HIG :: PAD);
     237  QLabel * label = new QLabel;
     238  label->setPixmap (QPixmap (QString::fromUtf8 (":/icons/alt-limit-off.png")));
     239  label->setAlignment (Qt::AlignLeft|Qt::AlignVCenter);
     240  h->addWidget (label);
     241  label = new QLabel (tr ("Alternative Speed Limits"));
     242  label->setStyleSheet (QString::fromUtf8 ("font: bold"));
     243  label->setAlignment (Qt::AlignLeft|Qt::AlignVCenter);
     244  h->addWidget (label);
     245  hig->addSectionTitle (h);
     246
     247    QString s = tr ("<small>Override normal speed limits manually or at scheduled times</small>");
     248    hig->addWideControl (new QLabel (s));
     249
     250    s = tr ("U&pload (%1):").arg (speed_K_str);
     251    r = spinBoxNew (Prefs :: ALT_SPEED_LIMIT_UP, 0, INT_MAX, 5);
     252    hig->addRow (s, r);
     253
     254    s = tr ("Do&wnload (%1):").arg (speed_K_str);
     255    r = spinBoxNew (Prefs :: ALT_SPEED_LIMIT_DOWN, 0, INT_MAX, 5);
     256    hig->addRow (s, r);
     257
     258    QCheckBox * c = checkBoxNew (tr ("&Scheduled times:"), Prefs::ALT_SPEED_LIMIT_TIME_ENABLED);
     259    h = new QHBoxLayout ();
     260    h->setSpacing (HIG::PAD);
     261    QWidget * w = timeEditNew (Prefs :: ALT_SPEED_LIMIT_TIME_BEGIN);
     262    h->addWidget (w, 1);
     263    mySchedWidgets << w;
     264    QLabel * nd = new QLabel (tr("&to"));
     265    h->addWidget (nd);
     266    mySchedWidgets << nd;
     267    w = timeEditNew (Prefs :: ALT_SPEED_LIMIT_TIME_END);
     268    nd->setBuddy (w);
     269    h->addWidget (w, 1);
     270    mySchedWidgets << w;
     271    hig->addRow (c, h, 0);
     272
     273    s = tr ("&On days:");
     274    QComboBox * box = new QComboBox;
     275    const QIcon noIcon;
     276    box->addItem (noIcon, tr ("Every Day"), QVariant (TR_SCHED_ALL));
     277    box->addItem (noIcon, tr ("Weekdays"),  QVariant (TR_SCHED_WEEKDAY));
     278    box->addItem (noIcon, tr ("Weekends"),  QVariant (TR_SCHED_WEEKEND));
     279    box->addItem (noIcon, tr ("Sunday"),    QVariant (TR_SCHED_SUN));
     280    box->addItem (noIcon, tr ("Monday"),    QVariant (TR_SCHED_MON));
     281    box->addItem (noIcon, tr ("Tuesday"),   QVariant (TR_SCHED_TUES));
     282    box->addItem (noIcon, tr ("Wednesday"), QVariant (TR_SCHED_WED));
     283    box->addItem (noIcon, tr ("Thursday"),  QVariant (TR_SCHED_THURS));
     284    box->addItem (noIcon, tr ("Friday"),    QVariant (TR_SCHED_FRI));
     285    box->addItem (noIcon, tr ("Saturday"),  QVariant (TR_SCHED_SAT));
     286    box->setCurrentIndex (box->findData (myPrefs.getInt (Prefs :: ALT_SPEED_LIMIT_TIME_DAY)));
     287    connect (box, SIGNAL(activated(int)), this, SLOT(altSpeedDaysEdited(int)));
     288    w = hig->addRow (s, box);
     289    mySchedWidgets << w << box;
     290
     291  hig->finish ();
     292  return hig;
    290293}
    291294
     
    295298
    296299QWidget *
    297 PrefsDialog :: createDesktopTab( )
    298 {
    299     HIG * hig = new HIG( this );
    300     hig->addSectionTitle( tr( "Desktop" ) );
    301 
    302       hig->addWideControl( checkBoxNew( tr( "Show Transmission icon in the &notification area" ), Prefs::SHOW_TRAY_ICON ) );
    303       hig->addWideControl( checkBoxNew( tr( "Start &minimized in notification area" ), Prefs::START_MINIMIZED ) );
    304 
    305     hig->addSectionDivider( );
    306     hig->addSectionTitle( tr ("Notification") );
    307 
    308       hig->addWideControl( checkBoxNew( tr( "Show a notification when torrents are a&dded" ), Prefs::SHOW_NOTIFICATION_ON_ADD ) );
    309       hig->addWideControl( checkBoxNew( tr( "Show a notification when torrents &finish" ), Prefs::SHOW_NOTIFICATION_ON_COMPLETE ) );
    310       hig->addWideControl( checkBoxNew( tr( "Play a &sound when torrents finish" ), Prefs::COMPLETE_SOUND_ENABLED ) );
    311 
    312     hig->finish( );
    313     return hig;
     300PrefsDialog :: createDesktopTab ()
     301{
     302  HIG * hig = new HIG (this);
     303  hig->addSectionTitle (tr ("Desktop"));
     304
     305    hig->addWideControl (checkBoxNew (tr ("Show Transmission icon in the &notification area"), Prefs::SHOW_TRAY_ICON));
     306    hig->addWideControl (checkBoxNew (tr ("Start &minimized in notification area"), Prefs::START_MINIMIZED));
     307
     308  hig->addSectionDivider ();
     309  hig->addSectionTitle (tr ("Notification"));
     310
     311    hig->addWideControl (checkBoxNew (tr ("Show a notification when torrents are a&dded"), Prefs::SHOW_NOTIFICATION_ON_ADD));
     312    hig->addWideControl (checkBoxNew (tr ("Show a notification when torrents &finish"), Prefs::SHOW_NOTIFICATION_ON_COMPLETE));
     313    hig->addWideControl (checkBoxNew (tr ("Play a &sound when torrents finish"), Prefs::COMPLETE_SOUND_ENABLED));
     314
     315  hig->finish ();
     316  return hig;
    314317}
    315318
     
    319322
    320323void
    321 PrefsDialog :: onPortTested( bool isOpen )
    322 {
    323     myPortButton->setEnabled( true );
    324     myWidgets[Prefs::PEER_PORT]->setEnabled( true );
    325     myPortLabel->setText( isOpen ? tr( "Port is <b>open</b>" )
    326                                  : tr( "Port is <b>closed</b>" ) );
    327 }
    328 
    329 void
    330 PrefsDialog :: onPortTest( )
    331 {
    332     myPortLabel->setText( tr( "Testing TCP Port..." ) );
    333     myPortButton->setEnabled( false );
    334     myWidgets[Prefs::PEER_PORT]->setEnabled( false );
    335     mySession.portTest( );
     324PrefsDialog :: onPortTested (bool isOpen)
     325{
     326  myPortButton->setEnabled (true);
     327  myWidgets[Prefs::PEER_PORT]->setEnabled (true);
     328  myPortLabel->setText (isOpen ? tr ("Port is <b>open</b>")
     329                               : tr ("Port is <b>closed</b>"));
     330}
     331
     332void
     333PrefsDialog :: onPortTest ()
     334{
     335  myPortLabel->setText (tr ("Testing TCP Port..."));
     336  myPortButton->setEnabled (false);
     337  myWidgets[Prefs::PEER_PORT]->setEnabled (false);
     338  mySession.portTest ();
    336339}
    337340
    338341QWidget *
    339 PrefsDialog :: createNetworkTab( )
    340 {
    341     HIG * hig = new HIG( this );
    342     hig->addSectionTitle( tr( "Incoming Peers" ) );
    343 
    344     QSpinBox * s = spinBoxNew( Prefs::PEER_PORT, 1, 65535, 1 );
    345     QHBoxLayout * h = new QHBoxLayout( );
    346     QPushButton * b = myPortButton = new QPushButton( tr( "Te&st Port" ) );
    347     QLabel * l = myPortLabel = new QLabel( tr( "Status unknown" ) );
    348     h->addWidget( l );
    349     h->addSpacing( HIG :: PAD_BIG );
    350     h->addWidget( b );
    351     h->setStretchFactor( l, 1 );
    352     connect( b, SIGNAL(clicked(bool)), this, SLOT(onPortTest()));
    353     connect( &mySession, SIGNAL(portTested(bool)), this, SLOT(onPortTested(bool)));
    354 
    355     hig->addRow( tr( "&Port for incoming connections:" ), s );
    356     hig->addRow( QString(), h, 0 );
    357     hig->addWideControl( checkBoxNew( tr( "Pick a &random port every time Transmission is started" ), Prefs :: PEER_PORT_RANDOM_ON_START ) );
    358     hig->addWideControl( checkBoxNew( tr( "Use UPnP or NAT-PMP port &forwarding from my router" ), Prefs::PORT_FORWARDING ) );
    359 
    360     hig->addSectionDivider( );
    361     hig->addSectionTitle( tr( "Peer Limits" ) );
    362     hig->addRow( tr( "Maximum peers per &torrent:" ), spinBoxNew( Prefs::PEER_LIMIT_TORRENT, 1, FD_SETSIZE, 5 ) );
    363     hig->addRow( tr( "Maximum peers &overall:" ), spinBoxNew( Prefs::PEER_LIMIT_GLOBAL, 1, FD_SETSIZE, 5 ) );
    364 
    365     hig->addSectionDivider( );
    366     hig->addSectionTitle( tr( "Options" ) );
    367 
    368     QWidget * w;
    369     hig->addWideControl( w = checkBoxNew( tr( "Enable &uTP for peer connections" ), Prefs::UTP_ENABLED ) );
    370     w->setToolTip( tr( "uTP is a tool for reducing network congestion." ) );
    371     hig->addWideControl( w = checkBoxNew( tr( "Use PE&X to find more peers" ), Prefs::PEX_ENABLED ) );
    372     w->setToolTip( tr( "PEX is a tool for exchanging peer lists with the peers you're connected to." ) );
    373     hig->addWideControl( w = checkBoxNew( tr( "Use &DHT to find more peers" ), Prefs::DHT_ENABLED ) );
    374     w->setToolTip( tr( "DHT is a tool for finding peers without a tracker." ) );
    375     hig->addWideControl( w = checkBoxNew( tr( "Use &Local Peer Discovery to find more peers" ), Prefs::LPD_ENABLED ) );
    376     w->setToolTip( tr( "LPD is a tool for finding peers on your local network." ) );
    377 
    378     hig->finish( );
    379     return hig;
     342PrefsDialog :: createNetworkTab ()
     343{
     344  HIG * hig = new HIG (this);
     345  hig->addSectionTitle (tr ("Incoming Peers"));
     346
     347  QSpinBox * s = spinBoxNew (Prefs::PEER_PORT, 1, 65535, 1);
     348  QHBoxLayout * h = new QHBoxLayout ();
     349  QPushButton * b = myPortButton = new QPushButton (tr ("Te&st Port"));
     350  QLabel * l = myPortLabel = new QLabel (tr ("Status unknown"));
     351  h->addWidget (l);
     352  h->addSpacing (HIG :: PAD_BIG);
     353  h->addWidget (b);
     354  h->setStretchFactor (l, 1);
     355  connect (b, SIGNAL(clicked(bool)), this, SLOT(onPortTest()));
     356  connect (&mySession, SIGNAL(portTested(bool)), this, SLOT(onPortTested(bool)));
     357
     358  hig->addRow (tr ("&Port for incoming connections:"), s);
     359  hig->addRow (QString(), h, 0);
     360  hig->addWideControl (checkBoxNew (tr ("Pick a &random port every time Transmission is started"), Prefs :: PEER_PORT_RANDOM_ON_START));
     361  hig->addWideControl (checkBoxNew (tr ("Use UPnP or NAT-PMP port &forwarding from my router"), Prefs::PORT_FORWARDING));
     362
     363  hig->addSectionDivider ();
     364  hig->addSectionTitle (tr ("Peer Limits"));
     365  hig->addRow (tr ("Maximum peers per &torrent:"), spinBoxNew (Prefs::PEER_LIMIT_TORRENT, 1, FD_SETSIZE, 5));
     366  hig->addRow (tr ("Maximum peers &overall:"), spinBoxNew (Prefs::PEER_LIMIT_GLOBAL, 1, FD_SETSIZE, 5));
     367
     368  hig->addSectionDivider ();
     369  hig->addSectionTitle (tr ("Options"));
     370
     371  QWidget * w;
     372  hig->addWideControl (w = checkBoxNew (tr ("Enable &uTP for peer connections"), Prefs::UTP_ENABLED));
     373  w->setToolTip (tr ("uTP is a tool for reducing network congestion."));
     374  hig->addWideControl (w = checkBoxNew (tr ("Use PE&X to find more peers"), Prefs::PEX_ENABLED));
     375  w->setToolTip (tr ("PEX is a tool for exchanging peer lists with the peers you're connected to."));
     376  hig->addWideControl (w = checkBoxNew (tr ("Use &DHT to find more peers"), Prefs::DHT_ENABLED));
     377  w->setToolTip (tr ("DHT is a tool for finding peers without a tracker."));
     378  hig->addWideControl (w = checkBoxNew (tr ("Use &Local Peer Discovery to find more peers"), Prefs::LPD_ENABLED));
     379  w->setToolTip (tr ("LPD is a tool for finding peers on your local network."));
     380
     381  hig->finish ();
     382  return hig;
    380383}
    381384
     
    385388
    386389void
    387 PrefsDialog :: onBlocklistDialogDestroyed( QObject * o )
    388 {
    389     Q_UNUSED( o );
    390 
    391     myBlocklistDialog = 0;
    392 }
    393 
    394 void
    395 PrefsDialog :: onUpdateBlocklistCancelled( )
    396 {
    397     disconnect( &mySession, SIGNAL(blocklistUpdated(int)), this, SLOT(onBlocklistUpdated(int))) ;
    398     myBlocklistDialog->deleteLater( );
    399 }
    400 
    401 void
    402 PrefsDialog :: onBlocklistUpdated( int n )
    403 {
    404     myBlocklistDialog->setText( tr( "<b>Update succeeded!</b><p>Blocklist now has %Ln rules.", 0, n ) );
    405     myBlocklistDialog->setTextFormat( Qt::RichText );
    406 }
    407 
    408 void
    409 PrefsDialog :: onUpdateBlocklistClicked( )
    410 {
    411     myBlocklistDialog = new QMessageBox( QMessageBox::Information,
    412                                          QString(),
    413                                          tr( "<b>Update Blocklist</b><p>Getting new blocklist..." ),
    414                                          QMessageBox::Close,
    415                                          this );
    416     connect( myBlocklistDialog, SIGNAL(rejected()), this, SLOT(onUpdateBlocklistCancelled()) );
    417     connect( &mySession, SIGNAL(blocklistUpdated(int)), this, SLOT(onBlocklistUpdated(int))) ;
    418     myBlocklistDialog->show( );
    419     mySession.updateBlocklist( );
    420 }
    421 
    422 void
    423 PrefsDialog :: encryptionEdited( int i )
    424 {
    425     const int value( qobject_cast<QComboBox*>(sender())->itemData(i).toInt( ) );
    426     setPref( Prefs::ENCRYPTION, value );
     390PrefsDialog :: onBlocklistDialogDestroyed (QObject * o)
     391{
     392  Q_UNUSED (o);
     393
     394  myBlocklistDialog = 0;
     395}
     396
     397void
     398PrefsDialog :: onUpdateBlocklistCancelled ()
     399{
     400  disconnect (&mySession, SIGNAL(blocklistUpdated(int)), this, SLOT(onBlocklistUpdated(int)));
     401  myBlocklistDialog->deleteLater ();
     402}
     403
     404void
     405PrefsDialog :: onBlocklistUpdated (int n)
     406{
     407  myBlocklistDialog->setText (tr ("<b>Update succeeded!</b><p>Blocklist now has %Ln rules.", 0, n));
     408  myBlocklistDialog->setTextFormat (Qt::RichText);
     409}
     410
     411void
     412PrefsDialog :: onUpdateBlocklistClicked ()
     413{
     414  myBlocklistDialog = new QMessageBox (QMessageBox::Information,
     415                                       QString(),
     416                                       tr ("<b>Update Blocklist</b><p>Getting new blocklist..."),
     417                                       QMessageBox::Close,
     418                                       this);
     419  connect (myBlocklistDialog, SIGNAL(rejected()), this, SLOT(onUpdateBlocklistCancelled()));
     420  connect (&mySession, SIGNAL(blocklistUpdated(int)), this, SLOT(onBlocklistUpdated(int)));
     421  myBlocklistDialog->show ();
     422  mySession.updateBlocklist ();
     423}
     424
     425void
     426PrefsDialog :: encryptionEdited (int i)
     427{
     428  const int value (qobject_cast<QComboBox*>(sender())->itemData(i).toInt ());
     429  setPref (Prefs::ENCRYPTION, value);
    427430}
    428431
    429432QWidget *
    430 PrefsDialog :: createPrivacyTab( )
    431 {
    432     QWidget * w;
    433     HIG * hig = new HIG( this );
    434 
    435     hig->addSectionTitle( tr( "Encryption" ) );
    436 
    437     QComboBox * box = new QComboBox( );
    438     box->addItem( tr( "Allow encryption" ), 0 );
    439     box->addItem( tr( "Prefer encryption" ), 1 );
    440     box->addItem( tr( "Require encryption" ), 2 );
    441     myWidgets.insert( Prefs :: ENCRYPTION, box );
    442     connect( box, SIGNAL(activated(int)), this, SLOT(encryptionEdited(int)));
    443 
    444     hig->addRow( tr( "&Encryption mode:" ), box );
    445 
    446     hig->addSectionDivider( );
    447     hig->addSectionTitle( tr( "Blocklist" ) );
    448 
    449     QWidget * l = checkBoxNew( tr("Enable &blocklist:"), Prefs::BLOCKLIST_ENABLED );
    450     QWidget * e = lineEditNew( Prefs::BLOCKLIST_URL );
    451     myBlockWidgets << e;
    452     hig->addRow( l, e );
    453 
    454     l = myBlocklistLabel = new QLabel( );
    455     myBlockWidgets << l;
    456     w = new QPushButton( tr( "&Update" ) );
    457     connect( w, SIGNAL(clicked(bool)), this, SLOT(onUpdateBlocklistClicked()));
    458     myBlockWidgets << w;
    459     QHBoxLayout * h = new QHBoxLayout( );
    460     h->addWidget( l );
    461     h->addStretch( 1 );
    462     h->addWidget( w );
    463     hig->addWideControl( h );
    464 
    465     l = checkBoxNew( tr( "Enable &automatic updates" ), Prefs::BLOCKLIST_UPDATES_ENABLED );
    466     myBlockWidgets << l;
    467     hig->addWideControl( l );
    468 
    469     hig->finish( );
    470     updateBlocklistLabel( );
    471     return hig;
     433PrefsDialog :: createPrivacyTab ()
     434{
     435  QWidget * w;
     436  HIG * hig = new HIG (this);
     437
     438  hig->addSectionTitle (tr ("Encryption"));
     439
     440  QComboBox * box = new QComboBox ();
     441  box->addItem (tr ("Allow encryption"), 0);
     442  box->addItem (tr ("Prefer encryption"), 1);
     443  box->addItem (tr ("Require encryption"), 2);
     444  myWidgets.insert (Prefs :: ENCRYPTION, box);
     445  connect (box, SIGNAL(activated(int)), this, SLOT(encryptionEdited(int)));
     446
     447  hig->addRow (tr ("&Encryption mode:"), box);
     448
     449  hig->addSectionDivider ();
     450  hig->addSectionTitle (tr ("Blocklist"));
     451
     452  QWidget * l = checkBoxNew (tr("Enable &blocklist:"), Prefs::BLOCKLIST_ENABLED);
     453  QWidget * e = lineEditNew (Prefs::BLOCKLIST_URL);
     454  myBlockWidgets << e;
     455  hig->addRow (l, e);
     456
     457  l = myBlocklistLabel = new QLabel ();
     458  myBlockWidgets << l;
     459  w = new QPushButton (tr ("&Update"));
     460  connect (w, SIGNAL(clicked(bool)), this, SLOT(onUpdateBlocklistClicked()));
     461  myBlockWidgets << w;
     462  QHBoxLayout * h = new QHBoxLayout ();
     463  h->addWidget (l);
     464  h->addStretch (1);
     465  h->addWidget (w);
     466  hig->addWideControl (h);
     467
     468  l = checkBoxNew (tr ("Enable &automatic updates"), Prefs::BLOCKLIST_UPDATES_ENABLED);
     469  myBlockWidgets << l;
     470  hig->addWideControl (l);
     471
     472  hig->finish ();
     473  updateBlocklistLabel ();
     474  return hig;
    472475}
    473476
     
    477480
    478481void
    479 PrefsDialog :: onScriptClicked( void )
    480 {
    481     const QString title = tr( "Select \"Torrent Done\" Script" );
    482     const QString myPath = myPrefs.getString( Prefs::SCRIPT_TORRENT_DONE_FILENAME );
    483     const QString path = Utils::remoteFileChooser( this, title, myPath, false, mySession.isServer() );
    484 
    485     if( !path.isEmpty() )
    486         onLocationSelected( path, Prefs::SCRIPT_TORRENT_DONE_FILENAME );
    487 }
    488 
    489 void
    490 PrefsDialog :: onIncompleteClicked( void )
    491 {
    492     const QString title = tr( "Select Incomplete Directory" );
    493     const QString myPath = myPrefs.getString( Prefs::INCOMPLETE_DIR );
    494     const QString path = Utils::remoteFileChooser( this, title, myPath, true, mySession.isServer() );
    495 
    496     if( !path.isEmpty() )
    497         onLocationSelected( path, Prefs::INCOMPLETE_DIR );
    498 }
    499 
    500 void
    501 PrefsDialog :: onWatchClicked( void )
    502 {
    503     const QString title = tr( "Select Watch Directory" );
    504     const QString myPath = myPrefs.getString( Prefs::DIR_WATCH );
    505     const QString path = Utils::remoteFileChooser( this, title, myPath, true, true );
    506 
    507     if( !path.isEmpty() )
    508         onLocationSelected( path, Prefs::DIR_WATCH );
    509 }
    510 
    511 void
    512 PrefsDialog :: onDestinationClicked( void )
    513 {
    514     const QString title = tr( "Select Destination" );
    515     const QString myPath = myPrefs.getString( Prefs::DOWNLOAD_DIR );
    516     const QString path = Utils::remoteFileChooser( this, title, myPath, true, mySession.isServer() );
    517 
    518     if( !path.isEmpty() )
    519         onLocationSelected( path, Prefs::DOWNLOAD_DIR );
    520 }
    521 
    522 void
    523 PrefsDialog :: onLocationSelected( const QString& path, int key )
    524 {
    525     setPref( key, path );
     482PrefsDialog :: onScriptClicked (void)
     483{
     484  const QString title = tr ("Select \"Torrent Done\" Script");
     485  const QString myPath = myPrefs.getString (Prefs::SCRIPT_TORRENT_DONE_FILENAME);
     486  const QString path = Utils::remoteFileChooser (this, title, myPath, false, mySession.isServer());
     487
     488  if (!path.isEmpty())
     489    onLocationSelected (path, Prefs::SCRIPT_TORRENT_DONE_FILENAME);
     490}
     491
     492void
     493PrefsDialog :: onIncompleteClicked (void)
     494{
     495  const QString title = tr ("Select Incomplete Directory");
     496  const QString myPath = myPrefs.getString (Prefs::INCOMPLETE_DIR);
     497  const QString path = Utils::remoteFileChooser (this, title, myPath, true, mySession.isServer());
     498
     499  if (!path.isEmpty())
     500    onLocationSelected (path, Prefs::INCOMPLETE_DIR);
     501}
     502
     503void
     504PrefsDialog :: onWatchClicked (void)
     505{
     506  const QString title = tr ("Select Watch Directory");
     507  const QString myPath = myPrefs.getString (Prefs::DIR_WATCH);
     508  const QString path = Utils::remoteFileChooser (this, title, myPath, true, true);
     509
     510  if (!path.isEmpty())
     511    onLocationSelected (path, Prefs::DIR_WATCH);
     512}
     513
     514void
     515PrefsDialog :: onDestinationClicked (void)
     516{
     517  const QString title = tr ("Select Destination");
     518  const QString myPath = myPrefs.getString (Prefs::DOWNLOAD_DIR);
     519  const QString path = Utils::remoteFileChooser (this, title, myPath, true, mySession.isServer());
     520
     521  if (!path.isEmpty())
     522    onLocationSelected (path, Prefs::DOWNLOAD_DIR);
     523}
     524
     525void
     526PrefsDialog :: onLocationSelected (const QString& path, int key)
     527{
     528  setPref (key, path);
    526529}
    527530
    528531QWidget *
    529 PrefsDialog :: createSeedingTab( )
    530 {
    531     const int iconSize( style( )->pixelMetric( QStyle :: PM_SmallIconSize ) );
    532     const QFileIconProvider iconProvider;
    533     const QIcon folderIcon = iconProvider.icon( QFileIconProvider::Folder );
    534     const QPixmap folderPixmap = folderIcon.pixmap( iconSize );
    535     const QIcon fileIcon = iconProvider.icon( QFileIconProvider::File );
    536     const QPixmap filePixmap = fileIcon.pixmap( iconSize );
    537 
    538     QWidget *l, *r;
    539     HIG * hig = new HIG( this );
    540     hig->addSectionTitle( tr( "Limits" ) );
    541 
    542         l = checkBoxNew( tr( "Stop seeding at &ratio:" ), Prefs::RATIO_ENABLED );
    543         r = doubleSpinBoxNew( Prefs::RATIO, 0, INT_MAX, 0.5, 2 );
    544         hig->addRow( l, r );
    545         enableBuddyWhenChecked( qobject_cast<QCheckBox*>(l), r );
    546 
    547         l = checkBoxNew( tr( "Stop seeding if idle for &N minutes:" ), Prefs::IDLE_LIMIT_ENABLED );
    548         r = spinBoxNew( Prefs::IDLE_LIMIT, 1, INT_MAX, 5 );
    549         hig->addRow( l, r );
    550         enableBuddyWhenChecked( qobject_cast<QCheckBox*>(l), r );
    551 
    552     hig->finish( );
    553     return hig;
     532PrefsDialog :: createSeedingTab ()
     533{
     534  const int iconSize (style ()->pixelMetric (QStyle :: PM_SmallIconSize));
     535  const QFileIconProvider iconProvider;
     536  const QIcon folderIcon = iconProvider.icon (QFileIconProvider::Folder);
     537  const QPixmap folderPixmap = folderIcon.pixmap (iconSize);
     538  const QIcon fileIcon = iconProvider.icon (QFileIconProvider::File);
     539  const QPixmap filePixmap = fileIcon.pixmap (iconSize);
     540
     541  QWidget *l, *r;
     542  HIG * hig = new HIG (this);
     543  hig->addSectionTitle (tr ("Limits"));
     544
     545    l = checkBoxNew (tr ("Stop seeding at &ratio:"), Prefs::RATIO_ENABLED);
     546    r = doubleSpinBoxNew (Prefs::RATIO, 0, INT_MAX, 0.5, 2);
     547    hig->addRow (l, r);
     548    enableBuddyWhenChecked (qobject_cast<QCheckBox*>(l), r);
     549
     550    l = checkBoxNew (tr ("Stop seeding if idle for &N minutes:"), Prefs::IDLE_LIMIT_ENABLED);
     551    r = spinBoxNew (Prefs::IDLE_LIMIT, 1, INT_MAX, 5);
     552    hig->addRow (l, r);
     553    enableBuddyWhenChecked (qobject_cast<QCheckBox*>(l), r);
     554
     555  hig->finish ();
     556  return hig;
    554557}
    555558
    556559QWidget *
    557 PrefsDialog :: createDownloadingTab( )
    558 {
    559     const int iconSize( style( )->pixelMetric( QStyle :: PM_SmallIconSize ) );
    560     const QFileIconProvider iconProvider;
    561     const QIcon folderIcon = iconProvider.icon( QFileIconProvider::Folder );
    562     const QPixmap folderPixmap = folderIcon.pixmap( iconSize );
    563     const QIcon fileIcon = iconProvider.icon( QFileIconProvider::File );
    564     const QPixmap filePixmap = fileIcon.pixmap( iconSize );
    565 
    566     QWidget * l;
    567     QPushButton * b;
    568     HIG * hig = new HIG( this );
    569     hig->addSectionTitle( tr( "Adding" ) );
    570 
    571         l = checkBoxNew( tr( "Automatically add .torrent files &from:" ), Prefs::DIR_WATCH_ENABLED );
    572         b = myWatchButton = new QPushButton;
    573         b->setIcon( folderPixmap );
    574         b->setStyleSheet( QString::fromUtf8( "text-align: left; padding-left: 5; padding-right: 5" ) );
    575         connect( b, SIGNAL(clicked(bool)), this, SLOT(onWatchClicked(void)) );
    576         hig->addRow( l, b );
    577         enableBuddyWhenChecked( qobject_cast<QCheckBox*>(l), b );
    578 
    579         hig->addWideControl( checkBoxNew( tr( "Show the Torrent Options &dialog" ), Prefs::OPTIONS_PROMPT ) );
    580 
    581         hig->addWideControl( checkBoxNew( tr( "&Start added torrents" ), Prefs::START ) );
    582 
    583         hig->addWideControl( checkBoxNew( tr( "Mo&ve the .torrent file to the trash" ), Prefs::TRASH_ORIGINAL ) );
    584 
    585         b = myDestinationButton = new QPushButton;
    586         b->setIcon( folderPixmap );
    587         b->setStyleSheet( QString::fromUtf8( "text-align: left; padding-left: 5; padding-right: 5" ) );
    588         connect( b, SIGNAL(clicked(bool)), this, SLOT(onDestinationClicked(void)) );
    589         hig->addRow( tr( "Save to &Location:" ), b );
    590 
    591         const QString downloadDir (myPrefs.getString(Prefs::DOWNLOAD_DIR));
    592         l = myFreespaceLabel = new FreespaceLabel (mySession, downloadDir, this);
    593         QHBoxLayout * h = new QHBoxLayout ();
    594         h->addStretch (1);
    595         h->addWidget (l);
    596         hig->addWideControl (h);
    597 
    598     hig->addSectionDivider( );
    599     hig->addSectionTitle( tr( "Download Queue" ) );
     560PrefsDialog :: createDownloadingTab ()
     561{
     562  const int iconSize (style ()->pixelMetric (QStyle :: PM_SmallIconSize));
     563  const QFileIconProvider iconProvider;
     564  const QIcon folderIcon = iconProvider.icon (QFileIconProvider::Folder);
     565  const QPixmap folderPixmap = folderIcon.pixmap (iconSize);
     566  const QIcon fileIcon = iconProvider.icon (QFileIconProvider::File);
     567  const QPixmap filePixmap = fileIcon.pixmap (iconSize);
     568
     569  QWidget * l;
     570  QPushButton * b;
     571  HIG * hig = new HIG (this);
     572  hig->addSectionTitle (tr ("Adding"));
     573
     574    l = checkBoxNew (tr ("Automatically add .torrent files &from:"), Prefs::DIR_WATCH_ENABLED);
     575    b = myWatchButton = new QPushButton;
     576    b->setIcon (folderPixmap);
     577    b->setStyleSheet (QString::fromUtf8 ("text-align: left; padding-left: 5; padding-right: 5"));
     578    connect (b, SIGNAL(clicked(bool)), this, SLOT(onWatchClicked(void)));
     579    hig->addRow (l, b);
     580    enableBuddyWhenChecked (qobject_cast<QCheckBox*>(l), b);
     581
     582    hig->addWideControl (checkBoxNew (tr ("Show the Torrent Options &dialog"), Prefs::OPTIONS_PROMPT));
     583
     584    hig->addWideControl (checkBoxNew (tr ("&Start added torrents"), Prefs::START));
     585
     586    hig->addWideControl (checkBoxNew (tr ("Mo&ve the .torrent file to the trash"), Prefs::TRASH_ORIGINAL));
     587
     588    b = myDestinationButton = new QPushButton;
     589    b->setIcon (folderPixmap);
     590    b->setStyleSheet (QString::fromUtf8 ("text-align: left; padding-left: 5; padding-right: 5"));
     591    connect (b, SIGNAL(clicked(bool)), this, SLOT(onDestinationClicked(void)));
     592    hig->addRow (tr ("Save to &Location:"), b);
     593
     594    const QString downloadDir (myPrefs.getString(Prefs::DOWNLOAD_DIR));
     595    l = myFreespaceLabel = new FreespaceLabel (mySession, downloadDir, this);
     596    QHBoxLayout * h = new QHBoxLayout ();
     597    h->addStretch (1);
     598    h->addWidget (l);
     599    hig->addWideControl (h);
     600
     601  hig->addSectionDivider ();
     602  hig->addSectionTitle (tr ("Download Queue"));
    600603   
    601         hig->addRow( tr( "Ma&ximum active downloads:" ), spinBoxNew( Prefs::DOWNLOAD_QUEUE_SIZE, 1, INT_MAX, 1 ) );
    602         hig->addRow( tr( "Downloads sharing data in the last &N minutes are active:" ), spinBoxNew( Prefs::QUEUE_STALLED_MINUTES, 1, INT_MAX, 10 ) );
    603 
    604     hig->addSectionDivider( );
    605     hig->addSectionTitle( tr( "Incomplete" ) );
    606 
    607         hig->addWideControl( checkBoxNew( tr( "Append \".&part\" to incomplete files' names" ), Prefs::RENAME_PARTIAL_FILES ) );
    608 
    609         l = myIncompleteCheckbox = checkBoxNew( tr( "Keep &incomplete files in:" ), Prefs::INCOMPLETE_DIR_ENABLED );
    610         b = myIncompleteButton = new QPushButton;
    611         b->setIcon( folderPixmap );
    612         b->setStyleSheet( QString::fromUtf8( "text-align: left; padding-left: 5; padding-right: 5" ) );
    613         connect( b, SIGNAL(clicked(bool)), this, SLOT(onIncompleteClicked(void)) );
    614         hig->addRow( myIncompleteCheckbox, b );
    615         enableBuddyWhenChecked( qobject_cast<QCheckBox*>(l), b );
    616 
    617         l = myTorrentDoneScriptCheckbox = checkBoxNew( tr( "Call scrip&t when torrent is completed:" ), Prefs::SCRIPT_TORRENT_DONE_ENABLED );
    618         b = myTorrentDoneScriptButton = new QPushButton;
    619         b->setIcon( filePixmap );
    620         b->setStyleSheet( QString::fromUtf8( "text-align: left; padding-left: 5; padding-right: 5" ) );
    621         connect( b, SIGNAL(clicked(bool)), this, SLOT(onScriptClicked(void)) );
    622         hig->addRow( myTorrentDoneScriptCheckbox, b );
    623         enableBuddyWhenChecked( qobject_cast<QCheckBox*>(l), b );
    624 
    625     hig->finish( );
    626     return hig;
     604    hig->addRow (tr ("Ma&ximum active downloads:"), spinBoxNew (Prefs::DOWNLOAD_QUEUE_SIZE, 1, INT_MAX, 1));
     605    hig->addRow (tr ("Downloads sharing data in the last &N minutes are active:"), spinBoxNew (Prefs::QUEUE_STALLED_MINUTES, 1, INT_MAX, 10));
     606
     607  hig->addSectionDivider ();
     608  hig->addSectionTitle (tr ("Incomplete"));
     609
     610    hig->addWideControl (checkBoxNew (tr ("Append \".&part\" to incomplete files' names"), Prefs::RENAME_PARTIAL_FILES));
     611
     612    l = myIncompleteCheckbox = checkBoxNew (tr ("Keep &incomplete files in:"), Prefs::INCOMPLETE_DIR_ENABLED);
     613    b = myIncompleteButton = new QPushButton;
     614    b->setIcon (folderPixmap);
     615    b->setStyleSheet (QString::fromUtf8 ("text-align: left; padding-left: 5; padding-right: 5"));
     616    connect (b, SIGNAL(clicked(bool)), this, SLOT(onIncompleteClicked(void)));
     617    hig->addRow (myIncompleteCheckbox, b);
     618    enableBuddyWhenChecked (qobject_cast<QCheckBox*>(l), b);
     619
     620    l = myTorrentDoneScriptCheckbox = checkBoxNew (tr ("Call scrip&t when torrent is completed:"), Prefs::SCRIPT_TORRENT_DONE_ENABLED);
     621    b = myTorrentDoneScriptButton = new QPushButton;
     622    b->setIcon (filePixmap);
     623    b->setStyleSheet (QString::fromUtf8 ("text-align: left; padding-left: 5; padding-right: 5"));
     624    connect (b, SIGNAL(clicked(bool)), this, SLOT(onScriptClicked(void)));
     625    hig->addRow (myTorrentDoneScriptCheckbox, b);
     626    enableBuddyWhenChecked (qobject_cast<QCheckBox*>(l), b);
     627
     628  hig->finish ();
     629  return hig;
    627630}
    628631
     
    631634***/
    632635
    633 PrefsDialog :: PrefsDialog( Session& session, Prefs& prefs, QWidget * parent ):
    634     QDialog( parent ),
    635     myIsServer( session.isServer( ) ),
    636     mySession( session ),
    637     myPrefs( prefs ),
    638     myLayout( new QVBoxLayout( this ) )
    639 {
    640     setWindowTitle( tr( "Transmission Preferences" ) );
    641 
    642     QTabWidget * t = new QTabWidget( this );
    643     t->addTab( createSpeedTab( ),        tr( "Speed" ) );
    644     t->addTab( createDownloadingTab( ),  tr( "Downloading" ) );
    645     t->addTab( createSeedingTab( ),      tr( "Seeding" ) );
    646     t->addTab( createPrivacyTab( ),      tr( "Privacy" ) );
    647     t->addTab( createNetworkTab( ),      tr( "Network" ) );
    648     t->addTab( createDesktopTab( ),      tr( "Desktop" ) );
    649     t->addTab( createRemoteTab(session), tr( "Remote" ) );
    650     myLayout->addWidget( t );
    651 
    652     QDialogButtonBox * buttons = new QDialogButtonBox( QDialogButtonBox::Close, Qt::Horizontal, this );
    653     connect( buttons, SIGNAL(rejected()), this, SLOT(close()) ); // "close" triggers rejected
    654     myLayout->addWidget( buttons );
    655     QWidget::setAttribute( Qt::WA_DeleteOnClose, true );
    656 
    657     connect( &mySession, SIGNAL(sessionUpdated()), this, SLOT(sessionUpdated()));
    658 
    659     QList<int> keys;
    660     keys << Prefs :: RPC_ENABLED
    661          << Prefs :: ALT_SPEED_LIMIT_ENABLED
    662          << Prefs :: ALT_SPEED_LIMIT_TIME_ENABLED
    663          << Prefs :: ENCRYPTION
    664          << Prefs :: BLOCKLIST_ENABLED
    665          << Prefs :: DIR_WATCH
    666          << Prefs :: DOWNLOAD_DIR
    667          << Prefs :: INCOMPLETE_DIR
    668          << Prefs :: INCOMPLETE_DIR_ENABLED
    669          << Prefs :: SCRIPT_TORRENT_DONE_FILENAME;
    670     foreach( int key, keys )
    671         refreshPref( key );
    672 
    673     // if it's a remote session, disable the preferences
    674     // that don't work in remote sessions
    675     if( !myIsServer )  {
    676         foreach( QWidget * w, myUnsupportedWhenRemote ) {
    677             w->setToolTip( tr( "Not supported by remote sessions" ) );
    678             w->setEnabled( false );
     636PrefsDialog :: PrefsDialog (Session& session, Prefs& prefs, QWidget * parent):
     637  QDialog (parent),
     638  myIsServer (session.isServer ()),
     639  mySession (session),
     640  myPrefs (prefs),
     641  myLayout (new QVBoxLayout (this))
     642{
     643  setWindowTitle (tr ("Transmission Preferences"));
     644
     645  QTabWidget * t = new QTabWidget (this);
     646  t->addTab (createSpeedTab (),        tr ("Speed"));
     647  t->addTab (createDownloadingTab (),  tr ("Downloading"));
     648  t->addTab (createSeedingTab (),      tr ("Seeding"));
     649  t->addTab (createPrivacyTab (),      tr ("Privacy"));
     650  t->addTab (createNetworkTab (),      tr ("Network"));
     651  t->addTab (createDesktopTab (),      tr ("Desktop"));
     652  t->addTab (createRemoteTab(session), tr ("Remote"));
     653  myLayout->addWidget (t);
     654
     655  QDialogButtonBox * buttons = new QDialogButtonBox (QDialogButtonBox::Close, Qt::Horizontal, this);
     656  connect (buttons, SIGNAL(rejected()), this, SLOT(close())); // "close" triggers rejected
     657  myLayout->addWidget (buttons);
     658  QWidget::setAttribute (Qt::WA_DeleteOnClose, true);
     659
     660  connect (&mySession, SIGNAL(sessionUpdated()), this, SLOT(sessionUpdated()));
     661
     662  QList<int> keys;
     663  keys << Prefs :: RPC_ENABLED
     664       << Prefs :: ALT_SPEED_LIMIT_ENABLED
     665       << Prefs :: ALT_SPEED_LIMIT_TIME_ENABLED
     666       << Prefs :: ENCRYPTION
     667       << Prefs :: BLOCKLIST_ENABLED
     668       << Prefs :: DIR_WATCH
     669       << Prefs :: DOWNLOAD_DIR
     670       << Prefs :: INCOMPLETE_DIR
     671       << Prefs :: INCOMPLETE_DIR_ENABLED
     672       << Prefs :: SCRIPT_TORRENT_DONE_FILENAME;
     673  foreach (int key, keys)
     674    refreshPref (key);
     675
     676  // if it's a remote session, disable the preferences
     677  // that don't work in remote sessions
     678  if (!myIsServer)
     679    {
     680      foreach (QWidget * w, myUnsupportedWhenRemote)
     681        {
     682          w->setToolTip (tr ("Not supported by remote sessions"));
     683          w->setEnabled (false);
    679684        }
    680685    }
    681686}
    682687
    683 PrefsDialog :: ~PrefsDialog( )
    684 {
    685 }
    686 
    687 void
    688 PrefsDialog :: setPref( int key, const QVariant& v )
    689 {
    690     myPrefs.set( key, v );
    691     refreshPref( key );
     688PrefsDialog :: ~PrefsDialog ()
     689{
     690}
     691
     692void
     693PrefsDialog :: setPref (int key, const QVariant& v)
     694{
     695  myPrefs.set (key, v);
     696  refreshPref (key);
    692697}
    693698
     
    697702
    698703void
    699 PrefsDialog :: sessionUpdated( )
    700 {
    701     updateBlocklistLabel( );
    702 }
    703 
    704 void
    705 PrefsDialog :: updateBlocklistLabel( )
    706 {
    707     const int n = mySession.blocklistSize( );
    708     myBlocklistLabel->setText( tr( "<i>Blocklist contains %Ln rules</i>", 0, n ) );
    709 }
    710 
    711 void
    712 PrefsDialog :: refreshPref( int key )
    713 {
    714     switch( key )
     704PrefsDialog :: sessionUpdated ()
     705{
     706  updateBlocklistLabel ();
     707}
     708
     709void
     710PrefsDialog :: updateBlocklistLabel ()
     711{
     712  const int n = mySession.blocklistSize ();
     713  myBlocklistLabel->setText (tr ("<i>Blocklist contains %Ln rules</i>", 0, n));
     714}
     715
     716void
     717PrefsDialog :: refreshPref (int key)
     718{
     719  switch (key)
    715720    {
    716         case Prefs :: RPC_ENABLED:
    717         case Prefs :: RPC_WHITELIST_ENABLED:
    718         case Prefs :: RPC_AUTH_REQUIRED: {
    719             const bool enabled( myPrefs.getBool( Prefs::RPC_ENABLED ) );
    720             const bool whitelist( myPrefs.getBool( Prefs::RPC_WHITELIST_ENABLED ) );
    721             const bool auth( myPrefs.getBool( Prefs::RPC_AUTH_REQUIRED ) );
    722             foreach( QWidget * w, myWebWhitelistWidgets ) w->setEnabled( enabled && whitelist );
    723             foreach( QWidget * w, myWebAuthWidgets ) w->setEnabled( enabled && auth );
    724             foreach( QWidget * w, myWebWidgets ) w->setEnabled( enabled );
    725             break;
    726         }
    727 
    728         case Prefs :: ALT_SPEED_LIMIT_TIME_ENABLED: {
    729             const bool enabled = myPrefs.getBool( key );
    730             foreach( QWidget * w, mySchedWidgets ) w->setEnabled( enabled );
    731             break;
    732         }
    733 
    734         case Prefs :: BLOCKLIST_ENABLED: {
    735             const bool enabled = myPrefs.getBool( key );
    736             foreach( QWidget * w, myBlockWidgets ) w->setEnabled( enabled );
    737             break;
    738         }
    739 
    740         case Prefs :: DIR_WATCH:
    741             myWatchButton->setText( QFileInfo(myPrefs.getString(Prefs::DIR_WATCH)).fileName() );
    742             break;
    743 
    744         case Prefs :: SCRIPT_TORRENT_DONE_FILENAME: {
    745             const QString path( myPrefs.getString( key ) );
    746             myTorrentDoneScriptButton->setText( QFileInfo(path).fileName() );
    747             break;
    748         }
    749 
    750         case Prefs :: PEER_PORT:
    751             myPortLabel->setText( tr( "Status unknown" ) );
    752             myPortButton->setEnabled( true );
    753             break;
    754 
    755         case Prefs :: DOWNLOAD_DIR: {
    756             const QString path( myPrefs.getString( key ) );
    757             myDestinationButton->setText( QFileInfo(path).fileName() );
    758             myFreespaceLabel->setPath (path);
    759             break;
    760         }
    761 
    762         case Prefs :: INCOMPLETE_DIR: {
    763             QString path( myPrefs.getString( key ) );
    764             myIncompleteButton->setText( QFileInfo(path).fileName() );
    765             break;
    766         }
    767 
    768         case Prefs :: INCOMPLETE_DIR_ENABLED: {
    769             const bool enabled = myPrefs.getBool( key );
    770             myIncompleteButton->setEnabled( enabled );
    771             break;
    772         }
    773 
    774         default:
    775             break;
     721      case Prefs :: RPC_ENABLED:
     722      case Prefs :: RPC_WHITELIST_ENABLED:
     723      case Prefs :: RPC_AUTH_REQUIRED:
     724        {
     725          const bool enabled (myPrefs.getBool (Prefs::RPC_ENABLED));
     726          const bool whitelist (myPrefs.getBool (Prefs::RPC_WHITELIST_ENABLED));
     727          const bool auth (myPrefs.getBool (Prefs::RPC_AUTH_REQUIRED));
     728          foreach (QWidget * w, myWebWhitelistWidgets)w->setEnabled (enabled && whitelist);
     729          foreach (QWidget * w, myWebAuthWidgets)w->setEnabled (enabled && auth);
     730          foreach (QWidget * w, myWebWidgets)w->setEnabled (enabled);
     731          break;
     732        }
     733
     734      case Prefs :: ALT_SPEED_LIMIT_TIME_ENABLED:
     735        {
     736          const bool enabled = myPrefs.getBool (key);
     737          foreach (QWidget * w, mySchedWidgets)w->setEnabled (enabled);
     738          break;
     739        }
     740
     741      case Prefs :: BLOCKLIST_ENABLED:
     742        {
     743          const bool enabled = myPrefs.getBool (key);
     744          foreach (QWidget * w, myBlockWidgets)w->setEnabled (enabled);
     745          break;
     746        }
     747
     748      case Prefs :: DIR_WATCH:
     749        myWatchButton->setText (QFileInfo(myPrefs.getString(Prefs::DIR_WATCH)).fileName());
     750        break;
     751
     752      case Prefs :: SCRIPT_TORRENT_DONE_FILENAME:
     753        {
     754          const QString path (myPrefs.getString (key));
     755          myTorrentDoneScriptButton->setText (QFileInfo(path).fileName());
     756          break;
     757        }
     758
     759      case Prefs :: PEER_PORT:
     760        myPortLabel->setText (tr ("Status unknown"));
     761        myPortButton->setEnabled (true);
     762        break;
     763
     764      case Prefs :: DOWNLOAD_DIR:
     765        {
     766          const QString path (myPrefs.getString (key));
     767          myDestinationButton->setText (QFileInfo(path).fileName());
     768          myFreespaceLabel->setPath (path);
     769          break;
     770        }
     771
     772      case Prefs :: INCOMPLETE_DIR:
     773        {
     774          QString path (myPrefs.getString (key));
     775          myIncompleteButton->setText (QFileInfo(path).fileName());
     776          break;
     777        }
     778
     779      case Prefs :: INCOMPLETE_DIR_ENABLED:
     780        {
     781          const bool enabled = myPrefs.getBool (key);
     782          myIncompleteButton->setEnabled (enabled);
     783          break;
     784        }
     785
     786      default:
     787        break;
    776788    }
    777789
    778     key2widget_t::iterator it( myWidgets.find( key ) );
    779     if( it != myWidgets.end( ) )
     790  key2widget_t::iterator it (myWidgets.find (key));
     791  if (it != myWidgets.end ())
    780792    {
    781         QWidget * w( it.value( ) );
    782         QCheckBox * checkBox;
    783         QSpinBox * spin;
    784         QDoubleSpinBox * doubleSpin;
    785         QTimeEdit * timeEdit;
    786         QLineEdit * lineEdit;
    787 
    788         if(( checkBox = qobject_cast<QCheckBox*>(w)))
    789         {
    790             checkBox->setChecked( myPrefs.getBool( key ) );
    791         }
    792         else if(( spin = qobject_cast<QSpinBox*>(w)))
    793         {
    794             spin->setValue( myPrefs.getInt( key ) );
    795         }
    796         else if(( doubleSpin = qobject_cast<QDoubleSpinBox*>(w)))
    797         {
    798             doubleSpin->setValue( myPrefs.getDouble( key ) );
    799         }
    800         else if(( timeEdit = qobject_cast<QTimeEdit*>(w)))
    801         {
    802             const int minutes( myPrefs.getInt( key ) );
    803             timeEdit->setTime( QTime().addSecs( minutes * 60 ) );
    804         }
    805         else if(( lineEdit = qobject_cast<QLineEdit*>(w)))
    806         {
    807             lineEdit->setText( myPrefs.getString( key ) );
    808         }
    809         else if( key == Prefs::ENCRYPTION )
    810         {
    811             QComboBox * comboBox( qobject_cast<QComboBox*>( w ) );
    812             const int index = comboBox->findData( myPrefs.getInt( key ) );
    813             comboBox->setCurrentIndex( index );
     793      QWidget * w (it.value ());
     794      QCheckBox * checkBox;
     795      QSpinBox * spin;
     796      QDoubleSpinBox * doubleSpin;
     797      QTimeEdit * timeEdit;
     798      QLineEdit * lineEdit;
     799
     800      if ((checkBox = qobject_cast<QCheckBox*>(w)))
     801        {
     802          checkBox->setChecked (myPrefs.getBool (key));
     803        }
     804      else if ((spin = qobject_cast<QSpinBox*>(w)))
     805        {
     806          spin->setValue (myPrefs.getInt (key));
     807        }
     808      else if ((doubleSpin = qobject_cast<QDoubleSpinBox*>(w)))
     809        {
     810          doubleSpin->setValue (myPrefs.getDouble (key));
     811        }
     812      else if ((timeEdit = qobject_cast<QTimeEdit*>(w)))
     813        {
     814          const int minutes (myPrefs.getInt (key));
     815          timeEdit->setTime (QTime().addSecs (minutes * 60));
     816        }
     817      else if ((lineEdit = qobject_cast<QLineEdit*>(w)))
     818        {
     819          lineEdit->setText (myPrefs.getString (key));
     820        }
     821      else if (key == Prefs::ENCRYPTION)
     822        {
     823          QComboBox * comboBox (qobject_cast<QComboBox*> (w));
     824          const int index = comboBox->findData (myPrefs.getInt (key));
     825          comboBox->setCurrentIndex (index);
    814826        }
    815827    }
     
    817829
    818830bool
    819 PrefsDialog :: isAllowed( int key ) const
    820 {
    821     Q_UNUSED( key );
    822 
    823     return true;
    824 }
     831PrefsDialog :: isAllowed (int key) const
     832{
     833  Q_UNUSED (key);
     834
     835  return true;
     836}
  • trunk/qt/prefs-dialog.h

    r13991 r14204  
    2020class QAbstractButton;
    2121class QCheckBox;
    22 class QString;
    2322class QDoubleSpinBox;
    24 class QSpinBox;
     23class QHttp;
    2524class QLabel;
    2625class QLineEdit;
    27 class QVBoxLayout;
     26class QMessageBox;
     27class QPushButton;
     28class QSpinBox;
     29class QString;
    2830class QTime;
    2931class QTimeEdit;
     32class QVBoxLayout;
    3033class QWidget;
    31 class QPushButton;
    32 class QMessageBox;
    33 class QHttp;
    3434
    3535class FreespaceLabel;
     
    3939class PrefsDialog: public QDialog
    4040{
    41         Q_OBJECT
     41    Q_OBJECT
    4242
    43     private slots:
    44         void checkBoxToggled( bool checked );
    45         void spinBoxEditingFinished( );
    46         void timeEditingFinished( );
    47         void lineEditingFinished( );
    48         void refreshPref( int key );
    49         void encryptionEdited( int );
    50         void altSpeedDaysEdited( int );
    51         void sessionUpdated( );
    52         void onWatchClicked( );
    53         void onScriptClicked( );
    54         void onIncompleteClicked( );
    55         void onDestinationClicked( );
    56         void onLocationSelected( const QString&, int key );
    57         void onPortTested( bool );
    58         void onPortTest( );
     43  private slots:
     44    void checkBoxToggled (bool checked);
     45    void spinBoxEditingFinished ();
     46    void timeEditingFinished ();
     47    void lineEditingFinished ();
     48    void refreshPref (int key);
     49    void encryptionEdited (int);
     50    void altSpeedDaysEdited (int);
     51    void sessionUpdated ();
     52    void onWatchClicked ();
     53    void onScriptClicked ();
     54    void onIncompleteClicked ();
     55    void onDestinationClicked ();
     56    void onLocationSelected (const QString&, int key);
     57    void onPortTested (bool);
     58    void onPortTest ();
    5959
    60         void onUpdateBlocklistClicked( );
    61         void onUpdateBlocklistCancelled( );
    62         void onBlocklistDialogDestroyed( QObject * );
    63         void onBlocklistUpdated( int n );
     60    void onUpdateBlocklistClicked ();
     61    void onUpdateBlocklistCancelled ();
     62    void onBlocklistDialogDestroyed (QObject *);
     63    void onBlocklistUpdated (int n);
    6464
    65     private:
    66         QDoubleSpinBox * doubleSpinBoxNew( int key, double low, double high, double step, int decimals );
    67         QCheckBox * checkBoxNew( const QString& text, int key );
    68         QSpinBox * spinBoxNew( int key, int low, int high, int step );
    69         QTimeEdit * timeEditNew( int key );
    70         QLineEdit * lineEditNew( int key, int mode = 0 );
    71         void enableBuddyWhenChecked( QCheckBox *, QWidget * );
    72         void updateBlocklistLabel( );
     65  private:
     66    QDoubleSpinBox * doubleSpinBoxNew (int key, double low, double high, double step, int decimals);
     67    QCheckBox * checkBoxNew (const QString& text, int key);
     68    QSpinBox * spinBoxNew (int key, int low, int high, int step);
     69    QTimeEdit * timeEditNew (int key);
     70    QLineEdit * lineEditNew (int key, int mode = 0);
     71    void enableBuddyWhenChecked (QCheckBox *, QWidget *);
     72    void updateBlocklistLabel ();
    7373
    74     public:
    75         PrefsDialog( Session&, Prefs&, QWidget * parent = 0 );
    76         ~PrefsDialog( );
     74  public:
     75    PrefsDialog (Session&, Prefs&, QWidget * parent = 0);
     76    ~PrefsDialog ();
    7777
    78     private:
    79         void setPref( int key, const QVariant& v );
    80         bool isAllowed( int key ) const;
    81         QWidget * createDownloadingTab( );
    82         QWidget * createSeedingTab( );
    83         QWidget * createSpeedTab( );
    84         QWidget * createPrivacyTab( );
    85         QWidget * createNetworkTab( );
    86         QWidget * createDesktopTab( );
    87         QWidget * createRemoteTab( Session& );
     78  private:
     79    void setPref (int key, const QVariant& v);
     80    bool isAllowed (int key) const;
     81    QWidget * createDownloadingTab ();
     82    QWidget * createSeedingTab ();
     83    QWidget * createSpeedTab ();
     84    QWidget * createPrivacyTab ();
     85    QWidget * createNetworkTab ();
     86    QWidget * createDesktopTab ();
     87    QWidget * createRemoteTab (Session&);
    8888
    89     private:
    90         typedef QMap<int,QWidget*> key2widget_t;
    91         key2widget_t myWidgets;
    92         const bool myIsServer;
    93         Session& mySession;
    94         Prefs& myPrefs;
    95         QVBoxLayout * myLayout;
    96         QLabel * myPortLabel;
    97         QPushButton * myPortButton;
    98         QPushButton * myWatchButton;
    99         QPushButton * myTorrentDoneScriptButton;
    100         QCheckBox * myTorrentDoneScriptCheckbox;
    101         QCheckBox * myIncompleteCheckbox;
    102         QPushButton * myIncompleteButton;
    103         QPushButton * myDestinationButton;
    104         QWidgetList myWebWidgets;
    105         QWidgetList myWebAuthWidgets;
    106         QWidgetList myWebWhitelistWidgets;
    107         QWidgetList myProxyWidgets;
    108         QWidgetList myProxyAuthWidgets;
    109         QWidgetList mySchedWidgets;
    110         QWidgetList myBlockWidgets;
    111         QWidgetList myUnsupportedWhenRemote;
    112         FreespaceLabel * myFreespaceLabel;
     89  private:
     90    typedef QMap<int,QWidget*> key2widget_t;
     91    key2widget_t myWidgets;
     92    const bool myIsServer;
     93    Session& mySession;
     94    Prefs& myPrefs;
     95    QVBoxLayout * myLayout;
     96    QLabel * myPortLabel;
     97    QPushButton * myPortButton;
     98    QPushButton * myWatchButton;
     99    QPushButton * myTorrentDoneScriptButton;
     100    QCheckBox * myTorrentDoneScriptCheckbox;
     101    QCheckBox * myIncompleteCheckbox;
     102    QPushButton * myIncompleteButton;
     103    QPushButton * myDestinationButton;
     104    QWidgetList myWebWidgets;
     105    QWidgetList myWebAuthWidgets;
     106    QWidgetList myWebWhitelistWidgets;
     107    QWidgetList myProxyWidgets;
     108    QWidgetList myProxyAuthWidgets;
     109    QWidgetList mySchedWidgets;
     110    QWidgetList myBlockWidgets;
     111    QWidgetList myUnsupportedWhenRemote;
     112    FreespaceLabel * myFreespaceLabel;
    113113
    114         int myBlocklistHttpTag;
    115         QHttp * myBlocklistHttp;
    116         QMessageBox * myBlocklistDialog;
    117         QLabel * myBlocklistLabel;
     114    int myBlocklistHttpTag;
     115    QHttp * myBlocklistHttp;
     116    QMessageBox * myBlocklistDialog;
     117    QLabel * myBlocklistLabel;
    118118};
    119119
  • trunk/qt/relocate.h

    r13944 r14204  
    4747  public:
    4848    RelocateDialog (Session&, TorrentModel&, const QSet<int>& ids, QWidget * parent = 0);
    49     ~RelocateDialog () { }
     49    ~RelocateDialog () {}
    5050};
    5151
  • trunk/qt/session-dialog.cc

    r11092 r14204  
    2929
    3030void
    31 SessionDialog :: onAccepted( )
     31SessionDialog :: onAccepted ()
    3232{
    33     myPrefs.set( Prefs::SESSION_IS_REMOTE, myRemoteRadioButton->isChecked( ) );
    34     myPrefs.set( Prefs::SESSION_REMOTE_HOST, myHostLineEdit->text( ) );
    35     myPrefs.set( Prefs::SESSION_REMOTE_PORT, myPortSpinBox->value( ) );
    36     myPrefs.set( Prefs::SESSION_REMOTE_AUTH, myAuthCheckBox->isChecked( ) );
    37     myPrefs.set( Prefs::SESSION_REMOTE_USERNAME, myUsernameLineEdit->text( ) );
    38     myPrefs.set( Prefs::SESSION_REMOTE_PASSWORD, myPasswordLineEdit->text( ) );
    39     mySession.restart( );
    40     hide( );
     33  myPrefs.set (Prefs::SESSION_IS_REMOTE, myRemoteRadioButton->isChecked ());
     34  myPrefs.set (Prefs::SESSION_REMOTE_HOST, myHostLineEdit->text ());
     35  myPrefs.set (Prefs::SESSION_REMOTE_PORT, myPortSpinBox->value ());
     36  myPrefs.set (Prefs::SESSION_REMOTE_AUTH, myAuthCheckBox->isChecked ());
     37  myPrefs.set (Prefs::SESSION_REMOTE_USERNAME, myUsernameLineEdit->text ());
     38  myPrefs.set (Prefs::SESSION_REMOTE_PASSWORD, myPasswordLineEdit->text ());
     39  mySession.restart ();
     40  hide ();
    4141}
    4242
    4343void
    44 SessionDialog :: resensitize( )
     44SessionDialog :: resensitize ()
    4545{
    46     const bool isRemote = myRemoteRadioButton->isChecked();
    47     const bool useAuth = myAuthCheckBox->isChecked();
     46  const bool isRemote = myRemoteRadioButton->isChecked();
     47  const bool useAuth = myAuthCheckBox->isChecked();
    4848
    49     foreach( QWidget * w, myRemoteWidgets )
    50         w->setEnabled( isRemote );
     49  foreach (QWidget * w, myRemoteWidgets)
     50    w->setEnabled (isRemote);
    5151
    52     foreach( QWidget * w, myAuthWidgets )
    53         w->setEnabled( isRemote && useAuth );
     52  foreach (QWidget * w, myAuthWidgets)
     53    w->setEnabled (isRemote && useAuth);
    5454}
    5555
     
    5858***/
    5959
    60 SessionDialog :: SessionDialog( Session& session, Prefs& prefs, QWidget * parent ):
    61     QDialog( parent ),
    62     mySession( session ),
    63     myPrefs( prefs )
     60SessionDialog :: SessionDialog (Session& session, Prefs& prefs, QWidget * parent):
     61  QDialog (parent),
     62  mySession (session),
     63  myPrefs (prefs)
    6464{
    65     QWidget * l;
    66     QSpinBox * sb;
    67     QCheckBox * cb;
    68     QLineEdit * le;
    69     QRadioButton * rb;
     65  QWidget * l;
     66  QSpinBox * sb;
     67  QCheckBox * cb;
     68  QLineEdit * le;
     69  QRadioButton * rb;
    7070
    71     setWindowTitle( tr( "Change Session" ) );
    72     QVBoxLayout * top = new QVBoxLayout( this );
    73     top->setSpacing( HIG :: PAD );
     71  setWindowTitle (tr ("Change Session"));
     72  QVBoxLayout * top = new QVBoxLayout (this);
     73  top->setSpacing (HIG :: PAD);
    7474
    75     HIG * hig = new HIG;
    76     hig->setContentsMargins( 0, 0, 0, 0 );
    77     hig->addSectionTitle( tr( "Source" ) );
    78     rb = new QRadioButton( tr( "Start &Local Session" ) );
    79     rb->setChecked( !prefs.get<bool>(Prefs::SESSION_IS_REMOTE) );
    80     connect( rb, SIGNAL(toggled(bool)), this, SLOT(resensitize()));
    81     hig->addWideControl( rb );
    82     rb = myRemoteRadioButton = new QRadioButton( tr( "Connect to &Remote Session" ) );
    83     rb->setChecked( prefs.get<bool>(Prefs::SESSION_IS_REMOTE) );
    84     connect( rb, SIGNAL(toggled(bool)), this, SLOT(resensitize()));
    85     hig->addWideControl( rb );
    86     le = myHostLineEdit = new QLineEdit( );
    87     le->setText( prefs.get<QString>(Prefs::SESSION_REMOTE_HOST) );
    88     l = hig->addRow( tr( "&Host:" ), le );
    89     myRemoteWidgets << l << le;
    90     sb = myPortSpinBox = new QSpinBox;
    91     sb->setRange( 1, 65535 );
    92     sb->setValue( prefs.get<int>(Prefs::SESSION_REMOTE_PORT) );
    93     l = hig->addRow( tr( "&Port:" ), sb );
    94     myRemoteWidgets << l << sb;
    95     cb = myAuthCheckBox = new QCheckBox( tr( "&Authentication required" ) );
    96     cb->setChecked( prefs.get<bool>(Prefs::SESSION_REMOTE_AUTH) );
    97     connect( cb, SIGNAL(toggled(bool)), this, SLOT(resensitize()));
    98     myRemoteWidgets << cb;
    99     hig->addWideControl( cb );
    100     le = myUsernameLineEdit = new QLineEdit( );
    101     le->setText( prefs.get<QString>(Prefs::SESSION_REMOTE_USERNAME) );
    102     l = hig->addRow( tr( "&Username:" ), le );
    103     myAuthWidgets << l << le;
    104     le = myPasswordLineEdit = new QLineEdit( );
    105     le->setEchoMode( QLineEdit::Password );
    106     le->setText( prefs.get<QString>(Prefs::SESSION_REMOTE_PASSWORD) );
    107     l = hig->addRow( tr( "Pass&word:" ), le );
    108     myAuthWidgets << l << le;
    109     hig->finish( );
    110     top->addWidget( hig, 1 );
    111     resensitize( );
     75  HIG * hig = new HIG;
     76  hig->setContentsMargins (0, 0, 0, 0);
     77  hig->addSectionTitle (tr ("Source"));
     78  rb = new QRadioButton (tr ("Start &Local Session"));
     79  rb->setChecked (!prefs.get<bool>(Prefs::SESSION_IS_REMOTE));
     80  connect (rb, SIGNAL(toggled(bool)), this, SLOT(resensitize()));
     81  hig->addWideControl (rb);
     82  rb = myRemoteRadioButton = new QRadioButton (tr ("Connect to &Remote Session"));
     83  rb->setChecked (prefs.get<bool>(Prefs::SESSION_IS_REMOTE));
     84  connect (rb, SIGNAL(toggled(bool)), this, SLOT(resensitize()));
     85  hig->addWideControl (rb);
     86  le = myHostLineEdit = new QLineEdit ();
     87  le->setText (prefs.get<QString>(Prefs::SESSION_REMOTE_HOST));
     88  l = hig->addRow (tr ("&Host:"), le);
     89  myRemoteWidgets << l << le;
     90  sb = myPortSpinBox = new QSpinBox;
     91  sb->setRange (1, 65535);
     92  sb->setValue (prefs.get<int>(Prefs::SESSION_REMOTE_PORT));
     93  l = hig->addRow (tr ("&Port:"), sb);
     94  myRemoteWidgets << l << sb;
     95  cb = myAuthCheckBox = new QCheckBox (tr ("&Authentication required"));
     96  cb->setChecked (prefs.get<bool>(Prefs::SESSION_REMOTE_AUTH));
     97  connect (cb, SIGNAL(toggled(bool)), this, SLOT(resensitize()));
     98  myRemoteWidgets << cb;
     99  hig->addWideControl (cb);
     100  le = myUsernameLineEdit = new QLineEdit ();
     101  le->setText (prefs.get<QString>(Prefs::SESSION_REMOTE_USERNAME));
     102  l = hig->addRow (tr ("&Username:"), le);
     103  myAuthWidgets << l << le;
     104  le = myPasswordLineEdit = new QLineEdit ();
     105  le->setEchoMode (QLineEdit::Password);
     106  le->setText (prefs.get<QString>(Prefs::SESSION_REMOTE_PASSWORD));
     107  l = hig->addRow (tr ("Pass&word:"), le);
     108  myAuthWidgets << l << le;
     109  hig->finish ();
     110  top->addWidget (hig, 1);
     111  resensitize ();
    112112
    113     QDialogButtonBox * buttons = new QDialogButtonBox( QDialogButtonBox::Cancel|QDialogButtonBox::Ok );
    114     connect( buttons, SIGNAL(rejected()), this, SLOT(hide()));
    115     connect( buttons, SIGNAL(accepted()), this, SLOT(onAccepted()));
    116     top->addWidget( buttons, 0 );
     113  QDialogButtonBox * buttons = new QDialogButtonBox (QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
     114  connect (buttons, SIGNAL(rejected()), this, SLOT(hide()));
     115  connect (buttons, SIGNAL(accepted()), this, SLOT(onAccepted()));
     116  top->addWidget (buttons, 0);
    117117}
  • trunk/qt/session-dialog.h

    r11092 r14204  
    2626class SessionDialog: public QDialog
    2727{
    28         Q_OBJECT
     28    Q_OBJECT
    2929
    30     public:
    31         SessionDialog( Session& session, Prefs& prefs, QWidget * parent = 0 );
    32         ~SessionDialog( ) { }
     30  public:
     31    SessionDialog (Session& session, Prefs& prefs, QWidget * parent = 0);
     32    ~SessionDialog () {}
    3333
    34     private slots:
    35         void onAccepted( );
    36         void resensitize( );
     34  private slots:
     35    void onAccepted ();
     36    void resensitize ();
    3737
    38     private:
    39         QCheckBox * myAuthCheckBox;
    40         QRadioButton * myRemoteRadioButton;
    41         QLineEdit * myHostLineEdit;
    42         QSpinBox * myPortSpinBox;
    43         QLineEdit * myUsernameLineEdit;
    44         QLineEdit * myPasswordLineEdit;
    45         QCheckBox * myAutomaticCheckBox;
     38  private:
     39    QCheckBox * myAuthCheckBox;
     40    QRadioButton * myRemoteRadioButton;
     41    QLineEdit * myHostLineEdit;
     42    QSpinBox * myPortSpinBox;
     43    QLineEdit * myUsernameLineEdit;
     44    QLineEdit * myPasswordLineEdit;
     45    QCheckBox * myAutomaticCheckBox;
    4646
    47     private:
    48         Session& mySession;
    49         Prefs& myPrefs;
    50         QWidgetList myRemoteWidgets;
    51         QWidgetList myAuthWidgets;
     47  private:
     48    Session& mySession;
     49    Prefs& myPrefs;
     50    QWidgetList myRemoteWidgets;
     51    QWidgetList myAuthWidgets;
    5252};
    5353
  • trunk/qt/speed.h

    r13944 r14204  
    2323
    2424  public:
    25     Speed (): _Bps (0) { }
     25    Speed (): _Bps (0) {}
    2626    double KBps () const;
    2727    int Bps () const { return _Bps; }
  • trunk/qt/squeezelabel.cc

    r10954 r14204  
    4747#include "squeezelabel.h"
    4848
    49 void SqueezeLabel::init()
     49void
     50SqueezeLabel :: init ()
    5051{
    51     setTextInteractionFlags(Qt::TextSelectableByMouse);
     52  setTextInteractionFlags(Qt::TextSelectableByMouse);
    5253}
    5354
    54 SqueezeLabel::SqueezeLabel(const QString& text, QWidget *parent): QLabel(text, parent)
     55SqueezeLabel :: SqueezeLabel (const QString& text, QWidget *parent):
     56  QLabel (text, parent)
    5557{
    56     init();
     58  init();
    5759}
    5860
    59 SqueezeLabel::SqueezeLabel(QWidget *parent) : QLabel(parent)
     61SqueezeLabel :: SqueezeLabel (QWidget * parent):
     62  QLabel (parent)
    6063{
    61     init();
     64  init();
    6265}
    6366
    64 void SqueezeLabel::paintEvent(QPaintEvent* paintEvent)
     67void
     68SqueezeLabel :: paintEvent (QPaintEvent * paintEvent)
    6569{
    66     Q_UNUSED(paintEvent);
     70  Q_UNUSED (paintEvent);
    6771
    68     QPainter painter(this);
    69     QFontMetrics fm = fontMetrics();
    70     QStyleOption opt;
    71     opt.initFrom(this);
    72     const QString elidedText = fm.elidedText( text(), Qt::ElideMiddle, width());
    73     style()->drawItemText(&painter, contentsRect(), alignment(), opt.palette, isEnabled(), elidedText, foregroundRole());
     72  QPainter painter (this);
     73  QFontMetrics fm = fontMetrics ();
     74  QStyleOption opt;
     75  opt.initFrom (this);
     76  const QString elidedText = fm.elidedText (text(), Qt::ElideMiddle, width());
     77  style()->drawItemText (&painter,
     78                         contentsRect(),
     79                         alignment(),
     80                         opt.palette,
     81                         isEnabled(),
     82                         elidedText,
     83                         foregroundRole());
    7484}
  • trunk/qt/squeezelabel.h

    r14150 r14204  
    4949    Q_OBJECT
    5050
    51 public:
    52     SqueezeLabel(QWidget *parent = 0);
    53     SqueezeLabel(const QString& text, QWidget *parent = 0);
     51  public:
     52    SqueezeLabel (QWidget *parent=0);
     53    SqueezeLabel (const QString& text, QWidget *parent=0);
    5454
    55 protected:
    56     void init();
    57     void paintEvent(QPaintEvent* paintEvent);
     55  protected:
     56    void init ();
     57    void paintEvent (QPaintEvent* paintEvent);
    5858};
    5959
  • trunk/qt/torrent-delegate-min.cc

    r14019 r14204  
    3333enum
    3434{
    35    GUI_PAD = 6,
    36    BAR_WIDTH = 50,
    37    BAR_HEIGHT = 12,
    38    LINE_SPACING = 4
     35  GUI_PAD = 6,
     36  BAR_WIDTH = 50,
     37  BAR_HEIGHT = 12,
     38  LINE_SPACING = 4
    3939};
    4040
     
    4848
    4949QSize
    50 TorrentDelegateMin :: sizeHint( const QStyleOptionViewItem& option, const Torrent& tor ) const
     50TorrentDelegateMin :: sizeHint (const QStyleOptionViewItem & option,
     51                                const Torrent              & tor) const
    5152{
    52     const QStyle* style( QApplication::style( ) );
    53     static const int iconSize( style->pixelMetric( QStyle :: PM_SmallIconSize ) );
     53  const QStyle* style (QApplication::style());
     54  static const int iconSize (style->pixelMetric (QStyle :: PM_SmallIconSize));
    5455
    55     QFont nameFont( option.font );
    56     const QFontMetrics nameFM( nameFont );
    57     const bool isMagnet( !tor.hasMetadata( ) );
    58     const QString nameStr = (isMagnet ? progressString( tor ) : tor.name( ) );
    59     const int nameWidth = nameFM.width( nameStr );
     56  QFont nameFont (option.font);
     57  const QFontMetrics nameFM (nameFont);
     58  const bool isMagnet (!tor.hasMetadata());
     59  const QString nameStr = (isMagnet ? progressString (tor) : tor.name());
     60  const int nameWidth = nameFM.width (nameStr);
    6061
    61     QFont statusFont( option.font );
    62     statusFont.setPointSize( int( option.font.pointSize( ) * 0.85 ) );
    63     const QFontMetrics statusFM( statusFont );
    64     const QString statusStr( shortStatusString( tor ) );
    65     const int statusWidth = statusFM.width( statusStr );
     62  QFont statusFont (option.font);
     63  statusFont.setPointSize (int (option.font.pointSize() * 0.85));
     64  const QFontMetrics statusFM (statusFont);
     65  const QString statusStr (shortStatusString (tor));
     66  const int statusWidth = statusFM.width (statusStr);
    6667
    67     const QSize m( margin( *style ) );
     68  const QSize m (margin (*style));
    6869
    69     return QSize( m.width()*2 + iconSize + GUI_PAD + nameWidth
    70                                          + GUI_PAD + statusWidth
    71                                          + GUI_PAD + BAR_WIDTH,
    72                   m.height()*2 + std::max( nameFM.height(), (int)BAR_HEIGHT ) );
     70  return QSize (m.width()*2 + iconSize + GUI_PAD + nameWidth
     71                                       + GUI_PAD + statusWidth
     72                                       + GUI_PAD + BAR_WIDTH,
     73                m.height()*2 + std::max (nameFM.height(), (int)BAR_HEIGHT));
    7374}
    7475
    7576void
    76 TorrentDelegateMin :: drawTorrent( QPainter * painter, const QStyleOptionViewItem& option, const Torrent& tor ) const
     77TorrentDelegateMin :: drawTorrent (QPainter                   * painter,
     78                                   const QStyleOptionViewItem & option,
     79                                   const Torrent              & tor) const
    7780{
    78     const bool isPaused( tor.isPaused( ) );
    79     const QStyle * style( QApplication::style( ) );
    80     static const int iconSize( style->pixelMetric( QStyle :: PM_SmallIconSize ) );
     81  const bool isPaused (tor.isPaused());
     82  const QStyle * style (QApplication::style());
     83  static const int iconSize (style->pixelMetric (QStyle :: PM_SmallIconSize));
    8184
    82     QFont nameFont( option.font );
    83     const QFontMetrics nameFM( nameFont );
    84     const bool isMagnet( !tor.hasMetadata( ) );
    85     const QString nameStr = (isMagnet ? progressString( tor ) : tor.name( ) );
     85  QFont nameFont (option.font);
     86  const QFontMetrics nameFM (nameFont);
     87  const bool isMagnet (!tor.hasMetadata());
     88  const QString nameStr = (isMagnet ? progressString (tor) : tor.name());
    8689
    87     QFont statusFont( option.font );
    88     statusFont.setPointSize( int( option.font.pointSize( ) * 0.85 ) );
    89     const QFontMetrics statusFM( statusFont );
    90     const QString statusStr( shortStatusString( tor ) );
    91     const QSize statusSize( statusFM.size( 0, statusStr ) );
     90  QFont statusFont (option.font);
     91  statusFont.setPointSize (int (option.font.pointSize() * 0.85));
     92  const QFontMetrics statusFM (statusFont);
     93  const QString statusStr (shortStatusString (tor));
     94  const QSize statusSize (statusFM.size (0, statusStr));
    9295
    93     painter->save( );
     96  painter->save();
    9497
    95     if (option.state & QStyle::State_Selected) {
    96         QPalette::ColorGroup cg = option.state & QStyle::State_Enabled
    97                                   ? QPalette::Normal : QPalette::Disabled;
    98         if (cg == QPalette::Normal && !(option.state & QStyle::State_Active))
    99             cg = QPalette::Inactive;
     98  if (option.state & QStyle::State_Selected)
     99    {
     100      QPalette::ColorGroup cg = option.state & QStyle::State_Enabled
     101                              ? QPalette::Normal : QPalette::Disabled;
     102      if (cg == QPalette::Normal && !(option.state & QStyle::State_Active))
     103        cg = QPalette::Inactive;
    100104
    101         painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Highlight));
     105      painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Highlight));
    102106    }
    103107
    104     QIcon::Mode im;
    105     if( isPaused || !(option.state & QStyle::State_Enabled ) ) im = QIcon::Disabled;
    106     else if( option.state & QStyle::State_Selected ) im = QIcon::Selected;
    107     else im = QIcon::Normal;
     108  QIcon::Mode im;
     109  if (isPaused || !(option.state & QStyle::State_Enabled))
     110    im = QIcon::Disabled;
     111  else if (option.state & QStyle::State_Selected)
     112    im = QIcon::Selected;
     113  else
     114    im = QIcon::Normal;
    108115
    109     QIcon::State qs;
    110     if( isPaused ) qs = QIcon::Off;
    111     else qs = QIcon::On;
     116  QIcon::State qs;
     117  if (isPaused)
     118    qs = QIcon::Off;
     119  else
     120    qs = QIcon::On;
    112121
    113     QPalette::ColorGroup cg = QPalette::Normal;
    114     if( isPaused || !(option.state & QStyle::State_Enabled ) ) cg = QPalette::Disabled;
    115     if( cg == QPalette::Normal && !(option.state & QStyle::State_Active ) ) cg = QPalette::Inactive;
     122  QPalette::ColorGroup cg = QPalette::Normal;
     123  if (isPaused || !(option.state & QStyle::State_Enabled))
     124    cg = QPalette::Disabled;
     125  if (cg == QPalette::Normal && !(option.state & QStyle::State_Active))
     126    cg = QPalette::Inactive;
    116127
    117     QPalette::ColorRole cr;
    118     if( option.state & QStyle::State_Selected ) cr = QPalette::HighlightedText;
    119     else cr = QPalette::Text;
     128  QPalette::ColorRole cr;
     129  if (option.state & QStyle::State_Selected)
     130    cr = QPalette::HighlightedText;
     131  else
     132    cr = QPalette::Text;
    120133
    121     QStyle::State progressBarState( option.state );
    122     if( isPaused ) progressBarState = QStyle::State_None;
    123     progressBarState |= QStyle::State_Small;
     134  QStyle::State progressBarState (option.state);
     135  if (isPaused)
     136    progressBarState = QStyle::State_None;
     137  progressBarState |= QStyle::State_Small;
    124138
    125     // layout
    126     const QSize m( margin( *style ) );
    127     QRect fillArea( option.rect );
    128     fillArea.adjust( m.width(), m.height(), -m.width(), -m.height() );
    129     const QRect iconArea( fillArea.x( ),
    130                           fillArea.y( ) + ( fillArea.height( ) - iconSize ) / 2,
    131                           iconSize,
    132                           iconSize );
    133     const QRect barArea( fillArea.x( ) + fillArea.width( ) - BAR_WIDTH,
    134                          fillArea.y( ) + ( fillArea.height( ) - BAR_HEIGHT ) / 2,
    135                          BAR_WIDTH,
    136                          BAR_HEIGHT );
    137     const QRect statusArea( barArea.x( ) - GUI_PAD - statusSize.width( ),
    138                             fillArea.y( ) + ( fillArea.height( ) - statusSize.height( ) ) / 2,
    139                             fillArea.width( ),
    140                             fillArea.height( ) );
    141     const QRect nameArea( iconArea.x( ) + iconArea.width( ) + GUI_PAD,
    142                           fillArea.y( ),
    143                           statusArea.x( ) - ( iconArea.x( ) + iconArea.width( ) + GUI_PAD * 2 ),
    144                           fillArea.height( ) );
     139  // layout
     140  const QSize m (margin (*style));
     141  QRect fillArea (option.rect);
     142  fillArea.adjust (m.width(), m.height(), -m.width(), -m.height());
     143  const QRect iconArea (fillArea.x(),
     144                        fillArea.y() +  (fillArea.height() - iconSize) / 2,
     145                        iconSize,
     146                        iconSize);
     147  const QRect barArea (fillArea.x() + fillArea.width() - BAR_WIDTH,
     148                       fillArea.y() +  (fillArea.height() - BAR_HEIGHT) / 2,
     149                       BAR_WIDTH,
     150                       BAR_HEIGHT);
     151  const QRect statusArea (barArea.x() - GUI_PAD - statusSize.width(),
     152                          fillArea.y() +  (fillArea.height() - statusSize.height()) / 2,
     153                          fillArea.width(),
     154                          fillArea.height());
     155  const QRect nameArea (iconArea.x() + iconArea.width() + GUI_PAD,
     156                        fillArea.y(),
     157                        statusArea.x() -  (iconArea.x() + iconArea.width() + GUI_PAD * 2),
     158                        fillArea.height());
    145159
    146     // render
    147     if( tor.hasError( ) )
    148         painter->setPen( QColor( "red" ) );
    149     else
    150         painter->setPen( option.palette.color( cg, cr ) );
    151     tor.getMimeTypeIcon().paint( painter, iconArea, Qt::AlignCenter, im, qs );
    152     painter->setFont( nameFont );
    153     painter->drawText( nameArea, 0, nameFM.elidedText( nameStr, Qt::ElideRight, nameArea.width( ) ) );
    154     painter->setFont( statusFont );
    155     painter->drawText( statusArea, 0, statusStr );
    156     myProgressBarStyle->rect = barArea;
    157     if ( tor.isDownloading() ) {
    158         myProgressBarStyle->palette.setBrush( QPalette::Highlight, blueBrush );
    159         myProgressBarStyle->palette.setColor( QPalette::Base, blueBack );
    160         myProgressBarStyle->palette.setColor( QPalette::Window, blueBack );
     160  // render
     161  if (tor.hasError())
     162    painter->setPen (QColor ("red"));
     163  else
     164    painter->setPen (option.palette.color (cg, cr));
     165  tor.getMimeTypeIcon().paint (painter, iconArea, Qt::AlignCenter, im, qs);
     166  painter->setFont (nameFont);
     167  painter->drawText (nameArea, 0, nameFM.elidedText (nameStr, Qt::ElideRight, nameArea.width()));
     168  painter->setFont (statusFont);
     169  painter->drawText (statusArea, 0, statusStr);
     170  myProgressBarStyle->rect = barArea;
     171  if (tor.isDownloading())
     172    {
     173      myProgressBarStyle->palette.setBrush (QPalette::Highlight, blueBrush);
     174      myProgressBarStyle->palette.setColor (QPalette::Base, blueBack);
     175      myProgressBarStyle->palette.setColor (QPalette::Window, blueBack);
    161176    }
    162     else if ( tor.isSeeding() ) {
    163         myProgressBarStyle->palette.setBrush( QPalette::Highlight, greenBrush );
    164         myProgressBarStyle->palette.setColor( QPalette::Base, greenBack );
    165         myProgressBarStyle->palette.setColor( QPalette::Window, greenBack );
     177  else if (tor.isSeeding())
     178    {
     179      myProgressBarStyle->palette.setBrush (QPalette::Highlight, greenBrush);
     180      myProgressBarStyle->palette.setColor (QPalette::Base, greenBack);
     181      myProgressBarStyle->palette.setColor (QPalette::Window, greenBack);
    166182    }
    167     else {
    168         myProgressBarStyle->palette.setBrush( QPalette::Highlight, silverBrush );
    169         myProgressBarStyle->palette.setColor( QPalette::Base, silverBack );
    170         myProgressBarStyle->palette.setColor( QPalette::Window, silverBack );
     183  else
     184    {
     185      myProgressBarStyle->palette.setBrush (QPalette::Highlight, silverBrush);
     186      myProgressBarStyle->palette.setColor (QPalette::Base, silverBack);
     187      myProgressBarStyle->palette.setColor (QPalette::Window, silverBack);
    171188    }
    172     myProgressBarStyle->state = progressBarState;
    173     char buf[32];
    174     tr_snprintf( buf, sizeof( buf ), "%d%%", (int)tr_truncd( 100.0 * tor.percentDone( ), 0 ) );
    175     myProgressBarStyle->text = buf;
    176     myProgressBarStyle->textVisible = true;
    177     myProgressBarStyle->textAlignment = Qt::AlignCenter;
    178     setProgressBarPercentDone( option, tor );
    179     style->drawControl( QStyle::CE_ProgressBar, myProgressBarStyle, painter );
     189  myProgressBarStyle->state = progressBarState;
     190  char buf[32];
     191  tr_snprintf (buf, sizeof (buf), "%d%%", (int)tr_truncd (100.0 * tor.percentDone(), 0));
     192  myProgressBarStyle->text = buf;
     193  myProgressBarStyle->textVisible = true;
     194  myProgressBarStyle->textAlignment = Qt::AlignCenter;
     195  setProgressBarPercentDone (option, tor);
     196  style->drawControl (QStyle::CE_ProgressBar, myProgressBarStyle, painter);
    180197
    181     painter->restore( );
     198  painter->restore();
    182199}
  • trunk/qt/torrent-delegate-min.h

    r11092 r14204  
    2424class TorrentDelegateMin: public TorrentDelegate
    2525{
    26         Q_OBJECT
     26    Q_OBJECT
    2727
    28     protected:
    29         virtual QSize sizeHint( const QStyleOptionViewItem&, const Torrent& ) const;
    30         void drawTorrent( QPainter* painter, const QStyleOptionViewItem& option, const Torrent& ) const;
     28  protected:
     29    virtual QSize sizeHint (const QStyleOptionViewItem&, const Torrent&) const;
     30    void drawTorrent (QPainter* painter, const QStyleOptionViewItem& option, const Torrent&) const;
    3131
    32     public:
    33         explicit TorrentDelegateMin( QObject * parent=0 ): TorrentDelegate(parent) { }
    34         virtual ~TorrentDelegateMin( ) { }
     32  public:
     33    explicit TorrentDelegateMin (QObject * parent=0): TorrentDelegate(parent) {}
     34    virtual ~TorrentDelegateMin () {}
    3535};
    3636
  • trunk/qt/torrent-delegate.cc

    r14185 r14204  
    3030enum
    3131{
    32    GUI_PAD = 6,
    33    BAR_HEIGHT = 12
     32  GUI_PAD = 6,
     33  BAR_HEIGHT = 12
    3434};
    3535
     
    4141QColor TorrentDelegate :: silverBack;
    4242
    43 TorrentDelegate :: TorrentDelegate( QObject * parent ):
    44     QStyledItemDelegate( parent ),
    45     myProgressBarStyle( new QStyleOptionProgressBar )
    46 {
    47     myProgressBarStyle->minimum = 0;
    48     myProgressBarStyle->maximum = 1000;
    49 
    50     greenBrush = QColor("forestgreen");
    51     greenBack = QColor("darkseagreen");
    52 
    53     blueBrush = QColor("steelblue");
    54     blueBack = QColor("lightgrey");
    55 
    56     silverBrush = QColor("silver");
    57     silverBack = QColor("grey");
    58 }
    59 
    60 TorrentDelegate :: ~TorrentDelegate( )
    61 {
    62     delete myProgressBarStyle;
     43TorrentDelegate :: TorrentDelegate (QObject * parent):
     44  QStyledItemDelegate (parent),
     45  myProgressBarStyle (new QStyleOptionProgressBar)
     46{
     47  myProgressBarStyle->minimum = 0;
     48  myProgressBarStyle->maximum = 1000;
     49
     50  greenBrush = QColor ("forestgreen");
     51  greenBack = QColor ("darkseagreen");
     52
     53  blueBrush = QColor ("steelblue");
     54  blueBack = QColor ("lightgrey");
     55
     56  silverBrush = QColor ("silver");
     57  silverBack = QColor ("grey");
     58}
     59
     60TorrentDelegate :: ~TorrentDelegate ()
     61{
     62  delete myProgressBarStyle;
    6363}
    6464
     
    6868
    6969QSize
    70 TorrentDelegate :: margin( const QStyle& style ) const
    71 {
    72     Q_UNUSED( style );
    73 
    74     return QSize( 4, 4 );
     70TorrentDelegate :: margin (const QStyle& style) const
     71{
     72  Q_UNUSED (style);
     73
     74  return QSize (4, 4);
    7575}
    7676
    7777QString
    78 TorrentDelegate :: progressString( const Torrent& tor ) const
    79 {
    80     const bool isMagnet( !tor.hasMetadata( ) );
    81     const bool isDone( tor.isDone( ) );
    82     const bool isSeed( tor.isSeed( ) );
    83     const uint64_t haveTotal( tor.haveTotal( ) );
    84     QString str;
    85     double seedRatio;
    86     const bool hasSeedRatio( tor.getSeedRatio( seedRatio ) );
    87 
    88     if( isMagnet ) // magnet link with no metadata
    89     {
    90         /* %1 is the percentage of torrent metadata downloaded */
    91         str = tr( "Magnetized transfer - retrieving metadata (%1%)" )
    92             .arg( Formatter::percentToString( tor.metadataPercentDone() * 100.0 ) );
    93     }
    94     else if( !isDone ) // downloading
    95     {
    96         /* %1 is how much we've got,
    97            %2 is how much we'll have when done,
    98            %3 is a percentage of the two */
    99         str = tr( "%1 of %2 (%3%)" ).arg( Formatter::sizeToString( haveTotal ) )
    100                                     .arg( Formatter::sizeToString( tor.sizeWhenDone( ) ) )
    101                                     .arg( Formatter::percentToString( tor.percentDone( ) * 100.0 ) );
    102     }
    103     else if( !isSeed ) // partial seed
    104     {
    105         if( hasSeedRatio )
     78TorrentDelegate :: progressString (const Torrent& tor) const
     79{
     80  const bool isMagnet (!tor.hasMetadata());
     81  const bool isDone (tor.isDone ());
     82  const bool isSeed (tor.isSeed ());
     83  const uint64_t haveTotal (tor.haveTotal());
     84  QString str;
     85  double seedRatio;
     86  const bool hasSeedRatio (tor.getSeedRatio (seedRatio));
     87
     88  if (isMagnet) // magnet link with no metadata
     89    {
     90      // %1 is the percentage of torrent metadata downloaded
     91      str = tr ("Magnetized transfer - retrieving metadata (%1%)")
     92            .arg (Formatter::percentToString (tor.metadataPercentDone() * 100.0));
     93    }
     94  else if (!isDone) // downloading
     95    {
     96      /* %1 is how much we've got,
     97         %2 is how much we'll have when done,
     98         %3 is a percentage of the two */
     99      str = tr ("%1 of %2 (%3%)")
     100            .arg (Formatter::sizeToString (haveTotal))
     101            .arg (Formatter::sizeToString (tor.sizeWhenDone()))
     102            .arg (Formatter::percentToString (tor.percentDone() * 100.0));
     103    }
     104  else if (!isSeed) // partial seed
     105    {
     106      if (hasSeedRatio)
    106107        {
    107             /* %1 is how much we've got,
    108                %2 is the torrent's total size,
    109                %3 is a percentage of the two,
    110                %4 is how much we've uploaded,
    111                %5 is our upload-to-download ratio
    112                %6 is the ratio we want to reach before we stop uploading */
    113             str = tr( "%1 of %2 (%3%), uploaded %4 (Ratio: %5 Goal: %6)" )
    114                   .arg( Formatter::sizeToString( haveTotal ) )
    115                   .arg( Formatter::sizeToString( tor.totalSize( ) ) )
    116                   .arg( Formatter::percentToString( tor.percentComplete( ) * 100.0 ) )
    117                   .arg( Formatter::sizeToString( tor.uploadedEver( ) ) )
    118                   .arg( Formatter::ratioToString( tor.ratio( ) ) )
    119                   .arg( Formatter::ratioToString( seedRatio ) );
     108          /* %1 is how much we've got,
     109             %2 is the torrent's total size,
     110             %3 is a percentage of the two,
     111             %4 is how much we've uploaded,
     112             %5 is our upload-to-download ratio
     113             %6 is the ratio we want to reach before we stop uploading */
     114          str = tr ("%1 of %2 (%3%), uploaded %4 (Ratio: %5 Goal: %6)")
     115                .arg (Formatter::sizeToString (haveTotal))
     116                .arg (Formatter::sizeToString (tor.totalSize()))
     117                .arg (Formatter::percentToString (tor.percentComplete() * 100.0))
     118                .arg (Formatter::sizeToString (tor.uploadedEver()))
     119                .arg (Formatter::ratioToString (tor.ratio()))
     120                .arg (Formatter::ratioToString (seedRatio));
    120121        }
    121122        else
     
    126127               %4 is how much we've uploaded,
    127128               %5 is our upload-to-download ratio */
    128             str = tr( "%1 of %2 (%3%), uploaded %4 (Ratio: %5)" )
    129                   .arg( Formatter::sizeToString( haveTotal ) )
    130                   .arg( Formatter::sizeToString( tor.totalSize( ) ) )
    131                   .arg( Formatter::percentToString( tor.percentComplete( ) * 100.0 ) )
    132                   .arg( Formatter::sizeToString( tor.uploadedEver( ) ) )
    133                   .arg( Formatter::ratioToString( tor.ratio( ) ) );
     129            str = tr ("%1 of %2 (%3%), uploaded %4 (Ratio: %5)")
     130                  .arg (Formatter::sizeToString (haveTotal))
     131                  .arg (Formatter::sizeToString (tor.totalSize()))
     132                  .arg (Formatter::percentToString (tor.percentComplete() * 100.0))
     133                  .arg (Formatter::sizeToString (tor.uploadedEver()))
     134                  .arg (Formatter::ratioToString (tor.ratio()));
    134135        }
    135136    }
    136     else // seeding
    137     {
    138         if( hasSeedRatio )
     137  else // seeding
     138    {
     139      if (hasSeedRatio)
    139140        {
    140             /* %1 is the torrent's total size,
    141                %2 is how much we've uploaded,
    142                %3 is our upload-to-download ratio,
    143                %4 is the ratio we want to reach before we stop uploading */
    144             str = tr( "%1, uploaded %2 (Ratio: %3 Goal: %4)" )
    145                   .arg( Formatter::sizeToString( haveTotal ) )
    146                   .arg( Formatter::sizeToString( tor.uploadedEver( ) ) )
    147                   .arg( Formatter::ratioToString( tor.ratio( ) ) )
    148                   .arg( Formatter::ratioToString( seedRatio ) );
     141          /* %1 is the torrent's total size,
     142             %2 is how much we've uploaded,
     143             %3 is our upload-to-download ratio,
     144             %4 is the ratio we want to reach before we stop uploading */
     145          str = tr ("%1, uploaded %2 (Ratio: %3 Goal: %4)")
     146                .arg (Formatter::sizeToString (haveTotal))
     147                .arg (Formatter::sizeToString (tor.uploadedEver()))
     148                .arg (Formatter::ratioToString (tor.ratio()))
     149                .arg (Formatter::ratioToString (seedRatio));
    149150        }
    150         else /* seeding w/o a ratio */
     151      else // seeding w/o a ratio
    151152        {
    152             /* %1 is the torrent's total size,
    153                %2 is how much we've uploaded,
    154                %3 is our upload-to-download ratio */
    155             str = tr( "%1, uploaded %2 (Ratio: %3)" )
    156                   .arg( Formatter::sizeToString( haveTotal ) )
    157                   .arg( Formatter::sizeToString( tor.uploadedEver( ) ) )
    158                   .arg( Formatter::ratioToString( tor.ratio( ) ) );
     153          /* %1 is the torrent's total size,
     154             %2 is how much we've uploaded,
     155             %3 is our upload-to-download ratio */
     156          str = tr ("%1, uploaded %2 (Ratio: %3)")
     157                .arg (Formatter::sizeToString (haveTotal))
     158                .arg (Formatter::sizeToString (tor.uploadedEver()))
     159                .arg (Formatter::ratioToString (tor.ratio()));
    159160        }
    160161    }
    161162
    162     /* add time when downloading */
    163     if( ( hasSeedRatio && tor.isSeeding( ) ) || tor.isDownloading( ) )
    164     {
    165         str += tr( " - " );
    166         if( tor.hasETA( ) )
    167             str += tr( "%1 left" ).arg( Formatter::timeToString( tor.getETA( ) ) );
    168         else
    169             str += tr( "Remaining time unknown" );
     163  // add time when downloading
     164  if ((hasSeedRatio && tor.isSeeding()) || tor.isDownloading())
     165    {
     166      str += tr (" - ");
     167      if (tor.hasETA ())
     168        str += tr ("%1 left").arg (Formatter::timeToString (tor.getETA ()));
     169      else
     170        str += tr ("Remaining time unknown");
    170171    }
    171172
     
    182183
    183184  if (haveDown)
    184     str = tr( "%1   %2" ).arg(Formatter::downloadSpeedToString(tor.downloadSpeed()))
    185                          .arg(Formatter::uploadSpeedToString(tor.uploadSpeed()));
     185    str = tr ("%1   %2")
     186          .arg(Formatter::downloadSpeedToString(tor.downloadSpeed()))
     187          .arg(Formatter::uploadSpeedToString(tor.uploadSpeed()));
    186188
    187189  else if (haveUp)
     
    192194
    193195QString
    194 TorrentDelegate :: shortStatusString( const Torrent& tor ) const
    195 {
    196     QString str;
    197     static const QChar ratioSymbol (0x262F);
    198 
    199     switch( tor.getActivity( ) )
    200     {
    201         case TR_STATUS_CHECK:
    202             str = tr( "Verifying local data (%1% tested)" ).arg( Formatter::percentToString( tor.getVerifyProgress()*100.0 ) );
    203             break;
    204 
    205         case TR_STATUS_DOWNLOAD:
    206         case TR_STATUS_SEED:
    207             str = tr("%1    %2 %3").arg(shortTransferString(tor))
    208                                    .arg(tr("Ratio:"))
    209                                    .arg(Formatter::ratioToString(tor.ratio()));
    210             break;
    211 
    212         default:
    213             str = tor.activityString( );
    214             break;
    215     }
    216 
    217     return str;
     196TorrentDelegate :: shortStatusString (const Torrent& tor) const
     197{
     198  QString str;
     199  static const QChar ratioSymbol (0x262F);
     200
     201  switch (tor.getActivity ())
     202    {
     203      case TR_STATUS_CHECK:
     204        str = tr ("Verifying local data (%1% tested)").arg (Formatter::percentToString (tor.getVerifyProgress()*100.0));
     205        break;
     206
     207      case TR_STATUS_DOWNLOAD:
     208      case TR_STATUS_SEED:
     209        str = tr("%1    %2 %3")
     210              .arg(shortTransferString(tor))
     211              .arg(tr("Ratio:"))
     212              .arg(Formatter::ratioToString(tor.ratio()));
     213        break;
     214
     215      default:
     216        str = tor.activityString ();
     217        break;
     218    }
     219
     220  return str;
    218221}
    219222
    220223QString
    221 TorrentDelegate :: statusString( const Torrent& tor ) const
    222 {
    223     QString str;
    224 
    225     if( tor.hasError( ) )
    226     {
    227         str = tor.getError( );
    228     }
    229     else switch( tor.getActivity( ) )
    230     {
    231         case TR_STATUS_STOPPED:
    232         case TR_STATUS_CHECK_WAIT:
    233         case TR_STATUS_CHECK:
    234         case TR_STATUS_DOWNLOAD_WAIT:
    235         case TR_STATUS_SEED_WAIT:
    236             str = shortStatusString( tor );
    237             break;
    238 
    239         case TR_STATUS_DOWNLOAD:
    240             if( !tor.hasMetadata() ) {
    241                 str = tr( "Downloading metadata from %n peer(s) (%1% done)", 0, tor.peersWeAreDownloadingFrom( ) )
    242                         .arg( Formatter::percentToString( 100.0 * tor.metadataPercentDone( ) ) );
    243             } else {
    244                 /* it would be nicer for translation if this was all one string, but I don't see how to do multiple %n's in tr() */
    245                 str = tr( "Downloading from %1 of %n connected peer(s)", 0, tor.connectedPeersAndWebseeds( ) )
    246                         .arg( tor.peersWeAreDownloadingFrom( ) );
    247                 if (tor.webseedsWeAreDownloadingFrom())
    248                     str += tr(" and %n web seed(s)", "", tor.webseedsWeAreDownloadingFrom());
    249             }
    250             break;
    251 
    252         case TR_STATUS_SEED:
    253             str = tr( "Seeding to %1 of %n connected peer(s)", 0, tor.connectedPeers( ) )
    254                   .arg( tor.peersWeAreUploadingTo( ) );
    255             break;
    256 
    257         default:
    258             str = tr( "Error" );
    259             break;
    260     }
    261 
    262     if( tor.isReadyToTransfer( ) ) {
    263         QString s = shortTransferString( tor );
    264         if( !s.isEmpty( ) )
    265             str += tr( " - " ) + s;
    266     }
    267 
    268     return str;
     224TorrentDelegate :: statusString (const Torrent& tor) const
     225{
     226  QString str;
     227
     228  if (tor.hasError ())
     229    {
     230      str = tor.getError ();
     231    }
     232  else switch (tor.getActivity ())
     233    {
     234      case TR_STATUS_STOPPED:
     235      case TR_STATUS_CHECK_WAIT:
     236      case TR_STATUS_CHECK:
     237      case TR_STATUS_DOWNLOAD_WAIT:
     238      case TR_STATUS_SEED_WAIT:
     239        str = shortStatusString (tor);
     240        break;
     241
     242      case TR_STATUS_DOWNLOAD:
     243        if (!tor.hasMetadata())
     244          {
     245            str = tr ("Downloading metadata from %n peer(s) (%1% done)", 0, tor.peersWeAreDownloadingFrom ())
     246                  .arg (Formatter::percentToString (100.0 * tor.metadataPercentDone ()));
     247          }
     248        else
     249          {
     250            /* it would be nicer for translation if this was all one string, but I don't see how to do multiple %n's in tr() */
     251            str = tr ("Downloading from %1 of %n connected peer(s)", 0, tor.connectedPeersAndWebseeds ())
     252                  .arg (tor.peersWeAreDownloadingFrom ());
     253
     254            if (tor.webseedsWeAreDownloadingFrom())
     255              str += tr(" and %n web seed(s)", "", tor.webseedsWeAreDownloadingFrom());
     256          }
     257        break;
     258
     259      case TR_STATUS_SEED:
     260        str = tr ("Seeding to %1 of %n connected peer(s)", 0, tor.connectedPeers ())
     261              .arg (tor.peersWeAreUploadingTo ());
     262        break;
     263
     264      default:
     265        str = tr ("Error");
     266        break;
     267    }
     268
     269  if (tor.isReadyToTransfer ())
     270    {
     271      QString s = shortTransferString (tor);
     272      if (!s.isEmpty ())
     273        str += tr (" - ") + s;
     274    }
     275
     276  return str;
    269277}
    270278
     
    275283namespace
    276284{
    277     int MAX3( int a, int b, int c )
    278     {
    279         const int ab( a > b ? a : b );
    280         return ab > c ? ab : c;
     285  int MAX3 (int a, int b, int c)
     286    {
     287      const int ab (a > b ? a : b);
     288      return ab > c ? ab : c;
    281289    }
    282290}
    283291
    284292QSize
    285 TorrentDelegate :: sizeHint( const QStyleOptionViewItem& option, const Torrent& tor ) const
    286 {
    287     const QStyle* style( QApplication::style( ) );
    288     static const int iconSize( style->pixelMetric( QStyle::PM_MessageBoxIconSize ) );
    289 
    290     QFont nameFont( option.font );
    291     nameFont.setWeight( QFont::Bold );
    292     const QFontMetrics nameFM( nameFont );
    293     const QString nameStr( tor.name( ) );
    294     const int nameWidth = nameFM.width( nameStr );
    295     QFont statusFont( option.font );
    296     statusFont.setPointSize( int( option.font.pointSize( ) * 0.9 ) );
    297     const QFontMetrics statusFM( statusFont );
    298     const QString statusStr( statusString( tor ) );
    299     const int statusWidth = statusFM.width( statusStr );
    300     QFont progressFont( statusFont );
    301     const QFontMetrics progressFM( progressFont );
    302     const QString progressStr( progressString( tor ) );
    303     const int progressWidth = progressFM.width( progressStr );
    304     const QSize m( margin( *style ) );
    305     return QSize( m.width()*2 + iconSize + GUI_PAD + MAX3( nameWidth, statusWidth, progressWidth ),
    306                   //m.height()*3 + nameFM.lineSpacing() + statusFM.lineSpacing()*2 + progressFM.lineSpacing() );
    307                   m.height()*3 + nameFM.lineSpacing() + statusFM.lineSpacing() + BAR_HEIGHT + progressFM.lineSpacing() );
     293TorrentDelegate :: sizeHint (const QStyleOptionViewItem& option, const Torrent& tor) const
     294{
     295  const QStyle* style (QApplication::style ());
     296  static const int iconSize (style->pixelMetric (QStyle::PM_MessageBoxIconSize));
     297
     298  QFont nameFont (option.font);
     299  nameFont.setWeight (QFont::Bold);
     300  const QFontMetrics nameFM (nameFont);
     301  const QString nameStr (tor.name ());
     302  const int nameWidth = nameFM.width (nameStr);
     303  QFont statusFont (option.font);
     304  statusFont.setPointSize (int (option.font.pointSize () * 0.9));
     305  const QFontMetrics statusFM (statusFont);
     306  const QString statusStr (statusString (tor));
     307  const int statusWidth = statusFM.width (statusStr);
     308  QFont progressFont (statusFont);
     309  const QFontMetrics progressFM (progressFont);
     310  const QString progressStr (progressString (tor));
     311  const int progressWidth = progressFM.width (progressStr);
     312  const QSize m (margin (*style));
     313  return QSize (m.width()*2 + iconSize + GUI_PAD + MAX3 (nameWidth, statusWidth, progressWidth),
     314                //m.height()*3 + nameFM.lineSpacing() + statusFM.lineSpacing()*2 + progressFM.lineSpacing());
     315                m.height()*3 + nameFM.lineSpacing() + statusFM.lineSpacing() + BAR_HEIGHT + progressFM.lineSpacing());
    308316}
    309317
    310318QSize
    311 TorrentDelegate :: sizeHint( const QStyleOptionViewItem  & option,
    312                              const QModelIndex           & index ) const
    313 {
    314     const Torrent * tor( index.data( TorrentModel::TorrentRole ).value<const Torrent*>() );
    315     return sizeHint( option, *tor );
     319TorrentDelegate :: sizeHint (const QStyleOptionViewItem  & option,
     320                             const QModelIndex           & index) const
     321{
     322  const Torrent * tor (index.data (TorrentModel::TorrentRole).value<const Torrent*>());
     323  return sizeHint (option, *tor);
    316324}
    317325
    318326void
    319 TorrentDelegate :: paint( QPainter                    * painter,
     327TorrentDelegate :: paint (QPainter                    * painter,
    320328                          const QStyleOptionViewItem  & option,
    321329                          const QModelIndex           & index) const
    322330{
    323     const Torrent * tor( index.data( TorrentModel::TorrentRole ).value<const Torrent*>() );
    324     painter->save( );
    325     painter->setClipRect( option.rect );
    326     drawTorrent( painter, option, *tor );
    327     painter->restore( );
     331  const Torrent * tor (index.data (TorrentModel::TorrentRole).value<const Torrent*>());
     332  painter->save ();
     333  painter->setClipRect (option.rect);
     334  drawTorrent (painter, option, *tor);
     335  painter->restore ();
    328336}
    329337
    330338void
    331 TorrentDelegate :: setProgressBarPercentDone( const QStyleOptionViewItem& option, const Torrent& tor ) const
    332 {
    333     double seedRatioLimit;
    334     if (tor.isSeeding() && tor.getSeedRatio(seedRatioLimit))
    335     {
    336         const double seedRateRatio = tor.ratio() / seedRatioLimit;
    337         const int scaledProgress = seedRateRatio * (myProgressBarStyle->maximum - myProgressBarStyle->minimum);
    338         myProgressBarStyle->progress = myProgressBarStyle->minimum + scaledProgress;
    339     }
    340     else
    341     {
    342         const bool isMagnet( !tor.hasMetadata( ) );
    343         myProgressBarStyle->direction = option.direction;
    344         myProgressBarStyle->progress = int(myProgressBarStyle->minimum + (((isMagnet ? tor.metadataPercentDone() : tor.percentDone()) * (myProgressBarStyle->maximum - myProgressBarStyle->minimum))));
     339TorrentDelegate :: setProgressBarPercentDone (const QStyleOptionViewItem & option,
     340                                              const Torrent              & tor) const
     341{
     342  double seedRatioLimit;
     343  if (tor.isSeeding() && tor.getSeedRatio(seedRatioLimit))
     344    {
     345      const double seedRateRatio = tor.ratio() / seedRatioLimit;
     346      const int scaledProgress = seedRateRatio * (myProgressBarStyle->maximum - myProgressBarStyle->minimum);
     347      myProgressBarStyle->progress = myProgressBarStyle->minimum + scaledProgress;
     348    }
     349  else
     350    {
     351      const bool isMagnet (!tor.hasMetadata ());
     352      myProgressBarStyle->direction = option.direction;
     353      myProgressBarStyle->progress = int(myProgressBarStyle->minimum + (((isMagnet ? tor.metadataPercentDone() : tor.percentDone()) * (myProgressBarStyle->maximum - myProgressBarStyle->minimum))));
    345354    }
    346355}
    347356
    348357void
    349 TorrentDelegate :: drawTorrent( QPainter * painter, const QStyleOptionViewItem& option, const Torrent& tor ) const
    350 {
    351     const QStyle * style( QApplication::style( ) );
    352     static const int iconSize( style->pixelMetric( QStyle::PM_LargeIconSize ) );
    353     QFont nameFont( option.font );
    354     nameFont.setWeight( QFont::Bold );
    355     const QFontMetrics nameFM( nameFont );
    356     const QString nameStr( tor.name( ) );
    357     const QSize nameSize( nameFM.size( 0, nameStr ) );
    358     QFont statusFont( option.font );
    359     statusFont.setPointSize( int( option.font.pointSize( ) * 0.9 ) );
    360     const QFontMetrics statusFM( statusFont );
    361     const QString statusStr( progressString( tor ) );
    362     QFont progressFont( statusFont );
    363     const QFontMetrics progressFM( progressFont );
    364     const QString progressStr( statusString( tor ) );
    365     const bool isPaused( tor.isPaused( ) );
    366 
    367     painter->save( );
    368 
    369     if (option.state & QStyle::State_Selected) {
    370         QPalette::ColorGroup cg = option.state & QStyle::State_Enabled
    371                                   ? QPalette::Normal : QPalette::Disabled;
    372         if (cg == QPalette::Normal && !(option.state & QStyle::State_Active))
    373             cg = QPalette::Inactive;
    374 
    375         painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Highlight));
    376     }
    377 
    378     QIcon::Mode im;
    379     if( isPaused || !(option.state & QStyle::State_Enabled ) ) im = QIcon::Disabled;
    380     else if( option.state & QStyle::State_Selected ) im = QIcon::Selected;
    381     else im = QIcon::Normal;
    382 
    383     QIcon::State qs;
    384     if( isPaused ) qs = QIcon::Off;
    385     else qs = QIcon::On;
    386 
    387     QPalette::ColorGroup cg = QPalette::Normal;
    388     if( isPaused || !(option.state & QStyle::State_Enabled ) ) cg = QPalette::Disabled;
    389     if( cg == QPalette::Normal && !(option.state & QStyle::State_Active ) ) cg = QPalette::Inactive;
    390 
    391     QPalette::ColorRole cr;
    392     if( option.state & QStyle::State_Selected ) cr = QPalette::HighlightedText;
    393     else cr = QPalette::Text;
    394 
    395     QStyle::State progressBarState( option.state );
    396     if( isPaused ) progressBarState = QStyle::State_None;
    397     progressBarState |= QStyle::State_Small;
    398 
    399     // layout
    400     const QSize m( margin( *style ) );
    401     QRect fillArea( option.rect );
    402     fillArea.adjust( m.width(), m.height(), -m.width(), -m.height() );
    403     QRect iconArea( fillArea.x( ), fillArea.y( ) + ( fillArea.height( ) - iconSize ) / 2, iconSize, iconSize );
    404     QRect nameArea( iconArea.x( ) + iconArea.width( ) + GUI_PAD, fillArea.y( ),
    405                     fillArea.width( ) - GUI_PAD - iconArea.width( ), nameSize.height( ) );
    406     QRect statusArea( nameArea );
    407     statusArea.moveTop( nameArea.y( ) + nameFM.lineSpacing( ) );
    408     statusArea.setHeight( nameSize.height( ) );
    409     QRect barArea( statusArea );
    410     barArea.setHeight( BAR_HEIGHT );
    411     barArea.moveTop( statusArea.y( ) + statusFM.lineSpacing( ) );
    412     QRect progArea( statusArea );
    413     progArea.moveTop( barArea.y( ) + barArea.height( ) );
    414 
    415     // render
    416     if( tor.hasError( ) )
    417         painter->setPen( QColor( "red" ) );
    418     else
    419         painter->setPen( option.palette.color( cg, cr ) );
    420     tor.getMimeTypeIcon().paint( painter, iconArea, Qt::AlignCenter, im, qs );
    421     painter->setFont( nameFont );
    422     painter->drawText( nameArea, 0, nameFM.elidedText( nameStr, Qt::ElideRight, nameArea.width( ) ) );
    423     painter->setFont( statusFont );
    424     painter->drawText( statusArea, 0, statusFM.elidedText( statusStr, Qt::ElideRight, statusArea.width( ) ) );
    425     painter->setFont( progressFont );
    426     painter->drawText( progArea, 0, progressFM.elidedText( progressStr, Qt::ElideRight, progArea.width( ) ) );
    427     myProgressBarStyle->rect = barArea;
    428     if ( tor.isDownloading() ) {
    429         myProgressBarStyle->palette.setBrush( QPalette::Highlight, blueBrush );
    430         myProgressBarStyle->palette.setColor( QPalette::Base, blueBack );
    431         myProgressBarStyle->palette.setColor( QPalette::Window, blueBack );
    432     }
    433     else if ( tor.isSeeding() ) {
    434         myProgressBarStyle->palette.setBrush( QPalette::Highlight, greenBrush );
    435         myProgressBarStyle->palette.setColor( QPalette::Base, greenBack );
    436         myProgressBarStyle->palette.setColor( QPalette::Window, greenBack );
    437     }
    438     else {
    439         myProgressBarStyle->palette.setBrush( QPalette::Highlight, silverBrush );
    440         myProgressBarStyle->palette.setColor( QPalette::Base, silverBack );
    441         myProgressBarStyle->palette.setColor( QPalette::Window, silverBack );
    442     }
    443     myProgressBarStyle->state = progressBarState;
    444     setProgressBarPercentDone( option, tor );
    445 
    446     style->drawControl( QStyle::CE_ProgressBar, myProgressBarStyle, painter );
    447 
    448     painter->restore( );
    449 }
     358TorrentDelegate :: drawTorrent (QPainter                   * painter,
     359                                const QStyleOptionViewItem & option,
     360                                const Torrent              & tor) const
     361{
     362  const QStyle * style (QApplication::style ());
     363  static const int iconSize (style->pixelMetric (QStyle::PM_LargeIconSize));
     364  QFont nameFont (option.font);
     365  nameFont.setWeight (QFont::Bold);
     366  const QFontMetrics nameFM (nameFont);
     367  const QString nameStr (tor.name ());
     368  const QSize nameSize (nameFM.size (0, nameStr));
     369  QFont statusFont (option.font);
     370  statusFont.setPointSize (int (option.font.pointSize () * 0.9));
     371  const QFontMetrics statusFM (statusFont);
     372  const QString statusStr (progressString (tor));
     373  QFont progressFont (statusFont);
     374  const QFontMetrics progressFM (progressFont);
     375  const QString progressStr (statusString (tor));
     376  const bool isPaused (tor.isPaused ());
     377
     378  painter->save ();
     379
     380  if (option.state & QStyle::State_Selected)
     381    {
     382      QPalette::ColorGroup cg = option.state & QStyle::State_Enabled
     383                              ? QPalette::Normal : QPalette::Disabled;
     384      if (cg == QPalette::Normal && !(option.state & QStyle::State_Active))
     385        cg = QPalette::Inactive;
     386
     387      painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Highlight));
     388    }
     389
     390  QIcon::Mode im;
     391  if (isPaused || !(option.state & QStyle::State_Enabled))
     392    im = QIcon::Disabled;
     393  else if (option.state & QStyle::State_Selected)
     394    im = QIcon::Selected;
     395  else
     396    im = QIcon::Normal;
     397
     398  QIcon::State qs;
     399  if (isPaused)
     400    qs = QIcon::Off;
     401  else
     402    qs = QIcon::On;
     403
     404  QPalette::ColorGroup cg = QPalette::Normal;
     405  if (isPaused || !(option.state & QStyle::State_Enabled))
     406    cg = QPalette::Disabled;
     407  if (cg == QPalette::Normal && !(option.state & QStyle::State_Active))
     408    cg = QPalette::Inactive;
     409
     410  QPalette::ColorRole cr;
     411  if (option.state & QStyle::State_Selected)
     412    cr = QPalette::HighlightedText;
     413  else
     414    cr = QPalette::Text;
     415
     416  QStyle::State progressBarState (option.state);
     417  if (isPaused)
     418    progressBarState = QStyle::State_None;
     419  progressBarState |= QStyle::State_Small;
     420
     421  // layout
     422  const QSize m (margin (*style));
     423  QRect fillArea (option.rect);
     424  fillArea.adjust (m.width(), m.height(), -m.width(), -m.height());
     425  QRect iconArea (fillArea.x (), fillArea.y () +  (fillArea.height () - iconSize) / 2, iconSize, iconSize);
     426  QRect nameArea (iconArea.x () + iconArea.width () + GUI_PAD, fillArea.y (),
     427                  fillArea.width () - GUI_PAD - iconArea.width (), nameSize.height ());
     428  QRect statusArea (nameArea);
     429  statusArea.moveTop (nameArea.y () + nameFM.lineSpacing ());
     430  statusArea.setHeight (nameSize.height ());
     431  QRect barArea (statusArea);
     432  barArea.setHeight (BAR_HEIGHT);
     433  barArea.moveTop (statusArea.y () + statusFM.lineSpacing ());
     434  QRect progArea (statusArea);
     435  progArea.moveTop (barArea.y () + barArea.height ());
     436
     437  // render
     438  if (tor.hasError ())
     439    painter->setPen (QColor ("red"));
     440  else
     441    painter->setPen (option.palette.color (cg, cr));
     442  tor.getMimeTypeIcon().paint (painter, iconArea, Qt::AlignCenter, im, qs);
     443  painter->setFont (nameFont);
     444  painter->drawText (nameArea, 0, nameFM.elidedText (nameStr, Qt::ElideRight, nameArea.width ()));
     445  painter->setFont (statusFont);
     446  painter->drawText (statusArea, 0, statusFM.elidedText (statusStr, Qt::ElideRight, statusArea.width ()));
     447  painter->setFont (progressFont);
     448  painter->drawText (progArea, 0, progressFM.elidedText (progressStr, Qt::ElideRight, progArea.width ()));
     449  myProgressBarStyle->rect = barArea;
     450  if (tor.isDownloading())
     451    {
     452      myProgressBarStyle->palette.setBrush (QPalette::Highlight, blueBrush);
     453      myProgressBarStyle->palette.setColor (QPalette::Base, blueBack);
     454      myProgressBarStyle->palette.setColor (QPalette::Window, blueBack);
     455    }
     456  else if (tor.isSeeding())
     457    {
     458      myProgressBarStyle->palette.setBrush (QPalette::Highlight, greenBrush);
     459      myProgressBarStyle->palette.setColor (QPalette::Base, greenBack);
     460      myProgressBarStyle->palette.setColor (QPalette::Window, greenBack);
     461    }
     462  else
     463    {
     464      myProgressBarStyle->palette.setBrush (QPalette::Highlight, silverBrush);
     465      myProgressBarStyle->palette.setColor (QPalette::Base, silverBack);
     466      myProgressBarStyle->palette.setColor (QPalette::Window, silverBack);
     467    }
     468  myProgressBarStyle->state = progressBarState;
     469  setProgressBarPercentDone (option, tor);
     470
     471  style->drawControl (QStyle::CE_ProgressBar, myProgressBarStyle, painter);
     472
     473  painter->restore ();
     474}
  • trunk/qt/torrent-delegate.h

    r14019 r14204  
    2525class TorrentDelegate: public QStyledItemDelegate
    2626{
    27         Q_OBJECT
     27    Q_OBJECT
    2828
    29     public:
    30       static QColor blueBrush, greenBrush, silverBrush;
    31       static QColor blueBack,  greenBack, silverBack;
     29  public:
     30    static QColor blueBrush, greenBrush, silverBrush;
     31    static QColor blueBack,  greenBack, silverBack;
    3232
    33     protected:
    34         QStyleOptionProgressBar * myProgressBarStyle;
     33  protected:
     34    QStyleOptionProgressBar * myProgressBarStyle;
    3535
    36     protected:
    37         QString statusString( const Torrent& tor ) const;
    38         QString progressString( const Torrent& tor ) const;
    39         QString shortStatusString( const Torrent& tor ) const;
    40         QString shortTransferString( const Torrent& tor ) const;
     36  protected:
     37    QString statusString (const Torrent& tor) const;
     38    QString progressString (const Torrent& tor) const;
     39    QString shortStatusString (const Torrent& tor) const;
     40    QString shortTransferString (const Torrent& tor) const;
    4141
    42     protected:
    43         QSize margin( const QStyle& style ) const;
    44         virtual QSize sizeHint( const QStyleOptionViewItem&, const Torrent& ) const;
    45         virtual void setProgressBarPercentDone( const QStyleOptionViewItem& option, const Torrent& ) const;
    46         virtual void drawTorrent( QPainter* painter, const QStyleOptionViewItem& option, const Torrent& ) const;
     42  protected:
     43    QSize margin (const QStyle& style) const;
     44    virtual QSize sizeHint (const QStyleOptionViewItem&, const Torrent&) const;
     45    virtual void setProgressBarPercentDone (const QStyleOptionViewItem& option, const Torrent&) const;
     46    virtual void drawTorrent (QPainter* painter, const QStyleOptionViewItem& option, const Torrent&) const;
    4747
    48     public:
    49         explicit TorrentDelegate( QObject * parent=0 );
    50         virtual ~TorrentDelegate( );
     48  public:
     49    explicit TorrentDelegate (QObject * parent=0);
     50    virtual ~TorrentDelegate ();
    5151
    52         QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
    53         void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
    54 
     52    QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
     53    void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
    5554};
    5655
  • trunk/qt/torrent-filter.cc

    r14194 r14204  
    2222#include "utils.h"
    2323
    24 TorrentFilter :: TorrentFilter( Prefs& prefs ):
    25     myPrefs( prefs )
    26 {
    27     // listen for changes to the preferences to know when to refilter / resort
    28     connect( &myPrefs, SIGNAL(changed(int)), this, SLOT(refreshPref(int)));
    29 
    30     setDynamicSortFilter( true );
    31 
    32     // initialize our state from the current prefs
    33     QList<int> initKeys;
    34     initKeys << Prefs :: SORT_MODE
    35              << Prefs :: FILTER_MODE
    36              << Prefs :: FILTER_TRACKERS
    37              << Prefs :: FILTER_TEXT;
    38     foreach( int key, initKeys )
    39         refreshPref( key );
    40 }
    41 
    42 TorrentFilter :: ~TorrentFilter( )
     24TorrentFilter :: TorrentFilter (Prefs& prefs):
     25  myPrefs (prefs)
     26{
     27  // listen for changes to the preferences to know when to refilter / resort
     28  connect (&myPrefs, SIGNAL(changed(int)), this, SLOT(refreshPref(int)));
     29
     30  setDynamicSortFilter (true);
     31
     32  // initialize our state from the current prefs
     33  QList<int> initKeys;
     34  initKeys << Prefs :: SORT_MODE
     35           << Prefs :: FILTER_MODE
     36           << Prefs :: FILTER_TRACKERS
     37           << Prefs :: FILTER_TEXT;
     38  foreach (int key, initKeys)
     39    refreshPref (key);
     40}
     41
     42TorrentFilter :: ~TorrentFilter ()
    4343{
    4444}
    4545
    4646void
    47 TorrentFilter :: refreshPref( int key )
    48 {
    49     switch( key )
    50     {
    51         case Prefs :: FILTER_TEXT:
    52         case Prefs :: FILTER_MODE:
    53         case Prefs :: FILTER_TRACKERS:
    54             invalidateFilter( );
    55             /* force a re-sort */
    56             sort( 0, !myPrefs.getBool(Prefs::SORT_REVERSED) ? Qt::AscendingOrder : Qt::DescendingOrder );
    57 
    58         case Prefs :: SORT_MODE:
    59         case Prefs :: SORT_REVERSED:
    60             sort( 0, myPrefs.getBool(Prefs::SORT_REVERSED) ? Qt::AscendingOrder : Qt::DescendingOrder );
    61             invalidate( );
    62             break;
     47TorrentFilter :: refreshPref (int key)
     48{
     49  switch (key)
     50    {
     51      case Prefs :: FILTER_TEXT:
     52      case Prefs :: FILTER_MODE:
     53      case Prefs :: FILTER_TRACKERS:
     54        invalidateFilter ();
     55        /* force a re-sort */
     56        sort (0, !myPrefs.getBool(Prefs::SORT_REVERSED) ? Qt::AscendingOrder : Qt::DescendingOrder);
     57
     58      case Prefs :: SORT_MODE:
     59      case Prefs :: SORT_REVERSED:
     60        sort (0, myPrefs.getBool(Prefs::SORT_REVERSED) ? Qt::AscendingOrder : Qt::DescendingOrder);
     61        invalidate ();
     62        break;
    6363    }
    6464}
     
    7070namespace
    7171{
    72     template <typename T> int compare( const T a, const T b )
    73     {
    74         if( a < b ) return -1;
    75         if( b < a ) return 1;
    76         return 0;
    77     }
    78 }
    79 
    80 bool
    81 TorrentFilter :: lessThan( const QModelIndex& left, const QModelIndex& right ) const
    82 {
    83     int val = 0;
    84     const Torrent * a = sourceModel()->data( left, TorrentModel::TorrentRole ).value<const Torrent*>();
    85     const Torrent * b = sourceModel()->data( right, TorrentModel::TorrentRole ).value<const Torrent*>();
    86 
    87     switch( myPrefs.get<SortMode>(Prefs::SORT_MODE).mode() )
    88     {
    89         case SortMode :: SORT_BY_QUEUE:
    90             if( !val ) val = -compare( a->queuePosition(), b->queuePosition() );
    91             break;
    92         case SortMode :: SORT_BY_SIZE:
    93             if( !val ) val = compare( a->sizeWhenDone(), b->sizeWhenDone() );
    94             break;
    95         case SortMode :: SORT_BY_AGE:
    96             val = compare( a->dateAdded().toTime_t(), b->dateAdded().toTime_t() );
    97             break;
    98         case SortMode :: SORT_BY_ID:
    99             if( !val ) val = compare( a->id(), b->id() );
    100             break;
    101         case SortMode :: SORT_BY_ACTIVITY:
    102             if( !val ) val = compare( a->downloadSpeed() + a->uploadSpeed(), b->downloadSpeed() + b->uploadSpeed() );
    103             if( !val ) val = compare( a->peersWeAreUploadingTo() + a->webseedsWeAreDownloadingFrom(),
    104                                       b->peersWeAreUploadingTo() + b->webseedsWeAreDownloadingFrom());
    105             // fall through
    106         case SortMode :: SORT_BY_STATE:
    107             if( !val ) val = -compare( a->isPaused(), b->isPaused() );
    108             if( !val ) val = compare( a->getActivity(), b->getActivity() );
    109             if( !val ) val = -compare( a->queuePosition(), b->queuePosition() );
    110             if( !val ) val = compare( a->hasError(), b->hasError() );
    111             // fall through
    112         case SortMode :: SORT_BY_PROGRESS:
    113             if( !val ) val = compare( a->percentComplete(), b->percentComplete() );
    114             if( !val ) val = a->compareSeedRatio( *b );
    115             if( !val ) val = -compare( a->queuePosition(), b->queuePosition() );
    116         case SortMode :: SORT_BY_RATIO:
    117             if( !val ) val = a->compareRatio( *b );
    118             break;
    119         case SortMode :: SORT_BY_ETA:
    120             if( !val ) val = a->compareETA( *b );
    121             break;
    122         default:
    123             break;
    124     }
    125     if( val == 0 )
    126         val = -a->name().compare( b->name(), Qt::CaseInsensitive );
    127     if( val == 0 )
    128         val = compare( a->hashString(), b->hashString() );
    129     return val < 0;
     72  template <typename T> int compare (const T a, const T b)
     73    {
     74      if (a < b)
     75        return -1;
     76
     77      if (b < a)
     78        return 1;
     79
     80      return 0;
     81    }
     82}
     83
     84bool
     85TorrentFilter :: lessThan (const QModelIndex& left, const QModelIndex& right) const
     86{
     87  int val = 0;
     88  const Torrent * a = sourceModel()->data (left, TorrentModel::TorrentRole).value<const Torrent*>();
     89  const Torrent * b = sourceModel()->data (right, TorrentModel::TorrentRole).value<const Torrent*>();
     90
     91  switch (myPrefs.get<SortMode>(Prefs::SORT_MODE).mode())
     92    {
     93      case SortMode :: SORT_BY_QUEUE:
     94        if (!val)
     95          val = -compare (a->queuePosition(), b->queuePosition());
     96        break;
     97
     98      case SortMode :: SORT_BY_SIZE:
     99        if (!val)
     100          val = compare (a->sizeWhenDone(), b->sizeWhenDone());
     101        break;
     102
     103      case SortMode :: SORT_BY_AGE:
     104        val = compare (a->dateAdded().toTime_t(), b->dateAdded().toTime_t());
     105        break;
     106
     107      case SortMode :: SORT_BY_ID:
     108        if (!val)
     109          val = compare (a->id(), b->id());
     110        break;
     111
     112      case SortMode :: SORT_BY_ACTIVITY:
     113        if (!val)
     114          val = compare (a->downloadSpeed() + a->uploadSpeed(), b->downloadSpeed() + b->uploadSpeed());
     115        if (!val)
     116          val = compare (a->peersWeAreUploadingTo() + a->webseedsWeAreDownloadingFrom(),
     117                         b->peersWeAreUploadingTo() + b->webseedsWeAreDownloadingFrom());
     118        // fall through
     119
     120      case SortMode :: SORT_BY_STATE:
     121        if (!val)
     122          val = -compare (a->isPaused(), b->isPaused());
     123        if (!val)
     124          val = compare (a->getActivity(), b->getActivity());
     125        if (!val)
     126          val = -compare (a->queuePosition(), b->queuePosition());
     127        if (!val)
     128          val = compare (a->hasError(), b->hasError());
     129        // fall through
     130
     131      case SortMode :: SORT_BY_PROGRESS:
     132        if (!val)
     133          val = compare (a->percentComplete(), b->percentComplete());
     134        if (!val)
     135          val = a->compareSeedRatio (*b);
     136        if (!val)
     137          val = -compare (a->queuePosition(), b->queuePosition());
     138
     139      case SortMode :: SORT_BY_RATIO:
     140        if (!val)
     141          val = a->compareRatio (*b);
     142        break;
     143
     144      case SortMode :: SORT_BY_ETA:
     145        if (!val)
     146          val = a->compareETA (*b);
     147        break;
     148
     149      default:
     150        break;
     151    }
     152
     153  if (val == 0)
     154    val = -a->name().compare (b->name(), Qt::CaseInsensitive);
     155
     156  if (val == 0)
     157    val = compare (a->hashString(), b->hashString());
     158
     159  return val < 0;
    130160}
    131161
     
    136166
    137167bool
    138 TorrentFilter :: trackerFilterAcceptsTorrent( const Torrent * tor, const QString& tracker ) const
    139 {
    140     return tracker.isEmpty() || tor->hasTrackerSubstring( tracker );
    141 }
    142 
    143 bool
    144 TorrentFilter :: activityFilterAcceptsTorrent( const Torrent * tor, const FilterMode& m ) const
    145 {
    146     bool accepts;
    147 
    148     switch( m.mode( ) )
    149     {
    150         case FilterMode::SHOW_ACTIVE:
    151             accepts = tor->peersWeAreUploadingTo( ) > 0 || tor->peersWeAreDownloadingFrom( ) > 0 || tor->isVerifying( );
    152             break;
    153         case FilterMode::SHOW_DOWNLOADING:
    154             accepts = tor->isDownloading( ) || tor->isWaitingToDownload( );
    155             break;
    156         case FilterMode::SHOW_SEEDING:
    157             accepts = tor->isSeeding( ) || tor->isWaitingToSeed( );
    158             break;
    159         case FilterMode::SHOW_PAUSED:
    160             accepts = tor->isPaused( );
    161             break;
    162         case FilterMode::SHOW_FINISHED:
    163             accepts = tor->isFinished( );
    164             break;
    165         case FilterMode::SHOW_VERIFYING:
    166             accepts = tor->isVerifying( ) || tor->isWaitingToVerify( );
    167             break;
    168         case FilterMode::SHOW_ERROR:
    169             accepts = tor->hasError( );
    170             break;
    171         default: // FilterMode::SHOW_ALL
    172             accepts = true;
    173             break;
    174     }
    175 
    176     return accepts;
    177 }
    178 
    179 bool
    180 TorrentFilter :: filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const
    181 {
    182     QModelIndex childIndex = sourceModel()->index( sourceRow, 0, sourceParent );
    183     const Torrent * tor = childIndex.model()->data( childIndex, TorrentModel::TorrentRole ).value<const Torrent*>();
    184     bool accepts = true;
    185 
    186     if( accepts ) {
    187         const FilterMode m = myPrefs.get<FilterMode>(Prefs::FILTER_MODE);
    188         accepts = activityFilterAcceptsTorrent( tor, m );
    189     }
    190 
    191     if( accepts ) {
    192         const QString trackers = myPrefs.getString(Prefs::FILTER_TRACKERS);
    193         accepts = trackerFilterAcceptsTorrent( tor, trackers );
    194     }
    195 
    196     if( accepts ) {
    197         const QString text = myPrefs.getString( Prefs::FILTER_TEXT );
    198         if( !text.isEmpty( ) )
    199             accepts = tor->name().contains( text, Qt::CaseInsensitive );
    200     }
    201 
    202     return accepts;
     168TorrentFilter :: trackerFilterAcceptsTorrent (const Torrent * tor, const QString& tracker) const
     169{
     170  return tracker.isEmpty() || tor->hasTrackerSubstring (tracker);
     171}
     172
     173bool
     174TorrentFilter :: activityFilterAcceptsTorrent (const Torrent * tor, const FilterMode& m) const
     175{
     176  bool accepts;
     177
     178  switch (m.mode ())
     179    {
     180      case FilterMode::SHOW_ACTIVE:
     181        accepts = tor->peersWeAreUploadingTo () > 0 || tor->peersWeAreDownloadingFrom () > 0 || tor->isVerifying ();
     182        break;
     183
     184      case FilterMode::SHOW_DOWNLOADING:
     185        accepts = tor->isDownloading () || tor->isWaitingToDownload ();
     186        break;
     187
     188      case FilterMode::SHOW_SEEDING:
     189        accepts = tor->isSeeding () || tor->isWaitingToSeed ();
     190        break;
     191
     192      case FilterMode::SHOW_PAUSED:
     193        accepts = tor->isPaused ();
     194        break;
     195
     196      case FilterMode::SHOW_FINISHED:
     197        accepts = tor->isFinished ();
     198        break;
     199
     200      case FilterMode::SHOW_VERIFYING:
     201        accepts = tor->isVerifying () || tor->isWaitingToVerify ();
     202        break;
     203
     204      case FilterMode::SHOW_ERROR:
     205        accepts = tor->hasError ();
     206        break;
     207
     208      default: // FilterMode::SHOW_ALL
     209        accepts = true;
     210        break;
     211    }
     212
     213  return accepts;
     214}
     215
     216bool
     217TorrentFilter :: filterAcceptsRow (int sourceRow, const QModelIndex& sourceParent) const
     218{
     219  QModelIndex childIndex = sourceModel()->index (sourceRow, 0, sourceParent);
     220  const Torrent * tor = childIndex.model()->data (childIndex, TorrentModel::TorrentRole).value<const Torrent*>();
     221  bool accepts = true;
     222
     223  if (accepts)
     224    {
     225      const FilterMode m = myPrefs.get<FilterMode>(Prefs::FILTER_MODE);
     226      accepts = activityFilterAcceptsTorrent (tor, m);
     227    }
     228
     229  if (accepts)
     230    {
     231      const QString trackers = myPrefs.getString(Prefs::FILTER_TRACKERS);
     232      accepts = trackerFilterAcceptsTorrent (tor, trackers);
     233    }
     234
     235  if (accepts)
     236    {
     237      const QString text = myPrefs.getString (Prefs::FILTER_TEXT);
     238      if (!text.isEmpty ())
     239        accepts = tor->name().contains (text, Qt::CaseInsensitive);
     240    }
     241
     242  return accepts;
    203243}
    204244
    205245int
    206 TorrentFilter :: hiddenRowCount( ) const
    207 {
    208     return sourceModel()->rowCount( ) - rowCount( );
     246TorrentFilter :: hiddenRowCount () const
     247{
     248  return sourceModel()->rowCount () - rowCount ();
    209249}
    210250
     
    220260        break;
    221261
    222       const Torrent * tor (index.data( TorrentModel::TorrentRole ).value<const Torrent*>());
     262      const Torrent * tor (index.data (TorrentModel::TorrentRole).value<const Torrent*>());
    223263      for (int mode(0); mode<FilterMode::NUM_MODES; ++mode)
    224264        if (activityFilterAcceptsTorrent (tor, mode))
  • trunk/qt/torrent-filter.h

    r13720 r14204  
    2727class TorrentFilter: public QSortFilterProxyModel
    2828{
    29         Q_OBJECT
     29    Q_OBJECT
    3030
    31     public:
    32         TorrentFilter( Prefs& prefs );
    33         virtual ~TorrentFilter( );
     31  public:
     32    TorrentFilter (Prefs& prefs);
     33    virtual ~TorrentFilter ();
    3434
    35     public:
    36         enum TextMode { FILTER_BY_NAME, FILTER_BY_FILES, FILTER_BY_TRACKER };
    37         int hiddenRowCount( ) const;
     35  public:
     36    enum TextMode { FILTER_BY_NAME, FILTER_BY_FILES, FILTER_BY_TRACKER };
     37    int hiddenRowCount () const;
    3838
    39     private slots:
    40         void refreshPref( int key );
     39  private slots:
     40    void refreshPref (int key);
    4141
    42     protected:
    43         virtual bool filterAcceptsRow( int, const QModelIndex& ) const;
    44         virtual bool lessThan( const QModelIndex&, const QModelIndex& ) const;
     42  protected:
     43    virtual bool filterAcceptsRow (int, const QModelIndex&) const;
     44    virtual bool lessThan (const QModelIndex&, const QModelIndex&) const;
    4545
    46     private:
    47         bool activityFilterAcceptsTorrent( const Torrent * tor, const FilterMode& mode ) const;
    48         bool trackerFilterAcceptsTorrent( const Torrent * tor, const QString& tracker ) const;
     46  private:
     47    bool activityFilterAcceptsTorrent (const Torrent * tor, const FilterMode& mode) const;
     48    bool trackerFilterAcceptsTorrent (const Torrent * tor, const QString& tracker) const;
    4949
    50     public:
    51         void countTorrentsPerMode (int * setmeCounts) const;
     50  public:
     51    void countTorrentsPerMode (int * setmeCounts) const;
    5252
    53     private:
    54         Prefs& myPrefs;
     53  private:
     54    Prefs& myPrefs;
    5555};
    5656
  • trunk/qt/torrent-model.cc

    r14185 r14204  
    2121
    2222void
    23 TorrentModel :: clear( )
    24 {
    25     beginResetModel ();
    26 
    27     myIdToRow.clear( );
    28     myIdToTorrent.clear( );
    29     foreach( Torrent * tor, myTorrents ) delete tor;
    30     myTorrents.clear( );
    31 
    32     endResetModel ();
     23TorrentModel :: clear ()
     24{
     25  beginResetModel ();
     26
     27  myIdToRow.clear ();
     28  myIdToTorrent.clear ();
     29  foreach (Torrent * tor, myTorrents) delete tor;
     30  myTorrents.clear ();
     31
     32  endResetModel ();
    3333}
    3434
    3535int
    36 TorrentModel :: rowCount( const QModelIndex& parent ) const
    37 {
    38     Q_UNUSED( parent );
    39 
    40     return myTorrents.size( );
     36TorrentModel :: rowCount (const QModelIndex& parent) const
     37{
     38  Q_UNUSED (parent);
     39
     40  return myTorrents.size ();
    4141}
    4242
     
    7777
    7878void
    79 TorrentModel :: addTorrent( Torrent * t )
    80 {
    81     myIdToTorrent.insert( t->id( ), t );
    82     myIdToRow.insert( t->id( ), myTorrents.size( ) );
    83     myTorrents.append( t );
    84 }
    85 
    86 TorrentModel :: TorrentModel( Prefs& prefs ):
    87     myPrefs( prefs )
    88 {
    89 }
    90 
    91 TorrentModel :: ~TorrentModel( )
    92 {
    93     clear( );
     79TorrentModel :: addTorrent (Torrent * t)
     80{
     81  myIdToTorrent.insert (t->id (), t);
     82  myIdToRow.insert (t->id (), myTorrents.size ());
     83  myTorrents.append (t);
     84}
     85
     86TorrentModel :: TorrentModel (Prefs& prefs):
     87  myPrefs (prefs)
     88{
     89}
     90
     91TorrentModel :: ~TorrentModel ()
     92{
     93  clear ();
    9494}
    9595
     
    9999
    100100Torrent*
    101 TorrentModel :: getTorrentFromId( int id )
    102 {
    103     id_to_torrent_t::iterator it( myIdToTorrent.find( id ) );
    104     return it == myIdToTorrent.end() ? 0 : it.value( );
     101TorrentModel :: getTorrentFromId (int id)
     102{
     103  id_to_torrent_t::iterator it (myIdToTorrent.find (id));
     104  return it == myIdToTorrent.end() ? 0 : it.value ();
    105105}
    106106
    107107const Torrent*
    108 TorrentModel :: getTorrentFromId( int id ) const
    109 {
    110     id_to_torrent_t::const_iterator it( myIdToTorrent.find( id ) );
    111     return it == myIdToTorrent.end() ? 0 : it.value( );
     108TorrentModel :: getTorrentFromId (int id) const
     109{
     110  id_to_torrent_t::const_iterator it (myIdToTorrent.find (id));
     111  return it == myIdToTorrent.end() ? 0 : it.value ();
    112112}
    113113
     
    117117
    118118void
    119 TorrentModel :: onTorrentChanged( int torrentId )
    120 {
    121     const int row( myIdToRow.value( torrentId, -1 ) );
    122     if( row >= 0 ) {
    123         QModelIndex qmi( index( row, 0 ) );
    124         emit dataChanged( qmi, qmi );
    125     }
    126 }
    127 
    128 void
    129 TorrentModel :: removeTorrents( tr_variant * torrents )
    130 {
    131     int i = 0;
    132     tr_variant * child;
    133     while(( child = tr_variantListChild( torrents, i++ ))) {
    134         int64_t intVal;
    135         if( tr_variantGetInt( child, &intVal ) )
    136             removeTorrent( intVal );
    137     }
    138 }
    139 
    140 void
    141 TorrentModel :: updateTorrents( tr_variant * torrents, bool isCompleteList )
    142 {
    143     QList<Torrent*> newTorrents;
    144     QSet<int> oldIds;
    145     QSet<int> addIds;
    146     QSet<int> newIds;
    147     int updatedCount = 0;
    148 
    149     if ( isCompleteList )
    150       oldIds = getIds( );
    151 
    152     if( tr_variantIsList( torrents ) )
    153     {
    154         size_t i( 0 );
    155         tr_variant * child;
    156         while(( child = tr_variantListChild( torrents, i++ )))
     119TorrentModel :: onTorrentChanged (int torrentId)
     120{
     121  const int row (myIdToRow.value (torrentId, -1));
     122  if (row >= 0)
     123    {
     124      QModelIndex qmi (index (row, 0));
     125      emit dataChanged (qmi, qmi);
     126    }
     127}
     128
     129void
     130TorrentModel :: removeTorrents (tr_variant * torrents)
     131{
     132  int i = 0;
     133  tr_variant * child;
     134  while( (child = tr_variantListChild (torrents, i++)))
     135    {
     136      int64_t intVal;
     137      if (tr_variantGetInt (child, &intVal))
     138        removeTorrent (intVal);
     139    }
     140}
     141
     142void
     143TorrentModel :: updateTorrents (tr_variant * torrents, bool isCompleteList)
     144{
     145  QList<Torrent*> newTorrents;
     146  QSet<int> oldIds;
     147  QSet<int> addIds;
     148  QSet<int> newIds;
     149  int updatedCount = 0;
     150
     151  if  (isCompleteList)
     152    oldIds = getIds ();
     153
     154  if (tr_variantIsList (torrents))
     155    {
     156      size_t i (0);
     157      tr_variant * child;
     158      while( (child = tr_variantListChild (torrents, i++)))
    157159        {
    158             int64_t id;
    159             if( tr_variantDictFindInt( child, TR_KEY_id, &id ) )
     160          int64_t id;
     161          if (tr_variantDictFindInt (child, TR_KEY_id, &id))
    160162            {
    161                 newIds.insert( id );
    162 
    163                 Torrent * tor = getTorrentFromId( id );
    164                 if( tor == 0 )
     163              newIds.insert (id);
     164
     165              Torrent * tor = getTorrentFromId (id);
     166              if (tor == 0)
    165167                {
    166                     tor = new Torrent( myPrefs, id );
    167                     tor->update( child );
    168                     if( !tor->hasMetadata() )
    169                         tor->setMagnet( true );
    170                     newTorrents.append( tor );
    171                     connect( tor, SIGNAL(torrentChanged(int)), this, SLOT(onTorrentChanged(int)));
     168                  tor = new Torrent (myPrefs, id);
     169                  tor->update (child);
     170                  if (!tor->hasMetadata())
     171                    tor->setMagnet (true);
     172                  newTorrents.append (tor);
     173                  connect (tor, SIGNAL(torrentChanged(int)), this, SLOT(onTorrentChanged(int)));
    172174                }
    173                 else
     175              else
    174176                {
    175                     tor->update( child );
    176                     ++updatedCount;
    177                     if( tor->isMagnet() && tor->hasMetadata() )
     177                  tor->update (child);
     178                  ++updatedCount;
     179                  if (tor->isMagnet() && tor->hasMetadata())
    178180                    {
    179                         addIds.insert( tor->id() );
    180                         tor->setMagnet( false );
     181                      addIds.insert (tor->id());
     182                      tor->setMagnet (false);
    181183                    }
    182184                }
     
    185187    }
    186188
    187     if( !newTorrents.isEmpty( ) )
    188     {
    189         const int oldCount( rowCount( ) );
    190         const int newCount( oldCount + newTorrents.size( ) );
    191         QSet<int> ids;
    192