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
remotes/origin/old/work/newpageview
Pino Toscano 20 years ago
parent 3e620c0918
commit c0d67ae2e3
  1. 6
      core/chooseenginedialog.cpp
  2. 3
      core/chooseenginedialog.h
  3. 11
      core/document.cpp

@ -15,7 +15,7 @@
#include "chooseenginedialog.h" #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 ) : KDialog( parent )
{ {
setCaption( i18n( "Generator Selection" ) ); setCaption( i18n( "Generator Selection" ) );
@ -29,8 +29,8 @@ ChooseEngineDialog::ChooseEngineDialog( const QStringList &generators, const QSt
m_widget->engineList->addItems(generators); m_widget->engineList->addItems(generators);
m_widget->description->setText( m_widget->description->setText(
i18n( "More than one generator found for mimetype \"%1\".\n" i18n( "More than one generator found for mimetype \"%1\" (%2).\n"
"Please select which one to use:", mime ) ); "Please select which one to use:", mime->comment(), mime->name() ) );
} }
int ChooseEngineDialog::selectedGenerator() const int ChooseEngineDialog::selectedGenerator() const

@ -13,13 +13,14 @@
#include <qstringlist.h> #include <qstringlist.h>
#include <kdialog.h> #include <kdialog.h>
#include <kmimetype.h>
class Ui_ChooseEngineWidget; class Ui_ChooseEngineWidget;
class ChooseEngineDialog : public KDialog class ChooseEngineDialog : public KDialog
{ {
public: 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; int selectedGenerator() const;

@ -14,6 +14,7 @@
#include <qfile.h> #include <qfile.h>
#include <qfileinfo.h> #include <qfileinfo.h>
#include <qimage.h> #include <qimage.h>
#include <QtAlgorithms>
#include <qtextstream.h> #include <qtextstream.h>
#include <qvector.h> #include <qvector.h>
#include <qtimer.h> #include <qtimer.h>
@ -134,6 +135,10 @@ KPDFDocument::~KPDFDocument()
delete d; 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 ) 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); KService::List offers = KMimeTypeTrader::self()->query(mime->name(),"okular/Generator",constraint);
if (offers.isEmpty()) if (offers.isEmpty())
{ {
kWarning() << "No plugin for '" << mime->name() << "' mimetype." << endl; kWarning() << "No plugin for mimetype '" << mime->name() << "'." << endl;
return false; return false;
} }
int hRank=0; int hRank=0;
// order the offers: the offers with an higher priority come before
qStableSort( offers.begin(), offers.end(), kserviceMoreThan );
// best ranked offer search // best ranked offer search
if (offers.count() > 1 && KpdfSettings::chooseGenerators() ) 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(); 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 retval=choose->exec();
int index=choose->selectedGenerator(); int index=choose->selectedGenerator();

Loading…
Cancel
Save