[app] Create sample book on the first time run
This commit is contained in:
parent
85473cb2b4
commit
78372a0963
7 changed files with 142 additions and 58 deletions
|
@ -85,6 +85,10 @@ formats.files = data/formats/*
|
|||
formats.path = $$TARGET_DEFAULT_DATA_DIR/formats
|
||||
INSTALLS += formats
|
||||
|
||||
samples.files = data/samples/*
|
||||
samples.path = $$TARGET_DEFAULT_DATA_DIR/samples
|
||||
INSTALLS += samples
|
||||
|
||||
INCLUDEPATH += \
|
||||
src \
|
||||
$$HARBOUR_INCLUDE_DIR \
|
||||
|
|
BIN
app/data/samples/welcome.fb2.zip
Normal file
BIN
app/data/samples/welcome.fb2.zip
Normal file
Binary file not shown.
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2018 Jolla Ltd.
|
||||
* Copyright (C) 2015-2018 Slava Monich <slava.monich@jolla.com>
|
||||
* Copyright (C) 2015-2019 Jolla Ltd.
|
||||
* Copyright (C) 2015-2019 Slava Monich <slava.monich@jolla.com>
|
||||
*
|
||||
* You may use this file under the terms of the BSD license as follows:
|
||||
*
|
||||
|
@ -8,15 +8,15 @@
|
|||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Jolla Ltd nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the names of the copyright holders nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
|
@ -47,6 +47,7 @@
|
|||
#define KEY_PAGE_DETAILS "pageDetails"
|
||||
#define KEY_PAGE_DETAILS_FIXED "pageDetailsFixed"
|
||||
#define KEY_TURN_PAGE_BY_TAP "turnPageByTap"
|
||||
#define KEY_SAMPLE_BOOK_COPIED "sampleBookCopied"
|
||||
#define KEY_CURRENT_BOOK "currentBook"
|
||||
#define KEY_CURRENT_FOLDER "currentFolder"
|
||||
#define KEY_REMOVABLE_ROOT "removableRoot"
|
||||
|
@ -60,6 +61,7 @@
|
|||
#define DEFAULT_PAGE_DETAILS 0
|
||||
#define DEFAULT_PAGE_DETAILS_FIXED false
|
||||
#define DEFAULT_TURN_PAGE_BY_TAP false
|
||||
#define DEFAULT_SAMPLE_BOOK_COPIED false
|
||||
#define DEFAULT_CURRENT_BOOK QString()
|
||||
#define DEFAULT_CURRENT_FOLDER QString()
|
||||
#define DEFAULT_REMOVABLE_ROOT "Books"
|
||||
|
@ -240,6 +242,7 @@ public:
|
|||
MGConfItem* iPageDetailsFixedConf;
|
||||
MGConfItem* iTurnPageByTapConf;
|
||||
MGConfItem* iInvertColorsConf;
|
||||
MGConfItem* iSampleBookCopiedConf;
|
||||
MGConfItem* iKeepDisplayOnConf;
|
||||
MGConfItem* iVolumeUpActionConf;
|
||||
MGConfItem* iVolumeDownActionConf;
|
||||
|
@ -263,6 +266,7 @@ BooksSettings::Private::Private(BooksSettings* aParent) :
|
|||
iPageDetailsFixedConf(new MGConfItem(DCONF_PATH KEY_PAGE_DETAILS_FIXED, this)),
|
||||
iTurnPageByTapConf(new MGConfItem(DCONF_PATH KEY_TURN_PAGE_BY_TAP, this)),
|
||||
iInvertColorsConf(new MGConfItem(DCONF_PATH KEY_INVERT_COLORS, this)),
|
||||
iSampleBookCopiedConf(new MGConfItem(DCONF_PATH KEY_SAMPLE_BOOK_COPIED, this)),
|
||||
iKeepDisplayOnConf(new MGConfItem(DCONF_PATH KEY_KEEP_DISPLAY_ON, this)),
|
||||
iVolumeUpActionConf(new MGConfItem(DCONF_PATH KEY_VOLUME_UP_ACTION, this)),
|
||||
iVolumeDownActionConf(new MGConfItem(DCONF_PATH KEY_VOLUME_DOWN_ACTION, this)),
|
||||
|
@ -281,6 +285,7 @@ BooksSettings::Private::Private(BooksSettings* aParent) :
|
|||
connect(iTurnPageByTapConf, SIGNAL(valueChanged()), iParent, SIGNAL(turnPageByTapChanged()));
|
||||
connect(iInvertColorsConf, SIGNAL(valueChanged()), iParent, SIGNAL(invertColorsChanged()));
|
||||
connect(iInvertColorsConf, SIGNAL(valueChanged()), iParent, SIGNAL(pageBackgroundColorChanged()));
|
||||
connect(iSampleBookCopiedConf, SIGNAL(valueChanged()), iParent, SIGNAL(sampleBookCopiedChanged()));
|
||||
connect(iKeepDisplayOnConf, SIGNAL(valueChanged()), iParent, SIGNAL(keepDisplayOnChanged()));
|
||||
connect(iVolumeUpActionConf, SIGNAL(valueChanged()), iParent, SIGNAL(volumeUpActionChanged()));
|
||||
connect(iVolumeDownActionConf, SIGNAL(valueChanged()), iParent, SIGNAL(volumeDownActionChanged()));
|
||||
|
@ -586,6 +591,19 @@ BooksSettings::setInvertColors(
|
|||
iPrivate->iInvertColorsConf->set(aValue);
|
||||
}
|
||||
|
||||
bool
|
||||
BooksSettings::sampleBookCopied() const
|
||||
{
|
||||
return iPrivate->iSampleBookCopiedConf->value(DEFAULT_SAMPLE_BOOK_COPIED).toBool();
|
||||
}
|
||||
|
||||
void
|
||||
BooksSettings::setSampleBookCopied()
|
||||
{
|
||||
HDEBUG("");
|
||||
iPrivate->iSampleBookCopiedConf->set(true);
|
||||
}
|
||||
|
||||
bool
|
||||
BooksSettings::keepDisplayOn() const
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2018 Jolla Ltd.
|
||||
* Copyright (C) 2015-2018 Slava Monich <slava.monich@jolla.com>
|
||||
* Copyright (C) 2015-2019 Jolla Ltd.
|
||||
* Copyright (C) 2015-2019 Slava Monich <slava.monich@jolla.com>
|
||||
*
|
||||
* You may use this file under the terms of the BSD license as follows:
|
||||
*
|
||||
|
@ -8,15 +8,15 @@
|
|||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Jolla Ltd nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the names of the copyright holders nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
|
@ -51,6 +51,7 @@ class BooksSettings : public QObject
|
|||
Q_PROPERTY(bool pageDetailsFixed READ pageDetailsFixed WRITE setPageDetailsFixed NOTIFY pageDetailsFixedChanged)
|
||||
Q_PROPERTY(bool turnPageByTap READ turnPageByTap WRITE setTurnPageByTap NOTIFY turnPageByTapChanged)
|
||||
Q_PROPERTY(bool invertColors READ invertColors WRITE setInvertColors NOTIFY invertColorsChanged)
|
||||
Q_PROPERTY(bool sampleBookCopied READ sampleBookCopied NOTIFY sampleBookCopiedChanged)
|
||||
Q_PROPERTY(bool keepDisplayOn READ keepDisplayOn WRITE setKeepDisplayOn NOTIFY keepDisplayOnChanged)
|
||||
Q_PROPERTY(int volumeUpAction READ volumeUpAction WRITE setVolumeUpAction NOTIFY volumeUpActionChanged)
|
||||
Q_PROPERTY(int volumeDownAction READ volumeDownAction WRITE setVolumeDownAction NOTIFY volumeDownActionChanged)
|
||||
|
@ -93,6 +94,8 @@ public:
|
|||
Q_INVOKABLE bool increaseFontSize();
|
||||
Q_INVOKABLE bool decreaseFontSize();
|
||||
|
||||
shared_ptr<ZLTextStyle> textStyle(int aFontSizeAdjust) const;
|
||||
|
||||
int fontSize() const;
|
||||
void setFontSize(int aValue);
|
||||
|
||||
|
@ -105,11 +108,12 @@ public:
|
|||
bool turnPageByTap() const;
|
||||
void setTurnPageByTap(bool aValue);
|
||||
|
||||
shared_ptr<ZLTextStyle> textStyle(int aFontSizeAdjust) const;
|
||||
|
||||
bool invertColors() const;
|
||||
void setInvertColors(bool aValue);
|
||||
|
||||
bool sampleBookCopied() const;
|
||||
void setSampleBookCopied();
|
||||
|
||||
bool keepDisplayOn() const;
|
||||
void setKeepDisplayOn(bool aValue);
|
||||
|
||||
|
@ -141,6 +145,7 @@ Q_SIGNALS:
|
|||
void pageDetailsFixedChanged();
|
||||
void turnPageByTapChanged();
|
||||
void invertColorsChanged();
|
||||
void sampleBookCopiedChanged();
|
||||
void keepDisplayOnChanged();
|
||||
void volumeUpActionChanged();
|
||||
void volumeDownActionChanged();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2018 Jolla Ltd.
|
||||
* Copyright (C) 2015-2018 Slava Monich <slava.monich@jolla.com>
|
||||
* Copyright (C) 2015-2019 Jolla Ltd.
|
||||
* Copyright (C) 2015-2019 Slava Monich <slava.monich@jolla.com>
|
||||
*
|
||||
* You may use this file under the terms of the BSD license as follows:
|
||||
*
|
||||
|
@ -8,15 +8,15 @@
|
|||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Jolla Ltd nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the names of the copyright holders nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
|
@ -297,6 +297,7 @@ public:
|
|||
Private(BooksStorageManager* aParent);
|
||||
~Private();
|
||||
|
||||
BooksStorage internalStorage() const;
|
||||
int findDevice(QString aDevice) const;
|
||||
int findPath(QString aPath, QString* aRelPath) const;
|
||||
bool scanMounts();
|
||||
|
@ -422,6 +423,18 @@ BooksStorageManager::Private::~Private()
|
|||
}
|
||||
}
|
||||
|
||||
BooksStorage BooksStorageManager::Private::internalStorage() const
|
||||
{
|
||||
const int n = iStorageList.count();
|
||||
for (int i = 0; i < n; i++) {
|
||||
BooksStorage storage(iStorageList.at(i));
|
||||
if (storage.isInternal()) {
|
||||
return storage;
|
||||
}
|
||||
}
|
||||
return BooksStorage();
|
||||
}
|
||||
|
||||
int BooksStorageManager::Private::findDevice(QString aDevice) const
|
||||
{
|
||||
const int n = iStorageList.count();
|
||||
|
@ -614,6 +627,11 @@ QList<BooksStorage> BooksStorageManager::storageList() const
|
|||
return iPrivate->iStorageList;
|
||||
}
|
||||
|
||||
BooksStorage BooksStorageManager::internalStorage() const
|
||||
{
|
||||
return iPrivate->internalStorage();
|
||||
}
|
||||
|
||||
BooksStorage BooksStorageManager::storageForDevice(QString aDevice) const
|
||||
{
|
||||
int index = iPrivate->findDevice(aDevice);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2016 Jolla Ltd.
|
||||
* Contact: Slava Monich <slava.monich@jolla.com>
|
||||
* Copyright (C) 2015-2019 Jolla Ltd.
|
||||
* Copyright (C) 2015-2019 Slava Monich <slava.monich@jolla.com>
|
||||
*
|
||||
* You may use this file under the terms of the BSD license as follows:
|
||||
*
|
||||
|
@ -8,15 +8,15 @@
|
|||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Jolla Ltd nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the names of the copyright holders nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
|
@ -97,6 +97,7 @@ public:
|
|||
|
||||
int count() const;
|
||||
QList<BooksStorage> storageList() const;
|
||||
BooksStorage internalStorage() const;
|
||||
BooksStorage storageForDevice(QString aDevice) const;
|
||||
BooksStorage storageForPath(QString aPath, QString* aRelPath = NULL) const;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2018 Jolla Ltd.
|
||||
* Contact: Slava Monich <slava.monich@jolla.com>
|
||||
* Copyright (C) 2015-2019 Jolla Ltd.
|
||||
* Copyright (C) 2015-2019 Slava Monich <slava.monich@jolla.com>
|
||||
*
|
||||
* You may use this file under the terms of the BSD license as follows:
|
||||
*
|
||||
|
@ -8,15 +8,15 @@
|
|||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Jolla Ltd nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the names of the copyright holders nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
|
@ -63,6 +63,7 @@
|
|||
#include <QQmlContext>
|
||||
#include <QScreen>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <execinfo.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
|
@ -188,7 +189,44 @@ bool ZLibrary::init(int& aArgc, char** &aArgv)
|
|||
// Doing it the other way around will result in two instances of
|
||||
// BooksStorageManager being created :)
|
||||
QSharedPointer<BooksSettings> settings = BooksSettings::sharedInstance();
|
||||
BooksStorageManager::instance();
|
||||
BooksStorageManager* storageManager = BooksStorageManager::instance();
|
||||
|
||||
// Copy sample book (no more than once)
|
||||
if (!settings->sampleBookCopied()) {
|
||||
BooksStorage internal = storageManager->internalStorage();
|
||||
if (internal.isValid()) {
|
||||
QDir booksDir = internal.booksDir();
|
||||
if (!booksDir.exists()) {
|
||||
HDEBUG("Creating" << qPrintable(booksDir.path()));
|
||||
if (!booksDir.mkpath(".")) {
|
||||
HWARN("Failed to create" << qPrintable(booksDir.path()));
|
||||
}
|
||||
}
|
||||
// 2 files (. and ..) are always there
|
||||
if (booksDir.count() > 2) {
|
||||
// Don't copy sample book, something is already there
|
||||
HDEBUG("Sample is not needed (" << booksDir.count() << " files)");
|
||||
settings->setSampleBookCopied();
|
||||
} else {
|
||||
HDEBUG(qPrintable(booksDir.path()) << "is empty");
|
||||
const QString sampleBook("welcome.fb2.zip");
|
||||
const QString src(QString((ourZLibraryDirectory + "/samples/").c_str()) + sampleBook);
|
||||
const QString dest(booksDir.path() + "/" + sampleBook);
|
||||
QByteArray oldp(src.toLocal8Bit());
|
||||
QByteArray newp(dest.toLocal8Bit());
|
||||
int err = link(oldp.data(), newp.data());
|
||||
if (!err) {
|
||||
HDEBUG("Linked" << newp << "->" << oldp);
|
||||
settings->setSampleBookCopied();
|
||||
} else if (QFile::copy(src, dest)) {
|
||||
HDEBUG("Copied" << oldp << "to" << newp);
|
||||
settings->setSampleBookCopied();
|
||||
} else {
|
||||
HWARN("Failed to copy" << oldp << "to" << newp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue