- // Parts of the following code have been taken
- // from the class KonqOperations located in
- // libqonq/konq_operations.h of Konqueror.
- // (Copyright (C) 2000 David Faure <faure@kde.org>)
-
- KMenu* actionsMenu = new KMenu(i18n("Actions"));
-
- QList<QAction*> serviceActions;
-
- QStringList dirs = KGlobal::dirs()->findDirs("data", "dolphin/servicemenus/");
-
- KMenu* menu = 0;
- for (QStringList::ConstIterator dirIt = dirs.begin(); dirIt != dirs.end(); ++dirIt) {
- QDir dir(*dirIt);
- QStringList filters;
- filters << "*.desktop";
- dir.setNameFilters(filters);
- QStringList entries = dir.entryList(QDir::Files);
-
- for (QStringList::ConstIterator entryIt = entries.begin(); entryIt != entries.end(); ++entryIt) {
- KConfigGroup cfg(KSharedConfig::openConfig(*dirIt + *entryIt, KConfig::OnlyLocal), "Desktop Entry");
- if ((cfg.hasKey("Actions") || cfg.hasKey("X-KDE-GetActionMenu")) && cfg.hasKey("ServiceTypes")) {
- //const QStringList types = cfg.readListEntry("ServiceTypes");
- QStringList types;
- types = cfg.readEntry("ServiceTypes", types);
- for (QStringList::ConstIterator it = types.begin(); it != types.end(); ++it) {
- // check whether the mime type is equal or whether the
- // mimegroup (e. g. image/*) is supported
-
- bool insert = false;
- if ((*it) == "all/allfiles") {
- // The service type is valid for all files, but not for directories.
- // Check whether the selected items only consist of files...
- QListIterator<KFileItem*> mimeIt(m_selectedItems);
- insert = true;
- while (insert && mimeIt.hasNext()) {
- KFileItem* item = mimeIt.next();
- insert = !item->isDir();
- }
- }
-
- if (!insert) {
- // Check whether the MIME types of all selected files match
- // to the mimetype of the service action. As soon as one MIME
- // type does not match, no service menu is shown at all.
- QListIterator<KFileItem*> mimeIt(m_selectedItems);
- insert = true;
- while (insert && mimeIt.hasNext()) {
- KFileItem* item = mimeIt.next();
- const QString mimeType(item->mimetype());
- const QString mimeGroup(mimeType.left(mimeType.indexOf('/')));
-
- insert = (*it == mimeType) ||
- ((*it).right(1) == "*") &&
- ((*it).left((*it).indexOf('/')) == mimeGroup);
- }
- }
-
- if (insert) {
- menu = actionsMenu;
-
- const QString submenuName = cfg.readEntry("X-KDE-Submenu");
- if (!submenuName.isEmpty()) {
- menu = new KMenu(submenuName);
- actionsMenu->addMenu(menu);
- }
-
- Q3ValueList<KDesktopFileActions::Service> userServices =
- KDesktopFileActions::userDefinedServices(*dirIt + *entryIt, true);
-
- Q3ValueList<KDesktopFileActions::Service>::Iterator serviceIt;
- for (serviceIt = userServices.begin(); serviceIt != userServices.end(); ++serviceIt) {
- KDesktopFileActions::Service service = (*serviceIt);
- if (!service.m_strIcon.isEmpty()) {
- QAction* action = menu->addAction(KIcon(service.m_strIcon),
- service.m_strName);
- serviceActions << action;
- } else {
- QAction *action = menu->addAction(service.m_strName);
- serviceActions << action;
- }
- actionsVector.append(service);
- }
- }
- }
- }
- }