4 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
25 #include <Ecore_File.h>
27 #include "vconf-keys.h"
29 #include "bt-share-common.h"
31 int _bt_share_block_sleep(gboolean is_block)
33 static int block_sleep_count = 0;
36 DBG("is_block [%d], block_sleep_count[%d]\n", is_block,
40 if (block_sleep_count < 0) {
41 DBG("block_sleep_count[%d] is invalid. It is set to 0.\n",
43 block_sleep_count = 0;
44 } else if (block_sleep_count == 0) {
45 result = pm_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
47 DBG("LCD Lock is failed with result code [%d]\n", result);
57 if (block_sleep_count <= 0) {
58 DBG("block_sleep_count[%d] is invalid. It is set to 0.\n",
60 block_sleep_count = 0;
61 } else if (block_sleep_count == 1) {
62 result = pm_unlock_state(LCD_OFF, PM_RESET_TIMER);
64 DBG("LCD Unlock is failed with result code [%d]\n",
76 DBG("result [%d]\n", result);
82 int _bt_set_transfer_indicator(gboolean state)
85 static int block_cnt = 0;
88 ret = vconf_get_int(VCONFKEY_BT_STATUS, (void *)&bt_device_state);
90 DBG("Get vconf failed\n");
96 if(bt_device_state & BT_STATUS_TRANSFER)
98 bt_device_state |= BT_STATUS_TRANSFER;
104 bt_device_state ^= BT_STATUS_TRANSFER;
107 ret = vconf_set_int(VCONFKEY_BT_STATUS, bt_device_state);
109 DBG("Set vconf failed\n");
115 static char *__bt_share_get_transfer_file_name(int file_type)
123 if (file_type == BT_HTTP_FILE) {
124 file_name = HTML_FILE_NAME;
125 file_format = HTML_FILE_FORMAT;
127 file_name = TXT_FILE_NAME;
128 file_format = TXT_FILE_FORMAT;
131 file = g_strdup(file_name);
133 /* While the file exists, increase the file name */
134 while (access(file, F_OK) == 0) {
137 appendix = g_strdup_printf("_%d", count);
138 file = g_strdup_printf(file_format, appendix);
147 void _bt_remove_tmp_file(char *file_path)
149 if (g_str_has_prefix(file_path, BT_TMP_FILE) == TRUE) {
150 DBG("Remove the file: %s", file_path);
151 ecore_file_remove(file_path);
155 char *_bt_share_create_transfer_file(char *text)
164 retv_if(text == NULL, NULL);
166 url_sheme = g_uri_parse_scheme(text);
169 /* HTTP file generate */
171 file_type = BT_HTTP_FILE;
173 /* TXT file generate */
174 file_type = BT_TXT_FILE;
177 file = __bt_share_get_transfer_file_name(file_type);
178 retv_if(file == NULL, NULL);
180 fd = open(file, O_RDWR | O_CREAT, 0755);
183 ERR("Fail to open the file");
187 if (file_type == BT_HTTP_FILE) {
188 content = g_strdup_printf(HTML_FORMAT, text, text);
190 content = g_strdup(text);
193 DBG("content: \n%s", content);
195 write_size = write(fd, content, strlen(content));
199 if (write_size < 0) {
200 ERR("Fail to write in file");