示例#1
0
int main(int argc, char **argv)
{
    // nspluginviewer is a helper app, it shouldn't do session management at all
    setenv("SESSION_MANAGER", "", 1);

    // trap X errors
    kdDebug(1430) << "1 - XSetErrorHandler" << endl;
    XSetErrorHandler(x_errhandler);
    setvbuf(stderr, NULL, _IONBF, 0);

    kdDebug(1430) << "2 - parseCommandLine" << endl;
    parseCommandLine(argc, argv);

#if QT_VERSION < 0x030100
    // Create application
    kdDebug(1430) << "3 - XtToolkitInitialize" << endl;
    XtToolkitInitialize();
    g_appcon = XtCreateApplicationContext();
    Display *dpy = XtOpenDisplay(g_appcon, NULL, "nspluginviewer", "nspluginviewer", 0, 0, &argc, argv);

    _notifiers[0].setAutoDelete(TRUE);
    _notifiers[1].setAutoDelete(TRUE);
    _notifiers[2].setAutoDelete(TRUE);

    kdDebug(1430) << "4 - KXtApplication app" << endl;
    KLocale::setMainCatalogue("nsplugin");
    KXtApplication app(dpy, argc, argv, "nspluginviewer");
#else
    kdDebug(1430) << "3 - create QXtEventLoop" << endl;
    QXtEventLoop integrator("nspluginviewer");
    parseCommandLine(argc, argv);
    KLocale::setMainCatalogue("nsplugin");

    kdDebug(1430) << "4 - create KApplication" << endl;
    KApplication app(argc, argv, "nspluginviewer");
    GlibEvents glibevents;
#endif

    {
        KConfig cfg("kcmnspluginrc", true);
        cfg.setGroup("Misc");
        int v = KCLAMP(cfg.readNumEntry("Nice Level", 0), 0, 19);
        if(v > 0)
        {
            nice(v);
        }
        v = cfg.readNumEntry("Max Memory", 0);
        if(v > 0)
        {
            rlimit rl;
            memset(&rl, 0, sizeof(rl));
            if(0 == getrlimit(RLIMIT_AS, &rl))
            {
                rl.rlim_cur = kMin(v, int(rl.rlim_max));
                setrlimit(RLIMIT_AS, &rl);
            }
        }
    }

    // initialize the dcop client
    kdDebug(1430) << "5 - app.dcopClient" << endl;
    DCOPClient *dcop = app.dcopClient();
    if(!dcop->attach())
    {
        KMessageBox::error(NULL, i18n("There was an error connecting to the Desktop "
                                      "communications server. Please make sure that "
                                      "the 'dcopserver' process has been started, and "
                                      "then try again."),
                           i18n("Error Connecting to DCOP Server"));
        exit(1);
    }

    kdDebug(1430) << "6 - dcop->registerAs" << endl;
    if(g_dcopId)
        g_dcopId = dcop->registerAs(g_dcopId, false);
    else
        g_dcopId = dcop->registerAs("nspluginviewer");

    dcop->setNotifications(true);

    // create dcop interface
    kdDebug(1430) << "7 - new NSPluginViewer" << endl;
    NSPluginViewer *viewer = new NSPluginViewer("viewer", 0);

// start main loop
#if QT_VERSION < 0x030100
    kdDebug(1430) << "8 - XtAppProcessEvent" << endl;
    while(!g_quit)
        XtAppProcessEvent(g_appcon, XtIMAll);
#else
    kdDebug(1430) << "8 - app.exec()" << endl;
    app.exec();
#endif

    // delete viewer
    delete viewer;
}
示例#2
0
void ExtensionProxy::dock(const TQCString& callbackID)
{
    kdDebug(1210) << "Callback ID: " << callbackID << endl;

    _callbackID = callbackID;

    // try to attach to DCOP server
    DCOPClient* dcop = kapp->dcopClient();

    dcop->setNotifications(true);
    connect(dcop, TQT_SIGNAL(applicationRemoved(const TQCString&)),
	    TQT_SLOT(slotApplicationRemoved(const TQCString&)));

    WId win;

    // get docked
    {
	TQCString replyType;
	TQByteArray data, replyData;
	TQDataStream dataStream( data, IO_WriteOnly );

	int actions = 0;
	if(_extension) actions = _extension->actions();
	dataStream << actions;

	int type = 0;
	if (_extension) type = static_cast<int>(_extension->type());
	dataStream << type;

	// we use "call" to know whether it was sucessful

	int screen_number = 0;
	if (tqt_xdisplay())
	    screen_number = DefaultScreen(tqt_xdisplay());
	TQCString appname;
	if (screen_number == 0)
	    appname = "kicker";
	else
	    appname.sprintf("kicker-screen-%d", screen_number);

	if ( !dcop->call(appname, _callbackID, "dockRequest(int,int)",
			 data, replyType, replyData ) )
        {
            kdError() << "Failed to dock into the panel." << endl;
            exit(0);
        }

	TQDataStream reply( replyData, IO_ReadOnly );
	reply >> win;

    }

    if (win) {
        if (_extension)
        {
            _extension->hide();
        }
        QXEmbed::initialize();
        QXEmbed::embedClientIntoWindow( _extension, win );
    }
    else {
        kdError() << "Failed to dock into the panel." << endl;
        if(_extension) delete _extension;
        exit(0);
    }
}