scribble/inc/FileManager.h File Reference

#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <assert.h>
#include "ink.h"
#include <libermanifest/ermanifest.h>

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _ScribPage
struct  _Manifest
struct  _FileManager

Defines

#define MAX_PATHNAME   512
#define MAX_FILENAME   512
#define MAX_INKTYPE_LEN   10
#define SCRIB_TYPE   "irx"

Typedefs

typedef struct _ScribPage ScribPage
typedef ScribPagePScribPage
typedef struct _Manifest Manifest
typedef struct _FileManager FileManager
typedef FileManagerPFileManager

Functions

int createDirHirachy (PFileManager pFM)
int initFileManagerByTmpl (PFileManager pFM, const char *sTmplPathName)
int initFileManagerByManifest (PFileManager pFM, const char *sManifest)
PScribPage getCurrScribPage (PFileManager pFM)
void freeScribPage (PScribPage pPage)
const char * getCurrImgFileName (PFileManager pFM)
PScribPage jumptoScribPage (PFileManager pFM, int iPageNo)
int loadManifest (PFileManager pFM)
int insertNewPage (PFileManager pFM, int iPageNo, const char *sImgName)
int deleteCurrPage (PFileManager pFM)
int getTotalPage (PFileManager pFM)
int getCurrPageNo (PFileManager pFM)
int fm_saveFileManager (PFileManager pFM)
void FreeFileManager (PFileManager pFM)
char * getAbsPathFromCurrScrib (char *sAbsFileName, int iSize, const char *currFileName, const PFileManager pFM)
int get_ink_filename (char *inkFileName, int iSize, const PFileManager pFM)
int get_result_filename (char *resultFileName, int iSize, const PFileManager pFM, const PScribPage pScribPage)
int get_curr_result_filename (char *resultFileName, int iSize, const PFileManager pFM)
void fm_setIrxInkDirty (PFileManager pFM, gboolean bDirty)
PtrInk fm_loadCurrInk (PFileManager pFM)
int fm_initIrxHandle (PFileManager pFM, gboolean isOpen)
int fm_deleteOnePage (PFileManager pFM, PScribPage pPage)
int fm_saveOnePage (PFileManager pFM, PScribPage pPage)
int fm_saveCurrPage (PFileManager pFM)
int fm_saveAllPages (PFileManager pFM)
int fm_saveIrexInk (PFileManager pFM, gboolean bClose)
int fm_setIrxTypeAndSave (PFileManager pFM)
int fc_convertold2irx (PFileManager pFM)
void dumpManifest (Manifest *pM)
void dumpFileManager (PFileManager pFM)
void dumpIrxXml (const char *sPageName, erManifest *pXmlHandle, int i)


Define Documentation

#define MAX_FILENAME   512

Definition at line 44 of file FileManager.h.

#define MAX_INKTYPE_LEN   10

Definition at line 60 of file FileManager.h.

#define MAX_PATHNAME   512

Copyright (C) 2005-2008 iRex Technologies B.V. All rights reserved.

Definition at line 43 of file FileManager.h.

#define SCRIB_TYPE   "irx"

Definition at line 62 of file FileManager.h.


Typedef Documentation

typedef struct _FileManager FileManager

typedef struct _Manifest Manifest

Definition at line 114 of file FileManager.h.

Definition at line 78 of file FileManager.h.

typedef struct _ScribPage ScribPage


Function Documentation

int createDirHirachy ( PFileManager  pFM  ) 

Definition at line 54 of file FileManager.c.

00055 {    
00056     //if dir not exist, creat dirstruct
00057     const char* sDataDir=pFM->sDataDir;
00058     if( pFM->bNeedCreatDirHirachy && !FileExist(sDataDir) )
00059     {
00060         SB_FMPRINTF("create for\n%s\n",sDataDir);
00061         if( 0!=CreateDir(sDataDir))
00062         {
00063             SB_ERRORPRINTF("create directory [%s]fail\n",sDataDir);
00064             return -1;
00065         }
00066         SB_FMPRINTF("create directory [%s] ok\n",sDataDir);
00067         char sResultDir[MAX_PATHNAME+1];           
00068             //crearete ./result directory
00069         get_result_dirname(sResultDir,sizeof(sResultDir),sDataDir);
00070         if( 0!=CreateDir(sResultDir))
00071         {
00072             SB_ERRORPRINTF("create directory [%s]fail\n",sResultDir);
00073             return -1;
00074         }
00075         SB_FMPRINTF("create directory [%s] ok\n",sResultDir);
00076                  
00077         //now we can init the handle to .irx inkfile.
00078         if( 0!=fm_initIrxHandle(pFM,FALSE) )
00079         {
00080             SB_ERRORPRINTF("create .irx inkfile error\n");
00081             return -1;
00082         }
00083         pFM->bNeedCreatDirHirachy=FALSE; 
00084         SB_FMPRINTF("done\n");         
00085     }  
00086 
00087     return 0;
00088 }

Here is the call graph for this function:

int deleteCurrPage ( PFileManager  pFM  ) 

Definition at line 367 of file FileMgr_page.c.

00368 {
00369     return deletePage( pFM,getCurrPageNo(pFM) );
00370 }

Here is the call graph for this function:

void dumpFileManager ( PFileManager  pFM  ) 

Definition at line 91 of file FileManager.c.

00092 {
00093 
00094     SB_FMPRINTF("\n==========================================\n"
00095             "sTmplPathName=[%s]\n"
00096             "sManifestPathName=[%s]\n"
00097             "sDataDir=[%s]\n"
00098             "sScribbleName=[%s]\n"
00099             "========================================\n",
00100             pFM->sTmplPathName,
00101             pFM->sManifestPathName,
00102             pFM->sDataDir, 
00103             pFM->manifest.sScribbleName);
00104 }

void dumpIrxXml ( const char *  sPageName,
erManifest pXmlHandle,
int  i 
)

Definition at line 370 of file FileMgr_xml.c.

00371 {
00372     char sFileName[512];
00373     snprintf(sFileName,512,"/dump_%d.xml",i);
00374     FILE* file=fopen(sFileName,"w+");
00375     if(file==NULL)
00376     {
00377         printf(" error when open %s\n",sFileName);
00378         return;
00379     }
00380     xmlDocDump(file,pXmlHandle->pDoc);
00381     fclose(file);
00382 }

void dumpManifest ( Manifest pM  ) 

Definition at line 298 of file FileManager.c.

00299 {
00300     printf("\n=================================\n"
00301             "sScribbleName=[%s]\n"
00302             "iLastOpenPage=[%d]\n"
00303             "iTotalPages=[%d]\n",
00304             pM->sScribbleName,pM->iLastOpenPage,pM->iTotalPages);
00305     PScribPage  pPage=pM->pFirstScribPage;;
00306     while(pPage)
00307     {
00308         printf("----------------------------------\n");
00309         printf("sImgFileName=[%s]\nsPageName=[%s]\n",  
00310                pPage->sImgFileName,pPage->sPageName);
00311         printf("sImgFileName=[%s]\nsPageName=[%s]\nbDirty=%d\n",  
00312                pPage->sImgFileName,pPage->sPageName,pPage->bDirty);
00313                 
00314         pPage=pPage->pNextPage;
00315     }
00316     printf("=================================\n");
00317 }

int fc_convertold2irx ( PFileManager  pFM  ) 

Definition at line 71 of file FormatConverter.c.

00072 {
00073     //currently, we can only(also need only) convert notes
00074     if( 0!=strcasecmp(pFM->manifest.sInkType,"notes") )
00075     {
00076         SB_ERRORPRINTF("error:unknow ink type!\n");
00077         return -1;
00078     }
00079     //load everypage and fill in Manifest
00080     PScribPage pCurrPage=pFM->manifest.pFirstScribPage;
00081     char sInkFileName[MAX_FILENAME];
00082     
00083     while(pCurrPage)
00084     {
00085         fc_get_ink_filename(sInkFileName,MAX_FILENAME,pFM,pCurrPage);
00086         pCurrPage->pink=file_read_ink(sInkFileName);
00087         if( pCurrPage->pink== NULL)
00088         {
00089             SB_FMPRINTF("-- null in page \n%s\n",pCurrPage->sPageName);
00090         }else
00091         {
00092             SB_FMPRINTF("--load strokes=%d\nin [%s]",pCurrPage->pink->nStrokes,pCurrPage->sPageName);
00093         }
00094         pCurrPage=pCurrPage->pNextPage;
00095     }
00096     SB_FMPRINTF("-- saving the old ink folder");
00097     //save the ink
00098     int iRet=fm_saveAllPages(pFM);
00099     if( 0!= iRet)
00100     {
00101         SB_FMPRINTF("-- save pages error\n");
00102         return -1;
00103     }
00104 
00105     //when success,deleted the whole ink directory.
00106     char sInkDir[MAX_PATHNAME];
00107     fc_get_ink_dirname(sInkDir,sizeof(sInkDir),pFM->sDataDir);
00108     SB_FMPRINTF("-- deleting folder [%s]", sInkDir);
00109     char* cmd = g_strdup_printf("rm -rf \"%s\"", sInkDir);
00110     system(cmd);
00111     g_free(cmd);
00112     return 0;
00113 
00114 }

Here is the call graph for this function:

int fm_deleteOnePage ( PFileManager  pFM,
PScribPage  pPage 
)

Definition at line 356 of file FileMgr_xml.c.

00357 {
00358     //loop save every pages.
00359     SB_FMPRINTF("-- delete page=%s",pCurrPage->sPageName);
00360     //ignore currently.if(pCurrScribPage->bDirty)
00361     xml_write_ink(pFM->irxHandle,"/notes/pages",
00362                    NULL,pCurrPage->sPageName);
00363     fm_setIrxInkDirty(pFM,TRUE);
00364     
00365     setCurrentPageDirty(pFM,FALSE);
00366     SB_TIMEDISPLAY("--done--");
00367     return 0; 
00368 }

Here is the call graph for this function:

int fm_initIrxHandle ( PFileManager  pFM,
gboolean  isOpen 
)

Definition at line 321 of file FileMgr_xml.c.

00322 {
00323     char inkFileName[MAX_FILENAME];
00324     get_ink_filename (inkFileName, MAX_FILENAME,pFM);
00325     if( NULL==pFM->irxHandle)
00326     {
00327         pFM->irxHandle=(erManifest*)malloc(sizeof(erManifest));
00328     }
00329     gboolean bNeedCreate=TRUE ;
00330     if( isOpen )
00331     {
00332         if( FileExist(inkFileName) )
00333         {
00334             if( RET_OK!=ermXmlOpenFile(inkFileName, pFM->irxHandle) )
00335             {
00336                 SB_ERRORPRINTF("open xml [%s] fail\n",inkFileName);
00337                 return -1;
00338             }
00339             bNeedCreate=FALSE;
00340         }
00341     }
00342     if(bNeedCreate)
00343     {
00344         if( RET_OK!=ermXmlCreateFile(inkFileName,pFM->irxHandle) )
00345         {
00346             SB_ERRORPRINTF("create xml [%s] fail\n",inkFileName);
00347             return -1;
00348         }
00349         xml_write_irxHead(pFM->irxHandle);
00350     }
00351     SB_FMPRINTF("init [%s] successfully[open?=%d]\n",inkFileName,isOpen);
00352     return 0;
00353 }

Here is the call graph for this function:

PtrInk fm_loadCurrInk ( PFileManager  pFM  ) 

Definition at line 313 of file FileMgr_xml.c.

00314 {
00315     SB_FMPRINTF("entry");
00316     return fm_loadIrexInk(pFM->irxHandle,getCurrScribPage(pFM));
00317 }

Here is the call graph for this function:

int fm_saveAllPages ( PFileManager  pFM  ) 

Definition at line 411 of file FileMgr_xml.c.

00412 {
00413     erManifest irxHandle;
00414     
00415     char inkFileName[MAX_FILENAME];
00416     get_ink_filename (inkFileName, MAX_FILENAME,pFM);
00417     if( RET_OK!=ermXmlCreateFile(inkFileName, &irxHandle) )
00418     {
00419         SB_ERRORPRINTF("open irx xml [%s] fail (for save)\n",inkFileName);
00420         return -1;
00421     }
00422     SB_TIMEDISPLAY("-- write head to \n[%s]",inkFileName);
00423     xml_write_irxHead(&irxHandle);
00424     //loop save every pages.
00425     PScribPage pCurrPage=pFM->manifest.pFirstScribPage;
00426     while(pCurrPage)
00427     {
00428         SB_FMPRINTF("-- write page=%s",pCurrPage->sPageName);
00429         //ignore currently.if(pCurrScribPage->bDirty)
00430         xml_write_ink(&irxHandle,"/notes/pages",
00431                       pCurrPage->pink,pCurrPage->sPageName);
00432         
00433         pCurrPage=pCurrPage->pNextPage;
00434     }
00435     ermXmlSaveAndClose(&irxHandle);
00436     SB_TIMEDISPLAY("write irx inkfile finished");
00437     return 0; 
00438 }

Here is the call graph for this function:

int fm_saveCurrPage ( PFileManager  pFM  ) 

Definition at line 403 of file FileMgr_xml.c.

00404 {
00405     return fm_saveOnePage(pFM,getCurrScribPage(pFM));
00406 }

Here is the call graph for this function:

int fm_saveFileManager ( PFileManager  pFM  ) 

Definition at line 185 of file FileMgr_xml.c.

00186 {
00187     int ret;
00188 
00189     SB_FMPRINTF("\n\nstart save...[curropen=%d,lastopen=%d]\n",
00190                 pFM->iCurrOpenPage,pFM->manifest.iLastOpenPage);
00191     //if the last openpage is changed ,then save.
00192     if(pFM->iCurrOpenPage!=pFM->manifest.iLastOpenPage)
00193     {
00194         pFM->manifest.iLastOpenPage=pFM->iCurrOpenPage;
00195         pFM->bNeedSaveManifest=TRUE;
00196     }
00197     //bNeedCreatDirHirachy is true means nothing in current foder.
00198     if(!pFM->bNeedSaveManifest || pFM->bNeedCreatDirHirachy)
00199     {
00200         SB_FMPRINTF("manifest need no save\n");
00201         return 0;
00202     }
00203     ret = fm_saveManifest( &pFM->manifest,pFM->sManifestPathName,
00204                              pFM->isCreatedFromTmpl);
00205     if ( (0 == ret) && (TRUE == pFM->isCreatedFromTmpl) )
00206     {
00207         pFM->isCreatedFromTmpl = FALSE;
00208     }
00209     return ret;
00210 }

Here is the call graph for this function:

int fm_saveIrexInk ( PFileManager  pFM,
gboolean  bClose 
)

Definition at line 455 of file FileMgr_xml.c.

00456 {
00457     //bNeedCreatDirHirachy is true means nothing in current foder.
00458     if(!pFM->manifest.bNeedSaveIrx || pFM->bNeedCreatDirHirachy)
00459     {
00460         SB_FMPRINTF("need not save .irx inkfile\n");
00461         if (bClose)
00462         {
00463             if( NULL!=pFM->irxHandle )
00464             {
00465                 ermXmlClose(pFM->irxHandle);
00466             }
00467             pFM->irxHandle=NULL;
00468         }
00469         return 0;
00470     }
00471     
00472     if( NULL!=pFM->irxHandle )
00473     {
00474         SB_FMPRINTF("saving irx inkfile...\n");
00475         if (bClose)
00476         {
00477             ermXmlSaveAndClose(pFM->irxHandle);
00478         }
00479         else
00480         {
00481             ermXmlSave(pFM->irxHandle);
00482         }
00483     }
00484 
00485     SB_FMPRINTF("done...\n");
00486     return 0; 
00487 }

Here is the call graph for this function:

int fm_saveOnePage ( PFileManager  pFM,
PScribPage  pPage 
)

Definition at line 385 of file FileMgr_xml.c.

00386 {
00387     if(!pCurrPage->bDirty)
00388         return 0;
00389     
00390     //loop save every pages.
00391     SB_TIMEDISPLAY("-- write page=%s",pCurrPage->sPageName);
00392     //ignore currently.if(pCurrScribPage->bDirty)
00393     xml_write_ink(pFM->irxHandle,"/notes/pages",
00394                        pCurrPage->pink,pCurrPage->sPageName);
00395     fm_setIrxInkDirty(pFM,TRUE);
00396     
00397     setCurrentPageDirty(pFM,FALSE);
00398     SB_TIMEDISPLAY("write irx inkfile finished");
00399     return 0; 
00400 }

Here is the call graph for this function:

void fm_setIrxInkDirty ( PFileManager  pFM,
gboolean  bDirty 
)

Definition at line 384 of file FileMgr_page.c.

00385 {
00386     pFM->manifest.bNeedSaveIrx=bDirty;
00387 }

int fm_setIrxTypeAndSave ( PFileManager  pFM  ) 

Definition at line 164 of file FileMgr_xml.c.

00165 {
00166     erManifest erManifest;
00167     //open the manifest and then reset the value
00168     if( RET_OK!=ermXmlOpenFile(pFM->sManifestPathName, &erManifest))
00169     {
00170             SB_ERRORPRINTF("error when open manifest file\n");
00171             return -1;
00172     }
00173     //change the type to irx     
00174     ermXmlSetString(&erManifest,"/package/metadata/dc-metadata/Type",
00175                     SCRIB_TYPE);
00176     //save the manifest
00177     if( RET_OK!=ermXmlSaveAndClose(&erManifest) )
00178     {
00179         SB_ERRORPRINTF("update manifest error[%s]\n",pFM->sManifestPathName);
00180         return -1;
00181     }
00182     return 0;
00183 }

Here is the call graph for this function:

void FreeFileManager ( PFileManager  pFM  ) 

Definition at line 205 of file FileManager.c.

00206 {
00207     if( NULL==pFM ) return;
00208     
00209     PScribPage pCurrPage=pFM->manifest.pFirstScribPage;
00210     PScribPage pNextPage=NULL;
00211     while(pCurrPage)
00212     {
00213         pNextPage=pCurrPage->pNextPage;
00214         //free scribpage inlcude ink object
00215         freeScribPage(pCurrPage);
00216         pCurrPage=pNextPage;
00217     }
00218     if( NULL!=pFM->irxHandle)
00219     {
00220         free(pFM->irxHandle);
00221         pFM->irxHandle=NULL;
00222     }
00223     memset(pFM,0,sizeof(FileManager));
00224 }

Here is the call graph for this function:

void freeScribPage ( PScribPage  pPage  ) 

Definition at line 291 of file FileMgr_page.c.

00292 {
00293      //free ink object
00294     if(pPage->pink)
00295     {
00296         free(pPage->pink);
00297         pPage->pink=NULL;
00298     }
00299     free(pPage);
00300 }

int get_curr_result_filename ( char *  resultFileName,
int  iSize,
const PFileManager  pFM 
)

Definition at line 291 of file FileManager.c.

00292 {
00293     return get_result_filename(resultFileName,iSize,
00294                                pFM,getCurrScribPage(pFM));
00295 }

Here is the call graph for this function:

int get_ink_filename ( char *  inkFileName,
int  iSize,
const PFileManager  pFM 
)

Definition at line 250 of file FileManager.c.

00252 {
00253     //SB_FMPRINTF("__start__\n");   
00254     memset(inkFileName,0,iSize);
00255     snprintf( inkFileName,iSize-1,
00256               "%s%s.irx",
00257               pFM->sDataDir,
00258               pFM->manifest.sScribbleName);
00259     //SB_FMPRINTF("__end__\ninkFileName=%s\n", inkFileName);
00260     return 0;
00261 }

int get_result_filename ( char *  resultFileName,
int  iSize,
const PFileManager  pFM,
const PScribPage  pScribPage 
)

Definition at line 275 of file FileManager.c.

00277 {
00278     //SB_FMPRINTF("__start__\n");    
00279     if( NULL==pScribPage) return -1;
00280     
00281     memset(resultFileName,0,iSize);
00282     snprintf( resultFileName,iSize-1,
00283               "%sresult/%s.png",
00284               pFM->sDataDir,
00285               pScribPage->sPageName);
00286     //SB_FMPRINTF("__end__\nresultfile=%s\n", resultFileName);
00287     return 0;
00288 }

char* getAbsPathFromCurrScrib ( char *  sAbsFileName,
int  iSize,
const char *  currFileName,
const PFileManager  pFM 
)

Definition at line 228 of file FileManager.c.

00232 {
00233     memset(sAbsFileName,0,iSize);
00234     if( currFileName[0] == '/' ) 
00235     {
00236         strncpy(sAbsFileName,currFileName,iSize-1);
00237     }
00238     else
00239     {    
00240         
00241         snprintf( sAbsFileName,iSize-1,
00242                     "%s%s",
00243                     pFM->sDataDir,
00244                     currFileName);
00245     }
00246     return sAbsFileName;
00247 }

const char* getCurrImgFileName ( PFileManager  pFM  ) 

Definition at line 143 of file FileMgr_page.c.

00144 {
00145     return getCurrScribPage(pFM)->sImgFileName;
00146 }

Here is the call graph for this function:

int getCurrPageNo ( PFileManager  pFM  ) 

Definition at line 379 of file FileMgr_page.c.

00380 {
00381     return pFM->iCurrOpenPage;
00382 }

PScribPage getCurrScribPage ( PFileManager  pFM  ) 

Definition at line 137 of file FileMgr_page.c.

00138 {
00139     return pFM->pCurrPage;
00140 }

int getTotalPage ( PFileManager  pFM  ) 

Definition at line 374 of file FileMgr_page.c.

00375 {
00376     return pFM->manifest.iTotalPages;
00377 }

int initFileManagerByManifest ( PFileManager  pFM,
const char *  sManifest 
)

Definition at line 148 of file FileManager.c.

00149 {
00150     SB_FMPRINTF("init by \n%s\n",sManifestPathName);
00151     memset(pFM,0,sizeof(FileManager));
00152     strncpy(pFM->sManifestPathName,sManifestPathName,
00153             sizeof(pFM->sManifestPathName)-1 );
00154     if( 0!=loadManifest(pFM) )
00155     {
00156         SB_ERRORPRINTF("load manifest[%s] error\n",sManifestPathName);
00157         return -1;
00158     }    
00159 
00160     GetDirFromFullName(pFM->sDataDir,sizeof(pFM->sDataDir),sManifestPathName);   
00161     
00162     pFM->isCreatedFromTmpl=FALSE;
00163     
00164     SB_FMPRINTF("notes type is:[%s]",pFM->manifest.sInkType);
00165     //if type is not irex(current type), we need conversion it to new format
00166     if( 0!=strcasecmp(pFM->manifest.sInkType,SCRIB_TYPE) )
00167     {
00168         SB_FMPRINTF("init by \n%s\n",sManifestPathName);
00169         if( 0!=fc_convertold2irx(pFM) )
00170         {
00171             SB_ERRORPRINTF("converting error\n");
00172             return -1;
00173         }
00174         pFM->bNeedSaveManifest=TRUE;
00175         SB_FMPRINTF("update manifest...");
00176         strncpy(pFM->manifest.sInkType,SCRIB_TYPE,sizeof(pFM->manifest.sInkType));
00177         //change the type to irx and save the manifest
00178         if( 0!=fm_setIrxTypeAndSave(pFM) )
00179         {
00180             SB_ERRORPRINTF("save type error[%s]\n",pFM->sManifestPathName);
00181             return -1;
00182         }
00183     } 
00184        
00185     if( 0!=fm_initIrxHandle(pFM,TRUE) )
00186     {
00187             SB_ERRORPRINTF("open .irx inkfile error\n");
00188             return -1;
00189     }
00190     
00191     pFM->bNeedSaveManifest=FALSE;
00192        
00193     PScribPage pScribPage=jumptoScribPage(pFM,pFM->manifest.iLastOpenPage);
00194     if( NULL==pScribPage ) //no page
00195         return -1;
00196     //get template from CurrentPage
00197     strcpy(pFM->sTmplPathName,pScribPage->sImgFileName);    
00198     
00199     pFM->bNeedCreatDirHirachy=FALSE;
00200     
00201     dumpFileManager(pFM);
00202     return 0;
00203 }

Here is the call graph for this function:

int initFileManagerByTmpl ( PFileManager  pFM,
const char *  sTmplPathName 
)

Definition at line 107 of file FileManager.c.

00108 {    
00109     SB_FMPRINTF("init by %s\n",sTmplPathName);
00110     int iLenOfSuffix=strlen(".bmp");
00111     if( NULL==sTmplPathName || strlen(sTmplPathName)<=iLenOfSuffix )
00112         return -1;
00113     
00114     memset(pFM,0,sizeof(FileManager));
00115     
00116     strncpy(pFM->sTmplPathName,sTmplPathName,
00117             sizeof(pFM->sTmplPathName)-1);
00118     
00119     GetDirFromFullName(pFM->sDataDir,sizeof(pFM->sDataDir),sTmplPathName);
00120 
00121     if( 0!=getUniqNameForSCRIB(pFM) )
00122     {
00123         return -1;
00124     }
00125     //DataDir should just above of manifest
00126     strcat(pFM->sDataDir,pFM->manifest.sScribbleName);
00127     strcat(pFM->sDataDir,"/");
00128        
00129     //constract manifest       
00130     strcpy(pFM->sManifestPathName,pFM->sDataDir);
00131     strcat(pFM->sManifestPathName,MANIFEST_FILENAME);
00132     
00133     dumpFileManager(pFM);
00134     //init manifest.
00135     pFM->manifest.iLastOpenPage=0;//numbered from 1.
00136     pFM->manifest.iTotalPages=0;       
00137     
00138     pFM->bNeedCreatDirHirachy=TRUE;
00139     pFM->isCreatedFromTmpl=TRUE;
00140     
00141     //construct the first new page.
00142     insertNewPage(pFM,1,NULL);
00143     jumptoScribPage(pFM,1);    
00144     
00145     return 0;
00146 }

Here is the call graph for this function:

int insertNewPage ( PFileManager  pFM,
int  iPageNo,
const char *  sImgName 
)

Definition at line 206 of file FileMgr_page.c.

00207 {
00208     int iTotalPage=getTotalPage(pFM);
00209     SB_FMPRINTF("insert %d.current[total=%d,curropen=%d]\n",
00210                 iPageNo,getTotalPage(pFM),getCurrPageNo(pFM));
00211     if( iPageNo<1 || iPageNo>(1+iTotalPage) )
00212     {
00213         SB_WARNPRINTF("invalid pageno:%d[total=%d,curropen=%d]\n",
00214                     iPageNo,iTotalPage,getCurrPageNo(pFM));
00215         return -1;
00216     }
00217     ScribPage *pScribPage=(ScribPage *)malloc(sizeof(ScribPage));
00218     if(  NULL==pScribPage)
00219     {
00220         SB_ERRORPRINTF("error when malloc space\n");
00221         return -1;
00222     }
00223     memset(pScribPage,0,sizeof(ScribPage));
00224     if( 0!=getNewPageName(pScribPage,&pFM->manifest) )
00225     {
00226         SB_ERRORPRINTF("error when get new page name\n");
00227         free(pScribPage);
00228         return -1;
00229     }
00230     //generate a new ink data structure
00231     pScribPage->pink=construct_ink();
00232     assert(pScribPage->pink);
00233     
00234     const char *sCurrImgName=sImgName;
00235     if( isStrEmpty(sImgName) )
00236     {
00237         sCurrImgName=pFM->sTmplPathName;
00238     }
00239     //currently, the image name is always same as template name
00240     strcpy( pScribPage->sImgFileName,sCurrImgName);
00241     
00242     //get previous scribpage
00243     ScribPage *pPrevScribPage=getScribPage(pFM,iPageNo-1);
00244     if( NULL==pPrevScribPage)
00245     {//it's first page.
00246         pScribPage->pNextPage=pFM->manifest.pFirstScribPage;
00247         pFM->manifest.pFirstScribPage=pScribPage;       
00248     }
00249     else
00250     {
00251         pScribPage->pNextPage=pPrevScribPage->pNextPage;
00252         pPrevScribPage->pNextPage=pScribPage;
00253     }
00254     //reset total page
00255     pFM->manifest.iTotalPages++;
00256     //reset current pageno if necessary
00257     if( iPageNo<=getCurrPageNo(pFM))
00258     {
00259         pFM->iCurrOpenPage++;
00260     }
00261     
00262     pFM->bNeedSaveManifest=TRUE;
00263     SB_FMPRINTF("insert %d done.current[total=%d,curropen=%d]\n",
00264                 iPageNo,getTotalPage(pFM),getCurrPageNo(pFM));
00265     return 0;
00266 }

Here is the call graph for this function:

PScribPage jumptoScribPage ( PFileManager  pFM,
int  iPageNo 
)

Definition at line 182 of file FileMgr_page.c.

00183 {
00184     SB_FMPRINTF("jumpto pageno:%d[total=%d,curropen=%d]\n",
00185                 iPageNo,getTotalPage(pFM),getCurrPageNo(pFM));
00186     //if iPageNo<1, then set to 1, >iTotalpage, set to last.
00187     if( iPageNo<1 ) iPageNo=1;
00188 
00189     if( iPageNo>getTotalPage(pFM) ) iPageNo=getTotalPage(pFM);
00190 
00191     PScribPage pPage=getScribPage(pFM,iPageNo);
00192     //must find, actually.
00193     if( NULL!=pPage )
00194     {
00195         pFM->iCurrOpenPage=iPageNo;
00196         pFM->pCurrPage=pPage;
00197     }
00198     SB_FMPRINTF("jump done.pageno=%d[pPage==NULL?%d]\n",
00199                 iPageNo,NULL==pPage);
00200     return pPage;
00201 }

Here is the call graph for this function:

int loadManifest ( PFileManager  pFM  ) 

Definition at line 213 of file FileMgr_xml.c.

00214 {
00215     erManifest manifest;
00216     if( RET_OK!=ermXmlOpenFile(pFM->sManifestPathName, &manifest) )
00217     {
00218         SB_ERRORPRINTF("open xml [%s] fail\n",pFM->sManifestPathName);
00219         return -1;
00220     }
00221 
00222     Manifest *pManifest=&pFM->manifest;
00223     
00224     ermXmlGetString(&manifest, "/package/metadata/dc-metadata/Type",  
00225                      pFM->manifest.sInkType, MAX_INKTYPE_LEN);    
00226     ermXmlGetString(&manifest, "/package/Scribble/ScribbleName", 
00227                      pManifest->sScribbleName, MAX_FILENAME+1); 
00228     ermXmlGetInt(&manifest, "/package/Scribble/LastOpenPage", 
00229                   &pManifest->iLastOpenPage); 
00230     ermXmlGetInt(&manifest, "/package/Scribble/TotalPages", 
00231                   &pManifest->iTotalPages);  
00232     
00233     ScribPage *pLastPage=NULL;
00234     ScribPage *pScribPage=NULL;
00235     int i = 0;
00236     char xpathname[256] ={0};        
00237     //fetch every page
00238     for( i=0;i<pManifest->iTotalPages;i++ )
00239     {
00240         pScribPage=(ScribPage *)malloc(sizeof(ScribPage));
00241         if(  NULL==pScribPage)
00242         {
00243             SB_ERRORPRINTF("error when malloc space\n");
00244             return -1;
00245         }
00246         memset(pScribPage,0,sizeof(ScribPage));
00247         snprintf(xpathname, 256, 
00248                  "/package/Scribble/ScribPages/Page[%d]/ImgFileName",i+1);
00249         if(    RET_OK != ermXmlGetString(&manifest,xpathname, 
00250                pScribPage->sImgFileName,MAX_FILENAME+1)
00251                || isStrEmpty(pScribPage->sImgFileName) )
00252         {
00253             free(pScribPage);
00254             break;
00255         }
00256         
00257         snprintf(xpathname, 256, 
00258                  "/package/Scribble/ScribPages/Page[%d]/PageName",i+1);
00259         if(    RET_OK != ermXmlGetString(&manifest,xpathname, 
00260                pScribPage->sPageName,MAX_FILENAME+1)
00261                || isStrEmpty(pScribPage->sPageName) )
00262         {
00263             free(pScribPage);
00264             break;
00265         }
00266         if( 0==i )
00267         {   //first page
00268             pManifest->pFirstScribPage=pScribPage;
00269         }
00270         else
00271         {
00272             pLastPage->pNextPage=pScribPage;
00273         }
00274         pScribPage->bDirty=FALSE;
00275         pLastPage=pScribPage;
00276     }//end for loop
00277     //correct it if error totalpages    
00278        
00279     if( pManifest->iTotalPages != i  )
00280     {
00281         SB_WARNPRINTF("real pages=%d[in xml:%d]\n",i,pManifest->iTotalPages);
00282         pManifest->iTotalPages=i;
00283     }
00284     ermXmlClose(&manifest);
00285     
00286     if( 0==pManifest->iTotalPages  )
00287     {
00288         SB_ERRORPRINTF("no valid page!\n");
00289         return -1;
00290     }
00291     SB_FMPRINTF("manifest loaded success\n");
00292     //dumpManifest(pManifest);
00293     return 0;
00294 }

Here is the call graph for this function:


Generated on Sun Dec 14 17:14:24 2008 by  doxygen 1.5.6