2006-09-30 20:02:39 +04:00
|
|
|
/*
|
|
|
|
* Bittorrent Client using Qt4 and libtorrent.
|
2007-07-14 18:31:59 +04:00
|
|
|
* Copyright (C) 2006 Christophe Dumez
|
2006-09-30 20:02:39 +04:00
|
|
|
*
|
2007-07-14 18:31:59 +04:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-09-30 20:02:39 +04:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-07-14 18:31:59 +04:00
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
2009-04-05 21:00:55 +04:00
|
|
|
* In addition, as a special exception, the copyright holders give permission to
|
|
|
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
|
|
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
|
|
|
* and distribute the linked executables. You must obey the GNU General Public
|
|
|
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
|
|
|
* modify file(s), you may extend this exception to your version of the file(s),
|
|
|
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
|
|
|
* exception statement from your version.
|
|
|
|
*
|
2007-07-14 18:31:59 +04:00
|
|
|
* Contact : chris@qbittorrent.org
|
2006-09-30 20:02:39 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MISC_H
|
|
|
|
#define MISC_H
|
|
|
|
|
2011-04-17 14:29:44 +04:00
|
|
|
#include <libtorrent/version.hpp>
|
|
|
|
#include <libtorrent/torrent_info.hpp>
|
|
|
|
#include <libtorrent/torrent_handle.hpp>
|
2006-09-30 20:02:39 +04:00
|
|
|
#include <sstream>
|
|
|
|
#include <QString>
|
2010-08-13 18:02:19 +04:00
|
|
|
#include <QStringList>
|
2006-09-30 20:02:39 +04:00
|
|
|
#include <QThread>
|
2009-11-12 10:42:21 +03:00
|
|
|
#include <ctime>
|
2010-03-20 22:09:27 +03:00
|
|
|
#include <QPoint>
|
2010-07-24 23:22:55 +04:00
|
|
|
#include <QFile>
|
2010-10-02 00:51:08 +04:00
|
|
|
#include <QDir>
|
2012-09-23 12:09:01 +04:00
|
|
|
#include <QUrl>
|
2012-05-17 16:21:13 +04:00
|
|
|
#include <QCoreApplication>
|
2010-12-17 00:21:45 +03:00
|
|
|
#ifndef DISABLE_GUI
|
2010-12-12 22:37:59 +03:00
|
|
|
#include <QIcon>
|
2010-12-17 00:21:45 +03:00
|
|
|
#endif
|
2010-12-12 22:37:59 +03:00
|
|
|
|
2010-05-21 15:46:12 +04:00
|
|
|
const qlonglong MAX_ETA = 8640000;
|
|
|
|
|
2006-09-30 20:02:39 +04:00
|
|
|
/* Miscellaneaous functions that can be useful */
|
2012-05-17 16:21:13 +04:00
|
|
|
class misc
|
|
|
|
{
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(misc)
|
2006-09-30 20:02:39 +04:00
|
|
|
|
2010-10-31 15:35:07 +03:00
|
|
|
private:
|
|
|
|
misc(); // Forbidden
|
|
|
|
|
2009-08-17 09:14:03 +04:00
|
|
|
public:
|
2010-12-02 20:36:08 +03:00
|
|
|
static inline QString toQString(const std::string &str) {
|
2010-03-03 20:27:25 +03:00
|
|
|
return QString::fromLocal8Bit(str.c_str());
|
2009-08-17 09:14:03 +04:00
|
|
|
}
|
2006-09-30 20:02:39 +04:00
|
|
|
|
2010-12-02 20:36:08 +03:00
|
|
|
static inline QString toQString(const char* str) {
|
2010-03-03 20:27:25 +03:00
|
|
|
return QString::fromLocal8Bit(str);
|
2009-08-17 09:14:03 +04:00
|
|
|
}
|
2007-08-20 10:29:18 +04:00
|
|
|
|
2010-12-02 20:36:08 +03:00
|
|
|
static inline QString toQStringU(const std::string &str) {
|
2010-06-04 00:08:19 +04:00
|
|
|
return QString::fromUtf8(str.c_str());
|
|
|
|
}
|
|
|
|
|
2010-12-02 20:36:08 +03:00
|
|
|
static inline QString toQStringU(const char* str) {
|
2010-06-04 00:08:19 +04:00
|
|
|
return QString::fromUtf8(str);
|
|
|
|
}
|
|
|
|
|
2010-12-02 20:36:08 +03:00
|
|
|
static inline QString toQString(const libtorrent::sha1_hash &hash) {
|
2012-02-16 23:17:15 +04:00
|
|
|
char out[41];
|
|
|
|
to_hex((char const*)&hash[0], libtorrent::sha1_hash::size, out);
|
|
|
|
return QString(out);
|
2010-10-17 18:46:01 +04:00
|
|
|
}
|
|
|
|
|
2011-01-15 11:42:32 +03:00
|
|
|
#ifndef DISABLE_GUI
|
2010-12-31 16:36:32 +03:00
|
|
|
static void shutdownComputer(bool sleep=false);
|
2011-01-15 11:42:32 +03:00
|
|
|
#endif
|
2010-08-16 21:35:32 +04:00
|
|
|
|
2011-04-04 21:16:34 +04:00
|
|
|
static QString parseHtmlLinks(const QString &raw_text);
|
|
|
|
|
2010-12-30 22:12:03 +03:00
|
|
|
static bool isUrl(const QString &s);
|
2010-03-03 22:04:34 +03:00
|
|
|
|
2010-01-24 15:07:07 +03:00
|
|
|
#ifndef DISABLE_GUI
|
2010-01-22 01:23:13 +03:00
|
|
|
// Get screen center
|
2010-03-20 22:09:27 +03:00
|
|
|
static QPoint screenCenter(QWidget *win);
|
2010-01-24 15:07:07 +03:00
|
|
|
#endif
|
2011-09-11 21:22:54 +04:00
|
|
|
static int pythonVersion();
|
2009-08-17 09:14:03 +04:00
|
|
|
// 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
|
2012-05-26 21:42:44 +04:00
|
|
|
static QString friendlyUnit(qreal val, bool is_speed = false);
|
2012-11-11 21:23:10 +04:00
|
|
|
static bool isPreviewable(const QString& extension);
|
2012-09-23 12:09:01 +04:00
|
|
|
static QString magnetUriToName(const QString& magnet_uri);
|
|
|
|
static QString magnetUriToHash(const QString& magnet_uri);
|
|
|
|
static QList<QUrl> magnetUriToTrackers(const QString& magnet_uri);
|
2010-07-23 02:19:42 +04:00
|
|
|
static QString bcLinkToMagnet(QString bc_link);
|
2009-08-17 09:14:03 +04:00
|
|
|
// Take a number of seconds and return an user-friendly
|
|
|
|
// time duration like "1d 2h 10m".
|
2010-03-20 22:09:27 +03:00
|
|
|
static QString userFriendlyDuration(qlonglong seconds);
|
2010-06-09 13:48:14 +04:00
|
|
|
static QString getUserIDString();
|
2010-06-05 22:59:05 +04:00
|
|
|
|
|
|
|
// Convert functions
|
|
|
|
static QStringList toStringList(const QList<bool> &l);
|
|
|
|
static QList<int> intListfromStringList(const QStringList &l);
|
|
|
|
static QList<bool> boolListfromStringList(const QStringList &l);
|
2010-11-09 22:10:42 +03:00
|
|
|
|
2012-05-15 20:57:31 +04:00
|
|
|
#if LIBTORRENT_VERSION_MINOR < 16
|
|
|
|
static QString toQString(const boost::posix_time::ptime& boostDate);
|
|
|
|
#else
|
|
|
|
static QString toQString(time_t t);
|
|
|
|
#endif
|
2006-09-30 20:02:39 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Trick to get a portable sleep() function
|
2010-03-20 22:09:27 +03:00
|
|
|
class SleeperThread : public QThread {
|
2009-08-17 09:14:03 +04:00
|
|
|
public:
|
|
|
|
static void msleep(unsigned long msecs)
|
|
|
|
{
|
|
|
|
QThread::msleep(msecs);
|
|
|
|
}
|
2006-09-30 20:02:39 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|