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