Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qt+afp: Create GUI for Avian Flight plans #186

Draft
wants to merge 7 commits into
base: 4.2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ QT_FORMS_UI = \
qt/forms/addpeerdialog.ui \
qt/forms/testpeerdialog.ui \
qt/forms/wrapping.ui \
qt/forms/flightplans.ui \
qt/forms/sendcoinsdialog.ui \
qt/forms/sendcoinsentry.ui \
qt/forms/signverifymessagedialog.ui \
Expand Down Expand Up @@ -169,6 +170,7 @@ QT_MOC_CPP = \
qt/moc_recentrequeststablemodel.cpp \
qt/moc_rpcconsole.cpp \
qt/moc_wrapping.cpp \
qt/moc_flightplans.cpp \
qt/moc_sendcoinsdialog.cpp \
qt/moc_sendcoinsentry.cpp \
qt/moc_signverifymessagedialog.cpp \
Expand Down Expand Up @@ -280,6 +282,7 @@ AVIAN_QT_H = \
qt/transactiontablemodel.h \
qt/transactionview.h \
qt/wrapping.h \
qt/flightplans.h \
qt/utilitydialog.h \
qt/verticallabel.h \
qt/peerdialog.h \
Expand Down Expand Up @@ -487,6 +490,7 @@ AVIAN_QT_WALLET_CPP = \
qt/transactiontablemodel.cpp \
qt/transactionview.cpp \
qt/wrapping.cpp \
qt/flightplans.cpp \
qt/verticallabel.cpp \
qt/peerdialog.cpp \
qt/walletframe.cpp \
Expand Down
30 changes: 22 additions & 8 deletions src/flightplans/flightplans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,29 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

/*
Avian Flight Plans (smart contracts) are experimental and prone to bugs.
/**
Avian Flight Plans are experimental and prone to bugs.
Please take precautions when using this feature.
*/

#include "flightplans.h"

#include "avianlib.h"
#include "util.h"
#include "fs.h"

#include <cstddef>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

#include "lua/lua.hpp"

FlightPlanResult AvianFlightPlans::run_file(const char* file, const char* func, std::vector<std::string> args)
FlightPlanResult CAvianFlightPlans::RunFile(const char* file, const char* func, std::vector<std::string> args)
{
/* Warn user **/
LogPrintf("Running flight plan -- Avian Flight Plans are experimental and prone to bugs. Please take precautions when using this feature.\n");
// Warn user
LogPrintf("Running flight plan; Avian Flight Plans are experimental and prone to bugs. Please take precautions when using this feature.\n");

// Result object
FlightPlanResult result;
Expand Down Expand Up @@ -59,14 +61,14 @@ FlightPlanResult AvianFlightPlans::run_file(const char* file, const char* func,

if (args.size() >= 1) {
n = args.size();
/* loop through each argument */
// Loop through each argument
for (int i = 0; i < n; i++) {
/* push argument */
lua_pushstring(L, args[i].c_str());
}
}

/* call the function with n arguments, return 1 result */
// Call the function with n arguments, return 1 result
status = lua_pcall(L, n, 1, 0);

if (status != LUA_OK) {
Expand All @@ -77,7 +79,7 @@ FlightPlanResult AvianFlightPlans::run_file(const char* file, const char* func,
return result;
}

/* get the result */
// Get the result
if (lua_isstring(L, -1)) {
result.result = (char*)lua_tostring(L, -1);
lua_pop(L, 1);
Expand All @@ -96,3 +98,15 @@ FlightPlanResult AvianFlightPlans::run_file(const char* file, const char* func,

return result;
}

std::vector<std::string> CAvianFlightPlans::GetPlans()
{
std::vector<std::string> plans;
fs::path path = GetDataDir(false) / "flightplans";
for (auto& file : fs::directory_iterator(path)) {
if (file.path().extension() == ".lua") {
plans.push_back(file.path().stem().string());
}
}
return plans;
}
5 changes: 3 additions & 2 deletions src/flightplans/flightplans.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ class FlightPlanResult
};

/* Avian Flightplans */
class AvianFlightPlans
class CAvianFlightPlans
{
public:
FlightPlanResult run_file(const char* file, const char* func, std::vector<std::string> args={});
static FlightPlanResult RunFile(const char* file, const char* func, std::vector<std::string> args={});
static std::vector<std::string> GetPlans();
};

#endif
31 changes: 31 additions & 0 deletions src/qt/aviangui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "optionsmodel.h"
#include "platformstyle.h"
#include "rpcconsole.h"
#include "flightplans.h"
#include "utilitydialog.h"
#include "validation.h"

Expand Down Expand Up @@ -142,6 +143,7 @@ AvianGUI::AvianGUI(const PlatformStyle *_platformStyle, const NetworkStyle *netw
openRPCConsoleAction(0),
openAction(0),
showHelpMessageAction(0),
openFlightplansAction(0),
transferAssetAction(0),
createAssetAction(0),
manageAssetAction(0),
Expand All @@ -159,6 +161,7 @@ AvianGUI::AvianGUI(const PlatformStyle *_platformStyle, const NetworkStyle *netw
trayIconMenu(0),
notificator(0),
rpcConsole(0),
flightplans(0),
helpMessageDialog(0),
modalOverlay(0),
prevBlocks(0),
Expand Down Expand Up @@ -197,6 +200,7 @@ AvianGUI::AvianGUI(const PlatformStyle *_platformStyle, const NetworkStyle *netw
#endif

rpcConsole = new RPCConsole(_platformStyle, 0);
flightplans = new Flightplans(_platformStyle, 0);
helpMessageDialog = new HelpMessageDialog(this, false);
#ifdef ENABLE_WALLET
if(enableWallet)
Expand Down Expand Up @@ -550,6 +554,13 @@ void AvianGUI::createActions()
showHelpMessageAction->setMenuRole(QAction::NoRole);
showHelpMessageAction->setStatusTip(tr("Show the %1 help message to get a list with possible Avian command-line options").arg(tr(PACKAGE_NAME)));

/** AVN START */
openFlightplansAction = new QAction(platformStyle->TextColorIcon(":/icons/avian"), tr("&Manage Avian Flight Plans"), this);
openFlightplansAction->setMenuRole(QAction::NoRole);
openFlightplansAction->setStatusTip(tr("Manage and create Avian Flight Plans"));
connect(openFlightplansAction, SIGNAL(triggered()), this, SLOT(showFlightplans()));
/** AVN END */

connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked()));
connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
Expand Down Expand Up @@ -621,6 +632,14 @@ void AvianGUI::createMenuBar()
}
settings->addAction(optionsAction);

/** AVN START */

QMenu *extra = appMenuBar->addMenu(tr("&Extra"));
extra->addAction(openFlightplansAction);
extra->addSeparator();

/** AVN END */

QMenu *help = appMenuBar->addMenu(tr("&Help"));
if(walletFrame)
{
Expand Down Expand Up @@ -1026,6 +1045,18 @@ void AvianGUI::showHelpMessageClicked()
helpMessageDialog->show();
}

/** AVN START */

void AvianGUI::showFlightplans()
{
flightplans->showNormal();
flightplans->show();
flightplans->raise();
flightplans->activateWindow();
}

/** AVN END */

#ifdef ENABLE_WALLET
void AvianGUI::openClicked()
{
Expand Down
7 changes: 7 additions & 0 deletions src/qt/aviangui.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Notificator;
class OptionsModel;
class PlatformStyle;
class RPCConsole;
class Flightplans;
class SendCoinsRecipient;
class UnitDisplayStatusBarControl;
class WalletFrame;
Expand Down Expand Up @@ -134,13 +135,15 @@ class AvianGUI : public QMainWindow
QAction *getMyWordsAction;
QAction *votingAction;
QAction *restrictedAssetAction;
QAction *openFlightplansAction;
QAction *wrapAction;
QWidget *headerWidget;
QLabel *labelCurrentMarket;
QLabel *labelCurrentPrice;
QTimer *pricingTimer;
QNetworkAccessManager* networkManager;
QNetworkRequest* request;
Flightplans *flightplans;
/** AVN END */

QSystemTrayIcon *trayIcon;
Expand Down Expand Up @@ -277,6 +280,10 @@ private Q_SLOTS:
void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
#endif

/** AVN START */
void showFlightplans();
/** AVN END */

/** Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHidden is true */
void showNormalIfMinimized(bool fToggleHidden = false);
/** Simply calls showNormalIfMinimized(true) for use in SLOT() macro */
Expand Down
72 changes: 72 additions & 0 deletions src/qt/flightplans.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) 2022 The Avian Core developers
// Copyright (c) 2022 Shafil Alam
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#if defined(HAVE_CONFIG_H)
#include "config/avian-config.h"
#endif

#include "flightplans.h"
#include "ui_flightplans.h"
#include "flightplans/flightplans.h"

#include "guiutil.h"
#include "platformstyle.h"
#include "guiconstants.h"
#include "validation.h"
#include "util.h"

#include <vector>
#include <string>

#include <QMessageBox>
#include <QSignalMapper>
#include <QStringList>

#include <QPainter>
#include <QPainterPath>
#include <QGraphicsDropShadowEffect>

Flightplans::Flightplans(const PlatformStyle *platformStyle, QWidget *parent) :
QDialog(parent),
ui(new Ui::Flightplans)
{
ui->setupUi(this);

// Set data dir label
ui->labelDatadir->setText(tr("List of flightplans in: ") + QString::fromStdString((GetDataDir() / "flightplans" ).string()));

// Set warning
if (!AreFlightPlansDeployed()) {
ui->labelAlerts->setText(tr("Warning: Avian Flight Plans are not deployed."));
}

if (!gArgs.IsArgSet("-flightplans") && AreFlightPlansDeployed()) {
ui->labelAlerts->setText(tr("Warning: Avian Flight Plans are deployed but is disabled."));
}

if (gArgs.IsArgSet("-flightplans") && AreFlightPlansDeployed()) {
ui->labelAlerts->setText(tr("Warning: Avian Flight Plans are ACTIVE! Please exercise extreme caution."));
}

// List all flight plans
auto plans = CAvianFlightPlans::GetPlans();
ui->listWidget->addItem(QString::fromStdString(std::string("There are ") + std::to_string(plans.size()) + std::string(" flightplans.")));
for(const std::string& plan : plans) {
ui->listWidget->addItem(QString::fromStdString(plan));
}

/** Connect signals */
// connect(ui->wrapButton, SIGNAL(clicked()), this, SLOT(wrapped_clicked()));
}

void Flightplans::wrapped_clicked()
{
/** Show warning */
}

Flightplans::~Flightplans()
{
delete ui;
}
33 changes: 33 additions & 0 deletions src/qt/flightplans.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2022 The Avian Core developers
// Copyright (c) 2022 Shafil Alam
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef AVIAN_QT_FLIGHTPLANS_H
#define AVIAN_QT_FLIGHTPLANS_H

#include <QDialog>
#include <QThread>

class PlatformStyle;

namespace Ui {
class Flightplans;
}

class Flightplans: public QDialog
{
Q_OBJECT

public:
explicit Flightplans(const PlatformStyle *platformStyle, QWidget *parent = 0);
~Flightplans();

private Q_SLOTS:
void wrapped_clicked();

private:
Ui::Flightplans *ui;
};

#endif // AVIAN_QT_FLIGHTPLANS_H
Loading