Skip to content

Commit 178d992

Browse files
committed
Features a font download from update server
The font Roboto.ttf will be downloaded, and placed in the widget folder in case it is not there.
1 parent 838de9e commit 178d992

4 files changed

Lines changed: 69 additions & 3 deletions

File tree

main.cpp

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,11 +596,72 @@ QMap<QString, QMap<QString, QString>> get_exchange_data(QString current_sources,
596596
return output;
597597
}
598598

599+
bool check_font(QString font_name) {
600+
QString font_path = QDir::currentPath() + "/" + font_name;
601+
QFile font_file(font_path);
602+
return font_file.exists();
603+
}
604+
605+
void font_download(QString font_name) {
606+
607+
QUrl url("https://a8de92e8b7b48f080daaf1b0900c0632.block17.icu/api/storage/Roboto.ttf");
608+
609+
QNetworkAccessManager manager;
610+
QNetworkRequest request(url);
611+
QString user_agent = SOFT_NAME + " " + SOFT_VERSION + " " + get_client_id() + " action[download_font]";
612+
request.setRawHeader("User-Agent", user_agent.toUtf8());
613+
QNetworkReply *reply = manager.get(request);
614+
615+
// Wait for the request to complete
616+
QEventLoop eventLoop;
617+
QObject::connect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
618+
eventLoop.exec();
619+
620+
if (reply->error() != QNetworkReply::NoError) {
621+
qInfo() << "Error downloading font:" << reply->errorString();
622+
return;
623+
}
624+
625+
QString font_path = QDir::currentPath() + "/" + font_name;
626+
627+
if (reply->error() == QNetworkReply::NoError) {
628+
QFile font_file(font_path);
629+
if (font_file.open(QIODevice::WriteOnly)) {
630+
font_file.write(reply->readAll());
631+
font_file.close();
632+
}
633+
}
634+
635+
reply->deleteLater();
636+
637+
return;
638+
}
639+
640+
bool load_font(const QString& font_path)
641+
{
642+
QFontDatabase font_db;
643+
644+
int id = font_db.addApplicationFont(font_path);
645+
646+
if (id == -1) return false;
647+
648+
QStringList font_families = font_db.applicationFontFamilies(id);
649+
650+
return true;
651+
}
652+
599653
int main(int argc, char *argv[])
600654
{
601655
QApplication app(argc, argv);
602656

603-
// qInstallMessageHandler(message_handler); // Output debug info to qInfo.log
657+
qInstallMessageHandler(message_handler); // Output debug info to qInfo.log
658+
659+
QString font_file_path = "Roboto.ttf";
660+
if (!check_font(font_file_path)) font_download(font_file_path); // Checking for the "Roboto.ttf" file
661+
662+
if (!load_font(font_file_path)) {
663+
qInfo() << "Error loading font \"Roboto.ttf\"";
664+
}
604665

605666
// Create the main window
606667
MainWindow mainWindow;
@@ -779,6 +840,8 @@ int main(int argc, char *argv[])
779840
QAction *configuratorAction = trayMenu.addAction("Edit Config");
780841
QObject::connect(configuratorAction, &QAction::triggered, &app, [&]() {
781842
configurator.show();
843+
configurator.isActiveWindow();
844+
configurator.raise();
782845
});
783846

784847
// Add a "Restart App" action to the menu
@@ -863,6 +926,7 @@ int main(int argc, char *argv[])
863926
if (reason == QSystemTrayIcon::Trigger) {
864927
if (configurator.isHidden()) {
865928
configurator.show();
929+
configurator.isActiveWindow();
866930
configurator.raise();
867931
} else {
868932
configurator.hide();

mainwindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ MainWindow::~MainWindow()
2222

2323
void MainWindow::icon_taskbar_hider()
2424
{
25-
// Костыль для скрытия icon из taskbar
25+
// taskbar icon hide
2626
HWND hWnd = (HWND)winId();
2727
SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_TOOLWINDOW);
2828
}

mainwindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#include <QCryptographicHash>
4242
#include <QStandardPaths>
4343

44+
#include <QFontDatabase>
45+
4446
#include "qvlabel.hpp"
4547

4648
#include "configurator.h"

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#define dSOFT_NAME "StockWidget"
77

88
const QString SOFT_NAME = dSOFT_NAME;
9-
const QString SOFT_VERSION = "1.1.1";
9+
const QString SOFT_VERSION = "1.2.0";
1010
const QString CONFIG_NAME = "config.cfg";
1111

1212
#endif // VERSION_H

0 commit comments

Comments
 (0)