~charlesk/indicator-datetime/lp-1405806-improve-clock-change-detection-rtm-14.09

« back to all changes in this revision

Viewing changes to src/engine-eds.cpp

After a one-time Ubuntu alarm's notification is displayed, disable the alarm. Fixes: #1362341
Approved by: Ted Gould

Show diffs side-by-side

added added

removed removed

Lines of Context:
136
136
        }
137
137
    }
138
138
 
 
139
    void disable_ubuntu_alarm(const Appointment& appointment)
 
140
    {
 
141
        if (appointment.is_ubuntu_alarm())
 
142
        {
 
143
            for (auto& kv : m_clients) // find the matching icalcomponent
 
144
            {
 
145
                e_cal_client_get_object(kv.second,
 
146
                                        appointment.uid.c_str(),
 
147
                                        nullptr,
 
148
                                        m_cancellable,
 
149
                                        on_object_ready_for_disable,
 
150
                                        this);
 
151
            }
 
152
        }
 
153
    }
 
154
 
139
155
private:
140
156
 
141
157
    void set_dirty_now()
506
522
 
507
523
        return G_SOURCE_CONTINUE;
508
524
    }
 
525
 
 
526
    /***
 
527
    ****
 
528
    ***/
 
529
 
 
530
    static void on_object_ready_for_disable(GObject      * client,
 
531
                                            GAsyncResult * result,
 
532
                                            gpointer       gself)
 
533
    {
 
534
        icalcomponent * icc = nullptr;
 
535
        if (e_cal_client_get_object_finish (E_CAL_CLIENT(client), result, &icc, nullptr))
 
536
        {
 
537
            struct icaltimetype itt = icalcomponent_get_recurrenceid(icc);
 
538
            if (icaltime_is_null_time(itt))
 
539
            {
 
540
                g_debug("'%s' appears to be a one-time alarm... adding 'disabled' tag.",
 
541
                        icalcomponent_as_ical_string(icc));
 
542
 
 
543
                auto ecc = e_cal_component_new_from_icalcomponent (icc); // takes ownership of icc
 
544
                icc = nullptr;
 
545
 
 
546
                if (ecc != nullptr)
 
547
                {
 
548
                    // add TAG_DISABLED to the list of categories
 
549
                    GSList * old_categories = nullptr;
 
550
                    e_cal_component_get_categories_list(ecc, &old_categories);
 
551
                    auto new_categories = g_slist_copy(old_categories);
 
552
                    new_categories = g_slist_append(new_categories, const_cast<char*>(TAG_DISABLED));
 
553
                    e_cal_component_set_categories_list(ecc, new_categories);
 
554
                    g_slist_free(new_categories);
 
555
                    e_cal_component_free_categories_list(old_categories);
 
556
                    e_cal_client_modify_object(E_CAL_CLIENT(client),
 
557
                                               e_cal_component_get_icalcomponent(ecc),
 
558
                                               E_CAL_OBJ_MOD_THIS,
 
559
                                               static_cast<Impl*>(gself)->m_cancellable,
 
560
                                               on_disable_done,
 
561
                                               nullptr);
 
562
 
 
563
                    g_clear_object(&ecc);
 
564
                }
 
565
            }
 
566
 
 
567
            g_clear_pointer(&icc, icalcomponent_free);
 
568
        }
 
569
    }
 
570
 
 
571
    static void on_disable_done (GObject* gclient, GAsyncResult *res, gpointer)
 
572
    {
 
573
        GError * error = nullptr;
 
574
        if (!e_cal_client_modify_object_finish (E_CAL_CLIENT(gclient), res, &error))
 
575
        {
 
576
            if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
 
577
                g_warning("indicator-datetime cannot mark one-time alarm as disabled: %s", error->message);
 
578
 
 
579
            g_error_free(error);
 
580
        }
 
581
    }
 
582
 
 
583
    /***
 
584
    ****
 
585
    ***/
509
586
 
510
587
    core::Signal<> m_changed;
511
588
    std::set<ESource*> m_sources;
541
618
    p->get_appointments(begin, end, tz, func);
542
619
}
543
620
 
 
621
void EdsEngine::disable_ubuntu_alarm(const Appointment& appointment)
 
622
{
 
623
    p->disable_ubuntu_alarm(appointment);
 
624
}
 
625
 
544
626
/***
545
627
****
546
628
***/