You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.9 KiB
80 lines
2.9 KiB
#include <QApplication> |
|
#include <QPalette> |
|
#include <QStyleFactory> |
|
#include <QDir> |
|
#include <cstdio> |
|
#include "mainwindow.h" |
|
#include "../db/db_manager.h" |
|
#include "../transport/node_config.h" |
|
|
|
int main(int argc, char *argv[]) { |
|
QApplication app(argc, argv); |
|
app.setApplicationName("Chat"); |
|
app.setQuitOnLastWindowClosed(false); |
|
|
|
app.setStyle(QStyleFactory::create("Fusion")); |
|
QPalette p; |
|
p.setColor(QPalette::Window, QColor(53, 53, 53)); |
|
p.setColor(QPalette::WindowText, QColor(220, 220, 220)); |
|
p.setColor(QPalette::Base, QColor(42, 42, 42)); |
|
p.setColor(QPalette::AlternateBase, QColor(66, 66, 66)); |
|
p.setColor(QPalette::ToolTipBase, QColor(25, 25, 25)); |
|
p.setColor(QPalette::ToolTipText, QColor(220, 220, 220)); |
|
p.setColor(QPalette::Text, QColor(220, 220, 220)); |
|
p.setColor(QPalette::Button, QColor(53, 53, 53)); |
|
p.setColor(QPalette::ButtonText, QColor(220, 220, 220)); |
|
p.setColor(QPalette::BrightText, Qt::red); |
|
p.setColor(QPalette::Link, QColor(42, 130, 218)); |
|
p.setColor(QPalette::Highlight, QColor(42, 130, 218)); |
|
p.setColor(QPalette::HighlightedText, Qt::white); |
|
p.setColor(QPalette::Disabled, QPalette::Text, QColor(127, 127, 127)); |
|
p.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(127, 127, 127)); |
|
app.setPalette(p); |
|
|
|
QString cfgPath = QCoreApplication::applicationDirPath() + "/chatgui.cfg"; |
|
|
|
NodeConfig cfg(cfgPath); |
|
bool needSave = false; |
|
|
|
if (!cfg.exists()) { |
|
if (!cfg.create("chatgui", 1333)) { |
|
qCritical("Failed to create config: %s", qPrintable(cfgPath)); |
|
return 1; |
|
} |
|
} else { |
|
if (!cfg.load()) { |
|
qCritical("Cannot open/read config file: %s", qPrintable(cfgPath)); |
|
return 1; |
|
} |
|
if (cfg.hasErrors()) { |
|
for (const auto& err : cfg.errors()) |
|
fprintf(stderr, "CONFIG ERROR: %s\n", qPrintable(err)); |
|
return 1; |
|
} |
|
if (cfg.privKey().length() != 64 || cfg.pubKey().length() != 64) { |
|
qWarning("Config: keys missing/invalid, regenerating identity"); |
|
cfg.generateIdentity(); |
|
needSave = true; |
|
} |
|
if (cfg.nodeId().length() != 16) { |
|
qWarning("Config: my_node_id missing/invalid, regenerating identity"); |
|
cfg.generateIdentity(); |
|
needSave = true; |
|
} |
|
if (needSave) |
|
cfg.save(); |
|
} |
|
|
|
QString dbPath = cfg.dbPath(); |
|
if (dbPath.isEmpty()) dbPath = "chat_data"; |
|
if (!QDir::isAbsolutePath(dbPath)) |
|
dbPath = QCoreApplication::applicationDirPath() + "/" + dbPath; |
|
QDir(dbPath).mkpath("."); |
|
|
|
DbManager db; |
|
MainWindow w(nullptr, &db, cfgPath, dbPath, cfg.debugFile(), |
|
cfg.debugLevel(), cfg.debugCategories()); |
|
w.show(); |
|
|
|
return app.exec(); |
|
}
|
|
|