From kde-core-devel Wed Mar 02 23:10:14 2005 From: Albert Astals Cid Date: Wed, 02 Mar 2005 23:10:14 +0000 To: kde-core-devel Subject: [PATCH] KPDF don't start kttsd each time Message-Id: <200503030010.14989.astals11 () terra ! es> X-MARC-Message: https://marc.info/?l=kde-core-devel&m=110980503112105 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary-00=_WfkJCuVNRqkqFzZ" --Boundary-00=_WfkJCuVNRqkqFzZ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi Gary Cramblitt (kttsd author) sent me this patch to kpdf to improve the= =20 current usage we make of kttsd. Currently we start kttsd each time if it ha= s=20 not been started yet to see if we can use it, that has some problems. - No need to start it to know if we can use it, just ask ktrader, so we sa= ve=20 a few user's resources if the user does not want to use kttsd. - Second and maybe =BFmore important?, people using Klax get that behaviou= r: - Start kpdf - kpdf starts kttsd - kttsd realizes it has not been configured and asks to be configured b= ut=20 it can't be configured as there is no spped synthesizer available - That cycle repeats each time kpdf is launched That can potentially mean bad reviews from [bad] reviewers so as the patch = is=20 quite clear i would like to ask permission to backport to the 3.4 branch Albert --Boundary-00=_WfkJCuVNRqkqFzZ Content-Type: text/x-diff; charset="iso-8859-1"; name="kpdf_kttsd.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="kpdf_kttsd.patch" ? COSAS ? kpdf_kttsd.patch Index: part.cpp =================================================================== RCS file: /home/kde/kdegraphics/kpdf/part.cpp,v retrieving revision 1.28 diff -u -r1.28 part.cpp --- part.cpp 19 Feb 2005 13:04:40 -0000 1.28 +++ part.cpp 2 Mar 2005 23:03:19 -0000 @@ -49,6 +49,7 @@ #include #include #include +#include // local includes #include "xpdf/GlobalParams.h" @@ -251,10 +252,8 @@ connect( m_dirtyHandler, SIGNAL( timeout() ),this, SLOT( slotDoFileDirty() ) ); // [SPEECH] check for KTTSD presence and usability - Settings::setUseKTTSD( true ); - if ( !kapp->dcopClient()->isApplicationRegistered("kttsd") ) - if ( KApplication::startServiceByDesktopName( "kttsd" ) ) - Settings::setUseKTTSD( false ); + KTrader::OfferList offers = KTrader::self()->query("DCOP/Text-to-Speech", "Name == 'KTTSD'"); + Settings::setUseKTTSD( (offers.count() > 0) ); // set our XML-UI resource file setXMLFile("part.rc"); Index: ui/pageview.cpp =================================================================== RCS file: /home/kde/kdegraphics/kpdf/ui/pageview.cpp,v retrieving revision 1.45 diff -u -r1.45 pageview.cpp --- ui/pageview.cpp 1 Mar 2005 18:43:47 -0000 1.45 +++ ui/pageview.cpp 2 Mar 2005 23:03:31 -0000 @@ -35,6 +35,7 @@ #include #include #include +#include #include // system includes @@ -1039,23 +1040,40 @@ DCOPClient * client = DCOPClient::mainClient(); // Albert says is this ever necessary? // we already attached on Part constructor - if ( !client->isAttached() ) - client->attach(); - // serialize the text to speech (selectedText) and the - // preferred reader ("" is the default voice) ... - QByteArray data; - QDataStream arg( data, IO_WriteOnly ); - arg << selectedText; - arg << QString(); - QCString replyType; - QByteArray replyData; - // ..and send it to KTTSD - if (client->call( "kttsd", "KSpeech", "setText(QString,QString)", data, replyType, replyData, true )) + // if ( !client->isAttached() ) + // client->attach(); + // If KTTSD not running, start it. + if (!client->isApplicationRegistered("kttsd")) { - QByteArray data2; - QDataStream arg2(data2, IO_WriteOnly); - arg2 << 0; - client->send("kttsd", "KSpeech", "startText(uint)", data2 ); + QString error; + if (KApplication::startServiceByDesktopName("kttsd", QStringList(), &error)) + { + // FIXME: Since this will be backported to KDE 3.4 branch, don't display + // error message as this would add a translated string. + // Use kdebug for now. + // d->messageWindow->display( i18n( "Starting KTTSD Failed") ) + kdDebug() << "Starting KTTSD Failed" << endl; + Settings::setUseKTTSD(false); + } + } + if ( Settings::useKTTSD() ) + { + // serialize the text to speech (selectedText) and the + // preferred reader ("" is the default voice) ... + QByteArray data; + QDataStream arg( data, IO_WriteOnly ); + arg << selectedText; + arg << QString(); + QCString replyType; + QByteArray replyData; + // ..and send it to KTTSD + if (client->call( "kttsd", "KSpeech", "setText(QString,QString)", data, replyType, replyData, true )) + { + QByteArray data2; + QDataStream arg2(data2, IO_WriteOnly); + arg2 << 0; + client->send("kttsd", "KSpeech", "startText(uint)", data2 ); + } } } } --Boundary-00=_WfkJCuVNRqkqFzZ--