src/hbtools/docml2bin/main.cpp
changeset 1 f7ac710697a9
child 2 06ff229162e9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hbtools/docml2bin/main.cpp	Mon May 03 12:48:33 2010 +0300
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (developer.feedback@nokia.com)
+**
+** This file is part of the HbTools module of the UI Extensions for Mobile.
+**
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this file.
+** Please review the following information to ensure the GNU Lesser General
+** Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights.  These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at developer.feedback@nokia.com.
+**
+****************************************************************************/
+
+#include <hbdocumentloader.h>
+#include <QtGui>
+#include <assert.h>
+#include <iostream>
+
+
+void showHelp() {
+    std::cout << "docml2bin.exe usage:\n\n";
+
+    std::cout << "docml2bin -s sourceFile [-t targetFile]\n\n";
+
+    std::cout << "    Converts plain text docml file to a binary file.\n\n";
+
+    std::cout << "    If target file name is not given creates file named\n";
+    std::cout << "    <source file> + \".bin\".\n\n";
+
+    std::cout << "options:\n\n";
+
+    std::cout << " -s \t\tname of the source file (\"<filename.docml>\").\n";
+    std::cout << " -t \t\tname of the targe file (\"<binaryfile.bin>\").\n\n";
+
+    std::cout << "Example:\n";
+    std::cout << "docml2bin.exe -s myfile.docml -t c:/resouces/bin/mybinary.docml\n\n";
+}
+
+int main(int argc, char *argv[])
+{
+    QApplication app(argc, argv, false); // GUIenabled=false
+
+    if (argc <= 2) {
+        showHelp();
+    } else {
+        QString source, target;
+        QStringList args(app.arguments());
+
+        for (int n = 0; n < args.count(); n++) {
+            if (args[n].toLower() == "-s") {
+                source = args[n+1];
+                n++;
+            } else if (args[n].toLower() == "-t") {
+                target = args[n+1];
+                n++;
+            } 
+        }
+
+        if (source.length() > 0) {
+            if (!QFile::exists(source)) {
+                std::cout << "Error: file " << source.toStdString() << " does not exist.\n";
+            } else {
+                // Open file and parse lines. Each line should have three value separated with:
+                QFile sourceFile(source);
+                if (sourceFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
+                    if (!target.length()) {
+                        target = source + ".bin";
+                    }
+                    if (QFile::exists(target)) {
+                        std::cout << "Error: target file already exists.\n";
+                    } else {
+                        QFile targetFile(target);
+                        if (targetFile.open(QIODevice::WriteOnly)) {
+                            HbDocumentLoader loader;
+                            loader.createBinary( &sourceFile, &targetFile );
+                            targetFile.close();
+                        }
+                    }
+                    sourceFile.close();
+                }
+            }
+        }
+    }
+
+    return 0;
+}
+