summaryrefslogtreecommitdiffstats
path: root/fileplugin/kfile_kbarcode.cpp
blob: bd2c1c866271fd29505862350d780abe64c59b9a (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
/*
 * Copyright (C) 2003 Dominik Seichter <domseichter@web.de>
 */

#include "kfile_kbarcode.h"

#include <kgenericfactory.h>
#include <klocale.h>

#include <qfile.h>
#include <qdom.h>

K_EXPORT_COMPONENT_FACTORY(kfile_kbarcode, KGenericFactory<KBarcodePlugin>( "kfile_kbarcode" ));

KBarcodePlugin::KBarcodePlugin(QObject *parent, const char *name,
                       const QStringList &args)

    : KFilePlugin(parent, name, args)
{
    KFileMimeTypeInfo* info = addMimeTypeInfo( "application/kbarcode-label" );

    KFileMimeTypeInfo::GroupInfo* group = 0L;

    group = addGroupInfo(info, "Label", i18n("Label"));

    KFileMimeTypeInfo::ItemInfo* item;

    item = addItemInfo(group, "Manufacturer", i18n("Manufacturer"), QVariant::String );
    item = addItemInfo(group, "Type", i18n("Type"), QVariant::String);
    item = addItemInfo(group, "Description", i18n("Description"), QVariant::String );
    item = addItemInfo(group, "Id", i18n("Label Id"), QVariant::String );
    item = addItemInfo(group, "Dimensions", i18n("Dimensions"), QVariant::Size);
    setHint( item, KFileMimeTypeInfo::Size );
    setUnit(item, KFileMimeTypeInfo::Centimeters );
}


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

    QDomDocument doc( "KBarcodeLabel" );
    if ( !doc.setContent( &f ) ) {
        f.close();
        return false;
    }

    KFileMetaInfoGroup group = appendGroup(info, "Label");

    QDomNode n = doc.documentElement().firstChild();
    while( !n.isNull() ) {
        QDomElement e = n.toElement(); // try to convert the node to an element.
        if( !e.isNull() )
            if( e.tagName() == "label" ) {
                QDomNode node = e.firstChild();
                while( !node.isNull() ) {
                    QDomElement e = node.toElement(); // try to convert the node to an element.
                    if( !e.isNull() )
                        if( e.tagName() == "description" )
                            appendItem(group, "Description", e.text() );
                        else if( e.tagName() == "id" ) {
                            appendItem(group, "Manufacturer", e.attribute("producer", "") );
                            appendItem(group, "Type", e.attribute("type", "") );
                            appendItem(group, "Id", e.text() );
                            appendItem(group, "Dimensions",
                                QSize( int(e.attribute("width", "0").toDouble()/10), int(e.attribute("height", "0").toDouble()/10) ) );
                        }

                    node = node.nextSibling();
                }
                n = n.nextSibling();
            }

        n = n.nextSibling();
    }


    f.close();
    return true;
}

#include "kfile_kbarcode.moc"