diff --git a/app/app.pro b/app/app.pro index feae011..d960f1c 100644 --- a/app/app.pro +++ b/app/app.pro @@ -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 \ diff --git a/app/data/samples/welcome.fb2.zip b/app/data/samples/welcome.fb2.zip new file mode 100644 index 0000000..fbb2d0e Binary files /dev/null and b/app/data/samples/welcome.fb2.zip differ diff --git a/app/src/BooksSettings.cpp b/app/src/BooksSettings.cpp index d1cce85..4660570 100644 --- a/app/src/BooksSettings.cpp +++ b/app/src/BooksSettings.cpp @@ -1,6 +1,6 @@ /* - * Copyright (C) 2015-2018 Jolla Ltd. - * Copyright (C) 2015-2018 Slava Monich + * Copyright (C) 2015-2019 Jolla Ltd. + * Copyright (C) 2015-2019 Slava Monich * * 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 { diff --git a/app/src/BooksSettings.h b/app/src/BooksSettings.h index 36588f9..ff67c31 100644 --- a/app/src/BooksSettings.h +++ b/app/src/BooksSettings.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2015-2018 Jolla Ltd. - * Copyright (C) 2015-2018 Slava Monich + * Copyright (C) 2015-2019 Jolla Ltd. + * Copyright (C) 2015-2019 Slava Monich * * 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 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 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(); diff --git a/app/src/BooksStorage.cpp b/app/src/BooksStorage.cpp index a89953a..805ad8f 100644 --- a/app/src/BooksStorage.cpp +++ b/app/src/BooksStorage.cpp @@ -1,6 +1,6 @@ /* - * Copyright (C) 2015-2018 Jolla Ltd. - * Copyright (C) 2015-2018 Slava Monich + * Copyright (C) 2015-2019 Jolla Ltd. + * Copyright (C) 2015-2019 Slava Monich * * 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 BooksStorageManager::storageList() const return iPrivate->iStorageList; } +BooksStorage BooksStorageManager::internalStorage() const +{ + return iPrivate->internalStorage(); +} + BooksStorage BooksStorageManager::storageForDevice(QString aDevice) const { int index = iPrivate->findDevice(aDevice); diff --git a/app/src/BooksStorage.h b/app/src/BooksStorage.h index 47af8be..f5d0170 100644 --- a/app/src/BooksStorage.h +++ b/app/src/BooksStorage.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2015-2016 Jolla Ltd. - * Contact: Slava Monich + * Copyright (C) 2015-2019 Jolla Ltd. + * Copyright (C) 2015-2019 Slava Monich * * 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 storageList() const; + BooksStorage internalStorage() const; BooksStorage storageForDevice(QString aDevice) const; BooksStorage storageForPath(QString aPath, QString* aRelPath = NULL) const; diff --git a/app/src/ZLibrary.cpp b/app/src/ZLibrary.cpp index 7c03558..1d9015a 100644 --- a/app/src/ZLibrary.cpp +++ b/app/src/ZLibrary.cpp @@ -1,6 +1,6 @@ /* - * Copyright (C) 2015-2018 Jolla Ltd. - * Contact: Slava Monich + * Copyright (C) 2015-2019 Jolla Ltd. + * Copyright (C) 2015-2019 Slava Monich * * 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 #include +#include #include #include @@ -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 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; }