Changeset View
Changeset View
Standalone View
Standalone View
thumbnail/djvucreator.cpp
Show All 31 Lines | |||||
32 | #endif | 32 | #endif | ||
33 | #include <sys/time.h> | 33 | #include <sys/time.h> | ||
34 | #include <sys/wait.h> | 34 | #include <sys/wait.h> | ||
35 | #include <fcntl.h> | 35 | #include <fcntl.h> | ||
36 | #include <errno.h> | 36 | #include <errno.h> | ||
37 | 37 | | |||
38 | #include <QFile> | 38 | #include <QFile> | ||
39 | #include <QImage> | 39 | #include <QImage> | ||
40 | 40 | #include <QStandardPaths> | |||
41 | 41 | | |||
42 | extern "C" | 42 | extern "C" | ||
43 | { | 43 | { | ||
44 | Q_DECL_EXPORT ThumbCreator *new_creator() | 44 | Q_DECL_EXPORT ThumbCreator *new_creator() | ||
45 | { | 45 | { | ||
46 | return new DjVuCreator; | 46 | return new DjVuCreator; | ||
47 | } | 47 | } | ||
48 | } | 48 | } | ||
49 | 49 | | |||
50 | bool DjVuCreator::create(const QString &path, int width, int height, QImage &img) | 50 | bool DjVuCreator::create(const QString &path, int width, int height, QImage &img) | ||
51 | { | 51 | { | ||
52 | if (QStandardPaths::findExecutable(QStringLiteral("ddjvu")).isEmpty()) | ||||
53 | return false; | ||||
54 | | ||||
pino: extra brackets | |||||
I'd like to use instead the Framework coding style to improve homogenizing coding styles. meven: I'd like to use instead the Framework coding style to improve homogenizing coding styles.
https… | |||||
this code does not follow that style, so please keep new changes coherent with the existing style pino: this code does not follow that style, so please keep new changes coherent with the existing… | |||||
52 | int output[2]; | 55 | int output[2]; | ||
53 | QByteArray data(1024, 'k'); | 56 | QByteArray data(1024, 'k'); | ||
54 | bool ok = false; | 57 | bool ok = false; | ||
55 | 58 | | |||
56 | if (pipe(output) == -1) | 59 | if (pipe(output) == -1) | ||
57 | return false; | 60 | return false; | ||
58 | 61 | | |||
59 | const char* argv[8]; | 62 | const char* argv[8]; | ||
60 | QByteArray sizearg, fnamearg; | 63 | QByteArray sizearg, fnamearg; | ||
61 | sizearg = QByteArray::number(width) + 'x' + QByteArray::number(height); | 64 | sizearg = QByteArray::number(width) + 'x' + QByteArray::number(height); | ||
62 | fnamearg = QFile::encodeName( path ); | 65 | fnamearg = QFile::encodeName( path ); | ||
63 | argv[0] = "ddjvu"; | 66 | argv[0] = "ddjvu"; | ||
64 | argv[1] = "-page"; | 67 | argv[1] = "-page"; | ||
65 | argv[2] = "1"; // krazy:exclude=doublequote_chars | 68 | argv[2] = "1"; // krazy:exclude=doublequote_chars | ||
66 | argv[3] = "-size"; | 69 | argv[3] = "-size"; | ||
67 | argv[4] = sizearg.data(); | 70 | argv[4] = sizearg.data(); | ||
68 | argv[5] = fnamearg.data(); | 71 | argv[5] = fnamearg.data(); | ||
69 | argv[6] = nullptr; | 72 | argv[6] = nullptr; | ||
70 | 73 | | |||
71 | pid_t pid = fork(); | 74 | pid_t pid = fork(); | ||
72 | if (pid == 0) | 75 | if (pid == 0) | ||
73 | { | 76 | { | ||
77 | // child process | ||||
74 | close(output[0]); | 78 | close(output[0]); | ||
75 | dup2(output[1], STDOUT_FILENO); | 79 | dup2(output[1], STDOUT_FILENO); | ||
76 | execvp(argv[0], const_cast<char *const *>(argv)); | 80 | execvp(argv[0], const_cast<char *const *>(argv)); | ||
77 | exit(1); | 81 | _exit(1); | ||
78 | } | 82 | } | ||
79 | else if (pid >= 0) | 83 | else if (pid > 0) | ||
80 | { | 84 | { | ||
85 | // parent process | ||||
81 | close(output[1]); | 86 | close(output[1]); | ||
82 | int offset = 0; | 87 | int offset = 0; | ||
83 | while (!ok) { | 88 | while (!ok) { | ||
84 | fd_set fds; | 89 | fd_set fds; | ||
85 | FD_ZERO(&fds); | 90 | FD_ZERO(&fds); | ||
86 | FD_SET(output[0], &fds); | 91 | FD_SET(output[0], &fds); | ||
87 | struct timeval tv; | 92 | struct timeval tv; | ||
88 | tv.tv_sec = 20; | 93 | tv.tv_sec = 20; | ||
Show All 22 Lines | |||||
111 | if (!ok) | 116 | if (!ok) | ||
112 | kill(pid, SIGTERM); | 117 | kill(pid, SIGTERM); | ||
113 | int status = 0; | 118 | int status = 0; | ||
114 | if (waitpid(pid, &status, 0) != pid || (status != 0 && status != 256) ) | 119 | if (waitpid(pid, &status, 0) != pid || (status != 0 && status != 256) ) | ||
115 | ok = false; | 120 | ok = false; | ||
116 | } | 121 | } | ||
117 | else | 122 | else | ||
118 | { | 123 | { | ||
124 | // error case | ||||
119 | close(output[1]); | 125 | close(output[1]); | ||
120 | } | 126 | } | ||
121 | 127 | | |||
122 | close(output[0]); | 128 | close(output[0]); | ||
123 | int l = img.loadFromData( data ); | 129 | int l = img.loadFromData( data ); | ||
124 | return ok && l; | 130 | return ok && l; | ||
125 | } | 131 | } | ||
126 | 132 | | |||
127 | 133 | | |||
128 | ThumbCreator::Flags DjVuCreator::flags() const | 134 | ThumbCreator::Flags DjVuCreator::flags() const | ||
129 | { | 135 | { | ||
130 | return static_cast<Flags>(None); | 136 | return static_cast<Flags>(None); | ||
131 | } | 137 | } | ||
132 | 138 | | |||
133 | 139 | |
extra brackets