@ -43,7 +43,6 @@
# include <QFile>
# include <QFile>
# include <QDir>
# include <QDir>
# include <QUrl>
# include <QUrl>
# include <QCoreApplication>
# ifndef DISABLE_GUI
# ifndef DISABLE_GUI
# include <QIcon>
# include <QIcon>
# endif
# endif
@ -51,79 +50,73 @@
const qlonglong MAX_ETA = 8640000 ;
const qlonglong MAX_ETA = 8640000 ;
/* Miscellaneaous functions that can be useful */
/* Miscellaneaous functions that can be useful */
class misc
namespace misc
{
{
Q_DECLARE_TR_FUNCTIONS ( misc )
inline QString toQString ( const std : : string & str ) {
private :
misc ( ) ; // Forbidden
public :
static inline QString toQString ( const std : : string & str ) {
return QString : : fromLocal8Bit ( str . c_str ( ) ) ;
return QString : : fromLocal8Bit ( str . c_str ( ) ) ;
}
}
static inline QString toQString ( const char * str ) {
inline QString toQString ( const char * str ) {
return QString : : fromLocal8Bit ( 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 ( ) ) ;
return QString : : fromUtf8 ( str . c_str ( ) ) ;
}
}
static inline QString toQStringU ( const char * str ) {
inline QString toQStringU ( const char * str ) {
return QString : : fromUtf8 ( 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 ] ;
char out [ 41 ] ;
to_hex ( ( char const * ) & hash [ 0 ] , libtorrent : : sha1_hash : : size , out ) ;
to_hex ( ( char const * ) & hash [ 0 ] , libtorrent : : sha1_hash : : size , out ) ;
return QString ( out ) ;
return QString ( out ) ;
}
}
# ifndef DISABLE_GUI
# ifndef DISABLE_GUI
static void shutdownComputer ( bool sleep = false ) ;
void shutdownComputer ( bool sleep = false ) ;
# endif
# 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
# ifndef DISABLE_GUI
// Get screen center
// Get screen center
static QPoint screenCenter ( QWidget * win ) ;
QPoint screenCenter ( QWidget * win ) ;
# endif
# endif
static int pythonVersion ( ) ;
int pythonVersion ( ) ;
// return best userfriendly storage unit (B, KiB, MiB, GiB, TiB)
// return best userfriendly storage unit (B, KiB, MiB, GiB, TiB)
// use Binary prefix standards from IEC 60027-2
// use Binary prefix standards from IEC 60027-2
// see http://en.wikipedia.org/wiki/Kilobyte
// see http://en.wikipedia.org/wiki/Kilobyte
// value must be given in bytes
// value must be given in bytes
static QString friendlyUnit ( qreal val , bool is_speed = false ) ;
QString friendlyUnit ( qreal val , bool is_speed = false ) ;
static bool isPreviewable ( const QString & extension ) ;
bool isPreviewable ( const QString & extension ) ;
static QString magnetUriToName ( const QString & magnet_uri ) ;
QString magnetUriToName ( const QString & magnet_uri ) ;
static QString magnetUriToHash ( const QString & magnet_uri ) ;
QString magnetUriToHash ( const QString & magnet_uri ) ;
static QList < QUrl > magnetUriToTrackers ( const QString & magnet_uri ) ;
QList < QUrl > magnetUriToTrackers ( const QString & magnet_uri ) ;
static QString bcLinkToMagnet ( QString bc_link ) ;
QString bcLinkToMagnet ( QString bc_link ) ;
// Take a number of seconds and return an user-friendly
// Take a number of seconds and return an user-friendly
// time duration like "1d 2h 10m".
// time duration like "1d 2h 10m".
static QString userFriendlyDuration ( qlonglong seconds ) ;
QString userFriendlyDuration ( qlonglong seconds ) ;
static QString getUserIDString ( ) ;
QString getUserIDString ( ) ;
// Convert functions
// Convert functions
static QStringList toStringList ( const QList < bool > & l ) ;
QStringList toStringList ( const QList < bool > & l ) ;
static QList < int > intListfromStringList ( const QStringList & l ) ;
QList < int > intListfromStringList ( const QStringList & l ) ;
static QList < bool > boolListfromStringList ( const QStringList & l ) ;
QList < bool > boolListfromStringList ( const QStringList & l ) ;
# if LIBTORRENT_VERSION_NUM < 001600
# if LIBTORRENT_VERSION_NUM < 001600
static QString toQString ( const boost : : posix_time : : ptime & boostDate ) ;
QString toQString ( const boost : : posix_time : : ptime & boostDate ) ;
# else
# else
static QString toQString ( time_t t ) ;
QString toQString ( time_t t ) ;
# endif
# endif
# ifndef DISABLE_GUI
# ifndef DISABLE_GUI
static bool naturalSort ( QString left , QString right , bool & result ) ;
bool naturalSort ( QString left , QString right , bool & result ) ;
# endif
# endif
} ;
}
// Trick to get a portable sleep() function
// Trick to get a portable sleep() function
class SleeperThread : public QThread {
class SleeperThread : public QThread {