#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <gtk/gtk.h>
#include <liberregxml/erregapi.h>
#include "setupLog.h"
#include "iLiadArcLocData.h"
#include "settings.h"
Go to the source code of this file.
Copyright (C) 2005-2008 iRex Technologies B.V. All rights reserved.
Providing archive location data.
Definition in file iLiadArcLocData.c.
| static arcLocData_t * arcLocDataDup | ( | const arcLocData_t * | settings | ) | [static] |
Definition at line 415 of file iLiadArcLocData.c.
00416 { 00417 ST_LOGPRINTF("entry"); 00418 00419 arcLocData_t *dup = NULL; 00420 00421 if (settings) 00422 { 00423 dup = g_new0(arcLocData_t, 1); 00424 if (dup) 00425 { 00426 dup->newsLoc = settings->newsLoc; 00427 dup->booksLoc = settings->booksLoc; 00428 dup->docsLoc = settings->docsLoc; 00429 dup->notesLoc = settings->notesLoc; 00430 } 00431 } 00432 return dup; 00433 }
| static void arcLocDataToArcPath | ( | arcLocData_t * | arcLocData, | |
| arcPath_t * | arcPaths | |||
| ) | [static] |
Definition at line 646 of file iLiadArcLocData.c.
00647 { 00648 ST_LOGPRINTF("entry %p, %p", arcLocData, arcPaths); 00649 00650 if (arcLocData && arcPaths) 00651 { 00652 mediaPath_t *mediaPaths = g_media_paths; 00653 arcPath_t* archivePaths = g_arc_paths; 00654 00655 if (mediaPaths && archivePaths) 00656 { 00657 // arcPaths->newsPath 00658 g_free(arcPaths->newsPath); 00659 arcPaths->newsPath= NULL; 00660 arcPaths->newsPath = data2path(arcNews, arcLocData->newsLoc, mediaPaths, archivePaths); 00661 00662 // arcPaths->booksPath 00663 g_free(arcPaths->booksPath); 00664 arcPaths->booksPath= NULL; 00665 arcPaths->booksPath = data2path(arcBooks, arcLocData->booksLoc, mediaPaths, archivePaths); 00666 00667 // arcPaths->docsPath 00668 g_free(arcPaths->docsPath); 00669 arcPaths->docsPath= NULL; 00670 arcPaths->docsPath = data2path(arcDocs, arcLocData->docsLoc, mediaPaths, archivePaths); 00671 00672 // arcPaths->notesPath 00673 g_free(arcPaths->notesPath); 00674 arcPaths->notesPath= NULL; 00675 arcPaths->notesPath = data2path(arcNotes, arcLocData->notesLoc, mediaPaths, archivePaths); 00676 } 00677 } 00678 }

| static void arcPathToArcLocData | ( | arcPath_t * | arcPaths, | |
| arcLocData_t * | arcLocData | |||
| ) | [static] |
Definition at line 615 of file iLiadArcLocData.c.
00616 { 00617 ST_LOGPRINTF("entry"); 00618 00619 if (arcPaths && arcLocData) 00620 { 00621 // set the default values 00622 arcLocData->newsLoc = arcLocMain; 00623 arcLocData->booksLoc = arcLocMain; 00624 arcLocData->docsLoc = arcLocMain; 00625 arcLocData->notesLoc = arcLocMain; 00626 00627 mediaPath_t *mediaPaths = g_media_paths; 00628 if (mediaPaths) 00629 { 00630 // arcLocData->newsLoc 00631 path2data(arcPaths->newsPath, &(arcLocData->newsLoc), mediaPaths); 00632 00633 // arcLocData->booksLoc 00634 path2data(arcPaths->booksPath, &(arcLocData->booksLoc), mediaPaths); 00635 00636 // arcLocData->docsLoc 00637 path2data(arcPaths->docsPath, &(arcLocData->docsLoc), mediaPaths); 00638 00639 // arcLocData->notesLoc 00640 path2data(arcPaths->notesPath, &(arcLocData->notesLoc), mediaPaths); 00641 } 00642 } 00643 }

| static char * data2path | ( | const arcType_e | arc, | |
| const arcLocType_e | data, | |||
| mediaPath_t * | mediaPaths, | |||
| arcPath_t * | arcPaths | |||
| ) | [static] |
Definition at line 707 of file iLiadArcLocData.c.
00709 { 00710 char* path = NULL; 00711 00712 if (mediaPaths && arcPaths) 00713 { 00714 char* subdir = NULL; 00715 switch (arc) 00716 { 00717 case arcNews: 00718 subdir = strrchr(arcPaths->newsPath, '/'); 00719 break; 00720 case arcBooks: 00721 subdir = strrchr(arcPaths->booksPath, '/'); 00722 break; 00723 case arcDocs: 00724 subdir = strrchr(arcPaths->docsPath, '/'); 00725 break; 00726 case arcNotes: 00727 subdir = strrchr(arcPaths->notesPath, '/'); 00728 break; 00729 default: 00730 break; 00731 } 00732 00733 if (mediaPaths->mainPath && (data == arcLocMain)) 00734 { 00735 path = g_strdup_printf("%s%s", mediaPaths->mainPath, subdir); 00736 } 00737 else if (mediaPaths->cardPath && (data == arcLocCard)) 00738 { 00739 path = g_strdup_printf("%s%s", mediaPaths->cardPath, subdir); 00740 } 00741 else if (mediaPaths->cfPath && (data == arcLocCF)) 00742 { 00743 path = g_strdup_printf("%s%s", mediaPaths->cfPath, subdir); 00744 } 00745 else if (mediaPaths->usbPath && (data == arcLocUSB)) 00746 { 00747 path = g_strdup_printf("%s%s", mediaPaths->usbPath, subdir); 00748 } 00749 else 00750 { 00751 path = g_strdup_printf("%s%s", mediaPaths->mainPath, subdir); 00752 } 00753 } 00754 00755 return path; 00756 }
| static regExportMemType_t * export_settings_dup | ( | regExportMemType_t * | theExportMemType | ) | [static] |
Definition at line 398 of file iLiadArcLocData.c.
00399 { 00400 ST_LOGPRINTF("entry"); 00401 00402 regExportMemType_t *dup = NULL; 00403 00404 if (theExportMemType) 00405 { 00406 dup = g_new0(regExportMemType_t, 1); 00407 g_assert(NULL != dup); 00408 00409 dup->location = g_strdup(theExportMemType->location); 00410 } 00411 00412 return dup; 00413 }
| static void freeArcPaths | ( | arcPath_t * | arcPaths | ) | [static] |
Definition at line 587 of file iLiadArcLocData.c.
00588 { 00589 ST_LOGPRINTF("entry"); 00590 00591 if (arcPaths) 00592 { 00593 if (arcPaths->newsPath) 00594 { 00595 g_free(arcPaths->newsPath); 00596 } 00597 if (arcPaths->booksPath) 00598 { 00599 g_free(arcPaths->booksPath); 00600 } 00601 if (arcPaths->docsPath) 00602 { 00603 g_free(arcPaths->docsPath); 00604 } 00605 if (arcPaths->notesPath) 00606 { 00607 g_free(arcPaths->notesPath); 00608 } 00609 g_free(arcPaths); 00610 arcPaths = NULL; 00611 } 00612 }
| static void freeMediaPaths | ( | mediaPath_t * | mediaPaths | ) | [static] |
Definition at line 498 of file iLiadArcLocData.c.
00499 { 00500 ST_LOGPRINTF("entry"); 00501 00502 if (mediaPaths) 00503 { 00504 if (mediaPaths->mainPath) 00505 { 00506 g_free(mediaPaths->mainPath); 00507 } 00508 if (mediaPaths->cfPath) 00509 { 00510 g_free(mediaPaths->cfPath); 00511 } 00512 if (mediaPaths->cardPath) 00513 { 00514 g_free(mediaPaths->cardPath); 00515 } 00516 if (mediaPaths->usbPath) 00517 { 00518 g_free(mediaPaths->usbPath); 00519 } 00520 g_free(mediaPaths); 00521 } 00522 }
| static arcPath_t * getArcPaths | ( | void | ) | [static] |
Definition at line 524 of file iLiadArcLocData.c.
00525 { 00526 ST_LOGPRINTF("entry"); 00527 00528 arcPath_t *arc = NULL; 00529 00530 arc = g_new0(arcPath_t, 1); 00531 if (arc) 00532 { 00533 regContentCategory_t *category = NULL; 00534 00535 // get the path of the archive arc of newspaper 00536 category = erRegGetContentCategory(NEWSPAPERS_CATEGORY); 00537 if (category && category->location) 00538 { 00539 arc->newsPath = g_strdup(category->location); 00540 erRegFreeContentCategory(category); 00541 } 00542 else 00543 { 00544 ST_ERRORPRINTF("error occurred when reading NEWSPAPERS_CATEGORY from registry"); 00545 } 00546 // get the path of the archive arc of books 00547 category = erRegGetContentCategory(BOOKS_CATEGORY); 00548 if (category && category->location) 00549 { 00550 arc->booksPath = g_strdup(category->location); 00551 erRegFreeContentCategory(category); 00552 } 00553 else 00554 { 00555 ST_ERRORPRINTF("error occurred when reading BOOKS_CATEGORY from registry"); 00556 } 00557 // get the path of the archive arc of documents 00558 category = erRegGetContentCategory(DOCUMENTS_CATEGORY); 00559 if (category && category->location) 00560 { 00561 arc->docsPath = g_strdup(category->location); 00562 erRegFreeContentCategory(category); 00563 } 00564 else 00565 { 00566 ST_ERRORPRINTF("error occurred when reading DOCUMENTS_CATEGORY from registry"); 00567 } 00568 // get the path of the archive arc of notes 00569 category = erRegGetContentCategory(NOTES_CATEGORY); 00570 if (category && category->location) 00571 { 00572 arc->notesPath = g_strdup(category->location); 00573 erRegFreeContentCategory(category); 00574 } 00575 else 00576 { 00577 ST_ERRORPRINTF("error occurred when reading NOTES_CATEGORY from registry"); 00578 } 00579 } 00580 else 00581 { 00582 ST_ERRORPRINTF("memory allocation error"); 00583 } 00584 return arc; 00585 }

| static mediaPath_t * getMediaPaths | ( | void | ) | [static] |
Definition at line 435 of file iLiadArcLocData.c.
00436 { 00437 ST_LOGPRINTF("entry"); 00438 00439 mediaPath_t *media = NULL; 00440 00441 media = g_new0(mediaPath_t, 1); 00442 if (media) 00443 { 00444 regContentCategory_t *category = NULL; 00445 // get main memory path 00446 category = erRegGetContentCategory(MAIN_CATEGORY); 00447 if (category && category->location) 00448 { 00449 media->mainPath = g_strdup(category->location); 00450 erRegFreeContentCategory(category); 00451 } 00452 else 00453 { 00454 ST_ERRORPRINTF("error occurred when reading MAIN_CATEGORY from registry"); 00455 } 00456 // get sd/mmc path 00457 category = erRegGetContentCategory(SD_CATEGORY); 00458 if (category && category->location) 00459 { 00460 media->cardPath = g_strdup(category->location); 00461 erRegFreeContentCategory(category); 00462 } 00463 else 00464 { 00465 ST_ERRORPRINTF("error occurred when reading SD_CATEGORY from registry"); 00466 } 00467 // get usb path 00468 category = erRegGetContentCategory(USB_CATEGORY); 00469 if (category && category->location) 00470 { 00471 media->usbPath = g_strdup(category->location); 00472 erRegFreeContentCategory(category); 00473 } 00474 else 00475 { 00476 ST_ERRORPRINTF("error occurred when reading USB_CATEGORY from registry"); 00477 } 00478 // get cf path 00479 category = erRegGetContentCategory(CF_CATEGORY); 00480 if (category && category->location) 00481 { 00482 media->cfPath = g_strdup(category->location); 00483 erRegFreeContentCategory(category); 00484 } 00485 else 00486 { 00487 ST_ERRORPRINTF("error occurred when reading CF_CATEGORY from registry"); 00488 } 00489 } 00490 else 00491 { 00492 ST_ERRORPRINTF("memory allocation error"); 00493 } 00494 00495 return media; 00496 }

| void iLiad_archive_location_data_destroy | ( | void | ) |
Definition at line 102 of file iLiadArcLocData.c.
00103 { 00104 ST_LOGPRINTF("entry"); 00105 00106 if (g_cur_settings) 00107 { 00108 g_free(g_cur_settings); 00109 g_cur_settings = NULL; 00110 } 00111 00112 if (g_stored_settings) 00113 { 00114 g_free(g_stored_settings); 00115 g_stored_settings = NULL; 00116 } 00117 00118 if (g_arc_paths) 00119 { 00120 freeArcPaths(g_arc_paths); 00121 g_arc_paths = NULL; 00122 } 00123 00124 if (g_media_paths) 00125 { 00126 freeMediaPaths(g_media_paths); 00127 g_media_paths = NULL; 00128 } 00129 00130 if (g_cur_export_settings) 00131 { 00132 erRegFreeExportMemType(g_cur_export_settings); 00133 g_cur_export_settings = NULL; 00134 } 00135 00136 if (g_stored_export_settings) 00137 { 00138 erRegFreeExportMemType(g_stored_export_settings); 00139 g_stored_export_settings = NULL; 00140 } 00141 }

| arcLocType_e iLiad_archive_location_data_get | ( | arcType_e | arc | ) |
Definition at line 335 of file iLiadArcLocData.c.
00336 { 00337 ST_LOGPRINTF("arc=%d", arc); 00338 00339 arcLocType_e location = arcLocMain; 00340 00341 if (g_cur_settings) 00342 { 00343 switch (arc) 00344 { 00345 case arcNews: 00346 location = g_cur_settings->newsLoc; 00347 break; 00348 case arcBooks: 00349 location = g_cur_settings->booksLoc; 00350 break; 00351 case arcDocs: 00352 location = g_cur_settings->docsLoc; 00353 break; 00354 case arcNotes: 00355 location = g_cur_settings->notesLoc; 00356 break; 00357 default: 00358 ST_ERRORPRINTF("error:arc=%d", arc); 00359 } 00360 } 00361 else 00362 { 00363 ST_WARNPRINTF("g_cur_settings == NULL"); 00364 } 00365 00366 return location; 00367 }
| void iLiad_archive_location_data_init | ( | void | ) |
Definition at line 69 of file iLiadArcLocData.c.
00070 { 00071 ST_LOGPRINTF("entry"); 00072 00073 iLiad_archive_location_data_destroy(); 00074 00075 g_cur_settings = g_new0(arcLocData_t, 1); 00076 if (g_cur_settings != NULL) 00077 { 00078 g_arc_paths = getArcPaths(); 00079 g_media_paths = getMediaPaths(); 00080 00081 arcPathToArcLocData(g_arc_paths, g_cur_settings); 00082 g_stored_settings = arcLocDataDup(g_cur_settings); 00083 } 00084 else 00085 { 00086 ST_ERRORPRINTF("memory allocation error"); 00087 } 00088 00089 g_cur_export_settings = erRegGetExportMemType(); 00090 if (g_cur_export_settings == NULL) 00091 { 00092 g_cur_export_settings = g_new0(regExportMemType_t, 1); 00093 g_assert(NULL != g_cur_export_settings); 00094 00095 // Use internal memory as default 00096 g_cur_export_settings->location = g_strdup(MAIN_CATEGORY); 00097 } 00098 00099 g_stored_export_settings = export_settings_dup(g_cur_export_settings); 00100 }

| void iLiad_archive_location_data_set | ( | arcType_e | arc, | |
| arcLocType_e | location | |||
| ) |
Definition at line 304 of file iLiadArcLocData.c.
00305 { 00306 ST_LOGPRINTF("arc=%d, location=%d", arc, location); 00307 00308 g_return_if_fail(g_cur_settings != NULL); 00309 00310 if ((location < arcLocMain) || (location >= arcLocUndefined)) 00311 { 00312 ST_WARNPRINTF("invalid location value and use the default value(%d)", arcLocMain); 00313 location = arcLocMain; 00314 } 00315 00316 switch (arc) 00317 { 00318 case arcNews: 00319 g_cur_settings->newsLoc = location; 00320 break; 00321 case arcBooks: 00322 g_cur_settings->booksLoc = location; 00323 break; 00324 case arcDocs: 00325 g_cur_settings->docsLoc = location; 00326 break; 00327 case arcNotes: 00328 g_cur_settings->notesLoc = location; 00329 break; 00330 default: 00331 ST_ERRORPRINTF("error:arc=%d", arc); 00332 } 00333 }
| void iLiad_archive_location_data_store | ( | void | ) |
Definition at line 143 of file iLiadArcLocData.c.
00144 { 00145 gboolean bSaveNews=FALSE, bSaveBooks=FALSE, bSaveDocs=FALSE, bSaveNotes=FALSE, bSaveExport=FALSE; 00146 00147 ST_LOGPRINTF("entry"); 00148 00149 g_return_if_fail(NULL != g_cur_settings); 00150 g_return_if_fail(NULL != g_stored_settings); 00151 00152 // need to save changes or not? 00153 if (g_cur_settings->newsLoc != g_stored_settings->newsLoc) 00154 { 00155 bSaveNews = TRUE; 00156 } 00157 00158 if (g_cur_settings->booksLoc != g_stored_settings->booksLoc) 00159 { 00160 bSaveBooks = TRUE; 00161 } 00162 00163 if (g_cur_settings->docsLoc != g_stored_settings->docsLoc) 00164 { 00165 bSaveDocs = TRUE; 00166 } 00167 00168 if (g_cur_settings->notesLoc != g_stored_settings->notesLoc) 00169 { 00170 bSaveNotes = TRUE; 00171 } 00172 00173 if (strcmp(g_cur_export_settings->location, g_stored_export_settings->location) != 0) 00174 { 00175 bSaveExport = TRUE; 00176 } 00177 00178 if (bSaveNews || bSaveBooks || bSaveDocs || bSaveNotes || bSaveExport) 00179 { 00180 ST_LOGPRINTF("entry %d %d %d %d %d", bSaveNews, bSaveBooks, bSaveDocs, bSaveNotes, bSaveExport); 00181 00182 // save changes to registry 00183 prepare_registry_write(); 00184 00185 regContentCategory_t* category = NULL; 00186 arcPath_t* arcPaths= g_new0(arcPath_t, 1); 00187 arcLocDataToArcPath(g_cur_settings, arcPaths); 00188 00189 if (bSaveNews) 00190 { 00191 // save the location of newspapers 00192 category = erRegGetContentCategory(NEWSPAPERS_CATEGORY); 00193 if (category && category->location) 00194 { 00195 g_free(category->location); 00196 category->location = g_strdup(arcPaths->newsPath); 00197 erRegSetContentCategory(NEWSPAPERS_CATEGORY, category); 00198 } 00199 erRegFreeContentCategory(category); 00200 category = NULL; 00201 } 00202 00203 if (bSaveBooks) 00204 { 00205 // save the location of books 00206 category = erRegGetContentCategory(BOOKS_CATEGORY); 00207 if (category && category->location) 00208 { 00209 g_free(category->location); 00210 category->location = g_strdup(arcPaths->booksPath); 00211 erRegSetContentCategory(BOOKS_CATEGORY, category); 00212 } 00213 erRegFreeContentCategory(category); 00214 category = NULL; 00215 } 00216 00217 if (bSaveDocs) 00218 { 00219 // save the location of docs 00220 category = erRegGetContentCategory(DOCUMENTS_CATEGORY); 00221 if (category && category->location) 00222 { 00223 g_free(category->location); 00224 category->location = g_strdup(arcPaths->docsPath); 00225 erRegSetContentCategory(DOCUMENTS_CATEGORY, category); 00226 } 00227 erRegFreeContentCategory(category); 00228 category = NULL; 00229 } 00230 00231 if (bSaveNotes) 00232 { 00233 // save the location of notes 00234 category = erRegGetContentCategory(NOTES_CATEGORY); 00235 if (category && category->location) 00236 { 00237 g_free(category->location); 00238 category->location = g_strdup(arcPaths->notesPath); 00239 erRegSetContentCategory(NOTES_CATEGORY, category); 00240 } 00241 erRegFreeContentCategory(category); 00242 category = NULL; 00243 } 00244 00245 if (bSaveExport) 00246 { 00247 if (!erRegSetExportMemType(g_cur_export_settings)) 00248 { 00249 ST_ERRORPRINTF("Error storing export settings"); 00250 } 00251 else 00252 { 00253 // success 00254 erRegFreeExportMemType(g_stored_export_settings); 00255 g_stored_export_settings = export_settings_dup(g_cur_export_settings); 00256 } 00257 } 00258 00259 // free the memory 00260 freeArcPaths(arcPaths); 00261 arcPaths = NULL; 00262 00263 // also update the g_stored_settings 00264 g_free(g_stored_settings); 00265 g_stored_settings = arcLocDataDup(g_cur_settings); 00266 00267 do_registry_write(); 00268 } 00269 }

| arcLocType_e iLiad_export_location_data_get | ( | ) |
Definition at line 369 of file iLiadArcLocData.c.
00370 { 00371 ST_LOGPRINTF("entry"); 00372 00373 if (strcmp(g_cur_export_settings->location, MAIN_CATEGORY) == 0) 00374 { 00375 return arcLocMain; 00376 } 00377 else if (strcmp(g_cur_export_settings->location, SD_CATEGORY) == 0) 00378 { 00379 return arcLocCard; 00380 } 00381 else if (strcmp(g_cur_export_settings->location, USB_CATEGORY) == 0) 00382 { 00383 return arcLocUSB; 00384 } 00385 else if (strcmp(g_cur_export_settings->location, CF_CATEGORY) == 0) 00386 { 00387 return arcLocCF; 00388 } 00389 else 00390 { 00391 ST_ERRORPRINTF("Invalid location: %s", g_cur_export_settings->location); 00392 00393 // Use internal memory as default 00394 return arcLocMain; 00395 } 00396 }
| void iLiad_export_location_data_set | ( | arcLocType_e | location | ) |
Definition at line 271 of file iLiadArcLocData.c.
00272 { 00273 ST_LOGPRINTF("Set export memory types: location=%d", location); 00274 00275 g_return_if_fail(g_cur_export_settings != NULL); 00276 00277 if ((location < arcLocMain) || (location >= arcLocUndefined)) 00278 { 00279 ST_WARNPRINTF("invalid location value and use the default value(%d)", arcLocMain); 00280 location = arcLocMain; 00281 } 00282 00283 g_free(g_cur_export_settings->location); 00284 switch (location) 00285 { 00286 case arcLocMain: 00287 g_cur_export_settings->location = g_strdup(MAIN_CATEGORY); 00288 break; 00289 case arcLocCard: 00290 g_cur_export_settings->location = g_strdup(SD_CATEGORY); 00291 break; 00292 case arcLocUSB: 00293 g_cur_export_settings->location = g_strdup(USB_CATEGORY); 00294 break; 00295 case arcLocCF: 00296 g_cur_export_settings->location = g_strdup(CF_CATEGORY); 00297 break; 00298 default: 00299 g_assert_not_reached(); 00300 break; 00301 } 00302 }
| static void path2data | ( | const char * | path, | |
| arcLocType_e * | data, | |||
| mediaPath_t * | mediaPaths | |||
| ) | [static] |
Definition at line 680 of file iLiadArcLocData.c.
00681 { 00682 if (path && data && mediaPaths) 00683 { 00684 if (mediaPaths->mainPath && strstr(path, mediaPaths->mainPath)) 00685 { 00686 *data = arcLocMain; 00687 } 00688 else if (mediaPaths->cardPath && strstr(path, mediaPaths->cardPath)) 00689 { 00690 *data = arcLocCard; 00691 } 00692 else if (mediaPaths->cfPath && strstr(path, mediaPaths->cfPath)) 00693 { 00694 *data = arcLocCF; 00695 } 00696 else if (mediaPaths->usbPath && strstr(path, mediaPaths->usbPath)) 00697 { 00698 *data = arcLocUSB; 00699 } 00700 else 00701 { 00702 *data = arcLocMain; 00703 } 00704 } 00705 }
arcPath_t* g_arc_paths = NULL [static] |
Definition at line 51 of file iLiadArcLocData.c.
regExportMemType_t* g_cur_export_settings = NULL [static] |
Definition at line 47 of file iLiadArcLocData.c.
arcLocData_t* g_cur_settings = NULL [static] |
Definition at line 44 of file iLiadArcLocData.c.
mediaPath_t* g_media_paths = NULL [static] |
Definition at line 52 of file iLiadArcLocData.c.
regExportMemType_t* g_stored_export_settings = NULL [static] |
Definition at line 48 of file iLiadArcLocData.c.
arcLocData_t* g_stored_settings = NULL [static] |
Definition at line 45 of file iLiadArcLocData.c.
1.5.6