Changeset View
Standalone View
part.cpp
Show First 20 Lines • Show All 298 Lines • ▼ Show 20 Line(s) | |||||
299 | namespace Okular | 299 | namespace Okular | ||
300 | { | 300 | { | ||
301 | 301 | | |||
302 | Part::Part(QWidget *parentWidget, | 302 | Part::Part(QWidget *parentWidget, | ||
303 | QObject *parent, | 303 | QObject *parent, | ||
304 | const QVariantList &args) | 304 | const QVariantList &args) | ||
305 | : KParts::ReadWritePart(parent), | 305 | : KParts::ReadWritePart(parent), | ||
306 | m_tempfile( nullptr ), m_documentOpenWithPassword( false ), m_swapInsteadOfOpening( false ), m_isReloading( false ), m_fileWasRemoved( false ), m_showMenuBarAction( nullptr ), m_showFullScreenAction( nullptr ), m_actionsSearched( false ), | 306 | m_tempfile( nullptr ), m_documentOpenWithPassword( false ), m_swapInsteadOfOpening( false ), m_isReloading( false ), m_fileWasRemoved( false ), m_showMenuBarAction( nullptr ), m_showFullScreenAction( nullptr ), m_actionsSearched( false ), | ||
307 | m_cliPresentation(false), m_cliPrint(false), m_embedMode(detectEmbedMode(parentWidget, parent, args)), m_generatorGuiClient(nullptr), m_keeper( nullptr ) | 307 | m_cliPresentation(false), m_cliPrint(false), m_cliPrintAndExit(false), m_embedMode(detectEmbedMode(parentWidget, parent, args)), m_generatorGuiClient(nullptr), m_keeper( nullptr ) | ||
308 | { | 308 | { | ||
309 | // make sure that the component name is okular otherwise the XMLGUI .rc files are not found | 309 | // make sure that the component name is okular otherwise the XMLGUI .rc files are not found | ||
310 | // when this part is used in an application other than okular (e.g. unit tests) | 310 | // when this part is used in an application other than okular (e.g. unit tests) | ||
311 | setComponentName(QStringLiteral("okular"), QString()); | 311 | setComponentName(QStringLiteral("okular"), QString()); | ||
312 | 312 | | |||
313 | const QLatin1String configFileName("okularpartrc"); | 313 | const QLatin1String configFileName("okularpartrc"); | ||
314 | 314 | | |||
315 | // first, we check if a config file name has been specified | 315 | // first, we check if a config file name has been specified | ||
▲ Show 20 Lines • Show All 1324 Lines • ▼ Show 20 Line(s) | 1595 | #endif | |||
1640 | m_generatorGuiClient = factory() ? m_document->guiClient() : nullptr; | 1640 | m_generatorGuiClient = factory() ? m_document->guiClient() : nullptr; | ||
1641 | if ( m_generatorGuiClient ) | 1641 | if ( m_generatorGuiClient ) | ||
1642 | factory()->addClient( m_generatorGuiClient ); | 1642 | factory()->addClient( m_generatorGuiClient ); | ||
1643 | if ( m_cliPrint ) | 1643 | if ( m_cliPrint ) | ||
1644 | { | 1644 | { | ||
1645 | m_cliPrint = false; | 1645 | m_cliPrint = false; | ||
1646 | slotPrint(); | 1646 | slotPrint(); | ||
1647 | } | 1647 | } | ||
1648 | else if ( m_cliPrintAndExit ) | ||||
1649 | { | ||||
1650 | slotPrint(); | ||||
1651 | } | ||||
1648 | return true; | 1652 | return true; | ||
1649 | } | 1653 | } | ||
1650 | 1654 | | |||
1651 | bool Part::openUrl( const QUrl &url ) | 1655 | bool Part::openUrl( const QUrl &url ) | ||
1652 | { | 1656 | { | ||
1653 | return openUrl( url, false /* swapInsteadOfOpening */ ); | 1657 | return openUrl( url, false /* swapInsteadOfOpening */ ); | ||
1654 | } | 1658 | } | ||
1655 | 1659 | | |||
▲ Show 20 Lines • Show All 1407 Lines • ▼ Show 20 Line(s) | 3063 | { | |||
3063 | } | 3067 | } | ||
3064 | } | 3068 | } | ||
3065 | 3069 | | |||
3066 | void Part::enableStartWithPrint() | 3070 | void Part::enableStartWithPrint() | ||
3067 | { | 3071 | { | ||
3068 | m_cliPrint = true; | 3072 | m_cliPrint = true; | ||
3069 | } | 3073 | } | ||
3070 | 3074 | | |||
3075 | void Part::enableExitAfterPrint() | ||||
3076 | { | ||||
3077 | m_cliPrintAndExit = true; | ||||
3078 | } | ||||
3079 | | ||||
3071 | void Part::slotAboutBackend() | 3080 | void Part::slotAboutBackend() | ||
3072 | { | 3081 | { | ||
3073 | const KPluginMetaData data = m_document->generatorInfo(); | 3082 | const KPluginMetaData data = m_document->generatorInfo(); | ||
3074 | if (!data.isValid()) | 3083 | if (!data.isValid()) | ||
3075 | return; | 3084 | return; | ||
3076 | 3085 | | |||
3077 | KAboutData aboutData = KAboutData::fromPluginMetaData(data); | 3086 | KAboutData aboutData = KAboutData::fromPluginMetaData(data); | ||
3078 | 3087 | | |||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Line(s) | 3193 | { | |||
3201 | } | 3210 | } | ||
3202 | 3211 | | |||
3203 | // Enable the Current Page option in the dialog. | 3212 | // Enable the Current Page option in the dialog. | ||
3204 | if ( m_document->pages() > 1 && currentPage() > 0 ) | 3213 | if ( m_document->pages() > 1 && currentPage() > 0 ) | ||
3205 | { | 3214 | { | ||
3206 | printDialog->setOption( QAbstractPrintDialog::PrintCurrentPage ); | 3215 | printDialog->setOption( QAbstractPrintDialog::PrintCurrentPage ); | ||
3207 | } | 3216 | } | ||
3208 | 3217 | | |||
3218 | bool success = true; | ||||
aacid: What is the value of isError when
if ( printDialog->exec() )
returns false? | |||||
Undefined behavior - isError can either be true or false, my bad. Submitting a new patch. dileepsankhla: Undefined behavior - isError can either be true or false, my bad. Submitting a new patch. | |||||
3209 | if ( printDialog->exec() ) | 3219 | if ( printDialog->exec() ) | ||
3210 | doPrint( printer ); | 3220 | success = doPrint( printer ); | ||
3211 | delete printDialog; | 3221 | delete printDialog; | ||
3222 | if ( m_cliPrintAndExit ) | ||||
3223 | exit ( success ? EXIT_SUCCESS : EXIT_FAILURE ); | ||||
We discussed a bit on IRC but i don't remeber which your reason for not using QCoreApplication::exit were, can you please remind me? aacid: We discussed a bit on IRC but i don't remeber which your reason for not using QCoreApplication… | |||||
I have talked about using std::exit instead of QCoreApplication::exit here : https://phabricator.kde.org/D10249#200260 With that, I want to add that QCoreApplication::exit does nothing if the event loop is not running. You can find the info in the docs here: http://doc.qt.io/qt-5/qcoreapplication.html#exit dileepsankhla: I have talked about using std::exit instead of QCoreApplication::exit here : https… | |||||
3212 | } | 3224 | } | ||
3213 | } | 3225 | } | ||
3214 | 3226 | | |||
aacid: You have far too many exit calls, i'm 99% sure you could have just one. | |||||
Agree that only one exit call is required but what about the exit status - EXIT_SUCCESS or EXIT_FAILURE? The issue description talked about the command line batch processing. For that purpose, should I set a bool "isError" when failing condition is encountered like "printing is not allowed" and then based on the isError's status, should I call either exit (EXIT_SUCCESS) or exit (EXIT_FAILURE)? dileepsankhla: Agree that only one exit call is required but what about the exit status - EXIT_SUCCESS or… | |||||
3215 | 3227 | | |||
3216 | void Part::setupPrint( QPrinter &printer ) | 3228 | void Part::setupPrint( QPrinter &printer ) | ||
3217 | { | 3229 | { | ||
3218 | printer.setOrientation(m_document->orientation()); | 3230 | printer.setOrientation(m_document->orientation()); | ||
3219 | 3231 | | |||
3220 | // title | 3232 | // title | ||
3221 | QString title = m_document->metaData( QStringLiteral("DocumentTitle") ).toString(); | 3233 | QString title = m_document->metaData( QStringLiteral("DocumentTitle") ).toString(); | ||
3222 | if ( title.isEmpty() ) | 3234 | if ( title.isEmpty() ) | ||
3223 | { | 3235 | { | ||
3224 | title = m_document->currentDocument().fileName(); | 3236 | title = m_document->currentDocument().fileName(); | ||
3225 | } | 3237 | } | ||
3226 | if ( !title.isEmpty() ) | 3238 | if ( !title.isEmpty() ) | ||
3227 | { | 3239 | { | ||
3228 | printer.setDocName( title ); | 3240 | printer.setDocName( title ); | ||
3229 | } | 3241 | } | ||
3230 | } | 3242 | } | ||
3231 | 3243 | | |||
3232 | 3244 | | |||
3233 | void Part::doPrint(QPrinter &printer) | 3245 | bool Part::doPrint(QPrinter &printer) | ||
Can you please make doPrint return true on success and not on error? It's a much saner API. aacid: Can you please make doPrint return true on success and not on error?
It's a much saner API. | |||||
3234 | { | 3246 | { | ||
3235 | if (!m_document->isAllowed(Okular::AllowPrint)) | 3247 | if (!m_document->isAllowed(Okular::AllowPrint)) | ||
3236 | { | 3248 | { | ||
3237 | KMessageBox::error(widget(), i18n("Printing this document is not allowed.")); | 3249 | KMessageBox::error(widget(), i18n("Printing this document is not allowed.")); | ||
3238 | return; | 3250 | return false; | ||
3239 | } | 3251 | } | ||
3240 | 3252 | | |||
3241 | if (!m_document->print(printer)) | 3253 | if (!m_document->print(printer)) | ||
3242 | { | 3254 | { | ||
3243 | const QString error = m_document->printError(); | 3255 | const QString error = m_document->printError(); | ||
3244 | if (error.isEmpty()) | 3256 | if (error.isEmpty()) | ||
3245 | { | 3257 | { | ||
3246 | KMessageBox::error(widget(), i18n("Could not print the document. Unknown error. Please report to bugs.kde.org")); | 3258 | KMessageBox::error(widget(), i18n("Could not print the document. Unknown error. Please report to bugs.kde.org")); | ||
3247 | } | 3259 | } | ||
3248 | else | 3260 | else | ||
3249 | { | 3261 | { | ||
3250 | KMessageBox::error(widget(), i18n("Could not print the document. Detailed error is \"%1\". Please report to bugs.kde.org", error)); | 3262 | KMessageBox::error(widget(), i18n("Could not print the document. Detailed error is \"%1\". Please report to bugs.kde.org", error)); | ||
3251 | } | 3263 | } | ||
3264 | return false; | ||||
3252 | } | 3265 | } | ||
3266 | return true; | ||||
3253 | } | 3267 | } | ||
3254 | 3268 | | |||
3255 | void Part::psTransformEnded(int exit, QProcess::ExitStatus status) | 3269 | void Part::psTransformEnded(int exit, QProcess::ExitStatus status) | ||
3256 | { | 3270 | { | ||
3257 | Q_UNUSED( exit ) | 3271 | Q_UNUSED( exit ) | ||
3258 | if ( status != QProcess::NormalExit ) | 3272 | if ( status != QProcess::NormalExit ) | ||
3259 | return; | 3273 | return; | ||
3260 | 3274 | | |||
▲ Show 20 Lines • Show All 231 Lines • ▼ Show 20 Line(s) | |||||
3492 | { | 3506 | { | ||
3493 | const KPluginMetaData data = m_document->generatorInfo(); | 3507 | const KPluginMetaData data = m_document->generatorInfo(); | ||
3494 | m_aboutBackend->setEnabled(data.isValid()); | 3508 | m_aboutBackend->setEnabled(data.isValid()); | ||
3495 | } | 3509 | } | ||
3496 | 3510 | | |||
3497 | void Part::resetStartArguments() | 3511 | void Part::resetStartArguments() | ||
3498 | { | 3512 | { | ||
3499 | m_cliPrint = false; | 3513 | m_cliPrint = false; | ||
3514 | m_cliPrintAndExit = false; | ||||
3500 | } | 3515 | } | ||
3501 | 3516 | | |||
3502 | #if PURPOSE_FOUND | 3517 | #if PURPOSE_FOUND | ||
3503 | void Part::slotShareActionFinished(const QJsonObject &output, int error, const QString &message) | 3518 | void Part::slotShareActionFinished(const QJsonObject &output, int error, const QString &message) | ||
3504 | { | 3519 | { | ||
3505 | if (error) { | 3520 | if (error) { | ||
3506 | KMessageBox::error(widget(), i18n("There was a problem sharing the document: %1", message), | 3521 | KMessageBox::error(widget(), i18n("There was a problem sharing the document: %1", message), | ||
3507 | i18n("Share")); | 3522 | i18n("Share")); | ||
Show All 24 Lines |
What is the value of isError when
returns false?