[app] Support new SD-card mount location in Sailfish OS 2.2.0
It used to be mounted at /media and now it's /run/media I need to find a better way to detect removable media.
This commit is contained in:
parent
66aaaffb6b
commit
fbadaf142c
1 changed files with 17 additions and 9 deletions
|
@ -274,7 +274,6 @@ void BooksStorage::set(const BooksStorage& aStorage)
|
||||||
#define STORAGE_SUBSYSTEM "block"
|
#define STORAGE_SUBSYSTEM "block"
|
||||||
#define STORAGE_DISK "disk"
|
#define STORAGE_DISK "disk"
|
||||||
#define STORAGE_PARTITION "partition"
|
#define STORAGE_PARTITION "partition"
|
||||||
#define STORAGE_MOUNT_PREFIX "/media/"
|
|
||||||
|
|
||||||
#define STORAGE_ACTION_ADD "add"
|
#define STORAGE_ACTION_ADD "add"
|
||||||
#define STORAGE_ACTION_REMOVE "remove"
|
#define STORAGE_ACTION_REMOVE "remove"
|
||||||
|
@ -286,10 +285,13 @@ class BooksStorageManager::Private : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
static BooksStorageManager* gInstance;
|
static BooksStorageManager* gInstance;
|
||||||
|
static const QString STORAGE_MOUNT_PREFIX;
|
||||||
|
static const QString STORAGE_MOUNT_PREFIX2;
|
||||||
|
|
||||||
Private(BooksStorageManager* aParent);
|
Private(BooksStorageManager* aParent);
|
||||||
~Private();
|
~Private();
|
||||||
|
|
||||||
|
static bool isMediaMount(QString aPath);
|
||||||
int findDevice(QString aDevice) const;
|
int findDevice(QString aDevice) const;
|
||||||
int findPath(QString aPath, QString* aRelPath) const;
|
int findPath(QString aPath, QString* aRelPath) const;
|
||||||
bool scanMounts();
|
bool scanMounts();
|
||||||
|
@ -312,6 +314,8 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
BooksStorageManager* BooksStorageManager::Private::gInstance = NULL;
|
BooksStorageManager* BooksStorageManager::Private::gInstance = NULL;
|
||||||
|
const QString BooksStorageManager::Private::STORAGE_MOUNT_PREFIX("/media/");
|
||||||
|
const QString BooksStorageManager::Private::STORAGE_MOUNT_PREFIX2("/run/media/");
|
||||||
|
|
||||||
BooksStorageManager::Private::Private(BooksStorageManager* aParent) :
|
BooksStorageManager::Private::Private(BooksStorageManager* aParent) :
|
||||||
QObject(aParent),
|
QObject(aParent),
|
||||||
|
@ -336,17 +340,16 @@ BooksStorageManager::Private::Private(BooksStorageManager* aParent) :
|
||||||
// For some reason QTextStream can't read /proc/mounts line by line
|
// For some reason QTextStream can't read /proc/mounts line by line
|
||||||
QByteArray contents = mounts.readAll();
|
QByteArray contents = mounts.readAll();
|
||||||
QTextStream in(&contents);
|
QTextStream in(&contents);
|
||||||
QString mediaPrefix(STORAGE_MOUNT_PREFIX);
|
|
||||||
while (!in.atEnd()) {
|
while (!in.atEnd()) {
|
||||||
QString line = in.readLine();
|
QString line = in.readLine();
|
||||||
QStringList entries = line.split(' ', QString::SkipEmptyParts);
|
QStringList entries = line.split(' ', QString::SkipEmptyParts);
|
||||||
if (entries.count() > 2) {
|
if (entries.count() > 2) {
|
||||||
QString mount(entries.at(1));
|
const QString mount(entries.at(1));
|
||||||
if (mount == homeMount) {
|
if (mount == homeMount) {
|
||||||
homeDevice = entries.at(0);
|
homeDevice = entries.at(0);
|
||||||
HDEBUG("internal" << homeDevice);
|
HDEBUG("internal" << homeDevice);
|
||||||
} else if (mount.startsWith(mediaPrefix)) {
|
} else if (isMediaMount(mount)) {
|
||||||
QString dev = entries.at(0);
|
const QString dev = entries.at(0);
|
||||||
QString path(mount);
|
QString path(mount);
|
||||||
if (!path.endsWith('/')) path += '/';
|
if (!path.endsWith('/')) path += '/';
|
||||||
path += iSettings->removableRoot();
|
path += iSettings->removableRoot();
|
||||||
|
@ -395,6 +398,12 @@ BooksStorageManager::Private::~Private()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BooksStorageManager::Private::isMediaMount(QString aPath)
|
||||||
|
{
|
||||||
|
return aPath.startsWith(STORAGE_MOUNT_PREFIX) ||
|
||||||
|
aPath.startsWith(STORAGE_MOUNT_PREFIX2);
|
||||||
|
}
|
||||||
|
|
||||||
int BooksStorageManager::Private::findDevice(QString aDevice) const
|
int BooksStorageManager::Private::findDevice(QString aDevice) const
|
||||||
{
|
{
|
||||||
const int n = iStorageList.count();
|
const int n = iStorageList.count();
|
||||||
|
@ -439,14 +448,13 @@ bool BooksStorageManager::Private::scanMounts()
|
||||||
// For some reason QTextStream can't read /proc/mounts line by line
|
// For some reason QTextStream can't read /proc/mounts line by line
|
||||||
QByteArray contents = mounts.readAll();
|
QByteArray contents = mounts.readAll();
|
||||||
QTextStream in(&contents);
|
QTextStream in(&contents);
|
||||||
QString mediaPrefix(STORAGE_MOUNT_PREFIX);
|
|
||||||
while (!in.atEnd()) {
|
while (!in.atEnd()) {
|
||||||
QString line = in.readLine();
|
QString line = in.readLine();
|
||||||
QStringList entries = line.split(' ', QString::SkipEmptyParts);
|
QStringList entries = line.split(' ', QString::SkipEmptyParts);
|
||||||
if (entries.count() > 2) {
|
if (entries.count() > 2) {
|
||||||
QString mount(entries.at(1));
|
const QString mount(entries.at(1));
|
||||||
if (mount.startsWith(mediaPrefix)) {
|
if (isMediaMount(mount)) {
|
||||||
QString dev = entries.at(0);
|
const QString dev = entries.at(0);
|
||||||
int index = findDevice(dev);
|
int index = findDevice(dev);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
QString path = mount;
|
QString path = mount;
|
||||||
|
|
Loading…
Reference in a new issue