-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
android: custom datadir retrieve filepath
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |