File: djvu2pdf.cpp

package info (click to toggle)
yagf 0.9.5%2Brepack1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, trixie
  • size: 3,028 kB
  • sloc: cpp: 14,546; ansic: 47; xml: 30; makefile: 7; sh: 2
file content (91 lines) | stat: -rwxr-xr-x 2,410 bytes parent folder | download | duplicates (2)
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
/*
   YAGF - cuneiform and tesseract OCR graphical front-end
   Copyright (C) 2009-2015 Andrei Borovsky <borovsky.andrei@gmail.com>

   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 3 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, see <http://www.gnu.org/licenses/>.

*/

#include "djvu2pdf.h"
#include "utils.h"
#include "settings.h"
#include <QDir>
#include <QFileInfo>
#include <QFileInfoList>
#include <QStringList>

Djvu2PDF::Djvu2PDF(QObject *parent) :
    QObject(parent)
{
    pdfout = Settings::instance()->workingDir()+ QString("fromdjvu/");
    QDir dir(pdfout);
    if (!dir.exists())
        dir.mkdir(pdfout);
    connect(&process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(onError()));
    connect(&process, SIGNAL(started()), this, SIGNAL(started()), Qt::QueuedConnection);
    connect(&process, SIGNAL(finished(int)), this, SLOT(onFinished()), Qt::QueuedConnection);
}

Djvu2PDF::~Djvu2PDF()
{
    cancel();
}

void Djvu2PDF::convert(const QString &fileName)
{
    if (!findProgram("ddjvu")) {
        emit error(trUtf8("The ddjvu utility from the DjVuLibre package has not been found.\nPlease make sure the package is installed."));
        return;
    }
    QString output = pdfout + "out.pdf";
    QStringList sl;
    sl << "--format=pdf" << fileName << output;
    process.start("ddjvu", sl);
}

QString Djvu2PDF::pdfName() const
{
    return pdfout + "out.pdf";
}

void Djvu2PDF::onError()
{
    emit error(trUtf8("Failed to convert djvu to pdf"));
}

void Djvu2PDF::cancel()
{
    process.kill();
    clearFiles();
}

void Djvu2PDF::onFinished()
{
    QFileInfo fi(pdfout, "out.pdf");
    if (!fi.exists())
        onError();
    else
        emit finished();
}

void Djvu2PDF::clearFiles()
{
    QDir dir;
    dir.setPath(pdfout);
    QFileInfoList fil;
    fil = dir.entryInfoList();
    foreach (QFileInfo fi, fil) {
        dir.remove(fi.absoluteFilePath());
    }
}