[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    [PATCH] OOWriter uniqueness of automatic styles
From:       Nicolas Goutte <nicolasg () snafu ! de>
Date:       2003-11-15 23:51:33
[Download RAW message or body]

The attached patch is for koffice/filters/kword/oowriter

The patch to the OOWriter export filter checks that the name of the automatic 
style is not one of a user styles to avoid hidding a user style. In the case 
it is, it tries two variations of the name, if it still clashes, it uses the 
time to make the name unique. (The result might still be non-unique but 
somewhere it has to stop, hasn't it?)

Have a nice day!
["patch_oow_unique.diff" (text/x-diff)]

Index: ExportFilter.cc
===================================================================
RCS file: /home/kde/koffice/filters/kword/oowriter/ExportFilter.cc,v
retrieving revision 1.28
diff -u -r1.28 ExportFilter.cc
--- ExportFilter.cc	15 Nov 2003 19:50:00 -0000	1.28
+++ ExportFilter.cc	15 Nov 2003 23:37:43 -0000
@@ -749,8 +749,7 @@
         if (it==m_mapTextStyleKeys.end())
         {
             // We have not any match, so we need a new automatic text style
-            automaticStyle="T";
-            automaticStyle += QString::number(++m_automaticTextStyleNumber,10); // \
### TODO: verify that it is not a normal style +            \
automaticStyle=makeStyleNameUnique("T" + \
                QString::number(++m_automaticTextStyleNumber,10));
             kdDebug(30518) << "Creating automatic text style: " << automaticStyle << \
" key: " << styleKey << endl;  m_mapTextStyleKeys[styleKey]=automaticStyle;
 
@@ -1113,8 +1112,7 @@
         if (it==m_mapParaStyleKeys.end())
         {
             // We have additional properties, so we need an automatic style for the \
                paragraph
-            automaticStyle += "P";
-            automaticStyle += QString::number(++m_automaticParagraphStyleNumber,10); \
// ### TODO: verify that it is not a normal style +            automaticStyle = \
                makeStyleNameUnique("P" + \
                QString::number(++m_automaticParagraphStyleNumber,10));
             kdDebug(30518) << "Creating automatic paragraph style: " << \
automaticStyle << endl;  m_mapParaStyleKeys[styleKey]=automaticStyle;
 
@@ -1280,3 +1278,30 @@
     }
 }
 
+QString OOWriterWorker::makeStyleNameUnique(const QString& str) const
+{
+    // Checks if the automatic style has not the same name as a user one.
+    // If it is the case, change it!
+
+    if (m_styleMap.find(str)==m_styleMap.end())
+        return str; // Unique, so let's go!
+
+    QString str2(str+"_bis");
+    if (m_styleMap.find(str2)==m_styleMap.end())
+        return str2;
+
+    str2 = str+"_ter";
+    if (m_styleMap.find(str2)==m_styleMap.end())
+        return str2;
+
+    // If it is still not unique, try a time stamp.
+    const QDateTime dt(QDateTime::currentDateTime(Qt::UTC));
+
+    str2 = str + "_" + QString::number(dt.toTime_t(),16);
+    if (m_styleMap.find(str2)==m_styleMap.end())
+        return str2;
+
+    kdWarning(30518) << "Could not make an unique style name: " << str2 << endl;
+    return str2; // Still return, as we have nothing better
+}
+
Index: ExportFilter.h
===================================================================
RCS file: /home/kde/koffice/filters/kword/oowriter/ExportFilter.h,v
retrieving revision 1.12
diff -u -r1.12 ExportFilter.h
--- ExportFilter.h	5 Nov 2003 17:11:48 -0000	1.12
+++ ExportFilter.h	15 Nov 2003 23:37:43 -0000
@@ -98,6 +98,7 @@
     void writeStylesXml(void);
     void writeMetaXml(void);
     void writeStartOfFile(const QString& type);
+    QString makeStyleNameUnique(const QString& str) const;
 private: // ZIP methids
     bool zipPrepareWriting(const QString& name);
     bool zipDoneWriting(void);
@@ -120,8 +121,8 @@
     ulong m_automaticTextStyleNumber; // Number of text-based automatic styles \
                (increment *before* use)
     ulong m_footnoteNumber; // Number of footnote (for text:id) (increment *before* \
use)  
-    QString m_styles; // Normal paragraph styles
-    QString m_contentAutomaticStyles; // Automatic styles for content.xml
+    QString m_styles; // Normal paragraph styles (in OO format)
+    QString m_contentAutomaticStyles; // Automatic styles for content.xml (in OO \
format)  
     uint m_size; // Size of ZIP entry
     int m_paperFormat;



_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic