diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | bd9e6617827818fd043452c08c606f07b78014a0 (patch) | |
tree | 425bb4c3168f9c02f10150f235d2cb998dcc6108 /kbabel/datatools/arguments | |
download | tdesdk-bd9e6617827818fd043452c08c606f07b78014a0.tar.gz tdesdk-bd9e6617827818fd043452c08c606f07b78014a0.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdesdk@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kbabel/datatools/arguments')
-rw-r--r-- | kbabel/datatools/arguments/Makefile.am | 19 | ||||
-rw-r--r-- | kbabel/datatools/arguments/kbabel_argstool.desktop | 106 | ||||
-rw-r--r-- | kbabel/datatools/arguments/main.cc | 277 | ||||
-rw-r--r-- | kbabel/datatools/arguments/main.h | 55 |
4 files changed, 457 insertions, 0 deletions
diff --git a/kbabel/datatools/arguments/Makefile.am b/kbabel/datatools/arguments/Makefile.am new file mode 100644 index 00000000..5585d438 --- /dev/null +++ b/kbabel/datatools/arguments/Makefile.am @@ -0,0 +1,19 @@ + +INCLUDES = -I$(srcdir)/../../common -I../../common $(all_includes) +kbabel_argstool_la_LIBADD = $(LIB_KIO) ../../common/libkbabelcommon.la + +####### Files + +kde_module_LTLIBRARIES = kbabel_argstool.la + +kbabel_argstool_la_SOURCES = main.cc + +kbabel_argstool_la_LDFLAGS = $(all_libraries) -avoid-version -module -no-undefined + +noinst_HEADERS = main.h + +kbabel_argstool_la_METASOURCES = AUTO + +service_DATA = kbabel_argstool.desktop +servicedir = $(kde_servicesdir) + diff --git a/kbabel/datatools/arguments/kbabel_argstool.desktop b/kbabel/datatools/arguments/kbabel_argstool.desktop new file mode 100644 index 00000000..e90ba652 --- /dev/null +++ b/kbabel/datatools/arguments/kbabel_argstool.desktop @@ -0,0 +1,106 @@ +[Desktop Entry] +Name=Argument Validation for KBabel +Name[bg]=Валидност на аргументите - KBabel +Name[bs]=Provjera argumenata za KBabel +Name[ca]=Validació dels arguments per a KBabel +Name[cs]=Validace argumentů pro KBabel +Name[cy]= Dilysiant Ymresymiad i KBabel +Name[da]=Argument-validering for KBabel +Name[de]=Argument-Überprüfung für KBabel +Name[el]=Έλεγχος εγκυρότητας ορισμάτων για το KBabel +Name[es]=Validació de argumentos para KBabel +Name[et]=KBabeli argumentide kontrollija +Name[eu]=Argumentu balidazioa KBabel-entzat +Name[fa]=اعتبارسنجی نشانوند برای KBabel +Name[fi]=Argumenttien tarkistus KBabelissa +Name[fr]=Validation d'un argument pour KBabel +Name[ga]=Bailíochtú Argóintí le haghaidh KBabel +Name[gl]=Validación de Argumentos para KBabel +Name[hi]=के-बेबल के लिए आर्गुमेंट वेलिडेशन +Name[hu]=Argumentumellenőrző a KBabelhez +Name[is]=Viðfangastaðfestir fyrir KBabel +Name[it]=Convalida argomenti per KBabel +Name[ja]=KBabel 引数検証 +Name[ka]=KBabel-ის არგუმენტთა დამმოწმებელი +Name[kk]=KBabel-дың аргументтерін тексеруі +Name[lt]=Kbabel argumentų patikros įrankis +Name[ms]=Pengesahan Argumen untuk KBabel +Name[nb]=Argumentsjekk for KBabel +Name[nds]=Argumentenprööv för KBabel +Name[ne]=केब्याबलका लागि विषय प्रमाणीकरण +Name[nl]=Argumentenvalidatie voor KBabel +Name[nn]=Argumentsjekk for KBabel +Name[pa]=ਕੇਬਬੇਲ ਲਈ ਆਰਗੂਮਿੰਟ ਪੜਤਾਲ +Name[pl]=Sprawdzenie argumentów w KBabel +Name[pt]=Validação de Argumentos para o KBabel +Name[pt_BR]=Validação de Argumentos para o KBabel +Name[ru]=Проверка аргументов для KBabel +Name[sk]=Kontrola argumentov pre KBabel +Name[sl]=Argumentni potrjevalnik za KBabel +Name[sr]=Овера аргумената за KBabel +Name[sr@Latn]=Overa argumenata za KBabel +Name[sv]=Validering av parametrar för Kbabel +Name[ta]= Kபாபேலுக்கு தருமதிப்பு செல்லுபடிச் சோதனை +Name[tg]=Тафтиши далелҳо барои KBabel +Name[tr]=KBabel için Hızlandırma Argümanı +Name[uk]=Перевірка аргументів для KBabel +Name[zh_CN]=KBabel 的参数检查器 +Name[zh_TW]=KBabel 的參數檢查器 +X-KDE-Library=kbabel_argstool +Type=Service +Commands=validate +Comment=Check Arguments +Comment[bg]=Проверка на аргументите +Comment[bs]=Provjeri argumente +Comment[ca]=Comprova els arguments +Comment[cs]=Zkontrolovat argumenty +Comment[cy]=Gwirio Ymresymiadau +Comment[da]=Tjek argumenter +Comment[de]=Argumente prüfen +Comment[el]=Έλεγχος ορισμάτων +Comment[eo]=Kontroli argumentojn +Comment[es]=Comprobar argumentos +Comment[et]=Argumentide kontroll +Comment[eu]=Egiaztatu argumentuak +Comment[fa]=بررسی نشانوندها +Comment[fi]=Tarkista argumentit +Comment[fr]=Vérification des arguments +Comment[ga]=Seiceáil Argóintí +Comment[gl]=Verificación dos argumentos +Comment[he]=בודק ארגומנטים +Comment[hi]=आर्गुमेंट जांच करें +Comment[hu]=Az argumentumok ellenőrzése +Comment[is]=Athuga viðföng +Comment[it]=Controlla argomenti +Comment[ja]=引数を検証 +Comment[ka]=არგუმენტების შემოწმება +Comment[kk]=Аргументтерді тексеру +Comment[lt]=Patikrinti argumentus +Comment[ms]=Periksa Argumen +Comment[nb]=Sjekk argumenter +Comment[nds]=Argumenten pröven +Comment[ne]=विषय जाँच गर्नुहोस् +Comment[nl]=Argumenten controleren +Comment[nn]=Sjekk argument +Comment[pa]=ਆਰਗੂਮਿੰਟ ਜਾਂਚ +Comment[pl]=Sprawdzenie argumentów +Comment[pt]=Verificação dos argumentos +Comment[pt_BR]=Verifica Argumentos +Comment[ru]=Проверить аргументы +Comment[sk]=Kontrola argumentov +Comment[sl]=Preveri argumente +Comment[sr]=Провери аргументе +Comment[sr@Latn]=Proveri argumente +Comment[sv]=Kontrollera parametrar +Comment[ta]= தருமதிப்புகளை சரிபார்ப்பு +Comment[tg]=Тафтиш кардани далелҳо +Comment[tr]=Argümanların Denetimi +Comment[uk]=Перевірити аргументи +Comment[zh_CN]=检查参数 +Comment[zh_TW]=檢查參數 +Shortcuts=Ctrl+D +ValidationString=arguments +ServiceTypes=KDataTool,KBabelValidator +DataType=CatalogItem +DataMimeTypes=application/x-kbabel-catalogitem +ReadOnly=true diff --git a/kbabel/datatools/arguments/main.cc b/kbabel/datatools/arguments/main.cc new file mode 100644 index 00000000..92c9765c --- /dev/null +++ b/kbabel/datatools/arguments/main.cc @@ -0,0 +1,277 @@ +/* This file is part of KBabel + based Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> + 2002-2003 Stanislav Visnovsky <visnovsky@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. + +*/ + +#include <resources.h> +#include "catalogitem.h" +#include "catalogsettings.h" +#include "main.h" + +#include <kconfig.h> +#include <kdebug.h> +#include <kgenericfactory.h> +#include <klocale.h> +#include <kmessagebox.h> + +/*************************************************** + * + * Factory + * + ***************************************************/ + +K_EXPORT_COMPONENT_FACTORY( kbabel_argstool, KGenericFactory<ArgumentTool> ( "kbabeldatatool" ) ) + +using namespace KBabel; + +ArgumentTool::ArgumentTool( QObject* parent, const char* name, const QStringList & ) + : KDataTool( parent, name ), _cache_origin( 0 ) +{ + i18n( "what check found errors","arguments"); +} + +bool ArgumentTool::run( const QString& command, void* data, const QString& datatype, const QString& mimetype ) +{ + if ( command != "validate" ) + { + kdDebug(KBABEL) << "Argument Tool does only accept the command 'validate' and 'shortcut'" << endl; + kdDebug(KBABEL) << " The commands " << command << " is not accepted" << endl; + return FALSE; + } + + // Check wether we can accept the data + if ( datatype != "CatalogItem" ) + { + kdDebug(KBABEL) << "Argument Tool only accepts datatype CatalogItem" << endl; + return FALSE; + } + + if ( mimetype != "application/x-kbabel-catalogitem" ) + { + kdDebug(KBABEL) << "Argument Tool only accepts mimetype application/x-kbabel-catalogitem" << endl; + return FALSE; + } + + if( command == "validate" ) + { + CatalogItem* item = (CatalogItem*)(data); + + if( item->isNoCformat() ) return true; + bool hasError = false; + + if( _cache_origin != item->project() ) + { + _context = item->project()->miscSettings().contextInfo; + _checkPlurals = item->project()->identitySettings().checkPluralArgument; + _cache_origin = item->project(); + } + + if(!item->isUntranslated()) + { + + QString formatChars="dioxXucsfeEgGp%"; + + if( _checkPlurals ) formatChars+="n"; + + // FIXME: this should care about plural forms in msgid + QString line=item->msgid().first(); + QStringList argList; + +// if( isPluralForm() ) + { + // FIXME: this is KDE specific + if( line.startsWith("_n:" )) + { + // truncate text after first \n to get args only once + line = line.mid(0,line.find("\\n")); + } + } + line.replace(_context, ""); + line.replace(QRegExp("\\n"),""); + line.simplifyWhiteSpace(); + + // flag, for GNU only we can allow reordering + bool non_gnu = (item->pluralForm() == KDESpecific); + + int index=line.find(QRegExp("%.")); + + while(index>=0) + { + int endIndex=line.find(QRegExp("[^\\d]"),index+1); + if(endIndex<0) + { + endIndex=line.length(); + } + else if( formatChars.contains(line[endIndex]) ) + { + endIndex++; + } + + if(endIndex - index > 1 ) { + QString arg = line.mid(index,endIndex-index); + if( arg.contains( QRegExp("\\d") ) ) { + non_gnu = true; + } + argList.append(arg); + + } + + index=line.find(QRegExp("%."),endIndex); + } + + if( item->pluralForm()==KDESpecific) + { + // FIXME: this is KDE specific + if( _checkPlurals && line.startsWith("_n:" ) && !argList.contains("%n") ) + { + argList.append("%n"); + } + } + + // generate for each plural form to be checked separately + line=item->msgstr().first(); + QStringList lines; + + // FIXME; this is KDE specific + if( item->pluralForm() == KDESpecific ) + { + lines = QStringList::split("\\n",line); + } + else + { + lines.append(line); + } + + QStringList argCache = argList; + QStringList foundArgs; + + for(QStringList::Iterator i = lines.begin() ; i!=lines.end() ; i++) + { + // initialize for the next plural form + foundArgs.clear(); + argList = argCache; + + line=(*i); + + line.replace(QRegExp("\\n"),""); + + QRegExp argdesc( + "%((["+formatChars+"])" + +"|(\\d)+" + +"|(\\d)+\\$(["+formatChars+"])" + +")" ) ; + index = -1; + + do { + + index = argdesc.search( line, index+1 ); + + if( index == -1 ) break; + + // do not add a redundant argument, if it is non GNU + if( !non_gnu || !foundArgs.contains( argdesc.cap(0) ) ) + foundArgs.append( argdesc.cap( 0 ) ); + } while( true ); + + // now, compare the list + argList = argCache; + + if( non_gnu ) { + for ( QStringList::Iterator it = foundArgs.begin(); it != foundArgs.end(); ++it ) { + if( argList.find( *it ) == argList.end() ) { + hasError = true; + break; + } else { + argList.remove( *it ); + } + } + + if( ! argList.isEmpty() ) { + hasError = true; + } + } + else + { + // handle GNU with replacements + QStringList::Iterator oit = argList.begin(); + for ( QStringList::Iterator it = foundArgs.begin(); it != foundArgs.end(); ++it , ++oit) { + if( *it == *oit ) { + // argument is the same, mark as used + *oit = QString::null; + } else { + // try to strip replacement + int index = (*it).find( '$' ); + if( index == -1 ) { + // there is no replacement, this is wrong + hasError = true; + break; + } + QString place = (*it).mid( 1, index-1 ); + QString arg = (*it).right( index ); + arg[0] = '%'; + QStringList::Iterator a = argList.at( place.toInt()-1 ); + if( a != argList.end() && (*a) == arg ) + { + (*a) = QString::null; + } + else + { + // duplicate or index is too high + hasError = true; + } + } + } + + for ( QStringList::Iterator it = argList.begin(); it != argList.end(); ++it) { + if( ! (*it).isNull () ) { + // argument is the same, mark as used + hasError = true; + break; + } + } + } + } + } + + if(hasError) + { + item->appendError( "Arguments" ); + } + else + { + item->removeError( "Arguments" ); + } + + return !hasError; + } + return FALSE; +} + +#include "main.moc" diff --git a/kbabel/datatools/arguments/main.h b/kbabel/datatools/arguments/main.h new file mode 100644 index 00000000..a05cce49 --- /dev/null +++ b/kbabel/datatools/arguments/main.h @@ -0,0 +1,55 @@ +/* This file is part of KBabel + based on Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> + 2002-2003 Stanislav Visnovsky <visnovsky@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. + +*/ + +#ifndef __main_h__ +#define __main_h__ + +#include "kbproject.h" + +#include <kdatatool.h> + +#include <qregexp.h> + +class ArgumentTool : public KDataTool +{ + Q_OBJECT + +public: + ArgumentTool( QObject* parent, const char* name, const QStringList & ); + virtual bool run( const QString& command, void* data, const QString& datatype, const QString& mimetype); +private: + KBabel::Project::Ptr _cache_origin; + QRegExp _context; + bool _checkPlurals; +}; + +#endif |