/
alexashkin
/
telegraph
Обзор
Документация
Войти
/
alexashkin
/
telegraph
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/tdlib/tdlibcontroller.cpp
96 строк
4 KB
mbarashkov
Завершение ВЕЛИКОЛЕПНОГО рефакторинга
21 фев 2025, 20:32
21 фев 2025, 20:32
b9fcdf4
Код
Авторство
О чём код?
#include "tdlibcontroller.h" #include <QDir> #include <QStandardPaths> TDLibController::TDLibController(AppSettings *settings, QObject *parent) : QObject(parent), networkConfigurationManager(new QNetworkConfigurationManager(this)), appSettings(settings), tdLibState(this), requestFactory(this), requestService(&tdLibState, this), requestSender(&tdLibState, &requestFactory, &requestService, this), responseHandler( settings, &tdLibState, &requestFactory, &requestService, &requestSender, getApplicationDataPath(), this ) { createDBDirectoryIfNeeded(); handleOpenWithChanged(); connect(appSettings, SIGNAL(useOpenWithChanged()), this, SLOT(handleOpenWithChanged())); connect( networkConfigurationManager, SIGNAL(configurationChanged(QNetworkConfiguration)), this, SLOT(handleNetworkConfigurationChanged(QNetworkConfiguration)) ); requestService.sendRequest(requestFactory.setLogVerbosityLevelRequest()); requestSender.callSetOptionInteger("notification_group_count_max", 5); } void TDLibController::handleOpenWithChanged() { appSettings->getUseOpenWith() ? osService.initializeOpenWith() : osService.removeOpenWith(); } void TDLibController::createDBDirectoryIfNeeded() const { QString tdLibDatabaseDirectoryPath = getApplicationDataPath() + "/tdlib"; QDir tdLibDatabaseDirectory(tdLibDatabaseDirectoryPath); if (!tdLibDatabaseDirectory.exists()) { tdLibDatabaseDirectory.mkpath(tdLibDatabaseDirectoryPath); } } void TDLibController::handleNetworkConfigurationChanged(const QNetworkConfiguration&) { bool wifiFound = false; bool mobileFound = false; QList<QNetworkConfiguration> activeConfigurations = networkConfigurationManager->allConfigurations(QNetworkConfiguration::Active); QListIterator<QNetworkConfiguration> configurationIterator(activeConfigurations); while (configurationIterator.hasNext()) { QNetworkConfiguration activeConfiguration = configurationIterator.next(); if (activeConfiguration.bearerType() == QNetworkConfiguration::BearerWLAN || activeConfiguration.bearerType() == QNetworkConfiguration::BearerEthernet) { wifiFound = true; } if (activeConfiguration.bearerType() == QNetworkConfiguration::Bearer2G || activeConfiguration.bearerType() == QNetworkConfiguration::Bearer3G || activeConfiguration.bearerType() == QNetworkConfiguration::Bearer4G || activeConfiguration.bearerType() == QNetworkConfiguration::BearerCDMA2000 || activeConfiguration.bearerType() == QNetworkConfiguration::BearerEVDO || activeConfiguration.bearerType() == QNetworkConfiguration::BearerHSPA || activeConfiguration.bearerType() == QNetworkConfiguration::BearerLTE || activeConfiguration.bearerType() == QNetworkConfiguration::BearerWCDMA) { mobileFound = true; } } if (wifiFound) { requestSender.callSetNetworkType(TDLibConstants::NetworkType::WiFi); } else if (mobileFound) { requestSender.callSetNetworkType(TDLibConstants::NetworkType::Mobile); } else { requestSender.callSetNetworkType(TDLibConstants::NetworkType::None); } } QString TDLibController::getApplicationDataPath() const { #ifdef QT_DEBUG return QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + "/ru.telegrafaurora"; #else return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); #endif }