Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.
Closing a dialog after a timeout using Symbian C++
This code snippet shows how to create a dialog that will close after a specified amount of time. Obviously the actually closing of the dialog can be made dependent on other factors including for example when the inactivity timer times out.
There are three header files, one for the timer interface, one for the timer and one for the dialog that implements the timer interface.
First the interface for the timer to callback on when the timer expires. This will be implemented by observers who need to know when the timer condition has been met
virtual void HandleTimedOut() = 0;
Next the timer object it self which will call the MTimerCallback interface above when the timer expires
class CTimerCallback : public CTimer
static CTimerCallback* NewL(MTimerCallback& aCallback);
Finally we have dialog that will be requesting information from the user and will be closed automatically when the timer fires
: public CAknTextQueryDialog, public MTimerCallback
static CSymbianExampleQueryDialog* NewL(TDes& aDataText);
public: // CAknTextQueryDialog
The code for the timer looks like any other timer implementation.
This particular implementation starts the timer when the object is constructed since it results in less code all round for the example.
static CTimerCallback* CTimerCallback::NewL(MTimerCallback& aCallback)
CTimerCallback* self = new (ELeave) CTimerCallback(aCallback);
// TODO: Your own conditions such as At or Inactivity for example
// This example hardcodes 5 seconds
const TTimeIntervalMicroSeconds32 KFiveSeconds(5 * 1000000);
// TODO: Handle error conditions such as clock skew adjustment
// and time changes
The final "glue" to hold it all together is the implementation of the dialog To make this simple, the provided code just inherits from CAknTextQueryDialog
This is where the "magic" happens. When the dialog is constructed, the timer is also started (as above with a 5 second timeout). The implementation of the MTimerCallback inteface is also passed to the timer and so when the timer expires the HandleTimedOut method is called and this just calls TryExitL to exit the dialog asynchronously
CSymbianExampleQueryDialog* CSymbianExampleQueryDialog::NewL(TDes& aDataText)
CSymbianExampleQueryDialog* self = new (ELeave) CSymbianExampleQueryDialog(aDataText);
iCallBack = NULL;
iCallBack = CTimerCallback::NewL(*this);
The dialog will be closed when the timer expires