~bzoltan/ubuntu-ui-toolkit/add_default_tools

« back to all changes in this revision

Viewing changes to modules/Ubuntu/Components/plugin/ucalarm.cpp

  • Committer: Tarmac
  • Author(s): Zsombor Egri
  • Date: 2013-09-24 16:18:22 UTC
  • mfrom: (750.2.5 alarm-status)
  • Revision ID: tarmac-20130924161822-ews87nvw1wesa2ts
Fix alarm status reporting, updating documentation on asynchronous behavior of save and cancel operations. Alarm status notification reports the operation the status refers to. Fixes: https://bugs.launchpad.net/bugs/1226516.

Approved by PS Jenkins bot, Christian Dywan.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
    if (!request) {
53
53
        return false;
54
54
    }
55
 
    QObject::connect(request, SIGNAL(statusChanged(int,int)),
56
 
                     q_ptr, SLOT(_q_syncStatus(int,int)));
 
55
    QObject::connect(request, SIGNAL(statusChanged(int,int,int)),
 
56
                     q_ptr, SLOT(_q_syncStatus(int,int,int)));
57
57
    return true;
58
58
}
59
59
 
60
 
void UCAlarmPrivate::_q_syncStatus(int status, int error) {
 
60
void UCAlarmPrivate::_q_syncStatus(int operation, int status, int error) {
61
61
    UCAlarm::Status alarmStatus = static_cast<UCAlarm::Status>(status);
62
62
    if (this->status != alarmStatus || this->error != error) {
63
63
        this->status = alarmStatus;
80
80
            rawData.changes = 0;
81
81
        }
82
82
 
83
 
        Q_EMIT q_func()->statusChanged();
 
83
        Q_EMIT q_func()->statusChanged(static_cast<UCAlarm::Operation>(operation));
84
84
        Q_EMIT q_func()->errorChanged();
85
85
    }
86
86
}
280
280
 *                 alarm.save();
281
281
 *                 if (alarm.error != Alarm.NoError)
282
282
 *                     print("Error saving alarm, code: " + alarm.error);
283
 
 *                 else alarm.reset();
284
283
 *             }
285
284
 *         }
286
285
 *     }
569
568
 
570
569
/*!
571
570
 * \qmlproperty Status Alarm::status
572
 
 * The property holds the status of the last performed operation.
 
571
 * The property holds the status of the last performed operation. It can take one
 
572
 * of the following values:
 
573
 * \table
 
574
 *   \header
 
575
 *      \li Status code
 
576
 *      \li Value
 
577
 *      \li Description
 
578
 *   \row
 
579
 *      \li Ready
 
580
 *      \li 1
 
581
 *      \li Specifies either that the Alarm object is ready to perform any operation
 
582
 *          or that the previous operation has been successfully completed.
 
583
 *   \row
 
584
 *      \li InProgress
 
585
 *      \li 2
 
586
 *      \li Specifies that there is an operation pending on Alarm object.
 
587
 *   \row
 
588
 *      \li Fail
 
589
 *      \li 3
 
590
 *      \li Specifies that the last alarm operation has failed. The failure code is
 
591
 *          set in \l error property.
 
592
 * \endtable
 
593
 *
 
594
 * The notification signal has a parameter specifying the \a operation the status
 
595
 * refers to. The operation can take the following values:
 
596
 * \table
 
597
 *   \header
 
598
 *      \li Operation code
 
599
 *      \li Description
 
600
 *   \row
 
601
 *      \li NoOperation
 
602
 *      \li There is no operation pending. This may be set when an error occured
 
603
 *          in the alarm adapters and the operation cannot be determined.
 
604
 *  \row
 
605
 *      \li Saving
 
606
 *      \li The status reported refers to an operation requested through save().
 
607
 *  \row
 
608
 *      \li Canceling
 
609
 *      \li The status reported refers to an operation requested through cancel().
 
610
 *  \row
 
611
 *      \li Reseting
 
612
 *      \li The status reported refers to an operation requested through reset().
 
613
 * \endtable
 
614
 *
 
615
 * For example an implementation which resets the alarm data whenever
 
616
 * the save or cancel operations succeed would look as follows:
 
617
 *
 
618
 * \qml
 
619
 * Alarm {
 
620
 *     onStatusChanged: {
 
621
 *         if (status !== Alarm.Ready)
 
622
 *             return;
 
623
 *         if ((operation > Alarm.NoOperation) && (operation < Alarm.Reseting)) {
 
624
 *             reset();
 
625
 *         }
 
626
 *     }
 
627
 * }
 
628
 * \endqml
573
629
 */
574
630
UCAlarm::Status UCAlarm::status() const
575
631
{
595
651
 *  \li - the \l daysOfWeek property is set to multiple days for one time alarm
596
652
 * \endlist
597
653
 *
 
654
 * The operation is asynchronous, and its status is reported through the \l status
 
655
 * property. Further operations should wait till the previous operation is completed.
598
656
 * The operation result is stored in the \l error property.
599
657
 */
600
658
void UCAlarm::save()
610
668
 
611
669
    UCAlarm::Error result = d->checkAlarm();
612
670
    if (result != UCAlarm::NoError) {
613
 
        d->_q_syncStatus(Fail, result);
 
671
        d->_q_syncStatus(Saving, Fail, result);
614
672
    } else {
615
673
        if (d->createRequest()) {
616
674
            d->request->save(d->rawData);
623
681
 * The function removes the alarm from the collection. The function will fail
624
682
 * for alarms which are not yet registered to the collection.
625
683
 *
 
684
 * The operation is asynchronous, and its status is reported through the \l status
 
685
 * property. Further operations should wait till the previous operation is completed.
626
686
 * The operation result is stored in the \l error property.
627
687
 */
628
688
void UCAlarm::cancel()
644
704
 * \qmlmethod Alarm::reset()
645
705
 * The function resets the alarm properties to its defaults. After this call the
646
706
 * object can be used to create a new alarm event.
 
707
 *
 
708
 * \b Note: do not call this function on alarm objects retrieved from AlarmModel, as
 
709
 * calling it will result in the model being out of sync from the alarm database.
647
710
 */
648
711
void UCAlarm::reset()
649
712
{
650
713
    Q_D(UCAlarm);
651
 
    d->error = NoError;
652
 
    d->status = InProgress;
 
714
    d->_q_syncStatus(Reseting, InProgress, NoError);
653
715
 
654
 
    delete d->request;
655
 
    d->request = 0;
656
716
    d->rawData = AlarmData();
657
717
    d->setDefaults();
658
718
    d->rawData.changes = AlarmData::AllFields;
659
 
    d->_q_syncStatus(Ready, NoError);
 
719
    d->_q_syncStatus(Reseting, Ready, NoError);
660
720
}
661
721
 
662
722
#include "moc_ucalarm.cpp"