本文整理汇总了C++中kservice::List::first方法的典型用法代码示例。如果您正苦于以下问题:C++ List::first方法的具体用法?C++ List::first怎么用?C++ List::first使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kservice::List
的用法示例。
在下文中一共展示了List::first方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: openFile
void FileManager::openFile( const QString& fileName, const QString& name, const QString& title, const QString& partName, const QVariantList& partParams )
{
if( fileName.isEmpty() )
return;
QString fullName = name.isEmpty() ? KUrl( fileName ).fileName() : name;
QString fullTitle = title.isEmpty() ? fullName : title;
if( d->parts.contains( fullName ) )
{
emit newPart( fullName, fullTitle );
return;
}
KMimeType::Ptr mime = KMimeType::findByPath( fileName );
KParts::ReadOnlyPart* part = 0;
KService::List parts;
if( !partName.isEmpty() )
{
KService::Ptr service = KService::serviceByDesktopName( partName );
if( !service.isNull() )
parts.append( service );
}
if( parts.count() == 0 )
{
parts.append( KMimeTypeTrader::self()->query( mime->name(), "KParts/ReadWritePart" ) );
parts.append( KMimeTypeTrader::self()->query( mime->name(), "KParts/ReadOnlyPart" ) );
if( mime->name().contains( "audio" ) && parts.count() == 0 )
parts.append( KService::serviceByStorageId( "dragonplayer_part.desktop" ) );
}
if( parts.count() > 0 )
{
part = parts.first()->createInstance<KParts::ReadWritePart>( 0, partParams );
if( !part )
part = parts.first()->createInstance<KParts::ReadOnlyPart>( 0, partParams );
}
if( part )
{
// Add the part if it is found
KUrl url( fileName );
part->openUrl( url );
d->parts.insert( fullName, part );
d->partManager->addPart( part, true );
emit newPart( fullName, fullTitle );
return;
}
// There really is no part that can be used.
// Instead, just open it in an external application.
// KRun* runner = new KRun( KUrl( fileName ), qApp->activeWindow() );
}
示例2: getViewer
KService::Ptr ArkViewer::getViewer(const QString &mimeType)
{
// No point in even trying to find anything for application/octet-stream
if (mimeType == QStringLiteral("application/octet-stream")) {
return KService::Ptr();
}
// Try to get a read-only kpart for the internal viewer
KService::List offers = KMimeTypeTrader::self()->query(mimeType, QStringLiteral("KParts/ReadOnlyPart"));
auto arkPartIt = std::find_if(offers.begin(), offers.end(), [](KService::Ptr service) {
return service->storageId() == QLatin1String("ark_part.desktop");
});
// Use the Ark part only when the mime type matches an archive type directly.
// Many file types (e.g. Open Document) are technically just archives
// but browsing their internals is typically not what the user wants.
if (arkPartIt != offers.end()) {
// Not using hasMimeType() as we're explicitly not interested in inheritance.
if (!(*arkPartIt)->mimeTypes().contains(mimeType)) {
offers.erase(arkPartIt);
}
}
// If we can't find a kpart, try to get an external application
if (offers.isEmpty()) {
offers = KMimeTypeTrader::self()->query(mimeType, QStringLiteral("Application"));
}
if (!offers.isEmpty()) {
return offers.first();
} else {
return KService::Ptr();
}
}
示例3: installButton
bool
EngineController::installDistroCodec()
{
KService::List services = KServiceTypeTrader::self()->query( "Amarok/CodecInstall"
, QString( "[X-KDE-Amarok-codec] == 'mp3' and [X-KDE-Amarok-engine] == 'phonon-%1'").arg( "xine" ) );
//todo - figure out how to query Phonon for the current backend loaded
if( !services.isEmpty() )
{
KService::Ptr service = services.first(); //list is not empty
QString installScript = service->exec();
if( !installScript.isNull() ) //just a sanity check
{
KGuiItem installButton( i18n( "Install MP3 Support" ) );
if(KMessageBox::questionYesNo( The::mainWindow()
, i18n("Amarok currently cannot play MP3 files. Do you want to install support for MP3?")
, i18n( "No MP3 Support" )
, installButton
, KStandardGuiItem::no()
, "codecInstallWarning" ) == KMessageBox::Yes )
{
KRun::runCommand(installScript, 0);
return true;
}
}
}
return false;
}
示例4: urlSelected
bool DocumentationViewer::urlSelected(const QString &url, int button, int state, const QString &_target, const KParts::OpenUrlArguments &args, const KParts::BrowserArguments & /* browserArgs */)
{
KUrl cURL = completeURL(url);
QString mime = KMimeType::findByUrl(cURL).data()->name();
//load this URL in the embedded viewer if KHTML can handle it, or when mimetype detection failed
KService::Ptr service = KService::serviceByDesktopName("khtml");
if(( mime == KMimeType::defaultMimeType() ) || (service && service->hasServiceType(mime))) {
KHTMLPart::urlSelected(url, button, state, _target, args);
openUrl(cURL);
addToHistory(cURL.url());
}
//KHTML can't handle it, look for an appropriate application
else {
KService::List offers = KMimeTypeTrader::self()->query(mime, "Type == 'Application'");
if(offers.isEmpty()) {
KMessageBox::error(view(), i18n("No KDE service found for the MIME type \"%1\".", mime));
return false;
}
KUrl::List lst;
lst.append(cURL);
KRun::run(*(offers.first()), lst, view());
}
return true;
}
示例5: findPartFactory
KParts::Factory* IPartController::findPartFactory ( const QString& mimetype, const QString& parttype, const QString& preferredName )
{
// parttype may be a interface type not derived from KParts/ReadOnlyPart
const KService::List offers = KMimeTypeTrader::self()->query( mimetype,
QString::fromLatin1( "KParts/ReadOnlyPart" ),
QString::fromLatin1( "'%1' in ServiceTypes" ).arg( parttype ) );
if ( ! offers.isEmpty() )
{
KService::Ptr ptr;
// if there is a preferred plugin we'll take it
if ( !preferredName.isEmpty() )
{
KService::List::ConstIterator it;
for ( it = offers.constBegin(); it != offers.constEnd(); ++it )
{
if ( ( *it ) ->desktopEntryName() == preferredName )
{
ptr = ( *it );
break;
}
}
}
// else we just take the first in the list
if ( !ptr )
{
ptr = offers.first();
}
KPluginLoader loader( QFile::encodeName( ptr->library() ) );
return static_cast<KParts::Factory*>( loader.factory() );
}
return 0;
}
示例6: launchDateKcm
void Clock::launchDateKcm() //SLOT
{
KService::List offers = KServiceTypeTrader::self()->query("KCModule", "Library == 'kcm_locale'");
if (!offers.isEmpty()) {
KService::Ptr service = offers.first();
KRun::run(*service, KUrl::List(), 0);
}
update();
}
示例7: findPropertyByCountry
QVariant ibanBicData::findPropertyByCountry(const QString& countryCode, const QString& property, const QVariant::Type type)
{
const KService::List services = KServiceTypeTrader::self()->query("KMyMoney/IbanBicData",
QString("'%1' ~in [X-KMyMoney-CountryCodes] and exist [%2]").arg(countryCode).arg(property)
);
if (!services.isEmpty())
return services.first()->property(property, type);
// Something went wrong
return QVariant();
}
示例8:
KFileWritePlugin*
KFileWriterProvider::loadPlugin(const QString& key) {
//kDebug() << "loading writer for key " << key;
const QString constraint = QString::fromLatin1("'%1' in MetaDataKeys")
.arg(key);
const KService::List offers = KServiceTypeTrader::self()->query(
"KFileWrite", constraint);
if (offers.isEmpty()) {
return 0;
}
return offers.first()->createInstance<KFileWritePlugin>();
}
示例9: plugin
TestDataEngineBlackBox::TestDataEngineBlackBox(QString identifier)
{
Plasma::DataEngine* engine = 0;
// load the engine, add it to the engines
QString constraint = QString("[X-KDE-PluginInfo-Name] == '" + identifier + '\'').arg(identifier);
KService::List offers = KServiceTypeTrader::self()->query("Plasma/DataEngine", constraint);
QString error;
if (!offers.isEmpty()) {
QVariantList allArgs;
allArgs << offers.first()->storageId();
QString api = offers.first()->property("X-Plasma-API").toString();
if (api.isEmpty()) {
if (offers.first()) {
KPluginLoader plugin(*offers.first());
if (Plasma::isPluginVersionCompatible(plugin.pluginVersion())) {
engine = offers.first()->createInstance<Plasma::DataEngine>(0, allArgs, &error);
}
}
} else {
engine = new Plasma::DataEngine(0, offers.first());
}
}
m_engine = engine;
}
示例10: viewInInternalViewer
bool ArkViewer::viewInInternalViewer(const QString& fileName, const QMimeType &mimeType)
{
setWindowFilePath(fileName);
// Set icon and comment for the mimetype.
m_iconLabel->setPixmap(QIcon::fromTheme(mimeType.iconName()).pixmap(IconSize(KIconLoader::Small), IconSize(KIconLoader::Small)));
m_commentLabel->setText(mimeType.comment());
// Create the ReadOnlyPart instance.
m_part = KMimeTypeTrader::self()->createPartInstanceFromQuery<KParts::ReadOnlyPart>(mimeType.name(), this, this);
// Drop the KHTMLPart, if necessary.
const KService::Ptr service = KMimeTypeTrader::self()->preferredService(mimeType.name(), QStringLiteral("KParts/ReadOnlyPart"));
qCDebug(ARK) << "Preferred service for mimetype" << mimeType.name() << "is" << service->library();
if (service.constData()->desktopEntryName() == QLatin1String("khtml")) {
KService::List offers = KMimeTypeTrader::self()->query(mimeType.name(), QStringLiteral("KParts/ReadOnlyPart"));
offers.removeFirst();
qCDebug(ARK) << "Removed KHTMLPart from the offers for mimetype" << mimeType.name()
<< ". Using" << offers.first().constData()->desktopEntryName() << "instead.";
m_part = offers.first().constData()->createInstance<KParts::ReadOnlyPart>(this, this);
}
if (!m_part.data()) {
return false;
}
// Insert the KPart into its placeholder.
centralWidget()->layout()->replaceWidget(m_partPlaceholder, m_part.data()->widget());
createGUI(m_part.data());
setAutoSaveSettings(QStringLiteral("Viewer"), true);
m_part.data()->openUrl(QUrl::fromLocalFile(fileName));
m_part.data()->widget()->setFocus();
m_fileName = fileName;
return true;
}
示例11: isBicAllocated
ibanBicData::bicAllocationStatus ibanBicData::isBicAllocated(const QString& bic)
{
// Get countryCode
const QString countryCode = bic.mid(4, 2);
if (countryCode.length() != 2)
return bicNotAllocated;
// Get services which have a database entry
KService::List services = KServiceTypeTrader::self()->query("KMyMoney/IbanBicData",
QString("(\'%1' ~in [X-KMyMoney-CountryCodes] or '*' in [X-KMyMoney-CountryCodes]) and exist [X-KMyMoney-Bankdata-Database]").arg(countryCode)
);
if (services.isEmpty())
return bicAllocationUncertain;
QSqlDatabase db = createDatabaseConnection(services.first()->property(QLatin1String("X-KMyMoney-Bankdata-Database"), QVariant::String).toString());
if (!db.isOpen()) // This is an error
return bicAllocationUncertain;
QSqlQuery query(db);
query.prepare("SELECT ? IN (SELECT bic FROM institutions)");
query.bindValue(0, bic);
if (!query.exec() || !query.next()) {
qWarning() << QString("Could not execute query on \"%1\" to check if bic exists. Error: %2").arg(db.databaseName()).arg(query.lastError().text());
return bicAllocationUncertain;
}
if (query.value(0).toBool()) // Bic found
return bicAllocated;
// Bic not found, test if database is complete
if (services.first()->property(QLatin1String("X-KMyMoney-Bankdata-IsComplete"), QVariant::Bool).toBool())
return bicNotAllocated;
return bicAllocationUncertain;
}
示例12: openFilesWithDefaultApplication
void FileOperation::openFilesWithDefaultApplication(const QList<QUrl>& urls, QWidget* const parentWidget)
{
if (urls.isEmpty())
{
return;
}
// Create a map of service depending of type mimes to route and start only one instance of relevant application with all same type mime files.
QMap<KService::Ptr, QList<QUrl>> servicesMap;
foreach (const QUrl& url, urls)
{
const QString mimeType = QMimeDatabase().mimeTypeForFile(url.path(), QMimeDatabase::MatchExtension).name();
KService::List offers = KMimeTypeTrader::self()->query(mimeType, QLatin1String("Application"));
if (offers.isEmpty())
{
return;
}
KService::Ptr ptr = offers.first();
QMap<KService::Ptr, QList<QUrl>>::const_iterator it = servicesMap.constFind(ptr);
if (it != servicesMap.constEnd())
{
servicesMap[ptr] << url;
}
else
{
servicesMap.insert(ptr, QList<QUrl>() << url);
}
}
for (QMap<KService::Ptr, QList<QUrl>>::const_iterator it = servicesMap.constBegin();
it != servicesMap.constEnd(); ++it)
{
// Run the dedicated app to open the item.
#if KIO_VERSION < QT_VERSION_CHECK(5,6,0)
KRun::run(*it.key(), it.value(), parentWidget);
#else
KRun::runService(*it.key(), it.value(), parentWidget);
#endif
}
}
示例13: QString
QString ibanBicData::iban2Bic(const QString& iban)
{
Q_ASSERT(iban.length() < 1 || iban.at(0).isLetterOrNumber());
Q_ASSERT(iban.length() < 2 || iban.at(1).isLetterOrNumber());
Q_ASSERT(iban == payeeIdentifiers::ibanBic::ibanToElectronic(iban));
if (iban.length() <= 4) // This iban is to short to extract a BIC
return QString("");
// Get bank identifier
const QString bankCode = extractBankIdentifier(iban);
if (bankCode.isEmpty())
return bankCode; // keep .isEmpty() or .isNull()
// Get countryCode
const QString countryCode = iban.left(2);
// Get services which support iban2bic and have a database entry
KService::List services = KServiceTypeTrader::self()->query("KMyMoney/IbanBicData",
QString("(\'%1' ~in [X-KMyMoney-CountryCodes] or '*' in [X-KMyMoney-CountryCodes]) and true == [X-KMyMoney-IBAN-2-BIC-supported] and exist [X-KMyMoney-Bankdata-Database]").arg(countryCode)
);
if (services.isEmpty())
return QString();
QSqlDatabase db = createDatabaseConnection(services.first()->property(QLatin1String("X-KMyMoney-Bankdata-Database"), QVariant::String).toString());
if (!db.isOpen()) // This is an error
return QString();
QSqlQuery query = QSqlQuery(db);
query.prepare("SELECT bic FROM institutions WHERE bankcode=? and country=?");
query.bindValue(0, bankCode);
query.bindValue(1, countryCode);
if (!query.exec()) {
qWarning() << QString("Could not execute query on \"%1\" to receive BIC. Error: %2").arg(db.databaseName()).arg(query.lastError().text());
return QString();
}
if (query.next()) {
return query.value(0).toString();
}
return QString("");
}
示例14: readSaver
//---------------------------------------------------------------------------
//
// Read the command line needed to run the screensaver given a .desktop file.
//
void ScreenSaverWindow::readSaver()
{
if (!m_saver.isEmpty())
{
QString entryName = m_saver;
if( entryName.endsWith( QLatin1String( ".desktop" ) ))
entryName = entryName.left( entryName.length() - 8 ); // strip it
const KService::List offers = KServiceTypeTrader::self()->query( QLatin1String( "ScreenSaver" ),
QLatin1String( "DesktopEntryName == '" ) + entryName.toLower() + QLatin1Char( '\'' ) );
if( offers.isEmpty() )
{
kDebug(1204) << "Cannot find screesaver: " << m_saver;
return;
}
const QString file = KStandardDirs::locate("services", offers.first()->entryPath());
const bool opengl = KAuthorized::authorizeKAction(QLatin1String( "opengl_screensavers" ));
const bool manipulatescreen = KAuthorized::authorizeKAction(QLatin1String( "manipulatescreen_screensavers" ));
KDesktopFile config( file );
KConfigGroup desktopGroup = config.desktopGroup();
foreach (const QString &type, desktopGroup.readEntry("X-KDE-Type").split(QLatin1Char(';'))) {
if (type == QLatin1String("ManipulateScreen")) {
if (!manipulatescreen) {
kDebug(1204) << "Screensaver is type ManipulateScreen and ManipulateScreen is forbidden";
m_forbidden = true;
}
} else if (type == QLatin1String("OpenGL")) {
m_openGLVisual = true;
if (!opengl) {
kDebug(1204) << "Screensaver is type OpenGL and OpenGL is forbidden";
m_forbidden = true;
}
}
}
kDebug(1204) << "m_forbidden: " << (m_forbidden ? "true" : "false");
if (config.hasActionGroup(QLatin1String( "InWindow" )))
{
m_saverExec = config.actionGroup(QLatin1String( "InWindow" )).readPathEntry("Exec", QString());
}
}
示例15: kde_open
bool ClientApp::kde_open(const KUrl& url, const QString& mimeType, bool allowExec)
{
if ( mimeType.isEmpty() ) {
kDebug() << url;
KRun * run = new KRun( url, 0 );
run->setRunExecutables(allowExec);
QObject::connect( run, SIGNAL( finished() ), this, SLOT( delayedQuit() ));
QObject::connect( run, SIGNAL( error() ), this, SLOT( delayedQuit() ));
this->exec();
return !krun_has_error;
} else {
KUrl::List urls;
urls.append( url );
const KService::List offers = KMimeTypeTrader::self()->query(
mimeType, QLatin1String( "Application" ) );
if (offers.isEmpty()) return 1;
KService::Ptr serv = offers.first();
return KRun::run( *serv, urls, 0 );
}
}