More QUrl porting

frameworks
Frederik Gladhorn 12 years ago
parent 56eb2ae952
commit ac15a7075e
  1. 10
      core/action.cpp
  2. 4
      core/action.h
  3. 42
      core/document.cpp
  4. 49
      core/sourcereference.cpp
  5. 3
      core/sourcereference_p.h
  6. 16
      part.cpp
  7. 20
      part.h
  8. 3
      shell/shell.cpp
  9. 2
      ui/fileprinterpreview.cpp
  10. 2
      ui/guiutils.cpp
  11. 8
      ui/pageview.cpp
  12. 2
      ui/propertiesdialog.cpp
  13. 2
      ui/toc.cpp

@ -182,15 +182,15 @@ QString ExecuteAction::parameters() const
class Okular::BrowseActionPrivate : public Okular::ActionPrivate class Okular::BrowseActionPrivate : public Okular::ActionPrivate
{ {
public: public:
BrowseActionPrivate( const QString &url ) BrowseActionPrivate( const QUrl &url )
: ActionPrivate(), m_url( 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 ) ) : Action( *new BrowseActionPrivate( url ) )
{ {
} }
@ -213,10 +213,10 @@ QString BrowseAction::actionTip() const
{ {
return sourceReferenceToolTip( source, row, col ); 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 ); Q_D( const Okular::BrowseAction );
return d->m_url; return d->m_url;

@ -231,7 +231,7 @@ class OKULAR_EXPORT BrowseAction : public Action
* *
* @param url The url to browse. * @param url The url to browse.
*/ */
BrowseAction( const QString &url ); BrowseAction( const QUrl &url );
/** /**
* Destroys the browse action. * Destroys the browse action.
@ -251,7 +251,7 @@ class OKULAR_EXPORT BrowseAction : public Action
/** /**
* Returns the url to browse. * Returns the url to browse.
*/ */
QString url() const; QUrl url() const;
private: private:
Q_DECLARE_PRIVATE( BrowseAction ) Q_DECLARE_PRIVATE( BrowseAction )

@ -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 // 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 // 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 // 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() ) if ( newmime->name() != mime->name() )
{ {
mime = newmime; mime = newmime;
@ -3628,14 +3630,16 @@ void Document::processAction( const Action * action )
fileName = d->giveAbsolutePath( fileName ); fileName = d->giveAbsolutePath( fileName );
KMimeType::Ptr mime = KMimeType::findByPath( fileName ); KMimeType::Ptr mime = KMimeType::findByPath( fileName );
// Check executables // 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 // Don't have any pdf that uses this code path, just a guess on how it should work
if ( !exe->parameters().isEmpty() ) if ( !exe->parameters().isEmpty() )
{ {
fileName = d->giveAbsolutePath( exe->parameters() ); fileName = d->giveAbsolutePath( exe->parameters() );
mime = KMimeType::findByPath( fileName ); 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 // this case is a link pointing to an executable with a parameter
// that also is an executable, possibly a hand-crafted pdf // that also is an executable, possibly a hand-crafted pdf
@ -3713,7 +3717,7 @@ void Document::processAction( const Action * action )
QString lilySource; QString lilySource;
int lilyRow = 0, lilyCol = 0; int lilyRow = 0, lilyCol = 0;
// if the url is a mailto one, invoke mailer // 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() ); KToolInvocation::invokeMailer( browse->url() );
else if ( extractLilyPondSourceReference( browse->url(), &lilySource, &lilyRow, &lilyCol ) ) else if ( extractLilyPondSourceReference( browse->url(), &lilySource, &lilyRow, &lilyCol ) )
{ {
@ -3722,25 +3726,25 @@ void Document::processAction( const Action * action )
} }
else 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 // 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") // if (url.indexOf("http:") == 0 && url.indexOf("http://") == -1 && url.right(4) == ".pdf")
{ // {
d->openRelativeFile(url.mid(5)); // d->openRelativeFile(url.mid(5));
return; // return;
} // }
KUrl realUrl = KUrl( url );
// handle documents with relative path // FIXME
if ( d->m_url.isValid() ) // // handle documents with relative path
{ // if ( d->m_url.isValid() )
realUrl = KUrl( d->m_url.upUrl(), url ); // {
} // realUrl = KUrl( d->m_url.upUrl(), url );
// }
// Albert: this is not a leak! // // Albert: this is not a leak!
new KRun( realUrl, d->m_widget ); // new KRun( realUrl, d->m_widget );
} }
} break; } break;

@ -57,32 +57,35 @@ int SourceReference::column() const
return d->column; 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; return false;
*row = 0; #pragma message("KF5 fix LilyPond references")
*col = 0; return false;
int lilyChar = 0;
typedef int *IntPtr; // *row = 0;
const IntPtr int_data[] = { row, &lilyChar, col }; // *col = 0;
int int_index = sizeof( int_data ) / sizeof( int* ) - 1; // int lilyChar = 0;
int index_last = -1; // typedef int *IntPtr;
int index = url.lastIndexOf( QLatin1Char( ':' ), index_last ); // const IntPtr int_data[] = { row, &lilyChar, col };
while ( index != -1 && int_index >= 0 ) // int int_index = sizeof( int_data ) / sizeof( int* ) - 1;
{ // int index_last = -1;
// read the current "chunk" // int index = url.lastIndexOf( QLatin1Char( ':' ), index_last );
const QStringRef ref = url.midRef( index + 1, index_last - index - 1 ); // while ( index != -1 && int_index >= 0 )
*int_data[ int_index ] = QString::fromRawData( ref.data(), ref.count() ).toInt(); // {
// find the previous "chunk" // // read the current "chunk"
index_last = index; // const QStringRef ref = url.midRef( index + 1, index_last - index - 1 );
index = url.lastIndexOf( QLatin1Char( ':' ), index_last - 1 ); // *int_data[ int_index ] = QString::fromRawData( ref.data(), ref.count() ).toInt();
--int_index; // // find the previous "chunk"
} // index_last = index;
// NOTE: 11 is the length of "textedit://" // index = url.lastIndexOf( QLatin1Char( ':' ), index_last - 1 );
*file = QUrl::fromPercentEncoding( url.mid( 11, index_last != -1 ? index_last - 11 : -1 ).toUtf8() ); // --int_index;
return true; // }
// // 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 ) QString Okular::sourceReferenceToolTip( const QString &source, int row, int col )

@ -11,11 +11,12 @@
#define OKULAR_SOURCEREFERENCE_P_H #define OKULAR_SOURCEREFERENCE_P_H
class QString; class QString;
class QUrl;
namespace Okular 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 ); QString sourceReferenceToolTip( const QString &source, int row, int col );
} }

@ -115,7 +115,7 @@ class FileKeeper
void open( const QString & path ) void open( const QString & path )
{ {
if ( !m_handle ) if ( !m_handle )
m_handle = std::fopen( QFile::encodeName( path ), "r" ); m_handle = std::fopen( QFile::encodeName( path ).constData(), "r" );
} }
void close() 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->bookmarkManager(), SIGNAL(openUrl(KUrl)), this, SLOT(openUrlFromBookmarks(KUrl)) );
connect( m_document, SIGNAL(close()), this, SLOT(close()) ); 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()) ); connect( m_document, SIGNAL(quit()), parent, SLOT(slotQuit()) );
else else
connect( m_document, SIGNAL(quit()), this, SLOT(cannotQuit()) ); connect( m_document, SIGNAL(quit()), this, SLOT(cannotQuit()) );
@ -1454,7 +1454,7 @@ bool Part::openFile()
return true; return true;
} }
bool Part::openUrl(const KUrl &_url) bool Part::openUrl(const QUrl &_url)
{ {
// Close current document if any // Close current document if any
if ( !closeUrl() ) if ( !closeUrl() )
@ -2186,7 +2186,7 @@ void Part::slotSaveFileAs()
saveAs( saveUrl ); saveAs( saveUrl );
} }
bool Part::saveAs( const KUrl & saveUrl ) bool Part::saveAs( const QUrl & saveUrl )
{ {
KTemporaryFile tf; KTemporaryFile tf;
QString fileName; QString fileName;
@ -2219,10 +2219,10 @@ bool Part::saveAs( const KUrl & saveUrl )
return false; 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() ) ) 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; return false;
} }
@ -2576,7 +2576,7 @@ void Part::slotExportAs(QAction * act)
filter = m_exportFormats.at( id - 2 ).mimeType()->name(); filter = m_exportFormats.at( id - 2 ).mimeType()->name();
break; break;
} }
QString fileName = KFileDialog::getSaveFileName( url().isLocalFile() ? url().adjusted(QUrl::RemoveFilename) : QString(), QString fileName = KFileDialog::getSaveFileName( url(),
filter, widget(), QString(), filter, widget(), QString(),
KFileDialog::ConfirmOverwrite ); KFileDialog::ConfirmOverwrite );
if ( !fileName.isEmpty() ) if ( !fileName.isEmpty() )
@ -2747,7 +2747,7 @@ void Part::psTransformEnded(int exit, QProcess::ExitStatus status)
} }
setLocalFilePath( m_temporaryLocalFile ); setLocalFilePath( m_temporaryLocalFile );
openUrl( m_temporaryLocalFile ); openUrl( QUrl::fromLocalFile(m_temporaryLocalFile) );
m_temporaryLocalFile.clear(); m_temporaryLocalFile.clear();
} }

@ -164,17 +164,17 @@ class OKULAR_PART_EXPORT Part : public KParts::ReadWritePart, public Okular::Doc
protected: protected:
// reimplemented from KParts::ReadWritePart // reimplemented from KParts::ReadWritePart
bool openFile(); bool openFile() Q_DECL_OVERRIDE;
bool openUrl(const KUrl &url); bool openUrl(const QUrl &url) Q_DECL_OVERRIDE;
void guiActivateEvent(KParts::GUIActivateEvent *event); void guiActivateEvent(KParts::GUIActivateEvent *event) Q_DECL_OVERRIDE;
void displayInfoMessage( const QString &message, KMessageWidget::MessageType messageType = KMessageWidget::Information, int duration = -1 );; void displayInfoMessage( const QString &message, KMessageWidget::MessageType messageType = KMessageWidget::Information, int duration = -1 );
public: public:
bool saveFile(); bool saveFile() Q_DECL_OVERRIDE;
bool queryClose(); bool queryClose() Q_DECL_OVERRIDE;
bool closeUrl(); bool closeUrl() Q_DECL_OVERRIDE;
bool closeUrl(bool promptToSave); bool closeUrl(bool promptToSave) Q_DECL_OVERRIDE;
void setReadWrite(bool readwrite); void setReadWrite(bool readwrite) Q_DECL_OVERRIDE;
bool saveAs(const KUrl & saveUrl); bool saveAs(const QUrl & saveUrl) Q_DECL_OVERRIDE;
protected slots: protected slots:
// connected to actions // connected to actions

@ -396,7 +396,8 @@ void Shell::fileOpen()
const KParts::ReadWritePart* const curPart = m_tabs[activeTab].part; const KParts::ReadWritePart* const curPart = m_tabs[activeTab].part;
if ( curPart->url().isLocalFile() ) if ( curPart->url().isLocalFile() )
startDir = curPart->url().toLocalFile(); 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 ); dlg.setOperationMode( KFileDialog::Opening );
// A directory may be a document. E.g. comicbook generator. // A directory may be a document. E.g. comicbook generator.

@ -111,7 +111,7 @@ bool FilePrinterPreviewPrivate::doPreview()
return false; return false;
} else { } else {
q->setMainWidget(previewPart->widget()); q->setMainWidget(previewPart->widget());
return previewPart->openUrl(filename); return previewPart->openUrl(QUrl::fromLocalFile(filename));
} }
} }

@ -202,7 +202,7 @@ KIconLoader* iconLoader()
void saveEmbeddedFile( Okular::EmbeddedFile *ef, QWidget *parent ) void saveEmbeddedFile( Okular::EmbeddedFile *ef, QWidget *parent )
{ {
const QString caption = i18n( "Where do you want to save %1?", ef->name() ); 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 ); KFileDialog::ConfirmOverwrite );
if ( path.isEmpty() ) if ( path.isEmpty() )
return; return;

@ -2440,9 +2440,9 @@ void PageView::mouseReleaseEvent( QMouseEvent * e )
{ {
const Okular::BrowseAction * browseLink = static_cast< const Okular::BrowseAction * >( link ); const Okular::BrowseAction * browseLink = static_cast< const Okular::BrowseAction * >( link );
QClipboard *cb = QApplication::clipboard(); QClipboard *cb = QApplication::clipboard();
cb->setText( browseLink->url(), QClipboard::Clipboard ); cb->setText( browseLink->url().toDisplayString(), QClipboard::Clipboard );
if ( cb->supportsSelection() ) if ( cb->supportsSelection() )
cb->setText( browseLink->url(), QClipboard::Selection ); cb->setText( browseLink->url().toDisplayString(), QClipboard::Selection );
} }
else if ( res == actStopSound ) else if ( res == actStopSound )
{ {
@ -2621,13 +2621,13 @@ void PageView::mouseReleaseEvent( QMouseEvent * e )
else if ( choice == imageToFile ) else if ( choice == imageToFile )
{ {
// [3] save pixmap to file // [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 ); KFileDialog::ConfirmOverwrite );
if ( fileName.isEmpty() ) if ( fileName.isEmpty() )
d->messageWindow->display( i18n( "File not saved." ), QString(), PageViewMessage::Warning ); d->messageWindow->display( i18n( "File not saved." ), QString(), PageViewMessage::Warning );
else else
{ {
KMimeType::Ptr mime = KMimeType::findByUrl( fileName ); KMimeType::Ptr mime = KMimeType::findByUrl( QUrl::fromLocalFile(fileName) );
QString type; QString type;
if ( !mime || mime == KMimeType::defaultMimeTypePtr() ) if ( !mime || mime == KMimeType::defaultMimeTypePtr() )
type = "PNG"; type = "PNG";

@ -244,7 +244,7 @@ void PropertiesDialog::showFontsMenu(const QPoint &pos)
{ {
Okular::FontInfo fi = index.data(FontInfoRole).value<Okular::FontInfo>(); Okular::FontInfo fi = index.data(FontInfoRole).value<Okular::FontInfo>();
const QString caption = i18n( "Where do you want to save %1?", fi.name() ); 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() ) if ( path.isEmpty() )
return; return;

@ -150,7 +150,7 @@ void TOC::slotExecuted( const QModelIndex &index )
QString url = m_model->urlForIndex( index ); QString url = m_model->urlForIndex( index );
if ( !url.isEmpty() ) if ( !url.isEmpty() )
{ {
Okular::BrowseAction action( url ); Okular::BrowseAction action( QUrl::fromLocalFile( url ) );
m_document->processAction( &action ); m_document->processAction( &action );
return; return;
} }

Loading…
Cancel
Save