3 * Copyright 2012 Samsung Electronics Co., Ltd
5 * Licensed under the Flora License, Version 1.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://floralicense.org/license/
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include "list-provider.h"
19 #include "list-broker.h"
20 #include "list-comparator.h"
24 cal_list_provider_h allday;
25 cal_list_provider_h normal;
26 cal_list_provider_h task;
27 struct tm current_day;
31 cal_list_broker_h cal_list_broker_create(struct tm* start_date, int direction,
32 bool include_completed_tasks)
34 cal_list_broker_s* p = calloc(1, sizeof(cal_list_broker_s));
36 start_date->tm_hour = 0;
37 start_date->tm_min = 0;
38 start_date->tm_sec = 0;
40 calendar_query_h query_allday;
41 calendar_query_h query_normal;
42 calendar_query_h query_task;
45 query_allday = cal_query_create_list_more_allday_query(
46 _calendar_instance_allday_calendar_book.end_time,
47 start_date, direction);
48 query_normal = cal_query_create_list_more_normal_query(
49 _calendar_instance_normal_calendar_book.end_time,
50 start_date, direction);
51 query_task = cal_query_create_list_more_task_query(
52 start_date, direction, include_completed_tasks);
54 query_allday = cal_query_create_list_more_allday_query(
55 _calendar_instance_allday_calendar_book.start_time,
56 start_date, direction);
57 query_normal = cal_query_create_list_more_normal_query(
58 _calendar_instance_normal_calendar_book.start_time,
59 start_date, direction);
60 query_task = cal_query_create_list_more_task_query(
61 start_date, direction, include_completed_tasks);
64 p->allday = cal_list_provider_create(query_allday);
65 p->normal = cal_list_provider_create(query_normal);
66 p->task = cal_list_provider_create(query_task);
68 p->direction = direction;
73 bool cal_list_broker_no_more(cal_list_broker_h cursor)
75 cal_list_broker_s* p = (cal_list_broker_s*)cursor;
77 cal_list_provider_no_more(p->allday) &&
78 cal_list_provider_no_more(p->normal) &&
79 cal_list_provider_no_more(p->task);
82 void cal_list_broker_fetch(cal_list_broker_h cursor)
84 cal_list_broker_s* p = (cal_list_broker_s*)cursor;
86 cal_list_provider_fetch(p->allday);
87 cal_list_provider_fetch(p->normal);
88 cal_list_provider_fetch(p->task);
91 calendar_record_h cal_list_broker_get_next(cal_list_broker_h cursor, bool* day_has_changed)
93 cal_list_broker_s* p = (cal_list_broker_s*)cursor;
95 *day_has_changed = false;
97 // Default case - next is indeterminable until more is fetched.
98 if (cal_list_provider_not_ready(p->allday) ||
99 cal_list_provider_not_ready(p->normal) ||
100 cal_list_provider_not_ready(p->task)) {
101 DBG("One of the lists are not ready!");
105 // Peak foremost record of each run.
106 // NULL record means there is no more!
107 calendar_record_h allday = cal_list_provider_top_p(p->allday);
108 calendar_record_h normal = cal_list_provider_top_p(p->normal);
109 calendar_record_h task = cal_list_provider_top_p(p->task);
111 int winner = cal_list_comparator_determine_next(allday, normal, task,
112 _calendar_instance_allday_calendar_book.start_time,
113 _calendar_instance_normal_calendar_book.start_time,
114 _calendar_todo.due_time,
116 &p->current_day, day_has_changed);
120 DBG("Winner: allday");
121 return cal_list_provider_pop(p->allday);
123 DBG("Winner: normal");
124 return cal_list_provider_pop(p->normal);
127 return cal_list_provider_pop(p->task);
130 return cal_list_provider_pop(p->task);
137 const struct tm* cal_list_broker_get_current_day_p(cal_list_broker_h cursor)
139 cal_list_broker_s* p = (cal_list_broker_s*)cursor;
141 return &p->current_day;
144 void cal_list_broker_destroy(cal_list_broker_h cursor)
146 cal_list_broker_s* p = (cal_list_broker_s*)cursor;
148 cal_list_provider_destroy(p->allday);
149 cal_list_provider_destroy(p->normal);
150 cal_list_provider_destroy(p->task);