Esempio n. 1
0
void Shell::slotPartDisconnect(KParts::BrowserExtension *be)
{
    //if we got here then the part has no browserExtension, so we need to remove the actions
    //from the collection

    KParts::BrowserExtension::ActionSlotMap *slotmap = KParts::BrowserExtension::actionSlotMapPtr();
    KParts::BrowserExtension::ActionSlotMap::const_iterator it = slotmap->constBegin();
    KParts::BrowserExtension::ActionSlotMap::const_iterator itEnd = slotmap->constEnd();
    //iterate over the slotmap deactivating as we go... also copied from kongmainwindow.cpp
    for (; it != itEnd ; ++it) {
        QAction *act = actionCollection()->action(it.key().data());
        if (act && be->metaObject()->indexOfSlot(it.key() + "()") != -1) {
            act->disconnect(be);
            act->setDisabled(true);
        }
    }

}
Esempio n. 2
0
void Shell::slotPartConnect(KParts::Part* newPart)
{
    //if the currentpart is set, disconnect it before initializing the new part
    if (curPart) {
        slotPartDisconnect(curPart->browserExtension());
    }

    //cast the part into a readonly part, this should be safe so long as we never load a
    //non readonly part derived part
    KParts::ReadOnlyPart * ro_part = qobject_cast< KParts::ReadOnlyPart * >(newPart);
    if (ro_part == 0 || !ro_part->browserExtension()) {
        return;//if the cast fails (ro_part = 0) then we can't do anything.
    }
    KParts::BrowserExtension *be = ro_part->browserExtension();

    //check if the newpart has a browserExtension, if it does we will want to
    //activate some actions. This is based on konquerors kongmainwindow.cpp
    if (be) {
        KParts::BrowserExtension::ActionSlotMap *slotmap = KParts::BrowserExtension::actionSlotMapPtr();
        KParts::BrowserExtension::ActionSlotMap::const_iterator it = slotmap->constBegin();
        KParts::BrowserExtension::ActionSlotMap::const_iterator itEnd = slotmap->constEnd();

        //iterate over the slotmap, activating actions as we go
        for (; it != itEnd; ++it) {
            QAction *act = actionCollection()->action(it.key().data());
            if (act) {
                //check for the existence of the slot within this kpart
                if (be->metaObject()->indexOfSlot(it.key() + "()") != -1) {
                    connect(act, SIGNAL(triggered()), be, it.value());
                    act->setEnabled(be->isActionEnabled(it.key()));
                    const QString text = be->actionText(it.key());
                    if (!text.isEmpty()) {
                        act->setText(text);
                    }
                } else {
                    act->setEnabled(false);
                }
            }
        }
    }
    //set the currentpart to the newpart
    curPart = ro_part;
}