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();
        }
    }
}
예제 #2
0
QString KURIFilterData::iconName()
{
    if(m_bChanged)
    {
        switch(m_iType)
        {
            case KURIFilterData::LOCAL_FILE:
            case KURIFilterData::LOCAL_DIR:
            case KURIFilterData::NET_PROTOCOL:
            {
                m_strIconName = KMimeType::iconForURL(m_pURI);
                break;
            }
            case KURIFilterData::EXECUTABLE:
            {
                QString exeName = m_pURI.url();
                exeName = exeName.mid(exeName.findRev('/') + 1); // strip path if given
                KService::Ptr service = KService::serviceByDesktopName(exeName);
                if(service && service->icon() != QString::fromLatin1("unknown"))
                    m_strIconName = service->icon();
                // Try to find an icon with the same name as the binary (useful for non-kde apps)
                else if(!KGlobal::iconLoader()->loadIcon(exeName, KIcon::NoGroup, 16, KIcon::DefaultState, 0, true).isNull())
                    m_strIconName = exeName;
                else
                    // not found, use default
                    m_strIconName = QString::fromLatin1("exec");
                break;
            }
            case KURIFilterData::HELP:
            {
                m_strIconName = QString::fromLatin1("khelpcenter");
                break;
            }
            case KURIFilterData::SHELL:
            {
                m_strIconName = QString::fromLatin1("konsole");
                break;
            }
            case KURIFilterData::ERROR:
            case KURIFilterData::BLOCKED:
            {
                m_strIconName = QString::fromLatin1("error");
                break;
            }
            default:
                m_strIconName = QString::null;
                break;
        }
        m_bChanged = false;
    }
    return m_strIconName;
}
예제 #3
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();
}
예제 #4
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());
}
예제 #5
0
AppEntry::AppEntry(KService::Ptr service, const QString &name)
: m_service(service)
{
    m_name = name;
    m_icon = QIcon::fromTheme(service->icon(), QIcon::fromTheme("unknown"));
    m_service = service;
}
예제 #6
0
KPluginInfo::KPluginInfo( const KService::Ptr service )
: d( new KPluginInfoPrivate )
{
    if (!service) {
        d = 0; // isValid() == false
        return;
    }
    d->service = service;
    d->entryPath = service->entryPath();

    if ( service->isDeleted() )
    {
        d->hidden = true;
        return;
    }

    d->name = service->name();
    d->comment = service->comment();
    d->icon = service->icon();
    d->author = service->property( QLatin1String("X-KDE-PluginInfo-Author") ).toString();
    d->email = service->property( QLatin1String("X-KDE-PluginInfo-Email") ).toString();
    d->pluginName = service->property( QLatin1String("X-KDE-PluginInfo-Name") ).toString();
    d->version = service->property( QLatin1String("X-KDE-PluginInfo-Version") ).toString();
    d->website = service->property( QLatin1String("X-KDE-PluginInfo-Website") ).toString();
    d->category = service->property( QLatin1String("X-KDE-PluginInfo-Category") ).toString();
    d->license = service->property( QLatin1String("X-KDE-PluginInfo-License") ).toString();
    d->dependencies =
        service->property( QLatin1String("X-KDE-PluginInfo-Depends") ).toStringList();
    QVariant tmp = service->property( QLatin1String("X-KDE-PluginInfo-EnabledByDefault") );
    d->enabledbydefault = tmp.isValid() ? tmp.toBool() : false;
}
예제 #7
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;
}
예제 #8
0
static void createFileEntry(KIO::UDSEntry& entry, const KService::Ptr& service, const KUrl& parentUrl)
{
    entry.clear();
    entry.insert(KIO::UDSEntry::UDS_NAME, KIO::encodeFileName(service->name()));
    entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFREG);
    const QString fileUrl = parentUrl.url(KUrl::AddTrailingSlash) + service->desktopEntryName();
    entry.insert(KIO::UDSEntry::UDS_URL, fileUrl);
    entry.insert(KIO::UDSEntry::UDS_ACCESS, 0500);
    entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, "application/x-desktop");
    entry.insert(KIO::UDSEntry::UDS_SIZE, 0);
    entry.insert(KIO::UDSEntry::UDS_LOCAL_PATH, KStandardDirs::locate("apps", service->entryPath()));
    entry.insert(KIO::UDSEntry::UDS_MODIFICATION_TIME, time(0));
    entry.insert(KIO::UDSEntry::UDS_ICON_NAME, service->icon());
}
예제 #9
0
void NavigatorAppItem::populate( bool recursive )
{
  if ( mPopulated ) return;

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


  for ( KServiceGroup::List::ConstIterator it = list.constBegin();
        it != list.constEnd(); ++it )
  {
    const KSycocaEntry::Ptr e = *it;
    NavigatorItem *item;
    QString url;

    switch ( e->sycocaType() ) {
      case KST_KService:
      {
        const KService::Ptr s = KService::Ptr::staticCast(e);
        url = documentationURL( s.data() );
        if ( !url.isEmpty() ) {
          DocEntry *entry = new DocEntry( s->name(), url, s->icon() );
          item = new NavigatorItem( entry, this );
          item->setAutoDeleteDocEntry( true );
        }
        break;
      }
      case KST_KServiceGroup:
      {
        KServiceGroup::Ptr g = KServiceGroup::Ptr::staticCast(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;
    }
  }
  sortChildren( 0, Qt::AscendingOrder /* ascending */ );
  mPopulated = true;
}
예제 #10
0
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();
    }
}
예제 #11
0
void QuickLauncher::serviceStartedByStorageId(TQString /*starter*/, TQString storageId)
{
    KService::Ptr service = KService::serviceByStorageId(storageId);
    if (service->icon() == TQString::null) 
    {
        kdDebug() << storageId << " has no icon. Makes no sense to add it.";
        return;
    }
    QuickURL url = QuickURL(locate("apps", service->desktopEntryPath()));
    TQString desktopMenuId(url.menuId());
    kdDebug() << "storageId=" << storageId << " desktopURL=" << desktopMenuId << endl;
    // A service was started somwhere else. If the quicklauncher contains
    // this service too, we flash the icon
    QuickButton *startedButton = 0;
    std::set<TQString> buttonIdSet;
    for (uint n = 0; n < m_buttons->size(); ++n)
    {
        QuickButton *button = (*m_buttons)[n];
        TQString buttonMenuId = button->menuId();
        buttonIdSet.insert(buttonMenuId);
        if (desktopMenuId == buttonMenuId)
        {
           kdDebug() << "QuickLauncher: I know that one: " << storageId << endl;
           button->flash();
           startedButton = button;
        }
    }

    // Update popularity info.
    // We do this even if autoadjust is disabled
    // so there are sane values to start with if it's turned on.
    m_popularity->useService(desktopMenuId);

    if (m_settings->autoAdjustEnabled())
    {
        TQTimer::singleShot(0, this, TQT_SLOT(slotAdjustToCurrentPopularity()));
    }
}
예제 #12
0
 void showService(KService::Ptr selectedService)
 {
     KGuiItem openItem(i18nc("@label:button", "&Open with %1", selectedService->name()), selectedService->icon());
     setButtonGuiItem(OpenWith, openItem);
 }
예제 #13
0
TQString KURIFilterData::iconName()
{
    if( m_bChanged )
    {
        m_customIconPixmap = TQPixmap();
        switch ( m_iType )
        {
            case KURIFilterData::LOCAL_FILE:
            case KURIFilterData::LOCAL_DIR:
            case KURIFilterData::NET_PROTOCOL:
            {
                m_strIconName = KMimeType::iconForURL( m_pURI );
                break;
            }
            case KURIFilterData::EXECUTABLE:
            {
                TQString exeName = m_pURI.url();
                exeName = exeName.mid( exeName.findRev( '/' ) + 1 ); // strip path if given
                KService::Ptr service = KService::serviceByDesktopName( exeName );
#ifndef HAVE_ELFICON
                // Try to find an icon with the same name as the binary (useful for non-tde apps)
                // FIXME: We should only do this if the binary is in the system path somewhere,
                // otherwise TDE could end up showing system icons for user binaries
                if (service && service->icon() != TQString::fromLatin1( "unknown" )) {
                    m_strIconName = service->icon();
                }
                else if ( !TDEGlobal::iconLoader()->loadIcon( exeName, TDEIcon::NoGroup, 16, TDEIcon::DefaultState, 0, true ).isNull() ) {
                    m_strIconName = exeName;
                }
                else {
                    // use default
                    m_strIconName = TQString::fromLatin1("exec");
                }
#else // HAVE_ELFICON
		// Try to find an icon with the same name as the binary (useful for non-tde apps)
		// FIXME: We should only do this if the binary is in the system path somewhere,
		// otherwise TDE could end up showing system icons for user binaries
		if (service && service->icon() != TQString::fromLatin1( "unknown" )) {
			m_strIconName = service->icon();
		}
		else if ( !TDEGlobal::iconLoader()->loadIcon( exeName, TDEIcon::NoGroup, 16, TDEIcon::DefaultState, 0, true ).isNull() ) {
			m_strIconName = exeName;
		}
		else {
			// use default
			m_strIconName = TQString::fromLatin1("exec");
		}
		// Try to load from elf file (if supported)
		// Check for an embedded icon
		unsigned int icon_size;
		libr_icon *icon = NULL;
		libr_file *handle = NULL;
		libr_access_t access = LIBR_READ;
		char libr_can_continue = 1;

		if((handle = libr_open(const_cast<char*>(m_pURI.path().ascii()), access)) == NULL)
		{
			kdWarning() << "failed to open file" << m_pURI.path() << endl;
			libr_can_continue = 0;
		}

		if (libr_can_continue == 1) {
			icon_size = 32;	// FIXME: Is this a reasonable size request for all possible usages of kurifilter?
			icon = libr_icon_geticon_bysize(handle, icon_size);

			if (libr_can_continue == 1) {
				// See if the embedded icon name matches any icon file names already on the system
				// If it does, use the system icon instead of the embedded one
				int iconresnamefound = 0;
				iconentry *entry = NULL;
				iconlist icons;
				if(!get_iconlist(handle, &icons))
				{
					// Failed to obtain a list of ELF icons
					kdWarning() << "failed to obtain ELF icon: " << libr_errmsg() << endl;

					// See if there is a system icon we can use
					TQString sysIconName = elf_get_resource(handle, ".metadata_sysicon");
					if (!sysIconName.isEmpty()) {
						if (TDEGlobal::iconLoader()->iconPath(sysIconName.ascii(), 0, true) != "") {
							m_strIconName = sysIconName;
						}
					}

					libr_close(handle);
					libr_can_continue = 0;
				}
				else {
					while((entry = get_nexticon(&icons, entry)) != NULL)
					{
						if(icon == NULL)
						{
							// Try loading this icon as fallback
							icon = libr_icon_geticon_byname(handle, entry->name);
						}
						if (TDEGlobal::iconLoader()->iconPath(entry->name, 0, true) != "") {
							iconresnamefound = 1;
							m_strIconName = entry->name;
							break;
						}
					}
				}

				if (libr_can_continue == 1) {
					if ((iconresnamefound == 0) && (icon)) {
						// Extract the embedded icon
						size_t icon_data_length;
						char* icondata = libr_icon_malloc(icon, &icon_data_length);
						m_customIconPixmap.loadFromData(static_cast<uchar*>(static_cast<void*>(icondata)), icon_data_length);	// EVIL CAST
						if (icon_size != 0) {
							TQImage ip = m_customIconPixmap.convertToImage();
							ip = ip.smoothScale(icon_size, icon_size);
							m_customIconPixmap.convertFromImage(ip);
						}
						free(icondata);
						libr_icon_close(icon);
					}

					libr_close(handle);
				}
			}
		}
#endif // HAVE_ELFICON
                break;
            }
            case KURIFilterData::HELP:
            {
                m_strIconName = TQString::fromLatin1("khelpcenter");
                break;
            }
            case KURIFilterData::SHELL:
            {
                m_strIconName = TQString::fromLatin1("konsole");
                break;
            }
            case KURIFilterData::ERROR:
            case KURIFilterData::BLOCKED:
            {
                m_strIconName = TQString::fromLatin1("error");
                break;
            }
            default:
                m_strIconName = TQString::null;
                break;
        }
        m_bChanged = false;
    }
    return m_strIconName;
}
예제 #14
0
void KateProjectTreeViewContextMenu::exec(const QString &filename, const QPoint &pos, QWidget *parent)
{
    /**
     * create context menu
     */
    QMenu menu;

    QAction *copyAction = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-copy")), i18n("Copy Filename"));

    /**
     * handle "open with"
     * find correct mimetype to query for possible applications
     */
    QMenu *openWithMenu = menu.addMenu(i18n("Open With"));
    QMimeType mimeType = QMimeDatabase().mimeTypeForFile(filename);
    KService::List offers = KMimeTypeTrader::self()->query(mimeType.name(), QStringLiteral("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() == QStringLiteral("Kate")) {
            continue;    // omit Kate
        }
        QAction *action = openWithMenu->addAction(QIcon::fromTheme(service->icon()), service->name());
        action->setData(service->entryPath());
    }

    /**
     * perhaps disable menu, if no entries!
     */
    openWithMenu->setEnabled(!openWithMenu->isEmpty());

    KMoreToolsMenuFactory menuFactory(QLatin1String("kate/addons/project/git-tools"));

    QMenu gitMenu; // must live as long as the maybe filled menu items should live

    if (isGit(filename)) {

        menuFactory.fillMenuFromGroupingNames(&gitMenu, { QLatin1String("git-clients-and-actions") },
                                                               QUrl::fromLocalFile(filename));

        menu.addSection(i18n("Git:"));
        Q_FOREACH(auto action, gitMenu.actions()) {
            menu.addAction(action);
        }
    }

    /**
     * run menu and handle the triggered action
     */
    if (QAction *action = menu.exec(pos)) {

        // handle apps
        if (copyAction == action) {
            QApplication::clipboard()->setText(filename);
        } else {
            // handle "open with"
            const QString openWith = action->data().toString();
            if (KService::Ptr app = KService::serviceByDesktopPath(openWith)) {
                QList<QUrl> list;
                list << QUrl::fromLocalFile(filename);
                KRun::runService(*app, list, parent);
            }
        }
    }
}