apply FSL(Flora Software License)
[profile/ivi/indicator-win.git] / daemon / indicator_util.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 #include <Ecore.h>
18 #include <Ecore_X.h>
19 #include "common.h"
20 #include "indicator.h"
21 #include "indicator_ui.h"
22 #include "indicator_gui.h"
23 #include "indicator_util.h"
24 #include "indicator_icon_util.h"
25 #include "indicator_box_util.h"
26 #include <vconf.h>
27
28 #define DEFAULT_DIR     ICONDIR
29 #define DIR_PREFIX      "Theme_%02d_"
30 #define LABEL_STRING    "<color=#%02x%02x%02x%02x>%s</color>"
31
32 static char *_icondir;
33
34 char *set_label_text_color(const char *txt)
35 {
36         Eina_Strbuf *temp_buf = NULL;
37         Eina_Bool buf_result = EINA_FALSE;
38         char *ret_str = NULL;
39
40         retif(txt == NULL, NULL, "Invalid parameter!");
41
42         temp_buf = eina_strbuf_new();
43         buf_result = eina_strbuf_append_printf(temp_buf,
44                                 LABEL_STRING, FONT_COLOR, txt);
45
46         if (buf_result == EINA_FALSE)
47                 INFO("Failed to make label string!");
48         else
49                 ret_str = eina_strbuf_string_steal(temp_buf);
50
51         eina_strbuf_free(temp_buf);
52         return ret_str;
53 }
54
55 const char *get_icon_dir(void)
56 {
57         if (_icondir == NULL)
58                 _icondir = DEFAULT_DIR;
59
60         return (const char *)_icondir;
61 }
62
63 static int _set_icon_dir(char *newdir)
64 {
65         char *new_icon_dir = NULL;
66
67         char dirname[PATH_MAX];
68         int r;
69
70         retif(!newdir, FAIL, "Invalid parameter!");
71         memset(dirname, 0x00, sizeof(dirname));
72         r = snprintf(dirname, sizeof(dirname), ICONDIR "/%s", newdir);
73         if (r < 0) {
74                 ERR("Failed to set new dir name!");
75                 return FAIL;
76         }
77
78         if (new_icon_dir != NULL)
79                 free(new_icon_dir);
80
81         new_icon_dir = strdup(dirname);
82         _icondir = new_icon_dir;
83
84         return 0;
85 }