#include "stack.h"
Go to the source code of this file.
metadataStoreManager - init and manage the metadata store
<File description>="">
The data retrieved from the meta store is copied into an internal data format (dsListItem_t) used to render the information on the screen
"MAX_ITEMS_ON_ONE_PAGE" is a predefined value indicating the amount of meta store items that are displayed on one content lister page
<File description>="">
Definition in file metadataStoreManager.h.
void displayScanResult | ( | void | ) |
Definition at line 1071 of file metadataStoreManager.c.
01072 { 01073 int i; 01074 mdsFsItem_t *pFsItem; 01075 01076 for (i = 0; i < g_contentArray->len; i++) 01077 { 01078 pFsItem = &g_array_index(g_contentArray, mdsFsItem_t, i); 01079 printf("%d. Name: %s", i, pFsItem->szFilename); 01080 printf("\ttype: %d\n", (int) pFsItem->fit); 01081 } 01082 }
gchar* getContentCategoryID | ( | st_ContentType_e | type | ) |
Definition at line 716 of file metadataStoreManager.c.
00717 { 00718 static gchar szID[ERMDS_MAX_EXTENSION_ID_SIZE+1] = ""; 00719 00720 switch (type) 00721 { 00722 case st_ContentTypeBooks: 00723 strcpy(szID, BOOKS_CATEGORY); 00724 break; 00725 case st_ContentTypeNews: 00726 strcpy(szID, NEWSPAPERS_CATEGORY); 00727 break; 00728 case st_ContentTypeNotes: 00729 strcpy(szID, NOTES_CATEGORY); 00730 break; 00731 case st_ContentTypeDocs: 00732 strcpy(szID, DOCUMENTS_CATEGORY); 00733 break; 00734 case st_StorageTypeCF: 00735 strcpy(szID, CF_CATEGORY); 00736 break; 00737 case st_StorageTypeMain: 00738 strcpy(szID, MAIN_CATEGORY); 00739 break; 00740 case st_StorageTypeSD: 00741 strcpy(szID, SD_CATEGORY); 00742 break; 00743 case st_StorageTypeUSB: 00744 strcpy(szID, USB_CATEGORY); 00745 break; 00746 case st_MenuTypeMode: 00747 strcpy(szID, MODE_CATEGORY); 00748 break; 00749 case st_DownloadHistory: 00750 strcpy(szID, DOWNLOAD_HISTORY); 00751 break; 00752 case st_SearchResult: 00753 strcpy(szID, SEARCH_RESULT); 00754 break; 00755 case st_RecentDocuments: 00756 strcpy(szID, RECENTDOCUMENTS); 00757 break; 00758 case st_ContentTypeUndefined: 00759 default: 00760 szID[0] = '\0'; 00761 break; 00762 } 00763 return szID; 00764 }
char* getFieldString | ( | mdsFieldType_e | type | ) |
Definition at line 629 of file metadataStoreManager.c.
00630 { 00631 static char string[ERCL_MAX_FIELDNAME_SIZE+1]; 00632 00633 switch (type) 00634 { 00635 case mdsFieldAuthor: 00636 strcpy(string, AUTHOR); 00637 break; 00638 case mdsFieldDate: 00639 strcpy(string, DATE); 00640 break; 00641 case mdsFieldDescription: 00642 strcpy(string, DESCRIPTION); 00643 break; 00644 case mdsFieldFile: 00645 strcpy(string, FIELDFILE); 00646 break; 00647 case mdsFieldTitle: 00648 strcpy(string, TITLE); 00649 break; 00650 case mdsFieldFsName: 00651 strcpy(string, FSNAME); 00652 break; 00653 case mdsFieldExtName: 00654 strcpy(string, EXTENSION); 00655 break; 00656 case mdsFieldSize: 00657 strcpy(string, SIZE); 00658 break; 00659 case mdsFieldNone: 00660 default: 00661 string[0] = '\0'; 00662 break; 00663 } 00664 return string; 00665 }
mdsFieldType_e getFieldType | ( | char * | stringValue | ) |
Definition at line 667 of file metadataStoreManager.c.
00668 { 00669 if (stringValue) 00670 { 00671 //author - date - description - file - fsname - title - none 00672 if (strcmp(stringValue, AUTHOR) == 0) 00673 { 00674 return mdsFieldAuthor; 00675 } 00676 else if (strcmp(stringValue, DATE) == 0) 00677 { 00678 return mdsFieldDate; 00679 } 00680 else if (strcmp(stringValue, FIELDFILE) == 0) 00681 { 00682 return mdsFieldFile; 00683 } 00684 else if (strcmp(stringValue, FSNAME) == 0) 00685 { 00686 return mdsFieldFsName; 00687 } 00688 else if (strcmp(stringValue, TITLE) == 0) 00689 { 00690 return mdsFieldTitle; 00691 } 00692 else if (strcmp(stringValue, DESCRIPTION) == 0) 00693 { 00694 return mdsFieldDescription; 00695 } 00696 else if (strcmp(stringValue, EXTENSION) == 0) 00697 { 00698 return mdsFieldExtName; 00699 } 00700 else if (strcmp(stringValue, SIZE) == 0) 00701 { 00702 return mdsFieldSize; 00703 } 00704 else 00705 { 00706 return mdsFieldNone; 00707 } 00708 } 00709 else 00710 { 00711 return mdsFieldNone; 00712 } 00713 00714 }
gboolean mdsArcLocIsChanged | ( | st_ContentType_e | archiveType, | |
st_ContentType_e | storageType | |||
) |
Definition at line 825 of file metadataStoreManager.c.
00826 { 00827 char archiveDirName[ERMDS_MAX_FILENAME_SIZE], storageDirName[ERMDS_MAX_FILENAME_SIZE]; 00828 gboolean bRet = FALSE; 00829 00830 if ((archiveType != st_ContentTypeNews) 00831 && (archiveType != st_ContentTypeBooks) 00832 && (archiveType != st_ContentTypeDocs) 00833 && (archiveType != st_ContentTypeNotes)) 00834 { 00835 CL_ERRORPRINTF("invalid archive type[%d]", archiveType); 00836 return bRet; 00837 } 00838 if ((storageType != st_StorageTypeCF) 00839 && (storageType != st_StorageTypeSD) 00840 && (storageType != st_StorageTypeUSB) 00841 && (storageType != st_StorageTypeMain)) 00842 { 00843 CL_ERRORPRINTF("invalid storage type[%d]", storageType); 00844 return bRet; 00845 } 00846 00847 if ( mdsGetRootLocation(archiveType, archiveDirName, sizeof(archiveDirName)) > 0 ) 00848 { 00849 if ( mdsGetRootLocation(storageType, storageDirName, sizeof(storageDirName)) > 0 ) 00850 { 00851 CL_LOGPRINTF("%s,%s", archiveDirName, storageDirName); 00852 if (isRealPathSubFolder(archiveDirName, storageDirName)) 00853 { 00854 bRet = TRUE; 00855 } 00856 } 00857 else 00858 { 00859 CL_ERRORPRINTF("error"); 00860 } 00861 } 00862 else 00863 { 00864 CL_ERRORPRINTF("error"); 00865 } 00866 return bRet; 00867 }
void mdsDestroy | ( | void | ) |
Destroy memory allocated by this module
- |
Definition at line 93 of file metadataStoreManager.c.
00094 { 00095 rootInfoDestroy(); 00096 stackDestroyAll(); 00097 00098 if (g_contentArray) 00099 { 00100 g_array_free(g_contentArray, TRUE); 00101 g_contentArray = NULL; 00102 } 00103 }
unsigned int mdsGetIndex | ( | st_ContentType_e | contentType | ) |
Retrieve the index field of the current top stack item
Definition at line 369 of file metadataStoreManager.c.
00370 { 00371 unsigned int returnValue = 0; 00372 stItem_t *theItem; 00373 00374 theItem = stackPeek(contentType); 00375 00376 if (NULL != theItem) 00377 { 00378 returnValue = theItem->index; 00379 } 00380 else 00381 { 00382 if (NULL != g_rootInfo[contentType]) 00383 { 00384 returnValue = g_rootInfo[contentType]->index; 00385 } 00386 } 00387 return returnValue; 00388 }
int mdsGetItemCount | ( | void | ) |
Definition at line 258 of file metadataStoreManager.c.
00259 { 00260 00261 if (g_contentArray) 00262 { 00263 CL_STACKPRINTF("%d", g_contentArray->len); 00264 return g_contentArray->len; 00265 } 00266 else 00267 { 00268 CL_STACKPRINTF("0"); 00269 return 0; 00270 } 00271 }
gboolean mdsGetItemFilename | ( | int | index, | |
gchar * | szFilename, | |||
int | len | |||
) |
Definition at line 305 of file metadataStoreManager.c.
00306 { 00307 mdsFsItem_t *pFsItem = NULL; 00308 00309 g_return_val_if_fail((g_contentArray != NULL), FALSE); 00310 g_return_val_if_fail( ((index >= 0) && (index < g_contentArray->len)) , FALSE); 00311 g_return_val_if_fail((szFilename != NULL), FALSE); 00312 00313 pFsItem = &g_array_index(g_contentArray, mdsFsItem_t, index); 00314 g_return_val_if_fail((pFsItem != NULL), FALSE); 00315 snprintf(szFilename, len, "%s", pFsItem->szFilename); 00316 00317 return TRUE; 00318 }
int mdsGetItemIndex | ( | const gchar * | szFilename | ) |
Definition at line 274 of file metadataStoreManager.c.
00275 { 00276 int i; 00277 int index = -1; 00278 gboolean found; 00279 mdsFsItem_t *pFsItem; 00280 char *cp; 00281 char szRealpath[PATH_MAX]; 00282 00283 g_return_val_if_fail((g_contentArray != NULL), -1); 00284 00285 for ( i = 0, found = FALSE ; 00286 i < g_contentArray->len && !found ; 00287 i++ ) 00288 { 00289 pFsItem = &g_array_index(g_contentArray, mdsFsItem_t, i); 00290 cp = realpath(pFsItem->szFilename, szRealpath); 00291 if (cp != NULL) 00292 { 00293 if (strcmp(szFilename, szRealpath) == 0 ) 00294 { 00295 found = TRUE; 00296 index = i; 00297 } 00298 } 00299 } 00300 00301 return index; 00302 }
int mdsGetRootLocation | ( | const st_ContentType_e | contentType, | |
char * | location, | |||
const int | length | |||
) |
Retrieve the root location of specified content type
Definition at line 780 of file metadataStoreManager.c.
00781 { 00782 int nRet = 0; 00783 char* cp; 00784 char szRealpath[PATH_MAX]; 00785 00786 if (NULL == location || 0 >= length) 00787 { 00788 CL_ERRORPRINTF("Invalid buffer pointer or length!"); 00789 return nRet; 00790 } 00791 00792 if ((NULL == g_rootInfo[contentType]) || (NULL == g_rootInfo[contentType]->dirArray)) 00793 { 00794 if (contentType == st_MenuTypeMode) 00795 { 00796 CL_ERRORPRINTF("No root dir specified for st_MenuTypeMode!"); 00797 return nRet; 00798 } 00799 else 00800 { 00801 CL_ERRORPRINTF("No root dir for contentType [%d], fallback to MODE menu", contentType); 00802 return mdsGetRootLocation(st_MenuTypeMode, location, length); 00803 } 00804 } 00805 00806 mdsDirectory_t *directory = &g_array_index(g_rootInfo[contentType]->dirArray, mdsDirectory_t, 0); 00807 if (directory) 00808 { 00809 cp = realpath(directory->szFilename, szRealpath); 00810 if (cp == NULL) 00811 { 00812 // no realpath found -> report original path 00813 cp = directory->szFilename; 00814 } 00815 nRet = snprintf(location, length, "%s", cp); 00816 } 00817 else 00818 { 00819 CL_ERRORPRINTF("Invalid directory pointer!"); 00820 } 00821 return nRet; 00822 }
mdsSortStruct_t* mdsGetSortStructOfRootInfo | ( | st_ContentType_e | type | ) |
Definition at line 582 of file metadataStoreManager.c.
00583 { 00584 stItem_t *rootItem = NULL; 00585 00586 if (type < st_ContentTypeBooks || type >= st_ContentTypeUndefined || type >= TOTAL_STACK_COUNT) 00587 { 00588 CL_ERRORPRINTF("Invalid arguments"); 00589 return NULL; 00590 } 00591 00592 rootItem = g_rootInfo[type]; 00593 if (rootItem) 00594 { 00595 return &(rootItem->sort); 00596 } 00597 else 00598 { 00599 CL_WARNPRINTF("Can't find the rootItem of type%d", type); 00600 return NULL; 00601 } 00602 }
void mdsInit | ( | void | ) |
Init stack (for every content key) Init storage used for content history
- |
Definition at line 79 of file metadataStoreManager.c.
00080 { 00081 // destory the old ones 00082 mdsDestroy(); 00083 00084 rootInfoInit(); 00085 stackInitAll(); 00086 00087 mdsRecreateArchives(st_StorageTypeMain); 00088 mdsRecreateArchives(st_StorageTypeCF); 00089 mdsRecreateArchives(st_StorageTypeSD); 00090 mdsRecreateArchives(st_StorageTypeUSB); 00091 }
void mdsRecreateArchives | ( | st_ContentType_e | storageType | ) |
Definition at line 873 of file metadataStoreManager.c.
00874 { 00875 CL_LOGPRINTF("entry"); 00876 00877 // check the argument is valid or not 00878 if ( (storageType != st_StorageTypeCF) && (storageType != st_StorageTypeSD) 00879 && (storageType != st_StorageTypeUSB) && (storageType != st_StorageTypeMain) ) 00880 { 00881 CL_ERRORPRINTF("invalid storage type[%d]", storageType); 00882 return; 00883 } 00884 00885 if (st_StorageTypeMain == storageType) 00886 { 00887 // if it's internal memory, 00888 // always recreate the archive folders if they don't exist 00889 recreateArchives(st_StorageTypeMain); 00890 } 00891 else 00892 { 00893 // if one of the archives points to the storage, 00894 // recreate the archive folders if they don't exsit on storage 00895 if ( mdsArcLocIsChanged(st_ContentTypeNews, storageType) 00896 || mdsArcLocIsChanged(st_ContentTypeBooks, storageType) 00897 || mdsArcLocIsChanged(st_ContentTypeDocs, storageType) 00898 || mdsArcLocIsChanged(st_ContentTypeNotes, storageType) ) 00899 { 00900 recreateArchives(storageType); 00901 } 00902 } 00903 }
int mdsScanCurrent | ( | st_ContentType_e | contentType | ) |
Scan using the current "content details" information if not available use the "root" values
contentType | indication of the content category |
Definition at line 140 of file metadataStoreManager.c.
00141 { 00142 stItem_t *contentInfo; 00143 int result = 0; 00144 mdsSortStruct_t *sort = NULL; 00145 int sortResult; 00146 00147 CL_STACKPRINTF("entry: contentType [%d]", contentType); 00148 00149 if (NULL == g_rootInfo[contentType]) 00150 { 00151 CL_ERRORPRINTF("No g_rootInfo for contentType [%d], fallback to MODE menu", contentType); 00152 contentType = st_MenuTypeMode; 00153 } 00154 g_return_val_if_fail( (NULL != g_rootInfo[contentType]), result); 00155 00156 // clear the previous retrieved content information 00157 if (g_contentArray) 00158 { 00159 CL_STACKPRINTF("g_array_free"); 00160 g_array_free(g_contentArray, TRUE); 00161 g_contentArray = NULL; 00162 } 00163 00164 contentInfo = stackPeek(contentType); 00165 00166 CL_TIMEDISPLAY("before scan"); 00167 00168 if (NULL == contentInfo) 00169 { 00170 CL_STACKPRINTF("=> root content"); 00171 result = erMdsContentScan(g_rootInfo[contentType]->dirArray, &g_contentArray); 00172 } 00173 else 00174 { 00175 //retrieve new content 00176 stackItemDisplay(contentInfo); 00177 result = erMdsContentScan(contentInfo->dirArray, &g_contentArray); 00178 } 00179 00180 CL_TIMEDISPLAY("after scan"); 00181 00182 if ((ERMDS_CONTENT_SCAN_FAILED != result) && (NULL != g_contentArray)) 00183 { 00184 // we always take the sort settings from the rootInfo 00185 sort = &g_rootInfo[contentType]->sort; 00186 sortResult = erMdsContentSort(g_contentArray, sort); 00187 00188 CL_LOGPRINTF("erMdsContentSort returned %d", sortResult); 00189 } 00190 return result; 00191 }
int mdsScanNext | ( | st_ContentType_e | contentType, | |
char * | directory, | |||
unsigned int | theIndex | |||
) |
Scan using the current "content details" information but with this new directory data. And store these new "content details" for this contentType on the stack.
contentType | indication of the content category | |
folder | directory information | |
index | currently selected index |
Also up
Definition at line 200 of file metadataStoreManager.c.
00201 { 00202 stItem_t *newItem; 00203 stItem_t *currentItem; 00204 int result = 0; 00205 mdsDirectory_t folder; 00206 00207 strcpy(folder.szFilename, directory); 00208 00209 CL_STACKPRINTF("%s", folder.szFilename); 00210 00211 newItem = g_new0(stItem_t, 1); 00212 currentItem = stackPeek(contentType); 00213 00214 if (NULL == currentItem) 00215 { 00216 CL_STACKPRINTF("=> root content"); 00217 currentItem = g_rootInfo[contentType]; 00218 } 00219 00220 // create a new array to store the directory info 00221 newItem->dirArray = g_array_sized_new(FALSE, TRUE, ERMDS_MAX_FILENAME_SIZE, INITIAL_DIR_COUNT_ARRAY_SIZE); 00222 CL_STACKPRINTF("newItem->dirArray 0x%x", (unsigned int) newItem->dirArray); 00223 g_array_append_val(newItem->dirArray, folder); 00224 00225 // copy the rest of the content from the "current" content details 00226 00227 // we needn't copy the sort settings because we always use them from the rootInfo. 00228 // newItem->sort.ascending = currentItem->sort.ascending; 00229 // newItem->sort.ft = currentItem->sort.ft; 00230 newItem->index = 0; 00231 00232 // put the new item on the stack 00233 stackPush(contentType, newItem); 00234 00235 //copy of new item (not of the referenced data!) was made on the stack 00236 g_free(newItem); 00237 00238 result = mdsScanCurrent(contentType); 00239 return result; 00240 }
int mdsScanPrevious | ( | st_ContentType_e | contentType | ) |
Remove the current "content details" from the stack and scan using the new current "content details" information.
if not available use the "root" values /home/ann/eReader/svn/eReader/content/
contentType | indication of the content category |
Definition at line 246 of file metadataStoreManager.c.
00247 { 00248 int result = 0; 00249 00250 CL_STACKPRINTF(""); 00251 00252 stackPop(contentType); 00253 result = mdsScanCurrent(contentType); 00254 return result; 00255 }
int mdsScanRoot | ( | st_ContentType_e | contentType | ) |
Scan the root directory
contentType | indication of the content category |
Definition at line 105 of file metadataStoreManager.c.
00106 { 00107 int result = 0; 00108 mdsSortStruct_t *sort = NULL; 00109 int sortResult; 00110 00111 CL_STACKPRINTF(""); 00112 00113 // clear the previous retrieved content information 00114 if (g_contentArray) 00115 { 00116 CL_STACKPRINTF("g_array_free"); 00117 g_array_free(g_contentArray, TRUE); 00118 g_contentArray = NULL; 00119 } 00120 00121 CL_TIMEDISPLAY("before scan"); 00122 00123 if (NULL != g_rootInfo[contentType]) 00124 { 00125 result = erMdsContentScan(g_rootInfo[contentType]->dirArray, &g_contentArray); 00126 sort = &g_rootInfo[contentType]->sort; 00127 } 00128 00129 CL_TIMEDISPLAY("after scan"); 00130 00131 if ((ERMDS_CONTENT_SCAN_FAILED != result) && (NULL != g_contentArray)) 00132 { 00133 sortResult = erMdsContentSort(g_contentArray, sort); 00134 00135 CL_LOGPRINTF("erMdsContentSort returned %d", sortResult); 00136 } 00137 return result; 00138 }
void mdsSetIndex | ( | st_ContentType_e | contentType, | |
unsigned int | index | |||
) |
Update the index field of the current top stack item
Definition at line 345 of file metadataStoreManager.c.
00346 { 00347 stItem_t *theItem; 00348 00349 theItem = stackPeek(contentType); 00350 00351 if (NULL != theItem) 00352 { 00353 //update the index value 00354 theItem->index = index; 00355 } 00356 else 00357 { 00358 //update the root index 00359 if (NULL != g_rootInfo[contentType]) 00360 { 00361 g_rootInfo[contentType]->index = index; 00362 } 00363 } 00364 return; 00365 }
int mdsSetPageContent | ( | clDisplayItem_t * | displayItemArray, | |
int | nBegin, | |||
int * | nChunk | |||
) |
Definition at line 321 of file metadataStoreManager.c.
00322 { 00323 int returnValue; 00324 00325 if (g_contentArray) 00326 { 00327 CL_TIMEDISPLAY("before erClGetDisplayItems"); 00328 00329 returnValue = erClGetDisplayItems(g_contentArray, nBegin, nChunk, displayItemArray); 00330 00331 CL_TIMEDISPLAY("after erClGetDisplayItems"); 00332 00333 } 00334 else 00335 { 00336 CL_ERRORPRINTF("g_contentArray == NULL"); 00337 returnValue = (-1); 00338 } 00339 00340 return returnValue; 00341 }
void mdsSetSortStructOfRootInfo | ( | st_ContentType_e | type, | |
const mdsSortStruct_t * | sort | |||
) |
Definition at line 604 of file metadataStoreManager.c.
00605 { 00606 stItem_t *rootItem = NULL; 00607 mdsSortStruct_t *localSort = NULL; 00608 00609 if (type < st_ContentTypeBooks || type >= st_ContentTypeUndefined || type >= TOTAL_STACK_COUNT || NULL == sort) 00610 { 00611 CL_ERRORPRINTF("Invalid arguments"); 00612 return; 00613 } 00614 00615 rootItem = g_rootInfo[type]; 00616 if (rootItem) 00617 { 00618 localSort = &(rootItem->sort); 00619 localSort->ascending = sort->ascending; 00620 localSort->ft = sort->ft; 00621 } 00622 else 00623 { 00624 CL_WARNPRINTF("Can't find the rootItem of type%d", type); 00625 return; 00626 } 00627 }
gboolean storageIsMounted | ( | st_ContentType_e | storageType | ) |
Definition at line 1021 of file metadataStoreManager.c.
01022 { 01023 CL_LOGPRINTF("entry"); 01024 01025 gboolean found = FALSE; 01026 01027 char storageDirName[ERMDS_MAX_FILENAME_SIZE]; 01028 01029 if ( mdsGetRootLocation(storageType, storageDirName, sizeof(storageDirName)) > 0 ) 01030 { 01031 char *cp = NULL; 01032 char realPath[ERMDS_MAX_FILENAME_SIZE]; 01033 01034 cp = realpath(storageDirName, realPath); 01035 CL_LOGPRINTF("%s,%s", storageDirName, realPath); 01036 01037 FILE *fp = setmntent("/proc/mounts", "r"); 01038 struct mntent* mt = NULL; 01039 01040 while ((mt = getmntent(fp))) 01041 { 01042 CL_LOGPRINTF("Partition: %s: %s %s", mt->mnt_fsname, mt->mnt_dir, mt->mnt_type); 01043 01044 if (strcasecmp(mt->mnt_dir, realPath) == 0) 01045 { 01046 if ( strcasecmp(mt->mnt_type, "vfat") == 0 ) 01047 { 01048 found = TRUE; 01049 break; 01050 } 01051 else 01052 { 01053 found = FALSE; 01054 } 01055 } 01056 } 01057 01058 endmntent(fp); 01059 } 01060 else 01061 { 01062 CL_ERRORPRINTF("can't get the path of storageType[%d]", storageType); 01063 } 01064 01065 CL_LOGPRINTF("found[%d]", found); 01066 return found; 01067 }