Changeset 14464


Ignore:
Timestamp:
Jan 28, 2015, 10:57:46 PM (6 years ago)
Author:
mikedld
Message:

Treat command-line arguments as UTF-8-encoded; hide char* Prefs setter, require explicit conversion

Location:
trunk/qt
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/app.cc

    r14433 r14464  
    3737#include "session-dialog.h"
    3838#include "torrent-model.h"
    39 #include "utils.h"
    4039#include "watchdir.h"
    4140
     
    6766  }
    6867
    69   void
    70   showUsage ()
    71   {
    72     tr_getopt_usage (MY_READABLE_NAME, getUsage (), opts);
    73     exit (0);
    74   }
    75 
    7668  enum
    7769  {
     
    152144  bool minimized = false;
    153145  const char * optarg;
    154   const char * host = 0;
    155   const char * port = 0;
    156   const char * username = 0;
    157   const char * password = 0;
    158   const char * configDir = 0;
     146  QString host;
     147  QString port;
     148  QString username;
     149  QString password;
     150  QString configDir;
    159151  QStringList filenames;
    160152  while ((c = tr_getopt (getUsage(), argc, const_cast<const char**> (argv), opts, &optarg)))
     
    162154      switch (c)
    163155        {
    164           case 'g': configDir = optarg; break;
    165           case 'p': port = optarg; break;
    166           case 'r': host = optarg; break;
    167           case 'u': username = optarg; break;
    168           case 'w': password = optarg; break;
     156          case 'g': configDir = QString::fromUtf8 (optarg); break;
     157          case 'p': port = QString::fromUtf8 (optarg); break;
     158          case 'r': host = QString::fromUtf8 (optarg); break;
     159          case 'u': username = QString::fromUtf8 (optarg); break;
     160          case 'w': password = QString::fromUtf8 (optarg); break;
    169161          case 'm': minimized = true; break;
    170           case 'v': std::cerr << MY_READABLE_NAME << ' ' << LONG_VERSION_STRING << std::endl; ::exit (0); break;
    171           case TR_OPT_ERR: Utils::toStderr (QObject::tr ("Invalid option")); showUsage (); break;
    172           default:         filenames.append (optarg); break;
     162          case 'v':
     163            std::cerr << MY_READABLE_NAME << ' ' << LONG_VERSION_STRING << std::endl;
     164            quitLater ();
     165            return;
     166          case TR_OPT_ERR:
     167            std::cerr << qPrintable(QObject::tr ("Invalid option")) << std::endl;
     168            tr_getopt_usage (MY_READABLE_NAME, getUsage (), opts);
     169            quitLater ();
     170            return;
     171          default:
     172            filenames.append (QString::fromUtf8 (optarg));
     173            break;
    173174        }
    174175    }
     
    207208    if (delegated)
    208209      {
    209         QTimer::singleShot (0, this, SLOT (quit ()));
     210        quitLater ();
    210211        return;
    211212      }
     
    213214
    214215  // set the fallback config dir
    215   if (configDir == 0)
    216     configDir = tr_getDefaultConfigDir ("transmission");
     216  if (configDir.isNull ())
     217    configDir = QString::fromUtf8 (tr_getDefaultConfigDir ("transmission"));
    217218
    218219  // ensure our config directory exists
     
    222223
    223224  // is this the first time we've run transmission?
    224   const bool firstTime = !QFile (QDir (configDir).absoluteFilePath ("settings.json")).exists ();
     225  const bool firstTime = !dir.exists ("settings.json");
    225226
    226227  // initialize the prefs
    227228  myPrefs = new Prefs (configDir);
    228   if (host != 0)
     229  if (!host.isNull ())
    229230    myPrefs->set (Prefs::SESSION_REMOTE_HOST, host);
    230   if (port != 0)
    231     myPrefs->set (Prefs::SESSION_REMOTE_PORT, port);
    232   if (username != 0)
     231  if (!port.isNull ())
     232    myPrefs->set (Prefs::SESSION_REMOTE_PORT, port.toUInt ());
     233  if (!username.isNull ())
    233234    myPrefs->set (Prefs::SESSION_REMOTE_USERNAME, username);
    234   if (password != 0)
     235  if (!password.isNull ())
    235236    myPrefs->set (Prefs::SESSION_REMOTE_PASSWORD, password);
    236   if ((host != 0) || (port != 0) || (username != 0) || (password != 0))
     237  if (!host.isNull () || !port.isNull () || !username.isNull () || !password.isNull ())
    237238    myPrefs->set (Prefs::SESSION_IS_REMOTE, true);
    238239  if (myPrefs->getBool (Prefs::START_MINIMIZED))
     
    330331        std::cerr << "couldn't register " << qPrintable (DBUS_OBJECT_PATH) << std::endl;
    331332    }
     333}
     334
     335void
     336MyApp::quitLater ()
     337{
     338  QTimer::singleShot (0, this, SLOT (quit ()));
    332339}
    333340
  • trunk/qt/app.h

    r14433 r14464  
    6868  private:
    6969    void maybeUpdateBlocklist ();
     70
     71    void quitLater ();
    7072};
    7173
  • trunk/qt/filterbar.cc

    r14454 r14464  
    624624              const bool isBootstrapping = myTrackerModel->rowCount () <= 2;
    625625              if (!isBootstrapping)
    626                 myPrefs.set (key, "");
     626                myPrefs.set (key, QString ());
    627627            }
    628628          break;
  • trunk/qt/mainwin.cc

    r14460 r14464  
    891891**/
    892892
    893 void TrMainWindow::showTotalRatio () { myPrefs.set (Prefs::STATUSBAR_STATS, "total-ratio"); }
    894 void TrMainWindow::showTotalTransfer () { myPrefs.set (Prefs::STATUSBAR_STATS, "total-transfer"); }
    895 void TrMainWindow::showSessionRatio () { myPrefs.set (Prefs::STATUSBAR_STATS, "session-ratio"); }
    896 void TrMainWindow::showSessionTransfer () { myPrefs.set (Prefs::STATUSBAR_STATS, "session-transfer"); }
     893void TrMainWindow::showTotalRatio () { myPrefs.set (Prefs::STATUSBAR_STATS, QString::fromLatin1 ("total-ratio")); }
     894void TrMainWindow::showTotalTransfer () { myPrefs.set (Prefs::STATUSBAR_STATS, QString::fromLatin1 ("total-transfer")); }
     895void TrMainWindow::showSessionRatio () { myPrefs.set (Prefs::STATUSBAR_STATS, QString::fromLatin1 ("session-ratio")); }
     896void TrMainWindow::showSessionTransfer () { myPrefs.set (Prefs::STATUSBAR_STATS, QString::fromLatin1 ("session-transfer")); }
    897897
    898898/**
  • trunk/qt/prefs.cc

    r14404 r14464  
    126126***/
    127127
    128 Prefs::Prefs (const char * configDir):
    129   myConfigDir (QString::fromUtf8 (configDir))
     128Prefs::Prefs (const QString& configDir):
     129  myConfigDir (configDir)
    130130{
    131131  assert (sizeof(myItems) / sizeof(myItems[0]) == PREFS_COUNT);
     
    143143  tr_variantInitDict (&top, 0);
    144144  initDefaults (&top);
    145   tr_sessionLoadSettings (&top, configDir, NULL);
     145  tr_sessionLoadSettings (&top, myConfigDir.toUtf8 ().constData (), NULL);
    146146
    147147  for (int i=0; i<PREFS_COUNT; ++i)
  • trunk/qt/prefs.h

    r14404 r14464  
    2626}
    2727
     28#include <QDebug>
    2829class Prefs: public QObject
    2930{
     
    145146  private:
    146147    QSet<int> myTemporaryPrefs;
    147     QString myConfigDir;
     148    QString const myConfigDir;
    148149    mutable QVariant myValues[PREFS_COUNT];
    149150    void initDefaults (tr_variant *);
     151
     152    void set (int key, const char * value);
    150153
    151154  public:
     
    157160    const QVariant& variant (int i) const { return myValues[i]; }
    158161
    159     Prefs (const char * configDir);
     162    Prefs (const QString& configDir);
    160163    ~Prefs ();
    161164
     
    168171    template<typename T> T get (int key) const { return myValues[key].value<T>(); }
    169172
    170     void set (int key, const char * value) { set (key, QString::fromUtf8 (value)); }
    171 
    172173    template<typename T> void set (int key, const T& value)
    173174    {
     
    176177      if (v.isNull() || (v!=tmp))
    177178        {
     179          qDebug () << key << ":" << v << "->" << tmp;
    178180          v = tmp;
    179181          emit changed (key);
  • trunk/qt/session.cc

    r14428 r14464  
    275275***/
    276276
    277 Session::Session (const char * configDir, Prefs& prefs):
     277Session::Session (const QString& configDir, Prefs& prefs):
    278278  nextUniqueTag (FIRST_UNIQUE_TAG),
    279279  myBlocklistSize (-1),
    280280  myPrefs (prefs),
    281281  mySession (0),
    282   myConfigDir (QString::fromUtf8 (configDir))
     282  myConfigDir (configDir)
    283283{
    284284  myStats.ratio = TR_RATIO_NA;
     
    831831  if (mySession != 0)
    832832    {
    833       myPrefs.set (Prefs::RPC_ENABLED,           tr_sessionIsRPCEnabled          (mySession));
    834       myPrefs.set (Prefs::RPC_AUTH_REQUIRED,     tr_sessionIsRPCPasswordEnabled  (mySession));
    835       myPrefs.set (Prefs::RPC_PASSWORD,          tr_sessionGetRPCPassword        (mySession));
    836       myPrefs.set (Prefs::RPC_PORT,              tr_sessionGetRPCPort            (mySession));
    837       myPrefs.set (Prefs::RPC_USERNAME,          tr_sessionGetRPCUsername        (mySession));
     833      myPrefs.set (Prefs::RPC_ENABLED,           tr_sessionIsRPCEnabled (mySession));
     834      myPrefs.set (Prefs::RPC_AUTH_REQUIRED,     tr_sessionIsRPCPasswordEnabled (mySession));
     835      myPrefs.set (Prefs::RPC_PASSWORD,          QString::fromUtf8 (tr_sessionGetRPCPassword (mySession)));
     836      myPrefs.set (Prefs::RPC_PORT,              tr_sessionGetRPCPort (mySession));
     837      myPrefs.set (Prefs::RPC_USERNAME,          QString::fromUtf8 (tr_sessionGetRPCUsername (mySession)));
    838838      myPrefs.set (Prefs::RPC_WHITELIST_ENABLED, tr_sessionGetRPCWhitelistEnabled (mySession));
    839       myPrefs.set (Prefs::RPC_WHITELIST,         tr_sessionGetRPCWhitelist       (mySession));
     839      myPrefs.set (Prefs::RPC_WHITELIST,         QString::fromUtf8 (tr_sessionGetRPCWhitelist (mySession)));
    840840    }
    841841
  • trunk/qt/session.h

    r14405 r14464  
    5252
    5353  public:
    54     Session (const char * configDir, Prefs& prefs);
     54    Session (const QString& configDir, Prefs& prefs);
    5555    ~Session ();
    5656
     
    159159    Prefs& myPrefs;
    160160    tr_session * mySession;
    161     QString myConfigDir;
     161    QString const myConfigDir;
    162162    QStringList myIdleJSON;
    163163    tr_session_stats myStats;
  • trunk/qt/utils.cc

    r14462 r14464  
    77 * $Id$
    88 */
    9 
    10 #include <iostream>
    119
    1210#ifdef _WIN32
     
    4442extern QPixmap qt_pixmapFromWinHICON(HICON icon);
    4543#endif
    46 
    47 void
    48 Utils::toStderr (const QString& str)
    49 {
    50   std::cerr << qPrintable(str) << std::endl;
    51 }
    5244
    5345#ifdef _WIN32
  • trunk/qt/utils.h

    r14462 r14464  
    4242    }
    4343
    44     // meh
    45     static void toStderr (const QString& qstr);
    46 
    4744    ///
    4845    /// URLs
Note: See TracChangeset for help on using the changeset viewer.