Search Project Gutenberg.
authorAkos Polster <akos@pipacs.com>
Sun, 24 Oct 2010 15:01:18 +0000 (17:01 +0200)
committerAkos Polster <akos@pipacs.com>
Sun, 24 Oct 2010 15:01:18 +0000 (17:01 +0200)
dorian.pro
mainwindow.cpp
pkg/maemo/control
platform.cpp
platform.h
search.cpp
search.h
searchdialog.cpp

index 9a0679c..8bfda6f 100644 (file)
@@ -1,4 +1,4 @@
-QT += webkit xml sql\r
+QT += webkit xml sql network\r
 \r
 INCLUDEPATH += $$PWD \\r
     $$PWD/model \\r
@@ -127,7 +127,7 @@ win32 {
 symbian {\r
     ICON = $$PWD/pkg/symbian/book.svgt\r
     TARGET.UID3 = 0xEA633557\r
-    # FIXME: TARGET.CAPABILITY = ...\r
+    TARGET.CAPABILITY = NetworkServices\r
     # FIXME: Include path to OpenC ZLIB?\r
     INCLUDEPATH += c:/Qt/4.7.0/src/3rdparty/zlib\r
     HEADERS += widgets/flickcharm.h\r
index 675bdd4..2ef654e 100755 (executable)
 #include "progress.h"
 #include "dyalog.h"
 #include "translucentbutton.h"
+#include "platform.h"
 
 #ifdef DORIAN_TEST_MODEL
 #   include "modeltest.h"
 #endif
 
-const int PROGRESS_HEIGHT = 17;
-static const char *DORIAN_VERSION =
-#include "pkg/version.txt"
-;
+const int DORIAN_PROGRESS_HEIGHT = 17;
 
 MainWindow::MainWindow(QWidget *parent):
     AdopterWindow(parent), view(0), preventBlankingTimer(-1)
@@ -202,7 +200,7 @@ void MainWindow::showRegular()
     otherChildren << progress << previousButton << nextButton;
     takeChildren(view, otherChildren);
     QRect geo = geometry();
-    progress->setGeometry(0, 0, geo.width(), PROGRESS_HEIGHT);
+    progress->setGeometry(0, 0, geo.width(), DORIAN_PROGRESS_HEIGHT);
 #if defined(Q_WS_MAEMO_5)
     previousButton->setGeometry(0,
         geo.height() - toolBar->height() - TranslucentButton::pixels,
@@ -235,7 +233,7 @@ void MainWindow::showBig()
     QList<QWidget *> otherChildren;
     otherChildren << progress << nextButton << previousButton;
     QRect screen = QApplication::desktop()->screenGeometry();
-    progress->setGeometry(0, 0, screen.width(), PROGRESS_HEIGHT);
+    progress->setGeometry(0, 0, screen.width(), DORIAN_PROGRESS_HEIGHT);
 #if defined(Q_WS_MAEMO_5)
     nextButton->setGeometry(screen.width() - TranslucentButton::pixels, 0,
         TranslucentButton::pixels, TranslucentButton::pixels);
@@ -417,7 +415,7 @@ void MainWindow::timerEvent(QTimerEvent *event)
 void MainWindow::resizeEvent(QResizeEvent *e)
 {
     Trace t("MainWindow::resizeEvent");
-    progress->setGeometry(QRect(0, 0, e->size().width(), PROGRESS_HEIGHT));
+    progress->setGeometry(QRect(0, 0, e->size().width(), DORIAN_PROGRESS_HEIGHT));
 #if defined(Q_WS_MAEMO_5)
     previousButton->setGeometry(0,
         e->size().height() - toolBar->height() - TranslucentButton::pixels,
@@ -453,7 +451,7 @@ void MainWindow::about()
         "Akos Polster &lt;akos@pipacs.com&gt;<br>"
         "Licensed under GNU General Public License, Version 3<br>"
         "Source code: <a href='https://garage.maemo.org/projects/dorian/'>"
-        "garage.maemo.org/projects/dorian</a>").arg(DORIAN_VERSION));
+        "garage.maemo.org/projects/dorian</a>").arg(Platform::version()));
     aboutDialog->addWidget(label);
     aboutDialog->addStretch();
     aboutDialog->show();
index 3848670..5fccc3f 100644 (file)
@@ -8,7 +8,7 @@ XSBC-Bugtracker: https://garage.maemo.org/tracker/?atid=6138&group_id=1757
 
 Package: dorian
 Architecture: armel
-Depends: zlib1g, libqt4-core (>= 4.6.1), libqt4-gui (>= 4.6.1), libqt4-webkit (>= 4.6.1), libqt4-xml (>= 4.6.1), libqt4-dbus (>= 4.6.1), libqt4-sql (>= 4.6.1), libqt4-sql-sqlite (>= 4.6.1), mce
+Depends: zlib1g, libqt4-core (>= 4.6.1), libqt4-gui (>= 4.6.1), libqt4-webkit (>= 4.6.1), libqt4-xml (>= 4.6.1), libqt4-dbus (>= 4.6.1), libqt4-sql (>= 4.6.1), libqt4-sql-sqlite (>= 4.6.1), libqt4-network (>= 4.6.1), mce
 Description: E-book reader
  Read books published in DRM-free EPUB format
 XB-Maemo-Display-Name: Dorian
index c65bae8..ea09cfe 100644 (file)
 #   define DORIAN_ICON_PREFIX ":/icons/"
 #endif
 
+static const char *DORIAN_VERSION =
+#include "pkg/version.txt"
+;
+
 QString Platform::dbPath()
 {
     QString base(QDir::home().absoluteFilePath(DORIAN_BASE));
@@ -39,3 +43,8 @@ void Platform::restart(char *argv[])
     Q_UNUSED(argv);
 #endif
 }
+
+QString Platform::version()
+{
+    return QString(DORIAN_VERSION);
+}
index f328667..5f63180 100644 (file)
@@ -10,6 +10,7 @@ public:
     static QString dbPath();
     static QString icon(const QString &name);
     static void restart(char *argv[]);
+    static QString version();
 };
 
 #endif // PLATFORM_H
index 4ed8768..6b2ff4d 100644 (file)
@@ -1,4 +1,10 @@
+#include <QNetworkAccessManager>
+#include <QNetworkReply>
+#include <QNetworkRequest>
+
 #include "search.h"
+#include "platform.h"
+#include "trace.h"
 
 Search *inst = 0;
 
@@ -16,14 +22,28 @@ void Search::close()
     inst = 0;
 }
 
-Search::Search(): QObject(0)
+Search::Search(): QObject(0), reply(0)
 {
+    manager = new QNetworkAccessManager(this);
+    connect(manager, SIGNAL(finished(QNetworkReply *)),
+            this, SLOT(onFinished(QNetworkReply *)));
 }
 
 void Search::start(const Query &query)
 {
+    Trace t("Search::start");
+
     emit beginSearch();
-    emit endSearch();
+
+    QNetworkRequest request;
+    request.setUrl(QUrl("http://www.gutenberg.org/catalog/world/results"));
+    // request.setRawHeader("User-Agent", "Dorian " + Platform::version());
+    QByteArray data;
+    data = "title=" + QUrl::toPercentEncoding(query.title) + "&author=" +
+           QUrl::toPercentEncoding(query.author);
+    qDebug() << "Request:" << data;
+    reply = manager->post(request, data);
+    connect(reply, SIGNAL(finished()), this, SLOT(finished()));
 }
 
 QList<Search::Result> Search::results()
@@ -40,3 +60,12 @@ bool Search::download(const Search::Result &result, const QString &fileName)
     emit endDownload();
     return false;
 }
+
+void Search::finished()
+{
+    Trace t("Search::finished");
+    QByteArray data = reply->readAll();
+    qDebug() << data;
+    reply->deleteLater();
+    emit endSearch();
+}
index d577f2f..d11b7e5 100644 (file)
--- a/search.h
+++ b/search.h
@@ -7,6 +7,9 @@
 #include <QImage>
 #include <QList>
 
+class QNetworkAccessManager;
+class QNetworkReply;
+
 /** Search for books, display and download results. */
 class Search: public QObject
 {
@@ -45,9 +48,12 @@ public slots:
     void start(const Query &query);
     QList<Result> results();
     bool download(const Result &result, const QString &fileName);
+    void finished();
 
 protected:
     explicit Search();
+    QNetworkAccessManager *manager;
+    QNetworkReply *reply;
 };
 
 #endif // SEARCH_H
index da5182a..9054619 100644 (file)
@@ -2,10 +2,11 @@
 
 #include "searchdialog.h"
 #include "search.h"
+#include "trace.h"
 
 SearchDialog::SearchDialog(QWidget *parent): Dyalog(parent)
 {
-    setWindowTitle(tr("Search"));
+    setWindowTitle(tr("SearchDialog::SearchDialog"));
 
     QLabel *titleLabel = new QLabel(tr("Title:"), this);
     title = new QLineEdit(this);
@@ -22,8 +23,10 @@ SearchDialog::SearchDialog(QWidget *parent): Dyalog(parent)
 
 Search::Query SearchDialog::query()
 {
+    Trace t("SearchDialog::query");
     Search::Query ret;
     ret.title = title->text();
     ret.author = author->text();
+    qDebug() << ret.title << ret.author;
     return ret;
 }