瀏覽代碼

Set values <program-used> and <date> in section <document-info>

Kandrashin Denis 12 年之前
父節點
當前提交
3b0991f414
共有 8 個文件被更改,包括 115 次插入67 次删除
  1. 二進制
      desktop/fb2edit064.png
  2. 1 0
      source/fb2head.cpp
  3. 12 0
      source/fb2html.cpp
  4. 1 0
      source/fb2html.h
  5. 43 47
      source/fb2save.cpp
  6. 3 16
      source/fb2save.hpp
  7. 二進制
      source/ts/ru.qm
  8. 55 4
      source/ts/ru.ts

二進制
desktop/fb2edit064.png


+ 1 - 0
source/fb2head.cpp

@@ -193,6 +193,7 @@ FbHeadItem::HintHash::HintHash()
     insert( "book-title"    , tr( "Title"       ));
     insert( "annotation"    , tr( "Annotation"  ));
     insert( "coverpage"     , tr( "Cover"       ));
+    insert( "program-used"  , tr( "Editor"      ));
     insert( "date"          , tr( "Date"        ));
     insert( "lang"          , tr( "Language"    ));
     insert( "translator"    , tr( "Translator"  ));

+ 12 - 0
source/fb2html.cpp

@@ -112,6 +112,18 @@ bool FbTextElement::Sublist::operator !=(const FbTextElement &element) const
 //  FbTextElement
 //---------------------------------------------------------------------------
 
+FbTextElement FbTextElement::operator[](const QString &name)
+{
+    FbTextElement child = firstChild();
+    while (!child.isNull()) {
+        if (child.tagName().toLower() == name) return child;
+        child = child.nextSibling();
+    }
+    QString html = QString("<%1></%1>").arg(name);
+    appendInside(html);
+    return lastChild();
+}
+
 QString FbTextElement::blockName() const
 {
     QString n = tagName().toLower();

+ 1 - 0
source/fb2html.h

@@ -70,6 +70,7 @@ public:
     int index() const;
 
 public:
+    FbTextElement operator[](const QString &name);
     bool hasChild(const QString &style) const;
     bool isBody() const;
     bool isSection() const;

+ 43 - 47
source/fb2save.cpp

@@ -4,10 +4,12 @@
 #include "fb2save.hpp"
 #include "fb2text.hpp"
 #include "fb2utils.h"
+#include "fb2html.h"
 
 #include <QAbstractNetworkCache>
 #include <QBuffer>
 #include <QComboBox>
+#include <QDateTime>
 #include <QFileDialog>
 #include <QGridLayout>
 #include <QLabel>
@@ -321,7 +323,18 @@ void FbSaveHandler::TextHandler::writeAtts(const QXmlAttributes &atts)
     if (m_tag.isEmpty()) return;
     int count = atts.count();
     for (int i = 0; i < count; i++) {
-        m_writer.writeAttribute(atts.qName(i), atts.value(i));
+        QString name = atts.qName(i);
+        QString value = atts.value(i);
+        if (m_tag == "image") {
+            if (name == "src") {
+                name = "l:href";
+                value = m_writer.getFileName(value);
+                value.prepend('#');
+            }
+        } else if (m_tag == "a") {
+            if (name == "href") name = "l:href";
+        }
+        m_writer.writeAttribute(name, value);
     }
 }
 
@@ -331,10 +344,10 @@ FbXmlHandler::NodeHandler * FbSaveHandler::TextHandler::NewTag(const QString &na
     QString tag = QString();
     switch (toKeyword(name)) {
         case Origin    : tag = name; break;
-        case Anchor    : return new AnchorHandler(this, name, atts);
-        case Image     : return new ImageHandler(this, name, atts);
         case Parag     : return new ParagHandler(this, name, atts);
         case Span      : return new SpanHandler(this, name, atts);
+        case Anchor    : tag = "a"             ; break;
+        case Image     : tag = "image"         ; break;
         case Strong    : tag = "strong"        ; break;
         case Emphas    : tag = "emphasis"      ; break;
         case Strike    : tag = "strikethrough" ; break;
@@ -405,49 +418,6 @@ FbSaveHandler::SpanHandler::SpanHandler(TextHandler *parent, const QString &name
 {
 }
 
-//---------------------------------------------------------------------------
-//  FbSaveHandler::AnchorHandler
-//---------------------------------------------------------------------------
-
-FbSaveHandler::AnchorHandler::AnchorHandler(TextHandler *parent, const QString &name, const QXmlAttributes &atts)
-    : TextHandler(parent, name, atts, "a")
-{
-}
-
-void FbSaveHandler::AnchorHandler::writeAtts(const QXmlAttributes &atts)
-{
-    int count = atts.count();
-    for (int i = 0; i < count; i++) {
-        QString name = atts.qName(i);
-        if (name == "href") name == "l:href";
-        m_writer.writeAttribute(name, atts.value(i));
-    }
-}
-
-//---------------------------------------------------------------------------
-//  FbSaveHandler::ImageHandler
-//---------------------------------------------------------------------------
-
-FbSaveHandler::ImageHandler::ImageHandler(TextHandler *parent, const QString &name, const QXmlAttributes &atts)
-    : TextHandler(parent, name, atts, "image")
-{
-}
-
-void FbSaveHandler::ImageHandler::writeAtts(const QXmlAttributes &atts)
-{
-    int count = atts.count();
-    for (int i = 0; i < count; i++) {
-        QString name = atts.qName(i);
-        QString value = atts.value(i);
-        if (name == "src") {
-            name == "l:href";
-            value = m_writer.getFileName(value);
-            value.prepend('#');
-        }
-        m_writer.writeAttribute(name, value);
-    }
-}
-
 //---------------------------------------------------------------------------
 //  FbSaveHandler::ParagHandler
 //---------------------------------------------------------------------------
@@ -513,13 +483,39 @@ FbXmlHandler::NodeHandler * FbSaveHandler::CreateRoot(const QString &name, const
     return 0;
 }
 
+void FbSaveHandler::setDocumentInfo(QWebFrame * frame)
+{
+    QString info1 = qApp->applicationName() += QString(" ") += qApp->applicationVersion();
+    QDateTime now = QDateTime::currentDateTime();
+    QString info2 = now.toString("dd MMMM yyyy");
+    QString value = now.toString("yyyy-MM-dd hh:mm:ss");
+
+    FbTextElement parent = frame->documentElement().findFirst("body");
+    parent = parent["fb:description"];
+    parent = parent["fb:document-info"];
+
+    FbTextElement child1 = parent["fb:program-used"];
+    child1.setInnerXml(info1);
+
+    FbTextElement child2 = parent["fb:date"];
+    child2.setInnerXml(info2);
+    child2.setAttribute("value", value);
+}
+
 bool FbSaveHandler::save()
 {
+    FbTextPage *page = m_writer.view().page();
+    if (!page) return false;
+
+    QWebFrame *frame = page->mainFrame();
+    if (!frame) return false;
+
+    if (page->isModified()) setDocumentInfo(frame);
     m_writer.writeStartDocument();
-    QWebFrame * frame = m_writer.view().page()->mainFrame();
     QString javascript = jScript("export.js");
     frame->addToJavaScriptWindowObject("handler", this);
     frame->evaluateJavaScript(javascript);
     m_writer.writeEndDocument();
+
     return true;
 }

+ 3 - 16
source/fb2save.hpp

@@ -153,22 +153,6 @@ private:
         explicit SpanHandler(TextHandler *parent, const QString &name, const QXmlAttributes &atts);
     };
 
-    class AnchorHandler : public TextHandler
-    {
-    public:
-        explicit AnchorHandler(TextHandler *parent, const QString &name, const QXmlAttributes &atts);
-    protected:
-        virtual void writeAtts(const QXmlAttributes &atts);
-    };
-
-    class ImageHandler : public TextHandler
-    {
-    public:
-        explicit ImageHandler(TextHandler *parent, const QString &name, const QXmlAttributes &atts);
-    protected:
-        virtual void writeAtts(const QXmlAttributes &atts);
-    };
-
     class ParagHandler : public TextHandler
     {
     public:
@@ -188,6 +172,9 @@ private:
 protected:
     virtual NodeHandler * CreateRoot(const QString &name, const QXmlAttributes &atts);
 
+private:
+    void setDocumentInfo(QWebFrame *frame);
+
 private:
     FbSaveWriter & m_writer;
 };

二進制
source/ts/ru.qm


+ 55 - 4
source/ts/ru.ts

@@ -90,7 +90,7 @@
     <name>FbHeadItem</name>
     <message>
         <source>#</source>
-        <translation>№</translation>
+        <translation type="obsolete">№</translation>
     </message>
     <message>
         <source>Book</source>
@@ -160,6 +160,10 @@
         <source>History</source>
         <translation>История</translation>
     </message>
+    <message>
+        <source>Editor</source>
+        <translation>Редактор</translation>
+    </message>
 </context>
 <context>
     <name>FbHeadModel</name>
@@ -171,20 +175,44 @@
         <source>Value</source>
         <translation>Значение</translation>
     </message>
+    <message>
+        <source>Extra</source>
+        <translation>Дополнение</translation>
+    </message>
+    <message>
+        <source>Info</source>
+        <translation>Информация</translation>
+    </message>
+    <message>
+        <source>Type</source>
+        <translation>Тип</translation>
+    </message>
+    <message>
+        <source>Can edit</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <source>Min</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <source>Max</source>
+        <translation type="unfinished"></translation>
+    </message>
 </context>
 <context>
     <name>FbHeadView</name>
     <message>
         <source>&amp;Append</source>
-        <translation type="unfinished">&amp;Добавить</translation>
+        <translation>&amp;Добавить</translation>
     </message>
     <message>
         <source>&amp;Modify</source>
-        <translation type="unfinished"></translation>
+        <translation>&amp;Изменить</translation>
     </message>
     <message>
         <source>&amp;Delete</source>
-        <translation type="unfinished">&amp;Удалить</translation>
+        <translation>&amp;Удалить</translation>
     </message>
 </context>
 <context>
@@ -558,6 +586,10 @@
         <translatorcomment>Стиль: Заголовок</translatorcomment>
         <translation>Заголовок</translation>
     </message>
+    <message>
+        <source>&amp;HTML</source>
+        <translation type="unfinished"></translation>
+    </message>
 </context>
 <context>
     <name>FbNodeDlg</name>
@@ -570,6 +602,17 @@
         <translation type="unfinished"></translation>
     </message>
 </context>
+<context>
+    <name>FbNodeEditDlg</name>
+    <message>
+        <source>Modify tag</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <source>Value:</source>
+        <translation type="unfinished"></translation>
+    </message>
+</context>
 <context>
     <name>FbNote</name>
     <message>
@@ -718,6 +761,14 @@
         <source>Insert epigraph</source>
         <translation type="unfinished"></translation>
     </message>
+    <message>
+        <source>Create &lt;%1&gt;</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <source>Remove section</source>
+        <translation type="unfinished">Удалить секцию</translation>
+    </message>
 </context>
 <context>
     <name>FbTreeModel</name>