瀏覽代碼

Read document from file

Kandrashin Denis 12 年之前
父節點
當前提交
155f55df7b
共有 4 個文件被更改,包括 19 次插入6 次删除
  1. 9 5
      source/fb2page.cpp
  2. 1 0
      source/fb2page.hpp
  3. 7 0
      source/fb2read.cpp
  4. 2 1
      source/fb2read.hpp

+ 9 - 5
source/fb2page.cpp

@@ -58,15 +58,19 @@ FbNetworkAccessManager *FbTextPage::temp()
     return qobject_cast<FbNetworkAccessManager*>(networkAccessManager());
 }
 
+bool FbTextPage::read(const QString &html)
+{
+    QXmlInputSource *source = new QXmlInputSource();
+    source->setData(html);
+    FbReadThread::execute(this, source);
+    return true;
+}
+
 bool FbTextPage::read(QIODevice &device)
 {
     QXmlInputSource *source = new QXmlInputSource();
     source->setData(device.readAll());
-
-    FbReadThread *thread = new FbReadThread(this, source);
-    connect(thread, SIGNAL(html(QObject*,QString)), this, SLOT(html(QObject*,QString)));
-    thread->start();
-
+    FbReadThread::execute(this, source);
     return true;
 }
 

+ 1 - 0
source/fb2page.hpp

@@ -29,6 +29,7 @@ class FbTextPage : public QWebPage
 public:
     explicit FbTextPage(QObject *parent = 0);
     FbNetworkAccessManager *temp();
+    bool read(const QString &html);
     bool read(QIODevice &device);
     void push(QUndoCommand * command, const QString &text = QString());
     FbTextElement element(const QString &location);

+ 7 - 0
source/fb2read.cpp

@@ -9,6 +9,13 @@
 //  FbReadThread
 //---------------------------------------------------------------------------
 
+void FbReadThread::execute(QObject *parent, QXmlInputSource *source)
+{
+    FbReadThread *thread = new FbReadThread(parent, source);
+    connect(thread, SIGNAL(html(QObject*,QString)), parent, SLOT(html(QObject*,QString)));
+    thread->start();
+}
+
 FbReadThread::FbReadThread(QObject *parent, QXmlInputSource *source)
     : QThread(parent)
     , m_source(source)

+ 2 - 1
source/fb2read.hpp

@@ -15,7 +15,7 @@ class FbReadThread : public QThread
     Q_OBJECT
 
 public:
-    FbReadThread(QObject *parent, QXmlInputSource *source);
+    static void execute(QObject *parent, QXmlInputSource *source);
     ~FbReadThread();
 
 signals:
@@ -26,6 +26,7 @@ protected:
     void run();
 
 private:
+    explicit FbReadThread(QObject *parent, QXmlInputSource *source);
     bool parse();
 
 private: