06efce51b305a5f469e28a12f3181b6ae5481084
[apps/core/preloaded/ug-image-viewer-efl.git] / main / src / common / ivug-config.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *        http://www.tizenopensource.org/license
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 #include "ivug-common.h"
19 #include "ivug-define.h"
20 #include "ivug-effect.h"
21 #include "ivug-config.h"
22
23 #include <vconf.h>
24 #include <vconf-keys.h>
25
26 // TODO: Request vconf key to setting part, Slide show setting vconf key
27 #define VCONFKEY_GALLERY_INTERVAL_TIME  "db/setting/gallery/interval_time"  //double
28 #define VCONFKEY_GALLERY_REPEAT_STATE   "db/setting/gallery/repeat_state" //boolean
29 #define VCONFKEY_GALLERY_SHUFFLE_STATE  "db/setting/gallery/shuffle_state" //boolean
30 #define VCONFKEY_GALLERY_TRANSITION_EFFECT      "db/setting/gallery/ss_effect"  //char
31
32 enum { STATE_FALSE = 0, STATE_TRUE = 1, };
33
34 /*
35         Set lock screen with given image.
36
37         CAUTION : does not check filepath integrity
38 */
39 bool ivug_config_set_lockscreen_image(const char* filepath)
40 {
41         if(filepath == NULL)
42         {
43                 MSG_IMAGEVIEW_ERROR("Lock screen path is NULL");
44                 return FALSE;
45         }
46
47         if(vconf_set_str( VCONFKEY_IDLE_LOCK_BGSET, filepath ) < 0)
48         {
49                 MSG_IMAGEVIEW_ERROR("Lockscreen set Error : %s", filepath);
50                 return FALSE;
51         }
52
53         MSG_IMAGEVIEW_HIGH("Set Lockscreen filepath = %s", filepath);
54
55         return TRUE;
56 }
57
58 /*
59         Set home screen with given image
60
61         CAUTION : does not check filepath integrity
62 */
63 bool ivug_config_set_homescreen_image( const char* filepath )
64 {
65         if(filepath == NULL)
66         {
67                 MSG_IMAGEVIEW_ERROR("Home screen path is NULL");
68                 return FALSE;
69         }
70 // TODO : Need to check file existence?????
71         if(vconf_set_str(VCONFKEY_BGSET, filepath) < 0)
72         {
73                 MSG_IMAGEVIEW_ERROR("Homescreen set Error");
74                 return FALSE;
75         }
76
77         MSG_IMAGEVIEW_HIGH("Set Homescreen filepath = %s", filepath);
78         return TRUE;
79 }
80
81
82 static bool
83 _ivug_config_get_slideshow_repeat_state(void)
84 {
85         int repeat_state = STATE_FALSE;
86
87         if(vconf_get_bool(VCONFKEY_GALLERY_REPEAT_STATE, &repeat_state) < 0)
88         {
89                 MSG_IMAGEVIEW_ERROR("vconf_get_bool failed, set as repeat state as default: false");
90                 return false;
91         }
92
93         MSG_IMAGEVIEW_HIGH("repeat state is: %d", repeat_state);
94
95         return (repeat_state == STATE_TRUE ? true : false);
96 }
97
98 static bool
99 _ivug_config_get_slideshow_shuffle_state(void)
100 {
101         int shuffle_state = STATE_FALSE;
102
103         if(vconf_get_bool(VCONFKEY_GALLERY_SHUFFLE_STATE, &shuffle_state) < 0)
104         {
105                 MSG_IMAGEVIEW_ERROR("vconf_get_bool failed, set as shuffle state as default: false");
106                 return false;
107         }
108
109         MSG_IMAGEVIEW_HIGH("shuffle state is: %d", shuffle_state);
110
111         return (shuffle_state == STATE_TRUE ? true : false);
112 }
113
114 static double
115 _ivug_config_get_slideshow_interval_time(void)
116 {
117         double interval_time = 0.0;
118
119         if(vconf_get_dbl(VCONFKEY_GALLERY_INTERVAL_TIME, &interval_time) < 0)
120         {
121                 MSG_IMAGEVIEW_ERROR("vconf_get_dbl failed, set as interval time as -1");
122
123                 interval_time = -1.0;
124         }
125
126         MSG_IMAGEVIEW_HIGH("interval time is: %f", interval_time);
127         return interval_time;
128 }
129
130 static char *
131 _ivug_config_get_slideshow_effect_type(void)
132 {
133 // TODO : Free returned string??
134         char *effect_str = NULL;
135         effect_str = vconf_get_str(VCONFKEY_GALLERY_TRANSITION_EFFECT);
136
137         if(!effect_str)
138         {
139                 MSG_IMAGEVIEW_ERROR("vconf_get_str failed, set as effect type as default");
140
141                 effect_str = NULL;
142         }
143
144         MSG_IMAGEVIEW_HIGH("effect is: %s", effect_str);
145
146         return effect_str;
147 }
148
149 static ivug_effect_type
150 _ivug_config_get_effect_type_by_string(char *effect_str)
151 {
152         ivug_retv_if(!effect_str, EFFECT_NONE);
153
154         ivug_effect_type type = IVUG_EFFECT_TYPE_SLIDE;
155
156         if(!strncmp(effect_str, "Slide", strlen(effect_str)))
157         {
158                 type = IVUG_EFFECT_TYPE_SLIDE;
159         }
160         else //Set all other cases as default NONE
161         {
162                 MSG_SLIDER_WARN("Invalid type : %s", effect_str);
163                 type = EFFECT_NONE;
164         }
165
166         MSG_IMAGEVIEW_HIGH("effect_str = %s, type = %d", effect_str, type);
167
168         return type;
169 }
170
171 void
172 ivug_config_get_slideshow_setting(slide_show_mode *mode,
173                                                         double *interval_time,
174                                                         ivug_effect_type *effect_type)
175 {
176         *mode = SLIDE_SHOW_MODE_NORMAL;
177
178         bool state;
179
180         state = _ivug_config_get_slideshow_repeat_state();
181         if(state == true)
182         {
183                 *mode |= SLIDE_SHOW_MODE_REPEAT;
184         }
185
186         state = _ivug_config_get_slideshow_shuffle_state();
187         if(state == true)
188         {
189                 *mode |= SLIDE_SHOW_MODE_SHUFFLE;
190         }
191
192         *interval_time = _ivug_config_get_slideshow_interval_time();
193
194         /* EFFECT_NONE, EFFECT_FADE, EFFECT_BLIND, EFFECT_IRIS */
195         char *effect = _ivug_config_get_slideshow_effect_type();
196
197         *effect_type = _ivug_config_get_effect_type_by_string(effect);
198 }
199
200