2006-09-30 20:02:39 +04:00
|
|
|
/*
|
2015-04-19 18:17:47 +03:00
|
|
|
* Bittorrent Client using Qt and libtorrent.
|
2018-04-14 22:53:45 +03:00
|
|
|
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
|
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.
|
2006-09-30 20:02:39 +04:00
|
|
|
*/
|
|
|
|
|
2015-05-06 14:53:27 +03:00
|
|
|
#ifndef UTILS_MISC_H
|
|
|
|
#define UTILS_MISC_H
|
2006-09-30 20:02:39 +04:00
|
|
|
|
2018-04-07 09:35:00 +03:00
|
|
|
#include <ctime>
|
2014-11-16 23:28:28 +03:00
|
|
|
#include <vector>
|
2018-04-07 09:35:00 +03:00
|
|
|
|
2018-04-07 10:35:35 +03:00
|
|
|
#include <QtGlobal>
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
#include <memory>
|
|
|
|
#include <Windows.h>
|
|
|
|
#endif
|
|
|
|
|
2018-04-07 09:35:00 +03:00
|
|
|
#include <QDir>
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QSize>
|
2006-09-30 20:02:39 +04:00
|
|
|
#include <QString>
|
2010-08-13 18:02:19 +04:00
|
|
|
#include <QStringList>
|
2012-09-23 12:09:01 +04:00
|
|
|
#include <QUrl>
|
2018-04-07 09:35:00 +03:00
|
|
|
|
2015-09-25 11:10:05 +03:00
|
|
|
#include "base/types.h"
|
2010-05-21 15:46:12 +04:00
|
|
|
|
2015-05-04 02:09:30 +03:00
|
|
|
/* Miscellaneous functions that can be useful */
|
2010-08-16 21:35:32 +04:00
|
|
|
|
2015-05-06 14:53:27 +03:00
|
|
|
namespace Utils
|
|
|
|
{
|
|
|
|
namespace Misc
|
|
|
|
{
|
2015-09-23 23:20:22 +03:00
|
|
|
// use binary prefix standards from IEC 60027-2
|
|
|
|
// see http://en.wikipedia.org/wiki/Kilobyte
|
|
|
|
enum class SizeUnit
|
|
|
|
{
|
|
|
|
Byte, // 1024^0,
|
|
|
|
KibiByte, // 1024^1,
|
|
|
|
MebiByte, // 1024^2,
|
|
|
|
GibiByte, // 1024^3,
|
|
|
|
TebiByte, // 1024^4,
|
|
|
|
PebiByte, // 1024^5,
|
|
|
|
ExbiByte // 1024^6,
|
|
|
|
// int64 is used for sizes and thus the next units can not be handled
|
|
|
|
// ZebiByte, // 1024^7,
|
|
|
|
// YobiByte, // 1024^8
|
|
|
|
};
|
|
|
|
|
2018-04-14 22:53:45 +03:00
|
|
|
QString parseHtmlLinks(const QString &rawText);
|
2015-05-06 14:53:27 +03:00
|
|
|
bool isUrl(const QString &s);
|
2010-03-03 22:04:34 +03:00
|
|
|
|
2016-04-12 21:33:17 +03:00
|
|
|
void shutdownComputer(const ShutdownDialogAction &action);
|
2016-04-16 08:50:41 +03:00
|
|
|
|
2016-02-27 00:48:53 +03:00
|
|
|
QString osName();
|
2016-02-27 03:27:56 +03:00
|
|
|
QString boostVersionString();
|
2016-02-27 03:38:52 +03:00
|
|
|
QString libtorrentVersionString();
|
2016-02-27 00:48:53 +03:00
|
|
|
|
2018-04-02 19:53:44 +03:00
|
|
|
QString unitString(SizeUnit unit, bool isSpeed = false);
|
2015-09-23 23:20:22 +03:00
|
|
|
|
2018-04-14 22:53:45 +03:00
|
|
|
// return the best user friendly storage unit (B, KiB, MiB, GiB, TiB)
|
2015-05-06 14:53:27 +03:00
|
|
|
// value must be given in bytes
|
2015-09-23 23:20:22 +03:00
|
|
|
QString friendlyUnit(qint64 bytesValue, bool isSpeed = false);
|
2016-09-26 13:26:25 +03:00
|
|
|
int friendlyUnitPrecision(SizeUnit unit);
|
2015-09-23 23:20:22 +03:00
|
|
|
qint64 sizeInBytes(qreal size, SizeUnit unit);
|
|
|
|
|
2018-04-14 22:53:45 +03:00
|
|
|
bool isPreviewable(const QString &extension);
|
2014-11-26 00:10:32 +03:00
|
|
|
|
2018-04-14 22:53:45 +03:00
|
|
|
// Take a number of seconds and return a user-friendly
|
2015-05-06 14:53:27 +03:00
|
|
|
// time duration like "1d 2h 10m".
|
|
|
|
QString userFriendlyDuration(qlonglong seconds);
|
|
|
|
QString getUserIDString();
|
2014-11-26 00:10:32 +03:00
|
|
|
|
2015-05-06 14:53:27 +03:00
|
|
|
// Convert functions
|
|
|
|
QStringList toStringList(const QList<bool> &l);
|
|
|
|
QList<int> intListfromStringList(const QStringList &l);
|
|
|
|
QList<bool> boolListfromStringList(const QStringList &l);
|
2006-09-30 20:02:39 +04:00
|
|
|
|
2015-06-28 21:58:39 +03:00
|
|
|
#ifndef DISABLE_GUI
|
2018-04-14 22:53:45 +03:00
|
|
|
void openPath(const QString &absolutePath);
|
|
|
|
void openFolderSelect(const QString &absolutePath);
|
2017-01-20 08:43:57 +03:00
|
|
|
|
2015-09-25 07:52:39 +03:00
|
|
|
QPoint screenCenter(const QWidget *w);
|
2015-06-28 21:58:39 +03:00
|
|
|
#endif
|
|
|
|
|
2016-07-23 08:19:26 +03:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
QString windowsSystemPath();
|
2018-04-07 10:35:35 +03:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T loadWinAPI(const QString &source, const char *funcName)
|
|
|
|
{
|
|
|
|
QString path = windowsSystemPath();
|
|
|
|
if (!path.endsWith('\\'))
|
|
|
|
path += '\\';
|
|
|
|
|
|
|
|
path += source;
|
|
|
|
|
|
|
|
std::unique_ptr<wchar_t[]> pathWchar(new wchar_t[path.length() + 1] {});
|
|
|
|
path.toWCharArray(pathWchar.get());
|
|
|
|
|
|
|
|
return reinterpret_cast<T>(
|
|
|
|
::GetProcAddress(::LoadLibraryW(pathWchar.get()), funcName));
|
|
|
|
}
|
2018-11-06 18:49:17 +03:00
|
|
|
#endif // Q_OS_WIN
|
2015-05-06 14:53:27 +03:00
|
|
|
}
|
2014-10-18 03:29:12 +04:00
|
|
|
}
|
2006-09-30 20:02:39 +04:00
|
|
|
|
2018-04-14 22:53:45 +03:00
|
|
|
#endif // UTILS_MISC_H
|