Logo Search packages:      
Sourcecode: d3lphin version File versions  Download package

void InfoSidebarPage::insertActions (  )  [private]

Inserts the available actions to the info page for the given item.

Definition at line 406 of file infosidebarpage.cpp.

References Dolphin::activeView(), Dolphin::mainWin(), DolphinView::selectedItems(), and startService().

Referenced by showItemInfo().

{
    // delete all existing action widgets
    // TODO: just use children() from QObject...
    QPtrListIterator<QWidget> deleteIter(m_actionWidgets);
    QWidget* widget = 0;
    while ((widget = deleteIter.current()) != 0) {
        widget->close();
        widget->deleteLater();
        ++deleteIter;
    }

    m_actionWidgets.clear();
    m_actionsVector.clear();

    int actionsIndex = 0;

    // The algorithm for searching the available actions works on a list
    // of KFileItems. If no selection is given, a temporary KFileItem
    // by the given URL 'url' is created and added to the list.
    KFileItem fileItem(S_IFDIR, KFileItem::Unknown, m_shownURL);
    KFileItemList localList;
    const KFileItemList* itemList = Dolphin::mainWin().activeView()->selectedItems();
    if ((itemList == 0) || itemList->isEmpty()) {
        fileItem.refresh();
        localList.append(&fileItem);
        itemList = &localList;
    }

    // 'itemList' contains now all KFileItems, where an item information should be shown.
    // TODO: the following algorithm is quite equal to DolphinContextMenu::insertActionItems().
    // It's open yet whether they should be merged or whether they have to work slightly different.
    QStringList dirs = KGlobal::dirs()->findDirs("data", "d3lphin/servicemenus/");
    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...
                        KFileItemListIterator mimeIt(*itemList);
                        KFileItem* item = 0;
                        insert = true;
                        while (insert && ((item = mimeIt.current()) != 0)) {
                            insert = !item->isDir();
                            ++mimeIt;
                        }
                    }

                    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.
                        KFileItemListIterator mimeIt(*itemList);
                        KFileItem* item = 0;
                        insert = true;
                        while (insert && ((item = mimeIt.current()) != 0)) {
                            const QString mimeType((*mimeIt)->mimetype());
                            const QString mimeGroup(mimeType.left(mimeType.find('/')));

                            insert  = (*it == mimeType) ||
                                      ((*it).right(1) == "*") &&
                                      ((*it).left((*it).find('/')) == mimeGroup);
                            ++mimeIt;
                        }
                    }

                    if (insert) {
                        const QString submenuName = cfg.readEntry( "X-KDE-Submenu" );
                        QPopupMenu* popup = 0;
                        if (!submenuName.isEmpty()) {
                            // create a sub menu containing all actions
                            popup = new QPopupMenu();
                            connect(popup, SIGNAL(activated(int)),
                                    this, SLOT(startService(int)));

                            QPushButton* button = new QPushButton(submenuName, m_actionBox);
                            button->setFlat(true);
                            button->setPopup(popup);
                            button->show();
                            m_actionWidgets.append(button);
                        }

                        QValueList<KDEDesktopMimeType::Service> userServices =
                            KDEDesktopMimeType::userDefinedServices(*dirIt + *entryIt, true);

                        // iterate through all actions and add them to a widget
                        QValueList<KDEDesktopMimeType::Service>::Iterator serviceIt;
                        for (serviceIt = userServices.begin(); serviceIt != userServices.end(); ++serviceIt) {
                            KDEDesktopMimeType::Service service = (*serviceIt);
                            if (popup == 0) {
                                ServiceButton* button = new ServiceButton(SmallIcon(service.m_strIcon),
                                                                          service.m_strName,
                                                                          m_actionBox,
                                                                          actionsIndex);
                                connect(button, SIGNAL(requestServiceStart(int)),
                                        this, SLOT(startService(int)));
                                m_actionWidgets.append(button);
                                button->show();
                            }
                            else {
                                popup->insertItem(SmallIcon(service.m_strIcon), service.m_strName, actionsIndex);
                            }

                            m_actionsVector.append(service);
                            ++actionsIndex;
                        }
                    }
                }
            }
        }
    }
}


Generated by  Doxygen 1.6.0   Back to index