examples/QtQuick/alarmserver/alarmserver_symbian.cpp

00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation
00006 **
00007 **
00008 ** $QT_BEGIN_LICENSE:BSD$
00009 ** You may use this file under the terms of the BSD license as follows:
00010 **
00011 ** "Redistribution and use in source and binary forms, with or without
00012 ** modification, are permitted provided that the following conditions are
00013 ** met:
00014 **   * Redistributions of source code must retain the above copyright
00015 **     notice, this list of conditions and the following disclaimer.
00016 **   * Redistributions in binary form must reproduce the above copyright
00017 **     notice, this list of conditions and the following disclaimer in
00018 **     the documentation and/or other materials provided with the
00019 **     distribution.
00020 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
00021 **     the names of its contributors may be used to endorse or promote
00022 **     products derived from this software without specific prior written
00023 **     permission.
00024 **
00025 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00026 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00027 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00028 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00029 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00030 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00031 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00032 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00033 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00034 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00035 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
00036 ** $QT_END_LICENSE$
00037 **
00038 ****************************************************************************/
00039 
00040 #include <asshdalarm.h>
00041 #include <asclisession.h>
00042 
00043 #include "alarmserver_symbian.h"
00044 
00048 AlarmServerExPrivate* AlarmServerExPrivate::NewL(AlarmServerEx *aPublicAPI)
00049 {
00050     AlarmServerExPrivate* self = new (ELeave) AlarmServerExPrivate(aPublicAPI);
00051     CleanupStack::PushL(self);
00052     self->ConstructL();
00053     CleanupStack::Pop(self);
00054     return self;
00055 }
00056 
00060 void AlarmServerExPrivate::ConstructL()
00061 {
00062     // connect to the alarm server
00063     User::LeaveIfError(iAlarmServerSession.Connect());
00064 }
00065 
00070 AlarmServerExPrivate::AlarmServerExPrivate(AlarmServerEx *aPublicAPI):iPublic(aPublicAPI)
00071 {
00072 
00073 }
00074 
00075 AlarmServerExPrivate::~AlarmServerExPrivate()
00076 {
00077     // Cancel any outstanding requests before this object is destroyed.
00078     // This destructor cannot leave - so trap any problems here.
00079 
00080     iAlarmServerSession.Close();
00081 }
00082 
00086 void AlarmServerExPrivate::AddFixedAlarm()
00087 {
00088     // Create an alarm.
00089     TASShdAlarm alarm;
00090 
00091     // Add alarm message.
00092     _LIT(KAlarmMessage, "This is a fixed alarm");
00093     alarm.Message() = KAlarmMessage;
00094 
00095     // Add alarm sound.
00096     _LIT(KAlarmSound, "Chimes");
00097     alarm.SoundName() = KAlarmSound;
00098 
00099     // Alarm occurs once.
00100     alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
00101 
00102     TTime time;
00103 
00104     // Time is set in UTC for a fixed alarm
00105     time.UniversalTime();
00106 
00107     // Set alarm to expire in 10 seconds.
00108     time += TTimeIntervalSeconds(10);
00109     alarm.SetUtcNextDueTime(time);
00110 
00111     // WriteUserData capability is required to add an alarm
00112     User::LeaveIfError(iAlarmServerSession.AlarmAdd(alarm));
00113 
00114     // Alarm id value is emitted by the signal.
00115     QString alarmId;
00116     alarmId.setNum(int(alarm.Id()));
00117     emit iPublic->alarmAdded(alarmId);
00118 }
00119 
00123 void AlarmServerExPrivate::AddFloatingAlarm()
00124 {
00125     // Create an alarm.
00126     TASShdAlarm alarm;
00127 
00128     // Alarm occurs once, today. This is the default.
00129     alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
00130 
00131     // Add alarm message.
00132     _LIT(KAlarmMessage,"This is a floating alarm.");
00133     alarm.Message() = KAlarmMessage;
00134 
00135     // Add alarm sound.
00136     _LIT(KAlarmSound, "Chimes");
00137     alarm.SoundName() = KAlarmSound;
00138 
00139     // Get the local time and set it as the alarm's due time
00140     alarm.NextDueTime().HomeTime();
00141 
00142     // Set alarm to expire in 10 seconds.
00143     alarm.NextDueTime() += TTimeIntervalSeconds(10);
00144     User::LeaveIfError(iAlarmServerSession.AlarmAdd(alarm));
00145 
00146     // Alarm id value is emitted by the signal.
00147     QString alarmId;
00148     alarmId.setNum(int(alarm.Id()));
00149     emit iPublic->alarmAdded(alarmId);
00150 }
00151 
00155 QString AlarmServerExPrivate::ConvertToString(TDateTime time)
00156 {
00157     QString displayText;
00158     displayText.append("Date: ");
00159     QString day;
00160     day.setNum((int)time.Day());
00161     displayText.append(day);
00162     displayText.append("-");
00163     QString month;
00164     month.setNum((int)time.Month());
00165     displayText.append(month);
00166     displayText.append("-");
00167     QString year;
00168     year.setNum((int)time.Year());
00169     displayText.append(year);
00170     displayText.append("\n");
00171     displayText.append("Time: ");
00172     QString hour;
00173     hour.setNum((int)time.Hour());
00174     displayText.append(hour);
00175     displayText.append(":");
00176     QString minute;
00177     minute.setNum((int)time.Minute());
00178     displayText.append(minute);
00179     displayText.append(":");
00180     QString second;
00181     second.setNum((int)time.Second());
00182     displayText.append(second);
00183 
00184     return displayText;
00185 }
00186 
00190 QString AlarmServerExPrivate::GetAlarmDetails(QString alarmId)
00191 {
00192     TASShdAlarm alarmInfo;
00193 
00194     // Convert QString to TInt, to get the alarmId
00195     TInt alarm = alarmId.toInt();
00196 
00197     // Get the alarm details.
00198     iAlarmServerSession.GetAlarmDetails(alarm,alarmInfo);
00199     QString alarmDetails;
00200     alarmDetails.append("\nAlarm ID:\n");
00201     alarmDetails.append(alarmId);
00202 
00203     // Alarm state information.
00204     alarmDetails.append("\n\nAlarm State:\n");
00205     TInt state = alarmInfo.State();
00206     if(state == EAlarmStateInPreparation)
00207         alarmDetails.append("Alarm State in preparation.\n");
00208     else if(state == EAlarmStateQueued)
00209         alarmDetails.append("Alarm State Queued.\n");
00210     else if(state == EAlarmStateSnoozed)
00211         alarmDetails.append("Alarm State Snoozed.\n");
00212     else if(state == EAlarmStateWaitingToNotify)
00213         alarmDetails.append("Alarm State waiting to notify.\n");
00214     else if(state == EAlarmStateNotifying)
00215         alarmDetails.append("Alarm State notifying.\n");
00216     else if(state == EAlarmStateNotified)
00217         alarmDetails.append("Alarm State notified.\n");
00218 
00219     // Alarm next due time.
00220     alarmDetails.append("\nAlarm Due time:\n");
00221     TDateTime dueTime = alarmInfo.NextDueTime().DateTime();
00222     QString displayText = ConvertToString(dueTime);
00223     alarmDetails.append(displayText);
00224 
00225     // Alarm original time.
00226     alarmDetails.append("\n\nOriginal time:\n");
00227     TDateTime originalTime = alarmInfo.OriginalExpiryTime().DateTime();
00228     displayText = ConvertToString(originalTime);
00229     alarmDetails.append(displayText);
00230 
00231     alarmDetails.append("\n\nAlarm Message :\n");
00232     alarmDetails.append(QString::fromUtf16(alarmInfo.Message().Ptr(),
00233                                            alarmInfo.Message().Length()));
00234     alarmDetails.append("\n\nSound Name :\n");
00235     alarmDetails.append(QString::fromUtf16(alarmInfo.SoundName().Ptr(),
00236                                            alarmInfo.SoundName().Length()));
00237 
00238     return alarmDetails;
00239 }
00240 

Generated by  doxygen 1.6.2