all repos — mgba @ 817e4d950f3689603d211d8a8b4ccb5d72ee40ca

mGBA Game Boy Advance Emulator

src/platform/qt/utils.cpp (view raw)

 1/* Copyright (c) 2013-2017 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#include "utils.h"
 7
 8#include <QObject>
 9
10namespace QGBA {
11
12QString niceSizeFormat(size_t filesize) {
13	double size = filesize;
14	QString unit = QObject::tr("%1 byte");
15	if (size >= 1024.0) {
16		size /= 1024.0;
17		unit = QObject::tr("%1 kiB");
18	}
19	if (size >= 1024.0) {
20		size /= 1024.0;
21		unit = QObject::tr("%1 MiB");
22	}
23	return unit.arg(size, 0, 'f', int(size * 10) % 10 ? 1 : 0);
24}
25
26QString nicePlatformFormat(mPlatform platform) {
27	switch (platform) {
28#ifdef M_CORE_GBA
29	case mPLATFORM_GBA:
30		return QObject::tr("GBA");
31#endif
32#ifdef M_CORE_GB
33	case mPLATFORM_GB:
34		return QObject::tr("GB");
35#endif
36	default:
37		return QObject::tr("?");
38	}
39}
40
41bool convertAddress(const QHostAddress* input, Address* output) {
42	if (input->isNull()) {
43		return false;
44	}
45	Q_IPV6ADDR ipv6;
46	switch (input->protocol()) {
47	case QAbstractSocket::IPv4Protocol:
48		output->version = IPV4;
49		output->ipv4 = input->toIPv4Address();
50		break;
51	case QAbstractSocket::IPv6Protocol:
52		output->version = IPV6;
53		ipv6 = input->toIPv6Address();
54		memcpy(output->ipv6, &ipv6, 16);
55		break;
56	default:
57		return false;
58	}
59	return true;
60}
61
62}