KParts::ReadOnlyPart *JournalPlugin::createPart() { KParts::ReadOnlyPart *part = loadPart(); if ( !part ) return 0; dcopClient(); // ensure that we register to DCOP as "korganizer" mIface = new KCalendarIface_stub( dcopClient(), "kontact", "CalendarIface" ); return part; }
void KDirNotify_stub::FilesChanged(const KURL::List &arg0) { if(!dcopClient()) { setStatus(CallFailed); return; } QByteArray data; QDataStream arg(data, IO_WriteOnly); arg << arg0; dcopClient()->emitDCOPSignal("KDirNotify", "FilesChanged(KURL::List)", data); setStatus(CallSucceeded); }
KateApp::KateApp (KCmdLineArgs *args) : KApplication () , m_args (args) , m_shouldExit (false) { // Don't handle DCOP requests yet dcopClient()->suspend(); // insert right translations for the katepart KGlobal::locale()->insertCatalogue("katepart"); // some global default Kate::Document::setFileChangedDialogsActivated (true); // application interface m_application = new Kate::Application (this); // doc + project man m_docManager = new KateDocManager (this); // init all normal plugins m_pluginManager = new KatePluginManager (this); // session manager up m_sessionManager = new KateSessionManager (this); // application dcop interface m_obj = new KateAppDCOPIface (this); kdDebug()<<"Setting KATE_PID: '"<<getpid()<<"'"<<endl; ::setenv( "KATE_PID", QString("%1").arg(getpid()).latin1(), 1 ); // handle restore different if (isRestored()) { restoreKate (); } else { // let us handle our command line args and co ;) // we can exit here if session chooser decides if (!startupKate ()) { m_shouldExit = true; return; } } // Ok. We are ready for DCOP requests. dcopClient()->resume(); }
bool DCOPRef::sendInternal(const QCString &fun, const QCString &args, const QByteArray &data) { if(isNull()) { qWarning("DCOPRef: send '%s' on null reference error", STR(fun)); return false; } Q_UNUSED(data); QCString sig = fun; if(fun.find('(') == -1) { sig += args; if(args.find("<unknown") != -1) qWarning( "DCOPRef: unknown type error " "<\"%s\",\"%s\">::send(\"%s\",%s", STR(m_app), STR(m_obj), STR(fun), args.data() + 1); } DCOPClient *dc = dcopClient(); if(!dc || !dc->isAttached()) { qWarning("DCOPRef::send(): no DCOP client or client not attached error"); return false; } return dc->send(m_app, m_obj, sig, data); }
DCOPReply DCOPRef::callInternal(const QCString &fun, const QCString &args, const QByteArray &data, EventLoopFlag useEventLoop, int timeout) { DCOPReply reply; if(isNull()) { qWarning("DCOPRef: call '%s' on null reference error", STR(fun)); return reply; } QCString sig = fun; if(fun.find('(') == -1) { sig += args; if(args.find("<unknown") != -1) qWarning( "DCOPRef: unknown type error " "<\"%s\",\"%s\">::call(\"%s\",%s", STR(m_app), STR(m_obj), STR(fun), args.data() + 1); } DCOPClient *dc = dcopClient(); if(!dc || !dc->isAttached()) { qWarning("DCOPRef::call(): no DCOP client or client not attached error"); return reply; } dc->call(m_app, m_obj, sig, data, reply.type, reply.data, useEventLoop == UseEventLoop, timeout); return reply; }
KarmPlugin::KarmPlugin(Kontact::Core *core, const char *, const QStringList &) : Kontact::Plugin(core, core, "KArm") { setInstance(KarmPluginFactory::instance()); (void)dcopClient(); insertNewAction(new KAction(i18n("New Task"), "karm", CTRL + SHIFT + Key_W, this, SLOT(newTask()), actionCollection(), "new_task")); }
KParts::ReadOnlyPart *KarmPlugin::createPart() { KParts::ReadOnlyPart *part = loadPart(); if(!part) return 0; // this calls a DCOP interface from karm via the lib KarmDCOPIface_stub that is generated automatically mStub = new KarmDCOPIface_stub(dcopClient(), "KArm", "KarmDCOPIface"); return part; }
KParts::ReadOnlyPart *KOrganizerPlugin::createPart() { KParts::ReadOnlyPart *part = loadPart(); if ( !part ) return 0; mIface = new KCalendarIface_stub( dcopClient(), "kontact", "CalendarIface" ); return part; }
Application::Application() : KApplication(), owner(screen_number) { KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if(!config()->isImmutable() && args->isSet("lock")) { config()->setReadOnly(true); config()->reparseConfiguration(); } if(screen_number == -1) screen_number = DefaultScreen(qt_xdisplay()); if(!owner.claim(args->isSet("replace"), true)) { fputs(i18n("kwin: unable to claim manager selection, another wm running? (try using --replace)\n").local8Bit(), stderr); ::exit(1); } connect(&owner, SIGNAL(lostOwnership()), SLOT(lostSelection())); // if there was already kwin running, it saved its configuration after loosing the selection -> reread config()->reparseConfiguration(); initting = TRUE; // startup.... // install X11 error handler XSetErrorHandler(x11ErrorHandler); // check whether another windowmanager is running XSelectInput(qt_xdisplay(), qt_xrootwin(), SubstructureRedirectMask); syncX(); // trigger error now options = new Options; atoms = new Atoms; // create workspace. (void)new Workspace(isSessionRestored()); syncX(); // trigger possible errors, there's still a chance to abort DCOPRef ref("kded", "kded"); ref.send("unloadModule", QCString("kdetrayproxy")); initting = FALSE; // startup done, we are up and running now. dcopClient()->send("ksplash", "", "upAndRunning(QString)", QString("wm started")); XEvent e; e.xclient.type = ClientMessage; e.xclient.message_type = XInternAtom(qt_xdisplay(), "_KDE_SPLASH_PROGRESS", False); e.xclient.display = qt_xdisplay(); e.xclient.window = qt_xrootwin(); e.xclient.format = 8; strcpy(e.xclient.data.b, "wm started"); XSendEvent(qt_xdisplay(), qt_xrootwin(), False, SubstructureNotifyMask, &e); }
void KUniqueApplication::delayRequest(const TQCString &fun, const TQByteArray &data) { DCOPRequest *request = new DCOPRequest; request->fun = fun; request->data = data; request->transaction = dcopClient()->beginTransaction(); d->requestList.append(request); if (!d->processingRequest) { TQTimer::singleShot(0, this, TQT_SLOT(processDelayed())); } }
KoApplication::KoApplication() : KApplication( initHack() ) { d = new KoApplicationPrivate; // Initialize all KOffice directories etc. KoGlobal::initialize(); // Prepare a DCOP interface d->m_appIface = new KoApplicationIface; dcopClient()->setDefaultObject( d->m_appIface->objId() ); m_starting = true; }
void KUniqueApplication::processDelayed() { if (dcopClient()->isSuspended()) { // Try again later. TQTimer::singleShot( 200, this, TQT_SLOT(processDelayed())); return; } d->processingRequest = true; while( !d->requestList.isEmpty() ) { DCOPRequest *request = d->requestList.take(0); TQByteArray replyData; TQCString replyType; if (request->fun == "newInstance()") { dcopClient()->setPriorityCall(false); TQDataStream ds(request->data, IO_ReadOnly); TDECmdLineArgs::loadAppArgs(ds); if( !ds.atEnd()) // backwards compatibility { TQCString asn_id; ds >> asn_id; setStartupId( asn_id ); } s_handleAutoStarted = false; int exitCode = newInstance(); d->firstInstance = false; #if defined Q_WS_X11 if( s_handleAutoStarted ) TDEStartupInfo::handleAutoAppStartedSending(); // KDE4 remove? #endif TQDataStream rs(replyData, IO_WriteOnly); rs << exitCode; replyType = "int"; }
void KateApp::shutdownKate (KateMainWindow *win) { if (!win->queryClose_internal()) return; sessionManager()->saveActiveSession(true, true); // detach the dcopClient dcopClient()->detach(); // cu main windows while (!m_mainWindows.isEmpty()) delete m_mainWindows[0]; quit (); }
void KUniqueApplication::newInstanceNoFork() { if (dcopClient()->isSuspended()) { // Try again later. TQTimer::singleShot( 200, this, TQT_SLOT(newInstanceNoFork()) ); return; } s_handleAutoStarted = false; newInstance(); d->firstInstance = false; #if defined Q_WS_X11 // KDE4 remove // A hack to make startup notification stop for apps which override newInstance() // and reuse an already existing window there, but use KWin::activateWindow() // instead of TDEStartupInfo::setNewStartupId(). Therefore KWin::activateWindow() // for now sets this flag. Automatically ending startup notification always // would cause problem if the new window would show up with a small delay. if( s_handleAutoStarted ) TDEStartupInfo::handleAutoAppStartedSending(); #endif // What to do with the return value ? }
bool KUniqueApplication::start() { if( s_uniqueTestDone ) return true; s_uniqueTestDone = true; addCmdLineOptions(); // Make sure to add cmd line options #ifdef Q_WS_WIN s_nofork = true; #else TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs("kuniqueapp"); s_nofork = !args->isSet("fork"); delete args; #endif TQCString appName = TDECmdLineArgs::about->appName(); if (s_nofork) { if (s_multipleInstances) { TQCString pid; pid.setNum(getpid()); appName = appName + "-" + pid; } // Check to make sure that we're actually able to register with the DCOP // server. #ifndef Q_WS_WIN //TODO if(dcopClient()->registerAs(appName, false).isEmpty()) { startKdeinit(); if(dcopClient()->registerAs(appName, false).isEmpty()) { kdError() << "KUniqueApplication: Can't setup DCOP communication." << endl; ::exit(255); } } #endif // We'll call newInstance in the constructor. Do nothing here. return true; } DCOPClient *dc; int fd[2]; signed char result; if (0 > pipe(fd)) { kdError() << "KUniqueApplication: pipe() failed!" << endl; ::exit(255); } int fork_result = fork(); switch(fork_result) { case -1: kdError() << "KUniqueApplication: fork() failed!" << endl; ::exit(255); break; case 0: // Child ::close(fd[0]); if (s_multipleInstances) appName.append("-").append(TQCString().setNum(getpid())); dc = dcopClient(); { TQCString regName = dc->registerAs(appName, false); if (regName.isEmpty()) { // Check DISPLAY if (TQCString(getenv(DISPLAY)).isEmpty()) { kdError() << "KUniqueApplication: Can't determine DISPLAY. Aborting." << endl; result = -1; // Error ::write(fd[1], &result, 1); ::exit(255); } // Try to launch tdeinit. startKdeinit(); regName = dc->registerAs(appName, false); if (regName.isEmpty()) { kdError() << "KUniqueApplication: Can't setup DCOP communication." << endl; result = -1; delete dc; // Clean up DCOP commmunication ::write(fd[1], &result, 1); ::exit(255); } } if (regName != appName) { // Already running. Ok. result = 0; delete dc; // Clean up DCOP commmunication ::write(fd[1], &result, 1); ::close(fd[1]); #if 0 #ifdef Q_WS_X11 // say we're up and running ( probably no new window will appear ) TDEStartupInfoId id; if( kapp != NULL ) // TDEApplication constructor unsets the env. variable id.initId( kapp->startupId()); else id = TDEStartupInfo::currentStartupIdEnv(); if( !id.none()) { Display* disp = XOpenDisplay( NULL ); if( disp != NULL ) // use extra X connection { TDEStartupInfo::sendFinishX( disp, id ); XCloseDisplay( disp ); } } #else //FIXME(E): implement #endif #endif return false; } dc->setPriorityCall(true); } { #ifdef Q_WS_X11 TDEStartupInfoId id; if( kapp != NULL ) // TDEApplication constructor unsets the env. variable id.initId( kapp->startupId()); else id = TDEStartupInfo::currentStartupIdEnv(); if( !id.none()) { // notice about pid change Display* disp = XOpenDisplay( NULL ); if( disp != NULL ) // use extra X connection { TDEStartupInfoData data; data.addPid( getpid()); TDEStartupInfo::sendChangeX( disp, id, data ); XCloseDisplay( disp ); } } #else //FIXME(E): Implement #endif } result = 0; ::write(fd[1], &result, 1); ::close(fd[1]); return true; // Finished. default: // Parent // DCOPClient::emergencyClose(); // dcopClient()->detach(); if (s_multipleInstances) appName.append("-").append(TQCString().setNum(fork_result)); ::close(fd[1]); for(;;) { int n = ::read(fd[0], &result, 1); if (n == 1) break; if (n == 0) { kdError() << "KUniqueApplication: Pipe closed unexpectedly." << endl; ::exit(255); } if (errno != EINTR) { kdError() << "KUniqueApplication: Error reading from pipe." << endl; ::exit(255); } } ::close(fd[0]); if (result != 0) ::exit(result); // Error occurred in child. dc = new DCOPClient(); if (!dc->attach()) { kdError() << "KUniqueApplication: Parent process can't attach to DCOP." << endl; delete dc; // Clean up DCOP commmunication ::exit(255); } if (!dc->isApplicationRegistered(appName)) { kdError() << "KUniqueApplication: Registering failed!" << endl; } TQCString new_asn_id; #if defined Q_WS_X11 TDEStartupInfoId id; if( kapp != NULL ) // TDEApplication constructor unsets the env. variable id.initId( kapp->startupId()); else id = TDEStartupInfo::currentStartupIdEnv(); if( !id.none()) new_asn_id = id.id(); #endif TQByteArray data, reply; TQDataStream ds(data, IO_WriteOnly); TDECmdLineArgs::saveAppArgs(ds); ds << new_asn_id; dc->setPriorityCall(true); TQCString replyType; if (!dc->call(appName, TDECmdLineArgs::about->appName(), "newInstance()", data, replyType, reply)) { kdError() << "Communication problem with " << TDECmdLineArgs::about->appName() << ", it probably crashed." << endl; delete dc; // Clean up DCOP commmunication ::exit(255); } dc->setPriorityCall(false); if (replyType != "int") { kdError() << "KUniqueApplication: DCOP communication error!" << endl; delete dc; // Clean up DCOP commmunication ::exit(255); } TQDataStream rs(reply, IO_ReadOnly); int exitCode; rs >> exitCode; delete dc; // Clean up DCOP commmunication ::exit(exitCode); break; } return false; // make insure++ happy }