[Ktutorial-commits] SF.net SVN: ktutorial:[324] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2011-06-12 15:29:33
|
Revision: 324 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=324&view=rev Author: danxuliu Date: 2011-06-12 15:29:27 +0000 (Sun, 12 Jun 2011) Log Message: ----------- Change TargetApplication signals behaviour. Now, finished() signal is only emitted if started() was previously emitted, and startFailed(Error) is now emitted whenever the target application ends before being able to determine if it uses KTutorial or not. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/targetapplication/TargetApplication.cpp trunk/ktutorial/ktutorial-editor/src/targetapplication/TargetApplication.h trunk/ktutorial/ktutorial-editor/src/view/TargetApplicationView.cpp trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/TargetApplicationTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/targetapplication/TargetApplication.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/targetapplication/TargetApplication.cpp 2011-06-10 22:19:57 UTC (rev 323) +++ trunk/ktutorial/ktutorial-editor/src/targetapplication/TargetApplication.cpp 2011-06-12 15:29:27 UTC (rev 324) @@ -202,11 +202,16 @@ } mProcess->kill(); - - emit startFailed(InvalidApplication); } void TargetApplication::clean() { + bool wasStartedSuccessfully = true; + if (!mRemoteEditorSupport) { + wasStartedSuccessfully = false; + + emit startFailed(InvalidApplication); + } + //Don't delete it directly, as waitForFinished crashes somewhere internally //due to an event problem mProcess->deleteLater(); @@ -216,5 +221,7 @@ delete mMapper; mMapper = 0; - emit finished(); + if (wasStartedSuccessfully) { + emit finished(); + } } Modified: trunk/ktutorial/ktutorial-editor/src/targetapplication/TargetApplication.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/targetapplication/TargetApplication.h 2011-06-10 22:19:57 UTC (rev 323) +++ trunk/ktutorial/ktutorial-editor/src/targetapplication/TargetApplication.h 2011-06-12 15:29:27 UTC (rev 324) @@ -42,13 +42,13 @@ * * The TargetApplication can be started using method start(). The method returns * immediately, and when the application is really running the started() signal - * is emitted. If the application could not be executed, or it was executed but - * other problem happened (for example, if the target application does not - * support KTutorial), startFailed(Error) signal is emitted instead. + * is emitted (if it uses KTutorial). If the application could not be executed, + * or it was executed but other problem happened (for example, if the target + * application does not use KTutorial), startFailed(Error) signal is emitted + * instead. * - * Note that started() and startFailed(Error) signals may not be emitted if the - * target application is closed too soon to realize that it was successfully - * started or that it does not support KTutorial. + * Note that startFailed(Error) signal is also emitted if the target application + * is closed too soon to check if it uses KTutorial. * * Once the target application has been started, remoteEditorSupport * returns a RemoteEditorSupport connected to the remote @@ -58,7 +58,8 @@ * The target application will be killed when the TargetApplication is * destroyed, or when the start method is called again after setting a different * application file path. In any of those cases, or if the target application - * was closed externally (by the user), finished() signal is emitted. + * was closed externally (by the user), finished() signal is emitted (but only + * if, preiously, it was successfully started). */ class TargetApplication: public QObject { Q_OBJECT @@ -70,7 +71,7 @@ enum Error { /** - * The application was started, but it does not support KTutorial. + * The application was started, but it does not use KTutorial. */ InvalidApplication, @@ -128,8 +129,9 @@ * Starts a new TargetApplication. * When the target application is running, started() signal is emitted. If * there is no application file path, the application file path is not valid - * or the application does not support KTutorial editor, startFailed(Error) - * signal is emitted instead. + * or the application does not support KTutorial editor (or it was closed + * before being able to determine it), startFailed(Error) signal is emitted + * instead. * * If the target application was already started nothing is done (even * started() signal is not emitted). @@ -139,8 +141,8 @@ Q_SIGNALS: /** - * Emitted when the target application was started and there is a D-Bus - * connection to it. + * Emitted when the target application was started, it uses KTutorial and + * there is a D-Bus connection to it. */ void started(); @@ -152,7 +154,10 @@ void startFailed(TargetApplication::Error error); /** - * Emitted when the target application was finished for any reason. + * Emitted when the target application was finished after being successfully + * started. + * Note that this signal is not emitted, for example, when a target + * application without support for KTutorial is closed. */ void finished(); @@ -177,7 +182,7 @@ * Timer to give time to "/ktutorial" object to appear in the service of * the target application. * If the timer ends and the object was not found, the target application - * seems to not to support KTutorial editor. + * seems to not to use KTutorial editor. */ QTimer mKTutorialSupportModuleDiscoveryTimer; @@ -234,15 +239,16 @@ /** * Called when the time to find the "/ktutorial" object expired. - * Signal startFailed(Error), with InvalidApplication, is emitted in that - * case. + * The target application is killed (which causes signal startFailed(Error), + * with InvalidApplication, to be emitted). */ void handleTargetApplicationDoesNotSupportKTutorial(); /** * Called when the process has finished. - * The process, mapper and remote editor support are deleted, and the - * finished() signal is emitted. + * The process, mapper and remote editor support are deleted. + * startFailed(Error) and finished() signals are emitted, depending on the + * case. */ void clean(); Modified: trunk/ktutorial/ktutorial-editor/src/view/TargetApplicationView.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TargetApplicationView.cpp 2011-06-10 22:19:57 UTC (rev 323) +++ trunk/ktutorial/ktutorial-editor/src/view/TargetApplicationView.cpp 2011-06-12 15:29:27 UTC (rev 324) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -84,15 +84,10 @@ //to show the error message. However, once started the signal must be //disconnected to avoid showing several error messages (for example, if the //target application fails after being started several times by this view). - //finished() is also connected, as if the target application is closed - //before it could be checked whether it supports KTutorial or not, only - //finished() signal is emitted. connect(mTargetApplication, SIGNAL(started()), this, SLOT(stopExpectingTheTargetApplicationToStart())); connect(mTargetApplication, SIGNAL(startFailed(TargetApplication::Error)), this, SLOT(showErrorMessage(TargetApplication::Error))); - connect(mTargetApplication, SIGNAL(finished()), - this, SLOT(stopExpectingTheTargetApplicationToStart())); QApplication::setOverrideCursor(QCursor(Qt::BusyCursor)); } @@ -129,8 +124,6 @@ this, SLOT(stopExpectingTheTargetApplicationToStart())); disconnect(mTargetApplication, SIGNAL(startFailed(TargetApplication::Error)), this, SLOT(showErrorMessage(TargetApplication::Error))); - disconnect(mTargetApplication, SIGNAL(finished()), - this, SLOT(stopExpectingTheTargetApplicationToStart())); QApplication::restoreOverrideCursor(); } Modified: trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/TargetApplicationTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/TargetApplicationTest.cpp 2011-06-10 22:19:57 UTC (rev 323) +++ trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/TargetApplicationTest.cpp 2011-06-12 15:29:27 UTC (rev 324) @@ -406,13 +406,13 @@ TargetApplication targetApplication; targetApplication.setTargetApplicationFilePath(mTargetApplicationStubPath); - QSignalSpy startedSpy(&targetApplication, SIGNAL(started())); //TargetApplication::Error must be registered in order to be used with //QSignalSpy qRegisterMetaType<TargetApplication::Error>("TargetApplication::Error"); - QSignalSpy startFailedSpy(&targetApplication, - SIGNAL(startFailed(TargetApplication::Error))); - SignalWait finishedWait(&targetApplication, SIGNAL(finished())); + SignalWait startFailedWait(&targetApplication, + SIGNAL(startFailed(TargetApplication::Error))); + QSignalSpy startedSpy(&targetApplication, SIGNAL(started())); + QSignalSpy finishedSpy(&targetApplication, SIGNAL(finished())); targetApplication.start(); @@ -422,7 +422,10 @@ targetApplication.mProcess->kill(); - QVERIFY(finishedWait.waitForCount(1, 1000)); + QVERIFY(startFailedWait.waitForCount(1, 1000)); + QVariant argument = startFailedWait.spy().at(0).at(0); + QCOMPARE(qvariant_cast<TargetApplication::Error>(argument), + TargetApplication::InvalidApplication); QVERIFY(!targetApplication.remoteEditorSupport()); //Keep waiting until the timeout expires to ensure that no other signal is @@ -430,7 +433,8 @@ QTest::qWait(3000); QCOMPARE(startedSpy.count(), 0); - QCOMPARE(startFailedSpy.count(), 0); + QCOMPARE(startFailedWait.spy().count(), 1); + QCOMPARE(finishedSpy.count(), 0); } void TargetApplicationTest:: @@ -439,13 +443,13 @@ targetApplication.setTargetApplicationFilePath( QApplication::applicationDirPath() + "/DummyApplication"); - QSignalSpy startedSpy(&targetApplication, SIGNAL(started())); //TargetApplication::Error must be registered in order to be used with //QSignalSpy qRegisterMetaType<TargetApplication::Error>("TargetApplication::Error"); - QSignalSpy startFailedSpy(&targetApplication, - SIGNAL(startFailed(TargetApplication::Error))); - SignalWait finishedWait(&targetApplication, SIGNAL(finished())); + SignalWait startFailedWait(&targetApplication, + SIGNAL(startFailed(TargetApplication::Error))); + QSignalSpy startedSpy(&targetApplication, SIGNAL(started())); + QSignalSpy finishedSpy(&targetApplication, SIGNAL(finished())); targetApplication.start(); @@ -455,7 +459,10 @@ targetApplication.mProcess->kill(); - QVERIFY(finishedWait.waitForCount(1, 1000)); + QVERIFY(startFailedWait.waitForCount(1, 1000)); + QVariant argument = startFailedWait.spy().at(0).at(0); + QCOMPARE(qvariant_cast<TargetApplication::Error>(argument), + TargetApplication::InvalidApplication); QVERIFY(!targetApplication.remoteEditorSupport()); //Keep waiting until the timeout expires to ensure that no other signal is @@ -463,7 +470,8 @@ QTest::qWait(3000); QCOMPARE(startedSpy.count(), 0); - QCOMPARE(startFailedSpy.count(), 0); + QCOMPARE(startFailedWait.spy().count(), 1); + QCOMPARE(finishedSpy.count(), 0); } QTEST_MAIN(TargetApplicationTest) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |