|
|
@ -37,16 +37,15 @@ Config Settings::getSettings() { |
|
|
|
if (server.trimmed().isEmpty()) { |
|
|
|
server = Settings::getRandomServer(); |
|
|
|
|
|
|
|
QString response = ""; |
|
|
|
bool isOnline = false; |
|
|
|
// make sure existing server in conf is alive, otherwise choose random one
|
|
|
|
try { |
|
|
|
char* resp = litelib_initialize_existing(false, server.toStdString().c_str()); |
|
|
|
response = litelib_process_response(resp); |
|
|
|
bool isOnline = litelib_check_server_online(server.toStdString().c_str()); |
|
|
|
} catch (const std::exception& e) { |
|
|
|
qDebug() << __func__ << ": caught an exception, ignoring: " << e.what(); |
|
|
|
} |
|
|
|
|
|
|
|
if (response.toUpper().trimmed() != "OK") { |
|
|
|
if (!isOnline) { |
|
|
|
qDebug() << "Lite server in conf " << server << " is down, getting a random one"; |
|
|
|
server = Settings::getRandomServer(); |
|
|
|
s.setValue("connection/server", server); |
|
|
@ -250,6 +249,22 @@ void Settings::setAllowFetchPrices(bool allow) { |
|
|
|
QSettings().setValue("options/allowfetchprices", allow); |
|
|
|
} |
|
|
|
|
|
|
|
bool Settings::getUseStickyServer() { |
|
|
|
return QSettings().value("connection/stickyServer", false).toBool(); |
|
|
|
} |
|
|
|
|
|
|
|
void Settings::setUseStickyServer(bool allow) { |
|
|
|
QSettings().setValue("connection/stickyServer", allow); |
|
|
|
} |
|
|
|
|
|
|
|
bool Settings::getUseNoteAutomation() { |
|
|
|
return QSettings().value("options/useNoteAutomation", true).toBool(); |
|
|
|
} |
|
|
|
|
|
|
|
void Settings::setUseNoteAutomation(bool allow) { |
|
|
|
QSettings().setValue("options/useNoteAutomation", allow); |
|
|
|
} |
|
|
|
|
|
|
|
QString Settings::get_currency_name() { |
|
|
|
// Load from the QT Settings.
|
|
|
|
return QSettings().value("options/currency_name", false).toString(); |
|
|
@ -317,17 +332,16 @@ QString Settings::getRandomServer() { |
|
|
|
while (tries < servers.size() ) { |
|
|
|
qDebug() << "Checking if lite server " << server << " is a alive, try=" << tries; |
|
|
|
|
|
|
|
QString response = ""; |
|
|
|
bool isOnline = ""; |
|
|
|
|
|
|
|
try { |
|
|
|
char* resp = litelib_initialize_existing(false, server.toStdString().c_str()); |
|
|
|
response = litelib_process_response(resp); |
|
|
|
isOnline = litelib_check_server_online(server.toStdString().c_str()); |
|
|
|
} catch (const std::exception& e) { |
|
|
|
qDebug() << __func__ << ": caught an exception, ignoring: " << e.what(); |
|
|
|
} |
|
|
|
|
|
|
|
// if we see a valid connection, return this server
|
|
|
|
if (response.toUpper().trimmed() == "OK") { |
|
|
|
// if we see a valid connection, return this server.
|
|
|
|
if (isOnline) { |
|
|
|
qDebug() << "Choosing lite server " << server; |
|
|
|
return server; |
|
|
|
} |
|
|
|