mirror of
https://invent.kde.org/graphics/okular
synced 2024-09-06 00:15:42 +00:00
Merge remote-tracking branch 'origin/KDE/4.14'
This commit is contained in:
commit
13395f4740
78
part.cpp
78
part.cpp
|
@ -1208,34 +1208,26 @@ static void addFileToWatcher( KDirWatch *watcher, const QString &filePath)
|
|||
if ( fi.isSymLink() ) watcher->addFile( fi.readLink() );
|
||||
}
|
||||
|
||||
bool Part::openFile()
|
||||
Document::OpenResult Part::doOpenFile( const KMimeType::Ptr &mimeA, const QString &fileNameToOpenA, bool *isCompressedFile )
|
||||
{
|
||||
KMimeType::Ptr mime;
|
||||
QString fileNameToOpen = localFilePath();
|
||||
const bool isstdin = url().isLocalFile() && url().fileName( KUrl::ObeyTrailingSlash ) == QLatin1String( "-" );
|
||||
const QFileInfo fileInfo( fileNameToOpen );
|
||||
if ( !isstdin && !fileInfo.exists() )
|
||||
return false;
|
||||
if ( !arguments().mimeType().isEmpty() )
|
||||
{
|
||||
mime = KMimeType::mimeType( arguments().mimeType() );
|
||||
}
|
||||
if ( !mime )
|
||||
{
|
||||
mime = KMimeType::findByPath( fileNameToOpen );
|
||||
}
|
||||
bool isCompressedFile = false;
|
||||
Document::OpenResult openResult = Document::OpenError;
|
||||
bool uncompressOk = true;
|
||||
KMimeType::Ptr mime = mimeA;
|
||||
QString fileNameToOpen = fileNameToOpenA;
|
||||
QString compressedMime = compressedMimeFor( mime->name() );
|
||||
if ( compressedMime.isEmpty() )
|
||||
compressedMime = compressedMimeFor( mime->parentMimeType() );
|
||||
if ( !compressedMime.isEmpty() )
|
||||
{
|
||||
isCompressedFile = true;
|
||||
*isCompressedFile = true;
|
||||
uncompressOk = handleCompressed( fileNameToOpen, localFilePath(), compressedMime );
|
||||
mime = KMimeType::findByPath( fileNameToOpen );
|
||||
}
|
||||
Document::OpenResult openResult = Document::OpenError;
|
||||
else
|
||||
{
|
||||
*isCompressedFile = false;
|
||||
}
|
||||
|
||||
isDocumentArchive = false;
|
||||
if ( uncompressOk )
|
||||
{
|
||||
|
@ -1320,6 +1312,56 @@ bool Part::openFile()
|
|||
}
|
||||
}
|
||||
|
||||
return openResult;
|
||||
}
|
||||
|
||||
bool Part::openFile()
|
||||
{
|
||||
QList<KMimeType::Ptr> mimes;
|
||||
QString fileNameToOpen = localFilePath();
|
||||
const bool isstdin = url().isLocalFile() && url().fileName( KUrl::ObeyTrailingSlash ) == QLatin1String( "-" );
|
||||
const QFileInfo fileInfo( fileNameToOpen );
|
||||
if ( !isstdin && !fileInfo.exists() )
|
||||
return false;
|
||||
KMimeType::Ptr pathMime = KMimeType::findByPath( fileNameToOpen );
|
||||
if ( !arguments().mimeType().isEmpty() )
|
||||
{
|
||||
KMimeType::Ptr argMime = KMimeType::mimeType( arguments().mimeType() );
|
||||
|
||||
// Select the "childmost" mimetype, if none of them
|
||||
// inherits the other trust more what pathMime says
|
||||
// but still do a second try if that one fails
|
||||
if ( argMime->is( pathMime->name() ) )
|
||||
{
|
||||
mimes << argMime;
|
||||
}
|
||||
else if ( pathMime->is( argMime->name() ) )
|
||||
{
|
||||
mimes << pathMime;
|
||||
}
|
||||
else
|
||||
{
|
||||
mimes << pathMime << argMime;
|
||||
}
|
||||
|
||||
if (mimes[0]->name() == "text/plain") {
|
||||
KMimeType::Ptr contentMime = KMimeType::findByFileContent( fileNameToOpen );
|
||||
mimes.prepend( contentMime );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mimes << pathMime;
|
||||
}
|
||||
|
||||
KMimeType::Ptr mime;
|
||||
Document::OpenResult openResult = Document::OpenError;
|
||||
bool isCompressedFile = false;
|
||||
while ( !mimes.isEmpty() && openResult == Document::OpenError ) {
|
||||
mime = mimes.takeFirst();
|
||||
openResult = doOpenFile( mime, fileNameToOpen, &isCompressedFile );
|
||||
}
|
||||
|
||||
bool canSearch = m_document->supportsSearching();
|
||||
emit mimeTypeChanged( mime );
|
||||
|
||||
|
|
2
part.h
2
part.h
|
@ -234,6 +234,8 @@ class OKULAR_PART_EXPORT Part : public KParts::ReadWritePart, public Okular::Doc
|
|||
void noticeMessage( const QString &message, int duration = -1 );
|
||||
|
||||
private:
|
||||
Document::OpenResult doOpenFile(const KMimeType::Ptr &mime, const QString &fileNameToOpen, bool *isCompressedFile);
|
||||
|
||||
void setupViewerActions();
|
||||
void setViewerShortcuts();
|
||||
void setupActions();
|
||||
|
|
Loading…
Reference in a new issue