From bd9e6617827818fd043452c08c606f07b78014a0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: 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 --- kfile-plugins/ts/kfile_ts.cpp | 93 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 kfile-plugins/ts/kfile_ts.cpp (limited to 'kfile-plugins/ts/kfile_ts.cpp') 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 + * + * 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 +#include + +#include +#include + +typedef KGenericFactory 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("", false)) + return false; + + while (!stream.eof()) + { + line = stream.readLine(); + + if (line.contains("type=\"obsolete\"")) obsolete++; + + if (line.contains("")) 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" -- cgit v1.2.1