当前位置: 首页>>代码示例>>C++>>正文


C++ DCOPClient::attach方法代码示例

本文整理汇总了C++中DCOPClient::attach方法的典型用法代码示例。如果您正苦于以下问题:C++ DCOPClient::attach方法的具体用法?C++ DCOPClient::attach怎么用?C++ DCOPClient::attach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DCOPClient的用法示例。


在下文中一共展示了DCOPClient::attach方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: dcopPrint

int KPrinterImpl::dcopPrint(const TQString& cmd, const TQStringList& files, bool removeflag)
{
	kdDebug(500) << "tdeprint: print command: " << cmd << endl;

	int result = 0;
	DCOPClient	*dclient = kapp->dcopClient();
	if (!dclient || (!dclient->isAttached() && !dclient->attach()))
	{
		return result;
	}

	TQByteArray data, replyData;
	TQCString replyType;
	TQDataStream arg( data, IO_WriteOnly );
	arg << cmd;
	arg << files;
	arg << removeflag;
	if (dclient->call( "kded", "tdeprintd", "print(TQString,TQStringList,bool)", data, replyType, replyData ))
	{
		if (replyType == "int")
		{
			TQDataStream _reply_stream( replyData, IO_ReadOnly );
			_reply_stream >> result;
		}
	}
开发者ID:Fat-Zer,项目名称:tdelibs,代码行数:25,代码来源:kprinterimpl.cpp

示例2: main

int main(int argc, char **argv)
{
    bool ok;

    KApplication app(argc, argv, "kmobile_client", false);

    // get our DCOP client and attach so that we may use it
    DCOPClient *client = app.dcopClient();
    client->attach();

    QByteArray data;
    QDataStream ds(data, IO_WriteOnly);
//     ds << QString("a");

    QCString replyType;
    QByteArray replyData;
    ok = client->call("kmobile", "kmobileIface", "deviceNames()", data, replyType, replyData);

    QDataStream reply(replyData, IO_ReadOnly); 
    QStringList deviceNames; 
    reply >> deviceNames;

    kdDebug() << QString("%1\n").arg(ok?"Ok":"Failure");
    kdDebug() << QString("Number of currently registered drivers: %1\n").arg(deviceNames.count());
    for (int i=0; i<deviceNames.count(); i++)
      kdDebug() << QString("Device %1: %2\n").arg(i+1).arg(deviceNames[i]);

  //  return app.exec();
}
开发者ID:,项目名称:,代码行数:29,代码来源:

示例3: testStyle

void Style::testStyle()
{
    // Read entire XML into DOM Tree
    QFile file(selectedStyle);
    file.open(IO_ReadOnly);
    dom.setContent(file.readAll());
    file.close();

    // attach to dcop
    DCOPClient *client = kapp->dcopClient();
    if (!client->isAttached())
        client->attach();

    // kicker settings
    KConfig *kickerConf = new KConfig("kickerrc");
    kickerConf->setGroup("General");

    QDomElement Kicker = dom.elementsByTagName("kicker").item(0).toElement();

    kickerConf->writeEntry("LegacyKMenu", !checkKickoff->isChecked());
    kickerConf->writeEntry("Transparent", getProperty(Kicker, "Transparent", "value"));
    kickerConf->writeEntry("SizePercentage", getProperty(Kicker, "SizePercentage", "value"));
    kickerConf->writeEntry("CustomSize", getProperty(Kicker, "CustomSize", "value"));
    kickerConf->writeEntry("Position", getProperty(Kicker, "Position", "value"));
    kickerConf->writeEntry("Alignment", getProperty(Kicker, "Alignment", "value"));
    kickerConf->sync();
    delete kickerConf;

    // restart kicker
    client->send("kicker", "kicker", "restart()", "");

    // kwin settings
    KConfig *kwinConf = new KConfig("kwinrc");
    kwinConf->setGroup("Style");

    QDomElement KWin = dom.elementsByTagName("kwin").item(0).toElement();

    kwinConf->writeEntry("PluginLib", getProperty(KWin, "PluginLib", "value"));
    kwinConf->sync();
    delete kwinConf;

    // restart kwin
    client->send("kwin", "KWinInterface", "reconfigure()", "");

    // widget settings
    KConfig *globalConf = new KConfig("kdeglobals");
    globalConf->setGroup("General");

    QDomElement Widget = dom.elementsByTagName("widget").item(0).toElement();

    globalConf->writeEntry("widgetStyle", getProperty(Widget, "widgetStyle", "value"));
    globalConf->sync();
    delete globalConf;

    KIPC::sendMessageAll(KIPC::StyleChanged);
}
开发者ID:Tayyib,项目名称:uludag,代码行数:56,代码来源:style.cpp

示例4: holdSlave

Slave* Slave::holdSlave( const QString &protocol, const KURL& url )
{
    //kdDebug(7002) << "holdSlave '" << protocol << "' for " << url.prettyURL() << endl;
    // Firstly take into account all special slaves
    if (protocol == "data")
        return 0;

    DCOPClient *client = kapp->dcopClient();
    if (!client->isAttached())
	client->attach();

    QString prefix = locateLocal("socket", KGlobal::instance()->instanceName());
    KTempFile socketfile(prefix, QString::fromLatin1(".slave-socket"));
    if ( socketfile.status() != 0 )
	return 0;

#ifdef __CYGWIN__
   socketfile.close();
   socketfile.unlink();
#endif

#ifndef Q_WS_WIN
    KServerSocket *kss = new KServerSocket(QFile::encodeName(socketfile.name()));

    Slave *slave = new Slave(kss, protocol, socketfile.name());
#else
    Slave *slave = 0;
#endif

    QByteArray params, reply;
    QCString replyType;
    QDataStream stream(params, IO_WriteOnly);
    stream << url << socketfile.name();

    QCString launcher = KApplication::launcher();
    if (!client->call(launcher, launcher, "requestHoldSlave(KURL,QString)",
        params, replyType, reply)) {
        delete slave;
        return 0;
    }
    QDataStream stream2(reply, IO_ReadOnly);
    pid_t pid;
    stream2 >> pid;
    if (!pid)
    {
        delete slave;
        return 0;
    }
#ifndef Q_WS_WIN
    slave->setPID(pid);
    QTimer::singleShot(1000*SLAVE_CONNECTION_TIMEOUT_MIN, slave, SLOT(timeout()));
#endif
    return slave;
}
开发者ID:,项目名称:,代码行数:54,代码来源:

示例5: arg

KDE_EXPORT void
wake_laptop_daemon()
{
	DCOPClient      *dclient = kapp->dcopClient();
        if (!dclient || (!dclient->isAttached() && !dclient->attach())) 
		return;

	TQByteArray data;
	TQDataStream arg( data, IO_WriteOnly );
	(void) dclient->send( "kded", "klaptopdaemon", "restart()", data );
}
开发者ID:Fat-Zer,项目名称:tdeutils,代码行数:11,代码来源:wake_laptop.cpp

示例6: loadBgPixmap

void Desktop::loadBgPixmap(void)
{
//  if (!m_bgDirty) return;
  DCOPClient *client = kapp->dcopClient();
  if (!client->isAttached())
      client->attach();
  QByteArray data, data2, replyData;
  QCString replyType;
  if (client->call("kdesktop", "KBackgroundIface", "isCommon()",
                  data, replyType, replyData))
  {
    QDataStream reply(replyData, IO_ReadOnly);
    if (replyType == "bool") {
      reply >> m_isCommon;
    }
开发者ID:,项目名称:,代码行数:15,代码来源:

示例7: main

int main(int argc, char **argv)
{
    KApplication app(argc, argv, "kerp_client", false);

    // get our DCOP client and attach so that we may use it
    DCOPClient *client = app.dcopClient();
    client->attach();

    // do a 'send' for now
    QByteArray data;
    QDataStream ds(data, IO_WriteOnly);
    if (argc > 1)
        ds << QString(argv[1]);
    else
        ds << QString("http://www.kde.org");
    client->send("kerp", "kerpIface", "openURL(QString)", data);

    return app.exec();
}
开发者ID:BackupTheBerlios,项目名称:kerp,代码行数:19,代码来源:kerp_client.cpp

示例8: enableExports

void KRootPixmap::enableExports()
{
#ifdef Q_WS_X11
    kdDebug(270) << k_lineinfo << "activating background exports.\n";
    DCOPClient *client = kapp->dcopClient();
    if(!client->isAttached())
        client->attach();
    QByteArray data;
    QDataStream args(data, IO_WriteOnly);
    args << 1;

    QCString appname("kdesktop");
    int screen_number = DefaultScreen(qt_xdisplay());
    if(screen_number)
        appname.sprintf("kdesktop-screen-%d", screen_number);

    client->send(appname, "KBackgroundIface", "setExport(int)", data);
#endif
}
开发者ID:,项目名称:,代码行数:19,代码来源:

示例9: doubleClickedOnDetails

    void RunnerGUI::doubleClickedOnDetails(int para, int /*pos*/)
    {
        static QRegExp reFileAndLine("^(.*)\\[([0-9]+)\\]:");

        QString line = m_testerWidget->details()->text(para);
        m_testerWidget->details()->setSelection(para, 0, para, line.length()-1);

        if ( reFileAndLine.search(line) != -1 )
        {
            DCOPClient client;
            client.attach();
            QByteArray data;
            QDataStream arg(&data, QIODevice::WriteOnly);
            bool ok;
            arg << QString(reFileAndLine.cap(1)) << (reFileAndLine.cap(2).toInt(&ok) - 1);
            client.send("kdevelop-*", "KDevPartController", "editDocument(QString,int)", data);
            client.send("kdevelop-*", "MainWindow", "raise()", "");

            client.detach();
        }
    }
开发者ID:ShermanHuang,项目名称:kdesdk,代码行数:21,代码来源:runnergui.cpp

示例10: hold

void Slave::hold(const KURL &url)
{
    if(d->derived)
    { // TODO: clean up before KDE 4
        HoldParams params;
        params.url = &url;
        virtual_hook(VIRTUAL_HOLD, &params);
        return;
    } /*end if*/

    ref();
    {
        QByteArray data;
        QDataStream stream(data, IO_WriteOnly);
        stream << url;
        slaveconn.send(CMD_SLAVE_HOLD, data);
        slaveconn.close();
        dead = true;
        emit slaveDied(this);
    }
    deref();
    // Call KLauncher::waitForSlave(pid);
    {
        DCOPClient *client = kapp->dcopClient();
        if(!client->isAttached())
            client->attach();

        QByteArray params, reply;
        QCString replyType;
        QDataStream stream(params, IO_WriteOnly);
        pid_t pid = m_pid;
        stream << pid;

        QCString launcher = KApplication::launcher();
        client->call(launcher, launcher, "waitForSlave(pid_t)", params, replyType, reply);
    }
}
开发者ID:,项目名称:,代码行数:37,代码来源:

示例11: apply

void KTheme::apply()
{
    kdDebug() << "Going to apply theme: " << m_name << endl;

    QString themeDir = m_kgd->findResourceDir( "themes", m_name + "/" + m_name + ".xml") + m_name + "/";
    kdDebug() << "Theme dir: " << themeDir << endl;

    // 2. Background theme

    QDomNodeList desktopList = m_dom.elementsByTagName( "desktop" );
    KConfig desktopConf( "kdesktoprc" );
    desktopConf.setGroup( "Background Common" );

    for ( uint i = 0; i <= desktopList.count(); i++ )
    {
        QDomElement desktopElem = desktopList.item( i ).toElement();
        if ( !desktopElem.isNull() )
        {
            // TODO optimize, don't write several times the common section
            bool common = static_cast<bool>( desktopElem.attribute( "common", "true" ).toUInt() );
            desktopConf.writeEntry( "CommonDesktop", common );
            desktopConf.writeEntry( "DeskNum", desktopElem.attribute( "number", "0" ).toUInt() );

            desktopConf.setGroup( QString( "Desktop%1" ).arg( i ) );
            desktopConf.writeEntry( "BackgroundMode", getProperty( desktopElem, "mode", "id" ) );
            desktopConf.writeEntry( "Color1", QColor( getProperty( desktopElem, "color1", "rgb" ) ) );
            desktopConf.writeEntry( "Color2", QColor( getProperty( desktopElem, "color2", "rgb" ) ) );
            desktopConf.writeEntry( "BlendMode", getProperty( desktopElem, "blending", "mode" ) );
            desktopConf.writeEntry( "BlendBalance", getProperty( desktopElem, "blending", "balance" ) );
            desktopConf.writeEntry( "ReverseBlending",
                                    static_cast<bool>( getProperty( desktopElem, "blending", "reverse" ).toUInt() ) );
            desktopConf.writeEntry( "Pattern", getProperty( desktopElem, "pattern", "name" ) );
            desktopConf.writeEntry( "Wallpaper",
                                    unprocessFilePath( "desktop", getProperty( desktopElem, "wallpaper", "url" ) ) );
            desktopConf.writeEntry( "WallpaperMode", getProperty( desktopElem, "wallpaper", "mode" ) );

            if ( common )
                break;          // stop here
        }
    }

    // 11. Screensaver
    QDomElement saverElem = m_dom.elementsByTagName( "screensaver" ).item( 0 ).toElement();

    if ( !saverElem.isNull() )
    {
        desktopConf.setGroup( "ScreenSaver" );
        desktopConf.writeEntry( "Saver", saverElem.attribute( "name" ) );
    }

    desktopConf.sync();         // TODO sync and signal only if <desktop> elem present
    // reconfigure kdesktop. kdesktop will notify all clients
    DCOPClient *client = kapp->dcopClient();
    if ( !client->isAttached() )
        client->attach();
    client->send("kdesktop", "KBackgroundIface", "configure()", "");
    // FIXME Xinerama

    // 3. Icons
    QDomElement iconElem = m_dom.elementsByTagName( "icons" ).item( 0 ).toElement();
    if ( !iconElem.isNull() )
    {
        KConfig * iconConf = KGlobal::config();
        iconConf->setGroup( "Icons" );
        iconConf->writeEntry( "Theme", iconElem.attribute( "name", "crystalsvg" ), true, true );

        QDomNodeList iconList = iconElem.childNodes();
        for ( uint i = 0; i < iconList.count(); i++ )
        {
            QDomElement iconSubElem = iconList.item( i ).toElement();
            QString object = iconSubElem.attribute( "object" );
            if ( object == "desktop" )
                iconConf->setGroup( "DesktopIcons" );
            else if ( object == "mainToolbar" )
                iconConf->setGroup( "MainToolbarIcons" );
            else if ( object == "panel" )
                iconConf->setGroup( "PanelIcons" );
            else if ( object == "small" )
                iconConf->setGroup( "SmallIcons" );
            else if ( object == "toolbar" )
                iconConf->setGroup( "ToolbarIcons" );

            QString iconName = iconSubElem.tagName();
            if ( iconName.contains( "Color" ) )
            {
                QColor iconColor = QColor( iconSubElem.attribute( "rgb" ) );
                iconConf->writeEntry( iconName, iconColor, true, true );
            }
            else if ( iconName.contains( "Value" ) || iconName == "Size" )
                iconConf->writeEntry( iconName, iconSubElem.attribute( "value" ).toUInt(), true, true );
            else if ( iconName.contains( "Effect" ) )
                iconConf->writeEntry( iconName, iconSubElem.attribute( "name" ), true, true );
            else
                iconConf->writeEntry( iconName, static_cast<bool>( iconSubElem.attribute( "value" ).toUInt() ), true, true );
        }
        iconConf->sync();

        for ( int i = 0; i < KIcon::LastGroup; i++ )
            KIPC::sendMessageAll( KIPC::IconChanged, i );
        KService::rebuildKSycoca( m_parent );
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例12: aboutData

extern "C" KDE_EXPORT int kdemain(int argc, char **argv)
{
    {
        QCString multiHead = getenv("KDE_MULTIHEAD");
        if(multiHead.lower() == "true")
        {
            Display *dpy = XOpenDisplay(NULL);
            if(!dpy)
            {
                fprintf(stderr, "%s: FATAL ERROR: couldn't open display %s\n", argv[0], XDisplayName(NULL));
                exit(1);
            }

            int number_of_screens = ScreenCount(dpy);
            kicker_screen_number = DefaultScreen(dpy);
            int pos;
            QCString display_name = XDisplayString(dpy);
            XCloseDisplay(dpy);
            dpy = 0;

            if((pos = display_name.findRev('.')) != -1)
                display_name.remove(pos, 10);

            QCString env;
            if(number_of_screens != 1)
            {
                for(int i = 0; i < number_of_screens; i++)
                {
                    if(i != kicker_screen_number && fork() == 0)
                    {
                        kicker_screen_number = i;
                        // break here because we are the child process, we don't
                        // want to fork() anymore
                        break;
                    }
                }

                env.sprintf("DISPLAY=%s.%d", display_name.data(), kicker_screen_number);

                if(putenv(strdup(env.data())))
                {
                    fprintf(stderr, "%s: WARNING: unable to set DISPLAY environment variable\n", argv[0]);
                    perror("putenv()");
                }
            }
        }
    }

    KGlobal::locale()->setMainCatalogue("kicker");

    QCString appname;
    if(kicker_screen_number == 0)
        appname = "kicker";
    else
        appname.sprintf("kicker-screen-%d", kicker_screen_number);

    KAboutData aboutData(appname.data(), I18N_NOOP("KDE Panel"), version, description, KAboutData::License_BSD,
                         I18N_NOOP("(c) 1999-2004, The KDE Team"));

    aboutData.addAuthor("Aaron J. Seigo", I18N_NOOP("Current maintainer"), "[email protected]");
    aboutData.addAuthor("Matthias Elter", 0, "[email protected]");
    aboutData.addAuthor("Matthias Ettrich", 0, "[email protected]");
    aboutData.addAuthor("Wilco Greven", 0, "[email protected]");
    aboutData.addAuthor("Rik Hemsley", 0, "[email protected]");
    aboutData.addAuthor("Daniel M. Duley", 0, "[email protected]");
    aboutData.addAuthor("Preston Brown", 0, "[email protected]");
    aboutData.addAuthor("John Firebaugh", 0, "[email protected]");
    aboutData.addAuthor("Waldo Bastian", I18N_NOOP("Kiosk mode"), "[email protected]");

    aboutData.addCredit("Jessica Hall", /* I18N_NOOP("KConfigXT") */ 0, "[email protected]");
    aboutData.addCredit("Stefan Nikolaus", /* I18N_NOOP("Bug fixes") */ 0, "[email protected]");
    aboutData.addCredit("Benoît Minisini", /* I18N_NOOP("Bug fixes") */ 0, "[email protected]");
    KCmdLineArgs::init(argc, argv, &aboutData);

    if(!Kicker::start())
    {
        kdError() << "kicker is already running!" << endl;
        return 0;
    }

    if(signal(SIGTERM, sighandler) == SIG_IGN)
        signal(SIGTERM, SIG_IGN);
    if(signal(SIGINT, sighandler) == SIG_IGN)
        signal(SIGINT, SIG_IGN);
    if(signal(SIGHUP, sighandler) == SIG_IGN)
        signal(SIGHUP, SIG_IGN);

    // send it even before KApplication ctor, because ksmserver will launch another app as soon
    // as QApplication registers with it
    DCOPClient *cl = new DCOPClient;
    cl->attach();
    DCOPRef r("ksmserver", "ksmserver");
    r.setDCOPClient(cl);
    r.send("suspendStartup", QCString("kicker"));
    delete cl;
    Kicker *kicker = new Kicker;
    int rv = kicker->exec();
    delete kicker;
    return rv;
}
开发者ID:serghei,项目名称:kde3-kdebase,代码行数:100,代码来源:main.cpp

示例13: TDEAboutData

KCMThinkpadModule::KCMThinkpadModule(TQWidget* parent, const char* name, const TQStringList&)
	: TDECModule(KCMThinkpadModuleFactory::instance(), parent, name) {
	TDEAboutData* about =
		new TDEAboutData(I18N_NOOP("kcmthinkpad"),
			       I18N_NOOP("TDE Control Module for IBM Thinkpad "
					 "Laptop Hardware"),
			       0, 0, TDEAboutData::License_GPL,
			       "(c) 2004 Jonathan Riddell");

	about->addAuthor("Jonathan Riddell",
			 I18N_NOOP("Original author"),
			 "[email protected]");
	setAboutData( about );

	TQVBoxLayout* layout = new TQVBoxLayout(this);
	m_KCMThinkpadGeneral = new KCMThinkpadGeneral(this);
	layout->addWidget( m_KCMThinkpadGeneral );
	layout->addStretch();

	load();

	//try and open /dev/nvram
	m_nvramReadable = false;
	m_nvramWriteable = false;

#ifdef Q_OS_FREEBSD
	// Look if the sysctl tree of acpi_ibm is in place
	u_int n = 0;
	size_t len = sizeof(n);
	if (m_nvramReadable = ( sysctlbyname("dev.acpi_ibm.0.volume", &n, &len, NULL, 0) != -1 ))
		m_nvramWriteable = ( sysctlbyname("dev.acpi_ibm.0.volume", NULL, NULL, &n, len) != -1 );

	if (!m_nvramReadable) {
		setButtons(buttons() & ~Default);
		m_KCMThinkpadGeneral->bgGeneral->setEnabled(false);
		m_KCMThinkpadGeneral->tlOff->setText(i18n("In order to use the Thinkpad Buttons KMilo Plugin, "
							  "you have to load the acpi_ibm(4) driver."));
	} else if (!m_nvramWriteable) {
		m_KCMThinkpadGeneral->tlOff->setText(i18n("Could not write to dev.acpi_ibm.0.volume. "
							  "Using software volume, required for "
							  "R30/R31 models, or using a custom volume "
							  "change step is disabled."));
#else
	TQFile nvramFile(m_nvramFile);
	if ( nvramFile.open(IO_ReadOnly) )  {
		m_nvramReadable = true;
		nvramFile.close();
	}
	if ( nvramFile.open(IO_WriteOnly) )  {
		m_nvramWriteable = true;
		nvramFile.close();
	}

	if (!m_nvramReadable) {
            setButtons(buttons() & ~Default);
            m_KCMThinkpadGeneral->bgGeneral->setEnabled(false);
	} else if (!m_nvramWriteable) {
		m_KCMThinkpadGeneral->tlOff->setText(i18n("Could not write to %1. "
							  "To use the software volume, required for "
							  "R30/R31 models and to use a custom volume "
							  "change step, set the nvram device to world "
							  "writeable: <em>chmod 666 "
							  "/dev/nvram</em>").arg(m_nvramFile));
#endif
	} else {
		m_KCMThinkpadGeneral->tlOff->setText(i18n("Thinkpad Buttons KMilo Plugin Ready For Configuration"));
	}

	connect( m_KCMThinkpadGeneral, TQT_SIGNAL(changed()), TQT_SLOT(changed()));

}

void KCMThinkpadModule::save() {
	if (!m_nvramReadable)  {
		return;
	}
	DCOPClient client;

	TDEConfig config(CONFIG_FILE);
	config.setGroup("thinkpad");

	config.writeEntry("run", m_KCMThinkpadGeneral->mCbRun->isChecked());
	config.writeEntry("softwareVolume", m_KCMThinkpadGeneral->mCbSoftwareVolume->isChecked());
	config.writeEntry("volumeStep", m_KCMThinkpadGeneral->mSpinboxVolumeStep->value());
	config.writeEntry("buttonThinkpad", m_KCMThinkpadGeneral->commandExec->url());
	config.writeEntry("buttonHome", m_KCMThinkpadGeneral->commandExecHome->url());
	config.writeEntry("buttonSearch", m_KCMThinkpadGeneral->commandExecSearch->url());
	config.writeEntry("buttonMail", m_KCMThinkpadGeneral->commandExecMail->url());
	config.writeEntry("buttonZoom", m_KCMThinkpadGeneral->commandExecZoom->url());
	config.sync();

	if (client.attach()) {
		TQByteArray data, replyData;
		TQCString replyType;

		if (!client.call("kded", "kmilod", "reconfigure()", data, replyType, replyData))  {
			kdDebug() << "KCMThinkpad::showTextMsg: "
				  << "there was an error using DCOP on kmilod::reconfigure()." << endl;
		}
	} else {
//.........这里部分代码省略.........
开发者ID:Fat-Zer,项目名称:tdeutils,代码行数:101,代码来源:main.cpp

示例14: DataProtocol

Slave *Slave::createSlave(const QString &protocol, const KURL &url, int &error, QString &error_text)
{
    // kdDebug(7002) << "createSlave '" << protocol << "' for " << url.prettyURL() << endl;
    // Firstly take into account all special slaves
    if(protocol == "data")
        return new DataProtocol();

    DCOPClient *client = kapp->dcopClient();
    if(!client->isAttached())
        client->attach();

    QString prefix = locateLocal("socket", KGlobal::instance()->instanceName());
    KTempFile socketfile(prefix, QString::fromLatin1(".slave-socket"));
    if(socketfile.status() != 0)
    {
        error_text = i18n("Unable to create io-slave: %1").arg(strerror(errno));
        error = KIO::ERR_CANNOT_LAUNCH_PROCESS;
        return 0;
    }

#ifdef __CYGWIN__
    socketfile.close();
#endif

    KServerSocket *kss = new KServerSocket(QFile::encodeName(socketfile.name()));

    Slave *slave = new Slave(kss, protocol, socketfile.name());

    // WABA: if the dcopserver is running under another uid we don't ask
    // klauncher for a slave, because the slave might have that other uid
    // as well, which might either be a) undesired or b) make it impossible
    // for the slave to connect to the application.
    // In such case we start the slave via KProcess.
    // It's possible to force this by setting the env. variable
    // KDE_FORK_SLAVES, Clearcase seems to require this.
    static bool bForkSlaves = !QCString(getenv("KDE_FORK_SLAVES")).isEmpty();

    if(bForkSlaves || !client->isAttached() || client->isAttachedToForeignServer())
    {
        QString _name = KProtocolInfo::exec(protocol);
        if(_name.isEmpty())
        {
            error_text = i18n("Unknown protocol '%1'.").arg(protocol);
            error = KIO::ERR_CANNOT_LAUNCH_PROCESS;
            delete slave;
            return 0;
        }
        QString lib_path = KLibLoader::findLibrary(_name.latin1());
        if(lib_path.isEmpty())
        {
            error_text = i18n("Can not find io-slave for protocol '%1'.").arg(protocol);
            error = KIO::ERR_CANNOT_LAUNCH_PROCESS;
            return 0;
        }

        KProcess proc;

        proc << locate("exe", "kioslave") << lib_path << protocol << "" << socketfile.name();
        kdDebug(7002) << "kioslave"
                      << ", " << lib_path << ", " << protocol << ", " << QString::null << ", " << socketfile.name() << endl;

        proc.start(KProcess::DontCare);

        slave->setPID(proc.pid());
        QTimer::singleShot(1000 * SLAVE_CONNECTION_TIMEOUT_MIN, slave, SLOT(timeout()));
        return slave;
    }


    QByteArray params, reply;
    QCString replyType;
    QDataStream stream(params, IO_WriteOnly);
    stream << protocol << url.host() << socketfile.name();

    QCString launcher = KApplication::launcher();
    if(!client->call(launcher, launcher, "requestSlave(QString,QString,QString)", params, replyType, reply))
    {
        error_text = i18n("Cannot talk to klauncher");
        error = KIO::ERR_SLAVE_DEFINED;
        delete slave;
        return 0;
    }
    QDataStream stream2(reply, IO_ReadOnly);
    QString errorStr;
    pid_t pid;
    stream2 >> pid >> errorStr;
    if(!pid)
    {
        error_text = i18n("Unable to create io-slave:\nklauncher said: %1").arg(errorStr);
        error = KIO::ERR_CANNOT_LAUNCH_PROCESS;
        delete slave;
        return 0;
    }

    slave->setPID(pid);
    QTimer::singleShot(1000 * SLAVE_CONNECTION_TIMEOUT_MIN, slave, SLOT(timeout()));

    return slave;
}
开发者ID:,项目名称:,代码行数:99,代码来源:

示例15: ds


//.........这里部分代码省略.........
             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
}
开发者ID:Fat-Zer,项目名称:tdelibs,代码行数:101,代码来源:kuniqueapplication.cpp


注:本文中的DCOPClient::attach方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。