Changeset View
Changeset View
Standalone View
Standalone View
part.cpp
Show First 20 Lines • Show All 2530 Lines • ▼ Show 20 Line(s) | 2497 | { | |||
---|---|---|---|---|---|
2531 | if ( !tf.open() ) | 2531 | if ( !tf.open() ) | ||
2532 | { | 2532 | { | ||
2533 | KMessageBox::information( widget(), i18n("Could not open the temporary file for saving." ) ); | 2533 | KMessageBox::information( widget(), i18n("Could not open the temporary file for saving." ) ); | ||
2534 | return false; | 2534 | return false; | ||
2535 | } | 2535 | } | ||
2536 | fileName = tf.fileName(); | 2536 | fileName = tf.fileName(); | ||
2537 | tf.close(); | 2537 | tf.close(); | ||
2538 | 2538 | | |||
2539 | // Figure out the real save url, for symlinks we don't want to copy over the symlink but over the target file | ||||
2540 | const QUrl realSaveUrl = saveUrl.isLocalFile() ? QUrl::fromLocalFile( QFileInfo( saveUrl.toLocalFile() ).canonicalFilePath() ) | ||||
ngraham: Shouldn't `realSaveUrl.toLocalFile()` be `saveUrl.toLocalFile()`? | |||||
Yeah, that's what you get when you rewrite the match at last minute and don't test it again. aacid: Yeah, that's what you get when you rewrite the match at last minute and don't test it again. | |||||
2541 | : saveUrl; | ||||
2542 | | ||||
2539 | QScopedPointer<QTemporaryFile> tempFile; | 2543 | QScopedPointer<QTemporaryFile> tempFile; | ||
2540 | KIO::Job *copyJob = nullptr; // this will be filled with the job that writes to saveUrl | 2544 | KIO::Job *copyJob = nullptr; // this will be filled with the job that writes to saveUrl | ||
2541 | 2545 | | |||
2542 | // Does the user want a .okular archive? | 2546 | // Does the user want a .okular archive? | ||
2543 | if ( flags & SaveAsOkularArchive ) | 2547 | if ( flags & SaveAsOkularArchive ) | ||
2544 | { | 2548 | { | ||
2545 | if ( !hasUserAcceptedReload && !m_document->canSwapBackingFile() ) | 2549 | if ( !hasUserAcceptedReload && !m_document->canSwapBackingFile() ) | ||
2546 | { | 2550 | { | ||
Show All 12 Lines | |||||
2559 | } | 2563 | } | ||
2560 | 2564 | | |||
2561 | if ( !m_document->saveDocumentArchive( fileName ) ) | 2565 | if ( !m_document->saveDocumentArchive( fileName ) ) | ||
2562 | { | 2566 | { | ||
2563 | KMessageBox::information( widget(), i18n("File could not be saved in '%1'. Try to save it to another location.", fileName ) ); | 2567 | KMessageBox::information( widget(), i18n("File could not be saved in '%1'. Try to save it to another location.", fileName ) ); | ||
2564 | return false; | 2568 | return false; | ||
2565 | } | 2569 | } | ||
2566 | 2570 | | |||
2567 | copyJob = KIO::file_copy( QUrl::fromLocalFile( fileName ), saveUrl, -1, KIO::Overwrite ); | 2571 | copyJob = KIO::file_copy( QUrl::fromLocalFile( fileName ), realSaveUrl, -1, KIO::Overwrite ); | ||
2568 | } | 2572 | } | ||
2569 | else | 2573 | else | ||
2570 | { | 2574 | { | ||
2571 | bool wontSaveForms, wontSaveAnnotations; | 2575 | bool wontSaveForms, wontSaveAnnotations; | ||
2572 | checkNativeSaveDataLoss(&wontSaveForms, &wontSaveAnnotations); | 2576 | checkNativeSaveDataLoss(&wontSaveForms, &wontSaveAnnotations); | ||
2573 | 2577 | | |||
2574 | // If something can't be saved in this format, ask for confirmation | 2578 | // If something can't be saved in this format, ask for confirmation | ||
2575 | QStringList listOfwontSaves; | 2579 | QStringList listOfwontSaves; | ||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | 2636 | { | |||
2633 | if (errorText.isEmpty()) | 2637 | if (errorText.isEmpty()) | ||
2634 | KMessageBox::information( widget(), i18n("File could not be saved in '%1'. Try to save it to another location.", fileName ) ); | 2638 | KMessageBox::information( widget(), i18n("File could not be saved in '%1'. Try to save it to another location.", fileName ) ); | ||
2635 | else | 2639 | else | ||
2636 | KMessageBox::information( widget(), i18n("File could not be saved in '%1'. %2", fileName, errorText ) ); | 2640 | KMessageBox::information( widget(), i18n("File could not be saved in '%1'. %2", fileName, errorText ) ); | ||
2637 | 2641 | | |||
2638 | return false; | 2642 | return false; | ||
2639 | } | 2643 | } | ||
2640 | 2644 | | |||
2641 | copyJob = KIO::file_copy( QUrl::fromLocalFile( fileName ), saveUrl, -1, KIO::Overwrite ); | 2645 | copyJob = KIO::file_copy( QUrl::fromLocalFile( fileName ), realSaveUrl, -1, KIO::Overwrite ); | ||
2642 | } | 2646 | } | ||
2643 | else | 2647 | else | ||
2644 | { | 2648 | { | ||
2645 | // If the generators doesn't support saving changes, we will | 2649 | // If the generators doesn't support saving changes, we will | ||
2646 | // just copy the original file. | 2650 | // just copy the original file. | ||
2647 | 2651 | | |||
2648 | if ( isDocumentArchive ) | 2652 | if ( isDocumentArchive ) | ||
2649 | { | 2653 | { | ||
2650 | // Special case: if the user is extracting the contents of a | 2654 | // Special case: if the user is extracting the contents of a | ||
2651 | // .okular archive back to the native format, we can't just copy | 2655 | // .okular archive back to the native format, we can't just copy | ||
2652 | // the open file (which is a .okular). So let's ask to core to | 2656 | // the open file (which is a .okular). So let's ask to core to | ||
2653 | // extract and give us the real file | 2657 | // extract and give us the real file | ||
2654 | 2658 | | |||
2655 | if ( !m_document->extractArchivedFile( fileName ) ) | 2659 | if ( !m_document->extractArchivedFile( fileName ) ) | ||
2656 | { | 2660 | { | ||
2657 | KMessageBox::information( widget(), i18n("File could not be saved in '%1'. Try to save it to another location.", fileName ) ); | 2661 | KMessageBox::information( widget(), i18n("File could not be saved in '%1'. Try to save it to another location.", fileName ) ); | ||
2658 | return false; | 2662 | return false; | ||
2659 | } | 2663 | } | ||
2660 | 2664 | | |||
2661 | copyJob = KIO::file_copy( QUrl::fromLocalFile( fileName ), saveUrl, -1, KIO::Overwrite ); | 2665 | copyJob = KIO::file_copy( QUrl::fromLocalFile( fileName ), realSaveUrl, -1, KIO::Overwrite ); | ||
2662 | } | 2666 | } | ||
2663 | else | 2667 | else | ||
2664 | { | 2668 | { | ||
2665 | // Otherwise just copy the open file. | 2669 | // Otherwise just copy the open file. | ||
2666 | // make use of the already downloaded (in case of remote URLs) file, | 2670 | // make use of the already downloaded (in case of remote URLs) file, | ||
2667 | // no point in downloading that again | 2671 | // no point in downloading that again | ||
2668 | QUrl srcUrl = QUrl::fromLocalFile( localFilePath() ); | 2672 | QUrl srcUrl = QUrl::fromLocalFile( localFilePath() ); | ||
2669 | // duh, our local file disappeared... | 2673 | // duh, our local file disappeared... | ||
Show All 17 Lines | 2690 | { | |||
2687 | // we still have the original remote URL of the document, | 2691 | // we still have the original remote URL of the document, | ||
2688 | // so copy the document from there | 2692 | // so copy the document from there | ||
2689 | srcUrl = url(); | 2693 | srcUrl = url(); | ||
2690 | } | 2694 | } | ||
2691 | } | 2695 | } | ||
2692 | 2696 | | |||
2693 | if ( srcUrl != saveUrl ) | 2697 | if ( srcUrl != saveUrl ) | ||
2694 | { | 2698 | { | ||
2695 | copyJob = KIO::file_copy( srcUrl, saveUrl, -1, KIO::Overwrite ); | 2699 | copyJob = KIO::file_copy( srcUrl, realSaveUrl, -1, KIO::Overwrite ); | ||
2696 | } | 2700 | } | ||
2697 | else | 2701 | else | ||
2698 | { | 2702 | { | ||
2699 | // Don't do a real copy in this case, just update the timestamps | 2703 | // Don't do a real copy in this case, just update the timestamps | ||
2700 | copyJob = KIO::setModificationTime( saveUrl, QDateTime::currentDateTime() ); | 2704 | copyJob = KIO::setModificationTime( realSaveUrl, QDateTime::currentDateTime() ); | ||
2701 | } | 2705 | } | ||
2702 | } | 2706 | } | ||
2703 | } | 2707 | } | ||
2704 | } | 2708 | } | ||
2705 | 2709 | | |||
2706 | // Stop watching for changes while we write the new file (useful when | 2710 | // Stop watching for changes while we write the new file (useful when | ||
2707 | // overwriting) | 2711 | // overwriting) | ||
2708 | if ( url().isLocalFile() ) | 2712 | if ( url().isLocalFile() ) | ||
▲ Show 20 Lines • Show All 869 Lines • Show Last 20 Lines |
Shouldn't realSaveUrl.toLocalFile() be saveUrl.toLocalFile()?