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); } } }
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; }
void MainWindow::printRequested(QWebFrame *frame) { if (!currentTab()) return; if(currentTab()->page()->isOnRekonqPage()) { // trigger print part action instead of ours.. KParts::ReadOnlyPart *p = currentTab()->part(); if(p) { KParts::BrowserExtension *ext = p->browserExtension(); if(ext) { KParts::BrowserExtension::ActionSlotMap *actionSlotMap = KParts::BrowserExtension::actionSlotMapPtr(); connect(this, SIGNAL(triggerPartPrint()), ext, actionSlotMap->value("print")); emit triggerPartPrint(); return; } } } QWebFrame *printFrame = 0; if (frame == 0) { printFrame = currentTab()->page()->mainFrame(); } else { printFrame = frame; } QPrinter printer; QPrintPreviewDialog previewdlg(&printer, this); connect(&previewdlg, SIGNAL(paintRequested(QPrinter *)), printFrame, SLOT(print(QPrinter *))); previewdlg.exec(); }
void WebTab::printFrame() { if (page()->isOnRekonqPage()) { // trigger print part action instead of ours.. KParts::ReadOnlyPart *p = part(); if (p) { KParts::BrowserExtension *ext = p->browserExtension(); if (ext) { KParts::BrowserExtension::ActionSlotMap *actionSlotMap = KParts::BrowserExtension::actionSlotMapPtr(); connect(this, SIGNAL(triggerPartPrint()), ext, actionSlotMap->value("print")); emit triggerPartPrint(); return; } } } QWebFrame *printFrame = page()->currentFrame(); if (printFrame == 0) { printFrame = page()->mainFrame(); } QPrinter printer; printer.setDocName(printFrame->title()); QPrintDialog *printDialog = KdePrint::createPrintDialog(&printer, this); if (printDialog) //check if the Dialog was created { if (printDialog->exec()) printFrame->print(&printer); delete printDialog; } }