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

Wiring for Custom Datadir #408

Closed
9 changes: 6 additions & 3 deletions src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,12 @@ QML_RES_QML = \
qml/pages/wallet/WalletSelect.qml

if TARGET_ANDROID
BITCOIN_QT_H += qml/androidnotifier.h
BITCOIN_QML_BASE_CPP += qml/androidnotifier.cpp
QT_MOC_CPP += qml/moc_androidnotifier.cpp
BITCOIN_QT_H += qml/androidnotifier.h \
qml/androidcustomdatadir.h
BITCOIN_QML_BASE_CPP += qml/androidnotifier.cpp \
qml/androidcustomdatadir.cpp
QT_MOC_CPP += qml/moc_androidnotifier.cpp \
qml/moc_androidcustomdatadir.cpp
endif

BITCOIN_QT_CPP = $(BITCOIN_QT_BASE_CPP)
Expand Down
1 change: 1 addition & 0 deletions src/common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <cstddef>
#include <map>
#include <string>
#include <univalue.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every commit should pass compilation and all tests so if the failure occurs on the previous commit you should include it there (we are missing the "CI / test each commit (pull_request)" that exists on the other repos and I think @hebasto has it pending with other things he wanted to merge here into this repo).

#include <vector>

class UniValue;
Expand Down
48 changes: 48 additions & 0 deletions src/qml/androidcustomdatadir.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2023-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <qml/androidcustomdatadir.h>

#include <common/args.h>
#include <qml/util.h>
#include <qml/guiconstants.h>
#include <qt/guiutil.h>

#include <QDebug>
#include <QFile>
#include <QStandardPaths>
#include <QDir>

AndroidCustomDataDir::AndroidCustomDataDir(QObject * parent)
: QObject(parent)
{
m_default_data_dir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
}

void AndroidCustomDataDir::setDataDir(const QString & new_data_dir)
{
if (m_data_dir == new_data_dir) {
return;
}

m_data_dir = new_data_dir;
gArgs.SoftSetArg("-datadir", fs::PathToString(GUIUtil::QStringToPath(m_data_dir)));
gArgs.ClearPathCache();
Q_EMIT dataDirChanged();
}

QString AndroidCustomDataDir::readCustomDataDir()
{
QFile file(m_default_data_dir + "/filepath.txt");
QString storedPath;

if (file.open(QIODevice::ReadOnly)) {
QTextStream in(&file);
storedPath = in.readAll().trimmed();
file.close();
// Process the retrieved path
qDebug() << "Retrieved path: " << storedPath;
}
return storedPath;
}
32 changes: 32 additions & 0 deletions src/qml/androidcustomdatadir.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2024 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_QML_ANDROIDCUSTOMDATADIR_H
#define BITCOIN_QML_ANDROIDCUSTOMDATADIR_H

#include <QFile>
#include <QStandardPaths>
#include <QDir>

class AndroidCustomDataDir : public QObject
{
Q_OBJECT
Q_PROPERTY(QString dataDir READ dataDir WRITE setDataDir NOTIFY dataDirChanged)

public:
explicit AndroidCustomDataDir(QObject * parent = nullptr);

QString dataDir() const { return m_data_dir; }
void setDataDir(const QString & new_data_dir);
QString readCustomDataDir();

Q_SIGNALS:
void dataDirChanged();

private:
QString m_data_dir;
QString m_default_data_dir;
};

#endif // BITCOIN_QML_ANDROIDCUSTOMDATADIR_H
Loading
Loading