diff options
Diffstat (limited to 'kfile-plugins/c++')
-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 |
5 files changed, 310 insertions, 0 deletions
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 |