diff options
Diffstat (limited to 'src/festival-wallpaper.c')
-rwxr-xr-x | src/festival-wallpaper.c | 581 |
1 files changed, 0 insertions, 581 deletions
diff --git a/src/festival-wallpaper.c b/src/festival-wallpaper.c deleted file mode 100755 index 6d42440..0000000 --- a/src/festival-wallpaper.c +++ /dev/null @@ -1,581 +0,0 @@ -/* - * starter - * - * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com> - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - - -#include <Elementary.h> -#include <Ecore_X.h> -#include <vconf.h> -#include <vconf-keys.h> -#include <efl_assist.h> -#include <feedback.h> -#include <app_alarm.h> -#include <system_settings.h> -#include <sys/time.h> -#include <time.h> - -#include <calendar.h> - -#include "wallpaper-ui-service-debug.h" -#include "festival-wallpaper.h" - - -//#define ICON_DIR "/usr/ug/res/images/ug-lockscreen-options-efl" -//efine ICON_DIR "/usr/apps/org.tizen.wallpaper-ui-service/res/images/" -#define VCONF_LOCKSCREEN_FESTIVAL_INDEX "db/lockscreen/pre_wallpaper_type" // int : save festival wallpaper idx -#define VCONF_LOCKSCREEN_FESTIVAL_BGSET "db/lockscreen/pre_bgset" // string : save festival wallpaper location -#define LOCKSCREEN_FESTIVAL_DISMISS "__DISMISS__" -#define LOCKSCREEN_FESTIVAL_NONE "__NONE__" - -#define VCONFKEY_FESTIVAL_EVENTS_LIST "db/lockscreen/festival_wallpaper_enable_string" - - -#define MAX_FESTIVAL 17 - -typedef struct { - char* name; - int b_on; - - int duration; - time_t from_time; - time_t to_time; -} festival_day_info; - -festival_day_info day_info[MAX_FESTIVAL] = -{ - {"Milad-un-Nabi", 1, 1, 0, 0}, - {"Republic Day", 1, 1, 0, 0}, - {"Holi", 1, 1, 0, 0}, - {"Ram Navami", 1, 1, 0, 0}, - {"Mahavir Jayanti", 1, 1, 0, 0}, - {"Good Friday", 1, 1, 0, 0}, - {"Buddha Purnima", 1, 1, 0, 0}, - {"Idul Fitr", 1, 1, 0, 0}, - {"Independence Day", 1, 1, 0, 0}, - {"Janmashtami", 1, 1, 0, 0}, - {"Idul Juha", 1, 1, 0, 0}, - {"Mahatma Gandhi Birthday", 1, 1, 0, 0}, - {"Dussehra", 1, 1, 0, 0}, - {"Muharram (10th Day)", 1, 1, 0, 0}, - {"Deewali", 1, 5, 0, 0}, - {"Guru Nanak's Birthday", 1, 1, 0, 0}, - {"Christmas Day", 1, 5, 0, 0}, -}; - -static const char *icon_path[] = { - "/opt/usr/apps/org.tizen.wallpaper-ui-service-lite/data/wallpaper/festival/01_Milad-un-Nabi.jpg", - "/opt/usr/apps/org.tizen.wallpaper-ui-service-lite/data/wallpaper/festival/02_Republic_Day.jpg", - "/opt/usr/apps/org.tizen.wallpaper-ui-service-lite/data/wallpaper/festival/03_Holi.jpg", - "/opt/usr/apps/org.tizen.wallpaper-ui-service-lite/data/wallpaper/festival/04_Ram-Navami.jpg", - "/opt/usr/apps/org.tizen.wallpaper-ui-service-lite/data/wallpaper/festival/16_Mahavir_Jayanti.jpg", - "/opt/usr/apps/org.tizen.wallpaper-ui-service-lite/data/wallpaper/festival/05_Good_Friday.jpg", - "/opt/usr/apps/org.tizen.wallpaper-ui-service-lite/data/wallpaper/festival/06_Buddha.jpg", - "/opt/usr/apps/org.tizen.wallpaper-ui-service-lite/data/wallpaper/festival/07_Id-Ul-Fitr.jpg", - "/opt/usr/apps/org.tizen.wallpaper-ui-service-lite/data/wallpaper/festival/08_IndependenceDay.jpg", - "/opt/usr/apps/org.tizen.wallpaper-ui-service-lite/data/wallpaper/festival/10_Janmashtami.jpg", - "/opt/usr/apps/org.tizen.wallpaper-ui-service-lite/data/wallpaper/festival/09_Id-ul-Juha.jpg", - "/opt/usr/apps/org.tizen.wallpaper-ui-service-lite/data/wallpaper/festival/12_Mahatma_Gandhi_Jayanti.jpg", - "/opt/usr/apps/org.tizen.wallpaper-ui-service-lite/data/wallpaper/festival/11_Dussehra.jpg", - "/opt/usr/apps/org.tizen.wallpaper-ui-service-lite/data/wallpaper/festival/14_Muharram.jpg", - "/opt/usr/apps/org.tizen.wallpaper-ui-service-lite/data/wallpaper/festival/13_Diwali.jpg", - "/opt/usr/apps/org.tizen.wallpaper-ui-service-lite/data/wallpaper/festival/17_Guru_Nanak.jpg", - "/opt/usr/apps/org.tizen.wallpaper-ui-service-lite/data/wallpaper/festival/15_Christmas.jpg", -}; - -static void set_festival_as_value(void* data, int festival_value) -{ -#if 0 - int wallpaper_type = 0; - char* value = NULL; - - vconf_get_int(VCONFKEY_LOCKSCREEN_WALLPAPER_TYPE,&wallpaper_type); - - if(wallpaper_type!=LOCKSCREEN_WALLPAPER_TYPE_FESTIVAL) - { - vconf_set_int(VCONF_LOCKSCREEN_FESTIVAL_INDEX,wallpaper_type); - } - else - { - WALLPAPERUI_ERR("set pre type failed =%d", wallpaper_type); - } - - WALLPAPERUI_DBG("festival_wallpaper_handle pre(%d) current(%d)",wallpaper_type,LOCKSCREEN_WALLPAPER_TYPE_FESTIVAL); - if(system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, &value) == SYSTEM_SETTINGS_ERROR_NONE) { - WALLPAPERUI_ERR("SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN:get value=%s", value); - } - - if(wallpaper_type!=LOCKSCREEN_WALLPAPER_TYPE_FESTIVAL) - { - vconf_set_str(VCONF_LOCKSCREEN_FESTIVAL_BGSET,value); - } - else - { - WALLPAPERUI_ERR("set pre bgset failed =%d", value); - } - - //backup - //set - vconf_set_int(VCONFKEY_LOCKSCREEN_WALLPAPER_TYPE, LOCKSCREEN_WALLPAPER_TYPE_FESTIVAL); - if(system_settings_set_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN,icon_path[festival_value]) == SYSTEM_SETTINGS_ERROR_NONE) { - WALLPAPERUI_ERR("SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN:set value=%s", icon_path[festival_value]); - } - //notification_status_message_post(_("IDS_ST_POP_LOCK_SCREEN_WALLPAPER_CHANGED_ABB")); -#endif - - int idx = 0; - char *festival_wallpaper = NULL; - festival_wallpaper = vconf_get_str(VCONF_LOCKSCREEN_FESTIVAL_BGSET); - vconf_get_int(VCONF_LOCKSCREEN_FESTIVAL_BGSET, &idx); - if(festival_wallpaper && strcmp(festival_wallpaper, LOCKSCREEN_FESTIVAL_DISMISS) == 0 && idx == festival_value) { - WALLPAPERUI_ERR("%d is dismissed", idx); - } else { - vconf_set_str(VCONF_LOCKSCREEN_FESTIVAL_BGSET, icon_path[festival_value]); - vconf_set_int(VCONF_LOCKSCREEN_FESTIVAL_INDEX, festival_value); - } - if(festival_wallpaper!=NULL) - { - FREE(festival_wallpaper); - } -} - -static void reset_as_previous(void* data) -{ - wallpaper_ui_service_appdata *ad = (wallpaper_ui_service_appdata *)data; - vconf_set_str(VCONF_LOCKSCREEN_FESTIVAL_BGSET, LOCKSCREEN_FESTIVAL_NONE); - vconf_set_int(VCONF_LOCKSCREEN_FESTIVAL_INDEX, -1); - -} -void get_holiday_date(void* data) -{ - int i = 0; - char *checkinfo = NULL; - checkinfo = vconf_get_str(VCONFKEY_FESTIVAL_EVENTS_LIST); - WALLPAPERUI_DBG("checkinfo %s",checkinfo); - if(checkinfo!=NULL) - { - char* temp = NULL; - for(i=0;i<MAX_FESTIVAL;i++) - { - if(*(checkinfo+i) == '1') - day_info[i].b_on = 1; - else - day_info[i].b_on = 0; - } - } - if(checkinfo!=NULL) - { - FREE(checkinfo); - } - - //get data from calendar svc -} - -int check_today_is_holiday(void* data, int prev) -{ - int i = 0; - struct tm date; - time_t now; - time(&now); - localtime_r(&now, &date); - for(i=0;i<MAX_FESTIVAL;i++) - { -// struct tm date; -// WALLPAPERUI_ERR("NEXT %d, %d, %d, %d, %d, %d,index %d b_on %d",date.tm_year,date.tm_mon,date.tm_mday,date.tm_hour,date.tm_min,date.tm_sec,i,b_on); -// WALLPAPERUI_ERR("day_info[%d] $d %d, %d, %d",i,day_info[i].from_month,day_info[i].to_month,day_info[i].from_day,day_info[i].to_day,date.tm_min); - if(i!=prev)//check for previous holiday - { - if(day_info[i].from_time >= now && now < day_info[i].to_time) { - WALLPAPERUI_ERR("!!!today is holiday %d %s", i, day_info[i].name); - set_festival_as_value(data, i); - break; - } - } - } - -} - -void set_alarm_by_date(struct tm* date,int index,int day) -{ - WALLPAPERUI_ERR("NEXT %d, mon %d, day %d, hour %d, min %d, sec %d,index %d,day %d,name %s",date->tm_year,date->tm_mon,date->tm_mday,date->tm_hour,date->tm_min,date->tm_sec,index,day,day_info[day].name); - int tid; - - app_control_h service; - app_control_create(&service); - app_control_set_app_id(service, "org.tizen.wallpaper-ui-service"); - app_control_set_operation(service, APP_CONTROL_OPERATION_DEFAULT); - app_control_add_extra_data(service, "popup_type", "festival"); - app_control_add_extra_data(service, EXTRA_KEY_FESTIVAL_TYPE, EXTRA_DATA_FESTIVAL_TRIGGER); - - if(index==0)//off - { - app_control_add_extra_data(service, EXTRA_KEY_FESTIVAL_TRIGGER, EXTRA_DATA_FESTIVAL_TRIGGER_OFF); - } - else - { - app_control_add_extra_data(service, EXTRA_KEY_FESTIVAL_TRIGGER, EXTRA_DATA_FESTIVAL_TRIGGER_ON); - } - - char val[10] = {0,}; - snprintf(val,sizeof(val),"%d",day); - app_control_add_extra_data(service, EXTRA_KEY_FESTIVAL_TRIGGER_VAL, val); - int ret = alarm_schedule_at_date(service, date, 0, &tid); - if(ret == ALARM_ERROR_NONE) - { -// WALLPAPERUI_ERR("NO ERROR"); - } - else - { - WALLPAPERUI_ERR("ERROR(%d)", ret); - } - // app_control_send_launch_request(service,NULL,NULL); - app_control_destroy(service); - -} -void set_next_year_alarm(void) -{ - struct tm date; - int b_on = 1; - time_t now; - time(&now); - localtime_r(&now, &date); - - int tid; - - app_control_h service; - app_control_create(&service); - app_control_set_app_id(service, "org.tizen.wallpaper-ui-service"); - app_control_set_operation(service, APP_CONTROL_OPERATION_DEFAULT); - app_control_add_extra_data(service, "popup_type", "festival"); - app_control_add_extra_data(service, EXTRA_KEY_FESTIVAL_TYPE, EXTRA_DATA_FESTIVAL_CREATE); - - date.tm_year = date.tm_year+1; - date.tm_mon = 0; - date.tm_mday = 1; - date.tm_hour = 0; - date.tm_min = 0; - date.tm_sec = 0; - - WALLPAPERUI_ERR("NEXT year %d, mon %d, day %d, hour %d, min %d, sec %d",date.tm_year,date.tm_mon,date.tm_mday,date.tm_hour,date.tm_min,date.tm_sec); - - int ret = alarm_schedule_at_date(service, &date, 0, &tid); - if(ret == ALARM_ERROR_NONE) - { -// WALLPAPERUI_ERR("NO ERROR"); - } - else - { - WALLPAPERUI_ERR("ERROR(%d)", ret); - } - - app_control_destroy(service); - -} -int set_alarm_all(void* data) -{ - int i = 0; -// int b_plus_year = 0; - get_holiday_date(data); - - int b_plus_year = 0; - struct tm date; - time_t now; - time(&now); - localtime_r(&now, &date); - - Eina_Bool is_today_festival = EINA_FALSE; - - WALLPAPERUI_ERR("today %d, %d, %d, %d, %d, %d,index %d b_on %d",date.tm_year,date.tm_mon,date.tm_mday,date.tm_hour,date.tm_min,date.tm_sec); - - int b_on_list[MAX_FESTIVAL]; - - for(i=0;i<MAX_FESTIVAL;i++) - { - b_on_list[i] = 1; - - if(day_info[i].b_on==0) - { - WALLPAPERUI_DBG("SKIP unchecked event(%s) idx(%d)", day_info[i].name, i); - b_on_list[i] = 0; - continue; - } - - if(day_info[i].from_time <= now && now < day_info[i].to_time) { - WALLPAPERUI_ERR("!!!today is holiday %d %s", i, day_info[i].name); - set_festival_as_value(data, i); - b_on_list[i] = 0; - - /* end alarm */ - struct tm to_time; - localtime_r(&day_info[i].to_time, &to_time); - set_alarm_by_date(&to_time, b_on_list[i], i); - is_today_festival = EINA_TRUE; - } else if (day_info[i].from_time <= now) { - WALLPAPERUI_DBG("SKIP previous event(%s) idx(%d) from(%d) now(%d) to(%d)", day_info[i].name, i, day_info[i].from_time, now, day_info[i].to_time); - b_on_list[i] = 0; - continue; - } - } - - if(!is_today_festival) - { - reset_as_previous(data); - } - - /* set alarms */ - for(i=0;i<MAX_FESTIVAL;i++) - { - if(b_on_list[i] == 1)//on - { - int index = 0; - for(index=0; index<2 ;index++) - { - if(index==0) - { - // to - localtime_r(&day_info[i].to_time, &date); - } - else - { - // from - localtime_r(&day_info[i].from_time, &date); - } - set_alarm_by_date(&date, index, i); - } - } - } - - set_next_year_alarm(); - - return 0; -} - -calendar_query_h _create_range_list_query() -{ - const char* uri = _calendar_instance_localtime_calendar_book_extended._uri ; - const unsigned int startProperty = _calendar_instance_localtime_calendar_book_extended.start_time; - - calendar_query_h query = NULL; - calendar_query_create(uri, &query); - - calendar_filter_h filter = NULL; - calendar_filter_create(uri, &filter); - - struct tm tm_start; - time_t now = time(NULL); - localtime_r(&now, &tm_start); - - // time filter - calendar_time_s fromTime; - fromTime.type = CALENDAR_TIME_LOCALTIME; - fromTime.time.date.year = tm_start.tm_year+1900; - fromTime.time.date.month = 1; - fromTime.time.date.mday = 1; - fromTime.time.date.hour = 0; - fromTime.time.date.minute = 0; - fromTime.time.date.second = 0; - fromTime.time.date.is_leap_month = false; - - calendar_time_s toTime; - toTime.type = CALENDAR_TIME_LOCALTIME; - toTime.time.date.year = tm_start.tm_year+1900+1; - toTime.time.date.month = 1; - toTime.time.date.mday = 1; - toTime.time.date.hour = 0; - toTime.time.date.minute = 0; - toTime.time.date.second = 0; - toTime.time.date.is_leap_month = false; - - calendar_filter_add_caltime(filter, startProperty, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, fromTime); - calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND); - calendar_filter_add_caltime(filter, startProperty, CALENDAR_MATCH_LESS_THAN, toTime); - - // string filter - calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND); - calendar_filter_add_str(filter,_calendar_instance_localtime_calendar_book_extended.sync_data2,CALENDAR_MATCH_FULLSTRING, "FESTIVAL"); - - calendar_query_set_filter(query, filter); - calendar_filter_destroy(filter); - - calendar_query_set_sort(query, startProperty, true); - - return query; -} - -int _festival_date_find(const char *name) -{ - int i = 0; - - for(i = 0; i < MAX_FESTIVAL; i++) { - if(strstr(name, day_info[i].name) != NULL) { - return i; - } - } - return -1; -} - -void festival_date_get_from_calendar(void) -{ - calendar_connect(); - - calendar_query_h query = _create_range_list_query(); - if (query == NULL) { - WALLPAPERUI_ERR("_create_range_list_query() failed"); - return; - } - - calendar_list_h list = NULL; - int error = calendar_db_get_records_with_query(query, 0, 0, &list); - if (error != CALENDAR_ERROR_NONE) { - WALLPAPERUI_ERR("calendar_db_get_records_with_query() failed"); - return; - } - - if (list != NULL) { - int count = 0; - int i = 0; - calendar_list_first(list); - error = calendar_list_get_count(list, &count); - if (error != CALENDAR_ERROR_NONE) { - WALLPAPERUI_ERR("calendar_list_get_count() failed"); - return; - } - - for (i = 0; i < count; i++) - { - calendar_record_h record2 = NULL; - - error = calendar_list_get_current_record_p(list, &record2); - if (error != CALENDAR_ERROR_NONE) { - WALLPAPERUI_ERR("calendar_list_get_current_record_p() failed"); - } - - if (record2) { - char * tmp = NULL; - calendar_record_get_str_p(record2, _calendar_instance_localtime_calendar_book_extended.summary ,&tmp); - if (tmp) { - - /* TODO : tmp can be changed for multi languages */ - int index = _festival_date_find(tmp); - if(index != -1) { - calendar_time_s start; - calendar_record_get_caltime(record2, _calendar_instance_localtime_calendar_book_extended.start_time, &start); - if(start.type == CALENDAR_TIME_LOCALTIME) { - - struct tm temp_tm; - temp_tm.tm_year = start.time.date.year-1900; - temp_tm.tm_mon = start.time.date.month-1; - temp_tm.tm_mday = start.time.date.mday; - temp_tm.tm_hour = 0; - temp_tm.tm_min = 0; - temp_tm.tm_sec = 0; - - WALLPAPERUI_DBG("name(%s) y(%d) m(%d) d(%d)", tmp, start.time.date.year, start.time.date.month, start.time.date.mday); - - day_info[index].from_time = mktime(&temp_tm); - - //temp_tm.tm_mday += day_info[index].duration-1; - temp_tm.tm_mday += day_info[index].duration; - - day_info[index].to_time = mktime(&temp_tm); - - //WALLPAPERUI_DBG("from(%d) to(%d)", day_info[index].from_time, day_info[index].to_time); - } - } else { - WALLPAPERUI_ERR("There is no date(%s)", tmp); - } - } - } - - calendar_list_next(list); - } - calendar_list_destroy(list,true); - } - - calendar_disconnect(); -} - -void festival_wallpaper_handle(app_control_h service, void * data) -{ - WALLPAPERUI_DBG("festival_wallpaper_handle begin"); - wallpaper_ui_service_appdata *ad = (wallpaper_ui_service_appdata *)data; - if(ad->festival_data.festival_type == WALLPAPER_FESTIVAL_TYPE_CREATE) - { - int i = 0; - alarm_cancel_all(); - festival_date_get_from_calendar(); - set_alarm_all(data); - } - else if(ad->festival_data.festival_type == WALLPAPER_FESTIVAL_TYPE_DELETE) - { - alarm_cancel_all(); - reset_as_previous(data); - } - else if(ad->festival_data.festival_type == WALLPAPER_FESTIVAL_TYPE_TRIGGER) - { - char* trigger_type = NULL; - char* trigger_val = NULL; - - int type = 0; - int val = 0; - app_control_get_extra_data(service, EXTRA_KEY_FESTIVAL_TRIGGER, &trigger_type); - if(trigger_type!=NULL) - { - WALLPAPERUI_ERR("EXTRA_KEY_FESTIVAL_TRIGGER %s",trigger_type); - if(strcmp(trigger_type, EXTRA_DATA_FESTIVAL_TRIGGER_ON)==0) - { - type = 1; - } - else if(strcmp(trigger_type, EXTRA_DATA_FESTIVAL_TRIGGER_OFF)==0) - { - type = 0; - } - free(trigger_type); - } - else - { - type = 0; - } - - app_control_get_extra_data(service, EXTRA_KEY_FESTIVAL_TRIGGER_VAL, &trigger_val); - if(trigger_val!=NULL) - val = atoi(trigger_val); - - WALLPAPERUI_DBG("festival_wallpaper_handle %d %d",type,val); - if(val<0 || val>MAX_FESTIVAL) - { - val = 0; - } - - if(type==1) - { - set_festival_as_value(data,val); -// set_alarm_nearest_date_index(data,val); - } - else - { - reset_as_previous(data); - check_today_is_holiday(data,val); -// set_alarm_nearest_date_index(data,0); - } - - } - - WALLPAPERUI_DBG("festival_wallpaper_handle end"); -} |