File Manager / src / model /
  1. /*
  2. * Copyright 2014 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
  3. *
  4. * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
  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 "model/navi-path-storage.h"
  19. #include "utils/app-types.h"
  20. #include "utils/logger.h"
  21.  
  22. struct _navi_path_storage {
  23. Eina_List *path_list;
  24. };
  25.  
  26. navi_path_storage *navi_path_storage_create()
  27. {
  28. navi_path_storage *storage = calloc(1, sizeof(navi_path_storage));
  29. return storage;
  30. }
  31.  
  32. void navi_path_storage_destroy(navi_path_storage *storage)
  33. {
  34. if (storage) {
  35. char *temp = NULL;
  36. EINA_LIST_FREE(storage->path_list, temp)
  37. {
  38. free(temp);
  39. }
  40. storage->path_list = NULL;
  41. free(storage);
  42. }
  43. }
  44.  
  45. int navi_path_storage_add_folder(navi_path_storage *storage, const char *folder_name)
  46. {
  47. RETVM_IF(!storage, RESULT_TYPE_INVALID_ARG, "Storage is NULL");
  48. RETVM_IF(!folder_name, RESULT_TYPE_INVALID_ARG, "Name is NULL");
  49.  
  50. char *temp = strdup(folder_name);
  51. storage->path_list = eina_list_append(storage->path_list, temp);
  52.  
  53. return RESULT_TYPE_OK;
  54. }
  55.  
  56. int navi_path_storage_remove_path_to_index(navi_path_storage *storage, int index)
  57. {
  58. RETVM_IF(!storage, RESULT_TYPE_INVALID_ARG, "Storage is NULL");
  59.  
  60. int list_size = eina_list_count(storage->path_list);
  61. RETVM_IF(list_size < index, RESULT_TYPE_INVALID_ARG, "Requested index '%d' is to big", index);
  62.  
  63. if (storage->path_list) {
  64. while (eina_list_count(storage->path_list) > index) {
  65. Eina_List *last_node = eina_list_last(storage->path_list);
  66. if (last_node) {
  67. char *name = eina_list_data_get(last_node);
  68. free(name);
  69. }
  70. storage->path_list = eina_list_remove_list(storage->path_list, last_node);
  71. }
  72. return RESULT_TYPE_OK;
  73. } else {
  74. ERR("List is empty");
  75. return RESULT_TYPE_FAIL;
  76. }
  77. }
  78.  
  79. int navi_path_storage_get_path_list(navi_path_storage *storage, Eina_List **path_list)
  80. {
  81. RETVM_IF(!storage, RESULT_TYPE_INVALID_ARG, "Storage is NULL");
  82. RETVM_IF(!path_list, RESULT_TYPE_INVALID_ARG, "Folder list is NULL");
  83.  
  84. *path_list = storage->path_list;
  85.  
  86. return RESULT_TYPE_OK;
  87. }