void Configuration::setServiceMenu()
{
    KMenu *menu = qobject_cast<KMenu*>(sender());

    if (menu->actions().count() > 1)
    {
        return;
    }

    KServiceGroup::Ptr rootGroup = KServiceGroup::group(menu->actions()[0]->data().toString());

    if (!rootGroup || !rootGroup->isValid() || rootGroup->noDisplay())
    {
        return;
    }

    KServiceGroup::List list = rootGroup->entries(true, true, true, true);

    QAction *action = menu->addAction(KIcon("list-add"), i18n("Add This Menu"));
    action->setData(rootGroup->relPath());

    menu->addSeparator();

    for (int i = 0; i < list.count(); ++i)
    {
        if (list.at(i)->isType(KST_KService))
        {
            const KService::Ptr service = KService::Ptr::staticCast(list.at(i));

            action = menu->addAction(KIcon(service->icon()), service->name());
            action->setEnabled(false);
        }
        else if (list.at(i)->isType(KST_KServiceGroup))
        {
            const KServiceGroup::Ptr group = KServiceGroup::Ptr::staticCast(list.at(i));

            if (group->noDisplay() || group->childCount() == 0)
            {
                continue;
            }

            KMenu *subMenu = new KMenu(menu);

            QAction *action = subMenu->addAction(QString());
            action->setData(group->relPath());
            action->setVisible(false);

            action = menu->addAction(KIcon(group->icon()), group->caption());
            action->setMenu(subMenu);

            connect(subMenu, SIGNAL(aboutToShow()), this, SLOT(setServiceMenu()));
        }
        else if (list.at(i)->isType(KST_KServiceSeparator))
        {
            menu->addSeparator();
        }
    }
}
Exemplo n.º 2
0
void
KCustomMenuEditor::load(KConfigBase *cfg)
{
   cfg->setGroup(QString::null);
   int count = cfg->readNumEntry("NrOfItems");
   QListViewItem *last = 0;
   for(int i = 0; i < count; i++)
   {
      QString entry = cfg->readPathEntry(QString("Item%1").arg(i+1));
      if (entry.isEmpty())
         continue;

      // Try KSycoca first.
      KService::Ptr menuItem = KService::serviceByDesktopPath( entry );
      if (!menuItem)
         menuItem = KService::serviceByDesktopName( entry );
      if (!menuItem)
         menuItem = new KService( entry );

      if (!menuItem->isValid())
         continue;

      QListViewItem *item = new Item(m_listView, menuItem);
      item->moveItem(last);
      last = item;
   }
}
Exemplo n.º 3
0
void BasicTab::slotCapturedShortcut(const KShortcut &cut)
{
    if(signalsBlocked())
        return;

    if(KKeyChooser::checkGlobalShortcutsConflict(cut, true, topLevelWidget())
       || KKeyChooser::checkStandardShortcutsConflict(cut, true, topLevelWidget()))
        return;

    if(KHotKeys::present())
    {
        if(!_menuEntryInfo->isShortcutAvailable(cut))
        {
            KService::Ptr service;
            emit findServiceShortcut(cut, service);
            if(!service)
                service = KHotKeys::findMenuEntry(cut.toString());
            if(service)
            {
                KMessageBox::sorry(this, i18n("<qt>The key <b>%1</b> can not be used here because it is already used to activate <b>%2</b>.")
                                             .arg(cut.toString(), service->name()));
                return;
            }
            else
            {
                KMessageBox::sorry(this, i18n("<qt>The key <b>%1</b> can not be used here because it is already in use.").arg(cut.toString()));
                return;
            }
        }
        _menuEntryInfo->setShortcut(cut);
    }
    _keyEdit->setShortcut(cut, false);
    if(_menuEntryInfo)
        emit changed(_menuEntryInfo);
}
Exemplo n.º 4
0
KTextEditor::Editor *EditorChooser::createEditor(QWidget *parentWidget, QObject *parent, const char *widgetName, const char *name,
                                                 const QString &postfix, bool fallBackToKatePart)
{

    KTextEditor::Editor *tmpEd = 0;

    KConfig *cfg = kapp->config();
    QString previousGroup = cfg->group();
    cfg->setGroup("KTEXTEDITOR:" + postfix);
    QString editor = cfg->readPathEntry("editor");
    cfg->setGroup(previousGroup);
    if(editor.isEmpty())
    {
        KConfig *config = new KConfig("default_components");
        config->setGroup("KTextEditor");
        editor = config->readPathEntry("embeddedEditor", "katepart");
        delete config;
    }

    KService::Ptr serv = KService::serviceByDesktopName(editor);
    if(serv)
    {
        tmpEd = KTextEditor::createEditor(serv->library().latin1(), parentWidget, widgetName, parent, name);
        if(tmpEd)
            return tmpEd;
    }
    if(fallBackToKatePart)
        return KTextEditor::createEditor("libkatepart", parentWidget, widgetName, parent, name);

    return 0;
}
Exemplo n.º 5
0
DVBevents::DVBevents( QString devType, int anum, int tnum, const QString &charset, EventTable *table )
	: KaffeineDVBsection( anum, tnum, charset )
{
	events = table;
	KaffeineEpgPlugin *plug;
	QString plugName;
	int error;

	KTrader::OfferList offers = KTrader::self()->query("KaffeineEpgPlugin");
	KTrader::OfferList::Iterator end( offers.end() );
	for ( KTrader::OfferList::Iterator it=offers.begin(); it!=end; ++it ) {
		error = 0;
		KService::Ptr ptr = (*it);
		if ( !ptr->name().contains(devType) )
			continue;
		plug = KParts::ComponentFactory::createPartInstanceFromService<KaffeineEpgPlugin>(ptr, 0, ptr->name().ascii(), 0, 0, 0, &error );
		plugName = ptr->desktopEntryName();
		if (error > 0) {
			fprintf( stderr, "Loading of EPG plugin %s failed: %s\n", plugName.ascii(), KLibLoader::self()->lastErrorMessage().ascii() );
			plug = NULL;
		}
		else {
			plugs.append( plug );
			plug->setTable( table );
			plug->initSection( anum, tnum, charset );
			plugNames.append( plugName );
		}
	}
	fprintf( stderr, "%d EPG plugins loaded for device %d:%d.\n", plugs.count(), anum, tnum );
}
void AdminDatabase::queryButtonClicked()
{
	if ( ! m_listView->currentItem() )
		return;
	
	QVBox *widget = new QVBox(this);

	KTrader::OfferList offers = KTrader::self()->query("text/plain", "'KParts/ReadOnlyPart' in ServiceTypes");
	
	KLibFactory *factory = 0;

	KTrader::OfferList::Iterator it(offers.begin());
	for( ; it != offers.end(); ++it)
	{
		KService::Ptr ptr = (*it);
		factory = KLibLoader::self()->factory( ptr->library() );
		if (factory)
		{
			m_part = static_cast<KParts::ReadOnlyPart *>(factory->create(widget, ptr->name(), "KParts::ReadOnlyPart"));
			m_part->openURL("file://"+m_dumpDir->absPath()+"/"+m_listView->getText(0)+".sql");
			break;
		}
	}
	
	if (!factory)
	{
		KMessageBox::error(this, i18n("Could not find a suitable  component"));
		return;
	}
	
	emit sendWidget(widget,i18n("View dump")); 
}
Exemplo n.º 7
0
void PluginManager::loadPlugins()
{
    KService::List offers = KServiceTypeTrader::self()->query(QLatin1String("KTpAccountsKCM/AccountUiPlugin"));

    KService::List::const_iterator iter;
    for (iter = offers.constBegin(); iter < offers.constEnd(); ++iter) {
       QString error;
       KService::Ptr service = *iter;

        KPluginFactory *factory = KPluginLoader(service->library()).factory();

        if (!factory) {
            qWarning() << "KPluginFactory could not load the plugin:" << service->library();
            continue;
        }

       AbstractAccountUiPlugin *plugin = factory->create<AbstractAccountUiPlugin>(this);

       if (plugin) {
           qDebug() << "Loaded plugin:" << service->name();
           m_plugins.append(plugin);
       } else {
           qDebug() << error;
       }
    }
}
Exemplo n.º 8
0
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;
}
Exemplo n.º 9
0
    void addRecentApplication(KService::Ptr service, bool append) {
        // remove existing item if any
        if (removeExistingItem(service->entryPath())) {
            --recentApplicationCount;
        }

        QStandardItem *appItem = StandardItemFactory::createItemForService(service, displayOrder);
        appItem->setData(applicationTitle, Kickoff::GroupNameRole);
        itemsByPath.insert(service->entryPath(), appItem);

        if (append) {
            q->insertRow(recentApplicationCount, appItem);
        } else {
            q->insertRow(0, appItem);
        }
        ++recentApplicationCount;

        while (recentApplicationCount > maxRecentApps) {
            --recentApplicationCount;
            QList<QStandardItem*> row = q->takeRow(recentApplicationCount);

            //don't leave pending stuff in itemsByPath
            if (!row.isEmpty()) {
                itemsByPath.remove(row.first()->data(UrlRole).toString());
                qDeleteAll(row.begin(), row.end());
            }
        }
    }
Exemplo n.º 10
0
QVariant RecentAppsModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid() || index.row() >= m_recentApps.count()) {
        return QVariant();
    }

    const QString storageId = m_recentApps.at(index.row());
    KService::Ptr service = KService::serviceByStorageId(storageId);

    if (!service) {
        return QVariant();
    }

    if (role == Qt::DisplayRole) {
        return service->name();
    } else if (role == Qt::DecorationRole) {
        return QIcon::fromTheme(service->icon(), QIcon::fromTheme("unknown"));
    } else if (role == Kicker::FavoriteIdRole) {
        return QVariant("app:" + storageId);
    } else if (role == Kicker::HasActionListRole) {
        return true;
    } else if (role == Kicker::ActionListRole) {
        QVariantList actionList;

        const QVariantMap &forgetAction = Kicker::createActionItem(i18n("Forget Application"), "forget");
        actionList.append(forgetAction);

        const QVariantMap &forgetAllAction = Kicker::createActionItem(i18n("Forget All Applications"), "forgetAll");
        actionList.append(forgetAllAction);

        return actionList;
    }

    return QVariant();
}
Exemplo n.º 11
0
MainWindow::MainWindow(KTextEditor::Document* doc)
    : document(0),
      view(0)
{
    if(!doc) {
        KTextEditor::Editor* editor = NULL;
        KService::Ptr serv = KService::serviceByDesktopName("yzispart");

        if(!serv) {
            KMessageBox::error(this, "Could not find yzispart!");
            kapp->exit(-1);
        } else {
            editor = KTextEditor::editor(serv->library().toLatin1());

            if(!editor) {
                KMessageBox::error(this, "Could not create yziskpart editor component");
                kapp->exit(-1);
            }
        }

        document = editor->createDocument(0);
    } else {
        document = doc;
    }

    view = qobject_cast< KTextEditor::View* >(document->createView(this));
    setCentralWidget(view);
    guiFactory()->addClient(view);
    show();
}
Exemplo n.º 12
0
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;
}
Exemplo n.º 13
0
void SettingsBase::initApplication()
{
    // Prepare the menu of all modules
    categories = KServiceTypeTrader::self()->query("SystemSettingsCategory");
    modules = KServiceTypeTrader::self()->query("KCModule", "[X-KDE-System-Settings-Parent-Category] != ''");
    modules += KServiceTypeTrader::self()->query("SystemSettingsExternalApp");
    rootModule = new MenuItem( true, 0 );
    initMenuList(rootModule);
    // Handle lost+found modules...
    if (lostFound) {
        for (int i = 0; i < modules.size(); ++i) {
            const KService::Ptr entry = modules.at(i);
            MenuItem * infoItem = new MenuItem(false, lostFound);
            infoItem->setService( entry );
            qDebug() << "Added " << entry->name();
        }
    }

    // Prepare the Base Data
    BaseData::instance()->setMenuItem( rootModule );
    // Load all possible views
    const KService::List pluginObjects = KServiceTypeTrader::self()->query( "SystemSettingsView" );
    const int nbPlugins = pluginObjects.count();
    for( int pluginsDone = 0; pluginsDone < nbPlugins ; ++pluginsDone ) {
        KService::Ptr activeService = pluginObjects.at( pluginsDone );
        QString error;
        BaseMode * controller = activeService->createInstance<BaseMode>(this, QVariantList(), &error);
        if( error.isEmpty() ) {
            possibleViews.insert( activeService->library(), controller );
            controller->init( activeService );
            connect(controller, SIGNAL(changeToolBarItems(BaseMode::ToolBarItems)), this, SLOT(changeToolBar(BaseMode::ToolBarItems)));
            connect(controller, SIGNAL(actionsChanged()), this, SLOT(updateViewActions()));
            connect(searchText, SIGNAL(textChanged(QString)), controller, SLOT(searchChanged(QString)));
            connect(controller, SIGNAL(viewChanged(bool)), this, SLOT(viewChange(bool)));
        } else {
Exemplo n.º 14
0
bool Helper::handleAppsDialog()
    {
    if( !readArguments( 1 ))
        return false;
    QString title = getArgument();
    long wid = getArgumentParent();
    if( !allArgumentsUsed())
        return false;
    KOpenWithDialog dialog( NULL );
    if( !title.isEmpty())
        dialog.setWindowTitle( title );
    dialog.hideNoCloseOnExit();
    dialog.hideRunInTerminal(); // TODO
    if( wid != 0 )
        KWindowSystem::setMainWindow( &dialog, wid );
    if( dialog.exec())
        {
        KService::Ptr service = dialog.service();
        QString command;
        if( service )
            command = service->exec();
        else if( !dialog.text().isEmpty())
            command = dialog.text();
        else
            return false;
        command = command.split( " " ).first(); // only the actual command
        command = QStandardPaths::findExecutable(command);
        if( command.isEmpty())
            return false;
        outputLine( QUrl::fromUserInput( command ).url());
        return true;
        }
    return false;
    }
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;
}
Exemplo n.º 16
0
PluginData PluginLoader::instantiatePluginForDevice(const QString& name, Device* device) const
{
    PluginData ret;

    KService::Ptr service = plugins[name];
    if (!service) {
        kDebug(kdeconnect_kded()) << "Plugin unknown" << name;
        return ret;
    }

    KPluginFactory *factory = KPluginLoader(service->library()).factory();
    if (!factory) {
        kDebug(kdeconnect_kded()) << "KPluginFactory could not load the plugin:" << service->library();
        return ret;
    }

    ret.interfaces = service->property("X-KdeConnect-SupportedPackageType", QVariant::StringList).toStringList();

    QVariant deviceVariant = QVariant::fromValue<Device*>(device);

    //FIXME any reason to use QObject in template param instead KdeConnectPlugin?
    ret.plugin = factory->create<KdeConnectPlugin>(device, QVariantList() << deviceVariant);
    if (!ret.plugin) {
        kDebug(kdeconnect_kded()) << "Error loading plugin";
        return ret;
    }

    kDebug(kdeconnect_kded()) << "Loaded plugin:" << service->name();
    return ret;
}
Exemplo n.º 17
0
void FavoriteAppsModel::addFavorite(const QString &favoriteId)
{
    QString serviceId = serviceIdFromFavoriteId(favoriteId);
    if (serviceId.isEmpty()) {
        return;
    }
    KService::Ptr service = KService::serviceByStorageId(serviceId);
    if (service.isNull()) {
        kWarning() << "Could not find a service for" << serviceId;
        return;
    }
    int rank;
    if (!m_favoriteList.isEmpty()) {
        rank = m_favoriteList.last().rank + 1;
    } else {
        rank = 0;
    }
    FavoriteInfo info = { rank, service };

    int row = m_favoriteList.count();
    beginInsertRows(QModelIndex(), row, row);
    m_favoriteList << info;
    endInsertRows();
    countChanged();

    KConfigGroup baseGroup(m_config, "favorites");
    KConfigGroup group(&baseGroup, QString("favorite-%1").arg(rank));
    group.writeEntry("serviceId", serviceId);
    baseGroup.sync();
}
Exemplo n.º 18
0
void FavoriteAppsModel::setConfig(const KSharedConfig::Ptr &ptr)
{
    m_config = ptr;

    KConfigGroup baseGroup(m_config, "favorites");

    // get all the favorites
    QMap<int, KService::Ptr> favoriteMap;
    foreach (const QString &favoriteGroup, baseGroup.groupList()) {
        if (favoriteGroup.startsWith("favorite-")) {
            KConfigGroup favoriteConfig(&baseGroup, favoriteGroup);
            int rank = favoriteGroup.split("-").last().toInt();
            QString id = favoriteConfig.readEntry("serviceId");
            KService::Ptr service = KService::serviceByStorageId(id);
            if (!service.isNull()) {
                favoriteMap.insert(rank, service);
            }
        }
    }

    beginResetModel();
    m_favoriteList.clear();
    auto it = favoriteMap.constBegin(), end = favoriteMap.constEnd();
    for (; it != end; ++it) {
        FavoriteInfo info = { it.key(), it.value() };
        m_favoriteList << info;
    }
    endResetModel();
    countChanged();
}
Exemplo n.º 19
0
QString KProtocolInfo::exec(const QString& protocol)
{
  KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(protocol);

  // We have up to two sources of data:
  // 1) the exec line of the .protocol file, if there's one (could be a kioslave or a helper app)
  // 2) the application associated with x-scheme-handler/<protocol> if there's one

  // If both exist, then:
  //  A) if the .protocol file says "launch an application", then the new-style handler-app has priority
  //  B) but if the .protocol file is for a kioslave (e.g. kio_http) then this has priority over
  //     firefox or chromium saying x-scheme-handler/http. Gnome people want to send all HTTP urls
  //     to a webbrowser, but we want mimetype-determination-in-calling-application by default
  //     (the user can configure a BrowserApplication though)

  QString helperExe;
  const KService::Ptr service = KMimeTypeTrader::self()->preferredService(QString::fromLatin1("x-scheme-handler/") + protocol);
  if (service) {
      helperExe = service->exec();
      if (prot && prot->m_isHelperProtocol)
          return helperExe; // for helper protocols, the handler app has priority over the hardcoded one (see A above)
  }
  if (prot) {
      return prot->m_exec;
  }

  // If there's no protocol file, then return the handler app if any, otherwise empty string
  return helperExe;
}
Exemplo n.º 20
0
void KateFileTree::slotFixOpenWithMenu()
{
  QMenu *menu = (QMenu*)sender();
  menu->clear();
  
   KTextEditor::Document *doc = model()->data(m_indexContextMenu, KateFileTreeModel::DocumentRole).value<KTextEditor::Document *>();
  if (!doc) return;

  // get a list of appropriate services.
  KMimeType::Ptr mime = KMimeType::mimeType(doc->mimeType());
  //kDebug(13001) << "mime type: " << mime->name();

  QAction *a = 0;
  KService::List offers = KMimeTypeTrader::self()->query(mime->name(), "Application");
  // for each one, insert a menu item...
  for(KService::List::Iterator it = offers.begin(); it != offers.end(); ++it)
  {
    KService::Ptr service = *it;
    if (service->name() == "Kate") continue;
    a = menu->addAction(KIcon(service->icon()), service->name());
    a->setData(service->entryPath());
  }
  // append "Other..." to call the KDE "open with" dialog.
  a = menu->addAction(i18n("&Other..."));
  a->setData(QString());
}
Exemplo n.º 21
0
void ApplicationsProtocol::stat(const KUrl& url)
{
    KIO::UDSEntry entry;

    QString servicePath( url.path( KUrl::AddTrailingSlash ) );
    servicePath.remove(0, 1); // remove starting '/'

    KServiceGroup::Ptr grp = KServiceGroup::group(servicePath);

    if (grp && grp->isValid()) {
        createDirEntry(entry, ((m_runMode==ApplicationsMode) ? i18n("Applications") : i18n("Programs")),
                       url.url(), "inode/directory",grp->icon() );
    } else {
        KService::Ptr service = KService::serviceByDesktopName( url.fileName() );
        if (service && service->isValid()) {
            createFileEntry(entry, service, url );
        } else {
            error(KIO::ERR_SLAVE_DEFINED,i18n("Unknown application folder"));
            return;
        }
    }

    statEntry(entry);
    finished();
}
Exemplo n.º 22
0
 DesktopBehaviorPreviewItem(DesktopBehavior *rootOpts, QListView *parent,
             const KService::Ptr &plugin, bool on)
     : QCheckListItem(parent, plugin->name(), CheckBox),
       m_rootOpts(rootOpts)
 {
     m_pluginName = plugin->desktopEntryName();
     setOn(on);
 }
Exemplo n.º 23
0
PluginLoader::PluginLoader()
{
    KService::List offers = KServiceTypeTrader::self()->query("KdeConnect/Plugin");
    for(KService::List::const_iterator iter = offers.constBegin(); iter != offers.constEnd(); ++iter) {
        KService::Ptr service = *iter;
        plugins[service->library()] = service;
    }
}
Exemplo n.º 24
0
void NavigatorAppItem::populate(bool recursive)
{
    if(mPopulated)
        return;

    KServiceGroup::Ptr root = KServiceGroup::group(mRelpath);
    if(!root)
    {
        kdWarning() << "No Service groups\n";
        return;
    }
    KServiceGroup::List list = root->entries();


    for(KServiceGroup::List::ConstIterator it = list.begin(); it != list.end(); ++it)
    {
        KSycocaEntry *e = *it;
        KService::Ptr s;
        NavigatorItem *item;
        KServiceGroup::Ptr g;
        QString url;

        switch(e->sycocaType())
        {
            case KST_KService:
            {
                s = static_cast< KService * >(e);
                url = documentationURL(s);
                if(!url.isEmpty())
                {
                    DocEntry *entry = new DocEntry(s->name(), url, s->icon());
                    item = new NavigatorItem(entry, this);
                    item->setAutoDeleteDocEntry(true);
                    item->setExpandable(true);
                }
                break;
            }
            case KST_KServiceGroup:
            {
                g = static_cast< KServiceGroup * >(e);
                if((g->childCount() == 0) || g->name().startsWith("."))
                    continue;
                DocEntry *entry = new DocEntry(g->caption(), "", g->icon());
                NavigatorAppItem *appItem;
                appItem = new NavigatorAppItem(entry, this, g->relPath());
                appItem->setAutoDeleteDocEntry(true);
                if(recursive)
                    appItem->populate(recursive);
                break;
            }
            default:
                break;
        }
    }
    sortChildItems(0, true /* ascending */);
    mPopulated = true;
}
Exemplo n.º 25
0
bool FavoriteAppsModel::trigger(int row)
{
    KService::Ptr service = m_favoriteList.value(row).service;
    if (service.isNull()) {
        kWarning() << "Invalid row";
        return false;
    }
    return KRun::run(*service, KUrl::List(), 0);
}
Exemplo n.º 26
0
SearchProvider::SearchProvider(const KService::Ptr service)
               : m_dirty(false)
{
    m_desktopEntryName = service->desktopEntryName();
    m_name = service->name();
    m_query = service->property("Query").toString();
    m_keys = service->property("Keys").toStringList();
    m_charset = service->property("Charset").toString();
}
Exemplo n.º 27
0
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() );
}
Exemplo n.º 28
0
void KMimeTypeTest::testPreferredService()
{
    // The "NotShowIn=KDE" service should not be the preferred one!
    KService::Ptr serv = KMimeTypeTrader::self()->preferredService("text/plain");
    QVERIFY(serv);
    qDebug() << serv->entryPath();
    QVERIFY(serv->entryPath() != m_nonKdeApp);
    QCOMPARE(serv->entryPath(), m_textPlainApp);
}
Exemplo n.º 29
0
ksimoptsView::ksimoptsView(QWidget *parent)
    : QWidget(parent),
      DCOPObject("ksimoptsIface")
{
    // setup our layout manager to automatically add our widgets
    QHBoxLayout *top_layout = new QHBoxLayout(this);
    top_layout->setAutoAdd(true);

    // we want to look for all components that satisfy our needs.  the
    // trader will actually search through *all* registered KDE
    // applications and components -- not just KParts.  So we have to
    // specify two things: a service type and a constraint
    //
    // the service type is like a mime type.  we say that we want all
    // applications and components that can handle HTML -- 'text/html'
    //
    // however, by itself, this will return such things as Netscape..
    // not what we wanted.  so we constrain it by saying that the
    // string 'KParts/ReadOnlyPart' must be found in the ServiceTypes
    // field.  with this, only components of the type we want will be
    // returned.
    KTrader::OfferList offers = KTrader::self()->query("text/html", "'KParts/ReadWritePart' in ServiceTypes");

    KLibFactory *factory = 0;
    // in theory, we only care about the first one.. but let's try all
    // offers just in case the first can't be loaded for some reason
    KTrader::OfferList::Iterator it(offers.begin());
    for( ; it != offers.end(); ++it)
    {
        KService::Ptr ptr = (*it);

        // we now know that our offer can handle HTML and is a part.
        // since it is a part, it must also have a library... let's try to
        // load that now
        factory = KLibLoader::self()->factory( ptr->library() );
        if (factory)
        {
            m_html = static_cast<KParts::ReadWritePart *>(factory->create(this, ptr->name(), "KParts::ReadWritePart"));
            break;
        }
    }

    // if our factory is invalid, then we never found our component
    // and we might as well just exit now
    if (!factory)
    {
        KMessageBox::error(this, i18n("Could not find a suitable HTML component"));
        return;
    }

    connect(m_html, SIGNAL(setWindowCaption(const QString&)),
            this,   SLOT(slotSetTitle(const QString&)));
    connect(m_html, SIGNAL(setStatusBarText(const QString&)),
            this,   SLOT(slotOnURL(const QString&)));

}
void ExtensionMgr::loadExtension(const QString& name) {
  KService::List sl = KServiceType::offers("Kst Extension");
  for (KService::List::ConstIterator it = sl.begin(); it != sl.end(); ++it) {
    KService::Ptr service = *it;
    if (name == service->property("Name").toString()) {
      loadExtension(service);
      return;
    }
  }
}