示例#1
0
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;
}
示例#2
0
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;
		}
	}
示例#3
0
// the code was taken from pilotDaemon.cc in KPilot
                                                  // static
OSDWidget::KDesktopLockStatus OSDWidget::isKDesktopLockRunning()
{
    if (!Preferences::oSDCheckDesktopLock())
	return NotLocked;

    DCOPClient *dcopptr = KApplication::kApplication()->dcopClient();

    // Can't tell, very weird
    if (!dcopptr || !dcopptr->isAttached())
    {
        kdWarning() << k_funcinfo << ": Could not make DCOP connection." << endl;
        return DCOPError;
    }

    QByteArray data,returnValue;
    QCString returnType;

    if (!dcopptr->call("kdesktop","KScreensaverIface","isBlanked()",
        data,returnType,returnValue,true))
    {
        // KDesktop is not running. Maybe we are in a KDE4 desktop...
        kdDebug() << k_funcinfo << ": Check for screensaver failed." << endl;
        return DCOPError;
    }

    if (returnType == "bool")
    {
        bool b;
        QDataStream reply(returnValue,IO_ReadOnly);
        reply >> b;
        return (b ? Locked : NotLocked);
    }
示例#4
0
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();
}
示例#5
0
Wallpaper::Wallpaper( QWidget *parent, const char* name )
    : WallpaperDlg( parent, name )
{
    changePaper = true;
    selectedPaper = "";

    QStringList lst = KGlobal::dirs()->findAllResources("wallpaper", "*.desktop", false /* no recursion */, true /* unique files */ );
    QString line,lname,lang,langCode;

    // FIXME: What about other languages?
    lang = QString(getenv("LC_ALL"));
    if (lang == "tr_TR.UTF-8")
        langCode="Name[tr]";
    else
        langCode="Name";

    for(QStringList::Iterator it = lst.begin(); it != lst.end(); ++it)
    {
        if(!(*it).endsWith(".svgz.desktop"))
        {
                QFile desktopFile(*it);
                QTextStream stream(&desktopFile);
                desktopFile.open(IO_ReadOnly);

                bool foundName = false;
                while(!foundName && (line = stream.readLine()))
                {
                    if (line.startsWith(langCode))
                    {
                        lname = line.section("=",1,1);
                        foundName=true;
                    }
                }
            papers.insert(lname, (*it).remove(".desktop"));
            desktopFile.close();
        }
    }

    QMap<QString, QString>::ConstIterator it = papers.begin();
    for(; it != papers.constEnd(); ++it)
        wallpaperBox->insertItem(it.key());

    connect(testButton, SIGNAL(clicked()), this , SLOT(testWallpaper()));
    connect(wallpaperBox, SIGNAL(activated(int)), this, SLOT(paperSelected(int)));
    connect(changeCheck, SIGNAL(toggled(bool)), this, SLOT(optionChanged(bool)));

    emit paperSelected(0);

    // Backup old walpaper name
    DCOPClient *client = kapp->dcopClient();
    QByteArray replyData;
    QCString replyType;

    client->call("kdesktop", "KBackgroundIface", "currentWallpaper(int)", 6, replyType, replyData);
    QDataStream reply(replyData, IO_ReadOnly);
    reply >> oldWallpaper;
}
示例#6
0
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;
}
示例#7
0
static ParseNode f_dcop(Parser*, const ParameterList& params)
{
  QCString appId = params[0].toString().latin1();
  QCString object = params[1].toString().latin1();
  QString function = params[2].toString().section('(', 0, 0);
  QStringList items = QStringList::split(",", params[2].toString().section('(', 1, 1).section(')', 0, 0));
  QByteArray byteData;
  QDataStream byteDataStream(byteData, IO_WriteOnly);

  if (items.count() != params.count() - 3)
  {
     qDebug("Wrong number of parameters");
     return ParseNode();
  }
  int i = 3;
  for (QStringList::Iterator it = items.begin(); it != items.end(); ++it)
  {
    *it = (*it).stripWhiteSpace();
    if (*it == "int")
      byteDataStream << params[i++].toInt();
    else if (*it == "long")
      byteDataStream << params[i++].toInt();
    else if (*it == "float")
      byteDataStream << params[i++].toDouble();
    else if (*it == "double")
      byteDataStream << params[i++].toDouble();
    else if (*it == "bool")
      byteDataStream << (bool)params[i++].toInt();
    else if (*it == "QStringList")
      if (params[i].toString().find('\n') != -1)
        byteDataStream << QStringList::split("\n", params[i++].toString(), true);
      else
        byteDataStream << QStringList::split("\\n", params[i++].toString(), true);
    else 
      byteDataStream << params[i++].toString();
  }
  function.append(QString("(%1)").arg(items.join(",")));
  QCString replyType, byteReply;
  DCOPClient* cl = KApplication::dcopClient();
  if (!cl || !cl->call(appId, object, function.latin1(),
       byteData, replyType, byteReply))
  {
    qDebug("DCOP failure");
    return ParseNode();
  }
  QDataStream byteReplyStream(byteReply, IO_ReadOnly);
  if (replyType == "QString")
  {
    QString text;
    byteReplyStream >> text;
    return text;
  }
示例#8
0
int main(int argc, char *argv[])
{
	KAboutData aboutData( "kmousetool", I18N_NOOP("KMouseTool"),
	KMOUSETOOL_VERSION, description, KAboutData::License_GPL,
	"(c) 2002-2003, Jeff Roush\n(c) 2003, Gunnar Schmi Dt", 0, "http://www.mousetool.com", "*****@*****.**");

	aboutData.addAuthor("Gunnar Schmi Dt", I18N_NOOP("Current maintainer"), "*****@*****.**", "http://www.schmi-dt.de");
	aboutData.addAuthor("Olaf Schmidt", I18N_NOOP("Usability improvements"), "*****@*****.**");
	aboutData.addAuthor("Jeff Roush", I18N_NOOP("Original author"), "*****@*****.**", "http://www.mousetool.com");

	aboutData.addCredit("Joe Betts");
	KCmdLineArgs::init( argc, argv, &aboutData );
	KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
	KUniqueApplication::addCmdLineOptions();

	if (!KUniqueApplication::start()) {
		DCOPClient *client = new DCOPClient();
		client->attach();
		QByteArray  data;
		QCString    replyType;
		QByteArray  replyData;
		if ( !client->call("kmousetool", "qt/KMouseToolUI", "show()",
					data, replyType, replyData, true) ||
			!client->call("kmousetool", "qt/KMouseToolUI", "raise()",
					data, replyType, replyData, true) )
		fprintf(stderr, "The DCOP calls failed\n");
		delete client;
		exit(0);
	}
	KUniqueApplication a;

	KMouseTool *kmousetool = new KMouseTool();

	if (!kapp->config()->readBoolEntry("IsMinimized", false))
		kmousetool->show();

	return a.exec();
}
示例#9
0
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;
    }
示例#10
0
void KcmKRfb::checkKInetd(bool &kinetdAvailable, bool &krfbAvailable) {
    kinetdAvailable = false;
    krfbAvailable = false;

    DCOPClient *d = KApplication::dcopClient();

    QByteArray sdata, rdata;
    QCString replyType;
    QDataStream arg(sdata, IO_WriteOnly);
    arg << QString("krfb");
    if (!d->call ("kded", "kinetd", "isInstalled(QString)", sdata, replyType, rdata))
        return;

    if (replyType != "bool")
        return;

    QDataStream answer(rdata, IO_ReadOnly);
    answer >> krfbAvailable;
    kinetdAvailable = true;
}
示例#11
0
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);
    }
}
示例#12
0
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
}
示例#13
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);
    }
}
示例#14
0
void KHTMLPluginKTTSD::slotReadOut()
{
    // The parent is assumed to be a KHTMLPart
    if(!parent()->inherits("KHTMLPart"))
        QMessageBox::warning(0, i18n("Cannot Read source"), i18n("You cannot read anything except web pages with\n"
                                                                 "this plugin, sorry."));
    else
    {
        // If KTTSD not running, start it.
        DCOPClient *client = kapp->dcopClient();
        if(!client->isApplicationRegistered("kttsd"))
        {
            QString error;
            if(kapp->startServiceByDesktopName("kttsd", QStringList(), &error))
                QMessageBox::warning(0, i18n("Starting KTTSD Failed"), error);
        }

        // Find out if KTTSD supports xhtml (rich speak).
        QByteArray data;
        QBuffer dataBuf(data);
        QDataStream arg;
        dataBuf.open(IO_WriteOnly);
        arg.setDevice(&dataBuf);
        arg << "" << KSpeech::mtHtml;
        QCString replyType;
        QByteArray replyData;
        bool supportsXhtml = false;
        if(!client->call("kttsd", "KSpeech", "supportsMarkup(QString,uint)", data, replyType, replyData, true))
            QMessageBox::warning(0, i18n("DCOP Call Failed"), i18n("The DCOP call supportsMarkup failed."));
        else
        {
            QDataStream reply(replyData, IO_ReadOnly);
            reply >> supportsXhtml;
        }

        KHTMLPart *part = (KHTMLPart *)parent();

        QString query;
        if(supportsXhtml)
        {
            kdDebug() << "KTTS claims to support rich speak (XHTML to SSML)." << endl;
            if(part->hasSelection())
                query = part->selectedTextAsHTML();
            else
            {
                // TODO: Fooling around with the selection probably has unwanted
                // side effects, but until a method is supplied to get valid xhtml
                // from entire document..
                // query = part->document().toString().string();
                part->selectAll();
                query = part->selectedTextAsHTML();
                // Restore no selection.
                part->setSelection(part->document().createRange());
            }
        }
        else
        {
            if(part->hasSelection())
                query = part->selectedText();
            else
                query = part->htmlDocument().body().innerText().string();
        }
        // kdDebug() << "KHTMLPluginKTTSD::slotReadOut: query = " << query << endl;

        dataBuf.at(0); // reset data
        arg << query << "";
        if(!client->call("kttsd", "KSpeech", "setText(QString,QString)", data, replyType, replyData, true))
            QMessageBox::warning(0, i18n("DCOP Call Failed"), i18n("The DCOP call setText failed."));
        dataBuf.at(0);
        arg << 0;
        if(!client->call("kttsd", "KSpeech", "startText(uint)", data, replyType, replyData, true))
            QMessageBox::warning(0, i18n("DCOP Call Failed"), i18n("The DCOP call startText failed."));
    }
}
示例#15
0
文件: main.cpp 项目: Fat-Zer/tdeutils
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"),
			 "*****@*****.**");
	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 {
		kdDebug() << "KCMThinkpadModule: cannot attach to DCOP server, "
			  << "no automatic config update." << endl;
	}
}

void KCMThinkpadModule::load() {
	load( false );
}
示例#16
0
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;
}
示例#17
0
bool UriHandler::process(const QString &uri)
{
    kdDebug(5850) << "UriHandler::process(): " << uri << endl;

#ifndef KORG_NODCOP
    if(uri.startsWith("kmail:"))
    {
        // make sure kmail is running or the part is shown
        kapp->startServiceByDesktopPath("kmail");

        // parse string, show
        int colon = uri.find(':');
        // extract 'number' from 'kmail:<number>/<id>'
        QString serialNumberStr = uri.mid(colon + 1);
        serialNumberStr = serialNumberStr.left(serialNumberStr.find('/'));

        KMailIface_stub kmailIface("kmail", "KMailIface");
        kmailIface.showMail(serialNumberStr.toUInt(), QString());
        return true;
    }
    else if(uri.startsWith("mailto:"))
    {
        KApplication::kApplication()->invokeMailer(uri.mid(7), QString::null);
        return true;
    }
    else if(uri.startsWith("uid:"))
    {
        DCOPClient *client = KApplication::kApplication()->dcopClient();
        const QByteArray noParamData;
        const QByteArray paramData;
        QByteArray replyData;
        QCString replyTypeStr;
        bool foundAbbrowser = client->call("kaddressbook", "KAddressBookIface",
                                           "interfaces()",  noParamData,
                                           replyTypeStr, replyData);
        if(foundAbbrowser)
        {
            //KAddressbook is already running, so just DCOP to it to bring up the contact editor
#if KDE_IS_VERSION( 3, 2, 90 )
            kapp->updateRemoteUserTimestamp("kaddressbook");
#endif
            DCOPRef kaddressbook("kaddressbook", "KAddressBookIface");
            kaddressbook.send("showContactEditor", uri.mid(6));
            return true;
        }
        else
        {
            /*
              KaddressBook is not already running.  Pass it the UID of the contact via the command line while starting it - its neater.
              We start it without its main interface
            */
            QString iconPath = KGlobal::iconLoader()->iconPath("go", KIcon::Small);
            QString tmpStr = "kaddressbook --editor-only --uid ";
            tmpStr += KProcess::quote(uri.mid(6));
            KRun::runCommand(tmpStr, "KAddressBook", iconPath);
            return true;
        }
    }
    else    // no special URI, let KDE handle it
    {
        new KRun(KURL(uri));
    }
#endif

    return false;
}