Remove trivial unnecessary build dependency
[apps/core/preloaded/lockscreen.git] / src / background.c
1 /*
2  * Copyright (c) 2016 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.h"
20 #include "util.h"
21
22 #include <system_settings.h>
23 #include <Ecore.h>
24 #include <Ecore_File.h>
25
26 #define DEFAULT_BG IMAGE_DIR"Default.jpg"
27
28 static char *background_file;
29 static int init_count;
30 int LOCKSCREEN_EVENT_BACKGROUND_CHANGED;
31
32 int lockscreen_background_init(void)
33 {
34         char *bg;
35
36         if (!init_count) {
37                 LOCKSCREEN_EVENT_BACKGROUND_CHANGED = ecore_event_type_new();
38                 int ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, &bg);
39                 if (ret != SYSTEM_SETTINGS_ERROR_NONE) {
40                         ERR("system_settings_set_value_string failed: %s", get_error_message(ret));
41                         init_count = 0;
42                         return -1;
43                 }
44                 if (lockscreen_background_file_set(bg))
45                         lockscreen_background_file_set(NULL);
46                 free(bg);
47         }
48         init_count++;
49         return 0;
50 }
51
52 int lockscreen_background_file_set(const char *path)
53 {
54         if (!path) {
55                 return lockscreen_background_file_set(util_get_res_file_path(DEFAULT_BG));
56         }
57
58         if (background_file && !strcmp(background_file, path)) {
59                 return 0;
60         }
61
62         if (!ecore_file_can_read(path)) {
63                 ERR("Cannot access/read background file: %s", path);
64                 return -1;
65         }
66
67         free(background_file);
68         background_file = strdup(path);
69
70         ecore_event_add(LOCKSCREEN_EVENT_BACKGROUND_CHANGED, NULL, NULL, NULL);
71         return 0;
72 }
73
74 void lockscreen_background_shutdown(void)
75 {
76         if (init_count) {
77                 init_count--;
78                 free(background_file);
79                 background_file = NULL;
80         }
81 }
82
83 const char *lockscreen_background_file_get(void)
84 {
85         return background_file;
86 }