| 1 |
//C- -*- C++ -*- |
| 2 |
//C- ------------------------------------------------------------------- |
| 3 |
//C- DjView4 |
| 4 |
//C- Copyright (c) 2006- Leon Bottou |
| 5 |
//C- |
| 6 |
//C- This software is subject to, and may be distributed under, the |
| 7 |
//C- GNU General Public License, either version 2 of the license, |
| 8 |
//C- or (at your option) any later version. The license should have |
| 9 |
//C- accompanied the software or you may obtain a copy of the license |
| 10 |
//C- from the Free Software Foundation at http://www.fsf.org . |
| 11 |
//C- |
| 12 |
//C- This program is distributed in the hope that it will be useful, |
| 13 |
//C- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
//C- GNU General Public License for more details. |
| 16 |
//C- ------------------------------------------------------------------ |
| 17 |
|
| 18 |
#if AUTOCONF |
| 19 |
# include "config.h" |
| 20 |
#else |
| 21 |
# define HAVE_STRING_H 1 |
| 22 |
# define HAVE_SYS_TYPES_H 1 |
| 23 |
# define HAVE_STRERROR 1 |
| 24 |
# ifndef WIN32 |
| 25 |
# define HAVE_UNISTD_H 1 |
| 26 |
# endif |
| 27 |
#endif |
| 28 |
|
| 29 |
#include <stddef.h> |
| 30 |
#include <stdlib.h> |
| 31 |
#include <stdio.h> |
| 32 |
#include <stdarg.h> |
| 33 |
#include <errno.h> |
| 34 |
#include <limits.h> |
| 35 |
#include <signal.h> |
| 36 |
#if HAVE_SYS_TYPES_H |
| 37 |
# include <sys/types.h> |
| 38 |
#endif |
| 39 |
#if HAVE_STRING_H |
| 40 |
# include <string.h> |
| 41 |
#endif |
| 42 |
#if HAVE_UNISTD_H |
| 43 |
# include <unistd.h> |
| 44 |
#endif |
| 45 |
#if HAVE_TIFF |
| 46 |
# include <tiffio.h> |
| 47 |
#endif |
| 48 |
#include <algorithm> |
| 49 |
|
| 50 |
#include <QApplication> |
| 51 |
#include <QClipboard> |
| 52 |
#include <QCloseEvent> |
| 53 |
#include <QCoreApplication> |
| 54 |
#include <QDebug> |
| 55 |
#include <QDir> |
| 56 |
#include <QDialog> |
| 57 |
#include <QFile> |
| 58 |
#include <QFileDialog> |
| 59 |
#include <QFileInfo> |
| 60 |
#include <QFont> |
| 61 |
#include <QHBoxLayout> |
| 62 |
#include <QHeaderView> |
| 63 |
#include <QImageWriter> |
| 64 |
#include <QItemDelegate> |
| 65 |
#include <QKeySequence> |
| 66 |
#include <QList> |
| 67 |
#include <QMap> |
| 68 |
#include <QMessageBox> |
| 69 |
#include <QObject> |
| 70 |
#include <QPainter> |
| 71 |
#include <QPrinter> |
| 72 |
#include <QPrintDialog> |
| 73 |
#include <QPrintEngine> |
| 74 |
#include <QPushButton> |
| 75 |
#include <QRegExp> |
| 76 |
#include <QScrollBar> |
| 77 |
#include <QSettings> |
| 78 |
#include <QShortcut> |
| 79 |
#include <QString> |
| 80 |
#include <QStyle> |
| 81 |
#include <QTableWidget> |
| 82 |
#include <QTableWidgetItem> |
| 83 |
#include <QTabWidget> |
| 84 |
#include <QTextDocument> |
| 85 |
#include <QTimer> |
| 86 |
#include <QVBoxLayout> |
| 87 |
#include <QVector> |
| 88 |
#if QT_VERSION >= 0x50E00 |
| 89 |
# define tr8 tr |
| 90 |
#else |
| 91 |
# define tr8 trUtf8 |
| 92 |
#endif |
| 93 |
#if QT_VERSION >= 0x60000 |
| 94 |
# define reReplace(s,r,a) (r).replaceIn((s),(a)) |
| 95 |
# define reIndex(s,r,p) (r).indexIn((s),(p)) |
| 96 |
#else |
| 97 |
# define reReplace(s,r,a) (s).replace((r),(a)) |
| 98 |
# define reIndex(s,r,p) (s).indexOf((r),(p)) |
| 99 |
#endif |
| 100 |
|
| 101 |
#include <libdjvu/miniexp.h> |
| 102 |
#include <libdjvu/ddjvuapi.h> |
| 103 |
|
| 104 |
#include "qdjview.h" |
| 105 |
#include "qdjviewprefs.h" |
| 106 |
#include "qdjviewdialogs.h" |
| 107 |
#include "qdjviewexporters.h" |
| 108 |
#include "qdjvuwidget.h" |
| 109 |
#include "qdjvu.h" |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
// ======================================= |
| 115 |
// QDJVIEWERRORDIALOG |
| 116 |
// ======================================= |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
#include "ui_qdjviewerrordialog.h" |
| 121 |
|
| 122 |
struct QDjViewErrorDialog::Private { |
| 123 |
Ui::QDjViewErrorDialog ui; |
| 124 |
QList<QString> messages; |
| 125 |
void compose(); |
| 126 |
}; |
| 127 |
|
| 128 |
QDjViewErrorDialog::~QDjViewErrorDialog() |
| 129 |
{ |
| 130 |
delete d; |
| 131 |
} |
| 132 |
|
| 133 |
QDjViewErrorDialog::QDjViewErrorDialog(QWidget *parent) |
| 134 |
: QDialog(parent), |
| 135 |
d(new Private) |
| 136 |
{ |
| 137 |
d->ui.setupUi(this); |
| 138 |
#if QT_VERSION >= 0x60000 |
| 139 |
d->ui.textEdit->viewport()->setBackgroundRole(QPalette::Window); |
| 140 |
#else |
| 141 |
d->ui.textEdit->viewport()->setBackgroundRole(QPalette::Background); |
| 142 |
#endif |
| 143 |
setWindowTitle(tr("DjView Error")); |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
void |
| 148 |
QDjViewErrorDialog::compose() |
| 149 |
{ |
| 150 |
QString html; |
| 151 |
for (int i=0; i<d->messages.size(); i++) |
| 152 |
html = "<li>" + d->messages[i] + "</li>" + html; |
| 153 |
d->ui.textEdit->setHtml("<html><ul>" + html + "</ul></html>"); |
| 154 |
QScrollBar *scrollBar = d->ui.textEdit->verticalScrollBar(); |
| 155 |
scrollBar->setValue(scrollBar->maximum()); |
| 156 |
} |
| 157 |
|
| 158 |
void |
| 159 |
QDjViewErrorDialog::error(QString msg, QString, int) |
| 160 |
{ |
| 161 |
// Remove [1-nnnnn] prefix from djvulibre-3.5 |
| 162 |
if (msg.startsWith("[")) |
| 163 |
msg = reReplace(msg, QRegExp("^\\[\\d*-?\\d*\\]\\s*") , ""); |
| 164 |
#if QT_VERSION >= 0x50000 |
| 165 |
msg = msg.toHtmlEscaped(); |
| 166 |
#else |
| 167 |
msg = Qt::escape(msg); |
| 168 |
#endif |
| 169 |
// Ignore empty and duplicate messages |
| 170 |
if (msg.isEmpty()) return; |
| 171 |
if (!d->messages.isEmpty() && msg == d->messages[0]) return; |
| 172 |
// Add message |
| 173 |
d->messages.prepend(msg); |
| 174 |
while (d->messages.size() >= 16) |
| 175 |
d->messages.removeLast(); |
| 176 |
compose(); |
| 177 |
// For verbose mode |
| 178 |
QByteArray msga = msg.toLocal8Bit(); |
| 179 |
qWarning("%s", msga.constData()); |
| 180 |
} |
| 181 |
|
| 182 |
void |
| 183 |
QDjViewErrorDialog::prepare(QMessageBox::Icon icon, QString caption) |
| 184 |
{ |
| 185 |
#if QT_VERSION >= 0x60000 |
| 186 |
if (icon != QMessageBox::NoIcon) |
| 187 |
{ |
| 188 |
QIcon icon = style()->standardIcon(QStyle::SP_MessageBoxInformation); |
| 189 |
d->ui.iconLabel->setPixmap(icon.pixmap(d->ui.iconLabel->size())); |
| 190 |
} |
| 191 |
#else |
| 192 |
if (icon != QMessageBox::NoIcon) |
| 193 |
d->ui.iconLabel->setPixmap(QMessageBox::standardIcon(icon)); |
| 194 |
#endif |
| 195 |
if (caption.isEmpty()) |
| 196 |
caption = tr("Error - DjView", "dialog caption"); |
| 197 |
setWindowTitle(caption); |
| 198 |
} |
| 199 |
|
| 200 |
void |
| 201 |
QDjViewErrorDialog::done(int result) |
| 202 |
{ |
| 203 |
emit closing(); |
| 204 |
d->messages.clear(); |
| 205 |
QDialog::done(result); |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
// ======================================= |
| 210 |
// QDJVIEWAUTHDIALOG |
| 211 |
// ======================================= |
| 212 |
|
| 213 |
#include "ui_qdjviewauthdialog.h" |
| 214 |
|
| 215 |
struct QDjViewAuthDialog::Private |
| 216 |
{ |
| 217 |
Ui_QDjViewAuthDialog ui; |
| 218 |
}; |
| 219 |
|
| 220 |
QDjViewAuthDialog::~QDjViewAuthDialog() |
| 221 |
{ |
| 222 |
delete d; |
| 223 |
} |
| 224 |
|
| 225 |
QDjViewAuthDialog::QDjViewAuthDialog(QWidget *parent) |
| 226 |
: QDialog(parent), |
| 227 |
d(new Private) |
| 228 |
{ |
| 229 |
d->ui.setupUi(this); |
| 230 |
setWindowTitle(tr("Authentication required - DjView")); |
| 231 |
} |
| 232 |
|
| 233 |
QString |
| 234 |
QDjViewAuthDialog::user() const |
| 235 |
{ |
| 236 |
return d->ui.userLineEdit->text(); |
| 237 |
} |
| 238 |
|
| 239 |
QString |
| 240 |
QDjViewAuthDialog::pass() const |
| 241 |
{ |
| 242 |
return d->ui.passLineEdit->text(); |
| 243 |
} |
| 244 |
|
| 245 |
void |
| 246 |
QDjViewAuthDialog::setInfo(QString why) |
| 247 |
{ |
| 248 |
#if QT_VERSION >= 0x50000 |
| 249 |
QString ewhy = why.toHtmlEscaped(); |
| 250 |
#else |
| 251 |
QString ewhy = Qt::escape(why); |
| 252 |
#endif |
| 253 |
QString txt = QString("<html>%1</html>").arg(ewhy); |
| 254 |
d->ui.whyLabel->setText(txt); |
| 255 |
} |
| 256 |
|
| 257 |
void |
| 258 |
QDjViewAuthDialog::setUser(QString user) |
| 259 |
{ |
| 260 |
d->ui.userLineEdit->setText(user); |
| 261 |
} |
| 262 |
|
| 263 |
void |
| 264 |
QDjViewAuthDialog::setPass(QString pass) |
| 265 |
{ |
| 266 |
d->ui.passLineEdit->setText(pass); |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
// ======================================= |
| 272 |
// QDJVIEWINFODIALOG |
| 273 |
// ======================================= |
| 274 |
|
| 275 |
|
| 276 |
#include "ui_qdjviewinfodialog.h" |
| 277 |
|
| 278 |
struct QDjViewInfoDialog::Private { |
| 279 |
Ui::QDjViewInfoDialog ui; |
| 280 |
QDjView *djview; |
| 281 |
QDjVuDocument *document; |
| 282 |
QList<ddjvu_fileinfo_t> files; |
| 283 |
int fileno; |
| 284 |
int pageno; |
| 285 |
bool done; |
| 286 |
}; |
| 287 |
|
| 288 |
|
| 289 |
QDjViewInfoDialog::~QDjViewInfoDialog() |
| 290 |
{ |
| 291 |
delete d; |
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
QDjViewInfoDialog::QDjViewInfoDialog(QDjView *parent) |
| 296 |
: QDialog(parent), d(new Private) |
| 297 |
{ |
| 298 |
d->djview = parent; |
| 299 |
d->document = 0; |
| 300 |
d->fileno = 0; |
| 301 |
d->pageno = -1; |
| 302 |
d->done = false; |
| 303 |
d->ui.setupUi(this); |
| 304 |
|
| 305 |
QDjViewPrefs *prefs = QDjViewPrefs::instance(); |
| 306 |
int index = prefs->infoDialogTab; |
| 307 |
if (index >= 0 && index < d->ui.tabWidget->count()) |
| 308 |
d->ui.tabWidget->setCurrentIndex(index); |
| 309 |
|
| 310 |
QFont font = d->ui.fileText->font(); |
| 311 |
font.setFixedPitch(true); |
| 312 |
font.setStyleHint(QFont::Monospace); |
| 313 |
font.setFamily("monospace"); |
| 314 |
font.setPointSize((font.pointSize() * 5 + 5) / 6); |
| 315 |
d->ui.fileText->setFont(font); |
| 316 |
#if QT_VERSION >= 0x60000 |
| 317 |
d->ui.fileText->viewport()->setBackgroundRole(QPalette::Window); |
| 318 |
#else |
| 319 |
d->ui.fileText->viewport()->setBackgroundRole(QPalette::Background); |
| 320 |
#endif |
| 321 |
|
| 322 |
QStringList labels; |
| 323 |
d->ui.docTable->setColumnCount(6); |
| 324 |
labels << tr("File #") << tr("File Name") |
| 325 |
<< tr("File Size") << tr("File Type") |
| 326 |
<< tr("Page #") << tr("Page Title"); |
| 327 |
d->ui.docTable->setHorizontalHeaderLabels(labels); |
| 328 |
d->ui.docTable->verticalHeader()->hide(); |
| 329 |
d->ui.docTable->horizontalHeader()->setHighlightSections(false); |
| 330 |
d->ui.docTable->horizontalHeader()->setStretchLastSection(true); |
| 331 |
|
| 332 |
connect(d->djview, SIGNAL(documentClosed(QDjVuDocument*)), |
| 333 |
this, SLOT(clear())); |
| 334 |
connect(d->djview, SIGNAL(documentReady(QDjVuDocument*)), |
| 335 |
this, SLOT(refresh())); |
| 336 |
connect(d->djview->getDjVuWidget(), SIGNAL(pageChanged(int)), |
| 337 |
this, SLOT(setPage(int))); |
| 338 |
connect(d->ui.nextButton, SIGNAL(clicked()), |
| 339 |
this, SLOT(nextFile()) ); |
| 340 |
connect(d->ui.jumpButton, SIGNAL(clicked()), |
| 341 |
this, SLOT(jumpToSelectedPage()) ); |
| 342 |
connect(d->ui.fileCombo, SIGNAL(activated(int)), |
| 343 |
this, SLOT(setFile(int)) ); |
| 344 |
connect(d->ui.prevButton, SIGNAL(clicked()), |
| 345 |
this, SLOT(prevFile()) ); |
| 346 |
connect(d->ui.docTable, SIGNAL(currentCellChanged(int,int,int,int)), |
| 347 |
this, SLOT(setFile(int)) ); |
| 348 |
connect(d->ui.docTable, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), |
| 349 |
this, SLOT(jumpToSelectedPage()) ); |
| 350 |
|
| 351 |
d->ui.fileCombo->setEnabled(false); |
| 352 |
d->ui.jumpButton->setEnabled(false); |
| 353 |
d->ui.prevButton->setEnabled(false); |
| 354 |
d->ui.nextButton->setEnabled(false); |
| 355 |
|
| 356 |
// what's this |
| 357 |
QWidget *wd = d->ui.tabDocument; |
| 358 |
wd->setWhatsThis(tr("<html><b>Document information</b><br>" |
| 359 |
"This panel shows information about the document and " |
| 360 |
"its component files. Select a component file " |
| 361 |
"to display detailed information in the <tt>File</tt> " |
| 362 |
"tab. Double click a component file to show " |
| 363 |
"the corresponding page in the main window. " |
| 364 |
"</html>")); |
| 365 |
QWidget *wf = d->ui.tabFile; |
| 366 |
wf->setWhatsThis(tr("<html><b>File and page information</b><br>" |
| 367 |
"This panel shows the structure of the DjVu data " |
| 368 |
"corresponding to the component file or the page " |
| 369 |
"selected in the <tt>Document</tt> tab. " |
| 370 |
"The arrow buttons jump to the previous or next " |
| 371 |
"component file.</html>")); |
| 372 |
} |
| 373 |
|
| 374 |
void |
| 375 |
QDjViewInfoDialog::refresh() |
| 376 |
{ |
| 377 |
// document known |
| 378 |
if (! d->document) |
| 379 |
{ |
| 380 |
QDjVuDocument *doc; |
| 381 |
doc = d->djview->getDjVuWidget()->document(); |
| 382 |
if (! doc) |
| 383 |
return; |
| 384 |
d->document = doc; |
| 385 |
connect(doc, SIGNAL(pageinfo()), |
| 386 |
this, SLOT(refresh()) ); |
| 387 |
} |
| 388 |
// document ready |
| 389 |
if (! d->files.size()) |
| 390 |
{ |
| 391 |
QDjVuDocument *doc = d->document; |
| 392 |
if (ddjvu_document_decoding_status(*doc) != DDJVU_JOB_OK) |
| 393 |
return; |
| 394 |
int filenum = ddjvu_document_get_filenum(*doc); |
| 395 |
for (int i=0; i<filenum; i++) |
| 396 |
{ |
| 397 |
ddjvu_fileinfo_t info; |
| 398 |
ddjvu_document_get_fileinfo(*doc, i, &info); |
| 399 |
d->files << info; |
| 400 |
} |
| 401 |
fillFileCombo(); |
| 402 |
fillDocLabel(); |
| 403 |
fillDocTable(); |
| 404 |
if (d->pageno >= 0) |
| 405 |
setPage(d->pageno); |
| 406 |
else if (d->fileno >= 0) |
| 407 |
setFile(d->fileno); |
| 408 |
d->ui.fileCombo->setEnabled(true); |
| 409 |
d->done = false; |
| 410 |
} |
| 411 |
|
| 412 |
// file ready |
| 413 |
if (! d->done) |
| 414 |
{ |
| 415 |
QDjVuDocument *doc = d->document; |
| 416 |
ddjvu_fileinfo_t &info = d->files[d->fileno]; |
| 417 |
d->done = true; |
| 418 |
|
| 419 |
// file dump |
| 420 |
QString dump = tr("Waiting for data..."); |
| 421 |
char *s = ddjvu_document_get_filedump(*doc, d->fileno); |
| 422 |
if (! s) |
| 423 |
d->done = false; |
| 424 |
else |
| 425 |
{ |
| 426 |
dump = QString::fromUtf8(s); |
| 427 |
free(s); |
| 428 |
} |
| 429 |
d->ui.fileText->setPlainText(dump); |
| 430 |
d->ui.prevButton->setEnabled(d->fileno - 1 >= 0); |
| 431 |
d->ui.nextButton->setEnabled(d->fileno + 1 < d->files.size()); |
| 432 |
d->ui.jumpButton->setEnabled(info.type == 'P'); |
| 433 |
d->ui.fileCombo->setCurrentIndex(d->fileno); |
| 434 |
QTableWidget *table = d->ui.docTable; |
| 435 |
int rows = table->rowCount(); |
| 436 |
int cols = table->columnCount(); |
| 437 |
QTableWidgetSelectionRange all(0,0,rows-1,cols-1); |
| 438 |
table->setRangeSelected(all, false); |
| 439 |
table->selectRow(d->fileno); |
| 440 |
} |
| 441 |
} |
| 442 |
|
| 443 |
void |
| 444 |
QDjViewInfoDialog::setPage(int pageno) |
| 445 |
{ |
| 446 |
if (d->document && d->files.size()) |
| 447 |
{ |
| 448 |
int i; |
| 449 |
for (i=0; i<d->files.size(); i++) |
| 450 |
if (d->files[i].pageno == pageno && |
| 451 |
d->files[i].type == 'P' ) |
| 452 |
break; |
| 453 |
if (i < d->files.size()) |
| 454 |
setFile(i); |
| 455 |
} |
| 456 |
else |
| 457 |
{ |
| 458 |
d->fileno = -1; |
| 459 |
d->pageno = pageno; |
| 460 |
} |
| 461 |
} |
| 462 |
|
| 463 |
void |
| 464 |
QDjViewInfoDialog::setFile(int fileno) |
| 465 |
{ |
| 466 |
if (d->document && d->files.size()) |
| 467 |
{ |
| 468 |
if (fileno >= 0 && |
| 469 |
fileno < d->files.size() && |
| 470 |
fileno != d->fileno ) |
| 471 |
{ |
| 472 |
d->fileno = fileno; |
| 473 |
d->pageno = d->files[fileno].pageno; |
| 474 |
d->done = false; |
| 475 |
refresh(); |
| 476 |
} |
| 477 |
} |
| 478 |
else |
| 479 |
{ |
| 480 |
d->pageno = -1; |
| 481 |
d->fileno = fileno; |
| 482 |
} |
| 483 |
} |
| 484 |
|
| 485 |
void |
| 486 |
QDjViewInfoDialog::prevFile() |
| 487 |
{ |
| 488 |
if (d->document && d->files.size()) |
| 489 |
if (d->fileno - 1 >= 0) |
| 490 |
setFile(d->fileno - 1); |
| 491 |
} |
| 492 |
|
| 493 |
void |
| 494 |
QDjViewInfoDialog::nextFile() |
| 495 |
{ |
| 496 |
if (d->document && d->files.size()) |
| 497 |
if (d->fileno + 1 < d->files.size()) |
| 498 |
setFile(d->fileno + 1); |
| 499 |
} |
| 500 |
|
| 501 |
void |
| 502 |
QDjViewInfoDialog::jumpToSelectedPage() |
| 503 |
{ |
| 504 |
if (d->document && d->files.size()) |
| 505 |
{ |
| 506 |
ddjvu_fileinfo_t &info = d->files[d->fileno]; |
| 507 |
if (info.type == 'P') |
| 508 |
d->djview->goToPage(info.pageno); |
| 509 |
} |
| 510 |
} |
| 511 |
|
| 512 |
void |
| 513 |
QDjViewInfoDialog::clear() |
| 514 |
{ |
| 515 |
hide(); |
| 516 |
if (d->document) |
| 517 |
disconnect(d->document, 0, this, 0); |
| 518 |
d->files.clear(); |
| 519 |
d->document = 0; |
| 520 |
QDjViewPrefs *prefs = QDjViewPrefs::instance(); |
| 521 |
prefs->infoDialogTab = d->ui.tabWidget->currentIndex(); |
| 522 |
} |
| 523 |
|
| 524 |
void |
| 525 |
QDjViewInfoDialog::fillFileCombo() |
| 526 |
{ |
| 527 |
QComboBox *fileCombo = d->ui.fileCombo; |
| 528 |
fileCombo->clear(); |
| 529 |
for (int fileno=0; fileno<d->files.size(); fileno++) |
| 530 |
{ |
| 531 |
ddjvu_fileinfo_t &info = d->files[fileno]; |
| 532 |
QString msg; |
| 533 |
if (info.type == 'P') |
| 534 |
{ |
| 535 |
if (info.title && info.name && strcmp(info.title, info.name)) |
| 536 |
msg = tr8("Page #%1 - \302\253 %2 \302\273") // << .. >> |
| 537 |
.arg(info.pageno + 1).arg(QString::fromUtf8(info.title)); |
| 538 |
else |
| 539 |
msg = tr("Page #%1").arg(info.pageno + 1); |
| 540 |
} |
| 541 |
else if (info.type == 'T') |
| 542 |
msg = tr("Thumbnails"); |
| 543 |
else if (info.type == 'S') |
| 544 |
msg = tr("Shared annotations"); |
| 545 |
else |
| 546 |
msg = tr("Shared data"); |
| 547 |
fileCombo->addItem(tr("File #%1 - ").arg(fileno+1) + msg); |
| 548 |
} |
| 549 |
} |
| 550 |
|
| 551 |
void |
| 552 |
QDjViewInfoDialog::fillDocLabel() |
| 553 |
{ |
| 554 |
if (d->document && d->files.size()) |
| 555 |
{ |
| 556 |
QStringList msg; |
| 557 |
QDjVuDocument *doc = d->document; |
| 558 |
ddjvu_document_type_t docType = ddjvu_document_get_type(*doc); |
| 559 |
if (docType == DDJVU_DOCTYPE_SINGLEPAGE) |
| 560 |
msg << tr("Single DjVu page"); |
| 561 |
else |
| 562 |
{ |
| 563 |
if (docType == DDJVU_DOCTYPE_BUNDLED) |
| 564 |
msg << tr("Bundled DjVu document"); |
| 565 |
else if (docType == DDJVU_DOCTYPE_INDIRECT) |
| 566 |
msg << tr("Indirect DjVu document"); |
| 567 |
else if (docType == DDJVU_DOCTYPE_OLD_BUNDLED) |
| 568 |
msg << tr("Obsolete bundled DjVu document"); |
| 569 |
else if (docType == DDJVU_DOCTYPE_OLD_INDEXED) |
| 570 |
msg << tr("Obsolete indexed DjVu document"); |
| 571 |
|
| 572 |
int pagenum = ddjvu_document_get_pagenum(*doc); |
| 573 |
int filenum = ddjvu_document_get_filenum(*doc); |
| 574 |
msg << ((filenum==1) ? tr("1 file") : tr("%n files", 0, filenum)); |
| 575 |
msg << ((pagenum==1) ? tr("1 page") : tr("%n pages", 0, pagenum)); |
| 576 |
} |
| 577 |
d->ui.docLabel->setText(msg.join(" - ")); |
| 578 |
} |
| 579 |
} |
| 580 |
|
| 581 |
void |
| 582 |
QDjViewInfoDialog::fillDocTable() |
| 583 |
{ |
| 584 |
int filenum = d->files.size(); |
| 585 |
QTableWidget *table = d->ui.docTable; |
| 586 |
table->setRowCount(filenum); |
| 587 |
table->setSortingEnabled(false); |
| 588 |
for (int i=0; i<filenum; i++) |
| 589 |
fillDocRow(i); |
| 590 |
table->resizeColumnsToContents(); |
| 591 |
table->resizeRowsToContents(); |
| 592 |
table->horizontalHeader()->setStretchLastSection(true); |
| 593 |
} |
| 594 |
|
| 595 |
void |
| 596 |
QDjViewInfoDialog::fillDocRow(int i) |
| 597 |
{ |
| 598 |
ddjvu_fileinfo_t &info = d->files[i]; |
| 599 |
QTableWidget *table = d->ui.docTable; |
| 600 |
|
| 601 |
QTableWidgetItem *numItem = new QTableWidgetItem(); |
| 602 |
numItem->setText(QString("%1 ").arg(i+1,5)); |
| 603 |
numItem->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
| 604 |
numItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); |
| 605 |
table->setItem(i, 0, numItem); |
| 606 |
|
| 607 |
QTableWidgetItem *nameItem = new QTableWidgetItem(); |
| 608 |
QString name = (info.name) ? QString::fromUtf8(info.name) : tr("n/a"); |
| 609 |
nameItem->setText(QString(" %1 ").arg(name)); |
| 610 |
nameItem->setTextAlignment(Qt::AlignLeft|Qt::AlignVCenter); |
| 611 |
nameItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); |
| 612 |
table->setItem(i, 1, nameItem); |
| 613 |
|
| 614 |
QTableWidgetItem *sizeItem = new QTableWidgetItem(); |
| 615 |
sizeItem->setText((info.size>0) ? QString(" %1 ").arg(info.size) : tr("n/a")); |
| 616 |
sizeItem->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
| 617 |
sizeItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); |
| 618 |
table->setItem(i, 2, sizeItem); |
| 619 |
|
| 620 |
QTableWidgetItem *typeItem = new QTableWidgetItem(); |
| 621 |
if (info.type == 'P') |
| 622 |
typeItem->setText(tr(" Page ")); |
| 623 |
else if (info.type == 'T') |
| 624 |
typeItem->setText(tr(" Thumbnails ")); |
| 625 |
else |
| 626 |
typeItem->setText(tr(" Shared ")); |
| 627 |
typeItem->setTextAlignment(Qt::AlignLeft|Qt::AlignVCenter); |
| 628 |
typeItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); |
| 629 |
table->setItem(i, 3, typeItem); |
| 630 |
|
| 631 |
QTableWidgetItem *pnumItem = new QTableWidgetItem(); |
| 632 |
if (info.type == 'P') |
| 633 |
pnumItem->setText(QString(" %1 ").arg(info.pageno+1)); |
| 634 |
pnumItem->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
| 635 |
pnumItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); |
| 636 |
table->setItem(i, 4, pnumItem); |
| 637 |
|
| 638 |
QTableWidgetItem *titleItem = new QTableWidgetItem(); |
| 639 |
if (info.type == 'P') |
| 640 |
{ |
| 641 |
QString title = d->djview->pageName(info.pageno, true); |
| 642 |
titleItem->setText(QString(" %1 ").arg(title)); |
| 643 |
} |
| 644 |
titleItem->setTextAlignment(Qt::AlignLeft|Qt::AlignVCenter); |
| 645 |
titleItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); |
| 646 |
table->setItem(i, 5, titleItem); |
| 647 |
} |
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
// ======================================= |
| 654 |
// QDJVIEWMETADIALOG |
| 655 |
// ======================================= |
| 656 |
|
| 657 |
|
| 658 |
#include "ui_qdjviewmetadialog.h" |
| 659 |
|
| 660 |
struct QDjViewMetaDialog::Private { |
| 661 |
Ui::QDjViewMetaDialog ui; |
| 662 |
QDjView *djview; |
| 663 |
QDjVuDocument *document; |
| 664 |
int pageno; |
| 665 |
minivar_t docAnno; |
| 666 |
minivar_t pageAnno; |
| 667 |
}; |
| 668 |
|
| 669 |
|
| 670 |
QDjViewMetaDialog::~QDjViewMetaDialog() |
| 671 |
{ |
| 672 |
delete d; |
| 673 |
} |
| 674 |
|
| 675 |
|
| 676 |
QDjViewMetaDialog::QDjViewMetaDialog(QDjView *parent) |
| 677 |
: QDialog(parent), d(new Private) |
| 678 |
{ |
| 679 |
d->djview = parent; |
| 680 |
d->document = 0; |
| 681 |
d->pageno = 0; |
| 682 |
d->docAnno = miniexp_dummy; |
| 683 |
d->pageAnno = miniexp_dummy; |
| 684 |
d->ui.setupUi(this); |
| 685 |
|
| 686 |
// get preferences |
| 687 |
QDjViewPrefs *prefs = QDjViewPrefs::instance(); |
| 688 |
int index = prefs->metaDialogTab; |
| 689 |
if (index >= 0 && index < d->ui.tabWidget->count()) |
| 690 |
d->ui.tabWidget->setCurrentIndex(index); |
| 691 |
|
| 692 |
// make ctrl+c work |
| 693 |
new QShortcut(QKeySequence(tr("Ctrl+C","copy")), this, SLOT(copy())); |
| 694 |
// tweaks |
| 695 |
QStringList labels; |
| 696 |
labels << tr(" Key ") << tr(" Value "); |
| 697 |
d->ui.docTable->setColumnCount(2); |
| 698 |
d->ui.docTable->setHorizontalHeaderLabels(labels); |
| 699 |
d->ui.docTable->horizontalHeader()->setHighlightSections(false); |
| 700 |
d->ui.docTable->horizontalHeader()->setStretchLastSection(true); |
| 701 |
#if QT_VERSION >= 0x50000 |
| 702 |
d->ui.docTable->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); |
| 703 |
#else |
| 704 |
d->ui.docTable->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); |
| 705 |
#endif |
| 706 |
d->ui.docTable->verticalHeader()->hide(); |
| 707 |
d->ui.pageTable->setColumnCount(2); |
| 708 |
d->ui.pageTable->setHorizontalHeaderLabels(labels); |
| 709 |
d->ui.pageTable->horizontalHeader()->setHighlightSections(false); |
| 710 |
d->ui.pageTable->horizontalHeader()->setStretchLastSection(true); |
| 711 |
#if QT_VERSION >= 0x50000 |
| 712 |
d->ui.pageTable->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); |
| 713 |
#else |
| 714 |
d->ui.pageTable->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); |
| 715 |
#endif |
| 716 |
d->ui.pageTable->verticalHeader()->hide(); |
| 717 |
d->ui.pageCombo->setEnabled(false); |
| 718 |
d->ui.jumpButton->setEnabled(false); |
| 719 |
d->ui.prevButton->setEnabled(false); |
| 720 |
d->ui.nextButton->setEnabled(false); |
| 721 |
// connections |
| 722 |
connect(d->djview, SIGNAL(documentClosed(QDjVuDocument*)), |
| 723 |
this, SLOT(clear()) ); |
| 724 |
connect(d->djview, SIGNAL(documentReady(QDjVuDocument*)), |
| 725 |
this, SLOT(refresh())); |
| 726 |
connect(d->djview->getDjVuWidget(), SIGNAL(pageChanged(int)), |
| 727 |
this, SLOT(setPage(int)) ); |
| 728 |
connect(d->ui.jumpButton, SIGNAL(clicked()), |
| 729 |
this, SLOT(jumpToSelectedPage()) ); |
| 730 |
connect(d->ui.pageCombo, SIGNAL(activated(int)), |
| 731 |
this, SLOT(setPage(int)) ); |
| 732 |
connect(d->ui.prevButton, SIGNAL(clicked()), |
| 733 |
this, SLOT(prevPage()) ); |
| 734 |
connect(d->ui.nextButton, SIGNAL(clicked()), |
| 735 |
this, SLOT(nextPage()) ); |
| 736 |
connect(d->ui.pageCombo, SIGNAL(activated(int)), |
| 737 |
this, SLOT(setPage(int)) ); |
| 738 |
// what's this |
| 739 |
QWidget *wd = d->ui.docTab; |
| 740 |
wd->setWhatsThis(tr("<html><b>Document metadata</b><br>" |
| 741 |
"This panel displays metadata pertaining " |
| 742 |
"to the document, such as author, title, " |
| 743 |
"references, etc. " |
| 744 |
"This information can be saved into the document " |
| 745 |
"with program <tt>djvused</tt>: use the commands " |
| 746 |
"<tt>create-shared-ant</tt> and <tt>set-meta</tt>." |
| 747 |
"</html>")); |
| 748 |
QWidget *wp = d->ui.pageTab; |
| 749 |
wp->setWhatsThis(tr("<html><b>Page metadata</b><br>" |
| 750 |
"This panel displays metadata pertaining " |
| 751 |
"to a specific page. " |
| 752 |
"Page specific metadata override document metadata. " |
| 753 |
"This information can be saved into the document " |
| 754 |
"with program <tt>djvused</tt>: use command " |
| 755 |
"<tt>select</tt> to select the page and command " |
| 756 |
"<tt>set-meta</tt> to specify the metadata entries." |
| 757 |
"</html>")); |
| 758 |
} |
| 759 |
|
| 760 |
static QMap<QString,QString> |
| 761 |
metadataFromAnnotations(miniexp_t p) |
| 762 |
{ |
| 763 |
QMap<QString,QString> m; |
| 764 |
miniexp_t s_metadata = miniexp_symbol("metadata"); |
| 765 |
while (miniexp_consp(p)) |
| 766 |
{ |
| 767 |
if (miniexp_caar(p) == s_metadata) |
| 768 |
{ |
| 769 |
miniexp_t q = miniexp_cdar(p); |
| 770 |
while (miniexp_consp(q)) |
| 771 |
{ |
| 772 |
miniexp_t a = miniexp_car(q); |
| 773 |
q = miniexp_cdr(q); |
| 774 |
if (miniexp_consp(a) && |
| 775 |
miniexp_symbolp(miniexp_car(a)) && |
| 776 |
miniexp_stringp(miniexp_cadr(a)) ) |
| 777 |
{ |
| 778 |
QString k; |
| 779 |
k = QString::fromUtf8(miniexp_to_name(miniexp_car(a))); |
| 780 |
m[k] = QString::fromUtf8(miniexp_to_str(miniexp_cadr(a))); |
| 781 |
} |
| 782 |
} |
| 783 |
} |
| 784 |
p = miniexp_cdr(p); |
| 785 |
} |
| 786 |
return m; |
| 787 |
} |
| 788 |
|
| 789 |
static void |
| 790 |
metadataSubtract(QMap<QString,QString> &from, QMap<QString,QString> m) |
| 791 |
{ |
| 792 |
QMap<QString,QString>::const_iterator i = m.constBegin(); |
| 793 |
for( ; i != m.constEnd(); i++) |
| 794 |
if (from.contains(i.key()) && from[i.key()] == i.value()) |
| 795 |
from.remove(i.key()); |
| 796 |
} |
| 797 |
|
| 798 |
static void |
| 799 |
metadataFill(QTableWidget *table, QMap<QString,QString> m) |
| 800 |
{ |
| 801 |
QList<QString> keys; |
| 802 |
QMap<QString,QString>::const_iterator i = m.constBegin(); |
| 803 |
for( ; i != m.constEnd(); i++) |
| 804 |
keys << i.key(); |
| 805 |
std::sort(keys.begin(), keys.end()); |
| 806 |
int nkeys = keys.size(); |
| 807 |
table->setRowCount(nkeys); |
| 808 |
table->setSortingEnabled(false); |
| 809 |
table->setWordWrap(false); |
| 810 |
for(int j = 0; j < nkeys; j++) |
| 811 |
{ |
| 812 |
QTableWidgetItem *kitem = new QTableWidgetItem(keys[j]); |
| 813 |
QTableWidgetItem *vitem = new QTableWidgetItem(m[keys[j]]); |
| 814 |
kitem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); |
| 815 |
vitem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); |
| 816 |
table->setItem(j, 0, kitem); |
| 817 |
table->setItem(j, 1, vitem); |
| 818 |
} |
| 819 |
table->resizeColumnToContents(0); |
| 820 |
} |
| 821 |
|
| 822 |
|
| 823 |
void |
| 824 |
QDjViewMetaDialog::refresh() |
| 825 |
{ |
| 826 |
// new document? |
| 827 |
if (! d->document) |
| 828 |
{ |
| 829 |
QDjVuDocument *doc; |
| 830 |
doc = d->djview->getDjVuWidget()->document(); |
| 831 |
if (! doc) |
| 832 |
return; |
| 833 |
d->document = doc; |
| 834 |
connect(doc, SIGNAL(pageinfo()), |
| 835 |
this, SLOT(refresh()) ); |
| 836 |
} |
| 837 |
// document ready |
| 838 |
if (! d->ui.pageCombo->count()) |
| 839 |
{ |
| 840 |
if (! d->djview->pageNum()) |
| 841 |
return; |
| 842 |
d->djview->fillPageCombo(d->ui.pageCombo); |
| 843 |
d->ui.pageCombo->setEnabled(true); |
| 844 |
d->ui.jumpButton->setEnabled(true); |
| 845 |
} |
| 846 |
// document annotations known |
| 847 |
if (d->docAnno == miniexp_dummy) |
| 848 |
{ |
| 849 |
d->docAnno = d->document->getDocumentAnnotations(); |
| 850 |
if (d->docAnno != miniexp_dummy) |
| 851 |
{ |
| 852 |
QMap<QString,QString> docMeta = metadataFromAnnotations(d->docAnno); |
| 853 |
metadataFill(d->ui.docTable, docMeta); |
| 854 |
} |
| 855 |
} |
| 856 |
// page annotations |
| 857 |
if (d->ui.pageCombo->count() > 0) |
| 858 |
{ |
| 859 |
d->pageno = qBound(0, d->pageno, d->djview->pageNum()-1); |
| 860 |
d->ui.prevButton->setEnabled(d->pageno-1 >= 0); |
| 861 |
d->ui.nextButton->setEnabled(d->pageno+1 < d->djview->pageNum()); |
| 862 |
d->ui.pageCombo->setCurrentIndex(d->pageno); |
| 863 |
if (d->document && d->pageAnno == miniexp_dummy) |
| 864 |
{ |
| 865 |
d->pageAnno = d->document->getPageAnnotations(d->pageno); |
| 866 |
if (d->pageAnno != miniexp_dummy) |
| 867 |
{ |
| 868 |
QMap<QString,QString> docMeta |
| 869 |
= metadataFromAnnotations(d->docAnno); |
| 870 |
QMap<QString,QString> pageMeta |
| 871 |
= metadataFromAnnotations(d->pageAnno); |
| 872 |
metadataSubtract(pageMeta, docMeta); |
| 873 |
metadataFill(d->ui.pageTable, pageMeta); |
| 874 |
} |
| 875 |
} |
| 876 |
} |
| 877 |
} |
| 878 |
|
| 879 |
void |
| 880 |
QDjViewMetaDialog::prevPage() |
| 881 |
{ |
| 882 |
setPage(qMax(d->pageno - 1, 0)); |
| 883 |
} |
| 884 |
|
| 885 |
void |
| 886 |
QDjViewMetaDialog::nextPage() |
| 887 |
{ |
| 888 |
setPage(qMin(d->pageno + 1, d->djview->pageNum() - 1)); |
| 889 |
} |
| 890 |
|
| 891 |
void |
| 892 |
QDjViewMetaDialog::setPage(int pageno) |
| 893 |
{ |
| 894 |
if (d->document && pageno != d->pageno) |
| 895 |
{ |
| 896 |
d->pageno = pageno; |
| 897 |
d->pageAnno = miniexp_dummy; |
| 898 |
d->ui.pageTable->setRowCount(0); |
| 899 |
refresh(); |
| 900 |
} |
| 901 |
} |
| 902 |
|
| 903 |
void |
| 904 |
QDjViewMetaDialog::jumpToSelectedPage() |
| 905 |
{ |
| 906 |
if (d->document && |
| 907 |
d->pageno >= 0 && d->pageno < d->djview->pageNum() ) |
| 908 |
d->djview->goToPage(d->pageno); |
| 909 |
} |
| 910 |
|
| 911 |
void |
| 912 |
QDjViewMetaDialog::clear() |
| 913 |
{ |
| 914 |
hide(); |
| 915 |
if (d->document) |
| 916 |
disconnect(d->document, 0, this, 0); |
| 917 |
d->document = 0; |
| 918 |
d->pageno = 0; |
| 919 |
d->docAnno = miniexp_dummy; |
| 920 |
d->pageAnno = miniexp_dummy; |
| 921 |
d->ui.pageCombo->clear(); |
| 922 |
d->ui.pageCombo->setEnabled(false); |
| 923 |
d->ui.docTable->setRowCount(0); |
| 924 |
d->ui.pageTable->setRowCount(0); |
| 925 |
d->ui.jumpButton->setEnabled(false); |
| 926 |
QDjViewPrefs *prefs = QDjViewPrefs::instance(); |
| 927 |
prefs->infoDialogTab = d->ui.tabWidget->currentIndex(); |
| 928 |
} |
| 929 |
|
| 930 |
void |
| 931 |
QDjViewMetaDialog::copy() |
| 932 |
{ |
| 933 |
QTableWidget *table = d->ui.pageTable; |
| 934 |
if (d->ui.tabWidget->currentWidget() == d->ui.docTab) |
| 935 |
table = d->ui.docTable; |
| 936 |
QList<QTableWidgetItem*> selected = table->selectedItems(); |
| 937 |
if (selected.size() == 1) |
| 938 |
QApplication::clipboard()->setText(selected[0]->text()); |
| 939 |
} |
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
// ======================================= |
| 944 |
// QDJVIEWSAVEDIALOG |
| 945 |
// ======================================= |
| 946 |
|
| 947 |
|
| 948 |
#include "ui_qdjviewsavedialog.h" |
| 949 |
|
| 950 |
|
| 951 |
struct QDjViewSaveDialog::Private |
| 952 |
{ |
| 953 |
QDjView *djview; |
| 954 |
QDjVuDocument *document; |
| 955 |
Ui::QDjViewSaveDialog ui; |
| 956 |
QDjViewExporter *exporter; |
| 957 |
bool stopping; |
| 958 |
}; |
| 959 |
|
| 960 |
|
| 961 |
QDjViewSaveDialog::~QDjViewSaveDialog() |
| 962 |
{ |
| 963 |
delete d; |
| 964 |
} |
| 965 |
|
| 966 |
|
| 967 |
QDjViewSaveDialog::QDjViewSaveDialog(QDjView *djview) |
| 968 |
: QDialog(djview), d(0) |
| 969 |
{ |
| 970 |
d = new QDjViewSaveDialog::Private; |
| 971 |
|
| 972 |
d->djview = djview; |
| 973 |
d->document = 0; |
| 974 |
d->stopping = false; |
| 975 |
d->exporter = 0; |
| 976 |
|
| 977 |
d->ui.setupUi(this); |
| 978 |
#if QT_VERSION >= 0x60000 |
| 979 |
setWindowModality(Qt::WindowModal); |
| 980 |
#else |
| 981 |
setAttribute(Qt::WA_GroupLeader, true); |
| 982 |
#endif |
| 983 |
connect(d->ui.okButton, SIGNAL(clicked()), |
| 984 |
this, SLOT(start())); |
| 985 |
connect(d->ui.stopButton, SIGNAL(clicked()), |
| 986 |
this, SLOT(stop())); |
| 987 |
connect(d->ui.browseButton, SIGNAL(clicked()), |
| 988 |
this, SLOT(browse())); |
| 989 |
connect(d->ui.formatCombo, SIGNAL(activated(int)), |
| 990 |
this, SLOT(refresh())); |
| 991 |
connect(d->ui.fileNameEdit, SIGNAL(textChanged(QString)), |
| 992 |
this, SLOT(refresh())); |
| 993 |
connect(djview, SIGNAL(documentClosed(QDjVuDocument*)), |
| 994 |
this, SLOT(clear())); |
| 995 |
connect(djview, SIGNAL(documentReady(QDjVuDocument*)), |
| 996 |
this, SLOT(refresh())); |
| 997 |
|
| 998 |
setWhatsThis(tr("<html><b>Saving.</b><br/> " |
| 999 |
"You can save the whole document or a page range. " |
| 1000 |
"The bundled format creates a single file. " |
| 1001 |
"The indirect format creates multiple files " |
| 1002 |
"suitable for web serving.</html>")); |
| 1003 |
refresh(); |
| 1004 |
} |
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
void |
| 1009 |
QDjViewSaveDialog::refresh() |
| 1010 |
{ |
| 1011 |
bool nodoc = !d->document; |
| 1012 |
if (nodoc && d->djview->pageNum() > 0) |
| 1013 |
{ |
| 1014 |
nodoc = false; |
| 1015 |
d->document = d->djview->getDocument(); |
| 1016 |
QString fname = d->djview->getDocumentFileName(); |
| 1017 |
if (fname.isEmpty()) |
| 1018 |
fname = d->djview->getShortFileName(); |
| 1019 |
else |
| 1020 |
fname = QFileInfo(fname).absoluteFilePath(); |
| 1021 |
d->ui.fileNameEdit->setText(fname); |
| 1022 |
d->djview->fillPageCombo(d->ui.fromPageCombo); |
| 1023 |
d->ui.fromPageCombo->setCurrentIndex(0); |
| 1024 |
d->djview->fillPageCombo(d->ui.toPageCombo); |
| 1025 |
d->ui.toPageCombo->setCurrentIndex(d->djview->pageNum()-1); |
| 1026 |
} |
| 1027 |
bool notxt = d->ui.fileNameEdit->text().isEmpty(); |
| 1028 |
bool nojob = true; |
| 1029 |
bool nofmt = true; |
| 1030 |
QDjViewExporter *exporter = d->exporter; |
| 1031 |
QString exporterName = "DJVU/BUNDLED"; |
| 1032 |
if (d->ui.formatCombo->currentIndex() > 0) |
| 1033 |
exporterName = "DJVU/INDIRECT"; |
| 1034 |
if (exporter && |
| 1035 |
exporter->status() <= DDJVU_JOB_STARTED && |
| 1036 |
exporter->name() != exporterName ) |
| 1037 |
{ |
| 1038 |
exporter->saveProperties(); |
| 1039 |
delete exporter; |
| 1040 |
exporter = d->exporter = 0; |
| 1041 |
} |
| 1042 |
if (! exporter) |
| 1043 |
{ |
| 1044 |
exporter = QDjViewExporter::create(this, d->djview, exporterName); |
| 1045 |
if (exporter) |
| 1046 |
{ |
| 1047 |
exporter->loadProperties(); |
| 1048 |
connect(exporter, SIGNAL(progress(int)), this, SLOT(progress(int))); |
| 1049 |
d->exporter = exporter; |
| 1050 |
} |
| 1051 |
} |
| 1052 |
if (exporter) |
| 1053 |
{ |
| 1054 |
nofmt = false; |
| 1055 |
if (exporter->status() >= DDJVU_JOB_STARTED) |
| 1056 |
nojob = false; |
| 1057 |
} |
| 1058 |
d->ui.destinationGroupBox->setEnabled(nojob && !nodoc); |
| 1059 |
d->ui.saveGroupBox->setEnabled(nojob && !nodoc && !nofmt); |
| 1060 |
d->ui.formatCombo->setEnabled(nojob && !nodoc && !nofmt); |
| 1061 |
d->ui.okButton->setEnabled(nojob && !nodoc && !notxt && !nofmt); |
| 1062 |
d->ui.cancelButton->setEnabled(nojob); |
| 1063 |
d->ui.stopButton->setEnabled(!nojob); |
| 1064 |
d->ui.stackedWidget->setCurrentIndex(nojob ? 0 : 1); |
| 1065 |
} |
| 1066 |
|
| 1067 |
|
| 1068 |
void |
| 1069 |
QDjViewSaveDialog::clear() |
| 1070 |
{ |
| 1071 |
d->stopping = true; |
| 1072 |
reject(); |
| 1073 |
} |
| 1074 |
|
| 1075 |
|
| 1076 |
void |
| 1077 |
QDjViewSaveDialog::start() |
| 1078 |
{ |
| 1079 |
QString fname = d->ui.fileNameEdit->text(); |
| 1080 |
QFileInfo info(fname); |
| 1081 |
if (info.exists()) |
| 1082 |
{ |
| 1083 |
QString docname = d->djview->getDocumentFileName(); |
| 1084 |
if (info == QFileInfo(docname) && ! docname.isEmpty()) |
| 1085 |
{ |
| 1086 |
QMessageBox::critical(this, |
| 1087 |
tr("Error - DjView", "dialog caption"), |
| 1088 |
tr("Overwriting the current file " |
| 1089 |
"is not allowed!" ) ); |
| 1090 |
return; |
| 1091 |
} |
| 1092 |
if ( QMessageBox::question(this, |
| 1093 |
tr("Question - DjView", "dialog caption"), |
| 1094 |
tr("A file with this name already exists.\n" |
| 1095 |
"Do you want to replace it?"), |
| 1096 |
tr("&Replace"), |
| 1097 |
tr("&Cancel") )) |
| 1098 |
return; |
| 1099 |
} |
| 1100 |
QDjViewExporter *exporter = d->exporter; |
| 1101 |
if (exporter) |
| 1102 |
{ |
| 1103 |
int lastPage = d->djview->pageNum()-1; |
| 1104 |
int curPage = d->djview->getDjVuWidget()->page(); |
| 1105 |
int fromPage = d->ui.fromPageCombo->currentIndex(); |
| 1106 |
int toPage = d->ui.toPageCombo->currentIndex(); |
| 1107 |
if (d->ui.currentPageButton->isChecked()) |
| 1108 |
exporter->setFromTo(curPage, curPage); |
| 1109 |
else if (d->ui.pageRangeButton->isChecked()) |
| 1110 |
exporter->setFromTo(fromPage, toPage); |
| 1111 |
else |
| 1112 |
exporter->setFromTo(0, lastPage); |
| 1113 |
// ignition! |
| 1114 |
exporter->save(fname); |
| 1115 |
} |
| 1116 |
refresh(); |
| 1117 |
} |
| 1118 |
|
| 1119 |
|
| 1120 |
void |
| 1121 |
QDjViewSaveDialog::progress(int percent) |
| 1122 |
{ |
| 1123 |
ddjvu_status_t jobstatus = DDJVU_JOB_NOTSTARTED; |
| 1124 |
QDjViewExporter *exporter = d->exporter; |
| 1125 |
if (exporter) |
| 1126 |
jobstatus = exporter->status(); |
| 1127 |
d->ui.progressBar->setValue(percent); |
| 1128 |
switch(jobstatus) |
| 1129 |
{ |
| 1130 |
case DDJVU_JOB_OK: |
| 1131 |
QTimer::singleShot(0, this, SLOT(accept())); |
| 1132 |
break; |
| 1133 |
case DDJVU_JOB_FAILED: |
| 1134 |
exporter->error(tr("This operation has failed."), |
| 1135 |
__FILE__, __LINE__); |
| 1136 |
break; |
| 1137 |
case DDJVU_JOB_STOPPED: |
| 1138 |
exporter->error(tr("This operation has been interrupted."), |
| 1139 |
__FILE__, __LINE__); |
| 1140 |
break; |
| 1141 |
default: |
| 1142 |
break; |
| 1143 |
} |
| 1144 |
} |
| 1145 |
|
| 1146 |
|
| 1147 |
void |
| 1148 |
QDjViewSaveDialog::stop() |
| 1149 |
{ |
| 1150 |
QDjViewExporter *exporter = d->exporter; |
| 1151 |
if (exporter && exporter->status() == DDJVU_JOB_STARTED) |
| 1152 |
{ |
| 1153 |
exporter->stop(); |
| 1154 |
d->ui.stopButton->setEnabled(false); |
| 1155 |
d->stopping = true; |
| 1156 |
} |
| 1157 |
} |
| 1158 |
|
| 1159 |
|
| 1160 |
void |
| 1161 |
QDjViewSaveDialog::browse() |
| 1162 |
{ |
| 1163 |
QString fname = d->ui.fileNameEdit->text(); |
| 1164 |
QStringList info = QDjViewExporter::info("DJVU/BUNDLED"); |
| 1165 |
QString filters = tr("All files", "save filter") + " (*)"; |
| 1166 |
QString suffix; |
| 1167 |
if (info.size() > 3) |
| 1168 |
filters = info[3] + ";;" + filters; |
| 1169 |
if (info.size() > 1) |
| 1170 |
suffix = info[1]; |
| 1171 |
fname = QFileDialog::getSaveFileName(this, |
| 1172 |
tr("Save - DjView", "dialog caption"), |
| 1173 |
fname, filters, 0, |
| 1174 |
QFileDialog::DontConfirmOverwrite); |
| 1175 |
if (! fname.isEmpty()) |
| 1176 |
{ |
| 1177 |
QFileInfo finfo(fname); |
| 1178 |
if (finfo.suffix().isEmpty() && !suffix.isEmpty()) |
| 1179 |
fname = QFileInfo(finfo.dir(), finfo.completeBaseName() |
| 1180 |
+ "." + suffix).filePath(); |
| 1181 |
d->ui.fileNameEdit->setText(fname); |
| 1182 |
} |
| 1183 |
} |
| 1184 |
|
| 1185 |
|
| 1186 |
void |
| 1187 |
QDjViewSaveDialog::done(int reason) |
| 1188 |
{ |
| 1189 |
setEnabled(false); |
| 1190 |
QDjViewExporter *exporter = d->exporter; |
| 1191 |
if (!d->stopping && exporter && exporter->status()==DDJVU_JOB_STARTED) |
| 1192 |
{ |
| 1193 |
stop(); |
| 1194 |
return; |
| 1195 |
} |
| 1196 |
if (exporter) |
| 1197 |
exporter->saveProperties(); |
| 1198 |
delete exporter; |
| 1199 |
d->exporter = 0; |
| 1200 |
QDialog::done(reason); |
| 1201 |
} |
| 1202 |
|
| 1203 |
|
| 1204 |
void |
| 1205 |
QDjViewSaveDialog::closeEvent(QCloseEvent *event) |
| 1206 |
{ |
| 1207 |
QDjViewExporter *exporter = d->exporter; |
| 1208 |
if (!d->stopping && exporter && exporter->status()==DDJVU_JOB_STARTED) |
| 1209 |
{ |
| 1210 |
stop(); |
| 1211 |
event->ignore(); |
| 1212 |
return; |
| 1213 |
} |
| 1214 |
if (exporter) |
| 1215 |
exporter->saveProperties(); |
| 1216 |
delete exporter; |
| 1217 |
d->exporter = 0; |
| 1218 |
event->accept(); |
| 1219 |
QDialog::closeEvent(event); |
| 1220 |
} |
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
// ======================================= |
| 1227 |
// QDJVIEWEXPORTDIALOG |
| 1228 |
// ======================================= |
| 1229 |
|
| 1230 |
|
| 1231 |
#include "ui_qdjviewexportdialog.h" |
| 1232 |
|
| 1233 |
|
| 1234 |
struct QDjViewExportDialog::Private |
| 1235 |
{ |
| 1236 |
QDjView *djview; |
| 1237 |
QDjVuDocument *document; |
| 1238 |
Ui::QDjViewExportDialog ui; |
| 1239 |
bool stopping; |
| 1240 |
QDjViewExporter *exporter; |
| 1241 |
QStringList exporterNames; |
| 1242 |
}; |
| 1243 |
|
| 1244 |
|
| 1245 |
QDjViewExportDialog::~QDjViewExportDialog() |
| 1246 |
{ |
| 1247 |
delete d; |
| 1248 |
} |
| 1249 |
|
| 1250 |
|
| 1251 |
QDjViewExportDialog::QDjViewExportDialog(QDjView *djview) |
| 1252 |
: QDialog(djview), d(0) |
| 1253 |
{ |
| 1254 |
d = new QDjViewExportDialog::Private; |
| 1255 |
|
| 1256 |
d->djview = djview; |
| 1257 |
d->document = 0; |
| 1258 |
d->stopping = false; |
| 1259 |
d->exporter = 0; |
| 1260 |
|
| 1261 |
d->ui.setupUi(this); |
| 1262 |
#if QT_VERSION >= 0x60000 |
| 1263 |
setWindowModality(Qt::WindowModal); |
| 1264 |
#else |
| 1265 |
setAttribute(Qt::WA_GroupLeader, true); |
| 1266 |
#endif |
| 1267 |
|
| 1268 |
connect(d->ui.okButton, SIGNAL(clicked()), |
| 1269 |
this, SLOT(start())); |
| 1270 |
connect(d->ui.stopButton, SIGNAL(clicked()), |
| 1271 |
this, SLOT(stop())); |
| 1272 |
connect(d->ui.browseButton, SIGNAL(clicked()), |
| 1273 |
this, SLOT(browse())); |
| 1274 |
connect(d->ui.formatCombo, SIGNAL(activated(int)), |
| 1275 |
this, SLOT(refresh())); |
| 1276 |
connect(d->ui.resetButton, SIGNAL(clicked()), |
| 1277 |
this, SLOT(reset())); |
| 1278 |
connect(d->ui.fileNameEdit, SIGNAL(textChanged(QString)), |
| 1279 |
this, SLOT(refresh())); |
| 1280 |
connect(djview, SIGNAL(documentClosed(QDjVuDocument*)), |
| 1281 |
this, SLOT(clear())); |
| 1282 |
connect(djview, SIGNAL(documentReady(QDjVuDocument*)), |
| 1283 |
this, SLOT(refresh())); |
| 1284 |
|
| 1285 |
setWhatsThis(tr("<html><b>Saving.</b><br/> " |
| 1286 |
"You can save the whole document or a page range " |
| 1287 |
"under a variety of formats. Selecting certain " |
| 1288 |
"formats creates additional dialog pages for " |
| 1289 |
"specifying format options.</html>")); |
| 1290 |
|
| 1291 |
foreach (QString name, QDjViewExporter::names()) |
| 1292 |
if (!name.startsWith("DJVU") && !name.startsWith("PRN")) |
| 1293 |
{ |
| 1294 |
QStringList info = QDjViewExporter::info(name); |
| 1295 |
if (info.size() > 2) |
| 1296 |
{ |
| 1297 |
d->exporterNames << name; |
| 1298 |
d->ui.formatCombo->addItem(info[2], QVariant(name)); |
| 1299 |
} |
| 1300 |
} |
| 1301 |
d->ui.formatCombo->setCurrentIndex(0); |
| 1302 |
refresh(); |
| 1303 |
} |
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
void |
| 1308 |
QDjViewExportDialog::refresh() |
| 1309 |
{ |
| 1310 |
bool nodoc = !d->document; |
| 1311 |
if (nodoc && d->djview->pageNum() > 0) |
| 1312 |
{ |
| 1313 |
nodoc = false; |
| 1314 |
d->document = d->djview->getDocument(); |
| 1315 |
QString fname = d->djview->getDocumentFileName(); |
| 1316 |
if (fname.isEmpty()) |
| 1317 |
fname = d->djview->getShortFileName(); |
| 1318 |
else |
| 1319 |
fname = QFileInfo(fname).absoluteFilePath(); |
| 1320 |
d->ui.fileNameEdit->setText(fname); |
| 1321 |
d->djview->fillPageCombo(d->ui.fromPageCombo); |
| 1322 |
d->ui.fromPageCombo->setCurrentIndex(0); |
| 1323 |
d->djview->fillPageCombo(d->ui.toPageCombo); |
| 1324 |
d->ui.toPageCombo->setCurrentIndex(d->djview->pageNum()-1); |
| 1325 |
} |
| 1326 |
bool notxt = d->ui.fileNameEdit->text().isEmpty(); |
| 1327 |
bool nojob = true; |
| 1328 |
bool nofmt = true; |
| 1329 |
bool noopt = true; |
| 1330 |
QDjViewExporter *exporter = d->exporter; |
| 1331 |
int formatIndex = d->ui.formatCombo->currentIndex(); |
| 1332 |
QString formatName = d->ui.formatCombo->itemData(formatIndex).toString(); |
| 1333 |
if (exporter && |
| 1334 |
exporter->status() <= DDJVU_JOB_STARTED && |
| 1335 |
exporter->name() != formatName ) |
| 1336 |
{ |
| 1337 |
exporter->saveProperties(); |
| 1338 |
delete exporter; |
| 1339 |
exporter = d->exporter = 0; |
| 1340 |
} |
| 1341 |
if (! exporter) |
| 1342 |
{ |
| 1343 |
exporter = QDjViewExporter::create(this, d->djview, formatName); |
| 1344 |
if (exporter) |
| 1345 |
{ |
| 1346 |
exporter->loadProperties(); |
| 1347 |
connect(exporter, SIGNAL(progress(int)), this, SLOT(progress(int))); |
| 1348 |
d->exporter = exporter; |
| 1349 |
// update tabs |
| 1350 |
while (d->ui.tabWidget->count() > 1) |
| 1351 |
d->ui.tabWidget->removeTab(1); |
| 1352 |
QWidget *w; |
| 1353 |
for (int i=0; i<exporter->propertyPages(); i++) |
| 1354 |
if ((w = exporter->propertyPage(i))) |
| 1355 |
d->ui.tabWidget->addTab(w, w->objectName()); |
| 1356 |
// update fname |
| 1357 |
QString fname = d->ui.fileNameEdit->text(); |
| 1358 |
QStringList info = QDjViewExporter::info(formatName); |
| 1359 |
if (info.size() > 1) |
| 1360 |
{ |
| 1361 |
QString suffix = info[1]; |
| 1362 |
QFileInfo finfo(fname); |
| 1363 |
if (!finfo.suffix().isEmpty() && !suffix.isEmpty()) |
| 1364 |
fname = QFileInfo(finfo.dir(), finfo.completeBaseName() |
| 1365 |
+ "." + suffix).filePath(); |
| 1366 |
d->ui.fileNameEdit->setText(fname); |
| 1367 |
} |
| 1368 |
// update exportgroupbox |
| 1369 |
disconnect(d->ui.fromPageCombo, 0, d->ui.toPageCombo, 0); |
| 1370 |
d->ui.documentButton->setEnabled(true); |
| 1371 |
d->ui.toPageCombo->setEnabled(true); |
| 1372 |
d->ui.toLabel->setEnabled(true); |
| 1373 |
if (exporter->exportOnePageOnly()) |
| 1374 |
{ |
| 1375 |
connect(d->ui.fromPageCombo, SIGNAL(activated(int)), |
| 1376 |
d->ui.toPageCombo, SLOT(setCurrentIndex(int))); |
| 1377 |
d->ui.toPageCombo->setEnabled(false); |
| 1378 |
d->ui.toLabel->setEnabled(false); |
| 1379 |
d->ui.documentButton->setEnabled(false); |
| 1380 |
if (d->ui.documentButton->isChecked()) |
| 1381 |
d->ui.currentPageButton->setChecked(true); |
| 1382 |
int page = d->ui.fromPageCombo->currentIndex(); |
| 1383 |
d->ui.toPageCombo->setCurrentIndex(page); |
| 1384 |
} |
| 1385 |
} |
| 1386 |
} |
| 1387 |
if (exporter) |
| 1388 |
{ |
| 1389 |
nofmt = false; |
| 1390 |
if (exporter->status() >= DDJVU_JOB_STARTED) |
| 1391 |
nojob = false; |
| 1392 |
if (exporter->propertyPages() > 0) |
| 1393 |
noopt = false; |
| 1394 |
QWidget *w = 0; |
| 1395 |
for (int i=0; i<exporter->propertyPages(); i++) |
| 1396 |
if ((w = exporter->propertyPage(i))) |
| 1397 |
w->setEnabled(nojob); |
| 1398 |
} |
| 1399 |
d->ui.destinationGroupBox->setEnabled(nojob && !nodoc); |
| 1400 |
d->ui.saveGroupBox->setEnabled(nojob && !nodoc && !nofmt); |
| 1401 |
d->ui.resetButton->setEnabled(nojob && !nodoc && !noopt); |
| 1402 |
d->ui.okButton->setEnabled(nojob && !nodoc && !notxt && !nofmt); |
| 1403 |
d->ui.cancelButton->setEnabled(nojob); |
| 1404 |
d->ui.stopButton->setEnabled(!nojob); |
| 1405 |
d->ui.stackedWidget->setCurrentIndex(nojob ? 0 : 1); |
| 1406 |
} |
| 1407 |
|
| 1408 |
|
| 1409 |
void |
| 1410 |
QDjViewExportDialog::clear() |
| 1411 |
{ |
| 1412 |
d->stopping = true; |
| 1413 |
reject(); |
| 1414 |
} |
| 1415 |
|
| 1416 |
|
| 1417 |
void |
| 1418 |
QDjViewExportDialog::reset() |
| 1419 |
{ |
| 1420 |
QDjViewExporter *exporter = d->exporter; |
| 1421 |
if (exporter) |
| 1422 |
exporter->resetProperties(); |
| 1423 |
refresh(); |
| 1424 |
} |
| 1425 |
|
| 1426 |
|
| 1427 |
void |
| 1428 |
QDjViewExportDialog::start() |
| 1429 |
{ |
| 1430 |
QString fname = d->ui.fileNameEdit->text(); |
| 1431 |
QFileInfo info(fname); |
| 1432 |
if (info.exists()) |
| 1433 |
{ |
| 1434 |
QString docname = d->djview->getDocumentFileName(); |
| 1435 |
if (info == QFileInfo(docname) && ! docname.isEmpty()) |
| 1436 |
{ |
| 1437 |
QMessageBox::critical(this, |
| 1438 |
tr("Error - DjView", "dialog caption"), |
| 1439 |
tr("Overwriting the current file " |
| 1440 |
"is not allowed!" ) ); |
| 1441 |
return; |
| 1442 |
} |
| 1443 |
if ( QMessageBox::question(this, |
| 1444 |
tr("Question - DjView", "dialog caption"), |
| 1445 |
tr("A file with this name already exists.\n" |
| 1446 |
"Do you want to replace it?"), |
| 1447 |
tr("&Replace"), |
| 1448 |
tr("&Cancel") )) |
| 1449 |
return; |
| 1450 |
} |
| 1451 |
QDjViewExporter *exporter = d->exporter; |
| 1452 |
if (exporter) |
| 1453 |
{ |
| 1454 |
int lastPage = d->djview->pageNum()-1; |
| 1455 |
int curPage = d->djview->getDjVuWidget()->page(); |
| 1456 |
int fromPage = d->ui.fromPageCombo->currentIndex(); |
| 1457 |
int toPage = d->ui.toPageCombo->currentIndex(); |
| 1458 |
if (d->ui.currentPageButton->isChecked()) |
| 1459 |
exporter->setFromTo(curPage, curPage); |
| 1460 |
else if (d->ui.pageRangeButton->isChecked()) |
| 1461 |
exporter->setFromTo(fromPage, toPage); |
| 1462 |
else |
| 1463 |
exporter->setFromTo(0, lastPage); |
| 1464 |
// ignition! |
| 1465 |
exporter->save(fname); |
| 1466 |
} |
| 1467 |
refresh(); |
| 1468 |
} |
| 1469 |
|
| 1470 |
|
| 1471 |
void |
| 1472 |
QDjViewExportDialog::progress(int percent) |
| 1473 |
{ |
| 1474 |
QDjViewExporter *exporter = d->exporter; |
| 1475 |
ddjvu_status_t jobstatus = DDJVU_JOB_NOTSTARTED; |
| 1476 |
if (exporter) |
| 1477 |
jobstatus = exporter->status(); |
| 1478 |
d->ui.progressBar->setValue(percent); |
| 1479 |
switch(jobstatus) |
| 1480 |
{ |
| 1481 |
case DDJVU_JOB_OK: |
| 1482 |
QTimer::singleShot(0, this, SLOT(accept())); |
| 1483 |
break; |
| 1484 |
case DDJVU_JOB_FAILED: |
| 1485 |
exporter->error(tr("This operation has failed."), |
| 1486 |
__FILE__, __LINE__); |
| 1487 |
break; |
| 1488 |
case DDJVU_JOB_STOPPED: |
| 1489 |
exporter->error(tr("This operation has been interrupted."), |
| 1490 |
__FILE__, __LINE__); |
| 1491 |
break; |
| 1492 |
default: |
| 1493 |
break; |
| 1494 |
} |
| 1495 |
} |
| 1496 |
|
| 1497 |
|
| 1498 |
void |
| 1499 |
QDjViewExportDialog::stop() |
| 1500 |
{ |
| 1501 |
QDjViewExporter *exporter = d->exporter; |
| 1502 |
if (exporter && exporter->status() == DDJVU_JOB_STARTED) |
| 1503 |
{ |
| 1504 |
exporter->stop(); |
| 1505 |
d->ui.stopButton->setEnabled(false); |
| 1506 |
d->stopping = true; |
| 1507 |
} |
| 1508 |
} |
| 1509 |
|
| 1510 |
|
| 1511 |
void |
| 1512 |
QDjViewExportDialog::browse() |
| 1513 |
{ |
| 1514 |
QString fname = d->ui.fileNameEdit->text(); |
| 1515 |
QDjViewExporter *exporter = d->exporter; |
| 1516 |
QString format = (exporter) ? exporter->name() : QString(); |
| 1517 |
QStringList info = QDjViewExporter::info(format); |
| 1518 |
QString filters = tr("All files", "save filter") + " (*)"; |
| 1519 |
QString suffix; |
| 1520 |
if (info.size() > 3) |
| 1521 |
filters = info[3] + ";;" + filters; |
| 1522 |
if (info.size() > 1) |
| 1523 |
suffix = info[1]; |
| 1524 |
fname = QFileDialog::getSaveFileName(this, |
| 1525 |
tr("Export - DjView", "dialog caption"), |
| 1526 |
fname, filters, 0, |
| 1527 |
QFileDialog::DontConfirmOverwrite); |
| 1528 |
if (! fname.isEmpty()) |
| 1529 |
{ |
| 1530 |
QFileInfo finfo(fname); |
| 1531 |
if (finfo.suffix().isEmpty() && !suffix.isEmpty()) |
| 1532 |
fname = QFileInfo(finfo.dir(), finfo.completeBaseName() |
| 1533 |
+ "." + suffix).filePath(); |
| 1534 |
d->ui.fileNameEdit->setText(fname); |
| 1535 |
} |
| 1536 |
} |
| 1537 |
|
| 1538 |
|
| 1539 |
void |
| 1540 |
QDjViewExportDialog::done(int reason) |
| 1541 |
{ |
| 1542 |
setEnabled(false); |
| 1543 |
QDjViewExporter *exporter = d->exporter; |
| 1544 |
if (!d->stopping && exporter && exporter->status()==DDJVU_JOB_STARTED) |
| 1545 |
{ |
| 1546 |
stop(); |
| 1547 |
return; |
| 1548 |
} |
| 1549 |
if (exporter) |
| 1550 |
exporter->saveProperties(); |
| 1551 |
delete exporter; |
| 1552 |
d->exporter = 0; |
| 1553 |
QDialog::done(reason); |
| 1554 |
} |
| 1555 |
|
| 1556 |
|
| 1557 |
void |
| 1558 |
QDjViewExportDialog::closeEvent(QCloseEvent *event) |
| 1559 |
{ |
| 1560 |
QDjViewExporter *exporter = d->exporter; |
| 1561 |
if (!d->stopping && exporter && exporter->status()==DDJVU_JOB_STARTED) |
| 1562 |
{ |
| 1563 |
stop(); |
| 1564 |
event->ignore(); |
| 1565 |
return; |
| 1566 |
} |
| 1567 |
if (exporter) |
| 1568 |
exporter->saveProperties(); |
| 1569 |
delete exporter; |
| 1570 |
d->exporter = 0; |
| 1571 |
event->accept(); |
| 1572 |
QDialog::closeEvent(event); |
| 1573 |
} |
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
// ======================================= |
| 1580 |
// QDJVIEWPRINTDIALOG |
| 1581 |
// ======================================= |
| 1582 |
|
| 1583 |
|
| 1584 |
#include "ui_qdjviewprintdialog.h" |
| 1585 |
|
| 1586 |
struct QDjViewPrintDialog::Private |
| 1587 |
{ |
| 1588 |
QDjView *djview; |
| 1589 |
QDjVuDocument *document; |
| 1590 |
Ui::QDjViewPrintDialog ui; |
| 1591 |
QDjViewExporter *exporter; |
| 1592 |
QString groupname; |
| 1593 |
QPrinter *printer; |
| 1594 |
bool stopping; |
| 1595 |
}; |
| 1596 |
|
| 1597 |
|
| 1598 |
QDjViewPrintDialog::~QDjViewPrintDialog() |
| 1599 |
{ |
| 1600 |
if (d && d->printer) |
| 1601 |
delete d->printer; |
| 1602 |
if (d) |
| 1603 |
delete d; |
| 1604 |
} |
| 1605 |
|
| 1606 |
|
| 1607 |
QDjViewPrintDialog::QDjViewPrintDialog(QDjView *djview) |
| 1608 |
: QDialog(djview), d(0) |
| 1609 |
{ |
| 1610 |
d = new QDjViewPrintDialog::Private; |
| 1611 |
|
| 1612 |
d->djview = djview; |
| 1613 |
d->document = 0; |
| 1614 |
d->stopping = false; |
| 1615 |
d->exporter = 0; |
| 1616 |
d->printer = new QPrinter(QPrinter::HighResolution); |
| 1617 |
d->ui.setupUi(this); |
| 1618 |
#if QT_VERSION >= 0x60000 |
| 1619 |
setWindowModality(Qt::WindowModal); |
| 1620 |
#else |
| 1621 |
setAttribute(Qt::WA_GroupLeader, true); |
| 1622 |
#endif |
| 1623 |
connect(d->ui.okButton, SIGNAL(clicked()), |
| 1624 |
this, SLOT(start())); |
| 1625 |
connect(d->ui.stopButton, SIGNAL(clicked()), |
| 1626 |
this, SLOT(stop())); |
| 1627 |
connect(d->ui.resetButton, SIGNAL(clicked()), |
| 1628 |
this, SLOT(reset())); |
| 1629 |
connect(djview, SIGNAL(documentClosed(QDjVuDocument*)), |
| 1630 |
this, SLOT(clear())); |
| 1631 |
connect(djview, SIGNAL(documentReady(QDjVuDocument*)), |
| 1632 |
this, SLOT(refresh())); |
| 1633 |
connect(d->ui.printToFileCheckBox, SIGNAL(clicked()), |
| 1634 |
this, SLOT(refresh())); |
| 1635 |
connect(d->ui.fileNameEdit, SIGNAL(textChanged(QString)), |
| 1636 |
this, SLOT(refresh())); |
| 1637 |
connect(d->ui.printerButton, SIGNAL(clicked()), |
| 1638 |
this, SLOT(choose())); |
| 1639 |
connect(d->ui.browseButton, SIGNAL(clicked()), |
| 1640 |
this, SLOT(browse())); |
| 1641 |
|
| 1642 |
setWhatsThis(tr("<html><b>Printing.</b><br/> " |
| 1643 |
"You can print the whole document or a page range. " |
| 1644 |
"Use the <tt>Choose</tt> button to select a print " |
| 1645 |
"destination and specify printer options. Additional " |
| 1646 |
"dialog tabs might appear to specify conversion " |
| 1647 |
"options.</html>")); |
| 1648 |
|
| 1649 |
// Load preferences |
| 1650 |
d->ui.printerLabel->setText(QString()); |
| 1651 |
d->ui.fileNameEdit->setText("print.ps"); |
| 1652 |
QDjViewPrefs *prefs = QDjViewPrefs::instance(); |
| 1653 |
QString printerName = prefs->printerName; |
| 1654 |
QString printFile = prefs->printFile; |
| 1655 |
if (! printFile.isEmpty()) |
| 1656 |
{ |
| 1657 |
d->ui.printToFileCheckBox->setChecked(true); |
| 1658 |
d->ui.fileNameEdit->setText(printFile); |
| 1659 |
printerName = QString(); |
| 1660 |
} |
| 1661 |
else if (! printerName.isEmpty()) |
| 1662 |
{ |
| 1663 |
d->ui.printToFileCheckBox->setChecked(false); |
| 1664 |
d->ui.printerLabel->setText(prefs->printerName); |
| 1665 |
d->printer->setPrinterName(printerName); |
| 1666 |
} |
| 1667 |
else |
| 1668 |
{ |
| 1669 |
printFile = "print.ps"; |
| 1670 |
d->ui.printToFileCheckBox->setChecked(true); |
| 1671 |
d->ui.fileNameEdit->setText(printFile); |
| 1672 |
} |
| 1673 |
d->printer->setCollateCopies(prefs->printCollate); |
| 1674 |
if (prefs->printReverse) |
| 1675 |
d->printer->setPageOrder(QPrinter::LastPageFirst); |
| 1676 |
else |
| 1677 |
d->printer->setPageOrder(QPrinter::FirstPageFirst); |
| 1678 |
|
| 1679 |
// Create exporter |
| 1680 |
#ifdef Q_OS_WIN |
| 1681 |
if (! d->exporter) |
| 1682 |
d->exporter = QDjViewExporter::create(this, d->djview, "PRN"); |
| 1683 |
#endif |
| 1684 |
if (! d->exporter) |
| 1685 |
d->exporter = QDjViewExporter::create(this, d->djview, "PS"); |
| 1686 |
if (! d->exporter) |
| 1687 |
d->exporter = QDjViewExporter::create(this, d->djview, "PRN"); |
| 1688 |
if (d->exporter) |
| 1689 |
{ |
| 1690 |
QDjViewExporter *exporter = d->exporter; |
| 1691 |
exporter->loadProperties("Print-" + d->exporter->name()); |
| 1692 |
// setup exporter property pages |
| 1693 |
QWidget *w; |
| 1694 |
for (int i=0; i<exporter->propertyPages(); i++) |
| 1695 |
if ((w = exporter->propertyPage(i))) |
| 1696 |
d->ui.tabWidget->addTab(w, w->objectName()); |
| 1697 |
// setup exporter connections |
| 1698 |
connect(exporter, SIGNAL(progress(int)), this, SLOT(progress(int))); |
| 1699 |
} |
| 1700 |
// Refresh Ui |
| 1701 |
refresh(); |
| 1702 |
} |
| 1703 |
|
| 1704 |
|
| 1705 |
void |
| 1706 |
QDjViewPrintDialog::refresh() |
| 1707 |
{ |
| 1708 |
bool nodoc = !d->document; |
| 1709 |
if (nodoc && d->djview->pageNum() > 0) |
| 1710 |
{ |
| 1711 |
nodoc = false; |
| 1712 |
d->document = d->djview->getDocument(); |
| 1713 |
d->djview->fillPageCombo(d->ui.fromPageCombo); |
| 1714 |
d->ui.fromPageCombo->setCurrentIndex(0); |
| 1715 |
d->djview->fillPageCombo(d->ui.toPageCombo); |
| 1716 |
d->ui.toPageCombo->setCurrentIndex(d->djview->pageNum()-1); |
| 1717 |
} |
| 1718 |
bool tofile = d->ui.printToFileCheckBox->isChecked(); |
| 1719 |
bool noexp = !d->exporter; |
| 1720 |
bool nojob = true; |
| 1721 |
bool notxt = true; |
| 1722 |
if (tofile) |
| 1723 |
{ |
| 1724 |
notxt = d->ui.fileNameEdit->text().isEmpty(); |
| 1725 |
} |
| 1726 |
else if (d->printer) |
| 1727 |
{ |
| 1728 |
QString pName = d->printer->printerName(); |
| 1729 |
notxt = pName.isEmpty(); |
| 1730 |
d->ui.printerLabel->setText(pName); |
| 1731 |
if (notxt) |
| 1732 |
d->ui.printerLabel->setText(tr("(invalid printer)")); |
| 1733 |
} |
| 1734 |
if (d->exporter) |
| 1735 |
{ |
| 1736 |
noexp = false; |
| 1737 |
if (d->exporter->status() >= DDJVU_JOB_STARTED) |
| 1738 |
nojob = false; |
| 1739 |
QWidget *w = 0; |
| 1740 |
for (int i=0; i<d->exporter->propertyPages(); i++) |
| 1741 |
if ((w = d->exporter->propertyPage(i))) |
| 1742 |
w->setEnabled(nojob); |
| 1743 |
} |
| 1744 |
d->ui.pageFile->setEnabled(tofile); |
| 1745 |
d->ui.pagePrinter->setEnabled(!tofile); |
| 1746 |
d->ui.destStackedWidget->setCurrentIndex(tofile ? 0 : 1); |
| 1747 |
d->ui.destinationGroupBox->setEnabled(nojob && !noexp); |
| 1748 |
d->ui.printGroupBox->setEnabled(nojob && !nodoc && !noexp); |
| 1749 |
d->ui.resetButton->setEnabled(!noexp && nojob && !nodoc); |
| 1750 |
d->ui.okButton->setEnabled(nojob && !nodoc && !notxt && !noexp); |
| 1751 |
d->ui.cancelButton->setEnabled(nojob); |
| 1752 |
d->ui.stopButton->setEnabled(!nojob); |
| 1753 |
d->ui.stackedWidget->setCurrentIndex(nojob ? 0 : 1); |
| 1754 |
} |
| 1755 |
|
| 1756 |
|
| 1757 |
void |
| 1758 |
QDjViewPrintDialog::browse() |
| 1759 |
{ |
| 1760 |
QString fname = d->ui.fileNameEdit->text(); |
| 1761 |
QDjViewExporter *exporter = d->exporter; |
| 1762 |
QString format = (exporter) ? exporter->name() : QString(); |
| 1763 |
QStringList info = QDjViewExporter::info(format); |
| 1764 |
QString filters = tr("All files", "save filter") + " (*)"; |
| 1765 |
QString suffix; |
| 1766 |
if (info.size() > 3) |
| 1767 |
filters = info[3] + ";;" + filters; |
| 1768 |
if (info.size() > 1) |
| 1769 |
suffix = info[1]; |
| 1770 |
fname = QFileDialog::getSaveFileName(this, |
| 1771 |
tr("Print To File - DjView", |
| 1772 |
"dialog caption"), |
| 1773 |
fname, filters); |
| 1774 |
if (! fname.isEmpty()) |
| 1775 |
{ |
| 1776 |
QFileInfo finfo(fname); |
| 1777 |
if (finfo.suffix().isEmpty() && !suffix.isEmpty()) |
| 1778 |
fname = QFileInfo(finfo.dir(), finfo.completeBaseName() |
| 1779 |
+ "." + suffix).filePath(); |
| 1780 |
d->ui.fileNameEdit->setText(fname); |
| 1781 |
} |
| 1782 |
} |
| 1783 |
|
| 1784 |
|
| 1785 |
void |
| 1786 |
QDjViewPrintDialog::choose() |
| 1787 |
{ |
| 1788 |
if (d->exporter) |
| 1789 |
{ |
| 1790 |
d->exporter->savePrintSetup(d->printer); |
| 1791 |
QPrintDialog *dialog = new QPrintDialog(d->printer, this); |
| 1792 |
// options |
| 1793 |
#if QT_VERSION >= 0x60000 |
| 1794 |
QPrintDialog::PrintDialogOptions options = dialog->options(); |
| 1795 |
#else |
| 1796 |
QPrintDialog::PrintDialogOptions options = dialog->enabledOptions(); |
| 1797 |
#endif |
| 1798 |
options |= QPrintDialog::PrintCollateCopies; |
| 1799 |
options &= ~QPrintDialog::PrintToFile; |
| 1800 |
options &= ~QPrintDialog::PrintSelection; |
| 1801 |
#if QT_VERSION >= 0x60000 |
| 1802 |
dialog->setOptions(options); |
| 1803 |
#else |
| 1804 |
dialog->setEnabledOptions(options); |
| 1805 |
#endif |
| 1806 |
// copy page spec |
| 1807 |
int pagenum = d->djview->pageNum(); |
| 1808 |
int curpage = d->djview->getDjVuWidget()->page(); |
| 1809 |
int frompage = d->ui.fromPageCombo->currentIndex(); |
| 1810 |
int topage = d->ui.toPageCombo->currentIndex(); |
| 1811 |
dialog->setMinMax(1, pagenum); |
| 1812 |
dialog->setFromTo(1, pagenum); |
| 1813 |
dialog->setPrintRange(QPrintDialog::PageRange); |
| 1814 |
if (d->ui.currentPageButton->isChecked()) |
| 1815 |
dialog->setFromTo(curpage+1, curpage+1); |
| 1816 |
else if (d->ui.pageRangeButton->isChecked()) |
| 1817 |
dialog->setFromTo(frompage+1, topage+1); |
| 1818 |
else |
| 1819 |
dialog->setPrintRange(QPrintDialog::AllPages); |
| 1820 |
// exec |
| 1821 |
if (dialog->exec() == QDialog::Accepted) |
| 1822 |
{ |
| 1823 |
d->exporter->loadPrintSetup(d->printer, dialog); |
| 1824 |
// copy page spec back |
| 1825 |
frompage = qBound(0, dialog->fromPage()-1, pagenum-1); |
| 1826 |
topage = qBound(0, dialog->toPage()-1, pagenum-1); |
| 1827 |
if (dialog->printRange() == QPrintDialog::AllPages) |
| 1828 |
{ |
| 1829 |
d->ui.documentButton->setChecked(true); |
| 1830 |
d->ui.fromPageCombo->setCurrentIndex(0); |
| 1831 |
d->ui.toPageCombo->setCurrentIndex(pagenum-1); |
| 1832 |
} |
| 1833 |
else |
| 1834 |
{ |
| 1835 |
d->ui.fromPageCombo->setCurrentIndex(frompage); |
| 1836 |
d->ui.toPageCombo->setCurrentIndex(topage); |
| 1837 |
if (frompage == curpage && topage == curpage) |
| 1838 |
d->ui.currentPageButton->setChecked(true); |
| 1839 |
else |
| 1840 |
d->ui.pageRangeButton->setChecked(true); |
| 1841 |
} |
| 1842 |
} |
| 1843 |
delete dialog; |
| 1844 |
} |
| 1845 |
refresh(); |
| 1846 |
} |
| 1847 |
|
| 1848 |
|
| 1849 |
void |
| 1850 |
QDjViewPrintDialog::clear() |
| 1851 |
{ |
| 1852 |
d->stopping = true; |
| 1853 |
reject(); |
| 1854 |
} |
| 1855 |
|
| 1856 |
|
| 1857 |
void |
| 1858 |
QDjViewPrintDialog::reset() |
| 1859 |
{ |
| 1860 |
QDjViewExporter *exporter = d->exporter; |
| 1861 |
if (exporter) |
| 1862 |
exporter->resetProperties(); |
| 1863 |
refresh(); |
| 1864 |
} |
| 1865 |
|
| 1866 |
|
| 1867 |
void |
| 1868 |
QDjViewPrintDialog::start() |
| 1869 |
{ |
| 1870 |
// start conversion |
| 1871 |
QDjViewExporter *exporter = d->exporter; |
| 1872 |
if (exporter) |
| 1873 |
{ |
| 1874 |
int lastPage = d->djview->pageNum()-1; |
| 1875 |
int curPage = d->djview->getDjVuWidget()->page(); |
| 1876 |
int fromPage = d->ui.fromPageCombo->currentIndex(); |
| 1877 |
int toPage = d->ui.toPageCombo->currentIndex(); |
| 1878 |
if (d->ui.currentPageButton->isChecked()) |
| 1879 |
exporter->setFromTo(curPage, curPage); |
| 1880 |
else if (d->ui.pageRangeButton->isChecked()) |
| 1881 |
exporter->setFromTo(fromPage, toPage); |
| 1882 |
else |
| 1883 |
exporter->setFromTo(0, lastPage); |
| 1884 |
// ignition! |
| 1885 |
if (d->ui.printToFileCheckBox->isChecked()) |
| 1886 |
{ |
| 1887 |
QString fname = d->ui.fileNameEdit->text(); |
| 1888 |
QFileInfo info(fname); |
| 1889 |
if (info.exists() && |
| 1890 |
QMessageBox::question(this, |
| 1891 |
tr("Question - DjView", "dialog caption"), |
| 1892 |
tr("A file with this name already exists.\n" |
| 1893 |
"Do you want to replace it?"), |
| 1894 |
tr("&Replace"), |
| 1895 |
tr("&Cancel") )) |
| 1896 |
return; |
| 1897 |
// save preferences |
| 1898 |
QDjViewPrefs *prefs = QDjViewPrefs::instance(); |
| 1899 |
prefs->printerName = QString(); |
| 1900 |
prefs->printFile = fname; |
| 1901 |
// print to file |
| 1902 |
exporter->save(fname); |
| 1903 |
} |
| 1904 |
else |
| 1905 |
{ |
| 1906 |
QPrinter *printer = d->printer; |
| 1907 |
// save preferences |
| 1908 |
QDjViewPrefs *prefs = QDjViewPrefs::instance(); |
| 1909 |
prefs->printFile = QString(); |
| 1910 |
prefs->printerName = printer->printerName(); |
| 1911 |
// print |
| 1912 |
exporter->print(d->printer); |
| 1913 |
} |
| 1914 |
} |
| 1915 |
// refresh ui |
| 1916 |
refresh(); |
| 1917 |
} |
| 1918 |
|
| 1919 |
|
| 1920 |
void |
| 1921 |
QDjViewPrintDialog::progress(int percent) |
| 1922 |
{ |
| 1923 |
ddjvu_status_t jobstatus = DDJVU_JOB_NOTSTARTED; |
| 1924 |
QDjViewExporter *exporter = d->exporter; |
| 1925 |
if (exporter) |
| 1926 |
jobstatus = exporter->status(); |
| 1927 |
d->ui.progressBar->setValue(percent); |
| 1928 |
switch(jobstatus) |
| 1929 |
{ |
| 1930 |
case DDJVU_JOB_OK: |
| 1931 |
QTimer::singleShot(0, this, SLOT(accept())); |
| 1932 |
break; |
| 1933 |
case DDJVU_JOB_FAILED: |
| 1934 |
exporter->error(tr("This operation has failed."), |
| 1935 |
__FILE__, __LINE__); |
| 1936 |
break; |
| 1937 |
case DDJVU_JOB_STOPPED: |
| 1938 |
exporter->error(tr("This operation has been interrupted."), |
| 1939 |
__FILE__, __LINE__); |
| 1940 |
break; |
| 1941 |
default: |
| 1942 |
break; |
| 1943 |
} |
| 1944 |
} |
| 1945 |
|
| 1946 |
|
| 1947 |
void |
| 1948 |
QDjViewPrintDialog::stop() |
| 1949 |
{ |
| 1950 |
QDjViewExporter *exporter = d->exporter; |
| 1951 |
if (exporter && exporter->status() == DDJVU_JOB_STARTED) |
| 1952 |
{ |
| 1953 |
exporter->stop(); |
| 1954 |
d->ui.stopButton->setEnabled(false); |
| 1955 |
d->stopping = true; |
| 1956 |
} |
| 1957 |
} |
| 1958 |
|
| 1959 |
|
| 1960 |
void |
| 1961 |
QDjViewPrintDialog::done(int reason) |
| 1962 |
{ |
| 1963 |
setEnabled(false); |
| 1964 |
QDjViewExporter *exporter = d->exporter; |
| 1965 |
if (!d->stopping && exporter && exporter->status()==DDJVU_JOB_STARTED ) |
| 1966 |
{ |
| 1967 |
stop(); |
| 1968 |
return; |
| 1969 |
} |
| 1970 |
if (exporter) |
| 1971 |
exporter->saveProperties("Printer-" + exporter->name()); |
| 1972 |
delete exporter; |
| 1973 |
d->exporter = 0; |
| 1974 |
QDialog::done(reason); |
| 1975 |
} |
| 1976 |
|
| 1977 |
|
| 1978 |
void |
| 1979 |
QDjViewPrintDialog::closeEvent(QCloseEvent *event) |
| 1980 |
{ |
| 1981 |
QDjViewExporter *exporter = d->exporter; |
| 1982 |
if (!d->stopping && exporter && exporter->status() == DDJVU_JOB_STARTED) |
| 1983 |
{ |
| 1984 |
stop(); |
| 1985 |
event->ignore(); |
| 1986 |
return; |
| 1987 |
} |
| 1988 |
if (exporter) |
| 1989 |
exporter->saveProperties("Printer-" + exporter->name()); |
| 1990 |
delete exporter; |
| 1991 |
d->exporter = 0; |
| 1992 |
event->accept(); |
| 1993 |
QDialog::closeEvent(event); |
| 1994 |
} |
| 1995 |
|
| 1996 |
|
| 1997 |
|
| 1998 |
|
| 1999 |
|
| 2000 |
|
| 2001 |
/* ------------------------------------------------------------- |
| 2002 |
Local Variables: |
| 2003 |
c++-font-lock-extra-types: ( "\\sw+_t" "[A-Z]\\sw*[a-z]\\sw*" ) |
| 2004 |
End: |
| 2005 |
------------------------------------------------------------- */ |
| 2006 |
|
| 2007 |
|