[PATCH] Run msgfmt before processing a file in the catalog manager

Nicolas Goutte <[email protected]> Fri, 4 Nov 2005 23:20:27 +0100
Newsgroups gmane.comp.kde.devel.kbabel
Message-ID <[email protected]>
The attached patch is for the directory branches/KDE/3.5/kdesdk/kbabel

It is more a proof-of-concept for adding the posibility for the user to the 
select if msgfmt is run or not before a file is processed by the catalog 
manager. (Currently with this patch, Project/Configure crashes.)

Compared to a similar previous patch, now, the lexer is only slightly 
modified:
- for the support of msgctxt
- make an empty explicit rule for . (any character) and for alphabetic 
characters (the info doc of lex tells that it makes the lexer faster).

Probably I have missed something in the configure settting (at least missing 
is how to set the check box to be checked by default if there is no previous 
setting.)

For the PO thumbnail and file info, I have turned off the use of msgfmt, as I 
suppose that here speed is more wanted than precision.

Have a nice day!

_______________________________________________
kbabel mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kbabel
catman_msgfmt.diff (text/x-diff, 6.9 KB)
Index: commonui/projectprefwidgets.cpp
===================================================================
--- commonui/projectprefwidgets.cpp	(Revision 477717)
+++ commonui/projectprefwidgets.cpp	(Arbeitskopie)
@@ -481,6 +481,7 @@
     connect(_testPluralButton, SIGNAL(clicked()), this
             , SLOT(testPluralForm()));
 
+    // ### FIXME: "KDE >= 2.2" should be replaced
     QString msg=i18n("<qt><p><b>Number of singular/plural forms</b></p>\n"
             "<p><b>Note</b>: This option is KDE specific at the moment. "
             "If you are not translating a KDE application, you can safely "
@@ -942,11 +943,7 @@
 "<p>If you check this, KBabel will create an index for each PO file to speed up the find/replace functions.</p>\n"
 "<p>NOTE: This will slow down updating the file information considerably.</p></qt>") );
 
-    m_msgfmtButton = new QCheckBox( i18n("Run &msgfmt before processing a file"), box );
-    
-    // ### TEMPORARY
-    m_msgfmtButton->setChecked( true );
-    m_msgfmtButton->setEnabled( false );
+    m_msgfmtButton = new QCheckBox( i18n("Run &msgfmt before processing a file"), box, "kcfg_m_msgfmt" );
 
     QWhatsThis::add( m_msgfmtButton, i18n("<qt><p><b>Run msgfmt before processing a file</b></p>"
         "<p>If you check this, KBabel will run Gettext's "
@@ -977,7 +974,7 @@
 
    _killButton->setChecked(settings.killCmdOnExit );
    _indexButton->setChecked(settings.indexWords );
-   //m_msgfmtButton->setChecked( settings.msgfmtButton );
+   m_msgfmtButton->setChecked( settings.m_msgfmt );
 }
 
 DirCommandsPreferences::DirCommandsPreferences(QWidget* parent)
Index: common/poinfo.h
===================================================================
--- common/poinfo.h	(Revision 477642)
+++ common/poinfo.h	(Arbeitskopie)
@@ -93,7 +93,7 @@
     */
    static void cacheSave(const QString url, PoInfo& info);
 
-   static ConversionStatus info(const QString& url,PoInfo& info, QStringList &wordList, bool updateWordList, bool interactive=true);
+   static ConversionStatus info(const QString& url,PoInfo& info, QStringList &wordList, bool updateWordList, bool interactive, bool msgfmt);
    static PoInfo headerInfo(const CatalogItem&);
    static bool findInFile(const QString& url, FindOptions options );
    
Index: common/poinfo.cpp
===================================================================
--- common/poinfo.cpp	(Revision 477642)
+++ common/poinfo.cpp	(Arbeitskopie)
@@ -350,7 +350,7 @@
 }
 
 
-ConversionStatus PoInfo::info(const QString& url, PoInfo& info, QStringList &wordList, bool updateWordList, bool interactive)
+ConversionStatus PoInfo::info(const QString& url, PoInfo& info, QStringList &wordList, bool updateWordList, bool interactive, bool msgfmt)
 {
    stopStaticRead = false;
 
@@ -362,18 +362,18 @@
    {
        QFile file(target);
 
-#if 1
-	   // first check file with msgfmt to be sure, it is 
-	   // syntactically correct
-	   Msgfmt msgfmt;
-	   QString output;
-	   Msgfmt::Status stat = msgfmt.checkSyntax( target , output );
-	   if(stat == Msgfmt::SyntaxError)
-	   {
-          KIO::NetAccess::removeTempFile(target);
-		  return PARSE_ERROR;
-	   }
-#endif
+       if ( msgfmt )
+       {
+            // First check file with msgfmt to be sure, it is syntactically correct
+            Msgfmt msgfmt;
+            QString output;
+            Msgfmt::Status stat = msgfmt.checkSyntax( target , output );
+            if(stat == Msgfmt::SyntaxError)
+            {
+                KIO::NetAccess::removeTempFile(target);
+                return PARSE_ERROR;
+            }
+       }
 
 
        std::ifstream* stream = new std::ifstream( file.name().local8Bit());
@@ -398,8 +398,8 @@
 	       
 	       if( stopStaticRead )
 	       {
-                    // ### FIXME: delete temporary file
-	    	    delete lexer;
+                    KIO::NetAccess::removeTempFile(target);
+                    delete lexer;
 		    delete stream;
 		    return OK;
 		}
Index: common/libgettext/pofiles.ll
===================================================================
--- common/libgettext/pofiles.ll	(Revision 477642)
+++ common/libgettext/pofiles.ll	(Arbeitskopie)
@@ -82,7 +82,7 @@
 		}
 msgctxt         {
                     return T_MSGCTXT;
-}
+                }
 #~{NOEOL}*	{
 		   return T_OBSOLETE;
 		}
@@ -97,7 +97,8 @@
 		   return T_STRING;
 		}
 
-.		;
+[a-z]+          |
+.               ;
 
 <<EOF>>		{
 		    return T_EOF;
Index: common/projectsettings.h
===================================================================
--- common/projectsettings.h	(Revision 477642)
+++ common/projectsettings.h	(Arbeitskopie)
@@ -80,6 +80,8 @@
 
    bool killCmdOnExit;
    bool indexWords;
+   /// Should be msgfmt be run before processing a file?
+   bool m_msgfmt;
 
    bool flagColumn;
    bool fuzzyColumn;
Index: catalogmanager/catmanlistitem.cpp
===================================================================
--- catalogmanager/catmanlistitem.cpp	(Revision 477642)
+++ catalogmanager/catmanlistitem.cpp	(Arbeitskopie)
@@ -425,7 +425,7 @@
                 PoInfo poInfo;
                 QPixmap icon = ICON_UPDATING;
 		setPixmap(COL_NAME,icon);
-                if(PoInfo::info(_primary.absFilePath(),poInfo,_wordList,updateWordList)==OK)
+                if ( PoInfo::info( _primary.absFilePath(), poInfo, _wordList, updateWordList, true, _view->settings().m_msgfmt ) == OK ) 
                 {
 		    if( _view->isStopped() ) return;
 		    if( updateWordList) _wordListUpdated = true;
@@ -545,7 +545,7 @@
 		setPixmap(COL_NAME,ICON_UPDATING);
 
                 PoInfo poInfo;
-                if(PoInfo::info(_template.absFilePath(),poInfo,_wordList, false)==OK)
+                if ( PoInfo::info( _template.absFilePath(), poInfo, _wordList, false, true, _view->settings().m_msgfmt ) == OK )
                 {
         	    if( _view->isStopped() ) return;
 		    setText(COL_TOTAL,QString::number(poInfo.total));
Index: addons/preview/pothumbcreator.cpp
===================================================================
--- addons/preview/pothumbcreator.cpp	(Revision 477642)
+++ addons/preview/pothumbcreator.cpp	(Arbeitskopie)
@@ -83,7 +83,9 @@
     bool ok = false;
     PoInfo poInfo;
     QStringList wordList;
-    if( PoInfo::info(path,poInfo, wordList, false) == OK )
+
+    // We do not call msgfmt, as a thumbnail must be created fast.
+    if( PoInfo::info( path, poInfo, wordList, false, true, false ) == OK )
     {
        ok = true;
        
Index: addons/kfile-plugins/kfile_po.cpp
===================================================================
--- addons/kfile-plugins/kfile_po.cpp	(Revision 477642)
+++ addons/kfile-plugins/kfile_po.cpp	(Arbeitskopie)
@@ -62,8 +62,7 @@
 {
   PoInfo poInfo;
   QStringList wordList;
-  ConversionStatus status = PoInfo::info(metaInfo.path(), poInfo,
-					   wordList, false, false);
+  ConversionStatus status = PoInfo::info(metaInfo.path(), poInfo, wordList, false, false, false);
   if (status == OK) {
     KFileMetaInfoGroup group = appendGroup(metaInfo, "CatalogInfo");