Browse Source

Export HTML with images for debug JavaScript

Kandrashin Denis 12 years ago
parent
commit
026c23d861
3 changed files with 44 additions and 1 deletions
  1. 7 1
      source/fb2main.cpp
  2. 32 0
      source/fb2text.cpp
  3. 5 0
      source/fb2text.hpp

+ 7 - 1
source/fb2main.cpp

@@ -198,6 +198,12 @@ void FbMainWindow::createActions()
     connect(act, SIGNAL(triggered()), this, SLOT(fileSaveAs()));
     menu->addAction(act);
 
+#ifdef QT_DEBUG
+    act = new QAction(tr("&Export HTML"), this);
+    connect(act, SIGNAL(triggered()), text, SLOT(exportHtml()));
+    menu->addAction(act);
+#endif // QT_DEBUG
+
     menu->addSeparator();
 
     act = new QAction(FbIcon("window-close"), tr("&Close"), this);
@@ -446,7 +452,7 @@ void FbMainWindow::createActions()
     mainDock->addAction(Fb::Html, act);
     viewGroup->addAction(act);
     menu->addAction(act);
-#endif // _DEBUG
+#endif // QT_DEBUG
 
     menu->addSeparator();
 

+ 32 - 0
source/fb2text.cpp

@@ -340,6 +340,38 @@ void FbTextEdit::disconnectActions()
     viewInspector(false);
 }
 
+#ifdef QT_DEBUG
+void FbTextEdit::exportHtml()
+{
+    FbSaveDialog dlg(this, tr("Save As..."));
+    dlg.selectFile("filename.htm");
+    if (!dlg.exec()) return;
+    QString fileName = dlg.fileName();
+    if (fileName.isEmpty()) return;
+
+    QFile file(fileName);
+    if (!file.open(QFile::WriteOnly)) return;
+    QTextStream out(&file);
+    out.setCodec("UTF-8");
+    out << toHtml();
+
+    QFileInfo fileInfo(fileName);
+    QString dirName = fileInfo.path() + "/" + fileInfo.completeBaseName() + "/";
+    QDir().mkpath(dirName);
+
+    FbNetworkAccessManager *m = qobject_cast<FbNetworkAccessManager*>(page()->networkAccessManager());
+    if (!m) return;
+
+    int count = m->count();
+    for (int i = 0; i < count; i++) {
+        QFile file(dirName + m->info(i, 0).toString());
+        if (file.open(QFile::WriteOnly)) {
+            file.write(m->data(i));
+        }
+    }
+}
+#endif // QT_DEBUG
+
 void FbTextEdit::viewContents(bool show)
 {
     if (show) {

+ 5 - 0
source/fb2text.hpp

@@ -113,6 +113,11 @@ public slots:
     void insertLink();
     void find();
 
+#ifdef QT_DEBUG
+public slots:
+    void exportHtml();
+#endif // QT_DEBUG
+
 private slots:
     void linkHovered(const QString &link, const QString &title, const QString &textContent);
     void contextMenu(const QPoint &pos);