示例#1
0
static void continueInWindow(QString _wname)
{
    QCString wname = _wname.latin1();
    int id = -1;

    KStringList apps = kapp->dcopClient()->registeredApplications();
    for(KStringList::Iterator it = apps.begin(); it != apps.end(); ++it)
    {
        QCString &clientId = *it;

        if(qstrncmp(clientId, wname, wname.length()) != 0)
            continue;

        DCOPRef client(clientId.data(), wname + "-mainwindow#1");
        DCOPReply result = client.call("getWinID()");

        if(result.isValid())
        {
            id = (int)result;
            break;
        }
    }

    KWin::activateWindow(id);
}
void KopeteApplication::slotAllPluginsLoaded()
{
	KCmdLineArgs *args = KCmdLineArgs::parsedArgs();

	// --noconnect not specified?
	if ( args->isSet( "connect" )  && KopetePrefs::prefs()->autoConnect() )
		Kopete::AccountManager::self()->connectAll();


	// Handle things like '--autoconnect foo,bar --autoconnect foobar'
	KStringList connectArgsC = args->getOptionList( "autoconnect" );
	QStringList connectArgs;

	for ( KStringList::ConstIterator it = connectArgsC.begin(); it != connectArgsC.end(); ++it )
	{
		QStringList split = QStringList::split( ',', QString::fromLatin1( *it ) );

		for ( QStringList::ConstIterator it2 = split.begin(); it2 != split.end(); ++it2 )
		{
			connectArgs.append( *it2 );
		}
	}
	
	for ( QStringList::ConstIterator i = connectArgs.begin(); i != connectArgs.end(); ++i )
	{
		QRegExp rx( QString::fromLatin1( "([^\\|]*)\\|\\|(.*)" ) );
		rx.search( *i );
		QString protocolId = rx.cap( 1 );
		QString accountId = rx.cap( 2 );

		if ( accountId.isEmpty() )
		{
			if ( protocolId.isEmpty() )
				accountId = *i;
			else
				continue;
		}

		QPtrListIterator<Kopete::Account> it( Kopete::AccountManager::self()->accounts() );
		Kopete::Account *account;
		while ( ( account = it.current() ) != 0 )
		{
			++it;

			if ( ( account->accountId() == accountId ) )
			{
				if ( protocolId.isEmpty() || account->protocol()->pluginId() == protocolId )
				{
					account->connect();
					break;
				}
			}
		}
	}

	// Parse any passed URLs/files
	handleURLArgs();
}
示例#3
0
int KDEsuClient::exec(const QCString &prog, const QCString &user, const QCString &options, const KStringList &env)
{
    QCString cmd;
    cmd = "EXEC ";
    cmd += escape(prog);
    cmd += " ";
    cmd += escape(user);
    if(!options.isEmpty() || !env.isEmpty())
    {
        cmd += " ";
        cmd += escape(options);
        for(KStringList::ConstIterator it = env.begin(); it != env.end(); ++it)
        {
            cmd += " ";
            cmd += escape(*it);
        }
    }
    cmd += "\n";
    return command(cmd);
}
示例#4
0
int Application::newInstance()
{
    if(!isRestored())
    {
        DCOPRef akr("akregator", "AkregatorIface");

        KCmdLineArgs *args = KCmdLineArgs::parsedArgs();

        if(!mMainWindow)
        {
            mMainWindow = new Akregator::MainWindow();
            setMainWidget(mMainWindow);
            mMainWindow->loadPart();
            mMainWindow->setupProgressWidgets();
            if(!args->isSet("hide-mainwindow"))
                mMainWindow->show();
            akr.send("openStandardFeedList");
        }

        QString addFeedGroup = !args->getOption("group").isEmpty()
                               ? QString::fromLocal8Bit(args->getOption("group"))
                               : i18n("Imported Folder");

        KStringList feeds = args->getOptionList("addfeed");
        QStringList feedsToAdd;
        KStringList::ConstIterator end(feeds.end());
        for(KStringList::ConstIterator it = feeds.begin(); it != end; ++it)
            feedsToAdd.append(*it);

        if(!feedsToAdd.isEmpty())
            akr.send("addFeedsToGroup", feedsToAdd, addFeedGroup);

        args->clear();
    }
    return KUniqueApplication::newInstance();
}
示例#5
0
void PrintWrapper::slotPrint()
{
    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();

#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
    struct sigaction action;
#endif /* HAVE_SIGACTION && !HAVE_SIGSET*/

    // read variables from command line
    QString printer = args->getOption("d");
    QString title = args->getOption("t");
    int ncopies = QString(args->getOption("n")).toInt();
    QString job_mode = args->getOption("j");
    QString system = args->getOption("system");
    KStringList optlist = args->getOptionList("o");
    QMap< QString, QString > opts;
    KURL::List files;
    QStringList filestoprint;
    force_stdin = args->isSet("stdin");
    docopy = args->isSet("c");
    bool nodialog = !(args->isSet("dialog"));

    if(isatty(0))
    {
        kdDebug(500) << "stdin is a terminal, disabling it" << endl;
        check_stdin = false;
    }

    // parse options
    for(KStringList::ConstIterator it = optlist.begin(); it != optlist.end(); ++it)
    {
        QStringList l = QStringList::split('=', QString(*it), false);
        if(l.count() >= 1)
            opts[l[0]] = (l.count() == 2 ? l[1] : QString::null);
    }

    // read file list
    for(int i = 0; i < args->count(); i++)
        files.append(args->url(i));

    // some clean-up
    args->clear();

    // set default values if necessary
    if(job_mode == "console")
        job_output = 1;
    else if(job_mode == "none")
        job_output = 2;
    else
        job_output = 0;

    // some checking
    if(files.count() > 0)
    {
        check_stdin = false;

        if(force_stdin)
        {
            showmsg(i18n("A file has been specified on the command line. Printing from STDIN will be disabled."), 1);
            force_stdin = false;
        }
    }
    if(nodialog && files.count() == 0 && !force_stdin && !check_stdin)
    {
        errormsg(i18n("When using '--nodialog', you must at least specify one file to print or use the '--stdin' flag."));
    }

    if(check_stdin)
    { // check if there's any input on stdin
        fd_set in;
        struct timeval tm;
        tm.tv_sec = 0;
        tm.tv_usec = 0;
        FD_ZERO(&in);
        FD_SET(0, &in);
        if(select(1, &in, NULL, NULL, &tm))
        { // we have data on stdin
            if(read(0, &readchar, 1) > 0)
            {
                force_stdin = true;
                check_stdin = false;
                dataread = true;
                kdDebug(500) << "input detected on stdin" << endl;
            }
            else
            {
                force_stdin = check_stdin = false;
                kdDebug(500) << "stdin closed and empty" << endl;
            }
        }
        else
            kdDebug(500) << "no input on stdin at startup" << endl;
    }

    // force_stdin ? or also check_stdin ?
    KPrinter::ApplicationType dialog_mode = (force_stdin || nodialog ? KPrinter::StandAlone : KPrinter::StandAlonePersistent);
    KPrinter::setApplicationType(dialog_mode);
    if(!force_stdin)
        KPrinter::addStandardPage(KPrinter::FilesPage);

    KPrinter kprinter;
    if(nodialog)
    {
        KMPrinter *prt(0);
        KMManager *mgr = KMManager::self();

        mgr->printerList(false);
        if(!printer.isEmpty())
            prt = mgr->findPrinter(printer);
        else
            prt = mgr->defaultPrinter();

        if(prt == 0)
            errormsg(i18n("The specified printer or the default printer could not be found."));
        else if(!prt->autoConfigure(&kprinter))
            errormsg(i18n("Operation aborted."));
    }
    else if(!printer.isEmpty())
        kprinter.setSearchName(printer);
    kprinter.setDocName(title);
    kprinter.initOptions(opts);
    kprinter.setOption("kde-filelist", files.toStringList().join("@@"));
    kdDebug(500) << kprinter.option("kde-filelist") << endl;
    if(ncopies > 0)
        kprinter.setNumCopies(ncopies);

    if(nodialog)
        slotPrintRequested(&kprinter);
    else
    {
        dlg = KPrintDialog::printerDialog(&kprinter, 0);
        if(dlg)
        {
            connect(dlg, SIGNAL(printRequested(KPrinter *)), SLOT(slotPrintRequested(KPrinter *)));
            if(check_stdin)
            {
                notif = new QSocketNotifier(0, QSocketNotifier::Read, this);
                connect(notif, SIGNAL(activated(int)), this, SLOT(slotGotStdin()));
                kdDebug(500) << "waiting for input on stdin" << endl;
            }
            dlg->exec();
            delete dlg;
        }
        else
            errormsg(i18n("Unable to construct the print dialog."));
    }
示例#6
0
/**
 * Do the actual DCOP call
 */
int runDCOP(KStringList args, UserList users, Session session, const QString sessionName, bool readStdin, bool updateUserTime)
{
    bool DCOPrefmode = false;
    QCString app;
    QCString objid;
    QCString function;
    KStringList params;
    DCOPClient *client = 0L;
    int retval = 0;
    if(!args.isEmpty() && args[0].find("DCOPRef(") == 0)
    {
        int delimPos = args[0].findRev(',');
        if(delimPos == -1)
        {
            cerr_ << "Error: '" << args[0] << "' is not a valid DCOP reference." << endl;
            exit(-1);
        }
        app = args[0].mid(8, delimPos - 8);
        delimPos++;
        objid = args[0].mid(delimPos, args[0].length() - delimPos - 1);
        if(args.count() > 1)
            function = args[1];
        if(args.count() > 2)
        {
            params = args;
            params.remove(params.begin());
            params.remove(params.begin());
        }
        DCOPrefmode = true;
    }
    else
    {
        if(!args.isEmpty())
            app = args[0];
        if(args.count() > 1)
            objid = args[1];
        if(args.count() > 2)
            function = args[2];
        if(args.count() > 3)
        {
            params = args;
            params.remove(params.begin());
            params.remove(params.begin());
            params.remove(params.begin());
        }
    }

    bool firstRun = true;
    UserList::Iterator it;
    QStringList sessions;
    bool presetDCOPServer = false;
    //    char *dcopStr = 0L;
    QString dcopServer;

    for(it = users.begin(); it != users.end() || firstRun; ++it)
    {
        firstRun = false;

        // cout_ << "Iterating '" << it.key() << "'" << endl;

        if(session == QuerySessions)
        {
            QStringList sessions = dcopSessionList(it.key(), it.data());
            if(sessions.isEmpty())
            {
                if(users.count() <= 1)
                {
                    cout_ << "No active sessions";
                    if(!(*it).isEmpty())
                        cout_ << " for user " << *it;
                    cout_ << endl;
                }
            }
            else
            {
                cout_ << "Active sessions ";
                if(!(*it).isEmpty())
                    cout_ << "for user " << *it << " ";
                cout_ << ":" << endl;

                QStringList::Iterator sIt = sessions.begin();
                for(; sIt != sessions.end(); ++sIt)
                    cout_ << "  " << *sIt << endl;

                cout_ << endl;
            }
            continue;
        }

        if(getenv("DCOPSERVER"))
        {
            sessions.append(getenv("DCOPSERVER"));
            presetDCOPServer = true;
        }

        if(users.count() > 1 || (users.count() == 1 && (getenv("DCOPSERVER") == 0 /*&& getenv( "DISPLAY" ) == 0*/)))
        {
            sessions = dcopSessionList(it.key(), it.data());
            if(sessions.isEmpty())
            {
                if(users.count() > 1)
                    continue;
                else
                {
                    cerr_ << "ERROR: No active KDE sessions!" << endl
                          << "If you are sure there is one, please set the $DCOPSERVER variable manually" << endl
                          << "before calling dcop." << endl;
                    exit(-1);
                }
            }
            else if(!sessionName.isEmpty())
            {
                if(sessions.contains(sessionName))
                {
                    sessions.clear();
                    sessions.append(sessionName);
                }
                else
                {
                    cerr_ << "ERROR: The specified session doesn't exist!" << endl;
                    exit(-1);
                }
            }
            else if(sessions.count() > 1 && session != AllSessions)
            {
                cerr_ << "ERROR: Multiple available KDE sessions!" << endl
                      << "Please specify the correct session to use with --session or use the" << endl
                      << "--all-sessions option to broadcast to all sessions." << endl;
                exit(-1);
            }
        }

        if(users.count() > 1 || (users.count() == 1 && (getenv("ICEAUTHORITY") == 0 || getenv("DISPLAY") == 0)))
        {
            // Check for ICE authority file and if the file can be read by us
            QString home = it.data();
            QString iceFile = it.data() + "/.ICEauthority";
            QFileInfo fi(iceFile);
            if(iceFile.isEmpty())
            {
                cerr_ << "WARNING: Cannot determine home directory for user " << it.key() << "!" << endl
                      << "Please check permissions or set the $ICEAUTHORITY variable manually before" << endl
                      << "calling dcop." << endl;
            }
            else if(fi.exists())
            {
                if(fi.isReadable())
                {
                    char *envStr = strdup(("ICEAUTHORITY=" + iceFile).ascii());
                    putenv(envStr);
                    // cerr_ << "ice: " << envStr << endl;
                }
                else
                {
                    cerr_ << "WARNING: ICE authority file " << iceFile << "is not readable by you!" << endl
                          << "Please check permissions or set the $ICEAUTHORITY variable manually before" << endl
                          << "calling dcop." << endl;
                }
            }
            else
            {
                if(users.count() > 1)
                    continue;
                else
                {
                    cerr_ << "WARNING: Cannot find ICE authority file " << iceFile << "!" << endl
                          << "Please check permissions or set the $ICEAUTHORITY"
                          << " variable manually before" << endl
                          << "calling dcop." << endl;
                }
            }
        }

        // Main loop
        // If users is an empty list we're calling for the currently logged
        // in user. In this case we don't have a session, but still want
        // to iterate the loop once.
        QStringList::Iterator sIt = sessions.begin();
        for(; sIt != sessions.end() || users.isEmpty(); ++sIt)
        {
            if(!presetDCOPServer && !users.isEmpty())
            {
                QString dcopFile = it.data() + "/" + *sIt;
                QFile f(dcopFile);
                if(!f.open(IO_ReadOnly))
                {
                    cerr_ << "Can't open " << dcopFile << " for reading!" << endl;
                    exit(-1);
                }

                QStringList l(QStringList::split('\n', f.readAll()));
                dcopServer = l.first();

                if(dcopServer.isEmpty())
                {
                    cerr_ << "WARNING: Unable to determine DCOP server for session " << *sIt << "!" << endl
                          << "Please check permissions or set the $DCOPSERVER variable manually before" << endl
                          << "calling dcop." << endl;
                    exit(-1);
                }
            }

            delete client;
            client = new DCOPClient;
            if(!dcopServer.isEmpty())
                client->setServerAddress(dcopServer.ascii());
            bool success = client->attach();
            if(!success)
            {
                cerr_ << "ERROR: Couldn't attach to DCOP server!" << endl;
                retval = QMAX(retval, 1);
                if(users.isEmpty())
                    break;
                else
                    continue;
            }
            dcop = client;

            int argscount = args.count();
            if(DCOPrefmode)
                argscount++;
            switch(argscount)
            {
                case 0:
                    queryApplications("");
                    break;
                case 1:
                    if(endsWith(app, '*'))
                        queryApplications(app);
                    else
                        queryObjects(app, "");
                    break;
                case 2:
                    if(endsWith(objid, '*'))
                        queryObjects(app, objid);
                    else
                        queryFunctions(app, objid);
                    break;
                case 3:
                default:
                    if(updateUserTime)
                        sendUserTime(app);
                    if(readStdin)
                    {
                        KStringList::Iterator replaceArg = params.end();

                        KStringList::Iterator it = params.begin();
                        for(; it != params.end(); ++it)
                            if(*it == "%1")
                                replaceArg = it;

                        // Read from stdin until EOF and call function for each
                        // read line
                        while(!cin_.atEnd())
                        {
                            QString buf = cin_.readLine();

                            if(replaceArg != params.end())
                                *replaceArg = buf.local8Bit();

                            if(!buf.isNull())
                            {
                                int res = callFunction(app, objid, function, params);
                                retval = QMAX(retval, res);
                            }
                        }
                    }
                    else
                    {
                        // Just call function
                        //		    cout_ << "call " << app << ", " << objid << ", " << function << ", (params)" << endl;
                        int res = callFunction(app, objid, function, params);
                        retval = QMAX(retval, res);
                    }
                    break;
            }
            // Another sIt++ would make the loop infinite...
            if(users.isEmpty())
                break;
        }

        // Another it++ would make the loop infinite...
        if(it == users.end())
            break;
    }

    return retval;
}