Avoid complex types as statics.
authorAkos Polster <akos@pipacs.com>
Mon, 8 Nov 2010 18:47:02 +0000 (19:47 +0100)
committerAkos Polster <akos@pipacs.com>
Mon, 8 Nov 2010 18:47:02 +0000 (19:47 +0100)
20 files changed:
adopterwindow.cpp
bookview.cpp
bookview.h
devtools.cpp
fullscreenwindow.cpp
librarydialog.cpp
main.cpp
mainwindow.cpp
model/bookdb.cpp
model/library.cpp
model/library.h
model/settings.cpp
pkg/changelog
pkg/version.txt
platform.cpp
platform.h
searchresultsdialog.cpp
settingswindow.cpp
widgets/listwindow.cpp
widgets/translucentbutton.cpp

index d553a5c..27d5dbf 100644 (file)
@@ -98,7 +98,7 @@ QAction *AdopterWindow::addToolBarAction(QObject *receiver,
     TRACE;
     qDebug() << "icon" << iconName << "text" << text;
 #ifndef Q_OS_SYMBIAN
-    return toolBar->addAction(QIcon(Platform::icon(iconName)),
+    return toolBar->addAction(QIcon(Platform::instance()->icon(iconName)),
                               text, receiver, member);
 #else
     Q_UNUSED(iconName);
index fcdfd4b..e4b4773 100644 (file)
@@ -62,7 +62,7 @@ BookView::BookView(QWidget *parent): QWebView(parent), contentIndex(-1),
     connect(s, SIGNAL(valueChanged(const QString &)),
             this, SLOT(onSettingsChanged(const QString &)));
     s->setValue("zoom", s->value("zoom", 160));
-    s->setValue("font", s->value("font", Platform::defaultFont()));
+    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);
@@ -201,14 +201,18 @@ void BookView::goToPart(int part, const QString &fragment)
 {
     TRACE;
     if (mBook) {
-        if (part != contentIndex) {
-            qDebug() << "Loading new part" << part;
-            restoreFragmentAfterLoad = true;
-            fragmentAfterLoad = fragment;
-            loadContent(part);
+        if (fragment.isEmpty()) {
+            goToBookmark(Book::Bookmark(part, 0));
         } else {
-            goToFragment(fragment);
-            showProgress();
+            if (part != contentIndex) {
+                qDebug() << "Loading new part" << part;
+                restoreFragmentAfterLoad = true;
+                fragmentAfterLoad = fragment;
+                loadContent(part);
+            } else {
+                goToFragment(fragment);
+                showProgress();
+            }
         }
     }
 }
@@ -220,7 +224,7 @@ void BookView::goToFragment(const QString &fragment)
         QVariant ret = page()->mainFrame()->evaluateJavaScript(
                 QString("window.location='") + fragment + "'");
         qDebug() << ret;
-        setLastBookmark();
+        // FIXME: setLastBookmark();
     }
 }
 
@@ -411,7 +415,7 @@ void BookView::leaveEvent(QEvent *e)
     QWebView::leaveEvent(e);
 }
 
-void BookView::enterEvent(QEvent *e)
+void BookView::resizeEvent(QEvent *e)
 {
     TRACE;
     // Restore position saved at Leave event. This seems to be required,
index e3d6597..e2e1d17 100644 (file)
@@ -91,7 +91,7 @@ protected:
     void timerEvent(QTimerEvent *e);
 #ifdef Q_WS_MAEMO_5
     void leaveEvent(QEvent *e);
-    void enterEvent(QEvent *e);
+    void resizeEvent(QEvent *e);
 #endif // Q_WS_MAEMO_5
 
     /** Load given part. */
index 73ecb0d..d44c0ac 100644 (file)
@@ -57,7 +57,7 @@ void DevTools::onLevelButtonClicked(int level)
 
 void DevTools::onTraceToFileToggled(bool enable)
 {
-    QString name = enable? Platform::traceFileName(): QString();
+    QString name = enable? Platform::instance()->traceFileName(): QString();
     Trace::setFileName(name);
     Settings::instance()->setValue("tracefilename", name);
 }
index f708f53..4aff5d0 100644 (file)
@@ -6,6 +6,7 @@
 
 FullScreenWindow::FullScreenWindow(QWidget *parent): AdopterWindow(parent)
 {
+    TRACE;
     Q_ASSERT(parent);
 #ifdef Q_WS_MAEMO_5
     setAttribute(Qt::WA_Maemo5StackedWindow, true);
@@ -29,6 +30,7 @@ FullScreenWindow::FullScreenWindow(QWidget *parent): AdopterWindow(parent)
 
 void FullScreenWindow::showFullScreen()
 {
+    TRACE;
 #ifdef Q_WS_MAEMO_5
     setAttribute(Qt::WA_Maemo5PortraitOrientation, parentWidget()->
                  testAttribute(Qt::WA_Maemo5PortraitOrientation));
@@ -41,6 +43,7 @@ void FullScreenWindow::showFullScreen()
 
 void FullScreenWindow::resizeEvent(QResizeEvent *e)
 {
+    TRACE;
     Q_UNUSED(e);
     QRect screen = QApplication::desktop()->screenGeometry();
     restoreButton->setGeometry(screen.width() - TranslucentButton::pixels - 9,
index 416e05a..796fad6 100644 (file)
@@ -83,7 +83,8 @@ void LibraryDialog::onAdd()
     // Add book to library
     QModelIndex index = library->find(path);
     if (index.isValid()) {
-        Platform::information(tr("This book is already in the library"), this);
+        Platform::instance()->information(
+                tr("This book is already in the library"), this);
         setSelected(index);
     }
     else {
@@ -217,7 +218,7 @@ void LibraryDialog::onAddFromFolderDone(int added)
 
     progress->reset();
     qDebug() << "LibraryDialog::onRefreshDone:" << msg;
-    Platform::information(msg, this);
+    Platform::instance()->information(msg, this);
 }
 
 void LibraryDialog::onAddFromFolder(const QString &path)
index 8cd02b2..7de740b 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -61,18 +61,20 @@ int main(int argc, char *argv[])
         ret = a.exec();
     }
 
+    // Re-start application if event loop exit code was 1000
+    if (ret == 1000) {
+        Platform::instance()->restart(argv);
+    }
+
     // Release singletons
     Library::close();
     BookDb::close();
     Settings::close();
     Search::close();
+    Platform::close();
 #ifdef Q_OS_SYMBIAN
     MediaKeysObserver::close();
 #endif
 
-    // Re-start application if event loop exit code was 1000
-    if (ret == 1000) {
-        Platform::restart(argv);
-    }
     return ret;
 }
index 72f14ef..3cd94f7 100755 (executable)
@@ -179,6 +179,7 @@ MainWindow::MainWindow(QWidget *parent):
 
 void MainWindow::onCurrentBookChanged()
 {
+    TRACE;
     setCurrentBook(Library::instance()->nowReading());
 }
 
@@ -221,7 +222,7 @@ void MainWindow::showRegular()
     activateWindow();
 #elif defined(Q_WS_MAEMO_5)
     // FIXME: This is ugly.
-    view->restoreLastBookmark();
+    // view->restoreLastBookmark();
 #endif
     progress->flash();
     nextButton->flash();
@@ -342,7 +343,7 @@ void MainWindow::onSettingsChanged(const QString &key)
 void MainWindow::onPartLoadStart()
 {
     TRACE;
-    Platform::showBusy(this, true);
+    Platform::instance()->showBusy(this, true);
 }
 
 void MainWindow::onPartLoadEnd(int index)
@@ -359,14 +360,14 @@ void MainWindow::onPartLoadEnd(int index)
             enableNext = true;
         }
     }
-    Platform::showBusy(this, false);
+    Platform::instance()->showBusy(this, false);
 }
 
 void MainWindow::onAddBookmark(const QString &note)
 {
     TRACE;
     view->addBookmark(note);
-    Platform::information(tr("Bookmarked current position"), this);
+    Platform::instance()->information(tr("Bookmarked current position"), this);
 }
 
 void MainWindow::onGoToBookmark(int index)
@@ -446,6 +447,7 @@ void MainWindow::about()
 {
     Dyalog *aboutDialog = new Dyalog(this, false);
     aboutDialog->setWindowTitle(tr("About Dorian"));
+    QString version = Platform::instance()->version();
     QLabel *label = new QLabel(aboutDialog);
     label->setTextFormat(Qt::RichText);
     label->setOpenExternalLinks(true);
@@ -454,7 +456,7 @@ void MainWindow::about()
         "Akos Polster &lt;akos@pipacs.com&gt;<br>"
         "Licensed under GNU General Public License, Version 3<br>"
         "Source code:<br><a href='https://garage.maemo.org/projects/dorian/'>"
-        "garage.maemo.org/projects/dorian</a>").arg(Platform::version()));
+        "garage.maemo.org/projects/dorian</a>").arg(version));
     aboutDialog->addWidget(label);
     aboutDialog->addStretch();
     aboutDialog->show();
index 0dee139..ce35c7f 100644 (file)
@@ -24,7 +24,7 @@ BookDb::BookDb()
 {
     TRACE;
     bool shouldCreate = false;
-    QFileInfo info(Platform::dbPath());
+    QFileInfo info(Platform::instance()->dbPath());
     if (!info.exists()) {
         QDir dbDir;
         if (!dbDir.mkpath(info.absolutePath())) {
@@ -33,10 +33,10 @@ BookDb::BookDb()
         shouldCreate = true;
     }
     db = QSqlDatabase::addDatabase("QSQLITE");
-    db.setDatabaseName(QDir::toNativeSeparators(Platform::dbPath()));
+    db.setDatabaseName(QDir::toNativeSeparators(Platform::instance()->dbPath()));
     if (!db.open()) {
-        qCritical() << "Could not open" << Platform::dbPath() << ": Error"
-                << db.lastError().text();
+        qCritical() << "Could not open" << Platform::instance()->dbPath()
+                << ": Error" << db.lastError().text();
     }
     if (shouldCreate) {
         create();
index 1a322fc..a14a6f9 100644 (file)
@@ -7,7 +7,7 @@ static const char *DORIAN_VERSION =
 #include "pkg/version.txt"
 ;
 
-Library *Library::mInstance = 0;
+static Library *theInstance = 0;
 
 Library::Library(QObject *parent): QAbstractListModel(parent)
 {
@@ -20,10 +20,10 @@ Library::~Library()
 
 Library *Library::instance()
 {
-    if (!mInstance) {
-        mInstance = new Library();
+    if (!theInstance) {
+        theInstance = new Library();
     }
-    return mInstance;
+    return theInstance;
 }
 
 int Library::rowCount(const QModelIndex &parent) const
@@ -65,8 +65,8 @@ Book *Library::book(const QModelIndex &index)
 
 void Library::close()
 {
-    delete mInstance;
-    mInstance = 0;
+    delete theInstance;
+    theInstance = 0;
 }
 
 void Library::load()
index 0a4a7f3..1df272b 100644 (file)
@@ -49,7 +49,6 @@ private:
     explicit Library(QObject *parent = 0);
     ~Library();
     void clear();
-    static Library *mInstance;
     QList<Book *> mBooks;
     QModelIndex mNowReading;
 };
index 5e853ac..62fdcec 100644 (file)
@@ -2,7 +2,7 @@
 
 #include "settings.h"
 
-static Settings *inst;
+static Settings *theInstance;
 
 Settings::Settings(QObject *parent) :
     QObject(parent)
@@ -11,16 +11,16 @@ Settings::Settings(QObject *parent) :
 
 Settings *Settings::instance()
 {
-    if (!inst) {
-        inst = new Settings();
+    if (!theInstance) {
+        theInstance = new Settings();
     }
-    return inst;
+    return theInstance;
 }
 
 void Settings::close()
 {
-    delete inst;
-    inst = 0;
+    delete theInstance;
+    theInstance = 0;
 }
 
 void Settings::setValue(const QString &key, const QVariant &value)
index 61fde23..f5dfd19 100644 (file)
@@ -1,3 +1,9 @@
+dorian (0.3.5-1) unstable; urgency=low
+
+  *
+
+ -- Akos Polster <akos@pipacs.com>  Sun,  7 Nov 2010 02:00:00 +0100
+
 dorian (0.3.4-1) unstable; urgency=low
 
   * On Symbian, display confirmation after downloading a book
index eb9ce88..34eca29 100644 (file)
@@ -1 +1 @@
-"0.3.4"
+"0.3.5"
index 24ceed9..d2b8f3f 100644 (file)
@@ -33,6 +33,22 @@ static const char *DORIAN_VERSION =
 #   include <QMessageBox>
 #endif
 
+static Platform *theInstance;
+
+Platform *Platform::instance()
+{
+    if (!theInstance) {
+        theInstance = new Platform();
+    }
+    return theInstance;
+}
+
+void Platform::close()
+{
+    delete theInstance;
+    theInstance = 0;
+}
+
 QString Platform::dbPath()
 {
     QString base(QDir::home().absoluteFilePath(DORIAN_BASE));
index 47ce0d1..b648ffc 100644 (file)
@@ -9,15 +9,18 @@ class QWidget;
 class Platform
 {
 public:
-    static QString dbPath();
-    static QString icon(const QString &name);
-    static void restart(char *argv[]);
-    static QString version();
-    static QString downloadDir();
-    static QString defaultFont();
-    static void information(const QString &label, QWidget *parent = 0);
-    static void showBusy(QWidget *w, bool isBusy);
-    static QString traceFileName();
+    static Platform *instance();
+    static void close();
+
+    QString dbPath();
+    QString icon(const QString &name);
+    void restart(char *argv[]);
+    QString version();
+    QString downloadDir();
+    QString defaultFont();
+    void information(const QString &label, QWidget *parent = 0);
+    void showBusy(QWidget *w, bool isBusy);
+    QString traceFileName();
 };
 
 #endif // PLATFORM_H
index f52af1f..9535938 100644 (file)
@@ -69,7 +69,7 @@ void SearchResultsDialog::onDownload()
 QString SearchResultsDialog::downloadName() const
 {
     TRACE;
-    QString dir = Platform::downloadDir();
+    QString dir = Platform::instance()->downloadDir();
     QDir().mkpath(dir); // Not sure if this works. QDir API is quiet lame.
     unsigned i = 0;
     QString fileName;
@@ -102,7 +102,7 @@ void SearchResultsDialog::onEndDownload(int status, const Search::Result &result
         if (-1 != row) {
             list->model()->removeRow(row);
         }
-        Platform::information(tr("Downloaded \"%1\"\nand added to the library").
-                              arg(result.title), this);
+        Platform::instance()->information(tr("Downloaded \"%1\"\nand added to the "
+                                             "library").arg(result.title), this);
     }
 }
index 1bf3b8d..a5ac084 100644 (file)
@@ -88,10 +88,12 @@ SettingsWindow::SettingsWindow(QWidget *parent):  AdopterWindow(parent)
     ToolButtonBox *box = new ToolButtonBox(this);
     layout->addWidget(box);
     box->addButton(SchemeDefault, tr("Default"),
-                   Platform::icon("style-default"));
-    box->addButton(SchemeNight, tr("Night"), Platform::icon("style-night"));
-    box->addButton(SchemeDay, tr("Day"), Platform::icon("style-day"));
-    box->addButton(SchemeSand, tr("Sand"), Platform::icon("style-sand"));
+                   Platform::instance()->icon("style-default"));
+    box->addButton(SchemeNight, tr("Night"),
+                   Platform::instance()->icon("style-night"));
+    box->addButton(SchemeDay, tr("Day"), Platform::instance()->icon("style-day"));
+    box->addButton(SchemeSand, tr("Sand"),
+                   Platform::instance()->icon("style-sand"));
     box->addStretch();
     QString scheme = settings->value("scheme", "default").toString();
     if (scheme == "night") {
index c2d4fb0..65e26b5 100644 (file)
@@ -92,8 +92,8 @@ void ListWindow::addAction(const QString &title, QObject *receiver,
     TRACE;
 #ifdef Q_WS_MAEMO_5
     Q_UNUSED(role);
-    QPushButton *button =
-            new QPushButton(QIcon(Platform::icon(iconName)), title, this);
+    QPushButton *button = new QPushButton(QIcon(Platform::instance()->
+                                                icon(iconName)), title, this);
     contentLayout->addWidget(button);
     connect(button, SIGNAL(clicked()), receiver, slot);
 #elif defined(Q_OS_SYMBIAN)
index 7976dff..a80e8fc 100644 (file)
@@ -23,7 +23,7 @@ void TranslucentButton::paintEvent(QPaintEvent *)
     QPainter painter(this);
     if (!transparent) {
         painter.setRenderHint(QPainter::Antialiasing, true);
-        painter.drawPixmap(0, 0, QPixmap(Platform::icon(name)).scaled(
+        painter.drawPixmap(0, 0, QPixmap(Platform::instance()->icon(name)).scaled(
                 QSize(pixels, pixels), Qt::IgnoreAspectRatio,
                 Qt::SmoothTransformation));
     } else {