Commit 13395f47 authored by Albert Astals Cid's avatar Albert Astals Cid

Merge remote-tracking branch 'origin/KDE/4.14'

parents f76184cb fba90677
......@@ -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 );
......
......@@ -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();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment