Changeset View
Changeset View
Standalone View
Standalone View
plugins/ocr/abstractocrengine.cpp
Show First 20 Lines • Show All 244 Lines • ▼ Show 20 Line(s) | 241 | { | |||
---|---|---|---|---|---|
245 | QUrl u = QUrl::fromLocalFile(file); | 245 | QUrl u = QUrl::fromLocalFile(file); | ||
246 | s += xi18nc("@info", "<filename><link url=\"%1\">%2</link></filename><nl/>", u.url(), file); | 246 | s += xi18nc("@info", "<filename><link url=\"%1\">%2</link></filename><nl/>", u.url(), file); | ||
247 | } | 247 | } | ||
248 | 248 | | |||
249 | if (KMessageBox::questionYesNo(m_parent, s, | 249 | if (KMessageBox::questionYesNo(m_parent, s, | ||
250 | i18n("OCR Temporary Files"), | 250 | i18n("OCR Temporary Files"), | ||
251 | KStandardGuiItem::del(), | 251 | KStandardGuiItem::del(), | ||
252 | KStandardGuiItem::close(), | 252 | KStandardGuiItem::close(), | ||
253 | QString::null, | 253 | QString(), | ||
254 | KMessageBox::AllowLink)==KMessageBox::Yes) retain = false; | 254 | KMessageBox::AllowLink)==KMessageBox::Yes) retain = false; | ||
255 | } | 255 | } | ||
256 | 256 | | |||
257 | if (!retain) { | 257 | if (!retain) { | ||
258 | for (QStringList::const_iterator it = temps.constBegin(); it != temps.constEnd(); ++it) { | 258 | for (QStringList::const_iterator it = temps.constBegin(); it != temps.constEnd(); ++it) { | ||
259 | if ((*it).isEmpty()) { | 259 | if ((*it).isEmpty()) { | ||
260 | continue; | 260 | continue; | ||
261 | } | 261 | } | ||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Line(s) | 405 | { | |||
406 | const QString protoName = QDir::tempPath()+'/'+baseName+"_XXXXXX."+suffix; | 406 | const QString protoName = QDir::tempPath()+'/'+baseName+"_XXXXXX."+suffix; | ||
407 | QTemporaryFile tmpFile(protoName); | 407 | QTemporaryFile tmpFile(protoName); | ||
408 | tmpFile.setAutoRemove(false); | 408 | tmpFile.setAutoRemove(false); | ||
409 | 409 | | |||
410 | if (!tmpFile.open()) | 410 | if (!tmpFile.open()) | ||
411 | { | 411 | { | ||
412 | qDebug() << "error creating temporary file" << protoName; | 412 | qDebug() << "error creating temporary file" << protoName; | ||
413 | setErrorText(xi18nc("@info", "Cannot create temporary file <filename>%1</filename>", protoName)); | 413 | setErrorText(xi18nc("@info", "Cannot create temporary file <filename>%1</filename>", protoName)); | ||
414 | return (QString::null); | 414 | return (QString()); | ||
415 | } | 415 | } | ||
416 | 416 | | |||
417 | QString tmpName = QFile::encodeName(tmpFile.fileName()); | 417 | QString tmpName = QFile::encodeName(tmpFile.fileName()); | ||
418 | tmpFile.close(); // just want its name | 418 | tmpFile.close(); // just want its name | ||
419 | return (tmpName); | 419 | return (tmpName); | ||
420 | } | 420 | } | ||
421 | 421 | | |||
422 | 422 | | |||
423 | QString AbstractOcrEngine::tempSaveImage(const KookaImage *img, const ImageFormat &format, int colors) | 423 | QString AbstractOcrEngine::tempSaveImage(const KookaImage *img, const ImageFormat &format, int colors) | ||
424 | { | 424 | { | ||
425 | if (img==nullptr) return (QString::null); // no image to save | 425 | if (img==nullptr) return (QString()); // no image to save | ||
426 | 426 | | |||
427 | QString tmpName = tempFileName(format.extension(), "imagetemp"); | 427 | QString tmpName = tempFileName(format.extension(), "imagetemp"); | ||
428 | const KookaImage *tmpImg = nullptr; | 428 | const KookaImage *tmpImg = nullptr; | ||
429 | 429 | | |||
430 | if (colors!=-1 && img->depth()!=colors) // need to convert image | 430 | if (colors!=-1 && img->depth()!=colors) // need to convert image | ||
431 | { | 431 | { | ||
432 | QImage::Format newfmt; | 432 | QImage::Format newfmt; | ||
433 | switch (colors) | 433 | switch (colors) | ||
434 | { | 434 | { | ||
435 | case 1: newfmt = QImage::Format_Mono; | 435 | case 1: newfmt = QImage::Format_Mono; | ||
436 | break; | 436 | break; | ||
437 | 437 | | |||
438 | case 8: newfmt = QImage::Format_Indexed8; | 438 | case 8: newfmt = QImage::Format_Indexed8; | ||
439 | break; | 439 | break; | ||
440 | 440 | | |||
441 | case 24: newfmt = QImage::Format_RGB888; | 441 | case 24: newfmt = QImage::Format_RGB888; | ||
442 | break; | 442 | break; | ||
443 | 443 | | |||
444 | case 32: newfmt = QImage::Format_RGB32; | 444 | case 32: newfmt = QImage::Format_RGB32; | ||
445 | break; | 445 | break; | ||
446 | 446 | | |||
447 | default: qWarning() << "bad colour depth" << colors; | 447 | default: qWarning() << "bad colour depth" << colors; | ||
448 | return (QString::null); | 448 | return (QString()); | ||
449 | } | 449 | } | ||
450 | 450 | | |||
451 | tmpImg = new KookaImage(img->convertToFormat(newfmt)); | 451 | tmpImg = new KookaImage(img->convertToFormat(newfmt)); | ||
452 | img = tmpImg; // replace with converted image | 452 | img = tmpImg; // replace with converted image | ||
453 | } | 453 | } | ||
454 | 454 | | |||
455 | qDebug() << "saving to" << tmpName << "in format" << format; | 455 | qDebug() << "saving to" << tmpName << "in format" << format; | ||
456 | if (!img->save(tmpName, format.name())) | 456 | if (!img->save(tmpName, format.name())) | ||
▲ Show 20 Lines • Show All 140 Lines • Show Last 20 Lines |