From 7a16146f6f9afafe96a981fda44b46dc01d76888 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Sat, 27 Jul 2013 00:43:58 +0300 Subject: [PATCH] Convert misc class to a namespace instead. --- src/misc.cpp | 18 ++++++++-------- src/misc.h | 59 +++++++++++++++++++++++----------------------------- 2 files changed, 35 insertions(+), 42 deletions(-) diff --git a/src/misc.cpp b/src/misc.cpp index 6eab2efad..4eecd47ca 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -175,7 +175,7 @@ void misc::shutdownComputer(bool sleep) { if (sleep) SetSuspendState(false, false, false); else - InitiateSystemShutdownA(0, tr("qBittorrent will shutdown the computer now because all downloads are complete.").toLocal8Bit().data(), 10, true, false); + InitiateSystemShutdownA(0, QCoreApplication::translate("misc", "qBittorrent will shutdown the computer now because all downloads are complete.").toLocal8Bit().data(), 10, true, false); // Disable shutdown privilege. tkp.Privileges[0].Attributes = 0; @@ -233,17 +233,17 @@ int misc::pythonVersion() { // value must be given in bytes QString misc::friendlyUnit(qreal val, bool is_speed) { if (val < 0) - return tr("Unknown", "Unknown (size)"); + return QCoreApplication::translate("misc", "Unknown", "Unknown (size)"); int i = 0; while(val >= 1024. && i++<6) val /= 1024.; QString ret; if (i == 0) - ret = QString::number((long)val) + " " + tr(units[0].source, units[0].comment); + ret = QString::number((long)val) + " " + QCoreApplication::translate("misc", units[0].source, units[0].comment); else - ret = QString::number(val, 'f', 1) + " " + tr(units[i].source, units[i].comment); + ret = QString::number(val, 'f', 1) + " " + QCoreApplication::translate("misc", units[i].source, units[i].comment); if (is_speed) - ret += tr("/s", "per second"); + ret += QCoreApplication::translate("misc", "/s", "per second"); return ret; } @@ -379,21 +379,21 @@ QString misc::userFriendlyDuration(qlonglong seconds) { return "0"; } if (seconds < 60) { - return tr("< 1m", "< 1 minute"); + return QCoreApplication::translate("misc", "< 1m", "< 1 minute"); } int minutes = seconds / 60; if (minutes < 60) { - return tr("%1m","e.g: 10minutes").arg(QString::number(minutes)); + return QCoreApplication::translate("misc", "%1m","e.g: 10minutes").arg(QString::number(minutes)); } int hours = minutes / 60; minutes = minutes - hours*60; if (hours < 24) { - return tr("%1h %2m", "e.g: 3hours 5minutes").arg(QString::number(hours)).arg(QString::number(minutes)); + return QCoreApplication::translate("misc", "%1h %2m", "e.g: 3hours 5minutes").arg(QString::number(hours)).arg(QString::number(minutes)); } int days = hours / 24; hours = hours - days * 24; if (days < 100) { - return tr("%1d %2h", "e.g: 2days 10hours").arg(QString::number(days)).arg(QString::number(hours)); + return QCoreApplication::translate("misc", "%1d %2h", "e.g: 2days 10hours").arg(QString::number(days)).arg(QString::number(hours)); } return QString::fromUtf8("∞"); } diff --git a/src/misc.h b/src/misc.h index 6d9883574..883aef26f 100644 --- a/src/misc.h +++ b/src/misc.h @@ -43,7 +43,6 @@ #include #include #include -#include #ifndef DISABLE_GUI #include #endif @@ -51,79 +50,73 @@ const qlonglong MAX_ETA = 8640000; /* Miscellaneaous functions that can be useful */ -class misc +namespace misc { - Q_DECLARE_TR_FUNCTIONS(misc) - -private: - misc(); // Forbidden - -public: - static inline QString toQString(const std::string &str) { + inline QString toQString(const std::string &str) { return QString::fromLocal8Bit(str.c_str()); } - static inline QString toQString(const char* str) { + inline QString toQString(const char* str) { return QString::fromLocal8Bit(str); } - static inline QString toQStringU(const std::string &str) { + inline QString toQStringU(const std::string &str) { return QString::fromUtf8(str.c_str()); } - static inline QString toQStringU(const char* str) { + inline QString toQStringU(const char* str) { return QString::fromUtf8(str); } - static inline QString toQString(const libtorrent::sha1_hash &hash) { + inline QString toQString(const libtorrent::sha1_hash &hash) { char out[41]; to_hex((char const*)&hash[0], libtorrent::sha1_hash::size, out); return QString(out); } #ifndef DISABLE_GUI - static void shutdownComputer(bool sleep=false); + void shutdownComputer(bool sleep=false); #endif - static QString parseHtmlLinks(const QString &raw_text); + QString parseHtmlLinks(const QString &raw_text); - static bool isUrl(const QString &s); + bool isUrl(const QString &s); #ifndef DISABLE_GUI // Get screen center - static QPoint screenCenter(QWidget *win); + QPoint screenCenter(QWidget *win); #endif - static int pythonVersion(); + int pythonVersion(); // return best userfriendly storage unit (B, KiB, MiB, GiB, TiB) // use Binary prefix standards from IEC 60027-2 // see http://en.wikipedia.org/wiki/Kilobyte // value must be given in bytes - static QString friendlyUnit(qreal val, bool is_speed = false); - static bool isPreviewable(const QString& extension); - static QString magnetUriToName(const QString& magnet_uri); - static QString magnetUriToHash(const QString& magnet_uri); - static QList magnetUriToTrackers(const QString& magnet_uri); - static QString bcLinkToMagnet(QString bc_link); + QString friendlyUnit(qreal val, bool is_speed = false); + bool isPreviewable(const QString& extension); + QString magnetUriToName(const QString& magnet_uri); + QString magnetUriToHash(const QString& magnet_uri); + QList magnetUriToTrackers(const QString& magnet_uri); + QString bcLinkToMagnet(QString bc_link); // Take a number of seconds and return an user-friendly // time duration like "1d 2h 10m". - static QString userFriendlyDuration(qlonglong seconds); - static QString getUserIDString(); + QString userFriendlyDuration(qlonglong seconds); + QString getUserIDString(); // Convert functions - static QStringList toStringList(const QList &l); - static QList intListfromStringList(const QStringList &l); - static QList boolListfromStringList(const QStringList &l); + QStringList toStringList(const QList &l); + QList intListfromStringList(const QStringList &l); + QList boolListfromStringList(const QStringList &l); #if LIBTORRENT_VERSION_NUM < 001600 - static QString toQString(const boost::posix_time::ptime& boostDate); + QString toQString(const boost::posix_time::ptime& boostDate); #else - static QString toQString(time_t t); + QString toQString(time_t t); #endif #ifndef DISABLE_GUI - static bool naturalSort(QString left, QString right, bool& result); + bool naturalSort(QString left, QString right, bool& result); #endif -}; +} // Trick to get a portable sleep() function class SleeperThread : public QThread {