summaryrefslogtreecommitdiff
path: root/main/src/control/ivug-parameter.c
blob: 5717181044f6a6522e6527c5f039c82d3713a0d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
/*
 * Copyright 2012  Samsung Electronics Co., Ltd
 *
 * Licensed under the Flora License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *	  http://www.tizenopensource.org/license
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#include <bundle.h>
#include <string.h>

#include "ivug-common.h"
#include "ivug-debug.h"
#include "ivug-parameter.h"

//bundle key
#define IVUG_BUNDLE_KEY_VIEW_MODE 		"View Mode"
#define IVUG_BUNDLE_KEY_PATH			"Path"
#define IVUG_BUNDLE_KEY_THUMBNAIL_PATH	"Thumb Path"
#define IVUG_BUNDLE_KEY_ALBUM_IDX 		"Album index"
#define IVUG_BUNDLE_KEY_VIEW_BY			"View By"
#define IVUG_BUNDLE_KEY_INDEX			"Index"
#define IVUG_BUNDLE_KEY_SORT_BY			"Sort By"

#define IVUG_BUNDLE_KEY_MAX_LONGITUDE	"LON_MAX"
#define IVUG_BUNDLE_KEY_MIN_LONGITUDE	"LON_MIN"
#define IVUG_BUNDLE_KEY_MAX_LATITUDE	"LAT_MAX"
#define IVUG_BUNDLE_KEY_MIN_LATITUDE	"LAT_MIN"

#define IVUG_BUNDLE_KEY_SETAS_TYPE		"Setas type"

#define IVUG_BUNDLE_KEY_MEDIA_TYPE		"Media type"

//default values
#define IVUG_DEFAULT_MODE IVUG_MODE_SINGLE
#define IVUG_DEFAULT_INDEX (-1)

static ivug_mode
_get_view_mode(ivug_parameter* data, const char* val)
{
	IV_ASSERT(val != NULL);

#define IVUG_BUNDLE_VALUE_VIEW_MODE_ALBUM 	"ALBUM"
#define IVUG_BUNDLE_VALUE_VIEW_MODE_NORMAL 	"NORMAL"
#define IVUG_BUNDLE_VALUE_VIEW_MODE_SINGLE 	"SINGLE"
#define IVUG_BUNDLE_VALUE_VIEW_MODE_GALLERY 	"GALLERY"
#define IVUG_BUNDLE_VALUE_VIEW_MODE_CAMERA	"CAMERA"
#define IVUG_BUNDLE_VALUE_VIEW_MODE_DISPLAY	"DISPLAY"
#define IVUG_BUNDLE_VALUE_VIEW_MODE_SETAS		"SETAS"
	int len = strlen(val);

	if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_NORMAL, len) == 0
		|| strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_GALLERY, len) == 0 )
	{
		return IVUG_MODE_NORMAL;
	}
	else if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_ALBUM, len) == 0)
	{
		// Probably, UnUsed.
		MSG_IVUG_ERROR("ALBUM is deprecated!!!! plz check");
		printf("bundle key ALBUM is deprecated!!!! plz check\n");
		return IVUG_MODE_NORMAL;
	}
	else if ( strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_CAMERA, len) == 0)
	{
		data->start_index = 1;						//apply window loading
		data->view_by = IVUG_VIEW_BY_FOLDER;		// In camera case, All images should be shown in camera folder.
		return IVUG_MODE_CAMERA;
	}
	else if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_SINGLE, len) == 0)
	{
		data->view_by = IVUG_VIEW_BY_FILE;
		return IVUG_MODE_SINGLE;
	}
	else if ( strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_DISPLAY, len) == 0)
	{
		data->view_by = IVUG_VIEW_BY_FILE;
		return IVUG_MODE_DISPLAY;
	}
	else if(strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_SETAS, len) == 0)
	{
		data->view_by = IVUG_VIEW_BY_FILE;
		return IVUG_MODE_SETAS;
	}

	MSG_IVUG_ERROR("Invalid mode : %s", val);
	return IVUG_MODE_INVAILD;
}


static ivug_view_by
_get_view_by(const char* val)
{
	//bundle value
#define IVUG_BUNDLE_VALUE_VIEW_BY_ALL			"All"
#define IVUG_BUNDLE_VALUE_VIEW_BY_FLODER		"By Folder"
#define IVUG_BUNDLE_VALUE_VIEW_BY_PLACES		"Places"

	IV_ASSERT(val != NULL);

	int len = strlen(val);

	if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_BY_FLODER, len) == 0 )
	{
		return IVUG_VIEW_BY_FOLDER;
	}
	else if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_BY_ALL, len) == 0 )
	{
		return IVUG_VIEW_BY_ALL;
	}
	else if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_BY_PLACES, len) == 0)
	{
		return IVUG_VIEW_BY_PLACES;
	}

	MSG_IVUG_ERROR("Invalid view by : %s", val);

	return IVUG_VIEW_BY_FILE;

}


static ivug_setas_type
_get_setas_type(const char* val)
{
	IV_ASSERT(val != NULL);

#define IVUG_BUNDLE_VALUE_SETAS_UG_WALLPAPER	"Wallpaper"

	int len = strlen(val);

	if (strncmp(val, IVUG_BUNDLE_VALUE_SETAS_UG_WALLPAPER, len) == 0 )
	{
		return IVUG_SET_AS_UG_TYPE_WALLPAPER;
	}

	MSG_IVUG_ERROR("Invalid setas ug type : %s", val);
	return IVUG_SET_AS_UG_TYPE_INVALID;
}

static ivug_media_type
_get_media_type(const char* val)
{
	IV_ASSERT(val != NULL);
#define IVUG_BUNDLE_VALUE_MEDIA_TYPE_ALL	"All"
#define IVUG_BUNDLE_VALUE_MEDIA_TYPE_IMAGE	"Image"
#define IVUG_BUNDLE_VALUE_MEDIA_TYPE_VIDEO	"Video"

	int len = strlen(val);

	if (strncmp(val, IVUG_BUNDLE_VALUE_MEDIA_TYPE_IMAGE, len) == 0 )
	{
		return IVUG_MEDIA_TYPE_IMAGE;
	}
	else if (strncmp(val, IVUG_BUNDLE_VALUE_MEDIA_TYPE_VIDEO, len) == 0)
	{
		return IVUG_MEDIA_TYPE_VIDEO;
	}
	else if(strncmp(val, IVUG_BUNDLE_VALUE_MEDIA_TYPE_ALL, len) == 0)
	{
		return IVUG_MEDIA_TYPE_ALL;
	}

	MSG_IVUG_ERROR("Invalid media type : %s", val);
	return IVUG_MEDIA_TYPE_MAX;
}



static void
_bundle_print(const char *key, const char *val, void *data)
{
	MSG_IVUG_HIGH("   %s:%s",key, val);
}

//parsing bundle
ivug_parameter*
ivug_param_create_from_bundle(bundle* b)
{
	if (b == NULL)
	{
		MSG_IVUG_WARN("bundle value is NULL");
		return NULL;
	}

	int nbundle_cnt = bundle_get_count(b);

	if ( nbundle_cnt == 0 )
	{
		MSG_IVUG_WARN("bundle count is %d", nbundle_cnt);
		return NULL;
	}

	//print key and value.
	MSG_IVUG_HIGH("**********************************");
	MSG_IVUG_HIGH("  Bundle Count = %d", nbundle_cnt);
	bundle_iterate(b, _bundle_print, NULL);
	MSG_IVUG_HIGH("**********************************");

	//parsing param
	ivug_parameter* data = (ivug_parameter*)calloc(1, sizeof(ivug_parameter));

	if (data == NULL)
	{
		MSG_IMAGEVIEW_FATAL("Cannot allocate memory");
		return NULL;
	}

// View By
	const char* szViewBy = NULL;

	szViewBy = bundle_get_val(b, IVUG_BUNDLE_KEY_VIEW_BY);
	if (szViewBy != NULL)
	{
		MSG_IVUG_HIGH("View By = %s", szViewBy);

		data->view_by = _get_view_by(szViewBy);
	}
	else
	{
		MSG_IVUG_ERROR("View By is NULL");
		data->view_by = IVUG_VIEW_BY_INVAILD;
	}

//parse image index at album
	const char* val = NULL;

	val = bundle_get_val(b, IVUG_BUNDLE_KEY_INDEX);
	if(val)
	{
		data->start_index = atoi(val);
		MSG_IVUG_HIGH("Slide Index = %d", data->start_index);
	}
	else
	{
		data->start_index = IVUG_DEFAULT_INDEX;
		MSG_IVUG_HIGH("Slide Index is not set. Set as default : %d", data->start_index);
	}

//parse mode
	const char* szMode = NULL;

	szMode = bundle_get_val(b, IVUG_BUNDLE_KEY_VIEW_MODE);

	if (szMode != NULL)
	{
		data->mode = _get_view_mode(data, szMode);
		MSG_IVUG_HIGH("View mode is %s(%d)", szMode, data->mode);
	}
	else
	{
		data->mode = IVUG_DEFAULT_MODE;
		MSG_IVUG_HIGH("View mode is NULL. Set Default(%d)", data->mode);
	}

//parse path
	const char* szFilePath = NULL;

	szFilePath = bundle_get_val(b, IVUG_BUNDLE_KEY_PATH);

	if ( szFilePath != NULL )
	{
		data->filepath = strdup(szFilePath);
		MSG_IVUG_HIGH("Current File = %s", data->filepath);
	}

	//parse album id -album id is cluster id of media service
	val = bundle_get_val(b, IVUG_BUNDLE_KEY_ALBUM_IDX);

	if(val && data->view_by != IVUG_VIEW_BY_ALL)
	{
		data->album_id = uuid_getuuid(val);
		MSG_IVUG_HIGH("album_uuid is %s", uuid_getchar(data->album_id));
	}
	else
	{
		data->album_id = INVALID_UUID;
		MSG_IVUG_WARN("Album index is NULL");
	}
	if (data->mode == IVUG_MODE_CAMERA)
	{
/*
		**********************************
		  Bundle Count = 2
		   View Mode:CAMERA
		   Path:/opt/media/Camera shots/IMAGE0021.jpg
		**********************************
*/
		// Get album id from file path.
		UUID cluster_id = ivug_get_album_id_from_filepath(data->filepath);

		data->album_id = uuid_assign(cluster_id);

		MSG_IVUG_HIGH("Get Album ID(%s) from file %s", uuid_getchar(data->album_id), data->filepath);
	}

// TODO : Check parameter integrity
	val = bundle_get_val(b, IVUG_BUNDLE_KEY_MEDIA_TYPE);
	if(val != NULL)
	{
		data->media_type = _get_media_type(val);
		MSG_IVUG_HIGH("Media Type=%s(%d)", val, data->media_type);
	}
	else
	{
		MSG_IVUG_WARN("Media type is not specified.");
	}

	long long int m = 0;
	long int e = 0;

	val = bundle_get_val(b, IVUG_BUNDLE_KEY_MAX_LONGITUDE);
	if(val != NULL)
	{
		eina_convert_atod(val, strlen(val), &m, &e);
		data->max_longitude = ldexp((double)m, e);
		MSG_IVUG_HIGH("Max Longitude =%f", data->max_longitude);
	}
	else
	{
		MSG_IVUG_MED("Max Longitude is not specified.");
	}

	val = bundle_get_val(b, IVUG_BUNDLE_KEY_MIN_LONGITUDE);
	if(val != NULL)
	{
		eina_convert_atod(val, strlen(val), &m, &e);
		data->min_longitude = ldexp((double)m, e);
		MSG_IVUG_HIGH("Min Longitude =%f", data->min_longitude);
	}
	else
	{
		MSG_IVUG_MED("Min Longitude is not specified.");
	}

	val = bundle_get_val(b, IVUG_BUNDLE_KEY_MAX_LATITUDE);
	if(val != NULL)
	{
		eina_convert_atod(val, strlen(val), &m, &e);
		data->max_latitude = ldexp((double)m, e);
		MSG_IVUG_HIGH("Max Latitude =%f", data->max_latitude);
	}
	else
	{
		MSG_IVUG_MED("Max Latitude is not specified.");
	}

	val = bundle_get_val(b, IVUG_BUNDLE_KEY_MIN_LATITUDE);
	if(val != NULL)
	{
		eina_convert_atod(val, strlen(val), &m, &e);
		data->min_latitude = ldexp((double)m, e);
		MSG_IVUG_HIGH("Min Latitude =%f", data->min_latitude);
	}
	else
	{
		MSG_IVUG_MED("Min Latitude is not specified.");
	}

	val = bundle_get_val(b, IVUG_BUNDLE_KEY_SETAS_TYPE);
	if (val)
	{
		MSG_IVUG_HIGH("SetAs UG Type=%s", val);
		data->setas_type = _get_setas_type(val);
	}

	return data;
}

void
ivug_param_delete(ivug_parameter* data)
{
	IV_ASSERT(data != NULL);
	if (data->filepath)
	{
		free(data->filepath);
		data->filepath = NULL;
	}

	uuid_free(data->album_id);

	free(data);

	MSG_IVUG_HIGH("Parameter is freed.");

}