From c0d67ae2e3a18d5fba6c1bcc46fc14a2fe4ee6b7 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Fri, 7 Jul 2006 14:28:21 +0000 Subject: [PATCH] sort the plugins we have for the current file by priority (more priority ... less priority) improve a bit the message of the generator selection dialog svn path=/trunk/playground/graphics/okular/; revision=559497 --- core/chooseenginedialog.cpp | 6 +++--- core/chooseenginedialog.h | 3 ++- core/document.cpp | 11 +++++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/core/chooseenginedialog.cpp b/core/chooseenginedialog.cpp index 996a697a6..f20e3f61d 100644 --- a/core/chooseenginedialog.cpp +++ b/core/chooseenginedialog.cpp @@ -15,7 +15,7 @@ #include "chooseenginedialog.h" -ChooseEngineDialog::ChooseEngineDialog( const QStringList &generators, const QString &mime, QWidget * parent ) +ChooseEngineDialog::ChooseEngineDialog( const QStringList &generators, const KMimeType::Ptr &mime, QWidget * parent ) : KDialog( parent ) { setCaption( i18n( "Generator Selection" ) ); @@ -29,8 +29,8 @@ ChooseEngineDialog::ChooseEngineDialog( const QStringList &generators, const QSt m_widget->engineList->addItems(generators); m_widget->description->setText( - i18n( "More than one generator found for mimetype \"%1\".\n" - "Please select which one to use:", mime ) ); + i18n( "More than one generator found for mimetype \"%1\" (%2).\n" + "Please select which one to use:", mime->comment(), mime->name() ) ); } int ChooseEngineDialog::selectedGenerator() const diff --git a/core/chooseenginedialog.h b/core/chooseenginedialog.h index ca597c457..830af918f 100644 --- a/core/chooseenginedialog.h +++ b/core/chooseenginedialog.h @@ -13,13 +13,14 @@ #include #include +#include class Ui_ChooseEngineWidget; class ChooseEngineDialog : public KDialog { public: - ChooseEngineDialog( const QStringList &generators, const QString &mime, QWidget * parent = 0 ); + ChooseEngineDialog( const QStringList &generators, const KMimeType::Ptr &mime, QWidget * parent = 0 ); int selectedGenerator() const; diff --git a/core/document.cpp b/core/document.cpp index 52ec23770..350868916 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -134,6 +135,10 @@ KPDFDocument::~KPDFDocument() delete d; } +static bool kserviceMoreThan( const KService::Ptr &s1, const KService::Ptr &s2 ) +{ + return s1->property( "X-KDE-Priority" ).toInt() > s2->property( "X-KDE-Priority" ).toInt(); +} bool KPDFDocument::openDocument( const QString & docFile, const KUrl& url, const KMimeType::Ptr &mime ) { @@ -161,10 +166,12 @@ bool KPDFDocument::openDocument( const QString & docFile, const KUrl& url, const KService::List offers = KMimeTypeTrader::self()->query(mime->name(),"okular/Generator",constraint); if (offers.isEmpty()) { - kWarning() << "No plugin for '" << mime->name() << "' mimetype." << endl; + kWarning() << "No plugin for mimetype '" << mime->name() << "'." << endl; return false; } int hRank=0; + // order the offers: the offers with an higher priority come before + qStableSort( offers.begin(), offers.end(), kserviceMoreThan ); // best ranked offer search if (offers.count() > 1 && KpdfSettings::chooseGenerators() ) @@ -175,7 +182,7 @@ bool KPDFDocument::openDocument( const QString & docFile, const KUrl& url, const { list << offers[i]->property("Name").toString(); } - ChooseEngineDialog * choose = new ChooseEngineDialog (list, mime->name(), 0); + ChooseEngineDialog * choose = new ChooseEngineDialog (list, mime, 0); int retval=choose->exec(); int index=choose->selectedGenerator();