[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    [PATCH] KPDF don't start kttsd each time
From:       Albert Astals Cid <astals11 () terra ! es>
Date:       2005-03-02 23:10:14
Message-ID: 200503030010.14989.astals11 () terra ! es
[Download RAW message or body]

Hi Gary Cramblitt (kttsd author) sent me this patch to kpdf to improve the 
current usage we make of kttsd. Currently we start kttsd each time if it has 
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 save 
a few user's resources if the user does not want to use kttsd.
 - Second and maybe ¿more important?, people using Klax get that behaviour:
    - Start kpdf
    - kpdf starts kttsd
    - kttsd realizes it has not been configured and asks to be configured but 
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 
quite clear i would like to ask permission to backport to the 3.4 branch

Albert

["kpdf_kttsd.patch" (text/x-diff)]

? 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 <kpopupmenu.h>
 #include <kxmlguiclient.h>
 #include <kxmlguifactory.h>
+#include <ktrader.h>
 
 // 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 <kfiledialog.h>
 #include <kimageeffect.h>
 #include <kimageio.h>
+#include <kapplication.h>
 #include <kdebug.h>
 
 // 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 ); +                        }
                     }
                 }
             }



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic