diff options
Diffstat (limited to 'kfile-plugins')
-rw-r--r-- | kfile-plugins/Makefile.am | 1 | ||||
-rw-r--r-- | kfile-plugins/c++/Makefile.am | 22 | ||||
-rw-r--r-- | kfile-plugins/c++/kfile_cpp.cpp | 130 | ||||
-rw-r--r-- | kfile-plugins/c++/kfile_cpp.desktop | 60 | ||||
-rw-r--r-- | kfile-plugins/c++/kfile_cpp.h | 40 | ||||
-rw-r--r-- | kfile-plugins/c++/kfile_h.desktop | 58 | ||||
-rw-r--r-- | kfile-plugins/diff/Makefile.am | 22 | ||||
-rw-r--r-- | kfile-plugins/diff/kfile_diff.cpp | 610 | ||||
-rw-r--r-- | kfile-plugins/diff/kfile_diff.desktop | 57 | ||||
-rw-r--r-- | kfile-plugins/diff/kfile_diff.h | 52 | ||||
-rw-r--r-- | kfile-plugins/ts/Makefile.am | 21 | ||||
-rw-r--r-- | kfile-plugins/ts/kfile_ts.cpp | 93 | ||||
-rw-r--r-- | kfile-plugins/ts/kfile_ts.desktop | 54 | ||||
-rw-r--r-- | kfile-plugins/ts/kfile_ts.h | 39 |
14 files changed, 1259 insertions, 0 deletions
diff --git a/kfile-plugins/Makefile.am b/kfile-plugins/Makefile.am new file mode 100644 index 00000000..aa4d2f43 --- /dev/null +++ b/kfile-plugins/Makefile.am @@ -0,0 +1 @@ +SUBDIRS=diff c++ ts diff --git a/kfile-plugins/c++/Makefile.am b/kfile-plugins/c++/Makefile.am new file mode 100644 index 00000000..4770b509 --- /dev/null +++ b/kfile-plugins/c++/Makefile.am @@ -0,0 +1,22 @@ +## Makefile.am for c++ file meta info plugin + +# set the include path for X, qt and KDE +INCLUDES = $(all_includes) + +# these are the headers for your project +noinst_HEADERS = kfile_cpp.h + +kde_module_LTLIBRARIES = kfile_cpp.la + +kfile_cpp_la_SOURCES = kfile_cpp.cpp +kfile_cpp_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +kfile_cpp_la_LIBADD = $(LIB_KIO) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: + $(XGETTEXT) *.cpp -o $(podir)/kfile_cpp.pot + +services_DATA = kfile_cpp.desktop kfile_h.desktop +servicesdir = $(kde_servicesdir) diff --git a/kfile-plugins/c++/kfile_cpp.cpp b/kfile-plugins/c++/kfile_cpp.cpp new file mode 100644 index 00000000..6c854a00 --- /dev/null +++ b/kfile-plugins/c++/kfile_cpp.cpp @@ -0,0 +1,130 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Rolf Magnus <ramagnus@kde.org> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation version 2. + * + * This program 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + +#include "kfile_cpp.h" + +#include <kurl.h> +#include <klocale.h> +#include <kgenericfactory.h> +#include <kdebug.h> + +#include <qfile.h> +#include <qregexp.h> + +typedef KGenericFactory<KCppPlugin> CppFactory; + +K_EXPORT_COMPONENT_FACTORY(kfile_cpp, CppFactory("kfile_cpp")) + +KCppPlugin::KCppPlugin(QObject *parent, const char *name, + const QStringList &args) + : KFilePlugin(parent, name, args) +{ + kdDebug(7034) << "c++ plugin\n"; + makeMimeTypeInfo("text/x-c++src"); + makeMimeTypeInfo("text/x-chdr"); +} + +void KCppPlugin::makeMimeTypeInfo(const QString& mimetype) +{ + KFileMimeTypeInfo* info = addMimeTypeInfo( mimetype ); + + KFileMimeTypeInfo::GroupInfo* group = + addGroupInfo(info, "General", i18n("General")); + + KFileMimeTypeInfo::ItemInfo* item; + item = addItemInfo(group, "Lines", i18n("Lines"), QVariant::Int); + setAttributes(item, KFileMimeTypeInfo::Averaged); + item = addItemInfo(group, "Code", i18n("Code"), QVariant::Int); + setAttributes(item, KFileMimeTypeInfo::Averaged); + item = addItemInfo(group, "Comment", i18n("Comment"), QVariant::Int); + setAttributes(item, KFileMimeTypeInfo::Averaged); + item = addItemInfo(group, "Blank", i18n("Blank"), QVariant::Int); + setAttributes(item, KFileMimeTypeInfo::Averaged); + item = addItemInfo(group, "Strings", i18n("Strings"), QVariant::Int); + setAttributes(item, KFileMimeTypeInfo::Averaged); + item = addItemInfo(group, "i18n Strings", i18n("i18n Strings"), QVariant::Int); + setAttributes(item, KFileMimeTypeInfo::Averaged); + item = addItemInfo(group, "Included Files", i18n("Included Files"), QVariant::Int); + setAttributes(item, KFileMimeTypeInfo::Averaged); +} + +bool KCppPlugin::readInfo( KFileMetaInfo& info, uint ) +{ + QFile f(info.path()); + if (!f.open(IO_ReadOnly)) + return false; + + int codeLines = 0; + int commentLines = 0; + int totalLines = 0; + int emptyLines = 0; + int Strings = 0; + int Stringsi18n = 0; + int Includes = 0; + + bool inComment = false; + + QString line; + + QTextStream stream( &f ); + while (!stream.eof()) + { + line = stream.readLine(); + totalLines++; + + if (line.stripWhiteSpace().isEmpty()) + { + emptyLines++; + continue; + } + + if (line.contains("/*")) inComment = true; + + if (!inComment) + { + codeLines++; + if (line.contains(QRegExp("^\\s*#\\s*include"))) Includes++; + + int pos = line.find("//"); + if (pos>=0) commentLines++; + // truncate the comment - we don't want to count strings in it + line.truncate(pos); + + Strings+=line.contains(QRegExp("\".*\"")); + Stringsi18n+=line.contains(QRegExp("(?:i18n|I18N_NOOP)\\s*\\(")); + } + else + commentLines++; + + if (line.contains("*/")) inComment = false; + } + + KFileMetaInfoGroup group = appendGroup(info, "General"); + + appendItem(group, "Lines", int(totalLines)); + appendItem(group, "Code", int(codeLines)); + appendItem(group, "Comment", int(commentLines)); + appendItem(group, "Blank", int(emptyLines)); + appendItem(group, "Strings", int(Strings)); + appendItem(group, "i18n Strings", int(Stringsi18n)); + appendItem(group, "Included Files", int(Includes)); + return true; +} + +#include "kfile_cpp.moc" diff --git a/kfile-plugins/c++/kfile_cpp.desktop b/kfile-plugins/c++/kfile_cpp.desktop new file mode 100644 index 00000000..2792aa9f --- /dev/null +++ b/kfile-plugins/c++/kfile_cpp.desktop @@ -0,0 +1,60 @@ +[Desktop Entry] +Type=Service +Name=C++ Info +Name[af]=C++ Inligting +Name[bg]=Изходен код на C++ +Name[br]=Titouroù C++ +Name[ca]=Informació C++ +Name[cs]=C++ info +Name[cy]=Gwybodaeth C++ +Name[da]=C++-info +Name[de]=C++-Info +Name[el]=Πληροφορίες C++ +Name[eo]=C++-informo +Name[es]=Info de C++ +Name[et]=C++ info +Name[eu]=C++ informazioa +Name[fa]=اطلاعات C++ +Name[fi]=C++-tiedot +Name[fo]=C++-upplýsingar +Name[fr]=Informations C++ +Name[ga]=Eolas C++ +Name[gl]=Información de C++ +Name[he]=מידע ++C +Name[hi]=C++ जानकारी +Name[hr]=C++ informacije +Name[hu]=C++-jellemzők +Name[is]=C++ upplýsingar +Name[it]=Informazioni C++ +Name[ja]=C++ 情報 +Name[ka]=C++ ინფორმაცია +Name[kk]=C++ мәліметі +Name[lt]=C++ Informacija +Name[ms]=Info C++ +Name[nds]=C++-Datei-Info +Name[nl]=C++-info +Name[nn]=C++-info +Name[pa]=C++ ਜਾਣਕਾਰੀ +Name[pl]=Informacja z C++ +Name[pt]=Informação de C++ +Name[pt_BR]=Informações C++ +Name[ro]=Informaţii C++ +Name[ru]=Информация C++ +Name[sk]=Informácie o C++ +Name[sl]=Informacije o C++ +Name[sr]=C++ информације +Name[sr@Latn]=C++ informacije +Name[sv]=C++-information +Name[ta]= =C/C++ தகவல் +Name[tg]=Ахбороти C++ +Name[th]=ข้อมูล C++ +Name[tr]=C++ Bilgisi +Name[uk]=Інформація про C++ +Name[xh]=C++ Ulwazi +Name[zh_CN]=C++ 信息 +Name[zh_TW]=C++ 資訊 +ServiceTypes=KFilePlugin +X-KDE-Library=kfile_cpp +MimeType=text/x-c++src;text/x-chdr +PreferredGroups=General +PreferredItems=Lines,Code,Comment,Blank,Strings,i18n Strings,Included Files diff --git a/kfile-plugins/c++/kfile_cpp.h b/kfile-plugins/c++/kfile_cpp.h new file mode 100644 index 00000000..d238858d --- /dev/null +++ b/kfile-plugins/c++/kfile_cpp.h @@ -0,0 +1,40 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Rolf Magnus <ramagnus@kde.org> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation version 2. + * + * This program 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + +#ifndef __KFILE_CPP_H__ +#define __KFILE_CPP_H__ + +#include <kfilemetainfo.h> +#include <kurl.h> + +class QStringList; + +class KCppPlugin: public KFilePlugin +{ + Q_OBJECT + +public: + KCppPlugin(QObject *parent, const char *name, const QStringList& args); + virtual bool readInfo(KFileMetaInfo& info, uint what); + +private: + void makeMimeTypeInfo(const QString& mimetype); +}; + +#endif diff --git a/kfile-plugins/c++/kfile_h.desktop b/kfile-plugins/c++/kfile_h.desktop new file mode 100644 index 00000000..b0766114 --- /dev/null +++ b/kfile-plugins/c++/kfile_h.desktop @@ -0,0 +1,58 @@ +[Desktop Entry] +Type=Service +Name=C/C++ Header Info +Name[af]=C/C++ Opskrif Inligting +Name[bg]=Информация за заглавната част на C/C++ +Name[br]=Titouriñ diwar-benn ar reollin C/C++ +Name[ca]=Informació de capçaleres C/C++ +Name[cs]=Informace o C/C++ hlavičce +Name[cy]=Gwybodaeth Pennawd C/C++ +Name[da]=C/C++-headerinfo +Name[de]=C++-Header-Info +Name[el]=Πληροφορίες κεφαλίδων C/C++ +Name[es]=Info de cabecera C/C++ +Name[et]=C/C++ päise info +Name[eu]=C/C++ goiburuen informazioa +Name[fa]=اطلاعات سرآیند C/C++ +Name[fi]=C/C++-otsikkotiedot +Name[fr]=Informations d'en-tête C/C++ +Name[gl]=Información da cabeceira de C/C++ +Name[he]=מידע כותרות ++C/C +Name[hi]=C/C++ हेडर जानकारी +Name[hr]=Informacije o C++ zaglavljima +Name[hu]=C/C++ header fájl jellemzői +Name[is]=C/C++ haus upplýsingar +Name[it]=Informazioni intestazioni C/C++ +Name[ja]=C/C++ ヘッダ情報 +Name[ka]=C/C++ ზედა კოლონტიტულის ინფორმაცია +Name[kk]=C/C++ айдар мәліметі +Name[lt]=C/C++ antraščių informacija +Name[ms]=Info Pengepala C/C++ +Name[nb]=C++-deklarasjonsfilinfo +Name[nds]=C/C++-Koppdatei-Info +Name[ne]=C/C++ Header info +Name[nl]=C/C++ Header-info +Name[nn]=C/C++-deklarasjonsinfo +Name[pa]=C/C++ Header ਜਾਣਕਾਰੀ +Name[pl]=Informacja z nagłówka C/C++ +Name[pt]=Informações do Cabeçalho de C/C++ +Name[pt_BR]=Informações sobre Cabeçalhos C/C++ +Name[ro]=Informaţii antet C/C++ +Name[ru]=Информация о файлах заголовков C/C++ +Name[sk]=Informácie o hlavičkách C/C++ +Name[sl]=Informacije o glavi C/C++ +Name[sr]=Информације о C/C++ заглављу +Name[sr@Latn]=Informacije o C/C++ zaglavlju +Name[sv]=Information om C/C++-deklarationsfiler +Name[ta]= =C/C++ தலைப்பு தகவல் +Name[tg]=Ахборот дар бораи сарлавҳаи файлҳои C/C++ +Name[th]=ข้อมูลแฟ้มส่วนหัว C/C++ +Name[tr]=C/C++ Başlık Bilgisi +Name[uk]=Інформація по заголовкам C++ +Name[xh]=C/C++ Ulwazi lokubhaliweyo okuphezulu +Name[zh_CN]=C/C++ 头文件信息 +Name[zh_TW]=C/C++ 檔頭資訊 +ServiceTypes=KFilePlugin +X-KDE-Library=kfile_cpp +MimeType=text/x-chdr +PreferredItems=Lines,Code,Comment,Blank,Strings,i18n Strings,Included Files diff --git a/kfile-plugins/diff/Makefile.am b/kfile-plugins/diff/Makefile.am new file mode 100644 index 00000000..ea6cccc0 --- /dev/null +++ b/kfile-plugins/diff/Makefile.am @@ -0,0 +1,22 @@ +## Makefile.am for diff file meta info plugin + +# set the include path for X, qt and KDE +INCLUDES = $(all_includes) + +# these are the headers for your project +noinst_HEADERS = kfile_diff.h + +kde_module_LTLIBRARIES = kfile_diff.la + +kfile_diff_la_SOURCES = kfile_diff.cpp +kfile_diff_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +kfile_diff_la_LIBADD = $(LIB_KSYCOCA) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: + $(XGETTEXT) *.cpp *.h -o $(podir)/kfile_diff.pot + +services_DATA = kfile_diff.desktop +servicesdir = $(kde_servicesdir) diff --git a/kfile-plugins/diff/kfile_diff.cpp b/kfile-plugins/diff/kfile_diff.cpp new file mode 100644 index 00000000..0f2fa02d --- /dev/null +++ b/kfile-plugins/diff/kfile_diff.cpp @@ -0,0 +1,610 @@ +/************************************************************************** +** kfile_diff.cpp +** ------------------- +** begin : Sun Jan 20 23:25:44 2002 +** copyright : (C) 2002-2003 by Otto Bruggeman +** email : otto.bruggeman@home.nl +** +***************************************************************************/ +/*************************************************************************** +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +***************************************************************************/ + +/* +** Patch by Volker Augustin for empty diff files. Februari 8, 2002 +** +** Patched to work with CVS from after February 26, 2002 Otto +** +** Patched to work with CVS from after March 24, 2002 Otto +** +** Added support for Perforce diffs, April 26, 2003 Otto Bruggeman +** +** Added support for Subversion diffs, September 11, 2003 Otto Bruggeman +*/ + +#include <qcstring.h> +#include <qdatetime.h> +#include <qdict.h> +#include <qfile.h> +#include <qregexp.h> +#include <qvalidator.h> + +#include <kdebug.h> +#include <kgenericfactory.h> +#include <klocale.h> +#include <kprocess.h> +#include <kurl.h> + +#include "kfile_diff.h" + +K_EXPORT_COMPONENT_FACTORY(kfile_diff, KGenericFactory<KDiffPlugin>("kfile_diff")) + +KDiffPlugin::KDiffPlugin(QObject *parent, const char *name, + const QStringList &preferredItems) + : KFilePlugin(parent, name, preferredItems) +{ + kdDebug(7034) << "diff plugin" << endl; + + KFileMimeTypeInfo* info = addMimeTypeInfo( "text/x-diff" ); + + KFileMimeTypeInfo::GroupInfo* group; + group = addGroupInfo( info, "General", i18n( "General" ) ); + addItemInfo( group, "Files", i18n( "Files" ), QVariant::UInt ); + addItemInfo( group, "First", i18n( "First File" ), QVariant::String ); + addItemInfo( group, "Format", i18n( "Format" ), QVariant::String ); + addItemInfo( group, "DiffProgram", i18n( "Diff Program" ), QVariant::String ); + addItemInfo( group, "Hunks", i18n( "Hunks" ), QVariant::UInt ); + group = addGroupInfo( info, "Statistics", i18n( "Statistics" ) ); + addItemInfo( group, "Insert", i18n( "Insertions" ), QVariant::UInt ); + addItemInfo( group, "Modify", i18n( "Changes" ), QVariant::UInt ); + addItemInfo( group, "Delete", i18n( "Deletions" ), QVariant::UInt ); +} + +bool KDiffPlugin::readInfo( KFileMetaInfo& info, uint what ) +{ + // This is a hack to avoid using the what stuff, since it is not yet implemented + what = 0; + + // Used to determine if false or true should be returned + bool dataSet = false; + + KFileMetaInfoGroup group; + + QFile file( info.path() ); + QStringList lines; + + if( file.open( IO_ReadOnly ) ) + { + QTextStream stream( &file ); + while (!stream.eof()) + { + lines.append( stream.readLine() ); + } + file.close(); + } + + QString format; + QString program; + + enum KDiffPlugin::Format diffFormat; + enum KDiffPlugin::DiffProgram diffProgram; + + diffFormat = determineDiffFormat ( lines ); + + format = determineI18nedFormat( diffFormat ); + + diffProgram = determineDiffProgram( lines ); + + program = determineI18nedProgram( diffProgram ); + + int numberOfAdditions = 0; + int numberOfDeletions = 0; + int numberOfChanges = 0; + int numberOfHunks = 0; + int numberOfFiles = 0; + + + if ( what != KFileMetaInfo::Fastest ) + { + determineDiffInfo( lines, diffFormat, &numberOfFiles, &numberOfHunks, &numberOfAdditions, &numberOfChanges, &numberOfDeletions ); + } + + QString filename; + QRegExp firstFile( "^Index: (.*)" ); + QStringList::ConstIterator it = lines.begin(); + + it = lines.begin(); + while ( it != lines.end() ) + { + if ( firstFile.exactMatch( (*it) ) ) + { + filename = firstFile.cap(1); + // only interested in the first filename + break; + } + ++it; + } + + kdDebug(7034) << "Diff Format : " << format << endl; // i18n-ed but that is not a problem unless i get i18n-ed debug output ah well, we'll figure something out when then happens + + if (what != KFileMetaInfo::Fastest ) + { + // These dont get calculated in fastest mode... + kdDebug(7034) << "Number of additions : " << numberOfAdditions << endl; + kdDebug(7034) << "Number of deletions : " << numberOfDeletions << endl; + kdDebug(7034) << "Number of changes : " << numberOfChanges << endl; + kdDebug(7034) << "Number of hunks : " << numberOfHunks << endl; + } + + group = appendGroup( info, "General" ); + + if ( numberOfFiles != 0 && what != KFileMetaInfo::Fastest ) + { + appendItem( group, "Files", numberOfFiles ); + dataSet = true; + } + + if ( !filename.isEmpty() ) + { + appendItem( group, "First", filename ); + dataSet = true; + } + + if ( !format.isEmpty() ) + { + appendItem( group, "Format", format ); + dataSet = true; + } + + if ( !program.isEmpty() ) + { + appendItem( group, "DiffProgram", program ); + dataSet = true; + } + + if ( numberOfHunks != 0 && what != KFileMetaInfo::Fastest ) + { + appendItem( group, "Hunks", numberOfHunks ); + dataSet = true; + } + + group = appendGroup( info, "Statistics" ); + + if ( numberOfAdditions != 0 && what != KFileMetaInfo::Fastest ) + { + appendItem( group, "Insert", numberOfAdditions ); + dataSet = true; + } + + if ( numberOfChanges != 0 && what != KFileMetaInfo::Fastest ) + { + appendItem( group, "Modify", numberOfChanges ); + dataSet = true; + } + + if ( numberOfDeletions != 0 && what != KFileMetaInfo::Fastest ) + { + appendItem( group, "Delete", numberOfDeletions ); + dataSet = true; + } + + return dataSet; +} + +enum KDiffPlugin::Format KDiffPlugin::determineDiffFormat( const QStringList lines ) const +{ + QString line; + + if ( lines.count() == 0 ) + { + return KDiffPlugin::Empty; + } + + QStringList::ConstIterator it = lines.begin(); + + while ( it != lines.end() ) + { + line = (*it); + if ( line.find( QRegExp( "^[0-9]+[0-9,]*[acd][0-9]+[0-9,]*$" ), 0 ) == 0 ) + { + return KDiffPlugin::Normal; + } + else if ( line.find( QRegExp( "^--- " ), 0 ) == 0 ) + { + // unified has first a '^--- ' line, then a '^+++ ' line + return KDiffPlugin::Unified; + } + else if ( line.find( QRegExp( "^\\*\\*\\* [^\\t]+\\t" ), 0 ) == 0 ) + { + // context has first a '^*** ' line, then a '^--- ' line + return KDiffPlugin::Context; + } + else if ( line.find( QRegExp( "^[acd][0-9]+ [0-9]+" ), 0 ) == 0 ) + { + return KDiffPlugin::RCS; + } + else if ( line.find( QRegExp( "^[0-9]+[0-9,]*[acd]" ), 0 ) == 0 ) + { + return KDiffPlugin::Ed; + } + ++it; + } + return KDiffPlugin::Unknown; +} + +enum KDiffPlugin::DiffProgram KDiffPlugin::determineDiffProgram( const QStringList lines ) const +{ + if ( lines.count() == 0 ) + { + return KDiffPlugin::Undeterminable; + } + + QStringList::ConstIterator it = lines.begin(); + // very crude, might need some more refining + QRegExp diffRE( "^diff .*" ); + QRegExp p4sRE("^==== "); + + bool indexFound = false; + + while ( it != lines.end() ) + { + if ( (*it).startsWith( "Index:" ) ) + indexFound = true; + else if ( (*it).startsWith( "retrieving revision") ) + return KDiffPlugin::CVSDiff; + else if ( diffRE.exactMatch( *it ) ) + return KDiffPlugin::Diff; + else if ( p4sRE.exactMatch( *it ) ) + return KDiffPlugin::Perforce; + + ++it; + } + + if ( indexFound ) // but no "retrieving revision" found like only cvs diff adds. + return KDiffPlugin::SubVersion; + + return KDiffPlugin::Undeterminable; +} + +const QString KDiffPlugin::determineI18nedFormat( enum KDiffPlugin::Format diffFormat ) const +{ + QString format; + switch( diffFormat ) + { + case KDiffPlugin::Context: + format = i18n( "Context" ); + break; + case KDiffPlugin::Ed: + format = i18n( "Ed" ); + break; + case KDiffPlugin::Normal: + format = i18n( "Normal" ); + break; + case KDiffPlugin::RCS: + format = i18n( "RCS" ); + break; + case KDiffPlugin::Unified: + format = i18n( "Unified" ); + break; + case KDiffPlugin::Empty: + format = i18n( "Not Available (file empty)" ); + break; + case KDiffPlugin::Unknown: + format = i18n( "Unknown" ); + break; + case KDiffPlugin::SideBySide: + format = i18n( "Side by Side" ); + } + return format; +} + +const QString KDiffPlugin::determineI18nedProgram( enum KDiffPlugin::DiffProgram diffProgram ) const +{ + QString program; + + switch( diffProgram ) + { + case KDiffPlugin::CVSDiff: + program = i18n( "CVSDiff" ); + break; + case KDiffPlugin::Diff: + program = i18n( "Diff" ); + break; + case KDiffPlugin::Diff3: + program = i18n( "Diff3" ); + break; + case KDiffPlugin::Perforce: + program = i18n( "Perforce" ); + break; + case KDiffPlugin::SubVersion: + program = i18n( "SubVersion" ); + break; + case KDiffPlugin::Undeterminable: + program = i18n( "Unknown" ); + break; + } + return program; +} + +void KDiffPlugin::determineDiffInfo( const QStringList lines, + enum KDiffPlugin::Format diffFormat, + int* numberOfFiles, + int* numberOfHunks, + int* numberOfAdditions, + int* numberOfChanges, + int* numberOfDeletions ) +{ + QString line; + + QRegExp edAdd( "([0-9]+)(|,([0-9]+))a" ); + QRegExp edDel( "([0-9]+)(|,([0-9]+))d" ); + QRegExp edMod( "([0-9]+)(|,([0-9]+))c" ); + + QRegExp normalAdd( "[0-9]+a([0-9]+)(|,([0-9]+))" ); + QRegExp normalDel( "([0-9]+)(|,([0-9]+))d(|[0-9]+)" ); + QRegExp normalMod( "([0-9]+)(|,([0-9]+))c([0-9]+)(|,([0-9]+))" ); + + QRegExp rcsAdd( "a[0-9]+ ([0-9]+)" ); + QRegExp rcsDel( "d[0-9]+ ([0-9]+)" ); + + QStringList::ConstIterator it = lines.begin(); + + switch( diffFormat ) + { + case KDiffPlugin::Context: + while ( it != lines.end() ) + { + if ( (*it).startsWith("***************") ) + { + (*numberOfHunks)++; +// kdDebug(7034) << "Context Hunk : " << (*it) << endl; + } + else if ( (*it).startsWith("***") ) + { + (*numberOfFiles)++; +// kdDebug(7034) << "Context File : " << (*it) << endl; + } + else if ( (*it).startsWith("---") ) {} // ignore + else if ( (*it).startsWith("+") ) + { + (*numberOfAdditions)++; +// kdDebug(7034) << "Context Insertion : " << (*it) << endl; + } + else if ( (*it).startsWith("-") ) + { + (*numberOfDeletions)++; +// kdDebug(7034) << "Context Deletion : " << (*it) << endl; + } + else if ( (*it).startsWith("!") ) + { + (*numberOfChanges)++; +// kdDebug(7034) << "Context Modified : " << (*it) << endl; + } + else if ( (*it).startsWith(" ") ) + { +// kdDebug(7034) << "Context Context : " << (*it) << endl; + } + else + { +// kdDebug(7034) << "Context Unknown : " << (*it) << endl; + } + + ++it; + } + (*numberOfChanges) /= 2; // changes are in both parts of the hunks + (*numberOfFiles) -= (*numberOfHunks); // it counts old parts of a hunk as files :( + break; + case KDiffPlugin::Ed: + while ( it != lines.end() ) + { + if ( (*it).startsWith( "diff" ) ) + { + (*numberOfFiles)++; +// kdDebug(7034) << "Ed File : " << (*it) << endl; + } + else if ( edAdd.exactMatch( (*it) ) ) + { +// kdDebug(7034) << "Ed Insertion : " << (*it) << endl; + (*numberOfHunks)++; + ++it; + while( it != lines.end() && !(*it).startsWith(".") ) + { + (*numberOfAdditions)++; +// kdDebug(7034) << "Ed Insertion : " << (*it) << endl; + ++it; + } + } + else if ( edDel.exactMatch( (*it) ) ) + { +// kdDebug(7034) << "Ed Deletion : " << (*it) << endl; + (*numberOfHunks)++; + (*numberOfDeletions) += (edDel.cap(3).isEmpty() ? 1 : edDel.cap(3).toInt() - edDel.cap(1).toInt() + 1); +// kdDebug(7034) << "Ed noOfLines : " << (edDel.cap(3).isEmpty() ? 1 : edDel.cap(3).toInt() - edDel.cap(1).toInt() + 1) << endl; + } + else if ( edMod.exactMatch( (*it) ) ) + { +// kdDebug(7034) << "Ed Modification : " << (*it) << endl; + if ( edMod.cap(3).isEmpty() ) + (*numberOfDeletions)++; + else + (*numberOfDeletions) += edMod.cap(3).toInt() - edMod.cap(1).toInt() + 1; + (*numberOfHunks)++; + ++it; + while( it != lines.end() && !(*it).startsWith(".") ) + { + (*numberOfAdditions)++; +// kdDebug(7034) << "Ed Modification : " << (*it) << endl; + ++it; + } + } + else + { +// kdDebug(7034) << "Ed Unknown : " << (*it) << endl; + } + + ++it; + } + break; + case KDiffPlugin::Normal: + while ( it != lines.end() ) + { + if ( (*it).startsWith( "diff" ) ) + { + (*numberOfFiles)++; +// kdDebug(7034) << "Normal File : " << (*it) << endl; + } + else if ( normalAdd.exactMatch( *it ) ) + { +// kdDebug(7034) << "Normal Insertion : " << (*it) << endl; + (*numberOfHunks)++; + if ( normalAdd.cap(3).isEmpty() ) + { + (*numberOfAdditions)++; +// kdDebug(7034) << "Normal Addition : " << 1 << endl; + } + else + { + (*numberOfAdditions) += normalAdd.cap(3).toInt() - normalAdd.cap(1).toInt() + 1; +// kdDebug(7034) << "Normal Addition : " << normalAdd.cap(3).toInt() - normalAdd.cap(1).toInt() + 1 << endl; + } + } + else if ( normalDel.exactMatch( *it ) ) + { +// kdDebug(7034) << "Normal Deletion : " << (*it) << endl; + (*numberOfHunks)++; + if ( normalDel.cap(3).isEmpty() ) + { + (*numberOfDeletions)++; +// kdDebug(7034) << "Normal Deletion : " << 1 << endl; + } + else + { + (*numberOfDeletions) += normalDel.cap(3).toInt() - normalDel.cap(1).toInt() + 1; +// kdDebug(7034) << "Normal Deletion : " << normalDel.cap(3).toInt() - normalDel.cap(1).toInt() + 1 << endl; + } + } + else if ( normalMod.exactMatch( *it ) ) + { +// kdDebug(7034) << "Normal Modification : " << (*it) << endl; + (*numberOfHunks)++; + if ( normalMod.cap(3).isEmpty() ) + { + (*numberOfDeletions)++; +// kdDebug(7034) << "Normal Deletion : " << 1 << endl; + } + else + { + (*numberOfDeletions) += normalMod.cap(3).toInt() - normalMod.cap(1).toInt() + 1; +// kdDebug(7034) << "Normal Deletion : " << normalMod.cap(3).toInt() - normalMod.cap(1).toInt() + 1 << endl; + } + if ( normalMod.cap(6).isEmpty() ) + { + (*numberOfAdditions)++; +// kdDebug(7034) << "Normal Addition : " << 1 << endl; + } + else + { + (*numberOfAdditions) += normalMod.cap(6).toInt() - normalMod.cap(4).toInt() + 1; +// kdDebug(7034) << "Normal Addition : " << normalMod.cap(6).toInt() - normalMod.cap(4).toInt() + 1 << endl; + } + } + else if ( (*it).startsWith(">") ) + { +// numberOfAdditions++; +// kdDebug(7034) << "Normal Insertion : " << (*it) << endl; + } + else if ( (*it).startsWith("<") ) + { +// numberOfDeletions++; +// kdDebug(7034) << "Normal Deletion : " << (*it) << endl; + } + else + { +// kdDebug(7034) << "Normal Unknown : " << (*it) << endl; + } + + ++it; + } + break; + case KDiffPlugin::RCS: + while ( it != lines.end() ) + { + if ( (*it).startsWith( "diff" ) ) // works for cvs diff, have to test for normal diff + { +// kdDebug(7034) << "RCS File : " << (*it) << endl; + (*numberOfFiles)++; + } + else if ( rcsAdd.exactMatch( *it ) ) + { +// kdDebug(7034) << "RCS Insertion : " << (*it) << endl; + (*numberOfHunks)++; + (*numberOfAdditions) += rcsAdd.cap(1).toInt(); +// kdDebug(7034) << "RCS noOfLines : " << rcsAdd.cap(1).toInt() << endl; + } + else if ( rcsDel.exactMatch( *it ) ) + { +// kdDebug(7034) << "RCS Deletion : " << (*it) << endl; + (*numberOfHunks)++; + (*numberOfDeletions) += rcsDel.cap(1).toInt(); +// kdDebug(7034) << "RCS noOfLines : " << rcsDel.cap(1).toInt() << endl; + } + else + { +// kdDebug(7034) << "RCS Unknown : " << (*it) << endl; + } + + ++it; + } + break; + case KDiffPlugin::Unified: + while ( it != lines.end() ) + { + if ( (*it).startsWith("@@ ") ) + { + (*numberOfHunks)++; +// kdDebug(7034) << "Unified Hunk : " << (*it) << endl; + } + else if ( (*it).startsWith("---") ) + { + (*numberOfFiles)++; +// kdDebug(7034) << "Unified File : " << (*it) << endl; + } + else if ( (*it).startsWith("+++") ) {} // ignore (dont count as insertion) + else if ( (*it).startsWith("+") ) + { + (*numberOfAdditions)++; +// kdDebug(7034) << "Unified Insertion : " << (*it) << endl; + } + else if ( (*it).startsWith("-") ) + { + (*numberOfDeletions)++; +// kdDebug(7034) << "Unified Deletion : " << (*it) << endl; + } + else if ( (*it).startsWith(" ") ) + { +// kdDebug(7034) << "Unified Context : " << (*it) << endl; + } + else + { +// kdDebug(7034) << "Unified Unknown : " << (*it) << endl; + } + + ++it; + } + break; + case KDiffPlugin::Empty: + case KDiffPlugin::Unknown: + case KDiffPlugin::SideBySide: + break; + } +} + +#include "kfile_diff.moc" + +/* vim: set ts=4 sw=4 noet: */ + diff --git a/kfile-plugins/diff/kfile_diff.desktop b/kfile-plugins/diff/kfile_diff.desktop new file mode 100644 index 00000000..95b0bb78 --- /dev/null +++ b/kfile-plugins/diff/kfile_diff.desktop @@ -0,0 +1,57 @@ +[Desktop Entry] +Type=Service +Name=Diff Stats +Name[af]=Diff Statistiek +Name[bg]=Статистика за разлики +Name[br]=Stadegoù Diff +Name[bs]=Diff statistika +Name[ca]=Estadístiques de diff +Name[cs]=Statistika rozdílů +Name[cy]=Ystadegau Gwahaniaethau +Name[da]=Diff-stats +Name[de]=Diff-Statistiken +Name[el]=Στατιστικά diff +Name[es]=Estadísticas Diff +Name[et]=Võrdlemise tulemused +Name[eu]=Desberdintasun estatistikak +Name[fa]=آمارهای Diff +Name[fi]=Diff-tilastot +Name[fr]=Statistiques de diff +Name[ga]=Staitistic Diff +Name[gl]=Estatísticas de diff +Name[he]=סטטיסטיקת Diff +Name[hi]=डिफ स्टेट्स +Name[hr]=Diff statistike +Name[hu]=Diff statisztika +Name[it]=Statistiche di confronto +Name[ja]=Diff 統計 +Name[kk]=Diff статистикасы +Name[lt]=Skirtumų statistika +Name[ms]=Stat Diff +Name[nb]=Diff-statistikk +Name[nds]=Verscheelstatistiken +Name[ne]=भिन्न तथ्याङ्क +Name[nl]=Diff-statistieken +Name[nn]=Diff-statistikk +Name[pa]=ਅੰਤਰ ਹਾਲਤ +Name[pl]=Statystyka różnic +Name[pt]=Estatísticas do diff +Name[pt_BR]=Estados do Diff +Name[ro]=Statistici Diff +Name[ru]=Статистика различий +Name[sk]=Štatistiky Diff +Name[sl]=Statistike diff +Name[sr]=Статистика разликовања +Name[sr@Latn]=Statistika razlikovanja +Name[sv]=Diff-statistik +Name[ta]=டிப் ஸ்டட்ஸ் +Name[tg]=Статистикаи фарқият +Name[th]=สถานะแตกต่าง +Name[tr]=Diff İstatistikleri +Name[uk]=Статистика відмінностей +Name[zh_CN]=Diff 统计 +Name[zh_TW]=Diff 狀態 +ServiceTypes=KFilePlugin +X-KDE-Library=kfile_diff +MimeType=text/x-diff +PreferredItems=Files,First,Format,Hunks,Insert,Modify,Delete diff --git a/kfile-plugins/diff/kfile_diff.h b/kfile-plugins/diff/kfile_diff.h new file mode 100644 index 00000000..d32e176c --- /dev/null +++ b/kfile-plugins/diff/kfile_diff.h @@ -0,0 +1,52 @@ +/************************************************************************** +** kfile_diff.h +** ------------------- +** begin : Sun Jan 20 23:25:29 2002 +** copyright : (C) 2002 by Otto Bruggeman +** email : otto.bruggeman@home.nl +** +***************************************************************************/ +/*************************************************************************** +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +***************************************************************************/ + +#ifndef __KFILE_PDF_H__ +#define __KFILE_PDF_H__ + +#include <kfilemetainfo.h> + +class QStringList; + +class KDiffPlugin: public KFilePlugin +{ + Q_OBJECT + +public: + KDiffPlugin( QObject *parent, const char *name, + const QStringList& preferredItems ); + + + virtual bool readInfo( KFileMetaInfo& info, uint what ); + +public: + enum Format { Context, Ed, Normal, RCS, Unified, Empty, SideBySide, Unknown }; + enum DiffProgram { CVSDiff, Diff, Diff3, Perforce, SubVersion, Undeterminable }; // cant use Unknown again :( + +private: + enum Format determineDiffFormat ( const QStringList lines ) const; + enum DiffProgram determineDiffProgram ( const QStringList lines ) const; + const QString determineI18nedFormat ( enum KDiffPlugin::Format diffFormat ) const; + const QString determineI18nedProgram( enum KDiffPlugin::DiffProgram diffProgram ) const; + // yes ugly, it's better to use a struct or classmembers to pass these parameters around + void determineDiffInfo ( const QStringList lines, + enum KDiffPlugin::Format diffFormat, int* numberOfFiles, + int* numberOfHunks, int* numberOfAdditions, + int* numberOfChanges, int* numberOfDeletions ); +}; + +#endif diff --git a/kfile-plugins/ts/Makefile.am b/kfile-plugins/ts/Makefile.am new file mode 100644 index 00000000..dd64ec48 --- /dev/null +++ b/kfile-plugins/ts/Makefile.am @@ -0,0 +1,21 @@ +## Makefile.am for text file meta info plugin + +# set the include path for X, qt and KDE +INCLUDES = $(all_includes) + +noinst_HEADERS = kfile_ts.h + +kde_module_LTLIBRARIES = kfile_ts.la + +kfile_ts_la_SOURCES = kfile_ts.cpp +kfile_ts_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +kfile_ts_la_LIBADD = $(LIB_KIO) + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: + $(XGETTEXT) *.cpp -o $(podir)/kfile_ts.pot + +services_DATA = kfile_ts.desktop +servicesdir = $(kde_servicesdir) diff --git a/kfile-plugins/ts/kfile_ts.cpp b/kfile-plugins/ts/kfile_ts.cpp new file mode 100644 index 00000000..d6783fd7 --- /dev/null +++ b/kfile-plugins/ts/kfile_ts.cpp @@ -0,0 +1,93 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Carsten Niehaus <cniehaus@kde.org> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation version 2. + * + * This program 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + +#include "kfile_ts.h" + +#include <kgenericfactory.h> +#include <kdebug.h> + +#include <qfile.h> +#include <qstringlist.h> + +typedef KGenericFactory<KTsPlugin> TsFactory; + +K_EXPORT_COMPONENT_FACTORY(kfile_ts, TsFactory("kfile_ts")) + +KTsPlugin::KTsPlugin(QObject *parent, const char *name, + const QStringList &args) : KFilePlugin(parent, name, args) +{ + makeMimeTypeInfo( "application/x-linguist" ); +} + +void KTsPlugin::makeMimeTypeInfo(const QString& mimeType) +{ + KFileMimeTypeInfo* info = addMimeTypeInfo(mimeType); + + KFileMimeTypeInfo::GroupInfo* group = + addGroupInfo(info, "General", i18n("General")); + + KFileMimeTypeInfo::ItemInfo* item; + item = addItemInfo(group, "Messages", i18n("Messages"), QVariant::Int); + setAttributes(item, KFileMimeTypeInfo::Averaged); + item = addItemInfo(group, "Translated", i18n("Translated"), QVariant::Int); + setAttributes(item, KFileMimeTypeInfo::Averaged); + item = addItemInfo(group, "Untranslated", i18n("Untranslated"), QVariant::Int); + setAttributes(item, KFileMimeTypeInfo::Averaged); + item = addItemInfo(group, "Obsolete", i18n("Obsolete"), QVariant::Int); +} + +bool KTsPlugin::readInfo(KFileMetaInfo& info, uint) +{ + QFile f(info.path()); + if (!f.open(IO_ReadOnly)) + return false; + + int messages = 0; + int untranslated = 0; + int obsolete = 0; + + QTextStream stream( &f ); + QString line = stream.readLine(); + + // is it really a linguist file? + if (!line.contains("<!DOCTYPE TS>", false)) + return false; + + while (!stream.eof()) + { + line = stream.readLine(); + + if (line.contains("type=\"obsolete\"")) obsolete++; + + if (line.contains("<source>")) messages++; + + if (line.contains("type=\"unfinished\"")) untranslated++; + + } + + KFileMetaInfoGroup group = appendGroup(info, "General"); + appendItem(group, "Messages", messages); + appendItem(group, "Translated", messages-untranslated-obsolete); + appendItem(group, "Untranslated", untranslated); + appendItem(group, "Obsolete", obsolete); + + return true; +} + +#include "kfile_ts.moc" diff --git a/kfile-plugins/ts/kfile_ts.desktop b/kfile-plugins/ts/kfile_ts.desktop new file mode 100644 index 00000000..09c3ae7d --- /dev/null +++ b/kfile-plugins/ts/kfile_ts.desktop @@ -0,0 +1,54 @@ +[Desktop Entry] +Type=Service +Name=Qt Linguist File Info +Name[bg]=Информация за файла Qt Linguist +Name[br]=Restr titouroù Qt Linguist +Name[bs]=Qt Linguist informacije o datoteci +Name[ca]=Informació fitxer de Qt Linguist +Name[cs]=Info o souboru Qt Linguist +Name[cy]=Gwybodaeth Ffeil Qt Linguist +Name[da]=Qt Linguist Fil-info +Name[de]=Qt Linguist-Dateiinfo +Name[el]=Πληροφορίες αρχείου Qt Linguist +Name[es]=Información de archivo de Qt Linguist +Name[et]=Qt Linguisti faili info +Name[eu]=Qt Linguist fitxategi informazioa +Name[fa]=اطلاعات پروندۀ زبانشناسQt +Name[fi]=Qt Linquist -tiedoston tiedot +Name[fr]=Fichier d'informations Qt Linguist +Name[ga]=Eolas faoi Chomhad Qt Linguist +Name[gl]=Información do Ficheiro de Qt Linguist +Name[hi]=क्यूटी लिंग्विस्ट फ़ाइल जानकारी +Name[hu]=Qt Linguist fájljellemzők +Name[is]=Qt Linguist skráarupplýsingar +Name[it]=Informazioni file per Qt Linguist +Name[ja]=Qt Linguist ファイル情報 +Name[ka]=Qt Linguist ფაილის ინფორმაცია +Name[kk]=Qt Linguist файл мәліметі +Name[lt]=Qt Linguist bylos informacija +Name[nb]=Informasjon om Qt Linguist-fil +Name[nds]=QtLinguist-Datei-Info +Name[ne]=Qt बहुभाषी फाइल सूचना +Name[nl]=Qt Linquïst-bestandsinformatie +Name[nn]=Informasjon om Qt Linguist-fil +Name[pa]=Qt Linguist ਫਾਇਲ ਜਾਣਕਾਰੀ +Name[pl]=Informacja pliku Qt Linguist +Name[pt]=Informação do Ficheiro do Qt Linguist +Name[pt_BR]=Arquivo de Informações de Lingüística do Qt +Name[ru]=Информация о файле в формате Qt Linguist +Name[sk]=Informácie pre Qt Linguist +Name[sl]=Informacije o Qt Linguist +Name[sr]=Информације о фајлу Qt Linguist-а +Name[sr@Latn]=Informacije o fajlu Qt Linguist-a +Name[sv]=Qt Linguist-filinformation +Name[ta]=Qt மொழியியல் கோப்புகள் தகவல் +Name[tg]=Ахборот дар бораи файл дар формати Qt Linguist +Name[tr]=Qt Dilbilimci Dosya Bilgisi +Name[uk]=інформація про файл формату Qt Linguist +Name[zh_CN]=Qt 语言大师文件信息 +Name[zh_TW]=Qt 語言檔資訊 +ServiceTypes=KFilePlugin +X-KDE-Library=kfile_ts +MimeType=application/x-linguist +PreferredGroups=General +PreferredItems=Messages,Translated,Untranslated,Fuzzi diff --git a/kfile-plugins/ts/kfile_ts.h b/kfile-plugins/ts/kfile_ts.h new file mode 100644 index 00000000..0f976bbf --- /dev/null +++ b/kfile-plugins/ts/kfile_ts.h @@ -0,0 +1,39 @@ +/* This file is part of the KDE project + * Copyright (C) 2002 Carsten Niehaus <cniehaus@kde.org> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation version 2. + * + * This program 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + +#ifndef __KFILE_TS_H_ +#define __KFILE_TS_H_ + +#include <kfilemetainfo.h> + +class QStringList; + +class KTsPlugin: public KFilePlugin +{ + Q_OBJECT + +public: + KTsPlugin(QObject *parent, const char *name, const QStringList& args); + virtual bool readInfo(KFileMetaInfo& info, uint what); + +private: + void makeMimeTypeInfo(const QString& mimeType); +}; + +#endif |