File: converter.cpp

package info (click to toggle)
libkeduvocdocument 4%3A20.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,284 kB
  • sloc: cpp: 8,230; makefile: 3; sh: 3
file content (84 lines) | stat: -rw-r--r-- 3,525 bytes parent folder | download
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) 2007 by Jeremy Whiting <jpwhiting@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; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   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; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
 ***************************************************************************/

/** @file
 * \brief kvtml document reader/writer
 * partly to test the document class, partly to convert
 * old kvtml files to the new format
 * @author Jeremy Whiting <jpwhiting@kde.org>
 */

#include "keduvocdocument.h"

#include <KLocalizedString>
#include <QCoreApplication>
#include <QDebug>
#include <QUrl>
#include <QCommandLineParser>

int main( int argc, char ** argv )
{
    QCoreApplication::setApplicationName(QStringLiteral("kvtml-converter"));
    QCoreApplication::setApplicationVersion(QStringLiteral("0.2"));
    QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org"));
    QCoreApplication app( argc, argv );

    QCommandLineParser parser;
    parser.addHelpOption();
    parser.addVersionOption();
    QCommandLineOption formatOption(QStringList() << QStringLiteral("f") << QStringLiteral("format"),
            i18nc("main", "file format to write out (kvtml1, kvtml2, or csv)."));
    parser.addOption(formatOption);
    parser.addPositionalArgument(QStringLiteral("infile"), i18nc("main", "File to read in."));
    parser.addPositionalArgument(QStringLiteral("outfile"), i18nc("main", "File to write to."));

    parser.process(app);

    QStringList files = parser.positionalArguments();

    if ( files.count() > 0 ) {
        QUrl infile = QUrl::fromLocalFile(files.at( 0 ));
        if ( files.count() > 1 ) {
            QUrl outfile = QUrl::fromLocalFile(files.at( 1 ));

            KEduVocDocument document;
            qDebug() << "Reading " << infile;
            document.open( infile );
            qDebug() << "Writing to " << outfile;
            if (parser.value(QStringLiteral("f")) == QLatin1String("kvtml1"))
            {
                document.saveAs( outfile, KEduVocDocument::Kvtml1 );
            }
            else if (parser.value(QStringLiteral("f")) == QLatin1String("csv"))
            {
                document.saveAs( outfile, KEduVocDocument::Csv );
            }
            else
            {
                document.saveAs( outfile, KEduVocDocument::Kvtml );
            }
        }
    }
    else
    {
        qDebug() << parser.helpText();
    }

    return 0;
}