void MenuentryActionWidget::selectApplicationClicked() { KOpenWithDialog dlg; dlg.exec(); KService::Ptr service = dlg.service(); if (service) { ui.application->setText( service->name() ); storage_id = service->storageId(); } }
ServiceButton::ServiceButton(const KService::Ptr &service, QWidget* parent) : PanelButton(parent, "ServiceButton"), _service(service), _id(service->storageId()) { if (_id.startsWith("/")) { QString tmp = KGlobal::dirs()->relativeLocation("appdata", _id); if (!tmp.startsWith("/")) _id = ":"+tmp; } initialize(); }
void MenuentryActionWidget::doCopyFromObject() { Q_ASSERT(action()); KService::Ptr service = action()->service(); if (service) { ui.application->setText( service->name() ); storage_id = service->storageId(); } else { ui.application->setText(QString()); storage_id = QString(); } }
QVariant FavoriteAppsModel::data(const QModelIndex &index, int role) const { KService::Ptr service = m_favoriteList.value(index.row()).service; if (service.isNull()) { return QVariant(); } if (role == Qt::DisplayRole) { return service->name(); } else if (role == Qt::DecorationRole) { return KIcon(service->icon()); } else if (role == FavoriteIdRole) { return QVariant("app:" + service->storageId()); } else { kWarning() << "Unhandled role" << role; return QVariant(); } }
Menuentry_shortcut_action_data *khotkeys_get_menu_entry_internal2(const Action_data_group *data_P, const QString &entry_P) { if(!data_P->enabled(false)) return NULL; for(Action_data_group::Iterator it = data_P->first_child(); it; ++it) { if(!(*it)->enabled(true)) continue; if(Menuentry_shortcut_action_data *entry = dynamic_cast< Menuentry_shortcut_action_data * >(*it)) { KService::Ptr service = entry->action() ? entry->action()->service() : KService::Ptr(0); if(service && (service->storageId() == entry_P)) return entry; } if(Action_data_group *group = dynamic_cast< Action_data_group * >(*it)) { Menuentry_shortcut_action_data *data = khotkeys_get_menu_entry_internal2(group, entry_P); if(data != NULL) return data; } } return NULL; }
void KSycocaDict::save(QDataStream &str) { if (count() == 0) { d->hashTableSize = 0; d->hashList.clear(); str << d->hashTableSize; str << d->hashList; return; } d->offset = str.device()->pos(); //qDebug() << "KSycocaDict:" << count() << "entries."; //qDebug() << "Calculating hash keys.."; int maxLength = 0; //qDebug() << "Finding maximum string length"; for(KSycocaDictStringList::const_iterator it = d->stringlist->constBegin(); it != d->stringlist->constEnd(); ++it) { string_entry* entry = *it; entry->hash = 0; if (entry->length > maxLength) maxLength = entry->length; } //qDebug() << "Max string length=" << maxLength << "existing hashList=" << d->hashList; // use "almost prime" number for sz (to calculate diversity) and later // for the table size of big tables // int sz = d->stringlist->count()*5-1; register unsigned int sz = count()*4 + 1; while(!(((sz % 3) && (sz % 5) && (sz % 7) && (sz % 11) && (sz % 13)))) sz+=2; d->hashList.clear(); // Times (with warm caches, i.e. after multiple runs) // kbuildsycoca5 --noincremental 2.83s user 0.20s system 95% cpu 3.187 total // kbuildsycoca5 --noincremental 2.74s user 0.25s system 93% cpu 3.205 total // unittest: 0.50-60 msec per iteration / 0.40-50 msec per iteration // Now that MimeTypes are not parsed anymore: // kbuildsycoca5 --noincremental 2.18s user 0.30s system 91% cpu 2.719 total // kbuildsycoca5 --noincremental 2.07s user 0.34s system 89% cpu 2.681 total // If I enabled s_maxItems = 50, it goes down to // but I don't know if that's a good idea. // kbuildsycoca5 --noincremental 1.73s user 0.31s system 85% cpu 2.397 total // kbuildsycoca5 --noincremental 1.84s user 0.29s system 95% cpu 2.230 total // try to limit diversity scan by "predicting" positions // with high diversity QVector<int> oldvec(maxLength*2+1); oldvec.fill(0); int mindiv=0; int lastDiv = 0; while(true) { int divsum=0,divnum=0; int maxDiv = 0; int maxPos = 0; for (int pos = -maxLength; pos <= maxLength; ++pos) { // cut off if (oldvec[pos+maxLength] < mindiv) { oldvec[pos+maxLength]=0; continue; } const int diversity = calcDiversity(d->stringlist, pos, sz); if (diversity > maxDiv) { maxDiv = diversity; maxPos = pos; } oldvec[pos + maxLength] = diversity; divsum += diversity; ++divnum; } // arbitrary cut-off value 3/4 of average seems to work if (divnum) mindiv=(3*divsum)/(4*divnum); if (maxDiv <= lastDiv) break; //qDebug() << "Max Div=" << maxDiv << "at pos" << maxPos; lastDiv = maxDiv; addDiversity(d->stringlist, maxPos); d->hashList.append(maxPos); } for(KSycocaDictStringList::Iterator it = d->stringlist->begin(); it != d->stringlist->end(); ++it) { (*it)->hash = d->hashKey((*it)->keyStr); } // fprintf(stderr, "Calculating minimum table size..\n"); d->hashTableSize = sz; //qDebug() << "hashTableSize=" << sz << "hashList=" << d->hashList << "oldvec=" << oldvec; struct hashtable_entry { string_entry *entry; QList<string_entry*>* duplicates; qint64 duplicate_offset; }; hashtable_entry *hashTable = new hashtable_entry[ sz ]; //qDebug() << "Clearing hashtable..."; for (unsigned int i=0; i < sz; i++) { hashTable[i].entry = 0; hashTable[i].duplicates = 0; } //qDebug() << "Filling hashtable..."; for(KSycocaDictStringList::const_iterator it = d->stringlist->constBegin(); it != d->stringlist->constEnd(); ++it) { string_entry* entry = *it; //qDebug() << "entry keyStr=" << entry->keyStr << entry->payload.data() << entry->payload->entryPath(); int hash = entry->hash % sz; if (!hashTable[hash].entry) { // First entry hashTable[hash].entry = entry; } else { if (!hashTable[hash].duplicates) { // Second entry, build duplicate list. hashTable[hash].duplicates = new QList<string_entry*>; hashTable[hash].duplicates->append(hashTable[hash].entry); hashTable[hash].duplicate_offset = 0; } hashTable[hash].duplicates->append(entry); } } str << d->hashTableSize; str << d->hashList; d->offset = str.device()->pos(); // d->offset points to start of hashTable //qDebug() << QString("Start of Hash Table, offset = %1").arg(d->offset,8,16); // Write the hashtable + the duplicates twice. // The duplicates are after the normal hashtable, but the offset of each // duplicate entry is written into the normal hashtable. for(int pass = 1; pass <= 2; pass++) { str.device()->seek(d->offset); //qDebug() << QString("Writing hash table (pass #%1)").arg(pass); for(uint i=0; i < d->hashTableSize; i++) { qint32 tmpid; if (!hashTable[i].entry) tmpid = (qint32) 0; else if (!hashTable[i].duplicates) tmpid = (qint32) hashTable[i].entry->payload->offset(); // Positive ID else tmpid = (qint32) -hashTable[i].duplicate_offset; // Negative ID str << tmpid; //qDebug() << QString("Hash table : %1").arg(tmpid,8,16); } //qDebug() << QString("End of Hash Table, offset = %1").arg(str.device()->at(),8,16); //qDebug() << QString("Writing duplicate lists (pass #%1)").arg(pass); for(uint i=0; i < d->hashTableSize; i++) { const QList<string_entry*> *dups = hashTable[i].duplicates; if (dups) { hashTable[i].duplicate_offset = str.device()->pos(); /*qDebug() << QString("Duplicate lists: Offset = %1 list_size = %2") .arg(hashTable[i].duplicate_offset,8,16).arg(dups->count()); */ for(QList<string_entry*>::ConstIterator dup = dups->begin(); dup != dups->end(); ++dup) { const qint32 offset = (*dup)->payload->offset(); if (!offset) { const QString storageId = (*dup)->payload->storageId(); qDebug() << "about to assert! dict=" << this << "storageId=" << storageId << (*dup)->payload.data(); if ((*dup)->payload->isType(KST_KService)) { KService::Ptr service = KService::Ptr::staticCast((*dup)->payload); qDebug() << service->storageId() << service->entryPath(); } // save() must have been called on the entry Q_ASSERT_X( offset, "KSycocaDict::save", QByteArray("entry offset is 0, save() was not called on " + (*dup)->payload->storageId().toLatin1() + " entryPath=" + (*dup)->payload->entryPath().toLatin1()) ); } str << offset ; // Positive ID str << (*dup)->keyStr; // Key (QString) } str << (qint32) 0; // End of list marker (0) } } //qDebug() << QString("End of Dict, offset = %1").arg(str.device()->at(),8,16); } //qDebug() << "Cleaning up hash table."; for(uint i=0; i < d->hashTableSize; i++) { delete hashTable[i].duplicates; } delete [] hashTable; }
ContainmentActions *PluginLoader::loadContainmentActions(Containment *parent, const QString &name, const QVariantList &args) { if (name.isEmpty()) { return 0; } ContainmentActions *actions = d->isDefaultLoader ? 0 : internalLoadContainmentActions(parent, name, args); if (actions) { return actions; } // Look for C++ plugins first auto filter = [&name](const KPluginMetaData &md) -> bool { return md.pluginId() == name; }; QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_containmentActionsPluginDir, filter); if (plugins.count()) { KPluginInfo::List lst = KPluginInfo::fromMetaData(plugins); KPluginLoader loader(lst.first().libraryPath()); const QVariantList argsWithMetaData = QVariantList() << loader.metaData().toVariantMap(); KPluginFactory *factory = loader.factory(); if (factory) { actions = factory->create<Plasma::ContainmentActions>(0, argsWithMetaData); } } if (actions) { return actions; } //FIXME: this is only for backwards compatibility, but probably will have to stay //for the time being QString constraint = QStringLiteral("[X-KDE-PluginInfo-Name] == '%1'").arg(name); KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("Plasma/ContainmentActions"), constraint); if (offers.isEmpty()) { #ifndef NDEBUG qCDebug(LOG_PLASMA) << "offers is empty for " << name; #endif return 0; } KService::Ptr offer = offers.first(); KPluginLoader plugin(*offer); if (!Plasma::isPluginVersionCompatible(plugin.pluginVersion())) { return 0; } QVariantList allArgs; allArgs << offer->storageId() << args; QString error; actions = offer->createInstance<Plasma::ContainmentActions>(parent, allArgs, &error); if (!actions) { #ifndef NDEBUG // qCDebug(LOG_PLASMA) << "Couldn't load containmentActions \"" << name << "\"! reason given: " << error; #endif } return actions; }