#include <gtk/gtk.h>#include <time.h>#include "FileManager.h"#include "ScribbleDefine.h"#include "ScribbleLog.h"#include "ScribbleUtils.h"Go to the source code of this file.
| int deleteCurrPage | ( | PFileManager | pFM | ) |
Definition at line 367 of file FileMgr_page.c.
00368 { 00369 return deletePage( pFM,getCurrPageNo(pFM) ); 00370 }

| int deletePage | ( | PFileManager | pFM, | |
| int | iPageNo | |||
| ) |
Definition at line 304 of file FileMgr_page.c.
00305 { 00306 //dumpManifest(&pFM->manifest); 00307 int iTotalPage=getTotalPage(pFM); 00308 if( !isPageNoValid(pFM,iPageNo) ) 00309 { 00310 SB_ERRORPRINTF("invalid pageno:%d[total=%d,curropen=%d]\n", 00311 iPageNo,iTotalPage,getCurrPageNo(pFM)); 00312 return -1; 00313 } 00314 if( 1==iTotalPage ) 00315 { 00316 SB_WARNPRINTF("only 1 page,resuse to del\n"); 00317 return -1; 00318 } 00319 //get this scribpage 00320 ScribPage *pScribPage=getScribPage(pFM,iPageNo); 00321 if( NULL==pScribPage ) 00322 {//impossible case 00323 SB_ERRORPRINTF("sth error?[tobe del=%d,total=%d,curr=%d]\n", 00324 iPageNo,iTotalPage,getCurrPageNo(pFM)); 00325 return -1; 00326 } 00327 ScribPage *pPrevScribPage=getScribPage(pFM,iPageNo-1); 00328 if( NULL==pPrevScribPage ) 00329 {//first page 00330 pFM->manifest.pFirstScribPage=pScribPage->pNextPage; 00331 } 00332 else 00333 { 00334 pPrevScribPage->pNextPage=pScribPage->pNextPage; 00335 } 00336 //delete the real ink and result file. 00337 deleteRelatedFiles(pFM,pScribPage); 00338 //delete it from .irx 00339 fm_deleteOnePage(pFM,pScribPage); 00340 //free scribpage inlcude ink object 00341 freeScribPage(pScribPage); 00342 pScribPage=NULL; 00343 00344 //reset total page 00345 pFM->manifest.iTotalPages--; 00346 00347 //reset current pageno if necessary 00348 int iCurrPage=getCurrPageNo(pFM); 00349 if( iPageNo<iCurrPage ) 00350 { 00351 pFM->iCurrOpenPage--; 00352 } 00353 if( iPageNo==iCurrPage ) //delete current page,then jump to 1. 00354 { 00355 //we should reset currpage pointer!! 00356 pFM->pCurrPage=pFM->manifest.pFirstScribPage; 00357 jumptoScribPage(pFM,1);//1 cannot be del,so it bounce to refresh. 00358 } 00359 pFM->bNeedSaveManifest=TRUE; 00360 //dumpManifest(&pFM->manifest); 00361 return 0; 00362 }

| int deleteRelatedFiles | ( | PFileManager | pFM, | |
| ScribPage * | pScribPage | |||
| ) |
Definition at line 275 of file FileMgr_page.c.
00276 { 00277 if( NULL==pScribPage) return -1; 00278 00279 char sFileName[MAX_PATHNAME+1]; 00280 00281 //del the result page 00282 get_result_filename (sFileName, sizeof(sFileName),pFM,pScribPage ); 00283 if( 0!=FileDel(sFileName) ) 00284 { 00285 SB_ERRORPRINTF("del result file[%s] fail\n",sFileName); 00286 return -1; 00287 } 00288 return 0; 00289 }

| void fm_setIrxInkDirty | ( | PFileManager | pFM, | |
| gboolean | bDirty | |||
| ) |
Definition at line 384 of file FileMgr_page.c.
00385 { 00386 pFM->manifest.bNeedSaveIrx=bDirty; 00387 }
| 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 }
| const char* getCurrImgFileName | ( | PFileManager | pFM | ) |
Definition at line 143 of file FileMgr_page.c.
00144 { 00145 return getCurrScribPage(pFM)->sImgFileName; 00146 }

| int getCurrPageNo | ( | PFileManager | pFM | ) |
| PScribPage getCurrScribPage | ( | PFileManager | pFM | ) |
Definition at line 108 of file FileMgr_page.c.
00109 { 00110 char outstr[200]; 00111 time_t iTime; 00112 unsigned int iSize=sizeof(pScribPage->sPageName); 00113 00114 if( NULL==pScribPage || NULL==pManifest) return -1; 00115 00116 memset(pScribPage->sPageName,0,iSize); 00117 time(&iTime); 00118 //result is string from time but no duplicated. 00119 int i=0; 00120 SB_FMPRINTF("start get spagename,time=%d\n",(unsigned int)iTime); 00121 while(i++<500) //control the collision time 00122 { 00123 GetStrFromTime(outstr,sizeof(outstr),iTime); 00124 if(!isPageNameExisted(pManifest,outstr)) 00125 { 00126 strncpy(pScribPage->sPageName,outstr,iSize-1); 00127 SB_FMPRINTF("sPageName=%s\n",pScribPage->sPageName); 00128 return 0;//get the name 00129 } 00130 iTime++; 00131 } 00132 return -1; 00133 }

| PScribPage getScribPage | ( | PFileManager | pFM, | |
| const int | iPageNo | |||
| ) |
Definition at line 154 of file FileMgr_page.c.
00155 { 00156 //SB_FMPRINTF("get pageno:%d[total=%d,curropen=%d]\n", 00157 //iPageNo,getTotalPage(pFM),getCurrPageNo(pFM)); 00158 if( !isPageNoValid(pFM,iPageNo) ) return NULL; 00159 int iCurr=getCurrPageNo(pFM); 00160 if( iPageNo==iCurr && isPageNoValid(pFM,iCurr)) 00161 { 00162 return pFM->pCurrPage; 00163 } 00164 PScribPage pCurr=pFM->pCurrPage; 00165 if( iCurr>iPageNo || iCurr<1) //initial,iCurr==0 00166 { 00167 pCurr=pFM->manifest.pFirstScribPage;//first page 00168 iCurr=1; 00169 } 00170 //must exist 00171 while( iCurr!=iPageNo && iCurr<=getTotalPage(pFM)) 00172 { 00173 pCurr=pCurr->pNextPage; 00174 iCurr++; 00175 } 00176 //SB_FMPRINTF("result:pCurr==NULL?%d,iCurr=%d\n",pCurr==NULL,iCurr); 00177 return pCurr; 00178 }

| int getTemplName | ( | char * | sTmpl, | |
| int | iSize, | |||
| const char * | sTmplPathName | |||
| ) |
Copyright (C) 2005-2008 iRex Technologies B.V. All rights reserved.
Definition at line 45 of file FileMgr_page.c.
00046 { 00047 int iLenOfSuffix=strlen(".bmp"); 00048 if( NULL==sTmplPathName || strlen(sTmplPathName)<=iLenOfSuffix ) 00049 return -1; 00050 00051 GetFileNameFromFullName(sTmpl,iSize,sTmplPathName); 00052 //we should remove the suffix 00053 sTmpl[strlen(sTmpl)-iLenOfSuffix]=0; 00054 return 0; 00055 }

| int getTotalPage | ( | PFileManager | pFM | ) |
Definition at line 374 of file FileMgr_page.c.
00375 { 00376 return pFM->manifest.iTotalPages; 00377 }
| int getUniqNameForSCRIB | ( | PFileManager | pFM | ) |
Copyright (C) 2005-2008 iRex Technologies B.V. All rights reserved.
Definition at line 57 of file FileMgr_page.c.
00058 { 00059 char sTmpl[MAX_FILENAME]; 00060 if( 0!=getTemplName(sTmpl,sizeof(sTmpl),pFM->sTmplPathName) ) 00061 { 00062 SB_ERRORPRINTF("invalid template name\n%s",pFM->sTmplPathName); 00063 return -1; 00064 } 00065 00066 char outstr[200]; 00067 time_t iTime; 00068 time(&iTime); 00069 00070 char* sScribName=pFM->manifest.sScribbleName; 00071 int iSize=sizeof(pFM->manifest.sScribbleName); 00072 00073 unsigned int i=0; 00074 while(i++<60)//limit the collisions 00075 { 00076 GetStrFromTime(outstr,sizeof(outstr),iTime); 00077 memset(sScribName,0,iSize); 00078 snprintf(sScribName,iSize,"%s_%s",sTmpl,outstr); 00079 00080 if(!FileExist2(sScribName,pFM->sDataDir)) 00081 { 00082 SB_FMPRINTF("SCRIB=%s\n",sScribName); 00083 return 0;//get the name 00084 } 00085 iTime++; 00086 } 00087 return -1; 00088 }

| 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 }

| int insertNewPageAfterCurr | ( | PFileManager | pFM | ) |
Definition at line 269 of file FileMgr_page.c.
00270 { 00271 return insertNewPage(pFM,pFM->iCurrOpenPage+1,getCurrImgFileName(pFM)); 00272 }

| gboolean isPageNameExisted | ( | Manifest * | pManifest, | |
| const char * | sPageName | |||
| ) |
Definition at line 91 of file FileMgr_page.c.
00092 { 00093 if( NULL==pManifest) return FALSE; 00094 00095 PScribPage pCurrPage=pManifest->pFirstScribPage; 00096 while(pCurrPage) 00097 { 00098 if( 0==strcmp(pCurrPage->sPageName,sPageName) ) 00099 { 00100 return TRUE;//existed 00101 } 00102 pCurrPage=pCurrPage->pNextPage; 00103 } 00104 return FALSE; 00105 }
| gboolean isPageNoValid | ( | PFileManager | pFM, | |
| const int | iPageNo | |||
| ) |
Definition at line 148 of file FileMgr_page.c.
00149 { 00150 return ( iPageNo>0 && iPageNo<=getTotalPage(pFM)); 00151 }

| 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 }

| void setCurrentPageDirty | ( | PFileManager | pFM, | |
| gboolean | bDirty | |||
| ) |
Definition at line 389 of file FileMgr_page.c.
00390 { 00391 getCurrScribPage(pFM)->bDirty=bDirty; 00392 if(bDirty) 00393 { 00394 fm_setIrxInkDirty(pFM,TRUE); 00395 } 00396 }

1.5.6