|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "nmuiengineheaders.h" |
|
19 |
|
20 #include <QTimer> |
|
21 |
|
22 /*! |
|
23 \brief Constructor |
|
24 Constructor of NmOperation |
|
25 \param parent Parent object. |
|
26 */ |
|
27 NmOperation::NmOperation(QObject *parent) |
|
28 : QObject(parent), |
|
29 mProgress(0), |
|
30 mIsRunning(true) |
|
31 { |
|
32 // operation is started immediately |
|
33 mTimer = new QTimer(this); |
|
34 mTimer->setSingleShot(TRUE); |
|
35 connect(mTimer, SIGNAL(timeout()), this, SLOT(runAsyncOperation())); |
|
36 mTimer->start(1); |
|
37 } |
|
38 |
|
39 /*! |
|
40 \brief Destructor |
|
41 Does nothing |
|
42 */ |
|
43 NmOperation::~NmOperation() |
|
44 { |
|
45 } |
|
46 |
|
47 /*! |
|
48 \brief Tells whether the operation is running or not |
|
49 */ |
|
50 bool NmOperation::isRunning() const |
|
51 { |
|
52 return mIsRunning; |
|
53 } |
|
54 |
|
55 /*! |
|
56 \brief Slot, complete |
|
57 The performer of the asynchronous function call should use this slot when |
|
58 the operation is completed, this will emit the actionCompleted signal * |
|
59 \param result Result from operation |
|
60 */ |
|
61 void NmOperation::completeOperation(int result) |
|
62 { |
|
63 // Operation is completed, emit the signal |
|
64 doCompleteOperation(); |
|
65 emit this->operationCompleted(result); |
|
66 mIsRunning = false; |
|
67 } |
|
68 |
|
69 /*! |
|
70 \brief Slot, cancel |
|
71 The observer of the asynchronous function call should use this slot if it |
|
72 wants to cancel the ongoing operation, it will emit the actionCancelled signal |
|
73 */ |
|
74 void NmOperation::cancelOperation() |
|
75 { |
|
76 // Operation is canceled, emit the signal |
|
77 mTimer->stop(); |
|
78 this->doCancelOperation(); |
|
79 emit this->operationCancelled(); |
|
80 mIsRunning = false; |
|
81 } |
|
82 /*! |
|
83 \brief Slot, update progress |
|
84 The performer of the asynchronous function call should use this slot when |
|
85 updating the operation progress, this will emit the progressChanged signal |
|
86 */ |
|
87 void NmOperation::updateOperationProgress(int progress) |
|
88 { |
|
89 mProgress = progress; |
|
90 this->doUpdateOperationProgress(); |
|
91 emit this->operationProgressChanged(mProgress); |
|
92 } |
|
93 |
|
94 /*! |
|
95 \brief Virtual function to be implemented by subclasses |
|
96 This function is called from the completeAction before the signal is |
|
97 emitted. Derived class can override this is some special actions |
|
98 are needed. |
|
99 */ |
|
100 void NmOperation::doCompleteOperation() |
|
101 { |
|
102 |
|
103 } |
|
104 |
|
105 /*! |
|
106 \brief Virtual function to be implemented by subclasses |
|
107 This function is called from the cancelAction after the trigger timer |
|
108 and before the signal is emitted. Derived class can override this |
|
109 and put its own cancellation operations here. |
|
110 */ |
|
111 void NmOperation::doCancelOperation() |
|
112 { |
|
113 } |
|
114 |
|
115 /*! |
|
116 \brief Virtual function to be implemented by subclasses |
|
117 This function is called from the updateProgress after the progress |
|
118 value has been updated and before the signal is emitted. Derived class |
|
119 can override this. |
|
120 */ |
|
121 void NmOperation::doUpdateOperationProgress() |
|
122 { |
|
123 } |
|
124 |
|
125 |