widgets/progress.cpp \
widgets/adopterwindow.cpp \
platform.cpp \
- model/bookdb.cpp
+ model/bookdb.cpp \
+ searchdialog.cpp \
+ search.cpp
HEADERS += \
mainwindow.h \
widgets/listview.h \
model/xmlhandler.h \
platform.h \
- model/bookdb.h
+ model/bookdb.h \
+ searchdialog.h \
+ search.h
RESOURCES += \
dorian.qrc
#include "listview.h"
#include "trace.h"
#include "bookfinder.h"
+#include "searchdialog.h"
LibraryDialog::LibraryDialog(QWidget *parent): ListWindow(parent)
{
addItemAction(tr("Delete"), this, SLOT(onRemove()));
#endif // ! Q_WS_MAEMO_5
- addAction(tr("Add book"), this, SLOT(onAdd()), ":/icons/add.png");
- addAction(tr("Add books from folder"), this, SLOT(onAddFolder()),
- ":/icons/folder.png");
- addAction(tr("Search the Web"), this, SLOT(onSearch()), ":/icons/search.png");
+ addAction(tr("Add book"), this, SLOT(onAdd()), "add");
+ addAction(tr("Add books from folder"), this, SLOT(onAddFolder()), "folder");
+ addAction(tr("Search the Web"), this, SLOT(onSearch()), "search");
// Create and add list view
list = new ListView(this);
SLOT(onBookAdded()));
connect(list, SIGNAL(activated(const QModelIndex &)),
this, SLOT(onItemActivated(const QModelIndex &)));
+
+ // Create search dialog
+ searchDialog = new SearchDialog(this);
}
void LibraryDialog::onAdd()
progress->setLabelText(QFileInfo(path).fileName());
progress->setValue(progress->value() + 1);
}
+
+void LibraryDialog::onSearch()
+{
+ int ret = searchDialog->exec();
+ if (ret != QDialog::Accepted) {
+ return;
+ }
+ Search::instance()->start(searchDialog->query());
+}
class Book;
class InfoWindow;
class SortedLibrary;
+class SearchDialog;
/** Manage library. */
class LibraryDialog: public ListWindow
void onCurrentBookChanged();
void onAddFromFolder(const QString &path);
void onAddFromFolderDone(int added);
+ void onSearch();
+
private:
QString createItemText(const Book *book);
void setSelected(const QModelIndex &index);
ListView *list;
SortedLibrary *sortedLibrary;
QProgressDialog *progress;
+ SearchDialog *searchDialog;
};
#endif // LIBRARYDIALOG_H
-#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
-#include <unistd.h>
-#endif
-
#include <QtGui/QApplication>
#include "mainwindow.h"
#include "trace.h"
#include "settings.h"
+#include "library.h"
+#include "settings.h"
+#include "bookdb.h"
+#include "search.h"
+#include "platform.h"
static const char *DORIAN_VERSION =
#include "pkg/version.txt"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
+ int ret;
a.setApplicationName("Dorian");
a.setApplicationVersion(DORIAN_VERSION);
value("tracelevel", (int)DORIAN_DEFAULT_TRACE_LEVEL).toInt();
qInstallMsgHandler(Trace::messageHandler);
- MainWindow w;
- w.show();
-
-#if 0 // FIXME #ifdef Q_OS_SYMBIAN
- // Remove context menu from all widgets
- foreach (QWidget *w, QApplication::allWidgets()) {
- w->setContextMenuPolicy(Qt::NoContextMenu);
+ {
+ MainWindow w;
+ w.show();
+ ret = a.exec();
}
-#endif // Q_OS_SYMBIAN
- int ret = a.exec();
+ // Release singletons
+ Library::close();
+ BookDb::close();
+ Settings::close();
+ Search::close();
+
+ // Re-start application if event loop exit code was 1000
if (ret == 1000) {
-#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
- extern char **environ;
- execve(argv[0], argv, environ);
-#endif
+ Platform::restart(argv);
}
return ret;
}
return inst;
}
+void Settings::close()
+{
+ delete inst;
+ inst = 0;
+}
+
void Settings::setValue(const QString &key, const QVariant &value)
{
QSettings s;
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);
#include "sortedlibrary.h"
#include "book.h"
+#include "trace.h"
-SortedLibrary::SortedLibrary(QObject *parent): QSortFilterProxyModel(parent)
+SortedLibrary::SortedLibrary(QObject *parent):
+ QSortFilterProxyModel(parent), mSortBy(SortByTitle)
{
setSourceModel(Library::instance());
+ sort(0);
}
void SortedLibrary::sortBy(SortBy key)
break;
}
- return QString::localeAwareCompare(leftString, rightString);
+ return QString::localeAwareCompare(leftString, rightString) < 0;
}
dorian (0.3.1-1) unstable; urgency=low
- *
+ * Fix sorting of library
-- Akos Polster <akos@pipacs.com> Sat, 10 Oct 2010 02:00:00 +0200
+#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
+#include <unistd.h>
+#endif
+
#include <QDir>
#include "platform.h"
{
return QString(DORIAN_ICON_PREFIX) + name + ".png";
}
+
+void Platform::restart(char *argv[])
+{
+#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
+ extern char **environ;
+ execve(argv[0], argv, environ);
+#else
+ Q_UNUSED(argv);
+#endif
+}
public:
static QString dbPath();
static QString icon(const QString &name);
+ static void restart(char *argv[]);
};
#endif // PLATFORM_H
--- /dev/null
+#include "search.h"
+
+Search *inst = 0;
+
+Search *Search::instance()
+{
+ if (!inst) {
+ inst = new Search();
+ }
+ return inst;
+}
+
+void Search::close()
+{
+ delete inst;
+ inst = 0;
+}
+
+Search::Search(): QObject(0)
+{
+}
+
+void Search::start(const Query &query)
+{
+ emit beginSearch();
+ emit endSearch();
+}
+
+QList<Search::Result> Search::results()
+{
+ QList<Search::Result> ret;
+ return ret;
+}
+
+bool Search::download(const Search::Result &result, const QString &fileName)
+{
+ Q_UNUSED(result);
+ Q_UNUSED(fileName);
+ emit beginDownload(0);
+ emit endDownload();
+ return false;
+}
--- /dev/null
+#ifndef SEARCH_H
+#define SEARCH_H
+
+#include <QObject>
+#include <QString>
+#include <QStringList>
+#include <QImage>
+#include <QList>
+
+class Search: public QObject
+{
+ Q_OBJECT
+
+public:
+ struct Query
+ {
+ QString title;
+ QString author;
+ QStringList languages;
+ };
+
+ struct Result
+ {
+ QString id;
+ QString source;
+ QString title;
+ QStringList authors;
+ QString language;
+ QImage cover;
+ };
+
+ static Search *instance();
+ static void close();
+
+signals:
+ void beginSearch();
+ void searching();
+ void endSearch();
+ void beginDownload(int totalBlocks);
+ void downloading(int blocks);
+ void endDownload();
+
+public slots:
+ void start(const Query &query);
+ QList<Result> results();
+ bool download(const Result &result, const QString &fileName);
+
+protected:
+ explicit Search();
+};
+
+#endif // SEARCH_H
--- /dev/null
+#include <QtGui>
+
+#include "searchdialog.h"
+#include "search.h"
+
+SearchDialog::SearchDialog(QWidget *parent): Dyalog(parent)
+{
+ setWindowTitle(tr("Search"));
+
+ QLabel *titleLabel = new QLabel(tr("Title:"), this);
+ title = new QLineEdit(this);
+ QLabel *authorLabel = new QLabel(tr("Author"), this);
+ author = new QLineEdit(this);
+
+ addWidget(titleLabel);
+ addWidget(title);
+ addWidget(authorLabel);
+ addWidget(author);
+ addStretch();
+ addButton(tr("Search"), this, SLOT(accept()));
+}
+
+Search::Query SearchDialog::query()
+{
+ Search::Query ret;
+ ret.title = title->text();
+ ret.author = author->text();
+ return ret;
+}
--- /dev/null
+#ifndef SEARCHDIALOG_H
+#define SEARCHDIALOG_H
+
+#include <QVariantHash>
+
+#include "dyalog.h"
+#include "search.h"
+
+class QLineEdit;
+
+class SearchDialog : public Dyalog
+{
+ Q_OBJECT
+
+public:
+ explicit SearchDialog(QWidget *parent = 0);
+ Search::Query query();
+
+signals:
+
+public slots:
+
+protected:
+ QLineEdit *author;
+ QLineEdit *title;
+};
+
+#endif // SEARCHDIALOG_H
#include "listwindow.h"
#include "trace.h"
#include "listview.h"
+#include "platform.h"
ListWindow::ListWindow(QWidget *parent): QMainWindow(parent), list(0)
{
}
void ListWindow::addAction(const QString &title, QObject *receiver,
- const char *slot, const QString &iconPath,
+ const char *slot, const QString &iconName,
QDialogButtonBox::ButtonRole role)
{
Trace t("ListWindow::addAction");
#ifdef Q_WS_MAEMO_5
Q_UNUSED(role);
- QPushButton *button = new QPushButton(QIcon(iconPath), title, this);
+ QPushButton *button =
+ new QPushButton(QIcon(Platform::icon(iconName)), title, this);
contentLayout->addWidget(button);
connect(button, SIGNAL(clicked()), receiver, slot);
#elif defined(Q_OS_SYMBIAN)
Q_UNUSED(role);
+ Q_UNUSED(iconName);
QAction *action = new QAction(title, this);
connect(action, SIGNAL(triggered()), receiver, slot);
action->setSoftKeyRole(QAction::PositiveSoftKey);
menuBar()->addAction(action);
#else
- Q_UNUSED(iconPath);
+ Q_UNUSED(iconName);
QPushButton *button = buttonBox->addButton(title, role);
connect(button, SIGNAL(clicked()), receiver, slot);
#endif // Q_WS_MAEMO_5