Go to the source code of this file.
Defines | |
#define | MAX_RECENT_ITEMS 6 |
#define | MAX_DOWNLOAD_ITEMS 12 |
Functions | |
void | hsInit (void) |
void | hsDestroy (void) |
void | hsStoreItem (st_ContentType_e contentType, clDisplayItem_t *item) |
void | hsGetItem (st_ContentType_e contentType, clDisplayItem_t *item) |
gboolean | hsSetLocation (st_ContentType_e contentType, char *location) |
char * | hsGetLocation (st_ContentType_e contentType) |
gboolean | hsRemoveLocation (st_ContentType_e contentType) |
void | hsSetActiveViewer (st_ContentType_e contentType, char *viewerId) |
char * | hsGetActiveViewer (st_ContentType_e contentType) |
st_ContentType_e | hsGetContentType (char *viewerid) |
void | hsCleanupSymlinks (const char *szLinkDir) |
void | hsLimitSymlinks (const char *szLinkDir, int maxItems) |
<File description>=""> - store the last opened item for every category in memory
Definition in file history.h.
void hsCleanupSymlinks | ( | const char * | szLinkDir | ) |
Remove symlinks for which the target is not present
szTargetDir | directory to scan for symlinks |
Definition at line 544 of file history.c.
00545 { 00546 g_assert(szLinkDir != NULL); 00547 CL_HISTORYPRINTF("Entry: directory [%s]", szLinkDir); 00548 00549 DIR* dirp; 00550 struct dirent* direntp; 00551 struct stat statBuf; 00552 00553 char szName[ERMDS_MAX_FILENAME_SIZE]; 00554 00555 00556 if ((dirp = opendir(szLinkDir)) == NULL) 00557 { 00558 CL_ERRORPRINTF("Could not open directory %s (error %s).", szLinkDir, strerror(errno)); 00559 return; 00560 } 00561 else 00562 { 00563 while ((direntp = readdir(dirp)) != NULL) 00564 { 00565 if ( strcmp(".", direntp->d_name) == 0 00566 || strcmp("..", direntp->d_name) == 0) 00567 { 00568 // skip this entry 00569 continue; 00570 } 00571 00572 snprintf(szName, ERMDS_MAX_FILENAME_SIZE, "%s/%s", szLinkDir, direntp->d_name); 00573 if ( isSymLink(szName) 00574 && stat(szName, &statBuf) == -1 ) 00575 { 00576 // directory entry is a symlink, but no file/directory behind it: remove symlink 00577 CL_HISTORYPRINTF("Remove symlink [%s]", szName); 00578 unlink(szName); 00579 } 00580 } 00581 00582 closedir(dirp); 00583 } 00584 }
void hsDestroy | ( | void | ) |
Store the history information in the registry and destroy allocated resources used by the history module
Definition at line 137 of file history.c.
00138 { 00139 int index; 00140 regLastRead_t *theLastRead = NULL; 00141 00142 CL_HISTORYPRINTF(""); 00143 00144 //store the history information in the registry 00145 prepare_registry_write(); 00146 CL_HISTORYPRINTF("Checked and loaded registry"); 00147 00148 CL_HISTORYPRINTF("Store BOOKS_CATEGORY"); 00149 theLastRead = g_new0(regLastRead_t, 1); 00150 hsCreateConvertItem(theLastRead, g_history[st_ContentTypeBooks]); 00151 // avoid writing NULL to registry 00152 if (g_location[st_ContentTypeBooks]) 00153 { 00154 theLastRead->position = g_strdup(g_location[st_ContentTypeBooks]); 00155 } 00156 else 00157 { 00158 theLastRead->position = g_strdup(""); 00159 } 00160 erRegSetLastRead(BOOKS_CATEGORY, theLastRead); 00161 erRegFreeLastRead(theLastRead); 00162 00163 CL_HISTORYPRINTF("Store NEWSPAPERS_CATEGORY"); 00164 theLastRead = g_new0(regLastRead_t, 1); 00165 hsCreateConvertItem(theLastRead, g_history[st_ContentTypeNews]); 00166 // avoid writing NULL to registry 00167 if (g_location[st_ContentTypeNews]) 00168 { 00169 theLastRead->position = g_strdup(g_location[st_ContentTypeNews]); 00170 } 00171 else 00172 { 00173 theLastRead->position = g_strdup(""); 00174 } 00175 CL_HISTORYPRINTF("position %s", theLastRead->position); 00176 erRegSetLastRead(NEWSPAPERS_CATEGORY, theLastRead); 00177 erRegFreeLastRead(theLastRead); 00178 00179 CL_HISTORYPRINTF("Store DOCUMENTS_CATEGORY"); 00180 theLastRead = g_new0(regLastRead_t, 1); 00181 hsCreateConvertItem(theLastRead, g_history[st_ContentTypeDocs]); 00182 CL_HISTORYPRINTF("position %s", theLastRead->position); 00183 // avoid writing NULL to registry 00184 if (g_location[st_ContentTypeDocs]) 00185 { 00186 theLastRead->position = g_strdup(g_location[st_ContentTypeDocs]); 00187 } 00188 else 00189 { 00190 theLastRead->position = g_strdup(""); 00191 } 00192 CL_HISTORYPRINTF("position %s", theLastRead->position); 00193 erRegSetLastRead(DOCUMENTS_CATEGORY, theLastRead); 00194 erRegFreeLastRead(theLastRead); 00195 00196 CL_HISTORYPRINTF("Store NOTES_CATEGORY"); 00197 theLastRead = g_new0(regLastRead_t, 1); 00198 hsCreateConvertItem(theLastRead, g_history[st_ContentTypeNotes]); 00199 // avoid writing NULL to registry 00200 if (g_location[st_ContentTypeNotes]) 00201 { 00202 theLastRead->position = g_strdup(g_location[st_ContentTypeNotes]); 00203 } 00204 else 00205 { 00206 theLastRead->position = g_strdup(""); 00207 } 00208 CL_HISTORYPRINTF("position %s", theLastRead->position); 00209 erRegSetLastRead(NOTES_CATEGORY, theLastRead); 00210 erRegFreeLastRead(theLastRead); 00211 00212 do_registry_write(); 00213 CL_HISTORYPRINTF("Stored registry"); 00214 00215 00216 CL_HISTORYPRINTF("Free resources"); 00217 00218 for (index = 0; index < ARCHIVE_TYPE_COUNT; index++) 00219 { 00220 if (g_history[index]) 00221 { 00222 g_free(g_history[index]); 00223 g_history[index] = NULL; 00224 } 00225 00226 if (g_location[index]) 00227 { 00228 g_free(g_location[index]); 00229 g_location[index] = NULL; 00230 } 00231 } 00232 }
char* hsGetActiveViewer | ( | st_ContentType_e | contentType | ) |
Get the active viewer for the specified contentType
contentType |
Definition at line 335 of file history.c.
00336 { 00337 char *viewerId = NULL; 00338 00339 if (stackIsArchive(contentType)) 00340 { 00341 viewerId = g_activeViewer[contentType]; 00342 00343 CL_HISTORYPRINTF("contentType %d viewerId %s", contentType, viewerId); 00344 } 00345 return viewerId; 00346 }
st_ContentType_e hsGetContentType | ( | char * | viewerid | ) |
Get the contentType associated with the "active viewer"
contentType |
Definition at line 348 of file history.c.
00349 { 00350 st_ContentType_e theType = st_ContentTypeUndefined; 00351 int index; 00352 00353 CL_HISTORYPRINTF("viewerId %s", viewerId); 00354 00355 for (index = 0; index < ARCHIVE_TYPE_COUNT; index++) 00356 { 00357 if (strncmp(g_activeViewer[index], viewerId, UAID_MAX_SIZE) == 0) 00358 { 00359 CL_HISTORYPRINTF("theType %d", index); 00360 theType = index; 00361 } 00362 } 00363 return theType; 00364 }
void hsGetItem | ( | st_ContentType_e | contentType, | |
clDisplayItem_t * | item | |||
) |
retrieve a copy of the history item of the specified content type
contentType | ||
item | - reference to memory where the copy should be returned |
Definition at line 258 of file history.c.
00259 { 00260 CL_HISTORYPRINTF("contentType %d item 0x%x", contentType, (unsigned int) item); 00261 00262 if ((item) && (stackIsArchive(contentType))) 00263 { 00264 memcpy(item, g_history[contentType], sizeof(clDisplayItem_t)); 00265 } 00266 }
char* hsGetLocation | ( | st_ContentType_e | contentType | ) |
Get the item location information from the history data (RAM)
contentType |
Definition at line 286 of file history.c.
00287 { 00288 char *theLocation = NULL; 00289 00290 CL_HISTORYPRINTF("type %d", contentType); 00291 00292 if (stackIsArchive(contentType)) 00293 { 00294 theLocation = g_strdup(g_location[contentType]); 00295 } 00296 return theLocation; 00297 }
void hsInit | ( | void | ) |
Allocate memory to store one history item for the available archive content types and retrieve the history values from the registry
Definition at line 70 of file history.c.
00071 { 00072 int i; 00073 char buf[ERMDS_MAX_FILENAME_SIZE]; 00074 regLastRead_t *theBooks = NULL; 00075 regLastRead_t *theNews = NULL; 00076 regLastRead_t *theDocs = NULL; 00077 regLastRead_t *theNotes = NULL; 00078 00079 CL_HISTORYPRINTF(""); 00080 00081 // retrieve the history information from the registry 00082 theBooks = erRegGetLastRead(BOOKS_CATEGORY); 00083 theNews = erRegGetLastRead(NEWSPAPERS_CATEGORY); 00084 theDocs = erRegGetLastRead(DOCUMENTS_CATEGORY); 00085 theNotes = erRegGetLastRead(NOTES_CATEGORY); 00086 00087 g_history[st_ContentTypeBooks] = hsCreateItem(theBooks); 00088 if (theBooks) 00089 { 00090 CL_HISTORYPRINTF("Found BOOKS_CATEGORY (loc %s)", theBooks->position); 00091 g_location[st_ContentTypeBooks] = g_strdup(theBooks->position); 00092 erRegFreeLastRead(theBooks); 00093 } 00094 strncpy(g_activeViewer[st_ContentTypeBooks], NO_VIEWER_ACTIVE, UAID_MAX_SIZE); 00095 00096 g_history[st_ContentTypeNews] = hsCreateItem(theNews); 00097 if (theNews) 00098 { 00099 CL_HISTORYPRINTF("Found NEWSPAPERS_CATEGORY (loc %s)", theNews->position); 00100 g_location[st_ContentTypeNews] = g_strdup(theNews->position); 00101 erRegFreeLastRead(theNews); 00102 } 00103 strncpy(g_activeViewer[st_ContentTypeNews], NO_VIEWER_ACTIVE, UAID_MAX_SIZE); 00104 00105 g_history[st_ContentTypeDocs] = hsCreateItem(theDocs); 00106 if (theDocs) 00107 { 00108 CL_HISTORYPRINTF("Found DOCUMENTS_CATEGORY (loc %s)", theDocs->position); 00109 g_location[st_ContentTypeDocs] = g_strdup(theDocs->position); 00110 erRegFreeLastRead(theDocs); 00111 } 00112 strncpy(g_activeViewer[st_ContentTypeDocs], NO_VIEWER_ACTIVE, UAID_MAX_SIZE); 00113 00114 g_history[st_ContentTypeNotes] = hsCreateItem(theNotes); 00115 if (theNotes) 00116 { 00117 CL_HISTORYPRINTF("Found NOTES_CATEGORY (loc %s)", theNotes->position); 00118 g_location[st_ContentTypeNotes] = g_strdup(theNotes->position); 00119 erRegFreeLastRead(theNotes); 00120 } 00121 strncpy(g_activeViewer[st_ContentTypeNotes], NO_VIEWER_ACTIVE, UAID_MAX_SIZE); 00122 00123 // retrieve the recent-documents information from the registry 00124 i = mdsGetRootLocation(st_RecentDocuments, buf, sizeof(buf)); 00125 if (i > 0) 00126 { 00127 g_location[st_RecentDocuments] = g_strdup(buf); 00128 } 00129 else 00130 { 00131 CL_ERRORPRINTF("mdsGetRootLocation(st_RecentDocuments) returns [%d]", i); 00132 } 00133 }
void hsLimitSymlinks | ( | const char * | szLinkDir, | |
int | maxItems | |||
) |
Limit symlinks to the specified number, removing symlinks with "lowest" names
szTargetDir | directory to scan for symlinks | |
maxItems | maximum number of symlinks allowed |
Definition at line 588 of file history.c.
00589 { 00590 int i; 00591 DIR* dirp; 00592 struct dirent* direntp; 00593 00594 typedef struct 00595 { 00596 char szName[ERMDS_MAX_FILENAME_SIZE]; 00597 } linkInfo_t; 00598 00599 linkInfo_t* linkTable = alloca( sizeof(linkInfo_t) * (maxItems + 1) ); 00600 linkInfo_t* linkOldest = NULL; 00601 linkInfo_t* linkCurrent = &linkTable[0]; 00602 int linkNum = 0; 00603 00604 g_return_if_fail(linkTable != NULL); 00605 00606 if ((dirp = opendir(szLinkDir)) == NULL) 00607 { 00608 CL_ERRORPRINTF("Could not open directory %s (error %s).", szLinkDir, strerror(errno)); 00609 return; 00610 } 00611 else 00612 { 00613 while ((direntp = readdir(dirp)) != NULL) 00614 { 00615 if ( strcmp(".", direntp->d_name) == 0 00616 || strcmp("..", direntp->d_name) == 0) 00617 { 00618 // skip this entry 00619 continue; 00620 } 00621 00622 linkCurrent = &linkTable[linkNum]; 00623 snprintf(linkCurrent->szName, ERMDS_MAX_FILENAME_SIZE, "%s/%s", szLinkDir, direntp->d_name); 00624 00625 if (linkNum < maxItems) 00626 { 00627 // table not full: add this item 00628 linkNum++; 00629 if ( linkOldest == NULL 00630 || strcmp(linkCurrent->szName, linkOldest->szName) < 0) 00631 { 00632 linkOldest = linkCurrent; 00633 } 00634 } 00635 else if (strcmp(linkCurrent->szName, linkOldest->szName) < 0) 00636 { 00637 // table full and item older than oldest: remove current item 00638 CL_HISTORYPRINTF("Remove symlink [%s]", linkCurrent->szName); 00639 delete_fsitem(linkCurrent->szName); 00640 } 00641 else 00642 { 00643 // table full and item newer than oldest: replace oldest item 00644 CL_HISTORYPRINTF("Remove symlink [%s]", linkOldest->szName); 00645 delete_fsitem(linkOldest->szName); 00646 *linkOldest = *linkCurrent; 00647 00648 // find the oldest item now in the list 00649 for ( i = 0, linkCurrent = &linkTable[0] ; 00650 i < linkNum ; 00651 i++, linkCurrent++ ) 00652 { 00653 if (strcmp(linkCurrent->szName, linkOldest->szName) < 0) 00654 { 00655 linkOldest = linkCurrent; 00656 } 00657 } 00658 } 00659 }// while 00660 00661 closedir(dirp); 00662 } 00663 }
gboolean hsRemoveLocation | ( | st_ContentType_e | contentType | ) |
Remove the item location information from the history data (RAM)
contentType |
Definition at line 299 of file history.c.
00300 { 00301 gboolean returnValue = FALSE; 00302 00303 if (stackIsArchive(contentType)) 00304 { 00305 if (g_location[contentType]) 00306 { 00307 g_free(g_location[contentType]); 00308 g_location[contentType] = NULL; 00309 returnValue = TRUE; 00310 } 00311 } 00312 return returnValue; 00313 }
void hsSetActiveViewer | ( | st_ContentType_e | contentType, | |
char * | viewerId | |||
) |
Store the active viewer for the specified contentType and clear viewer ID if used for another contentType.
contentType | ||
viewerId | unique identification of the viewere |
Definition at line 315 of file history.c.
00316 { 00317 int index; 00318 00319 CL_HISTORYPRINTF("contentType %d viewerId %s", contentType, viewerId); 00320 00321 for (index = 0; index < ARCHIVE_TYPE_COUNT; index++) 00322 { 00323 if (g_activeViewer[index] == viewerId) 00324 { 00325 strncpy(g_activeViewer[index], NO_VIEWER_ACTIVE, UAID_MAX_SIZE); 00326 } 00327 } 00328 00329 if (stackIsArchive(contentType)) 00330 { 00331 strncpy(g_activeViewer[contentType], viewerId, UAID_MAX_SIZE); 00332 } 00333 }
gboolean hsSetLocation | ( | st_ContentType_e | contentType, | |
char * | location | |||
) |
Set the item location information in the history data (RAM) Thread safe
contentType | ||
location | current viewer location of the current history item of this contentType |
Definition at line 268 of file history.c.
00269 { 00270 CL_HISTORYPRINTF("type %d - %s", contentType, location); 00271 00272 if (stackIsArchive(contentType)) 00273 { 00274 if (g_location[contentType]) 00275 { 00276 g_free(g_location[contentType]); 00277 g_location[contentType] = NULL; 00278 } 00279 00280 g_location[contentType] = g_strdup(location); 00281 } 00282 00283 return TRUE; 00284 }
void hsStoreItem | ( | st_ContentType_e | contentType, | |
clDisplayItem_t * | item | |||
) |
Store (copy) the content of the item in the history of the specified content type
contentType | ||
item | - details of the currently "open item" |
Definition at line 234 of file history.c.
00235 { 00236 CL_HISTORYPRINTF("contentType %d item 0x%x", contentType, (unsigned int) item); 00237 00238 if ((item) && (stackIsArchive(contentType))) 00239 { 00240 memcpy(g_history[contentType], item, sizeof(clDisplayItem_t)); 00241 } 00242 00243 if (item) 00244 { 00245 if ( item->fit == mdsFitFile 00246 && strcasecmp(item->szFileExt, "png") == 0 ) 00247 { 00248 // Notes template: do not add to recent documents 00249 CL_WARNPRINTF("Notes template: file [%s] not added to recent documents", item->szFilename); 00250 } 00251 else 00252 { 00253 hsAddRecent(item); 00254 } 00255 } 00256 }