remove fatal to fail popup, show only one file that not in db
[apps/core/preloaded/ug-image-viewer-efl.git] / main / src / control / ivug-parameter.c
old mode 100644 (file)
new mode 100755 (executable)
index 58ef551..7cef9d3
@@ -5,7 +5,7 @@
  * 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
+ *       http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
 
 #define IVUG_BUNDLE_KEY_MEDIA_TYPE             "Media type"
 
-#define IVUG_BUNDLE_KEY_MSS_SERVER_ID  "MSS_ServerID"
-#define IVUG_BUNDLE_KEY_MSS_SORT_TYPE  "MSS_Sort_type"
-
-#define IVUG_BUNDLE_KEY_ALLSHARE_DEVICE_ID     "Device id"
-
-#define IVUG_BUNDLE_KEY_ALLSHARE_HANDLE_POINTER        "Handle pointer"
-
-#define IVUG_BUNDLE_KEY_PTP_TOTAL_COUNT                "Count"
-
 #define IVUG_BUNDLE_KEY_STANDALONE             "Standalone"
 
 #define IVUG_BUNDLE_KEY_CONTACT_ID             "Contact id"
@@ -88,15 +79,10 @@ _get_view_mode(ivug_parameter* data, const char* val)
 #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_WEB                "WEB_CLUSTER"
 #define IVUG_BUNDLE_VALUE_VIEW_MODE_CAMERA     "CAMERA"
 #define IVUG_BUNDLE_VALUE_VIEW_MODE_DISPLAY    "DISPLAY"
 #define IVUG_BUNDLE_VALUE_VIEW_MODE_SETAS              "SETAS"
-#define IVUG_BUNDLE_VALUE_VIEW_MODE_ALLSHARE   "ALLSHARE"
-#define IVUG_BUNDLE_VALUE_VIEW_MODE_PTP   "PTP"
 #define IVUG_BUNDLE_VALUE_VIEW_MODE_SLIDESHOW   "SLIDESHOW"
-#define IVUG_BUNDLE_VALUE_VIEW_MODE_BESTSHOT   "BESTSHOT"
-#define IVUG_BUNDLE_VALUE_VIEW_MODE_BUDDY   "BUDDY PHOTO SHARE"
 
        int len = strlen(val);
 
@@ -136,11 +122,7 @@ _get_view_mode(ivug_parameter* data, const char* val)
        }
        else if(strncmp(val, IVUG_BUNDLE_VALUE_VIEW_MODE_SLIDESHOW, len) == 0)
        {
-               if(data->view_by != IVUG_VIEW_BY_ALL &&
-                       data->view_by != IVUG_VIEW_BY_FAVORITES &&
-                       data->view_by != IVUG_VIEW_BY_TAG &&
-                       data->view_by != IVUG_VIEW_BY_PLACES &&
-                       data->view_by != IVUG_VIEW_BY_WEBALBUM)
+               if(data->view_by == IVUG_VIEW_BY_INVAILD)
                {
                        data->view_by = IVUG_VIEW_BY_FOLDER;
                }
@@ -161,9 +143,6 @@ _get_view_by(const char* val)
 #define IVUG_BUNDLE_VALUE_VIEW_BY_TAGS                 "Tags"
 #define IVUG_BUNDLE_VALUE_VIEW_BY_FLODER               "By Folder"
 #define IVUG_BUNDLE_VALUE_VIEW_BY_PLACES               "Places"
-#define IVUG_BUNDLE_VALUE_VIEW_BY_CONTACT_ID   "Contact id"
-#define IVUG_BUNDLE_VALUE_VIEW_BY_CONTACT_GROUP        "Contact group"
-#define IVUG_BUNDLE_VALUE_VIEW_BY_WEB                  "Web"
 
        IV_ASSERT(val != NULL);
 
@@ -189,18 +168,6 @@ _get_view_by(const char* val)
        {
                return IVUG_VIEW_BY_PLACES;
        }
-       else if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_BY_CONTACT_ID, len) == 0)
-       {
-               return IVUG_VIEW_BY_CONTACT_ID;
-       }
-       else if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_BY_CONTACT_GROUP, len) == 0)
-       {
-               return IVUG_VIEW_BY_CONTACT_GROUP;
-       }
-       else if (strncmp(val, IVUG_BUNDLE_VALUE_VIEW_BY_WEB, len) == 0)
-       {
-               return IVUG_VIEW_BY_WEBALBUM;
-       }
 
        MSG_IVUG_ERROR("Invalid view by : %s", val);
 
@@ -345,16 +312,6 @@ ivug_param_create_from_bundle(service_h service)
        _print_service_data(service);
        MSG_IVUG_HIGH("**********************************");
 
-       /*char *path = NULL;
-       service_get_uri(service, &path);        // app gadget
-       if(path)
-       {
-               MSG_IMAGEVIEW_ERROR("App gadget launched %s", path);
-               service_add_extra_data (service, "Path", path);
-               service_add_extra_data (service, "View Mode", "SINGLE");
-               _ivug_free(&path);
-       }*/
-
        //parsing param
        ivug_parameter* data = (ivug_parameter*)calloc(1, sizeof(ivug_parameter));
 
@@ -378,6 +335,40 @@ ivug_param_create_from_bundle(service_h service)
                data->bStandalone = false;
        }
 
+       //parse path
+       char* szFilePath = NULL;
+       {
+               service_get_extra_data (service, IVUG_BUNDLE_KEY_PATH, &szFilePath);
+               if(szFilePath == NULL)
+               {
+                       MSG_IVUG_ERROR("File path is NULL");
+                       service_get_uri(service, &szFilePath);  // app gadget
+                       if(szFilePath)
+                       {
+                               MSG_IMAGEVIEW_ERROR("App gadget launched %s", szFilePath);
+                               service_add_extra_data (service, "View Mode", "SINGLE");
+                       }
+               }
+               if ( szFilePath != NULL )
+               {
+                       if(strncmp(IVUG_FILE_PREFIX, szFilePath, strlen(IVUG_FILE_PREFIX)) == 0)
+                       {
+                               data->filepath = strdup(szFilePath + strlen(IVUG_FILE_PREFIX));
+                       }
+                       else
+                       {
+                               data->filepath = strdup(szFilePath);
+                       }
+                       MSG_IVUG_MED("Current File = %s", data->filepath);
+                       _ivug_free(&szFilePath);
+               }
+               else
+               {
+                       ivug_param_delete(data);
+                       return NULL;
+               }
+       }
+
 // View By
        char* szViewBy = NULL;
 
@@ -428,6 +419,13 @@ ivug_param_create_from_bundle(service_h service)
                data->view_by = IVUG_VIEW_BY_INVAILD;
        }
 
+       media_handle file_handle = ivug_db_get_file_handle(data->filepath);
+       if(file_handle == NULL)
+       {
+               MSG_IVUG_ERROR("Current File = %s is not in DB", data->filepath);
+               data->view_by = IVUG_VIEW_BY_FILE;
+       }
+
 //parse image index at album
        char* val = NULL;
 
@@ -440,7 +438,15 @@ ivug_param_create_from_bundle(service_h service)
        }
        else
        {
+               if(data->view_by == IVUG_VIEW_BY_FOLDER)
+               {
+                       MSG_IVUG_WARN("IVUG_VIEW_BY_FOLDER but index was not set");
+                       data->start_index = IVUG_INVALID_INDEX;
+               }
+               else
+               {
                data->start_index = IVUG_DEFAULT_INDEX;
+               }
                MSG_IVUG_WARN("Slide Index is not set. Set as default : %d", data->start_index);
        }
 
@@ -460,35 +466,6 @@ ivug_param_create_from_bundle(service_h service)
                MSG_IVUG_HIGH("View mode is NULL. Set Default(%d)", data->mode);
        }
 
-       //data->view_by = IVUG_VIEW_BY_ALLSHARE;        // TODO: for all share TEST
-
-//parse path
-       char* szFilePath = NULL;
-
-       {
-               service_get_extra_data (service, IVUG_BUNDLE_KEY_PATH, &szFilePath);
-               if ( szFilePath != NULL )
-               {
-                       if(strncmp(IVUG_FILE_PREFIX, szFilePath, strlen(IVUG_FILE_PREFIX)) == 0)
-                       {
-                               data->filepath = strdup(szFilePath + strlen(IVUG_FILE_PREFIX));
-                       }
-                       else
-                       {
-                               data->filepath = strdup(szFilePath);
-                       }
-                       MSG_IVUG_MED("Current File = %s", data->filepath);
-                       _ivug_free(&szFilePath);
-               }
-               else
-               {
-                       MSG_IVUG_ERROR("File path is NULL");
-
-                       ivug_param_delete(data);
-                       return NULL;
-               }
-       }
-
        //parse album id -album id is cluster id of media service
        service_get_extra_data (service, IVUG_BUNDLE_KEY_ALBUM_IDX, &val);
        if(val && data->view_by != IVUG_VIEW_BY_ALL)
@@ -515,22 +492,30 @@ ivug_param_create_from_bundle(service_h service)
                **********************************
 */
                // Get album id from file path.
-               media_handle m_handle = ivug_db_get_folder_handle(ecore_file_dir_get(data->filepath));
-               if(m_handle == NULL)
-               {
-                       MSG_IVUG_ERROR("View by Folder. but media handle is NULL" );
-                       ivug_param_delete(data);
-                       return NULL;
-               }
+               char *dir = ivug_get_directory(data->filepath);
+               media_handle m_handle = ivug_db_get_folder_handle(dir);
+               free(dir);
 
-               data->album_id = ivug_db_get_folder_id(m_handle);
+               if(data->album_id == INVALID_UUID)
+               {
+                       if(m_handle == NULL)
+                       {
+                               MSG_IVUG_ERROR("View by Folder. but media handle is NULL" );
+                               //ivug_param_delete(data);
+                               //return NULL;
+                               data->view_by = IVUG_VIEW_BY_DIRECTORY; // check manually
+                       }
+                       else
+                       {
+                               data->album_id = ivug_db_get_folder_id(m_handle);
 
-               ivug_db_destroy_folder_handle(m_handle);
+                               ivug_db_destroy_folder_handle(m_handle);
 
-               MSG_IVUG_HIGH("Get Album ID(%s) from file %s", uuid_getchar(data->album_id), data->filepath);
+                               MSG_IVUG_HIGH("Get Album ID(%s) from file %s", uuid_getchar(data->album_id), data->filepath);
+                       }
+               }
        }
 
-// TODO : Check parameter integrity
        service_get_extra_data (service, IVUG_BUNDLE_KEY_MEDIA_TYPE, &val);
        if(val != NULL)
        {
@@ -622,7 +607,6 @@ ivug_param_create_from_bundle(service_h service)
                }
                else
                {
-                       /* TODO : remove default value, width & height needed */
                        data->width = 100;
                        data->height = 100;
                        MSG_IVUG_HIGH("Rectangle ratio is not set. Set as default : %dx%d", data->width, data->height);
@@ -710,6 +694,7 @@ Filter_struct *ivug_param_create_filter(const ivug_parameter *param)
        IV_ASSERT(filter_str != NULL);
 
        media_handle handle = NULL;
+       char *dir = NULL;
 
        if ( param->view_by == IVUG_VIEW_BY_DIRECTORY )
        {
@@ -736,6 +721,10 @@ Filter_struct *ivug_param_create_filter(const ivug_parameter *param)
        filter_str->sort_type = param->sort_type;
        filter_str->index = param->start_index;
        filter_str->selected_list = param->selected_list;
+       if(param->filepath)
+       {
+               filter_str->filepath = strdup(param->filepath);
+       }
 
        if(filter_str->type == FILTER_DB)
        {
@@ -769,8 +758,10 @@ Filter_struct *ivug_param_create_filter(const ivug_parameter *param)
                case IVUG_VIEW_BY_FOLDER:
                        if(param->album_id == NULL)
                        {
-                               handle = ivug_db_get_folder_handle(ecore_file_dir_get(param->filepath));
+                               dir = ivug_get_directory(param->filepath);
+                               handle = ivug_db_get_folder_handle(dir);
                                filter->album_id = ivug_db_get_folder_id(handle);
+                               free(dir);
                        }
                        else
                        {
@@ -778,7 +769,6 @@ Filter_struct *ivug_param_create_filter(const ivug_parameter *param)
                        }
                        break;
                case IVUG_VIEW_BY_DIRECTORY:
-                       // TODO : Need more things?
                        break;
                case IVUG_VIEW_BY_INVAILD:
                default: