41ca5a6623ad13f1e299cd6d824740924ad531df
[apps/core/preloaded/lockscreen.git] / src / background_view.c
1 /*
2  * Copyright (c) 2009-2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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 #include "lockscreen.h"
18 #include "log.h"
19 #include "background_view.h"
20 #include "window.h"
21 #include "property.h"
22 #include "default_lock.h"
23
24 #define EDJE_SIGNAL_SOURCE "bg"
25 #define EDJE_SIGNAL_EMIT_MUSIC_ON "music_on"
26 #define EDJE_SIGNAL_EMIT_MUSIC_OFF "music_off"
27
28 static struct _s_info {
29         Evas_Object *bg;
30 } s_info = {
31         .bg = NULL,
32 };
33
34 Evas_Object *lock_background_view_bg_get(void)
35 {
36         return s_info.bg;
37 }
38
39 lock_error_e lock_background_view_image_set(lock_bg_type_e type, char *file)
40 {
41         Evas_Object *lock_layout = NULL;
42         const char *old_filename = NULL;
43         const char *emission;
44
45         char *lock_bg = NULL;
46
47         retv_if(!s_info.bg, LOCK_ERROR_INVALID_PARAMETER);
48
49         elm_bg_file_get(s_info.bg, &old_filename, NULL);
50         if (!old_filename) {
51                 old_filename = LOCK_DEFAULT_BG_PATH;
52         }
53         _D("old file name : %s", old_filename);
54
55         switch(type) {
56         case LOCK_BG_DEFAULT:
57                 if (LOCK_ERROR_OK != lock_property_get_string(PROPERTY_TYPE_SYSTEM_SETTINGS, (void *)SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, &lock_bg)) {
58                         _E("Failed to get lockscreen BG");
59                         goto ERROR;
60                 }
61                 goto_if(!lock_bg, ERROR);
62
63                 _D("lock_bg : %s", lock_bg);
64
65                 if (!elm_bg_file_set(s_info.bg, lock_bg, NULL)) {
66                         _E("Failed to set a BG image : %s", lock_bg);
67                         free(lock_bg);
68                         goto ERROR;
69                 }
70
71                 emission = EDJE_SIGNAL_EMIT_MUSIC_OFF;
72
73                 free(lock_bg);
74                 break;
75         case LOCK_BG_ALBUM_ART:
76                 if (!file) {
77                         _E("Failed to set a BG image");
78                         return LOCK_ERROR_INVALID_PARAMETER;
79                 }
80
81                 if (!elm_bg_file_set(s_info.bg, file, NULL)) {
82                         _E("Failed to set album art BG : %s", file);
83                         goto ERROR;
84                 }
85
86                 emission = EDJE_SIGNAL_EMIT_MUSIC_ON;
87                 break;
88         default:
89                 _E("Failed to set background image : type error(%d)", type);
90                 goto ERROR;
91         }
92
93         lock_layout = lock_default_lock_layout_get();
94         if (lock_layout) {
95                 elm_layout_signal_emit(lock_layout, emission, EDJE_SIGNAL_SOURCE);
96         }
97
98         return LOCK_ERROR_OK;
99
100 ERROR:
101         if (!elm_bg_file_set(s_info.bg, old_filename, NULL)) {
102                 _E("Failed to set old BG file : %s. Retry to set default BG.", old_filename);
103                 if (!elm_bg_file_set(s_info.bg, LOCK_DEFAULT_BG_PATH, NULL)) {
104                         _E("Failed to set default BG : %s.", LOCK_DEFAULT_BG_PATH);
105                         return LOCK_ERROR_FAIL;
106                 }
107         }
108
109         return LOCK_ERROR_OK;
110 }
111
112 Evas_Object *lock_background_view_bg_create(Evas_Object *win)
113 {
114         int win_w = lock_window_width_get();
115         int win_h = lock_window_height_get();
116         _D("win size : %dx%d", win_w, win_h);
117
118         retv_if(!win, NULL);
119
120         Evas_Object *bg = elm_bg_add(win);
121         retv_if(!bg , NULL);
122
123         elm_bg_option_set(bg, ELM_BG_OPTION_SCALE);
124
125         evas_object_size_hint_min_set(bg, win_w, win_h);
126         elm_win_resize_object_add(win, bg);
127         evas_object_show(bg);
128
129         s_info.bg = bg;
130
131         if (LOCK_ERROR_OK != lock_background_view_image_set(LOCK_BG_DEFAULT, NULL)) {
132                 _E("Failed to set a BG image");
133         }
134
135         return bg;
136 }
137
138 void lock_background_view_bg_del(void)
139 {
140         if (s_info.bg) {
141                 evas_object_del(s_info.bg);
142                 s_info.bg = NULL;
143         }
144 }