Skip to content

Commit

Permalink
android storage options on filepicker
Browse files Browse the repository at this point in the history
  • Loading branch information
Gibbz committed Aug 2, 2020
1 parent 1896b75 commit 19f9591
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "chaptermodel.h"
#include "player.h"
#include "shortcuts.h"
#include "util.h"

#ifdef Q_OS_ANDROID
#include <QtAndroidExtras>
Expand Down Expand Up @@ -74,6 +75,7 @@ int main(int argc, char *argv[])
qmlRegisterSingletonType<Settings>("QSettings", 1, 0, "QSettings", &Settings::qmlInstance);
qmlRegisterSingletonType<Database>("Database", 1, 0, "Database", &Database::qmlInstance);
qmlRegisterSingletonType<Player>("Player", 1, 0, "Player", &Player::qmlInstance);
qmlRegisterSingletonType<Util>("Util", 1, 0, "Util", &Util::qmlInstance);


qmlRegisterType<ChapterModel>("ChapterModel", 1, 0, "ChapterModel");
Expand Down
19 changes: 18 additions & 1 deletion src/qml/FilePicker.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import QtQuick.Layouts 1.2
import Qt.labs.folderlistmodel 2.1
import QtGraphicalEffects 1.0
import Database 1.0
import Util 1.0
import 'Style'

Page {
Expand Down Expand Up @@ -46,10 +47,26 @@ Page {
}
}

ComboBox {
id: extra_paths
anchors.top: parent.top
implicitWidth: parent.width
visible: Util.getAndroidStorageLocations().length > 0
model: Util.getAndroidStorageLocations()
onCurrentIndexChanged: {
folder_list_model.folder = 'file://' + Util.getAndroidStorageLocations()[currentIndex] + '/'
console.log('file://' + Util.getAndroidStorageLocations()[currentIndex] + '/')
console.log('file://' + Database.libraryPath)
}
}

ListView {
id: file_list_view
anchors.fill: parent
anchors.top: Util.getAndroidStorageLocations().length > 0 ? extra_paths.bottom : parent.top
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.left: parent.left
clip: true
ScrollBar.vertical: ScrollBar {}

model: FolderListModel {
Expand Down
37 changes: 30 additions & 7 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@
#include "taglib/fileref.h"


Util::Util(QObject *parent)
: QObject(parent)
{
}

Util *Util::instance()
{
static Util* instance = new Util;
return instance;
}

QObject *Util::qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine)
{
Q_UNUSED(engine);
Q_UNUSED(scriptEngine);
return Util::instance(); // C++ and QML instance
}


QString Util::getDisplayTime(const QString &xFileName)
{
Expand Down Expand Up @@ -96,16 +114,21 @@ QString Util::getMusicLocation()

QString Util::getHomeLocation()
{
#ifdef Q_OS_ANDROID
// GenericDataLocation = user folder
//QStringList systemEnvironment = QProcess::systemEnvironment();
//qDebug() << systemEnvironment;
//qDebug() << QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString(), QStandardPaths::LocateDirectory);
return QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString(), QStandardPaths::LocateDirectory);
#endif
return QStandardPaths::locate(QStandardPaths::HomeLocation, QString(), QStandardPaths::LocateDirectory);
}

QStringList Util::getAndroidStorageLocations()
{
// GenericDataLocation = user folder
QStringList system_environment = QProcess::systemEnvironment();
QStringList result;
for (auto s: system_environment) {
if (s.contains("STORAGE="))
result.append(s.split("=")[1]);
}
return result;
}

QString Util::appendFile(QString &xString) {
return QString("file://" + xString);
}
14 changes: 13 additions & 1 deletion src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@
#include <QFileInfo>

class QString;
class QQmlEngine;
class QJSEngine;

class Util
class Util : public QObject
{
Q_OBJECT

public:
Util(const Util&) = delete; // disable copy for singleton
static Util *instance();
static QObject *qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine);

static QString getDisplayTime(const QString &xFileName);
static QString getDisplayTime(uint xTimeMSec);
static uint getTimeMSec(const QString &xFileName);
Expand All @@ -22,7 +30,11 @@ class Util
Q_INVOKABLE static QString getCacheLocation();
Q_INVOKABLE static QString getMusicLocation();
Q_INVOKABLE static QString getHomeLocation();
Q_INVOKABLE static QStringList getAndroidStorageLocations();
Q_INVOKABLE static QString appendFile(QString &xString);

private:
explicit Util(QObject *parent = nullptr);
};

#endif // UTIL_H

0 comments on commit 19f9591

Please sign in to comment.