~ubuntu-branches/ubuntu/vivid/cairo-dock-plug-ins/vivid

« back to all changes in this revision

Viewing changes to clock/src/applet-backend-ical.c

  • Committer: Matthieu Baerts
  • Date: 2013-08-27 14:46:47 UTC
  • mto: (53.1.4 cairo-dock-plug-ins)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: matttbe@gmail.com-20130827144647-wm0kyawa8vcg0cso
Tags: upstream-3.2.99.beta1.1~20130827~bzr2928
ImportĀ upstreamĀ versionĀ 3.2.99.beta1.1~20130827~bzr2928

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
static CDClockIcalBackendData *_pBackendData = NULL;
43
43
static int s_iCounter = 0;  // a counter used to define a new ID
44
44
 
45
 
static void backend_ical_init(CairoDockModuleInstance *myApplet)
 
45
static void backend_ical_init(GldiModuleInstance *myApplet)
46
46
{
47
47
        cd_debug("Backend initialization.");
48
48
        gchar *cDirPath = g_strdup_printf ("%s/%s", g_cCairoDockDataDir, "clock");
88
88
        g_free (cDirPath);
89
89
}
90
90
 
91
 
static void backend_ical_stop(CairoDockModuleInstance *myApplet)
 
91
static void backend_ical_stop(GldiModuleInstance *myApplet)
92
92
{
93
93
        if( _pBackendData )
94
94
        {
144
144
        return piCalComponent;
145
145
}
146
146
 
147
 
static GList *get_tasks (CairoDockModuleInstance *myApplet)
 
147
static GList *get_tasks (GldiModuleInstance *myApplet)
148
148
{
149
149
        if( !_assert_data() ) return NULL;
150
150
        
151
151
        CDClockTask *pTask = NULL;
152
 
        gchar *cTaskID = NULL;
 
152
        gchar *cTaskID = NULL, *cTitle = NULL;
153
153
        GList *pTaskList = NULL;
154
154
 
155
155
        icalcomponent *piCalComponent = NULL;
159
159
             piCalComponent = icalcomponent_get_next_component(_pBackendData->piCalCalendar, ICAL_ANY_COMPONENT))
160
160
        {
161
161
                //if( ICAL_VCALENDAR_COMPONENT != icalcomponent_isa(piCalComponent) ) continue;
162
 
                cd_debug( "Fetching iCal component of kind: %s", icalcomponent_kind_to_string(icalcomponent_isa(piCalComponent)) );
 
162
                // cd_debug( "Fetching iCal component of kind: %s", icalcomponent_kind_to_string(icalcomponent_isa(piCalComponent)) );
163
163
                
164
164
                cTaskID = g_strdup(icalcomponent_get_uid(piCalComponent));
165
165
                if (cTaskID == NULL) // if the uid is NULL, skip it.
166
166
                        continue;
 
167
 
 
168
                cTitle = g_strdup (icalcomponent_get_summary (piCalComponent));
 
169
                /* if there is no title, it's not a task...
 
170
                 * It seems that some calendars add tasks with a correct ID but no title
 
171
                 * and the status is 'completed' and no other info => skip these tasks
 
172
                 */
 
173
                if (cTitle == NULL)
 
174
                {
 
175
                        g_free (cTaskID);
 
176
                        continue;
 
177
                }
 
178
 
167
179
                pTask = g_new0 (CDClockTask, 1);
168
 
                cd_debug ("+ task %s", cTaskID);
 
180
                // cd_debug ("+ task %s", cTaskID);
169
181
 
170
182
                struct icaltimetype liCalStartDate = icalcomponent_get_dtstart(piCalComponent);
171
183
                // struct icaldurationtype liCalDuration = icalcomponent_get_duration(piCalComponent); //ignored until Clock manages tasks duration
176
188
                pTask->iYear = liCalStartDate.year;
177
189
                pTask->iHour = liCalStartDate.hour;
178
190
                pTask->iMinute = liCalStartDate.minute;
179
 
                
 
191
 
 
192
                if (pTask->iMonth < 0 || pTask->iDay <= 0  // not a valid task, should not happen 
 
193
                        || pTask->iHour < 0 || pTask->iMinute < 0) // but be secure, data comes from outside
 
194
                {
 
195
                        cd_debug ("Not a valid task: %s", cTaskID);
 
196
                        g_free (cTaskID);
 
197
                        g_free (cTitle);
 
198
                        g_free (pTask);
 
199
                        continue;
 
200
                }
 
201
 
180
202
                pTask->iFrequency = CD_TASK_DONT_REPEAT;
181
203
                // TODO: really do the frequency management. If possible.
182
204
                icalproperty *rrule = NULL;
190
212
                        default:pTask->iFrequency = CD_TASK_DONT_REPEAT; break;
191
213
                }
192
214
 
193
 
                pTask->cTitle = g_strdup(icalcomponent_get_summary(piCalComponent));
 
215
                pTask->cTitle = cTitle;
194
216
                pTask->cText = g_strdup(icalcomponent_get_description(piCalComponent));
195
217
                pTask->cTags = g_strdup(icalcomponent_get_comment(piCalComponent));
196
218
                
203
225
}
204
226
 
205
227
 
206
 
static gboolean create_task (CDClockTask *pTask, CairoDockModuleInstance *myApplet)
 
228
static gboolean create_task (CDClockTask *pTask, GldiModuleInstance *myApplet)
207
229
{
208
230
        if( !_assert_data() ) return FALSE;
209
231
        if( pTask == NULL ) return FALSE;
297
319
        return TRUE;
298
320
}
299
321
 
300
 
static gboolean delete_task (CDClockTask *pTask, CairoDockModuleInstance *myApplet)
 
322
static gboolean delete_task (CDClockTask *pTask, GldiModuleInstance *myApplet)
301
323
{
302
324
        //g_print ("%s (%s)\n", __func__, pTask->cTitle);
303
325
 
318
340
        return TRUE;
319
341
}
320
342
 
321
 
static gboolean update_task (CDClockTask *pTask, CairoDockModuleInstance *myApplet)
 
343
static gboolean update_task (CDClockTask *pTask, GldiModuleInstance *myApplet)
322
344
{
323
345
        //g_print ("%s (%s, '%s')\n", __func__, pTask->cTitle, pTask->cText);
324
346
        return create_task (pTask, myApplet);  // the 'create' can also update a task
325
347
}
326
348
#endif
327
349
 
328
 
void cd_clock_register_backend_ical (CairoDockModuleInstance *myApplet)
 
350
void cd_clock_register_backend_ical (GldiModuleInstance *myApplet)
329
351
{
330
352
#ifdef CD_CLOCK_ICAL_SUPPORT
331
353
        CDClockTaskBackend *pBackend = g_new0 (CDClockTaskBackend, 1);