- KMenu* actionsMenu = new KMenu();
-
- 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 entries = dir.entryList("*.desktop", QDir::Files);
-
- for (QStringList::ConstIterator entryIt = entries.begin(); entryIt != entries.end(); ++entryIt) {
- KSimpleConfig cfg(*dirIt + *entryIt, true);
- cfg.setDesktopGroup();
- if ((cfg.hasKey("Actions") || cfg.hasKey("X-KDE-GetActionMenu")) && cfg.hasKey("ServiceTypes")) {
- const QStringList types = cfg.readListEntry("ServiceTypes");
- 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...
- const KFileItemList list = m_dolphinView->selectedItems();
-
- QListIterator<KFileItem*> mimeIt(list);
- 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.
- const KFileItemList list = m_dolphinView->selectedItems();
-
- QListIterator<KFileItem*> mimeIt(list);
- 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();
- actionsMenu->insertItem(submenuName, menu, submenuID);
- }
-
- Q3ValueList<KDEDesktopMimeType::Service> userServices =
- KDEDesktopMimeType::userDefinedServices(*dirIt + *entryIt, true);
-
- Q3ValueList<KDEDesktopMimeType::Service>::Iterator serviceIt;
- for (serviceIt = userServices.begin(); serviceIt != userServices.end(); ++serviceIt) {
- KDEDesktopMimeType::Service service = (*serviceIt);
- if (!service.m_strIcon.isEmpty()) {
- QAction *action = menu->addAction(SmallIcon(service.m_strIcon),
- service.m_strName);
- serviceActions << action;
- }
- else {
- QAction *action = menu->addAction(service.m_strName);
- serviceActions << action;
- }
- actionsVector.append(service);
- }
- }
- }
- }
- }