KParts::Part* IPartController::createPart ( const QString& mimetype, const QString& prefName ) { static const char* const services[] = { // Disable read/write parts until we can support them /*"KParts/ReadWritePart",*/ "KParts/ReadOnlyPart" }; static const char* const classNames[] = { /*"KParts::ReadWritePart",*/ "KParts::ReadOnlyPart" }; KParts::Part* part = 0; for ( uint i = 0; i < 2; ++i ) { KParts::Factory* editorFactory = findPartFactory( mimetype, QString::fromLatin1(services[ i ]), prefName ); if ( editorFactory ) { part = editorFactory->createPart( 0, this, classNames[ i ] ); break; } } return part; }
void Shell::init() { // set the shell's ui resource file setXMLFile("shell.rc"); // this routine will find and load our Part. it finds the Part by // name which is a bad idea usually.. but it's alright in this // case since our Part is made for this Shell KParts::Factory *factory = (KParts::Factory *) KLibLoader::self()->factory("libkpdfpart"); if (factory) { // now that the Part is loaded, we cast it to a Part to get // our hands on it m_part = (KParts::ReadOnlyPart*) factory->createPart(this, "kpdf_part", this, 0, "KParts::ReadOnlyPart"); if (m_part) { // then, setup our actions setupActions(); // tell the KParts::MainWindow that this is indeed the main widget setCentralWidget(m_part->widget()); // and integrate the part's GUI with the shell's setupGUI(Keys | Save); createGUI(m_part); m_showToolBarAction = static_cast<KToggleAction*>(toolBarMenuAction()); } } else { // if we couldn't find our Part, we exit since the Shell by // itself can't do anything useful KMessageBox::error(this, i18n("Unable to find kpdf part.")); m_part = 0; return; } connect( this, SIGNAL( restoreDocument(KConfig*) ),m_part, SLOT( restoreDocument(KConfig*))); connect( this, SIGNAL( saveDocumentRestoreInfo(KConfig*) ), m_part, SLOT( saveDocumentRestoreInfo(KConfig*))); connect( m_part, SIGNAL( enablePrintAction(bool) ), m_printAction, SLOT( setEnabled(bool))); readSettings(); if (!KGlobal::config()->hasGroup("MainWindow")) { KMainWindowInterface kmwi(this); kmwi.maximize(); } setAutoSaveSettings(); if (m_openUrl.isValid()) QTimer::singleShot(0, this, SLOT(delayedOpen())); }