2006-09-30 16:02:39 +00: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 16:02:39 +00:00
|
|
|
*
|
2007-07-14 14:31:59 +00: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 16:02:39 +00: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 14:31:59 +00: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 17:00:55 +00: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 16:02:39 +00:00
|
|
|
*/
|
|
|
|
|
2015-05-06 14:53:27 +03:00
|
|
|
#ifndef UTILS_MISC_H
|
|
|
|
#define UTILS_MISC_H
|
2006-09-30 16:02:39 +00:00
|
|
|
|
2018-04-07 15:35:35 +08:00
|
|
|
#include <QtGlobal>
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
#include <memory>
|
|
|
|
#include <Windows.h>
|
|
|
|
#endif
|
|
|
|
|
2019-05-16 11:56:10 +08:00
|
|
|
class QString;
|
2019-06-04 11:11:42 +03:00
|
|
|
|
2019-03-02 13:22:13 +08:00
|
|
|
enum class ShutdownDialogAction;
|
2010-05-21 11:46:12 +00:00
|
|
|
|
2015-05-04 02:09:30 +03:00
|
|
|
/* Miscellaneous functions that can be useful */
|
2010-08-16 17:35:32 +00:00
|
|
|
|
2015-05-06 14:53:27 +03:00
|
|
|
namespace Utils
|
|
|
|
{
|
|
|
|
namespace Misc
|
|
|
|
{
|
2015-09-23 22:20:22 +02: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);
|
2010-03-03 19:04:34 +00:00
|
|
|
|
2016-04-13 02:33:17 +08:00
|
|
|
void shutdownComputer(const ShutdownDialogAction &action);
|
2016-04-16 13:50:41 +08:00
|
|
|
|
2016-02-27 05:48:53 +08:00
|
|
|
QString osName();
|
2016-02-27 08:27:56 +08:00
|
|
|
QString boostVersionString();
|
2016-02-27 08:38:52 +08:00
|
|
|
QString libtorrentVersionString();
|
2018-12-08 12:19:29 +08:00
|
|
|
QString opensslVersionString();
|
2019-06-10 19:14:59 +02:00
|
|
|
QString zlibVersionString();
|
2016-02-27 05:48:53 +08:00
|
|
|
|
2018-04-02 23:53:44 +07:00
|
|
|
QString unitString(SizeUnit unit, bool isSpeed = false);
|
2015-09-23 22:20:22 +02: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 22:20:22 +02:00
|
|
|
QString friendlyUnit(qint64 bytesValue, bool isSpeed = false);
|
2016-09-26 13:26:25 +03:00
|
|
|
int friendlyUnitPrecision(SizeUnit unit);
|
2015-09-23 22:20:22 +02:00
|
|
|
qint64 sizeInBytes(qreal size, SizeUnit unit);
|
|
|
|
|
2018-04-14 22:53:45 +03:00
|
|
|
bool isPreviewable(const QString &extension);
|
2014-11-25 23:10:32 +02: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-25 23:10:32 +02:00
|
|
|
|
2016-07-23 13:19:26 +08:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
QString windowsSystemPath();
|
2018-04-07 15:35:35 +08: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 17:49:17 +02:00
|
|
|
#endif // Q_OS_WIN
|
2015-05-06 14:53:27 +03:00
|
|
|
}
|
2014-10-18 03:29:12 +04:00
|
|
|
}
|
2006-09-30 16:02:39 +00:00
|
|
|
|
2018-04-14 22:53:45 +03:00
|
|
|
#endif // UTILS_MISC_H
|