From 17d6666b4c32b9a8ae693a5f7543e766205f6b23 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Sat, 27 Dec 2014 14:07:14 +0000 Subject: [PATCH] A bit of harmless refactoring Prefer C++-style over C-style type casting. Use qApp instead of QApplication/QCoreApplication::instance(). Use explicit QString::fromLatin1()/fromUtf8() where applicable. --- qt/about.cc | 2 +- qt/add-data.cc | 2 +- qt/app.cc | 8 ++++---- qt/app.h | 3 +++ qt/details.cc | 6 +++--- qt/file-tree.cc | 14 +++++++------- qt/filterbar.cc | 6 +++--- qt/formatter.cc | 6 +++--- qt/mainwin.cc | 26 +++++++++++++------------- qt/make-dialog.cc | 2 +- qt/options.cc | 8 ++++---- qt/prefs.cc | 4 ++-- qt/prefs.h | 1 - qt/session.cc | 36 ++++++++++++++++++------------------ qt/torrent-delegate-min.cc | 8 ++++---- qt/torrent-delegate.cc | 10 +++++----- qt/torrent.cc | 15 +++++++-------- qt/torrent.h | 8 ++++---- qt/tracker-delegate.cc | 2 +- qt/tracker-model.cc | 2 +- qt/utils.cc | 6 +++--- 21 files changed, 88 insertions(+), 87 deletions(-) diff --git a/qt/about.cc b/qt/about.cc index 70dca2250..3afed9f1c 100644 --- a/qt/about.cc +++ b/qt/about.cc @@ -24,7 +24,7 @@ AboutDialog::AboutDialog (QWidget * parent): { ui.setupUi (this); - ui.iconLabel->setPixmap (QApplication::windowIcon ().pixmap (48)); + ui.iconLabel->setPixmap (qApp->windowIcon ().pixmap (48)); ui.titleLabel->setText (tr ("Transmission %1").arg (QString::fromUtf8 (LONG_VERSION_STRING))); QPushButton * b; diff --git a/qt/add-data.cc b/qt/add-data.cc index 137175902..fffc37261 100644 --- a/qt/add-data.cc +++ b/qt/add-data.cc @@ -102,7 +102,7 @@ AddData::readableName () const { tr_info inf; tr_ctor * ctor = tr_ctorNew (NULL); - tr_ctorSetMetainfo (ctor, (const quint8*)metainfo.constData(), metainfo.size()); + tr_ctorSetMetainfo (ctor, reinterpret_cast (metainfo.constData()), metainfo.size()); if (tr_torrentParse (ctor, &inf) == TR_PARSE_OK ) { ret = QString::fromUtf8 (inf.name); // metainfo is required to be UTF-8 diff --git a/qt/app.cc b/qt/app.cc index 8eab9e33c..883fb43a8 100644 --- a/qt/app.cc +++ b/qt/app.cc @@ -153,7 +153,7 @@ MyApp::MyApp (int& argc, char ** argv): const char * password = 0; const char * configDir = 0; QStringList filenames; - while ((c = tr_getopt (getUsage(), argc, (const char**)argv, opts, &optarg))) + while ((c = tr_getopt (getUsage(), argc, const_cast (argv), opts, &optarg))) { switch (c) { @@ -371,7 +371,7 @@ MyApp::onTorrentCompleted (int id) if (myPrefs->getBool (Prefs::COMPLETE_SOUND_ENABLED)) { #if defined (Q_OS_WIN) || defined (Q_OS_MAC) - QApplication::beep (); + beep (); #else QProcess::execute (myPrefs->getString (Prefs::COMPLETE_SOUND_COMMAND)); #endif @@ -533,7 +533,7 @@ MyApp::addTorrent (const AddData& addme) void MyApp::raise () { - QApplication::alert (myWindow); + alert (myWindow); } bool @@ -552,7 +552,7 @@ MyApp::notifyApp (const QString& title, const QString& body) const args.append (body); // body args.append (QStringList ()); // actions - unused for plain passive popups args.append (QVariantMap ()); // hints - unused atm - args.append (int32_t (-1)); // use the default timeout period + args.append (static_cast (-1)); // use the default timeout period m.setArguments (args); QDBusMessage replyMsg = QDBusConnection::sessionBus ().call (m); //std::cerr << qPrintable (replyMsg.errorName ()) << std::endl; diff --git a/qt/app.h b/qt/app.h index 7d2a5484c..1ddae1868 100644 --- a/qt/app.h +++ b/qt/app.h @@ -69,4 +69,7 @@ class MyApp: public QApplication void maybeUpdateBlocklist (); }; +#undef qApp +#define qApp static_cast (MyApp::instance ()) + #endif diff --git a/qt/details.cc b/qt/details.cc index 36137c501..cd29e86ae 100644 --- a/qt/details.cc +++ b/qt/details.cc @@ -482,7 +482,7 @@ Details::refresh () else if (sizeWhenDone == 0) string = none; else - string = QString ("%1%").arg (Formatter::percentToString ( (100.0 * available) / sizeWhenDone)); + string = QString::fromLatin1 ("%1%").arg (Formatter::percentToString ( (100.0 * available) / sizeWhenDone)); ui.availabilityValueLabel->setText (string); // myDownloadedLabel @@ -900,7 +900,7 @@ Details::refresh () } if (!txt.isEmpty ()) - codeTip += QString ("%1: %2\n").arg (ch).arg (txt); + codeTip += QString::fromLatin1 ("%1: %2\n").arg (ch).arg (txt); } if (!codeTip.isEmpty ()) @@ -908,7 +908,7 @@ Details::refresh () item->setText (COL_UP, peer.rateToPeer.isZero () ? "" : Formatter::speedToString (peer.rateToPeer)); item->setText (COL_DOWN, peer.rateToClient.isZero () ? "" : Formatter::speedToString (peer.rateToClient)); - item->setText (COL_PERCENT, peer.progress > 0 ? QString ("%1%").arg ( (int) (peer.progress * 100.0)) : ""); + item->setText (COL_PERCENT, peer.progress > 0 ? QString::fromLatin1 ("%1%").arg ( (int) (peer.progress * 100.0)) : ""); item->setText (COL_STATUS, code); item->setToolTip (COL_STATUS, codeTip); diff --git a/qt/file-tree.cc b/qt/file-tree.cc index 39410cd3a..ea209ea24 100644 --- a/qt/file-tree.cc +++ b/qt/file-tree.cc @@ -158,7 +158,7 @@ FileTreeItem::data (int column, int role) const else if (role == Qt::DecorationRole && column == COL_NAME) { if (childCount () > 0) - value = QApplication::style ()->standardIcon (QStyle::SP_DirOpenIcon); + value = qApp->style ()->standardIcon (QStyle::SP_DirOpenIcon); else value = Utils::guessMimeIcon (name ()); } @@ -815,7 +815,7 @@ FileTreeDelegate::paint (QPainter * painter, return; } - QStyle * style (QApplication::style ()); + QStyle * style (qApp->style ()); painter->save(); QItemDelegate::drawBackground (painter, option, index); @@ -824,11 +824,11 @@ FileTreeDelegate::paint (QPainter * painter, { QStyleOptionProgressBar p; p.state = option.state | QStyle::State_Small; - p.direction = QApplication::layoutDirection(); + p.direction = qApp->layoutDirection(); p.rect = option.rect; p.rect.setSize (QSize(option.rect.width()-2, option.rect.height()-8)); p.rect.moveCenter (option.rect.center()); - p.fontMetrics = QApplication::fontMetrics(); + p.fontMetrics = qApp->fontMetrics(); p.minimum = 0; p.maximum = 100; p.textAlignment = Qt::AlignCenter; @@ -841,10 +841,10 @@ FileTreeDelegate::paint (QPainter * painter, { QStyleOptionButton o; o.state = option.state; - o.direction = QApplication::layoutDirection(); + o.direction = qApp->layoutDirection(); o.rect.setSize (QSize(20, option.rect.height())); o.rect.moveCenter (option.rect.center()); - o.fontMetrics = QApplication::fontMetrics(); + o.fontMetrics = qApp->fontMetrics(); switch (index.data().toInt()) { case Qt::Unchecked: o.state |= QStyle::State_Off; break; @@ -948,7 +948,7 @@ FileTreeView::eventFilter (QObject * o, QEvent * event) // space is left over... if ((o == this) && (event->type() == QEvent::Resize)) { - QResizeEvent * r = dynamic_cast(event); + QResizeEvent * r = static_cast (event); int left = r->size().width(); const QFontMetrics fontMetrics(font()); for (int column=FIRST_VISIBLE_COLUMN; column<=LAST_VISIBLE_COLUMN; ++column) diff --git a/qt/filterbar.cc b/qt/filterbar.cc index a9088af21..4d80e5ae1 100644 --- a/qt/filterbar.cc +++ b/qt/filterbar.cc @@ -357,7 +357,7 @@ namespace void FilterBar::refreshTrackers () { - Favicons& favicons = dynamic_cast (QApplication::instance ())->favicons; + Favicons& favicons = qApp->favicons; const int firstTrackerRow = 2; // skip over the "All" and separator... // pull info from the tracker model... @@ -483,7 +483,7 @@ FilterBar::FilterBar (Prefs& prefs, TorrentModel& torrents, TorrentFilter& filte myIsBootstrapping (true) { QHBoxLayout * h = new QHBoxLayout (this); - const int hmargin = qMax (int (HIG::PAD), style ()->pixelMetric (QStyle::PM_LayoutHorizontalSpacing)); + const int hmargin = qMax (static_cast (HIG::PAD), style ()->pixelMetric (QStyle::PM_LayoutHorizontalSpacing)); myCountLabel = new QLabel (this); h->setSpacing (0); @@ -653,7 +653,7 @@ FilterBar::recount () QString FilterBar::getCountString (int n) const { - return QString ("%L1").arg (n); + return QString::fromLatin1 ("%L1").arg (n); } void diff --git a/qt/formatter.cc b/qt/formatter.cc index 1e7043ce4..936a7ab09 100644 --- a/qt/formatter.cc +++ b/qt/formatter.cc @@ -75,13 +75,13 @@ Formatter::initUnits () double Speed::KBps () const { - return _Bps / (double)speed_K; + return _Bps / static_cast (speed_K); } Speed Speed::fromKBps (double KBps) { - return int (KBps * speed_K); + return static_cast (KBps * speed_K); } /*** @@ -144,7 +144,7 @@ QString Formatter::percentToString (double x) { char buf[128]; - return QString (tr_strpercent (buf, x, sizeof (buf))); + return QString::fromUtf8 (tr_strpercent (buf, x, sizeof (buf))); } QString diff --git a/qt/mainwin.cc b/qt/mainwin.cc index 6d2f3b830..9e29ecec0 100644 --- a/qt/mainwin.cc +++ b/qt/mainwin.cc @@ -188,7 +188,7 @@ TrMainWindow::TrMainWindow (Session& session, Prefs& prefs, TorrentModel& model, connect (&myFilterModel, SIGNAL (rowsInserted (QModelIndex, int, int)), this, SLOT (refreshActionSensitivitySoon ())); connect (&myFilterModel, SIGNAL (rowsRemoved (QModelIndex, int, int)), this, SLOT (refreshActionSensitivitySoon ())); - connect (ui.action_Quit, SIGNAL (triggered ()), QCoreApplication::instance (), SLOT (quit ())); + connect (ui.action_Quit, SIGNAL (triggered ()), qApp, SLOT (quit ())); // torrent view myFilterModel.setSourceModel (&myModel); @@ -230,7 +230,7 @@ TrMainWindow::TrMainWindow (Session& session, Prefs& prefs, TorrentModel& model, menu->addSeparator (); menu->addAction (ui.action_Quit); myTrayIcon.setContextMenu (menu); - myTrayIcon.setIcon (QIcon::fromTheme ("transmission-tray-icon", QApplication::windowIcon ())); + myTrayIcon.setIcon (QIcon::fromTheme ("transmission-tray-icon", qApp->windowIcon ())); connect (&myPrefs, SIGNAL (changed (int)), this, SLOT (refreshPref (int))); connect (ui.action_ShowMainWindow, SIGNAL (triggered (bool)), this, SLOT (toggleWindows (bool))); @@ -942,7 +942,7 @@ TrMainWindow::toggleWindows (bool doShow) if (isMinimized ()) showNormal (); //activateWindow (); raise (); - QApplication::setActiveWindow (this); + qApp->setActiveWindow (this); } } @@ -1041,7 +1041,7 @@ TrMainWindow::refreshPref (int key) b = myPrefs.getBool (key); ui.action_TrayIcon->setChecked (b); myTrayIcon.setVisible (b); - dynamic_cast (QCoreApplication::instance ())->setQuitOnLastWindowClosed (!b); + qApp->setQuitOnLastWindowClosed (!b); refreshTrayIconSoon (); break; @@ -1117,7 +1117,7 @@ TrMainWindow::openTorrent () QCheckBox * b = new QCheckBox (tr ("Show &options dialog")); b->setChecked (myPrefs.getBool (Prefs::OPTIONS_PROMPT)); b->setObjectName (SHOW_OPTIONS_CHECKBOX_NAME); - auto l = dynamic_cast (d->layout ()); + auto l = qobject_cast (d->layout ()); if (l == nullptr) { l = new QGridLayout; @@ -1134,10 +1134,10 @@ TrMainWindow::openTorrent () void TrMainWindow::openURL () { - QString str = QApplication::clipboard ()->text (QClipboard::Selection); + QString str = qApp->clipboard ()->text (QClipboard::Selection); if (!AddData::isSupported (str)) - str = QApplication::clipboard ()->text (QClipboard::Clipboard); + str = qApp->clipboard ()->text (QClipboard::Clipboard); if (!AddData::isSupported (str)) str.clear (); @@ -1169,12 +1169,12 @@ TrMainWindow::addTorrent (const AddData& addMe, bool showOptions) { Options * o = new Options (mySession, myPrefs, addMe, this); o->show (); - QApplication::alert (o); + qApp->alert (o); } else { mySession.addTorrent (addMe); - QApplication::alert (this); + qApp->alert (this); } } @@ -1258,14 +1258,14 @@ TrMainWindow::removeTorrents (const bool deleteFiles) } } - msgBox.setWindowTitle (QString (" ")); - msgBox.setText (QString ("%1").arg (primary_text)); + msgBox.setWindowTitle (QLatin1String (" ")); + msgBox.setText (QString::fromLatin1 ("%1").arg (primary_text)); msgBox.setInformativeText (secondary_text); msgBox.setStandardButtons (QMessageBox::Ok | QMessageBox::Cancel); msgBox.setDefaultButton (QMessageBox::Cancel); msgBox.setIcon (QMessageBox::Question); // hack needed to keep the dialog from being too narrow - auto layout = dynamic_cast(msgBox.layout()); + auto layout = qobject_cast (msgBox.layout ()); if (layout == nullptr) { layout = new QGridLayout; @@ -1417,7 +1417,7 @@ TrMainWindow::dropEvent (QDropEvent * event) if (url.scheme () == "file") key = QUrl::fromPercentEncoding (url.path().toUtf8()); - dynamic_cast (QApplication::instance ())->addTorrent (key); + qApp->addTorrent (key); } } } diff --git a/qt/make-dialog.cc b/qt/make-dialog.cc index ce851de75..176507e6e 100644 --- a/qt/make-dialog.cc +++ b/qt/make-dialog.cc @@ -76,7 +76,7 @@ MakeDialog::onProgress () // progress bar const tr_metainfo_builder * b = myBuilder; const double denom = b->pieceCount ? b->pieceCount : 1; - myNewProgress->setValue ((int) ((100.0 * b->pieceIndex) / denom)); + myNewProgress->setValue (static_cast ((100.0 * b->pieceIndex) / denom)); // progress label const QString top = QString::fromLocal8Bit (myBuilder->top); diff --git a/qt/options.cc b/qt/options.cc index f076262fd..88f41644b 100644 --- a/qt/options.cc +++ b/qt/options.cc @@ -237,10 +237,10 @@ Options::eventFilter (QObject * o, QEvent * event) if (event->type() == QEvent::Resize) { if (o == mySourceButton) - refreshSource (dynamic_cast (event)->size ().width ()); + refreshSource (static_cast (event)->size ().width ()); else if (o == myDestinationButton) - refreshDestinationButton (dynamic_cast (event)->size ().width ()); + refreshDestinationButton (static_cast (event)->size ().width ()); } return false; @@ -529,7 +529,7 @@ Options::onTimeout () int64_t leftInPiece = getPieceSize (&myInfo, myVerifyPieceIndex) - myVerifyPiecePos; int64_t leftInFile = file->length - myVerifyFilePos; int64_t bytesThisPass = std::min (leftInFile, leftInPiece); - bytesThisPass = std::min (bytesThisPass, (int64_t)sizeof (myVerifyBuf)); + bytesThisPass = std::min (bytesThisPass, static_cast (sizeof (myVerifyBuf))); if (myVerifyFile.isOpen () && myVerifyFile.seek (myVerifyFilePos)) { @@ -588,7 +588,7 @@ Options::onTimeout () if (!have) // everything failed { // did the user accidentally specify the child directory instead of the parent? - const QStringList tokens = QString (file->name).split ('/'); + const QStringList tokens = QString::fromUtf8 (file->name).split ('/'); if (!tokens.empty () && myLocalDestination.dirName ()==tokens.at (0)) { // move up one directory and try again diff --git a/qt/prefs.cc b/qt/prefs.cc index 733a0002c..81709ac55 100644 --- a/qt/prefs.cc +++ b/qt/prefs.cc @@ -157,7 +157,7 @@ Prefs::Prefs (const char * configDir): { case QVariant::Int: if (tr_variantGetInt (b, &intVal)) - myValues[i].setValue (qlonglong(intVal)); + myValues[i].setValue (static_cast (intVal)); break; case TrTypes::SortModeType: @@ -177,7 +177,7 @@ Prefs::Prefs (const char * configDir): case QVariant::Bool: if (tr_variantGetBool (b, &boolVal)) - myValues[i].setValue (bool(boolVal)); + myValues[i].setValue (static_cast (boolVal)); break; case QVariant::Double: diff --git a/qt/prefs.h b/qt/prefs.h index 48de0df0e..ba3de1d54 100644 --- a/qt/prefs.h +++ b/qt/prefs.h @@ -167,7 +167,6 @@ class Prefs: public QObject template T get (int key) const { return myValues[key].value(); } - void set (int key, char * value) { set (key, QString::fromUtf8 (value)); } void set (int key, const char * value) { set (key, QString::fromUtf8 (value)); } template void set (int key, const T& value) diff --git a/qt/session.cc b/qt/session.cc index 859e06152..8cbf8b844 100644 --- a/qt/session.cc +++ b/qt/session.cc @@ -104,7 +104,7 @@ FileAdded::executed (int64_t tag, const QString& result, tr_variant * arguments) { const QString myFilename = QFileInfo (myName).fileName (); const QString name = QString::fromUtf8 (str); - QMessageBox::warning (QApplication::activeWindow (), + QMessageBox::warning (qApp->activeWindow (), tr ("Add Torrent"), tr ("

Unable to add \"%1\".

It is a duplicate of \"%2\" which is already added.

").arg (myFilename).arg (name)); } @@ -124,9 +124,9 @@ FileAdded::executed (int64_t tag, const QString& result, tr_variant * arguments) if (!i || text[i-1].isSpace ()) text[i] = text[i].toUpper (); - QMessageBox::warning (QApplication::activeWindow (), + QMessageBox::warning (qApp->activeWindow (), tr ("Error Adding Torrent"), - QString ("

%1

%2

").arg (text).arg (myName)); + QString::fromLatin1 ("

%1

%2

").arg (text).arg (myName)); } deleteLater (); @@ -719,8 +719,8 @@ Session::localSessionCallback (tr_session * s, evbuffer * json, void * vself) /* this callback is invoked in the libtransmission thread, so we don't want to process the response here... let's push it over to the Qt thread. */ - self->responseReceived (QByteArray ( (const char *)evbuffer_pullup (json, -1), - (int)evbuffer_get_length (json))); + self->responseReceived (QByteArray (reinterpret_cast (evbuffer_pullup (json, -1)), + static_cast (evbuffer_get_length (json)))); } #define REQUEST_DATA_PROPERTY_KEY "requestData" @@ -736,7 +736,7 @@ Session::exec (const char * json) { QNetworkRequest request; request.setUrl (myUrl); - request.setRawHeader ("User-Agent", QString (QCoreApplication::instance ()->applicationName () + "/" + LONG_VERSION_STRING).toUtf8 ()); + request.setRawHeader ("User-Agent", (qApp->applicationName () + "/" + LONG_VERSION_STRING).toUtf8 ()); request.setRawHeader ("Content-Type", "application/json; charset=UTF-8"); if (!mySessionId.isEmpty ()) @@ -779,7 +779,7 @@ Session::onFinished (QNetworkReply * reply) { // we got a 409 telling us our session id has expired. // update it and resubmit the request. - mySessionId = QString (reply->rawHeader (TR_RPC_SESSION_ID_HEADER)); + mySessionId = QString::fromUtf8 (reply->rawHeader (TR_RPC_SESSION_ID_HEADER)); exec (reply->property (REQUEST_DATA_PROPERTY_KEY).toByteArray ().constData ()); } else if (reply->error () != QNetworkReply::NoError) @@ -871,7 +871,7 @@ Session::parseResponse (const char * json, size_t jsonLength) const QString text = tr ("

Unable to rename \"%1\" as \"%2\": %3.

Please correct the errors and try again.

").arg (path).arg (name).arg (result); QMessageBox * d = new QMessageBox (QMessageBox::Information, title, text, QMessageBox::Close, - QApplication::activeWindow ()); + qApp->activeWindow ()); connect (d, SIGNAL (rejected ()), d, SLOT (deleteLater ())); d->show (); } @@ -879,8 +879,8 @@ Session::parseResponse (const char * json, size_t jsonLength) { // let's get the updated file list char * req = tr_strdup_printf ("{ \"arguments\": { \"fields\": [ \"fileStats\", \"files\", \"id\", \"name\" ], \"ids\": %d }, \"method\": \"torrent-get\", \"tag\": %d }", - int (id), - int (TAG_SOME_TORRENTS)); + static_cast (id), + static_cast (TAG_SOME_TORRENTS)); exec (req); tr_free (req); } @@ -889,10 +889,10 @@ Session::parseResponse (const char * json, size_t jsonLength) } case TAG_PORT_TEST: { - bool isOpen = 0; + bool isOpen = false; if (tr_variantDictFindDict (&top, TR_KEY_arguments, &args)) tr_variantDictFindBool (args, TR_KEY_port_is_open, &isOpen); - emit portTested ( (bool)isOpen); + emit portTested (isOpen); break; } @@ -905,7 +905,7 @@ Session::parseResponse (const char * json, size_t jsonLength) && tr_variantDictFindList (args, TR_KEY_torrents, &torrents) && ( (child = tr_variantListChild (torrents, 0))) && tr_variantDictFindStr (child, TR_KEY_magnetLink, &str, NULL)) - QApplication::clipboard ()->setText (str); + qApp->clipboard ()->setText (str); break; } @@ -916,7 +916,7 @@ Session::parseResponse (const char * json, size_t jsonLength) tr ("Add Torrent"), QString::fromUtf8 (str), QMessageBox::Close, - QApplication::activeWindow ()); + qApp->activeWindow ()); connect (d, SIGNAL (rejected ()), d, SLOT (deleteLater ())); d->show (); } @@ -999,7 +999,7 @@ Session::updateInfo (tr_variant * d) { int64_t val; if (tr_variantGetInt (b, &val)) - myPrefs.set (i, (int)val); + myPrefs.set (i, static_cast(val)); break; } case QVariant::Double: @@ -1013,7 +1013,7 @@ Session::updateInfo (tr_variant * d) { bool val; if (tr_variantGetBool (b, &val)) - myPrefs.set (i, (bool)val); + myPrefs.set (i, val); break; } case TrTypes::FilterModeType: @@ -1022,7 +1022,7 @@ Session::updateInfo (tr_variant * d) { const char * val; if (tr_variantGetStr (b, &val, NULL)) - myPrefs.set (i, QString (val)); + myPrefs.set (i, QString::fromUtf8 (val)); break; } default: @@ -1033,7 +1033,7 @@ Session::updateInfo (tr_variant * d) bool b; double x; if (tr_variantDictFindBool (d, TR_KEY_seedRatioLimited, &b)) - myPrefs.set (Prefs::RATIO_ENABLED, b ? true : false); + myPrefs.set (Prefs::RATIO_ENABLED, b); if (tr_variantDictFindReal (d, TR_KEY_seedRatioLimit, &x)) myPrefs.set (Prefs::RATIO, x); diff --git a/qt/torrent-delegate-min.cc b/qt/torrent-delegate-min.cc index 9d809965f..e3a182023 100644 --- a/qt/torrent-delegate-min.cc +++ b/qt/torrent-delegate-min.cc @@ -47,7 +47,7 @@ QSize TorrentDelegateMin::sizeHint (const QStyleOptionViewItem & option, const Torrent & tor) const { - const QStyle* style (QApplication::style()); + const QStyle* style (qApp->style()); static const int iconSize (style->pixelMetric (QStyle::PM_SmallIconSize)); QFont nameFont (option.font); @@ -57,7 +57,7 @@ TorrentDelegateMin::sizeHint (const QStyleOptionViewItem & option, const int nameWidth = nameFM.width (nameStr); QFont statusFont (option.font); - statusFont.setPointSize (int (option.font.pointSize() * 0.85)); + statusFont.setPointSize (static_cast (option.font.pointSize() * 0.85)); const QFontMetrics statusFM (statusFont); const QString statusStr (shortStatusString (tor)); const int statusWidth = statusFM.width (statusStr); @@ -76,7 +76,7 @@ TorrentDelegateMin::drawTorrent (QPainter * painter, const Torrent & tor) const { const bool isPaused (tor.isPaused()); - const QStyle * style (QApplication::style()); + const QStyle * style (qApp->style()); static const int iconSize (style->pixelMetric (QStyle::PM_SmallIconSize)); QFont nameFont (option.font); @@ -85,7 +85,7 @@ TorrentDelegateMin::drawTorrent (QPainter * painter, const QString nameStr = (isMagnet ? progressString (tor) : tor.name()); QFont statusFont (option.font); - statusFont.setPointSize (int (option.font.pointSize() * 0.85)); + statusFont.setPointSize (static_cast (option.font.pointSize() * 0.85)); const QFontMetrics statusFM (statusFont); const QString statusStr (shortStatusString (tor)); const QSize statusSize (statusFM.size (0, statusStr)); diff --git a/qt/torrent-delegate.cc b/qt/torrent-delegate.cc index d132bbc6f..3949c25f8 100644 --- a/qt/torrent-delegate.cc +++ b/qt/torrent-delegate.cc @@ -290,7 +290,7 @@ namespace QSize TorrentDelegate::sizeHint (const QStyleOptionViewItem& option, const Torrent& tor) const { - const QStyle* style (QApplication::style ()); + const QStyle* style (qApp->style ()); static const int iconSize (style->pixelMetric (QStyle::PM_MessageBoxIconSize)); QFont nameFont (option.font); @@ -299,7 +299,7 @@ TorrentDelegate::sizeHint (const QStyleOptionViewItem& option, const Torrent& to const QString nameStr (tor.name ()); const int nameWidth = nameFM.width (nameStr); QFont statusFont (option.font); - statusFont.setPointSize (int (option.font.pointSize () * 0.9)); + statusFont.setPointSize (static_cast (option.font.pointSize () * 0.9)); const QFontMetrics statusFM (statusFont); const QString statusStr (statusString (tor)); const int statusWidth = statusFM.width (statusStr); @@ -348,7 +348,7 @@ TorrentDelegate::setProgressBarPercentDone (const QStyleOptionViewItem & option, { const bool isMagnet (!tor.hasMetadata ()); myProgressBarStyle->direction = option.direction; - myProgressBarStyle->progress = int(myProgressBarStyle->minimum + (((isMagnet ? tor.metadataPercentDone() : tor.percentDone()) * (myProgressBarStyle->maximum - myProgressBarStyle->minimum)))); + myProgressBarStyle->progress = static_cast (myProgressBarStyle->minimum + (((isMagnet ? tor.metadataPercentDone() : tor.percentDone()) * (myProgressBarStyle->maximum - myProgressBarStyle->minimum)))); } } @@ -357,7 +357,7 @@ TorrentDelegate::drawTorrent (QPainter * painter, const QStyleOptionViewItem & option, const Torrent & tor) const { - const QStyle * style (QApplication::style ()); + const QStyle * style (qApp->style ()); static const int iconSize (style->pixelMetric (QStyle::PM_LargeIconSize)); QFont nameFont (option.font); nameFont.setWeight (QFont::Bold); @@ -365,7 +365,7 @@ TorrentDelegate::drawTorrent (QPainter * painter, const QString nameStr (tor.name ()); const QSize nameSize (nameFM.size (0, nameStr)); QFont statusFont (option.font); - statusFont.setPointSize (int (option.font.pointSize () * 0.9)); + statusFont.setPointSize (static_cast (option.font.pointSize () * 0.9)); const QFontMetrics statusFM (statusFont); const QString statusStr (progressString (tor)); QFont progressFont (statusFont); diff --git a/qt/torrent.cc b/qt/torrent.cc index 73bdaf0cb..e28e226cc 100644 --- a/qt/torrent.cc +++ b/qt/torrent.cc @@ -39,7 +39,7 @@ Torrent::Torrent (Prefs& prefs, int id): #endif setInt (ID, id); - setIcon (MIME_ICON, QApplication::style()->standardIcon (QStyle::SP_FileIcon)); + setIcon (MIME_ICON, qApp->style()->standardIcon (QStyle::SP_FileIcon)); } Torrent::~Torrent () @@ -393,9 +393,9 @@ Torrent::compareRatio (const Torrent& that) const { const double a = ratio (); const double b = that.ratio (); - if ((int)a == TR_RATIO_INF && (int)b == TR_RATIO_INF) return 0; - if ((int)a == TR_RATIO_INF) return 1; - if ((int)b == TR_RATIO_INF) return -1; + if (static_cast (a) == TR_RATIO_INF && static_cast (b) == TR_RATIO_INF) return 0; + if (static_cast (a) == TR_RATIO_INF) return 1; + if (static_cast (b) == TR_RATIO_INF) return -1; if (a < b) return -1; if (a > b) return 1; return 0; @@ -605,7 +605,7 @@ Torrent::update (tr_variant * d) { if (tr_variantDictFindStr(child, TR_KEY_announce, &str, &len)) { - dynamic_cast(QApplication::instance())->favicons.add (QUrl(QString::fromUtf8(str))); + qApp->favicons.add (QUrl(QString::fromUtf8(str))); list.append (QString::fromUtf8 (str, len)); } } @@ -645,7 +645,7 @@ Torrent::update (tr_variant * d) if (tr_variantDictFindStr(child, TR_KEY_announce, &str, &len)) { trackerStat.announce = QString::fromUtf8 (str, len); - dynamic_cast(QApplication::instance())->favicons.add (QUrl (trackerStat.announce)); + qApp->favicons.add (QUrl (trackerStat.announce)); } if (tr_variantDictFindInt (child, TR_KEY_announceState, &i)) @@ -801,7 +801,6 @@ Torrent::getError () const QPixmap TrackerStat::getFavicon () const { - MyApp * myApp = dynamic_cast(QApplication::instance()); - return myApp->favicons.find (QUrl (announce)); + return qApp->favicons.find (QUrl (announce)); } diff --git a/qt/torrent.h b/qt/torrent.h index 155681919..4ee012d1a 100644 --- a/qt/torrent.h +++ b/qt/torrent.h @@ -267,7 +267,7 @@ class Torrent: public QObject bool isMagnet () const { return magnetTorrent; } int pieceCount () const { return getInt (PIECE_COUNT); } double ratio () const { return getDouble (RATIO); } - double percentComplete () const { return haveTotal() / (double)totalSize(); } + double percentComplete () const { return haveTotal() / static_cast (totalSize()); } double percentDone () const { return getDouble (PERCENT_DONE); } double metadataPercentDone () const { return getDouble (METADATA_PERCENT_DONE); } uint64_t downloadedEver () const { return getSize (DOWNLOADED_EVER); } @@ -303,9 +303,9 @@ class Torrent: public QObject bool honorsSessionLimits () const { return getBool (HONORS_SESSION_LIMITS); } int peerLimit () const { return getInt (PEER_LIMIT); } double seedRatioLimit () const { return getDouble (SEED_RATIO_LIMIT); } - tr_ratiolimit seedRatioMode () const { return (tr_ratiolimit) getInt (SEED_RATIO_MODE); } + tr_ratiolimit seedRatioMode () const { return static_cast (getInt (SEED_RATIO_MODE)); } int seedIdleLimit () const { return getInt (SEED_IDLE_LIMIT); } - tr_idlelimit seedIdleMode () const { return (tr_idlelimit) getInt (SEED_IDLE_MODE); } + tr_idlelimit seedIdleMode () const { return static_cast (getInt (SEED_IDLE_MODE)); } TrackerStatsList trackerStats () const{ return myValues[TRACKERSTATS].value(); } QStringList trackers() const { return myValues[TRACKERS].value(); } QStringList hosts() const { return myValues[HOSTS].value(); } @@ -316,7 +316,7 @@ class Torrent: public QObject public: QString activityString () const; - tr_torrent_activity getActivity () const { return (tr_torrent_activity) getInt (ACTIVITY); } + tr_torrent_activity getActivity () const { return static_cast (getInt (ACTIVITY)); } bool isFinished () const { return getBool (IS_FINISHED); } bool isPaused () const { return getActivity () == TR_STATUS_STOPPED; } bool isWaitingToVerify () const { return getActivity () == TR_STATUS_CHECK_WAIT; } diff --git a/qt/tracker-delegate.cc b/qt/tracker-delegate.cc index b2b0d0492..b70473c1d 100644 --- a/qt/tracker-delegate.cc +++ b/qt/tracker-delegate.cc @@ -144,7 +144,7 @@ TrackerDelegate::getText (const TrackerInfo& inf) const char * host = NULL; int port = 0; tr_urlParse (inf.st.announce.toUtf8().constData(), -1, NULL, &host, &port, NULL); - str += QString ("%1:%2").arg (host).arg (port); + str += QString::fromLatin1 ("%1:%2").arg (host).arg (port); tr_free (host); if (!key.isEmpty()) str += " - " + key; str += inf.st.isBackup ? "" : ""; diff --git a/qt/tracker-model.cc b/qt/tracker-model.cc index 96d0de5ad..e1b8738d1 100644 --- a/qt/tracker-model.cc +++ b/qt/tracker-model.cc @@ -36,7 +36,7 @@ TrackerModel::data (const QModelIndex& index, int role) const switch (role) { case Qt::DisplayRole: - var = QString (trackerInfo.st.announce); + var = trackerInfo.st.announce; break; case Qt::DecorationRole: diff --git a/qt/utils.cc b/qt/utils.cc index 3725bbba9..e96a49832 100644 --- a/qt/utils.cc +++ b/qt/utils.cc @@ -82,7 +82,7 @@ namespace const QString filename = fileInfo.fileName (); SHFILEINFO shellFileInfo; - if (::SHGetFileInfoW ((const wchar_t*) filename.utf16 (), FILE_ATTRIBUTE_NORMAL, + if (::SHGetFileInfoW (reinterpret_cast (filename.utf16 ()), FILE_ATTRIBUTE_NORMAL, &shellFileInfo, sizeof(shellFileInfo), SHGFI_ICON | iconSize | SHGFI_USEFILEATTRIBUTES) != 0) { @@ -122,7 +122,7 @@ Utils::guessMimeIcon (const QString& filename) } if (icon.isNull ()) - icon = QApplication::style ()->standardIcon (QStyle::SP_FileIcon); + icon = qApp->style ()->standardIcon (QStyle::SP_FileIcon); return icon; #else @@ -133,7 +133,7 @@ Utils::guessMimeIcon (const QString& filename) if (fileIcons[0].isNull ()) { - fallback = QApplication::style()->standardIcon (QStyle::SP_FileIcon); + fallback = qApp->style()->standardIcon (QStyle::SP_FileIcon); suffixes[DISK] << QString::fromLatin1("iso"); fileIcons[DISK]= QIcon::fromTheme (QString::fromLatin1("media-optical"), fallback);