diff --git a/core/action.cpp b/core/action.cpp index 7c7b09c3e..b89ab14ff 100644 --- a/core/action.cpp +++ b/core/action.cpp @@ -182,15 +182,15 @@ QString ExecuteAction::parameters() const class Okular::BrowseActionPrivate : public Okular::ActionPrivate { public: - BrowseActionPrivate( const QString &url ) + BrowseActionPrivate( const QUrl &url ) : ActionPrivate(), m_url( url ) { } - QString m_url; + QUrl m_url; }; -BrowseAction::BrowseAction( const QString &url ) +BrowseAction::BrowseAction(const QUrl &url ) : Action( *new BrowseActionPrivate( url ) ) { } @@ -213,10 +213,10 @@ QString BrowseAction::actionTip() const { return sourceReferenceToolTip( source, row, col ); } - return d->m_url; + return d->m_url.toDisplayString(); } -QString BrowseAction::url() const +QUrl BrowseAction::url() const { Q_D( const Okular::BrowseAction ); return d->m_url; diff --git a/core/action.h b/core/action.h index 8a9c3c269..d21170179 100644 --- a/core/action.h +++ b/core/action.h @@ -231,7 +231,7 @@ class OKULAR_EXPORT BrowseAction : public Action * * @param url The url to browse. */ - BrowseAction( const QString &url ); + BrowseAction( const QUrl &url ); /** * Destroys the browse action. @@ -251,7 +251,7 @@ class OKULAR_EXPORT BrowseAction : public Action /** * Returns the url to browse. */ - QString url() const; + QUrl url() const; private: Q_DECLARE_PRIVATE( BrowseAction ) diff --git a/core/document.cpp b/core/document.cpp index 02de6aed9..053f87c91 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -2181,7 +2181,9 @@ Document::OpenResult Document::openDocument( const QString & docFile, const KUrl // There's still no offers, do a final mime search based on the filename // We need this because sometimes (e.g. when downloading from a webserver) the mimetype we // use is the one fed by the server, that may be wrong - newmime = KMimeType::findByUrl( docFile ); + +#pragma message("Fix generator loading") + // newmime = KMimeType::findByUrl( docFile ); if ( newmime->name() != mime->name() ) { mime = newmime; @@ -3628,14 +3630,16 @@ void Document::processAction( const Action * action ) fileName = d->giveAbsolutePath( fileName ); KMimeType::Ptr mime = KMimeType::findByPath( fileName ); // Check executables - if ( KRun::isExecutableFile( fileName, mime->name() ) ) +#pragma message("KF5 check if QUrl::fromUserInput is right here") + if ( KRun::isExecutableFile( QUrl::fromUserInput(fileName), mime->name() ) ) { // Don't have any pdf that uses this code path, just a guess on how it should work if ( !exe->parameters().isEmpty() ) { fileName = d->giveAbsolutePath( exe->parameters() ); mime = KMimeType::findByPath( fileName ); - if ( KRun::isExecutableFile( fileName, mime->name() ) ) + #pragma message("KF5 check QUrl usage") + if ( KRun::isExecutableFile( QUrl(fileName), mime->name() ) ) { // this case is a link pointing to an executable with a parameter // that also is an executable, possibly a hand-crafted pdf @@ -3713,7 +3717,7 @@ void Document::processAction( const Action * action ) QString lilySource; int lilyRow = 0, lilyCol = 0; // if the url is a mailto one, invoke mailer - if ( browse->url().startsWith( "mailto:", Qt::CaseInsensitive ) ) + if ( browse->url().scheme().compare("mailto") ) KToolInvocation::invokeMailer( browse->url() ); else if ( extractLilyPondSourceReference( browse->url(), &lilySource, &lilyRow, &lilyCol ) ) { @@ -3722,25 +3726,25 @@ void Document::processAction( const Action * action ) } else { - QString url = browse->url(); + QUrl url = browse->url(); +#pragma message("KF5 fix this mess - relative urls should probably be resolved earlier") // fix for #100366, documents with relative links that are the form of http:foo.pdf - if (url.indexOf("http:") == 0 && url.indexOf("http://") == -1 && url.right(4) == ".pdf") - { - d->openRelativeFile(url.mid(5)); - return; - } - - KUrl realUrl = KUrl( url ); - - // handle documents with relative path - if ( d->m_url.isValid() ) - { - realUrl = KUrl( d->m_url.upUrl(), url ); - } - - // Albert: this is not a leak! - new KRun( realUrl, d->m_widget ); +// if (url.indexOf("http:") == 0 && url.indexOf("http://") == -1 && url.right(4) == ".pdf") +// { +// d->openRelativeFile(url.mid(5)); +// return; +// } + +// FIXME +// // handle documents with relative path +// if ( d->m_url.isValid() ) +// { +// realUrl = KUrl( d->m_url.upUrl(), url ); +// } + +// // Albert: this is not a leak! +// new KRun( realUrl, d->m_widget ); } } break; diff --git a/core/sourcereference.cpp b/core/sourcereference.cpp index e34825aba..ab5a9dcf3 100644 --- a/core/sourcereference.cpp +++ b/core/sourcereference.cpp @@ -57,32 +57,35 @@ int SourceReference::column() const return d->column; } -bool Okular::extractLilyPondSourceReference( const QString &url, QString *file, int *row, int *col ) +bool Okular::extractLilyPondSourceReference( const QUrl &url, QString *file, int *row, int *col ) { - if ( !url.startsWith( QLatin1String( "textedit://" ) ) ) + if ( url.scheme() != QStringLiteral("textedit") ) return false; - *row = 0; - *col = 0; - int lilyChar = 0; - typedef int *IntPtr; - const IntPtr int_data[] = { row, &lilyChar, col }; - int int_index = sizeof( int_data ) / sizeof( int* ) - 1; - int index_last = -1; - int index = url.lastIndexOf( QLatin1Char( ':' ), index_last ); - while ( index != -1 && int_index >= 0 ) - { - // read the current "chunk" - const QStringRef ref = url.midRef( index + 1, index_last - index - 1 ); - *int_data[ int_index ] = QString::fromRawData( ref.data(), ref.count() ).toInt(); - // find the previous "chunk" - index_last = index; - index = url.lastIndexOf( QLatin1Char( ':' ), index_last - 1 ); - --int_index; - } - // NOTE: 11 is the length of "textedit://" - *file = QUrl::fromPercentEncoding( url.mid( 11, index_last != -1 ? index_last - 11 : -1 ).toUtf8() ); - return true; +#pragma message("KF5 fix LilyPond references") + return false; + +// *row = 0; +// *col = 0; +// int lilyChar = 0; +// typedef int *IntPtr; +// const IntPtr int_data[] = { row, &lilyChar, col }; +// int int_index = sizeof( int_data ) / sizeof( int* ) - 1; +// int index_last = -1; +// int index = url.lastIndexOf( QLatin1Char( ':' ), index_last ); +// while ( index != -1 && int_index >= 0 ) +// { +// // read the current "chunk" +// const QStringRef ref = url.midRef( index + 1, index_last - index - 1 ); +// *int_data[ int_index ] = QString::fromRawData( ref.data(), ref.count() ).toInt(); +// // find the previous "chunk" +// index_last = index; +// index = url.lastIndexOf( QLatin1Char( ':' ), index_last - 1 ); +// --int_index; +// } +// // NOTE: 11 is the length of "textedit://" +// *file = QUrl::fromPercentEncoding( url.mid( 11, index_last != -1 ? index_last - 11 : -1 ).toUtf8() ); +// return true; } QString Okular::sourceReferenceToolTip( const QString &source, int row, int col ) diff --git a/core/sourcereference_p.h b/core/sourcereference_p.h index cf7b3e826..bace61431 100644 --- a/core/sourcereference_p.h +++ b/core/sourcereference_p.h @@ -11,11 +11,12 @@ #define OKULAR_SOURCEREFERENCE_P_H class QString; +class QUrl; namespace Okular { -bool extractLilyPondSourceReference( const QString &url, QString *file, int *row, int *col ); +bool extractLilyPondSourceReference(const QUrl &url, QString *file, int *row, int *col ); QString sourceReferenceToolTip( const QString &source, int row, int col ); } diff --git a/part.cpp b/part.cpp index b4836e262..3ce96d4b2 100644 --- a/part.cpp +++ b/part.cpp @@ -115,7 +115,7 @@ class FileKeeper void open( const QString & path ) { if ( !m_handle ) - m_handle = std::fopen( QFile::encodeName( path ), "r" ); + m_handle = std::fopen( QFile::encodeName( path ).constData(), "r" ); } void close() @@ -361,7 +361,7 @@ m_cliPresentation(false), m_cliPrint(false), m_embedMode(detectEmbedMode(parentW connect( m_document->bookmarkManager(), SIGNAL(openUrl(KUrl)), this, SLOT(openUrlFromBookmarks(KUrl)) ); connect( m_document, SIGNAL(close()), this, SLOT(close()) ); - if ( parent && parent->metaObject()->indexOfSlot( QMetaObject::normalizedSignature( "slotQuit()" ) ) != -1 ) + if ( parent && parent->metaObject()->indexOfSlot( QMetaObject::normalizedSignature( "slotQuit()" ).constData() ) != -1 ) connect( m_document, SIGNAL(quit()), parent, SLOT(slotQuit()) ); else connect( m_document, SIGNAL(quit()), this, SLOT(cannotQuit()) ); @@ -1454,7 +1454,7 @@ bool Part::openFile() return true; } -bool Part::openUrl(const KUrl &_url) +bool Part::openUrl(const QUrl &_url) { // Close current document if any if ( !closeUrl() ) @@ -2186,7 +2186,7 @@ void Part::slotSaveFileAs() saveAs( saveUrl ); } -bool Part::saveAs( const KUrl & saveUrl ) +bool Part::saveAs( const QUrl & saveUrl ) { KTemporaryFile tf; QString fileName; @@ -2219,10 +2219,10 @@ bool Part::saveAs( const KUrl & saveUrl ) return false; } - KIO::Job *copyJob = KIO::file_copy( fileName, saveUrl, -1, KIO::Overwrite ); + KIO::Job *copyJob = KIO::file_copy( QUrl::fromLocalFile(fileName), saveUrl, -1, KIO::Overwrite ); if ( !KIO::NetAccess::synchronousRun( copyJob, widget() ) ) { - KMessageBox::information( widget(), i18n("File could not be saved in '%1'. Try to save it to another location.", saveUrl.prettyUrl() ) ); + KMessageBox::information( widget(), i18n("File could not be saved in '%1'. Try to save it to another location.", saveUrl.toDisplayString() ) ); return false; } @@ -2576,7 +2576,7 @@ void Part::slotExportAs(QAction * act) filter = m_exportFormats.at( id - 2 ).mimeType()->name(); break; } - QString fileName = KFileDialog::getSaveFileName( url().isLocalFile() ? url().adjusted(QUrl::RemoveFilename) : QString(), + QString fileName = KFileDialog::getSaveFileName( url(), filter, widget(), QString(), KFileDialog::ConfirmOverwrite ); if ( !fileName.isEmpty() ) @@ -2747,7 +2747,7 @@ void Part::psTransformEnded(int exit, QProcess::ExitStatus status) } setLocalFilePath( m_temporaryLocalFile ); - openUrl( m_temporaryLocalFile ); + openUrl( QUrl::fromLocalFile(m_temporaryLocalFile) ); m_temporaryLocalFile.clear(); } diff --git a/part.h b/part.h index e12e0c034..9abb693ad 100644 --- a/part.h +++ b/part.h @@ -164,17 +164,17 @@ class OKULAR_PART_EXPORT Part : public KParts::ReadWritePart, public Okular::Doc protected: // reimplemented from KParts::ReadWritePart - bool openFile(); - bool openUrl(const KUrl &url); - void guiActivateEvent(KParts::GUIActivateEvent *event); - void displayInfoMessage( const QString &message, KMessageWidget::MessageType messageType = KMessageWidget::Information, int duration = -1 );; + bool openFile() Q_DECL_OVERRIDE; + bool openUrl(const QUrl &url) Q_DECL_OVERRIDE; + void guiActivateEvent(KParts::GUIActivateEvent *event) Q_DECL_OVERRIDE; + void displayInfoMessage( const QString &message, KMessageWidget::MessageType messageType = KMessageWidget::Information, int duration = -1 ); public: - bool saveFile(); - bool queryClose(); - bool closeUrl(); - bool closeUrl(bool promptToSave); - void setReadWrite(bool readwrite); - bool saveAs(const KUrl & saveUrl); + bool saveFile() Q_DECL_OVERRIDE; + bool queryClose() Q_DECL_OVERRIDE; + bool closeUrl() Q_DECL_OVERRIDE; + bool closeUrl(bool promptToSave) Q_DECL_OVERRIDE; + void setReadWrite(bool readwrite) Q_DECL_OVERRIDE; + bool saveAs(const QUrl & saveUrl) Q_DECL_OVERRIDE; protected slots: // connected to actions diff --git a/shell/shell.cpp b/shell/shell.cpp index 929aa2100..ecf23a439 100644 --- a/shell/shell.cpp +++ b/shell/shell.cpp @@ -396,7 +396,8 @@ void Shell::fileOpen() const KParts::ReadWritePart* const curPart = m_tabs[activeTab].part; if ( curPart->url().isLocalFile() ) startDir = curPart->url().toLocalFile(); - KFileDialog dlg( startDir, QString(), this ); +#pragma message("KF5 check QUrl usage") + KFileDialog dlg( QUrl(startDir), QString(), this ); dlg.setOperationMode( KFileDialog::Opening ); // A directory may be a document. E.g. comicbook generator. diff --git a/ui/fileprinterpreview.cpp b/ui/fileprinterpreview.cpp index 1ffcb0b58..4724b8c6e 100644 --- a/ui/fileprinterpreview.cpp +++ b/ui/fileprinterpreview.cpp @@ -111,7 +111,7 @@ bool FilePrinterPreviewPrivate::doPreview() return false; } else { q->setMainWidget(previewPart->widget()); - return previewPart->openUrl(filename); + return previewPart->openUrl(QUrl::fromLocalFile(filename)); } } diff --git a/ui/guiutils.cpp b/ui/guiutils.cpp index 3bf3ad64b..aa12c2149 100644 --- a/ui/guiutils.cpp +++ b/ui/guiutils.cpp @@ -202,7 +202,7 @@ KIconLoader* iconLoader() void saveEmbeddedFile( Okular::EmbeddedFile *ef, QWidget *parent ) { const QString caption = i18n( "Where do you want to save %1?", ef->name() ); - const QString path = KFileDialog::getSaveFileName( ef->name(), QString(), parent, caption, + const QString path = KFileDialog::getSaveFileName( QUrl::fromLocalFile(ef->name()), QString(), parent, caption, KFileDialog::ConfirmOverwrite ); if ( path.isEmpty() ) return; diff --git a/ui/pageview.cpp b/ui/pageview.cpp index fc3174f3b..16dd66c02 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -2440,9 +2440,9 @@ void PageView::mouseReleaseEvent( QMouseEvent * e ) { const Okular::BrowseAction * browseLink = static_cast< const Okular::BrowseAction * >( link ); QClipboard *cb = QApplication::clipboard(); - cb->setText( browseLink->url(), QClipboard::Clipboard ); + cb->setText( browseLink->url().toDisplayString(), QClipboard::Clipboard ); if ( cb->supportsSelection() ) - cb->setText( browseLink->url(), QClipboard::Selection ); + cb->setText( browseLink->url().toDisplayString(), QClipboard::Selection ); } else if ( res == actStopSound ) { @@ -2621,13 +2621,13 @@ void PageView::mouseReleaseEvent( QMouseEvent * e ) else if ( choice == imageToFile ) { // [3] save pixmap to file - QString fileName = KFileDialog::getSaveFileName( KUrl(), "image/png image/jpeg", this, QString(), + QString fileName = KFileDialog::getSaveFileName( QUrl(), "image/png image/jpeg", this, QString(), KFileDialog::ConfirmOverwrite ); if ( fileName.isEmpty() ) d->messageWindow->display( i18n( "File not saved." ), QString(), PageViewMessage::Warning ); else { - KMimeType::Ptr mime = KMimeType::findByUrl( fileName ); + KMimeType::Ptr mime = KMimeType::findByUrl( QUrl::fromLocalFile(fileName) ); QString type; if ( !mime || mime == KMimeType::defaultMimeTypePtr() ) type = "PNG"; diff --git a/ui/propertiesdialog.cpp b/ui/propertiesdialog.cpp index 04e86dc69..5dc0c71e2 100644 --- a/ui/propertiesdialog.cpp +++ b/ui/propertiesdialog.cpp @@ -244,7 +244,7 @@ void PropertiesDialog::showFontsMenu(const QPoint &pos) { Okular::FontInfo fi = index.data(FontInfoRole).value(); const QString caption = i18n( "Where do you want to save %1?", fi.name() ); - const QString path = KFileDialog::getSaveFileName( fi.name(), QString(), this, caption, KFileDialog::ConfirmOverwrite ); + const QString path = KFileDialog::getSaveFileName( QUrl::fromLocalFile(fi.name()), QString(), this, caption, KFileDialog::ConfirmOverwrite ); if ( path.isEmpty() ) return; diff --git a/ui/toc.cpp b/ui/toc.cpp index 9ac338e6f..e796707fc 100644 --- a/ui/toc.cpp +++ b/ui/toc.cpp @@ -150,7 +150,7 @@ void TOC::slotExecuted( const QModelIndex &index ) QString url = m_model->urlForIndex( index ); if ( !url.isEmpty() ) { - Okular::BrowseAction action( url ); + Okular::BrowseAction action( QUrl::fromLocalFile( url ) ); m_document->processAction( &action ); return; }