summaryrefslogtreecommitdiffstats
path: root/kfile-plugins/ts/kfile_ts.cpp
blob: 0d6f5dc17841eff5c369b2cff4f504eb8d1c785f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* This file is part of the KDE project
 * Copyright (C) 2002 Carsten Niehaus <[email protected]>
 *
 * 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., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 */

#include "kfile_ts.h"

#include <kgenericfactory.h>
#include <kdebug.h>

#include <tqfile.h>
#include <tqstringlist.h>

typedef KGenericFactory<KTsPlugin> TsFactory;

K_EXPORT_COMPONENT_FACTORY(kfile_ts, TsFactory("kfile_ts"))

KTsPlugin::KTsPlugin(TQObject *parent, const char *name,
        const TQStringList &args) : KFilePlugin(parent, name, args)
{
    makeMimeTypeInfo( "application/x-linguist" );
}

void KTsPlugin::makeMimeTypeInfo(const TQString& mimeType)
{
    KFileMimeTypeInfo* info = addMimeTypeInfo(mimeType);

    KFileMimeTypeInfo::GroupInfo* group =
            addGroupInfo(info, "General", i18n("General"));

    KFileMimeTypeInfo::ItemInfo* item;
    item = addItemInfo(group, "Messages", i18n("Messages"), TQVariant::Int);
    setAttributes(item, KFileMimeTypeInfo::Averaged);
    item = addItemInfo(group, "Translated", i18n("Translated"), TQVariant::Int);
    setAttributes(item, KFileMimeTypeInfo::Averaged);
    item = addItemInfo(group, "Untranslated", i18n("Untranslated"), TQVariant::Int);
    setAttributes(item, KFileMimeTypeInfo::Averaged);
    item = addItemInfo(group, "Obsolete", i18n("Obsolete"), TQVariant::Int);
}

bool KTsPlugin::readInfo(KFileMetaInfo& info, uint)
{
    TQFile f(info.path());
    if (!f.open(IO_ReadOnly))
        return false;

    int messages      = 0;
    int untranslated  = 0;
    int obsolete      = 0;

    TQTextStream stream( &f );
    TQString 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"