Skip to content

Commit

Permalink
android: custom datadir retrieve filepath
Browse files Browse the repository at this point in the history
  • Loading branch information
D33r-Gee committed Sep 9, 2024
1 parent 7f41874 commit da4f6fe
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
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 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

0 comments on commit da4f6fe

Please sign in to comment.