Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

Commit

Permalink
ADD: json parser
Browse files Browse the repository at this point in the history
  • Loading branch information
anak10thn committed Feb 23, 2015
1 parent bc48f3a commit 28a0970
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 3 deletions.
5 changes: 3 additions & 2 deletions ign.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
#-------------------------------------------------

QT += network core webkitwidgets sql
QT += network core webkitwidgets sql printsupport

TARGET = ignsdk
TEMPLATE = app
Expand All @@ -26,7 +26,8 @@ HEADERS += src/ign.h \
src/ignsystem.h \
src/ignmovedrag.h \
src/ignnetwork.h \
src/version.h
src/version.h \
src/ignjson.h

RESOURCES += \
ign.qrc
Expand Down
29 changes: 29 additions & 0 deletions src/ignjson.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef IGNJSON
#define IGNJSON
#include <QObject>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonParseError>
#include <QDebug>

class ignjson : public QObject
{
Q_OBJECT
public:
explicit ignjson(QObject *parent = 0);
QJsonObject jsonParser(const QVariant &config){
/* json parsing */
QJsonParseError *err = new QJsonParseError();
QJsonDocument json = QJsonDocument::fromVariant(config);

if (err->error != 0) {
qDebug() << err->errorString();
exit (1);
}

return json.object();
}
};
#endif // IGNJSON

38 changes: 37 additions & 1 deletion src/ignsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#include <QDebug>

ignsystem::ignsystem(QObject *parent)
: QObject(parent)
: QObject(parent),
jsonParse(0)
{

}
Expand Down Expand Up @@ -63,3 +64,38 @@ void ignsystem::_out(){
void ignsystem::kill(){
proc->kill();
}

bool ignsystem::print(const QVariant &config){
QVariantMap conf = jsonParse->jsonParser(config).toVariantMap();
QPrinter print;
QTextDocument *doc = new QTextDocument();

QString type = conf["type"].toString();
QString txt = conf["content"].toString();
QString out = conf["out"].toString();

if(type == "html")
{
doc->setHtml(txt);
}
else
{
doc->setPlainText(txt);
}

if(out == "pdf"){
print.setOutputFormat(QPrinter::PdfFormat);
}

QPrintDialog *dialog = new QPrintDialog(&print);
if (dialog->exec() != QDialog::Accepted)
{
return false;
}
else
{
doc->print(&print);
delete doc;
return true;
}
}
8 changes: 8 additions & 0 deletions src/ignsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@
#include <QCryptographicHash>
#include <QDesktopServices>
#include <QUrl>
#include <QDebug>
#include <QTextDocument>
#include <QPrinter>
#include <QPrintDialog>
#include <QPrintPreviewDialog>
#include "ignjson.h"

class ignsystem : public QObject
{
Q_OBJECT
public:
explicit ignsystem(QObject *parent = 0);
QProcess *proc;
ignjson *jsonParse;

public slots:
QString cliOut(const QString& cli);
Expand All @@ -22,6 +29,7 @@ public slots:
void desktopService(const QString& link);
void _out();
void kill();
bool print(const QVariant &config);

signals:
void out(const QString& link);
Expand Down

1 comment on commit 28a0970

@anak10thn
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.