Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Graphics
Okular
Commits
ac15a707
Commit
ac15a707
authored
Aug 10, 2014
by
Frederik Gladhorn
Browse files
More QUrl porting
parent
56eb2ae9
Changes
13
Hide whitespace changes
Inline
Side-by-side
core/action.cpp
View file @
ac15a707
...
...
@@ -182,15 +182,15 @@ QString ExecuteAction::parameters() const
class
Okular
::
BrowseActionPrivate
:
public
Okular
::
ActionPrivate
{
public:
BrowseActionPrivate
(
const
Q
String
&
url
)
BrowseActionPrivate
(
const
Q
Url
&
url
)
:
ActionPrivate
(),
m_url
(
url
)
{
}
Q
String
m_url
;
Q
Url
m_url
;
};
BrowseAction
::
BrowseAction
(
const
Q
String
&
url
)
BrowseAction
::
BrowseAction
(
const
Q
Url
&
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
()
;
}
Q
String
BrowseAction
::
url
()
const
Q
Url
BrowseAction
::
url
()
const
{
Q_D
(
const
Okular
::
BrowseAction
);
return
d
->
m_url
;
...
...
core/action.h
View file @
ac15a707
...
...
@@ -231,7 +231,7 @@ class OKULAR_EXPORT BrowseAction : public Action
*
* @param url The url to browse.
*/
BrowseAction
(
const
Q
String
&
url
);
BrowseAction
(
const
Q
Url
&
url
);
/**
* Destroys the browse action.
...
...
@@ -251,7 +251,7 @@ class OKULAR_EXPORT BrowseAction : public Action
/**
* Returns the url to browse.
*/
Q
String
url
()
const
;
Q
Url
url
()
const
;
private:
Q_DECLARE_PRIVATE
(
BrowseAction
)
...
...
core/document.cpp
View file @
ac15a707
...
...
@@ -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
().
s
tartsWith
(
"mailto:"
,
Qt
::
CaseInsensitive
)
)
if
(
browse
->
url
().
s
cheme
().
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
{
Q
String
url
=
browse
->
url
();
Q
Url
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
;
...
...
core/sourcereference.cpp
View file @
ac15a707
...
...
@@ -57,32 +57,35 @@ int SourceReference::column() const
return
d
->
column
;
}
bool
Okular
::
extractLilyPondSourceReference
(
const
Q
String
&
url
,
QString
*
file
,
int
*
row
,
int
*
col
)
bool
Okular
::
extractLilyPondSourceReference
(
const
Q
Url
&
url
,
QString
*
file
,
int
*
row
,
int
*
col
)
{
if
(
!
url
.
s
tartsWith
(
QLatin1String
(
"textedit
://"
)
)
)
if
(
url
.
s
cheme
()
!=
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
)
...
...
core/sourcereference_p.h
View file @
ac15a707
...
...
@@ -11,11 +11,12 @@
#define OKULAR_SOURCEREFERENCE_P_H
class
QString
;
class
QUrl
;
namespace
Okular
{
bool
extractLilyPondSourceReference
(
const
Q
String
&
url
,
QString
*
file
,
int
*
row
,
int
*
col
);
bool
extractLilyPondSourceReference
(
const
Q
Url
&
url
,
QString
*
file
,
int
*
row
,
int
*
col
);
QString
sourceReferenceToolTip
(
const
QString
&
source
,
int
row
,
int
col
);
}
...
...
part.cpp
View file @
ac15a707
...
...
@@ -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
K
Url
&
_url
)
bool
Part
::
openUrl
(
const
Q
Url
&
_url
)
{
// Close current document if any
if
(
!
closeUrl
()
)
...
...
@@ -2186,7 +2186,7 @@ void Part::slotSaveFileAs()
saveAs
(
saveUrl
);
}
bool
Part
::
saveAs
(
const
K
Url
&
saveUrl
)
bool
Part
::
saveAs
(
const
Q
Url
&
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
();
}
...
...
part.h
View file @
ac15a707
...
...
@@ -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
K
Url
&
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
Q
Url
&
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
K
Url
&
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
Q
Url
&
saveUrl
)
Q_DECL_OVERRIDE
;
protected
slots
:
// connected to actions
...
...
shell/shell.cpp
View file @
ac15a707
...
...
@@ -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.
...
...
ui/fileprinterpreview.cpp
View file @
ac15a707
...
...
@@ -111,7 +111,7 @@ bool FilePrinterPreviewPrivate::doPreview()
return
false
;
}
else
{
q
->
setMainWidget
(
previewPart
->
widget
());
return
previewPart
->
openUrl
(
filename
);
return
previewPart
->
openUrl
(
QUrl
::
fromLocalFile
(
filename
)
)
;
}
}
...
...
ui/guiutils.cpp
View file @
ac15a707
...
...
@@ -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
;
...
...
ui/pageview.cpp
View file @
ac15a707
...
...
@@ -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
(
K
Url
(),
"image/png image/jpeg"
,
this
,
QString
(),
QString
fileName
=
KFileDialog
::
getSaveFileName
(
Q
Url
(),
"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"
;
...
...
ui/propertiesdialog.cpp
View file @
ac15a707
...
...
@@ -244,7 +244,7 @@ void PropertiesDialog::showFontsMenu(const QPoint &pos)
{
Okular
::
FontInfo
fi
=
index
.
data
(
FontInfoRole
).
value
<
Okular
::
FontInfo
>
();
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
;
...
...
ui/toc.cpp
View file @
ac15a707
...
...
@@ -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
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment