#include "platform.h"
#include "settings.h"
-AdopterWindow::AdopterWindow(QWidget *parent): QMainWindow(parent), bookView(0)
+AdopterWindow::AdopterWindow(QWidget *parent):
+ QMainWindow(parent), bookView(0), grabbingVolumeKeys(false)
{
TRACE;
#endif // Q_OS_SYMBIAN
// Monitor settings
- Settings *settings = Settings::instance();
- connect(settings, SIGNAL(valueChanged(const QString &)),
+ connect(Settings::instance(), SIGNAL(valueChanged(const QString &)),
this, SLOT(onSettingsChanged(const QString &)));
- settings->setValue("usevolumekeys", settings->value("usevolumekeys"));
}
void AdopterWindow::takeChildren(BookView *view, const QList<QWidget *> &others)
void AdopterWindow::onSettingsChanged(const QString &key)
{
- TRACE;
if (key == "usevolumekeys") {
- qDebug() << key;
- grabVolumeKeys(Settings::instance()->value(key).toBool());
+ bool grab = Settings::instance()->value(key, false).toBool();
+ qDebug() << "AdopterWindow::onSettingsChanged: usevolumekeys" << grab;
+ grabVolumeKeys(grab);
}
}
bookmarkImage = QImage(":/icons/bookmark.png");
// Handle settings changes, force handling initial settings
- Settings *s = Settings::instance();
- connect(s, SIGNAL(valueChanged(const QString &)),
+ connect(Settings::instance(), SIGNAL(valueChanged(const QString &)),
this, SLOT(onSettingsChanged(const QString &)));
- s->setValue("zoom", s->value("zoom", 160));
- s->setValue("font", s->value("font", Platform::instance()->defaultFont()));
- s->setValue("scheme", s->value("scheme", "default"));
- s->setValue("usevolumekeys", s->value("usevolumekeys", false));
setBook(0);
// Enable kinetic scrolling
void BookView::onSettingsChanged(const QString &key)
{
- TRACE;
- qDebug() << key << Settings::instance()->value(key);
+ Settings *s = Settings::instance();
+ Platform *p = Platform::instance();
if (key == "zoom") {
- setZoomFactor(Settings::instance()->value(key).toFloat() / 100.);
+ int value = s->value(key, p->defaultZoom()).toInt();
+ qDebug() << "BookView::onSettingsChanged: zoom" << value;
+ setZoomFactor(value / 100.);
}
else if (key == "font") {
- QString face = Settings::instance()->value(key).toString();
+ QString face = s->value(key, p->defaultFont()).toString();
+ qDebug() << "BookView::onSettingsChanged: font" << face;
settings()->setFontFamily(QWebSettings::StandardFont, face);
}
else if (key == "scheme") {
(scheme != "default")) {
scheme = "default";
}
+ qDebug() << "BookView::onSettingsChanged: scheme" << scheme;
QFile script(":/styles/" + scheme + ".js");
script.open(QFile::ReadOnly);
QString scriptText = script.readAll();
script.close();
- QVariant ret = frame->evaluateJavaScript(scriptText);
+ (void)frame->evaluateJavaScript(scriptText);
}
else if (key == "usevolumekeys") {
- grabVolumeKeys(Settings::instance()->value(key).toBool());
+ bool grab = s->value(key, false).toBool();
+ qDebug() << "BookView::onSettingsChanged: usevolumekeys" << grab;
+ grabVolumeKeys(grab);
}
}
a.processEvents();
#endif
- // Create main window, run event loop
- {
- MainWindow w;
+ // Create main window, re-apply settings, run event loop
+ MainWindow *mainWindow = new MainWindow();
+ settings->apply();
+ mainWindow->initialize();
#ifdef Q_OS_SYMBIAN
- splash->close();
- splash->deleteLater();
+ splash->close();
+ splash->deleteLater();
#endif
- ret = a.exec();
- }
+ ret = a.exec();
+ delete mainWindow;
// Re-start application if event loop exit code was 1000
if (ret == 1000) {
connect(library, SIGNAL(upgrading(const QString &)),
this, SLOT(onUpgrading(const QString &)));
connect(library, SIGNAL(endUpgrade()), this, SLOT(onEndUpgrade()));
-#ifndef Q_OS_SYMBIAN
- connect(library, SIGNAL(beginLoad(int)), this, SLOT(onBeginLoad(int)));
- connect(library, SIGNAL(loading(const QString &)),
- this, SLOT(onLoading(const QString &)));
- connect(library, SIGNAL(endLoad()), this, SLOT(onEndLoad()));
-#endif
- library->upgrade();
- library->load();
-
- // Load book on command line, or load last read book, or load default book
- if (QCoreApplication::arguments().size() == 2) {
- QString path = QCoreApplication::arguments()[1];
- library->add(path);
- QModelIndex index = library->find(path);
- if (index.isValid()) {
- library->setNowReading(index);
- }
- } else {
- QModelIndex index = library->nowReading();
- if (index.isValid()) {
- library->setNowReading(index);
- } else {
- if (!library->rowCount()) {
- library->add(":/books/2BR02B.epub");
- }
- library->setNowReading(library->index(0));
- }
- }
// Handle loading book parts
connect(view, SIGNAL(partLoadStart(int)), this, SLOT(onPartLoadStart()));
connect(fullScreenWindow, SIGNAL(restore()), this, SLOT(showRegular()));
// Handle settings changes
- Settings *settings = Settings::instance();
- connect(settings, SIGNAL(valueChanged(const QString &)),
+ connect(Settings::instance(), SIGNAL(valueChanged(const QString &)),
this, SLOT(onSettingsChanged(const QString &)));
- settings->setValue("orientation", settings->value("orientation"));
- settings->setValue("lightson", settings->value("lightson"));
// Handle book view buttons
connect(nextButton, SIGNAL(triggered()), this, SLOT(goToNextPage()));
#endif
}
+void MainWindow::initialize()
+{
+ TRACE;
+ Library *library = Library::instance();
+
+ // Upgrade library if needed, then load it
+ library->upgrade();
+ library->load();
+
+ // Load book on command line, or load last read book, or load default book
+ if (QCoreApplication::arguments().size() == 2) {
+ QString path = QCoreApplication::arguments()[1];
+ library->add(path);
+ QModelIndex index = library->find(path);
+ if (index.isValid()) {
+ library->setNowReading(index);
+ }
+ } else {
+ QModelIndex index = library->nowReading();
+ if (index.isValid()) {
+ library->setNowReading(index);
+ } else {
+ if (!library->rowCount()) {
+ library->add(":/books/2BR02B.epub");
+ }
+ library->setNowReading(library->index(0));
+ }
+ }
+}
+
void MainWindow::onCurrentBookChanged()
{
TRACE;
show();
#if defined(Q_OS_SYMBIAN)
activateWindow();
-#elif defined(Q_WS_MAEMO_5)
- // FIXME: This is ugly.
- // view->restoreLastBookmark();
#endif
progress->flash();
nextButton->flash();
void MainWindow::onSettingsChanged(const QString &key)
{
- TRACE;
- qDebug() << key;
#if defined(Q_WS_MAEMO_5)
if (key == "orientation") {
- QString value = Settings::instance()->value(key).toString();
+ QString value = Settings::instance()->value(key,
+ Platform::instance()->defaultOrientation()).toString();
+ qDebug() << "MainWindow::onSettingsChanged: orientation" << value;
if (value == "portrait") {
setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);
setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
}
} else if (key == "lightson") {
bool enable = Settings::instance()->value(key, false).toBool();
+ qDebug() << "MainWindow::onSettingsChanged: lightson" << enable;
killTimer(preventBlankingTimer);
if (enable) {
preventBlankingTimer = startTimer(29 * 1000);
public:
MainWindow(QWidget *parent = 0);
+ void initialize();
public slots:
void showLibrary();
#include <QSettings>
+#include <QString>
+#include <QStringList>
#include "settings.h"
+#include "trace.h"
static Settings *theInstance;
-Settings::Settings(QObject *parent) :
- QObject(parent)
+Settings::Settings(): QObject(0)
{
}
QSettings s;
return s.value(QString("settings/") + key, defaultValue);
}
+
+void Settings::apply()
+{
+ TRACE;
+ QSettings s;
+ foreach (QString key, s.allKeys()) {
+ if (key.startsWith("settings/")) {
+ key = key.mid(9);
+ setValue(key, value(key));
+ }
+ }
+}
Q_OBJECT
public:
- explicit Settings(QObject *parent = 0);
static Settings *instance();
static void close();
QVariant value(const QString &key, const QVariant &defaultValue = QVariant())
const;
void setValue(const QString &key, const QVariant &value);
+ void apply();
signals:
- void valueChanged(const QString &name);
+ void valueChanged(const QString &key);
-public slots:
+protected:
+ Settings();
};
#endif // SETTINGS_H
{
return QDir::home().absoluteFilePath(DORIAN_LOG);
}
+
+int Platform::defaultZoom()
+{
+ return 150;
+}
+
+QString Platform::defaultOrientation()
+{
+#ifdef Q_OS_SYMBIAN
+ return QString("portrait");
+#else
+ return QString("landscape");
+#endif
+}
QString version();
QString downloadDir();
QString defaultFont();
+ int defaultZoom();
+ QString defaultOrientation();
void information(const QString &label, QWidget *parent = 0);
void showBusy(QWidget *w, bool isBusy);
QString traceFileName();
#include "trace.h"
#ifdef Q_OS_SYMBIAN
-#include "flickcharm.h"
-#endif
-
-#ifdef Q_OS_SYMBIAN
-const char *DEFAULT_ORIENTATION = "portrait";
-#else
-const char *DEFAULT_ORIENTATION = "landscape";
+# include "flickcharm.h"
#endif
const int ZOOM_MIN = 75;
setWindowTitle("Settings");
Settings *settings = Settings::instance();
+ Platform *platform = Platform::instance();
+
QScrollArea *scroller = new QScrollArea(this);
#if defined(Q_WS_MAEMO_5)
scroller->setProperty("FingerScrollable", true);
layout->addWidget(grabVolume);
grabVolume->setChecked(settings->value("usevolumekeys", false).toBool());
- int zoom = Settings::instance()->value("zoom").toInt();
+ int zoom = settings->value("zoom", platform->defaultZoom()).toInt();
if (zoom < ZOOM_MIN) {
zoom = ZOOM_MIN;
} else if (zoom > ZOOM_MAX) {
QLabel *fontLabel = new QLabel(tr("Font:"), contents);
layout->addWidget(fontLabel);
- QString defaultFamily = fontLabel->fontInfo().family();
- QString family =
- Settings::instance()->value("font", defaultFamily).toString();
+ QString family = settings->value("font", platform->defaultFont()).toString();
fontButton = new QFontComboBox(contents);
fontButton->setCurrentFont(QFont(family));
fontButton->setEditable(false);
":/icons/settings-landscape.png");
orientationBox->addStretch();
QString orientation =
- settings->value("orientation", DEFAULT_ORIENTATION).toString();
+ settings->value("orientation", platform->defaultOrientation()).toString();
if (orientation == "portrait") {
orientationBox->toggle(OrientationPortrait);
} else {
return;
}
zoomLabel->setText(tr("Zoom level: %1%").arg(value));
-#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
- // Constant re-scaling of the book view is too much for mobiles
-#else
- Settings::instance()->setValue("zoom", value);
-#endif // Q_WS_MAEMO_5
}
void SettingsWindow::onCurrentFontChanged(const QFont &font)
{
-#ifdef Q_WS_MAEMO_5
Q_UNUSED(font);
-#else
- Settings::instance()->setValue("font", font.family());
-#endif // Q_WS_MAEMO_5
}
void SettingsWindow::onSchemeButtonClicked(int id)
#endif // Q_WS_MAEMO_5
}
-#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
-
void SettingsWindow::closeEvent(QCloseEvent *e)
{
TRACE;
e->accept();
}
-#endif // Q_WS_MAEMO_5 || Q_OS_SYMBIAN
-
void SettingsWindow::onLightsToggled(bool value)
{
Settings::instance()->setValue("lightson", value);
void onGrabVolumeToggled(bool enable);
protected:
-#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
void closeEvent(QCloseEvent *e);
-#endif
private:
QSlider *zoomSlider;