Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
Improved OS version determining
Browse files Browse the repository at this point in the history
  • Loading branch information
curoviyxru committed Apr 2, 2022
1 parent 2501716 commit 0fc71a6
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 29 deletions.
15 changes: 13 additions & 2 deletions library.pri
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
QT += network

load(mobilityconfig)
contains(MOBILITY_CONFIG, systeminfo) {
CONFIG += mobility
MOBILITY += systeminfo
DEFINES += MOBILITY_READY=1
} else {
message(Mobility API not available)
}

include(qt-json/qt-json.pri)
include(thirdparty/thirdparty.pri)

Expand All @@ -22,7 +31,8 @@ HEADERS += \
$$PWD/tlschema.h \
$$PWD/crypto.h \
$$PWD/qcompressor.h \
$$PWD/tl.h
$$PWD/tl.h \
$$PWD/systemname.h

SOURCES += \
$$PWD/telegramclient.cpp \
Expand All @@ -37,6 +47,7 @@ SOURCES += \
$$PWD/fileslayer.cpp \
$$PWD/updates.cpp \
$$PWD/qcompressor.cpp \
$$PWD/tl.cpp
$$PWD/tl.cpp \
$$PWD/systemname.cpp

INCLUDEPATH += $$PWD
99 changes: 99 additions & 0 deletions systemname.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include "systemname.h"

#include <QSysInfo>
#ifdef MOBILITY_READY
#include <QSystemDeviceInfo>

QTM_USE_NAMESPACE
#endif

QString deviceName()
{
#ifdef MOBILITY_READY
QSystemDeviceInfo info;
return info.manufacturer() + " " + info.model();
#else
return osName().append("-based Device");
#endif
}

QString osName()
{
#if defined(Q_OS_ANDROID)
return "Android";
#elif defined(Q_OS_SYMBIAN)
switch (QSysInfo::symbianVersion()) {
case QSysInfo::SV_9_2:
return "Symbian OS v9.2";
case QSysInfo::SV_9_3:
return "Symbian OS v9.3";
case QSysInfo::SV_9_4:
return "Symbian OS v9.4";
case QSysInfo::SV_SF_1:
return "S60 5th Edition";
case QSysInfo::SV_SF_2:
return "Symbian^2";
case QSysInfo::SV_SF_3:
return "Symbian^3";
case QSysInfo::SV_SF_4:
return "Symbian^4";
case QSysInfo::SV_API_5_3:
return "S60 API v5.3";
case QSysInfo::SV_API_5_4:
return "S60 API v5.4";
default:
return "Symbian";
}
#elif defined(Q_OS_BLACKBERRY)
return "Blackberry OS";
#elif defined(Q_OS_IOS)
return "iOS";
#elif defined(Q_OS_MACOS)
//TODO: QSysInfo version
return "macOS";
#elif defined(Q_OS_WIN)
switch (QSysInfo::windowsVersion()) {
case QSysInfo::WV_32s:
return "Windows 3.1 with Win32s";
case QSysInfo::WV_95:
return "Windows 95";
case QSysInfo::WV_98:
return "Windows 98";
case QSysInfo::WV_Me:
return "Windows Me";
case QSysInfo::WV_NT:
return "Windows NT";
case QSysInfo::WV_2000:
return "Windows 2000";
case QSysInfo::WV_XP:
return "Windows XP";
case QSysInfo::WV_2003:
return "Windows 2003";
case QSysInfo::WV_VISTA:
return "Windows Vista";
case QSysInfo::WV_WINDOWS7:
return "Windows 7";
case QSysInfo::WV_CE:
return "Windows CE";
case QSysInfo::WV_CENET:
return "Windows CE .NET";
case QSysInfo::WV_CE_5:
return "Windows CE 5";
case QSysInfo::WV_CE_6:
return "Windows CE 6";
default:
#ifdef defined(Q_OS_WINCE)
return "Windows CE";
#else
return "Windows";
#endif
}
#elif defined(Q_OS_LINUX)
return "Linux";
#elif defined(Q_OS_UNIX)
return "Unix";
#else
//TODO: more systems macros
return "Unknown";
#endif
}
9 changes: 9 additions & 0 deletions systemname.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef SYSTEMNAME_H
#define SYSTEMNAME_H

#include <QString>

QString osName();
QString deviceName();

#endif // SYSTEMNAME_H
29 changes: 2 additions & 27 deletions telegramclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <qcompressor.h>
#include <QDebug>
#include <cstdlib>
#include "systemname.h"

typedef void (TelegramClient::*HANDLE_METHOD)(QByteArray, qint64);

Expand Down Expand Up @@ -713,32 +714,6 @@ void TelegramClient::handleDhGenOk(QByteArray data, qint64 mtm)
changeState(AUTHORIZED);
}

//TODO: Use QSysInfo
QString osName()
{
#if defined(Q_OS_ANDROID)
return QString("Android");
#elif defined(Q_OS_SYMBIAN)
return QString("Symbian");
#elif defined(Q_OS_BLACKBERRY)
return QString("Blackberry OS");
#elif defined(Q_OS_IOS)
return QString("iOS");
#elif defined(Q_OS_MACOS)
return QString("macOS");
#elif defined(Q_OS_WINCE)
return QString("Windows CE");
#elif defined(Q_OS_WIN)
return QString("Windows");
#elif defined(Q_OS_LINUX)
return QString("Linux");
#elif defined(Q_OS_UNIX)
return QString("Unix");
#else
return QString("Unknown");
#endif
}

qint64 TelegramClient::getNewMessageId()
{
msgMutex.lock();
Expand Down Expand Up @@ -846,7 +821,7 @@ void TelegramClient::initConnection()

TGOBJECT(initRequest, TLType::InitConnectionMethod);
initRequest["api_id"] = APP_ID;
initRequest["device_model"] = osName().append("-based Device");
initRequest["device_model"] = deviceName();
initRequest["system_version"] = osName();
initRequest["app_version"] = QApplication::applicationVersion();
initRequest["system_lang_code"] = QLocale::system().name().split("_")[0];
Expand Down

0 comments on commit 0fc71a6

Please sign in to comment.