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
This commit is contained in:
Pino Toscano 2006-07-07 14:28:21 +00:00
parent 3e620c0918
commit c0d67ae2e3
3 changed files with 14 additions and 6 deletions

View file

@ -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

View file

@ -13,13 +13,14 @@
#include <qstringlist.h>
#include <kdialog.h>
#include <kmimetype.h>
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;

View file

@ -14,6 +14,7 @@
#include <qfile.h>
#include <qfileinfo.h>
#include <qimage.h>
#include <QtAlgorithms>
#include <qtextstream.h>
#include <qvector.h>
#include <qtimer.h>
@ -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();