Wizard: rework

This commit is contained in:
tobtoht
2021-03-12 20:01:53 +01:00
parent cc5b3c3c27
commit 6741e684f5
63 changed files with 2781 additions and 1783 deletions
+13 -2
View File
@@ -23,7 +23,10 @@ struct RestoreHeightLookup {
// will calculate the blockheight based off the last known
// date: ((now - lastKnownDate) / blockTime) - clearance
if(this->type == NetworkType::TESTNET) return 1;
if (this->type == NetworkType::TESTNET) {
return 1;
}
int blockTime = 120;
int blocksPerDay = 86400 / blockTime;
int blockCalcClearance = blocksPerDay * 5;
@@ -50,12 +53,20 @@ struct RestoreHeightLookup {
// @TODO: most likely inefficient, refactor
QMap<int, int>::iterator i;
int timestamp = 0;
int heightData = 1;
for (i = this->data.begin(); i != this->data.end(); ++i) {
int ts = i.key();
if (i.value() > height)
return timestamp;
timestamp = ts;
heightData = i.value();
}
while (heightData < height) {
heightData += 720; // blocks per day
timestamp += 86400; // seconds in day
}
return timestamp;
}
@@ -67,7 +78,7 @@ struct RestoreHeightLookup {
for(const auto &line: data.split('\n')) {
if(line.trimmed().isEmpty()) continue;
auto spl = line.trimmed().split(':');
rtn->data[spl.at(0).toUInt()] = spl.at(1).toUInt();
rtn->data[spl.at(0).toInt()] = spl.at(1).toInt();
}
return rtn;
}
+25 -9
View File
@@ -104,31 +104,47 @@ Config::Config(const QString& fileName, QObject* parent)
}
Config::Config(QObject* parent)
: QObject(parent)
: QObject(parent)
{
QString configPath;
QDir configDir = Config::defaultConfigDir();
QString portablePath = QCoreApplication::applicationDirPath().append("/%1");
if (QFile::exists(portablePath.arg(".portable"))) {
init(portablePath.arg("feather_data/settings.json"));
return;
}
bool isTails = TailsOS::detect();
configPath = QDir::homePath();
if (isTails) { // #if defined(PORTABLE)
QString appImagePath = qgetenv("APPIMAGE");
QFileInfo appImageDir(appImagePath);
QDir portablePath(appImageDir.absoluteDir().path() + "/.feather");
QDir portablePath(appImageDir.absoluteDir().path() + "/feather_data");
if (portablePath.mkpath(".")) {
configPath = portablePath.path();
}
else {
configDir = portablePath;
} else {
qCritical() << "Unable to create portable directory: " << portablePath.path();
}
}
configPath += "/.config/feather/settings.json";
QString configPath = configDir.filePath("settings.json");
init(QDir::toNativeSeparators(configPath));
}
QDir Config::defaultConfigDir() {
#if defined(Q_OS_WIN)
return QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
#elif defined(Q_OS_MACOS)
return QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
#else
return QDir(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/feather");
#endif
}
QDir Config::defaultPortableConfigDir() {
return QDir(QCoreApplication::applicationDirPath() + "/feather_data");
}
Config::~Config()
{
+6 -1
View File
@@ -9,6 +9,7 @@
#include <QObject>
#include <QSettings>
#include <QPointer>
#include <QDir>
class Config : public QObject
{
@@ -50,7 +51,8 @@ public:
redditFrontend,
showHistorySyncNotice,
GUI_HistoryViewState,
amountPrecision
amountPrecision,
portableMode
};
~Config() override;
@@ -60,6 +62,9 @@ public:
void sync();
void resetToDefaults();
static QDir defaultConfigDir();
static QDir defaultPortableConfigDir();
static Config* instance();
signals:
+6 -5
View File
@@ -69,14 +69,14 @@ void WalletKeysFilesModel::refresh() {
void WalletKeysFilesModel::updateDirectories() {
this->walletDirectories.clear();
this->walletDirectories << m_ctx->defaultWalletDirRoot;
this->walletDirectories << m_ctx->defaultWalletDir; // TODO
auto walletPath = config()->get(Config::walletPath).toString();
if(!walletPath.isEmpty() && Utils::fileExists(walletPath)) {
QDir d = QFileInfo(walletPath).absoluteDir();
this->walletDirectories << d.absolutePath();
}
this->walletDirectories << m_ctx->homeDir;
this->walletDirectories << QDir::homePath();
this->walletDirectories.removeDuplicates();
}
@@ -160,12 +160,13 @@ QVariant WalletKeysFilesModel::data(const QModelIndex &index, int role) const {
return QString("main");
}
case ModelColumns::FileName:
return walletKeyFile.fileName();
return walletKeyFile.fileName().replace(".keys", "");
case ModelColumns::Path: {
auto fp = walletKeyFile.path();
#if defined(Q_OS_MAC) || defined(Q_OS_LINUX)
if (fp.startsWith(m_ctx->homeDir))
fp = QString("~/%1").arg(fp.remove(0, m_ctx->homeDir.length() + 1));
if (fp.startsWith(QDir::homePath())) {
fp = QString("~/%1").arg(fp.remove(0, QDir::homePath().length() + 1));
}
#endif
return fp;
}
+1 -1
View File
@@ -20,7 +20,7 @@ Tor::Tor(AppContext *ctx, QObject *parent)
{
connect(m_checkConnectionTimer, &QTimer::timeout, this, &Tor::checkConnection);
this->torDir = QDir(m_ctx->configDirectory).filePath("tor");
this->torDir = Config::defaultConfigDir().filePath("tor");
this->torDataPath = QDir(this->torDir).filePath("data");
if (m_ctx->cmdargs->isSet("tor-port")) {
+18
View File
@@ -468,4 +468,22 @@ QTextCharFormat Utils::addressTextFormat(const SubaddressIndex &index) {
return rec;
}
return QTextCharFormat();
}
bool Utils::isTorsocks() {
#if defined(Q_OS_MAC)
return qgetenv("DYLD_INSERT_LIBRARIES").indexOf("libtorsocks") >= 0;
#elif defined(Q_OS_LINUX)
return qgetenv("LD_PRELOAD").indexOf("libtorsocks") >= 0;
#else
return false;
#endif
}
QString Utils::defaultWalletDir() {
#if defined(Q_OS_LINUX) or defined(Q_OS_MAC)
return QString("%1/Monero/wallets").arg(QDir::homePath());
#elif defined(Q_OS_WIN)
return QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + "/Monero/wallets";
#endif
}
+2
View File
@@ -76,6 +76,8 @@ public:
static QMap<QString, QLocale> localeCache;
static QString balanceFormat(quint64 balance);
static QTextCharFormat addressTextFormat(const SubaddressIndex &index);
static bool isTorsocks();
static QString defaultWalletDir();
template<typename QEnum>
static QString QtEnumToString (const QEnum value)