22 #include <hbaction.h> |
22 #include <hbaction.h> |
23 #include <hbdialog.h> |
23 #include <hbdialog.h> |
24 #include <hbmainwindow.h> |
24 #include <hbmainwindow.h> |
25 #include <hbdatetimepicker.h> |
25 #include <hbdatetimepicker.h> |
26 #include <vwsdef.h> |
26 #include <vwsdef.h> |
|
27 #include <hbactivitymanager.h> //Activity Manager |
|
28 #include <hbapplication.h> //hbapplication |
27 |
29 |
28 //user includes |
30 //user includes |
29 #include <CalenUid.h> |
31 #include <CalenUid.h> |
30 #include "calennativeview.h" |
32 #include "calennativeview.h" |
31 #include "calenservices.h" |
33 #include "calenservices.h" |
32 #include "calencontext.h" |
34 #include "calencontext.h" |
33 #include "calensettingsview.h" |
35 #include "calensettingsview.h" |
34 #include "calendateutils.h" |
36 #include "calendateutils.h" |
|
37 #include "calenconstants.h" |
35 |
38 |
36 /*! |
39 /*! |
37 \class CalenNativeView |
40 \class CalenNativeView |
38 Base class for all calendar views |
41 Base class for all calendar views |
39 */ |
42 */ |
40 |
43 |
41 /*! |
44 /*! |
42 Default constructor. |
45 Default constructor. |
43 */ |
46 */ |
44 CalenNativeView::CalenNativeView(MCalenServices &services) : |
47 CalenNativeView::CalenNativeView(MCalenServices &services) : |
45 mServices(services) |
48 mServices(services), mIsCapturedScreenShotValid(false) |
46 { |
49 { |
47 setTitle(hbTrId("txt_calendar_title_calendar")); |
50 setTitle(hbTrId("txt_calendar_title_calendar")); |
48 |
51 |
49 // Create services API and register for notifications |
52 // Create services API and register for notifications |
50 RArray<TCalenNotification> notificationArray; |
53 RArray<TCalenNotification> notificationArray; |
|
54 CleanupClosePushL(notificationArray); |
51 |
55 |
52 notificationArray.Append(ECalenNotifySystemTimeChanged); |
56 notificationArray.Append(ECalenNotifySystemTimeChanged); |
53 notificationArray.Append(ECalenNotifySystemLocaleChanged); |
57 notificationArray.Append(ECalenNotifySystemLocaleChanged); |
54 notificationArray.Append(ECalenNotifyContextChanged); |
58 notificationArray.Append(ECalenNotifyContextChanged); |
55 |
59 |
56 mServices.RegisterForNotificationsL(this, notificationArray); |
60 mServices.RegisterForNotificationsL(this, notificationArray); |
57 |
61 |
58 notificationArray.Reset(); |
62 CleanupStack::PopAndDestroy(¬ificationArray); |
59 } |
63 } |
60 |
64 |
61 /*! |
65 /*! |
62 Destructor |
66 Destructor |
63 */ |
67 */ |
93 /*! |
97 /*! |
94 Slot to handle gotodate |
98 Slot to handle gotodate |
95 */ |
99 */ |
96 void CalenNativeView::goToDate() |
100 void CalenNativeView::goToDate() |
97 { |
101 { |
98 // Get the current date. |
102 // Create a popup with datepicker for the user to select date. |
99 QDateTime currentDateTime = CalenDateUtils::today(); |
103 HbDialog *popUp = new HbDialog(); |
100 QDate currentDate = currentDateTime.date(); |
104 popUp->setDismissPolicy(HbDialog::NoDismiss); |
101 mDatePicker = new HbDateTimePicker(currentDate, this); |
105 popUp->setTimeout(HbDialog::NoTimeout); |
102 |
106 popUp->setAttribute( Qt::WA_DeleteOnClose, true ); |
|
107 popUp->setHeadingWidget(new HbLabel(hbTrId("txt_calendar_opt_go_to_date"))); |
|
108 |
|
109 if(mDatePicker) { |
|
110 mDatePicker = NULL; |
|
111 } |
|
112 mDatePicker = new HbDateTimePicker(QDate::currentDate(), popUp); |
103 // Set the date range. |
113 // Set the date range. |
104 mDatePicker->setMinimumDate(CalenDateUtils::minTime().date()); |
114 mDatePicker->setMinimumDate(CalenDateUtils::minTime().date()); |
105 mDatePicker->setMaximumDate(CalenDateUtils::maxTime().date()); |
115 mDatePicker->setMaximumDate(CalenDateUtils::maxTime().date()); |
106 |
116 mDatePicker->setDate(QDate::currentDate()); |
107 // Create a popup with datepicker for the user to select date. |
117 |
108 HbDialog popUp; |
118 popUp->setContentWidget(mDatePicker); |
109 popUp.setDismissPolicy(HbDialog::NoDismiss); |
|
110 popUp.setTimeout(HbDialog::NoTimeout); |
|
111 popUp.setHeadingWidget(new HbLabel(hbTrId("txt_calendar_opt_go_to_date"))); |
|
112 popUp.setContentWidget(mDatePicker); |
|
113 HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok")); |
119 HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok")); |
114 popUp.setPrimaryAction(okAction); |
120 popUp->addAction(okAction); |
115 connect(okAction, SIGNAL(triggered()), this, SLOT(goToSelectedDate())); |
121 connect(okAction, SIGNAL(triggered()), this, SLOT(goToSelectedDate())); |
116 connect(okAction, SIGNAL(triggered()), &popUp, SLOT(close())); |
122 popUp->addAction(new HbAction(hbTrId("txt_common_button_cancel"), popUp)); |
117 popUp.setSecondaryAction(new HbAction(hbTrId("txt_common_button_cancel"), &popUp)); |
123 popUp->open(); |
118 popUp.exec(); |
|
119 } |
124 } |
120 |
125 |
121 /* |
126 /* |
122 Slot to handle date selected on gotodate popup |
127 Slot to handle date selected on gotodate popup |
123 */ |
128 */ |
128 // Check if the selected date is within the range. |
133 // Check if the selected date is within the range. |
129 if (selectedDate.isValid() && |
134 if (selectedDate.isValid() && |
130 selectedDate >= CalenDateUtils::minTime().date() && |
135 selectedDate >= CalenDateUtils::minTime().date() && |
131 selectedDate <= CalenDateUtils::maxTime().date()) { |
136 selectedDate <= CalenDateUtils::maxTime().date()) { |
132 MCalenContext& context = mServices.Context(); |
137 MCalenContext& context = mServices.Context(); |
133 QDateTime contextDate = context.focusDateAndTimeL(); |
138 QDateTime contextDate = context.focusDateAndTime(); |
134 |
139 |
135 //Set the selected date to contextDate. |
140 //Set the selected date to contextDate. |
136 contextDate.setDate(selectedDate); |
141 contextDate.setDate(selectedDate); |
137 context.setFocusDateAndTimeL(contextDate, KCalenMonthViewUidValue); |
142 context.setFocusDateAndTime(contextDate); |
138 } |
143 } |
139 refreshViewOnGoToDate(); |
144 refreshViewOnGoToDate(); |
140 } |
145 } |
141 |
146 |
142 /*! |
147 /*! |
200 QString *CalenNativeView::pluginText() |
205 QString *CalenNativeView::pluginText() |
201 { |
206 { |
202 return mServices.InfobarTextL(); |
207 return mServices.InfobarTextL(); |
203 } |
208 } |
204 |
209 |
|
210 // ---------------------------------------------------------------------------- |
|
211 // captureScreenshot caltures screen shot for the given viewId |
|
212 // @param viewId view for which screenshot needs to be captured |
|
213 // ---------------------------------------------------------------------------- |
|
214 // |
|
215 void CalenNativeView::captureScreenshot(bool captureScreenShot) |
|
216 { |
|
217 // get a screenshot for saving to the activity manager. It's done for once |
|
218 // to optimize the performance |
|
219 if (captureScreenShot) { |
|
220 mScreenShotMetadata.clear(); // remove any screenshot captured earlier |
|
221 mScreenShotMetadata.insert("screenshot", QPixmap::grabWidget(mainWindow(), mainWindow()->rect())); |
|
222 } |
|
223 mIsCapturedScreenShotValid = captureScreenShot; // set the validity of the screenshot captured |
|
224 } |
|
225 |
|
226 // ---------------------------------------------------------------------------- |
|
227 // saveActivity saves the activity for current view |
|
228 // ---------------------------------------------------------------------------- |
|
229 // |
|
230 void CalenNativeView::saveActivity() |
|
231 { |
|
232 // Get a pointer to activity manager |
|
233 HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager(); |
|
234 |
|
235 // check if alerady a valid screen shot is captured |
|
236 if (!mIsCapturedScreenShotValid) { |
|
237 mScreenShotMetadata.clear(); // remove any screenshot captured earlier |
|
238 mScreenShotMetadata.insert("screenshot", QPixmap::grabWidget(mainWindow(), mainWindow()->rect())); |
|
239 } |
|
240 |
|
241 // Save any data necessary to save the state |
|
242 QByteArray serializedActivity; |
|
243 QDataStream stream(&serializedActivity, QIODevice::WriteOnly | QIODevice::Append); |
|
244 stream << mActivityId; |
|
245 |
|
246 bool ok(false); |
|
247 // Save activity |
|
248 ok = activityManager->addActivity(activityName, serializedActivity, mScreenShotMetadata); |
|
249 |
|
250 // Check is activity saved sucessfully |
|
251 if ( !ok ) { |
|
252 qFatal("Add failed" ); // Panic is activity is not saved successfully |
|
253 } |
|
254 } |
205 //End Of File |
255 //End Of File |