[app] Create sample book on the first time run

This commit is contained in:
Slava Monich 2019-04-01 03:31:55 +03:00
parent 85473cb2b4
commit 78372a0963
7 changed files with 142 additions and 58 deletions

View file

@ -85,6 +85,10 @@ formats.files = data/formats/*
formats.path = $$TARGET_DEFAULT_DATA_DIR/formats formats.path = $$TARGET_DEFAULT_DATA_DIR/formats
INSTALLS += formats INSTALLS += formats
samples.files = data/samples/*
samples.path = $$TARGET_DEFAULT_DATA_DIR/samples
INSTALLS += samples
INCLUDEPATH += \ INCLUDEPATH += \
src \ src \
$$HARBOUR_INCLUDE_DIR \ $$HARBOUR_INCLUDE_DIR \

Binary file not shown.

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2015-2018 Jolla Ltd. * Copyright (C) 2015-2019 Jolla Ltd.
* Copyright (C) 2015-2018 Slava Monich <slava.monich@jolla.com> * Copyright (C) 2015-2019 Slava Monich <slava.monich@jolla.com>
* *
* You may use this file under the terms of the BSD license as follows: * 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 * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* * Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer
* the documentation and/or other materials provided with the * in the documentation and/or other materials provided with the
* distribution. * distribution.
* * Neither the name of Jolla Ltd nor the names of its contributors * 3. Neither the names of the copyright holders nor the names of its
* may be used to endorse or promote products derived from this * contributors may be used to endorse or promote products derived
* software without specific prior written permission. * from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -47,6 +47,7 @@
#define KEY_PAGE_DETAILS "pageDetails" #define KEY_PAGE_DETAILS "pageDetails"
#define KEY_PAGE_DETAILS_FIXED "pageDetailsFixed" #define KEY_PAGE_DETAILS_FIXED "pageDetailsFixed"
#define KEY_TURN_PAGE_BY_TAP "turnPageByTap" #define KEY_TURN_PAGE_BY_TAP "turnPageByTap"
#define KEY_SAMPLE_BOOK_COPIED "sampleBookCopied"
#define KEY_CURRENT_BOOK "currentBook" #define KEY_CURRENT_BOOK "currentBook"
#define KEY_CURRENT_FOLDER "currentFolder" #define KEY_CURRENT_FOLDER "currentFolder"
#define KEY_REMOVABLE_ROOT "removableRoot" #define KEY_REMOVABLE_ROOT "removableRoot"
@ -60,6 +61,7 @@
#define DEFAULT_PAGE_DETAILS 0 #define DEFAULT_PAGE_DETAILS 0
#define DEFAULT_PAGE_DETAILS_FIXED false #define DEFAULT_PAGE_DETAILS_FIXED false
#define DEFAULT_TURN_PAGE_BY_TAP false #define DEFAULT_TURN_PAGE_BY_TAP false
#define DEFAULT_SAMPLE_BOOK_COPIED false
#define DEFAULT_CURRENT_BOOK QString() #define DEFAULT_CURRENT_BOOK QString()
#define DEFAULT_CURRENT_FOLDER QString() #define DEFAULT_CURRENT_FOLDER QString()
#define DEFAULT_REMOVABLE_ROOT "Books" #define DEFAULT_REMOVABLE_ROOT "Books"
@ -240,6 +242,7 @@ public:
MGConfItem* iPageDetailsFixedConf; MGConfItem* iPageDetailsFixedConf;
MGConfItem* iTurnPageByTapConf; MGConfItem* iTurnPageByTapConf;
MGConfItem* iInvertColorsConf; MGConfItem* iInvertColorsConf;
MGConfItem* iSampleBookCopiedConf;
MGConfItem* iKeepDisplayOnConf; MGConfItem* iKeepDisplayOnConf;
MGConfItem* iVolumeUpActionConf; MGConfItem* iVolumeUpActionConf;
MGConfItem* iVolumeDownActionConf; MGConfItem* iVolumeDownActionConf;
@ -263,6 +266,7 @@ BooksSettings::Private::Private(BooksSettings* aParent) :
iPageDetailsFixedConf(new MGConfItem(DCONF_PATH KEY_PAGE_DETAILS_FIXED, this)), iPageDetailsFixedConf(new MGConfItem(DCONF_PATH KEY_PAGE_DETAILS_FIXED, this)),
iTurnPageByTapConf(new MGConfItem(DCONF_PATH KEY_TURN_PAGE_BY_TAP, this)), iTurnPageByTapConf(new MGConfItem(DCONF_PATH KEY_TURN_PAGE_BY_TAP, this)),
iInvertColorsConf(new MGConfItem(DCONF_PATH KEY_INVERT_COLORS, 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)), iKeepDisplayOnConf(new MGConfItem(DCONF_PATH KEY_KEEP_DISPLAY_ON, this)),
iVolumeUpActionConf(new MGConfItem(DCONF_PATH KEY_VOLUME_UP_ACTION, this)), iVolumeUpActionConf(new MGConfItem(DCONF_PATH KEY_VOLUME_UP_ACTION, this)),
iVolumeDownActionConf(new MGConfItem(DCONF_PATH KEY_VOLUME_DOWN_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(iTurnPageByTapConf, SIGNAL(valueChanged()), iParent, SIGNAL(turnPageByTapChanged()));
connect(iInvertColorsConf, SIGNAL(valueChanged()), iParent, SIGNAL(invertColorsChanged())); connect(iInvertColorsConf, SIGNAL(valueChanged()), iParent, SIGNAL(invertColorsChanged()));
connect(iInvertColorsConf, SIGNAL(valueChanged()), iParent, SIGNAL(pageBackgroundColorChanged())); connect(iInvertColorsConf, SIGNAL(valueChanged()), iParent, SIGNAL(pageBackgroundColorChanged()));
connect(iSampleBookCopiedConf, SIGNAL(valueChanged()), iParent, SIGNAL(sampleBookCopiedChanged()));
connect(iKeepDisplayOnConf, SIGNAL(valueChanged()), iParent, SIGNAL(keepDisplayOnChanged())); connect(iKeepDisplayOnConf, SIGNAL(valueChanged()), iParent, SIGNAL(keepDisplayOnChanged()));
connect(iVolumeUpActionConf, SIGNAL(valueChanged()), iParent, SIGNAL(volumeUpActionChanged())); connect(iVolumeUpActionConf, SIGNAL(valueChanged()), iParent, SIGNAL(volumeUpActionChanged()));
connect(iVolumeDownActionConf, SIGNAL(valueChanged()), iParent, SIGNAL(volumeDownActionChanged())); connect(iVolumeDownActionConf, SIGNAL(valueChanged()), iParent, SIGNAL(volumeDownActionChanged()));
@ -586,6 +591,19 @@ BooksSettings::setInvertColors(
iPrivate->iInvertColorsConf->set(aValue); 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 bool
BooksSettings::keepDisplayOn() const BooksSettings::keepDisplayOn() const
{ {

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2015-2018 Jolla Ltd. * Copyright (C) 2015-2019 Jolla Ltd.
* Copyright (C) 2015-2018 Slava Monich <slava.monich@jolla.com> * Copyright (C) 2015-2019 Slava Monich <slava.monich@jolla.com>
* *
* You may use this file under the terms of the BSD license as follows: * 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 * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* * Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer
* the documentation and/or other materials provided with the * in the documentation and/or other materials provided with the
* distribution. * distribution.
* * Neither the name of Jolla Ltd nor the names of its contributors * 3. Neither the names of the copyright holders nor the names of its
* may be used to endorse or promote products derived from this * contributors may be used to endorse or promote products derived
* software without specific prior written permission. * from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "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 pageDetailsFixed READ pageDetailsFixed WRITE setPageDetailsFixed NOTIFY pageDetailsFixedChanged)
Q_PROPERTY(bool turnPageByTap READ turnPageByTap WRITE setTurnPageByTap NOTIFY turnPageByTapChanged) Q_PROPERTY(bool turnPageByTap READ turnPageByTap WRITE setTurnPageByTap NOTIFY turnPageByTapChanged)
Q_PROPERTY(bool invertColors READ invertColors WRITE setInvertColors NOTIFY invertColorsChanged) 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(bool keepDisplayOn READ keepDisplayOn WRITE setKeepDisplayOn NOTIFY keepDisplayOnChanged)
Q_PROPERTY(int volumeUpAction READ volumeUpAction WRITE setVolumeUpAction NOTIFY volumeUpActionChanged) Q_PROPERTY(int volumeUpAction READ volumeUpAction WRITE setVolumeUpAction NOTIFY volumeUpActionChanged)
Q_PROPERTY(int volumeDownAction READ volumeDownAction WRITE setVolumeDownAction NOTIFY volumeDownActionChanged) Q_PROPERTY(int volumeDownAction READ volumeDownAction WRITE setVolumeDownAction NOTIFY volumeDownActionChanged)
@ -93,6 +94,8 @@ public:
Q_INVOKABLE bool increaseFontSize(); Q_INVOKABLE bool increaseFontSize();
Q_INVOKABLE bool decreaseFontSize(); Q_INVOKABLE bool decreaseFontSize();
shared_ptr<ZLTextStyle> textStyle(int aFontSizeAdjust) const;
int fontSize() const; int fontSize() const;
void setFontSize(int aValue); void setFontSize(int aValue);
@ -105,11 +108,12 @@ public:
bool turnPageByTap() const; bool turnPageByTap() const;
void setTurnPageByTap(bool aValue); void setTurnPageByTap(bool aValue);
shared_ptr<ZLTextStyle> textStyle(int aFontSizeAdjust) const;
bool invertColors() const; bool invertColors() const;
void setInvertColors(bool aValue); void setInvertColors(bool aValue);
bool sampleBookCopied() const;
void setSampleBookCopied();
bool keepDisplayOn() const; bool keepDisplayOn() const;
void setKeepDisplayOn(bool aValue); void setKeepDisplayOn(bool aValue);
@ -141,6 +145,7 @@ Q_SIGNALS:
void pageDetailsFixedChanged(); void pageDetailsFixedChanged();
void turnPageByTapChanged(); void turnPageByTapChanged();
void invertColorsChanged(); void invertColorsChanged();
void sampleBookCopiedChanged();
void keepDisplayOnChanged(); void keepDisplayOnChanged();
void volumeUpActionChanged(); void volumeUpActionChanged();
void volumeDownActionChanged(); void volumeDownActionChanged();

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2015-2018 Jolla Ltd. * Copyright (C) 2015-2019 Jolla Ltd.
* Copyright (C) 2015-2018 Slava Monich <slava.monich@jolla.com> * Copyright (C) 2015-2019 Slava Monich <slava.monich@jolla.com>
* *
* You may use this file under the terms of the BSD license as follows: * 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 * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* * Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer
* the documentation and/or other materials provided with the * in the documentation and/or other materials provided with the
* distribution. * distribution.
* * Neither the name of Jolla Ltd nor the names of its contributors * 3. Neither the names of the copyright holders nor the names of its
* may be used to endorse or promote products derived from this * contributors may be used to endorse or promote products derived
* software without specific prior written permission. * from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -297,6 +297,7 @@ public:
Private(BooksStorageManager* aParent); Private(BooksStorageManager* aParent);
~Private(); ~Private();
BooksStorage internalStorage() const;
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();
@ -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 int BooksStorageManager::Private::findDevice(QString aDevice) const
{ {
const int n = iStorageList.count(); const int n = iStorageList.count();
@ -614,6 +627,11 @@ QList<BooksStorage> BooksStorageManager::storageList() const
return iPrivate->iStorageList; return iPrivate->iStorageList;
} }
BooksStorage BooksStorageManager::internalStorage() const
{
return iPrivate->internalStorage();
}
BooksStorage BooksStorageManager::storageForDevice(QString aDevice) const BooksStorage BooksStorageManager::storageForDevice(QString aDevice) const
{ {
int index = iPrivate->findDevice(aDevice); int index = iPrivate->findDevice(aDevice);

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2015-2016 Jolla Ltd. * Copyright (C) 2015-2019 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com> * Copyright (C) 2015-2019 Slava Monich <slava.monich@jolla.com>
* *
* You may use this file under the terms of the BSD license as follows: * 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 * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* * Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer
* the documentation and/or other materials provided with the * in the documentation and/or other materials provided with the
* distribution. * distribution.
* * Neither the name of Jolla Ltd nor the names of its contributors * 3. Neither the names of the copyright holders nor the names of its
* may be used to endorse or promote products derived from this * contributors may be used to endorse or promote products derived
* software without specific prior written permission. * from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -97,6 +97,7 @@ public:
int count() const; int count() const;
QList<BooksStorage> storageList() const; QList<BooksStorage> storageList() const;
BooksStorage internalStorage() const;
BooksStorage storageForDevice(QString aDevice) const; BooksStorage storageForDevice(QString aDevice) const;
BooksStorage storageForPath(QString aPath, QString* aRelPath = NULL) const; BooksStorage storageForPath(QString aPath, QString* aRelPath = NULL) const;

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2015-2018 Jolla Ltd. * Copyright (C) 2015-2019 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com> * Copyright (C) 2015-2019 Slava Monich <slava.monich@jolla.com>
* *
* You may use this file under the terms of the BSD license as follows: * 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 * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* * Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer
* the documentation and/or other materials provided with the * in the documentation and/or other materials provided with the
* distribution. * distribution.
* * Neither the name of Jolla Ltd nor the names of its contributors * 3. Neither the names of the copyright holders nor the names of its
* may be used to endorse or promote products derived from this * contributors may be used to endorse or promote products derived
* software without specific prior written permission. * from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -63,6 +63,7 @@
#include <QQmlContext> #include <QQmlContext>
#include <QScreen> #include <QScreen>
#include <unistd.h>
#include <execinfo.h> #include <execinfo.h>
#include <dlfcn.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 // Doing it the other way around will result in two instances of
// BooksStorageManager being created :) // BooksStorageManager being created :)
QSharedPointer<BooksSettings> settings = BooksSettings::sharedInstance(); 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; return true;
} }