From 156e40ef8337b8c0d668fb33a9c8bf2b6b34ba79 Mon Sep 17 00:00:00 2001 From: Akos Polster Date: Mon, 8 Nov 2010 19:47:02 +0100 Subject: [PATCH] Avoid complex types as statics. --- adopterwindow.cpp | 2 +- bookview.cpp | 24 ++++++++++++++---------- bookview.h | 2 +- devtools.cpp | 2 +- fullscreenwindow.cpp | 3 +++ librarydialog.cpp | 5 +++-- main.cpp | 10 ++++++---- mainwindow.cpp | 12 +++++++----- model/bookdb.cpp | 8 ++++---- model/library.cpp | 12 ++++++------ model/library.h | 1 - model/settings.cpp | 12 ++++++------ pkg/changelog | 6 ++++++ pkg/version.txt | 2 +- platform.cpp | 16 ++++++++++++++++ platform.h | 21 ++++++++++++--------- searchresultsdialog.cpp | 6 +++--- settingswindow.cpp | 10 ++++++---- widgets/listwindow.cpp | 4 ++-- widgets/translucentbutton.cpp | 2 +- 20 files changed, 99 insertions(+), 61 deletions(-) diff --git a/adopterwindow.cpp b/adopterwindow.cpp index d553a5c..27d5dbf 100644 --- a/adopterwindow.cpp +++ b/adopterwindow.cpp @@ -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); diff --git a/bookview.cpp b/bookview.cpp index fcdfd4b..e4b4773 100644 --- a/bookview.cpp +++ b/bookview.cpp @@ -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, diff --git a/bookview.h b/bookview.h index e3d6597..e2e1d17 100644 --- a/bookview.h +++ b/bookview.h @@ -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. */ diff --git a/devtools.cpp b/devtools.cpp index 73ecb0d..d44c0ac 100644 --- a/devtools.cpp +++ b/devtools.cpp @@ -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); } diff --git a/fullscreenwindow.cpp b/fullscreenwindow.cpp index f708f53..4aff5d0 100644 --- a/fullscreenwindow.cpp +++ b/fullscreenwindow.cpp @@ -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, diff --git a/librarydialog.cpp b/librarydialog.cpp index 416e05a..796fad6 100644 --- a/librarydialog.cpp +++ b/librarydialog.cpp @@ -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) diff --git a/main.cpp b/main.cpp index 8cd02b2..7de740b 100644 --- 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; } diff --git a/mainwindow.cpp b/mainwindow.cpp index 72f14ef..3cd94f7 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -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 ¬e) { 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 <akos@pipacs.com>
" "Licensed under GNU General Public License, Version 3
" "Source code:
" - "garage.maemo.org/projects/dorian").arg(Platform::version())); + "garage.maemo.org/projects/dorian").arg(version)); aboutDialog->addWidget(label); aboutDialog->addStretch(); aboutDialog->show(); diff --git a/model/bookdb.cpp b/model/bookdb.cpp index 0dee139..ce35c7f 100644 --- a/model/bookdb.cpp +++ b/model/bookdb.cpp @@ -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(); diff --git a/model/library.cpp b/model/library.cpp index 1a322fc..a14a6f9 100644 --- a/model/library.cpp +++ b/model/library.cpp @@ -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() diff --git a/model/library.h b/model/library.h index 0a4a7f3..1df272b 100644 --- a/model/library.h +++ b/model/library.h @@ -49,7 +49,6 @@ private: explicit Library(QObject *parent = 0); ~Library(); void clear(); - static Library *mInstance; QList mBooks; QModelIndex mNowReading; }; diff --git a/model/settings.cpp b/model/settings.cpp index 5e853ac..62fdcec 100644 --- a/model/settings.cpp +++ b/model/settings.cpp @@ -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) diff --git a/pkg/changelog b/pkg/changelog index 61fde23..f5dfd19 100644 --- a/pkg/changelog +++ b/pkg/changelog @@ -1,3 +1,9 @@ +dorian (0.3.5-1) unstable; urgency=low + + * + + -- Akos Polster Sun, 7 Nov 2010 02:00:00 +0100 + dorian (0.3.4-1) unstable; urgency=low * On Symbian, display confirmation after downloading a book diff --git a/pkg/version.txt b/pkg/version.txt index eb9ce88..34eca29 100644 --- a/pkg/version.txt +++ b/pkg/version.txt @@ -1 +1 @@ -"0.3.4" +"0.3.5" diff --git a/platform.cpp b/platform.cpp index 24ceed9..d2b8f3f 100644 --- a/platform.cpp +++ b/platform.cpp @@ -33,6 +33,22 @@ static const char *DORIAN_VERSION = # include #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)); diff --git a/platform.h b/platform.h index 47ce0d1..b648ffc 100644 --- a/platform.h +++ b/platform.h @@ -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 diff --git a/searchresultsdialog.cpp b/searchresultsdialog.cpp index f52af1f..9535938 100644 --- a/searchresultsdialog.cpp +++ b/searchresultsdialog.cpp @@ -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); } } diff --git a/settingswindow.cpp b/settingswindow.cpp index 1bf3b8d..a5ac084 100644 --- a/settingswindow.cpp +++ b/settingswindow.cpp @@ -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") { diff --git a/widgets/listwindow.cpp b/widgets/listwindow.cpp index c2d4fb0..65e26b5 100644 --- a/widgets/listwindow.cpp +++ b/widgets/listwindow.cpp @@ -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) diff --git a/widgets/translucentbutton.cpp b/widgets/translucentbutton.cpp index 7976dff..a80e8fc 100644 --- a/widgets/translucentbutton.cpp +++ b/widgets/translucentbutton.cpp @@ -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 { -- 1.7.9.5