scribble/src/FileMgr_xml.c File Reference

#include <gtk/gtk.h>
#include <libermanifest/ermanifest.h>
#include "FileManager.h"
#include "FileMgr_page.h"
#include "ScribbleLog.h"
#include "ScribbleUtils.h"
#include "ink_rw.h"

Go to the source code of this file.

Functions

int saveManifestHead (erManifest *pErManiHandle, Manifest *pManifest)
int fm_saveManifest (Manifest *pManifest, const char *sManifestFile, gboolean isCreatedFromTmpl)
int fm_setIrxTypeAndSave (PFileManager pFM)
int fm_saveFileManager (PFileManager pFM)
int loadManifest (PFileManager pFM)
PtrInk fm_loadIrexInk (erManifest *pIrxHandle, const PScribPage pScribPage)
PtrInk fm_loadCurrInk (PFileManager pFM)
int fm_initIrxHandle (PFileManager pFM, gboolean isOpen)
int fm_deleteOnePage (PFileManager pFM, PScribPage pCurrPage)
void dumpIrxXml (const char *sPageName, erManifest *pXmlHandle, int i)
int fm_saveOnePage (PFileManager pFM, PScribPage pCurrPage)
int fm_saveCurrPage (PFileManager pFM)
int fm_saveAllPages (PFileManager pFM)
int fm_loadAllInks (PFileManager pFM)
int fm_saveIrexInk (PFileManager pFM, gboolean bClose)


Function Documentation

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 }

int fm_deleteOnePage ( PFileManager  pFM,
PScribPage  pCurrPage 
)

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:

int fm_loadAllInks ( PFileManager  pFM  ) 

Definition at line 441 of file FileMgr_xml.c.

00442 {
00443     if( NULL==pFM->irxHandle ) return -1;
00444     
00445     PScribPage pCurrPage=pFM->manifest.pFirstScribPage;
00446     while(pCurrPage)
00447     {
00448         fm_loadIrexInk(pFM->irxHandle,pCurrPage);
00449         pCurrPage=pCurrPage->pNextPage;
00450     }
00451     return 0;
00452 }

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:

PtrInk fm_loadIrexInk ( erManifest pIrxHandle,
const PScribPage  pScribPage 
)

Definition at line 296 of file FileMgr_xml.c.

00297 {
00298     //assert(pIrxHandle!=NULL);
00299     if( NULL==pScribPage->pink )
00300     {   
00301         if( NULL==pIrxHandle)
00302         {
00303             pScribPage->pink=construct_ink ();
00304         }
00305         else
00306         {
00307             pScribPage->pink=xml_read_ink(pIrxHandle,pScribPage->sPageName);
00308         }
00309     }
00310     return pScribPage->pink;
00311 }

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_saveManifest ( Manifest pManifest,
const char *  sManifestFile,
gboolean  isCreatedFromTmpl 
)

Definition at line 105 of file FileMgr_xml.c.

00107 {
00108     erManifest erManifest;
00109     if(isCreatedFromTmpl)
00110     {
00111         //create new manifest file
00112         if( RET_OK!=ermXmlCreateFile(sManifestFile, &erManifest))
00113         {
00114             SB_ERRORPRINTF("error when create xml\n");
00115             return -1;
00116         }
00117         SB_FMPRINTF("xml created\n"); 
00118         saveManifestHead(&erManifest,pManifest);   
00119         ermXmlNewString(&erManifest, "/package", "Scribble", "");
00120         SB_FMPRINTF("manifest head created\n");     
00121     }
00122     else
00123     {
00124         //open the manifest and then reset the value
00125         if( RET_OK!=ermXmlOpenFile(sManifestFile, &erManifest))
00126         {
00127             SB_ERRORPRINTF("error when open manifest file\n");
00128             return -1;
00129         }
00130         //empty the existed content
00131         ermXmlSetString(&erManifest,"/package/Scribble","");
00132     }
00133         
00134     ermXmlNewString(&erManifest, "/package/Scribble", "ScribbleName", 
00135                      pManifest->sScribbleName);
00136     ermXmlNewInt(&erManifest, "/package/Scribble", "LastOpenPage", 
00137                   pManifest->iLastOpenPage);
00138     ermXmlNewInt(&erManifest, "/package/Scribble", "TotalPages", 
00139                   pManifest->iTotalPages);        
00140     ermXmlNewString(&erManifest, "/package/Scribble", "ScribPages", "");
00141     
00142     PScribPage  pCurrPage=pManifest->pFirstScribPage;
00143     
00144     int i = 0;
00145     char xpathname[256] ={0};
00146     while(pCurrPage)
00147     {
00148         ermXmlNewString(&erManifest, "/package/Scribble/ScribPages",
00149                          "Page","");
00150         snprintf(xpathname, MAX_PATHNAME, 
00151                  "/package/Scribble/ScribPages/Page[%d]", ++i);
00152         ermXmlNewString(&erManifest, xpathname,
00153                          "ImgFileName",pCurrPage->sImgFileName);
00154         ermXmlNewString(&erManifest, xpathname,
00155                          "PageName",pCurrPage->sPageName);
00156         pCurrPage=pCurrPage->pNextPage;
00157     }
00158     ermXmlSaveAndClose(&erManifest);
00159     SB_FMPRINTF("manifest saved\n");
00160     return 0;
00161 }

Here is the call graph for this function:

int fm_saveOnePage ( PFileManager  pFM,
PScribPage  pCurrPage 
)

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:

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:

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:

int saveManifestHead ( erManifest pErManiHandle,
Manifest pManifest 
)

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

Definition at line 68 of file FileMgr_xml.c.

00069 {
00070     ermXmlNewString(pErManiHandle, "/", "package", "");
00071  
00072     ermXmlNewString(pErManiHandle, "/package", "metadata", "");
00073     ermXmlNewString(pErManiHandle, "/package/metadata","dc-metadata", "");
00074     ermXmlNewString(pErManiHandle, "/package/metadata/dc-metadata", "Title", 
00075                     pManifest->sScribbleName);
00076     ermXmlNewString(pErManiHandle, "/package/metadata/dc-metadata", "Description", 
00077                     pManifest->sScribbleName);
00078     ermXmlNewString(pErManiHandle, "/package/metadata/dc-metadata", "Type", SCRIB_TYPE);
00079         
00080     ermXmlNewString(pErManiHandle, "/package/metadata", "y-metadata", "");
00081     ermXmlNewString(pErManiHandle, "/package/metadata/y-metadata", 
00082                     "startpage", "dummy.bmp");    
00083     return 0;
00084 }

Here is the call graph for this function:


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