added bool oper. for new theme, plus new animations
This commit is contained in:
@@ -10,40 +10,52 @@
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
ConnectionLoader::ConnectionLoader(MainWindow* main, Controller* rpc)
|
||||
ConnectionLoader::ConnectionLoader(MainWindow* main, Controller* rpc)
|
||||
{
|
||||
this->main = main;
|
||||
this->rpc = rpc;
|
||||
|
||||
d = new QDialog(main);
|
||||
connD = new Ui_ConnectionDialog();
|
||||
connD->setupUi(d);
|
||||
QPixmap logo(":/img/res/logobig.gif");
|
||||
connD->topIcon->setBasePixmap(
|
||||
logo.scaled(
|
||||
256,
|
||||
256,
|
||||
Qt::KeepAspectRatio,
|
||||
Qt::SmoothTransformation
|
||||
)
|
||||
);
|
||||
|
||||
auto theme = Settings::getInstance()->get_theme_name();
|
||||
qDebug() << theme << "theme has loaded";
|
||||
auto size = QSize(512,512);
|
||||
|
||||
if (theme == "dark" || theme == "midnight") {
|
||||
QMovie *movie2 = new QMovie(":/img/res/silentdragonlite-animated-startup-dark.gif");;
|
||||
movie2->setScaledSize(size);
|
||||
qDebug() << "Animation dark loaded";
|
||||
connD->topIcon->setMovie(movie2);
|
||||
movie2->start();
|
||||
} else {
|
||||
QMovie *movie1 = new QMovie(":/img/res/silentdragonlite-animated-startup.gif");;
|
||||
movie1->setScaledSize(size);
|
||||
qDebug() << "Animation light loaded";
|
||||
connD->topIcon->setMovie(movie1);
|
||||
movie1->start();
|
||||
}
|
||||
main->logger->write("Set animation");
|
||||
qDebug() << "Set animation";
|
||||
isSyncing = new QAtomicInteger<bool>();
|
||||
}
|
||||
|
||||
ConnectionLoader::~ConnectionLoader()
|
||||
ConnectionLoader::~ConnectionLoader()
|
||||
{
|
||||
delete isSyncing;
|
||||
delete connD;
|
||||
delete d;
|
||||
}
|
||||
|
||||
void ConnectionLoader::loadConnection()
|
||||
void ConnectionLoader::loadConnection()
|
||||
{
|
||||
QTimer::singleShot(1, [=]() { this->doAutoConnect(); });
|
||||
if (!Settings::getInstance()->isHeadless())
|
||||
d->exec();
|
||||
}
|
||||
|
||||
void ConnectionLoader::doAutoConnect()
|
||||
void ConnectionLoader::doAutoConnect()
|
||||
{
|
||||
qDebug() << "Doing autoconnect";
|
||||
auto config = std::shared_ptr<ConnectionConfig>(new ConnectionConfig());
|
||||
@@ -54,29 +66,29 @@ void ConnectionLoader::doAutoConnect()
|
||||
main->logger->write(QObject::tr("Attempting to initialize library with ") + config->server);
|
||||
|
||||
// Check to see if there's an existing wallet
|
||||
if (litelib_wallet_exists(Settings::getDefaultChainName().toStdString().c_str()))
|
||||
if (litelib_wallet_exists(Settings::getDefaultChainName().toStdString().c_str()))
|
||||
{
|
||||
main->logger->write(QObject::tr("Using existing wallet."));
|
||||
char* resp = litelib_initialize_existing(
|
||||
config->dangerous,
|
||||
config->dangerous,
|
||||
config->server.toStdString().c_str()
|
||||
);
|
||||
QString response = litelib_process_response(resp);
|
||||
|
||||
if (response.toUpper().trimmed() != "OK")
|
||||
if (response.toUpper().trimmed() != "OK")
|
||||
{
|
||||
showError(response);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
main->logger->write(QObject::tr("Create/restore wallet."));
|
||||
createOrRestore(config->dangerous, config->server);
|
||||
d->show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
auto connection = makeConnection(config);
|
||||
auto me = this;
|
||||
|
||||
@@ -97,14 +109,14 @@ void ConnectionLoader::doAutoConnect()
|
||||
// When sync is done, set the connection
|
||||
this->doRPCSetConnection(connection);
|
||||
});
|
||||
|
||||
|
||||
// While it is syncing, we'll show the status updates while it is alive.
|
||||
QObject::connect(syncTimer, &QTimer::timeout, [=]() {
|
||||
// Check the sync status
|
||||
if (isSyncing != nullptr && isSyncing->load()) {
|
||||
// Get the sync status
|
||||
connection->doRPC("syncstatus", "", [=](json reply) {
|
||||
if (isSyncing != nullptr && reply.find("synced_blocks") != reply.end())
|
||||
if (isSyncing != nullptr && reply.find("synced_blocks") != reply.end())
|
||||
{
|
||||
qint64 synced = reply["synced_blocks"].get<json::number_unsigned_t>();
|
||||
qint64 total = reply["total_blocks"].get<json::number_unsigned_t>();
|
||||
@@ -117,8 +129,8 @@ void ConnectionLoader::doAutoConnect()
|
||||
qDebug() << "Sync error" << err;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
syncTimer->setInterval(1* 1000);
|
||||
syncTimer->start();
|
||||
|
||||
@@ -127,16 +139,16 @@ void ConnectionLoader::doAutoConnect()
|
||||
});
|
||||
}
|
||||
|
||||
void ConnectionLoader::createOrRestore(bool dangerous, QString server)
|
||||
void ConnectionLoader::createOrRestore(bool dangerous, QString server)
|
||||
{
|
||||
// Close the startup dialog, since we'll be showing the wizard
|
||||
d->hide();
|
||||
// Create a wizard
|
||||
FirstTimeWizard wizard(dangerous, server);
|
||||
FirstTimeWizard wizard(dangerous, server);
|
||||
wizard.exec();
|
||||
}
|
||||
|
||||
void ConnectionLoader::doRPCSetConnection(Connection* conn)
|
||||
void ConnectionLoader::doRPCSetConnection(Connection* conn)
|
||||
{
|
||||
qDebug() << "Connectionloader finished, setting connection";
|
||||
rpc->setConnection(conn);
|
||||
@@ -144,26 +156,26 @@ void ConnectionLoader::doRPCSetConnection(Connection* conn)
|
||||
QTimer::singleShot(1, [=]() { delete this; });
|
||||
}
|
||||
|
||||
Connection* ConnectionLoader::makeConnection(std::shared_ptr<ConnectionConfig> config)
|
||||
Connection* ConnectionLoader::makeConnection(std::shared_ptr<ConnectionConfig> config)
|
||||
{
|
||||
return new Connection(main, config);
|
||||
}
|
||||
|
||||
// Update the UI with the status
|
||||
void ConnectionLoader::showInformation(QString info, QString detail)
|
||||
void ConnectionLoader::showInformation(QString info, QString detail)
|
||||
{
|
||||
connD->status->setText(info);
|
||||
connD->statusDetail->setText(detail);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show error will close the loading dialog and show an error.
|
||||
* Show error will close the loading dialog and show an error.
|
||||
*/
|
||||
void ConnectionLoader::showError(QString explanation)
|
||||
{
|
||||
void ConnectionLoader::showError(QString explanation)
|
||||
{
|
||||
rpc->noConnection();
|
||||
QMessageBox::critical(
|
||||
main,
|
||||
main,
|
||||
QObject::tr("Connection Error"),
|
||||
explanation,
|
||||
QMessageBox::Ok
|
||||
@@ -171,7 +183,7 @@ void ConnectionLoader::showError(QString explanation)
|
||||
d->close();
|
||||
}
|
||||
|
||||
QString litelib_process_response(char* resp)
|
||||
QString litelib_process_response(char* resp)
|
||||
{
|
||||
char* resp_copy = new char[strlen(resp) + 1];
|
||||
//a safer version of strcpy
|
||||
@@ -185,15 +197,15 @@ QString litelib_process_response(char* resp)
|
||||
|
||||
/***********************************************************************************
|
||||
* Connection, Executor and Callback Class
|
||||
************************************************************************************/
|
||||
void Executor::run()
|
||||
************************************************************************************/
|
||||
void Executor::run()
|
||||
{
|
||||
char* resp = litelib_execute(this->cmd.toStdString().c_str(), this->args.toStdString().c_str());
|
||||
QString reply = litelib_process_response(resp);
|
||||
//qDebug() << "RPC Reply=" << reply;
|
||||
auto parsed = json::parse(
|
||||
reply.toStdString().c_str(),
|
||||
nullptr,
|
||||
reply.toStdString().c_str(),
|
||||
nullptr,
|
||||
false
|
||||
);
|
||||
if (parsed.is_discarded() || parsed.is_null())
|
||||
@@ -204,14 +216,14 @@ void Executor::run()
|
||||
}
|
||||
|
||||
|
||||
void Callback::processRPCCallback(json resp)
|
||||
void Callback::processRPCCallback(json resp)
|
||||
{
|
||||
this->cb(resp);
|
||||
// Destroy self
|
||||
delete this;
|
||||
}
|
||||
|
||||
void Callback::processError(QString resp)
|
||||
void Callback::processError(QString resp)
|
||||
{
|
||||
this->errCb(resp);
|
||||
// Destroy self
|
||||
@@ -226,7 +238,7 @@ Connection::Connection(MainWindow* m, std::shared_ptr<ConnectionConfig> conf)
|
||||
qRegisterMetaType<json>("json");
|
||||
}
|
||||
|
||||
void Connection::doRPC(const QString cmd, const QString args, const std::function<void(json)>& cb, const std::function<void(QString)>& errCb)
|
||||
void Connection::doRPC(const QString cmd, const QString args, const std::function<void(json)>& cb, const std::function<void(QString)>& errCb)
|
||||
{
|
||||
if (shutdownInProgress)
|
||||
// Ignoring RPC because shutdown in progress
|
||||
@@ -242,26 +254,26 @@ void Connection::doRPC(const QString cmd, const QString args, const std::functio
|
||||
|
||||
QObject::connect(runner, &Executor::responseReady, c, &Callback::processRPCCallback);
|
||||
QObject::connect(runner, &Executor::handleError, c, &Callback::processError);
|
||||
QThreadPool::globalInstance()->start(runner);
|
||||
QThreadPool::globalInstance()->start(runner);
|
||||
}
|
||||
|
||||
void Connection::doRPCWithDefaultErrorHandling(const QString cmd, const QString args, const std::function<void(json)>& cb)
|
||||
void Connection::doRPCWithDefaultErrorHandling(const QString cmd, const QString args, const std::function<void(json)>& cb)
|
||||
{
|
||||
doRPC(cmd, args, cb, [=] (QString err) {
|
||||
this->showTxError(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void Connection::doRPCIgnoreError(const QString cmd, const QString args, const std::function<void(json)>& cb)
|
||||
void Connection::doRPCIgnoreError(const QString cmd, const QString args, const std::function<void(json)>& cb)
|
||||
{
|
||||
doRPC(cmd, args, cb, [=] (auto) {
|
||||
// Ignored error handling
|
||||
});
|
||||
}
|
||||
|
||||
void Connection::showTxError(const QString& error)
|
||||
void Connection::showTxError(const QString& error)
|
||||
{
|
||||
if (error.isNull())
|
||||
if (error.isNull())
|
||||
return;
|
||||
|
||||
// Prevent multiple dialog boxes from showing, because they're all called async
|
||||
@@ -271,8 +283,8 @@ void Connection::showTxError(const QString& error)
|
||||
|
||||
shown = true;
|
||||
QMessageBox::critical(
|
||||
main,
|
||||
QObject::tr("Transaction Error"),
|
||||
main,
|
||||
QObject::tr("Transaction Error"),
|
||||
QObject::tr("There was an error sending the transaction. The error was:") + "\n\n" + error,
|
||||
QMessageBox::StandardButton::Ok
|
||||
);
|
||||
@@ -281,8 +293,8 @@ void Connection::showTxError(const QString& error)
|
||||
|
||||
/**
|
||||
* Prevent all future calls from going through
|
||||
*/
|
||||
void Connection::shutdown()
|
||||
*/
|
||||
void Connection::shutdown()
|
||||
{
|
||||
shutdownInProgress = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user