Skip to content

Commit 19f9591

Browse files
committed
android storage options on filepicker
1 parent 1896b75 commit 19f9591

File tree

4 files changed

+63
-9
lines changed

4 files changed

+63
-9
lines changed

src/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "chaptermodel.h"
1515
#include "player.h"
1616
#include "shortcuts.h"
17+
#include "util.h"
1718

1819
#ifdef Q_OS_ANDROID
1920
#include <QtAndroidExtras>
@@ -74,6 +75,7 @@ int main(int argc, char *argv[])
7475
qmlRegisterSingletonType<Settings>("QSettings", 1, 0, "QSettings", &Settings::qmlInstance);
7576
qmlRegisterSingletonType<Database>("Database", 1, 0, "Database", &Database::qmlInstance);
7677
qmlRegisterSingletonType<Player>("Player", 1, 0, "Player", &Player::qmlInstance);
78+
qmlRegisterSingletonType<Util>("Util", 1, 0, "Util", &Util::qmlInstance);
7779

7880

7981
qmlRegisterType<ChapterModel>("ChapterModel", 1, 0, "ChapterModel");

src/qml/FilePicker.qml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import QtQuick.Layouts 1.2
44
import Qt.labs.folderlistmodel 2.1
55
import QtGraphicalEffects 1.0
66
import Database 1.0
7+
import Util 1.0
78
import 'Style'
89

910
Page {
@@ -46,10 +47,26 @@ Page {
4647
}
4748
}
4849

50+
ComboBox {
51+
id: extra_paths
52+
anchors.top: parent.top
53+
implicitWidth: parent.width
54+
visible: Util.getAndroidStorageLocations().length > 0
55+
model: Util.getAndroidStorageLocations()
56+
onCurrentIndexChanged: {
57+
folder_list_model.folder = 'file://' + Util.getAndroidStorageLocations()[currentIndex] + '/'
58+
console.log('file://' + Util.getAndroidStorageLocations()[currentIndex] + '/')
59+
console.log('file://' + Database.libraryPath)
60+
}
61+
}
4962

5063
ListView {
5164
id: file_list_view
52-
anchors.fill: parent
65+
anchors.top: Util.getAndroidStorageLocations().length > 0 ? extra_paths.bottom : parent.top
66+
anchors.right: parent.right
67+
anchors.bottom: parent.bottom
68+
anchors.left: parent.left
69+
clip: true
5370
ScrollBar.vertical: ScrollBar {}
5471

5572
model: FolderListModel {

src/util.cpp

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@
77
#include "taglib/fileref.h"
88

99

10+
Util::Util(QObject *parent)
11+
: QObject(parent)
12+
{
13+
}
14+
15+
Util *Util::instance()
16+
{
17+
static Util* instance = new Util;
18+
return instance;
19+
}
20+
21+
QObject *Util::qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine)
22+
{
23+
Q_UNUSED(engine);
24+
Q_UNUSED(scriptEngine);
25+
return Util::instance(); // C++ and QML instance
26+
}
27+
1028

1129
QString Util::getDisplayTime(const QString &xFileName)
1230
{
@@ -96,16 +114,21 @@ QString Util::getMusicLocation()
96114

97115
QString Util::getHomeLocation()
98116
{
99-
#ifdef Q_OS_ANDROID
100-
// GenericDataLocation = user folder
101-
//QStringList systemEnvironment = QProcess::systemEnvironment();
102-
//qDebug() << systemEnvironment;
103-
//qDebug() << QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString(), QStandardPaths::LocateDirectory);
104-
return QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString(), QStandardPaths::LocateDirectory);
105-
#endif
106117
return QStandardPaths::locate(QStandardPaths::HomeLocation, QString(), QStandardPaths::LocateDirectory);
107118
}
108119

120+
QStringList Util::getAndroidStorageLocations()
121+
{
122+
// GenericDataLocation = user folder
123+
QStringList system_environment = QProcess::systemEnvironment();
124+
QStringList result;
125+
for (auto s: system_environment) {
126+
if (s.contains("STORAGE="))
127+
result.append(s.split("=")[1]);
128+
}
129+
return result;
130+
}
131+
109132
QString Util::appendFile(QString &xString) {
110133
return QString("file://" + xString);
111134
}

src/util.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@
55
#include <QFileInfo>
66

77
class QString;
8+
class QQmlEngine;
9+
class QJSEngine;
810

9-
class Util
11+
class Util : public QObject
1012
{
13+
Q_OBJECT
14+
1115
public:
16+
Util(const Util&) = delete; // disable copy for singleton
17+
static Util *instance();
18+
static QObject *qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine);
19+
1220
static QString getDisplayTime(const QString &xFileName);
1321
static QString getDisplayTime(uint xTimeMSec);
1422
static uint getTimeMSec(const QString &xFileName);
@@ -22,7 +30,11 @@ class Util
2230
Q_INVOKABLE static QString getCacheLocation();
2331
Q_INVOKABLE static QString getMusicLocation();
2432
Q_INVOKABLE static QString getHomeLocation();
33+
Q_INVOKABLE static QStringList getAndroidStorageLocations();
2534
Q_INVOKABLE static QString appendFile(QString &xString);
35+
36+
private:
37+
explicit Util(QObject *parent = nullptr);
2638
};
2739

2840
#endif // UTIL_H

0 commit comments

Comments
 (0)