File: c2bConsole.cpp

package info (click to toggle)
cb2bib 1.9.2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,368 kB
  • sloc: cpp: 24,179; sh: 481; makefile: 16
file content (103 lines) | stat: -rw-r--r-- 2,706 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/***************************************************************************
 *   Copyright (C) 2004-2015 by Pere Constans
 *   constans@molspaces.com
 *   cb2Bib version 1.9.2. Licensed under the GNU GPL version 3.
 *   See the LICENSE file that comes with this distribution.
 ***************************************************************************/
#include "c2bConsole.h"

#include "c2bSettings.h"
#include "c2bTests.h"
#include "c2bNetworkQuery.h"

#include <bibExtractor.h>
#include <bibParser.h>
#include <collectionIndex.h>
#include <metadataParser.h>
#include <texToHtml.h>

#include <QCoreApplication>
#include <QTimer>


c2bConsole::c2bConsole(QObject* parento) : QObject(parento)
{}

c2bConsole::~c2bConsole()
{}


void c2bConsole::load()
{
    // Send _process to application cue
    QTimer::singleShot(0, this, SLOT(_process()));
}

void c2bConsole::_process()
{
    int code(0);
    if (c2bSettingsP->cl_html_annote)
        code = cl_html_annote();
    else if (c2bSettingsP->cl_doc2bib)
        code = cl_doc2bib();
    else if (c2bSettingsP->cl_txt2bib)
        code = cl_txt2bib();
    else if (c2bSettingsP->cl_index)
        code = cl_index();
    else if (c2bSettingsP->cl_cb2bib_tests)
        code = cl_cb2bib_tests();
    QCoreApplication::exit(code);
}

int c2bConsole::cl_html_annote()
{
    if (QFileInfo(c2bSettingsP->cl_annote_filename).exists())
    {
        const QString tex(c2bUtils::fileToString(c2bSettingsP->cl_annote_filename));
        const QString htmlf(c2bSettingsP->cl_annote_filename + ".html");
        texToHtml t2h;
        t2h.toHtml(tex, htmlf);
        return 0;
    }
    else
    {
        c2bUtils::warn(QObject::tr("Error: Could not open %1 file for reading").arg(c2bSettingsP->cl_annote_filename));
        return 1;
    }
}

int c2bConsole::cl_doc2bib()
{
    bibParser bp;
    metadataParser mp(&bp);
    c2bNetworkQuery nq(&bp); // needs c2bUtils::fromHtmlString
    bibExtractor be(&bp, &mp, &nq);
    const int c(be.extract(c2bSettingsP->cl_extract_input_filenames, c2bSettingsP->cl_extract_output_filename, bibExtractor::Document));
    return c;
}

int c2bConsole::cl_txt2bib()
{
    bibParser bp;
    metadataParser mp(&bp);
    c2bNetworkQuery nq(&bp);
    bibExtractor be(&bp, &mp, &nq);
    const int c(be.extract(c2bSettingsP->cl_extract_input_filenames, c2bSettingsP->cl_extract_output_filename, bibExtractor::PlainText));
    return c;
}

int c2bConsole::cl_index()
{
    bibParser bp;
    collectionIndex ci(&bp);
    const int c(ci.index(c2bSettingsP->cl_index_dirname));
    return c;
}

int c2bConsole::cl_cb2bib_tests()
{
    c2bTests* t = new c2bTests();
    const int passed(t->allTests());
    delete t;
    return passed;
}