#include <fcntl.h>#include <string.h>#include <sys/ioctl.h>#include <libermanifest/ermanifest.h>#include "scbdoc.h"#include "scblog.h"Go to the source code of this file.
Defines | |
| #define | _GNU_SOURCE |
Functions | |
| gboolean | _doc_check_path (ScbPathPtr ptr) |
| ScbDocPtr | scb_doc_new () |
| void | scb_doc_free (ScbDocPtr ptr) |
| ScbDocPtr | scb_doc_open (ScbPathPtr ptr) |
| ScbDocPtr | scb_doc_make_sure_exist (ScbPathPtr ptr) |
| gboolean | scb_doc_save (ScbDocPtr doc) |
| gboolean | scb_doc_saveAs (ScbDocPtr doc, ScbPathPtr ptr) |
| ScbPagesPtr | scb_doc_get_pages (ScbDocPtr ptr) |
| ScbStrokeStylePtr | scb_doc_get_current_stroke_style (ScbDocPtr doc) |
| ScbPagePtr | scb_doc_get_page (ScbDocPtr doc, ScbPageIdPtr id) |
| gboolean | scb_doc_add_page (ScbDocPtr doc, ScbPagePtr page) |
| void | scb_doc_init_context (ScbDocPtr ptr) |
| void | scb_doc_free_context (ScbDocPtr ptr) |
| void | scb_doc_add_map_item (ScbDocPtr doc, const ScbTBSItemPtr ptr) |
| ScbTBState | scb_doc_get_current_state (ScbDocPtr doc) |
| gboolean | scb_state_is_scribble (ScbDocPtr doc) |
| gboolean | scb_state_is_erase (ScbDocPtr doc) |
| void | scb_doc_dump (ScbDocPtr ptr) |
| #define _GNU_SOURCE |
| gboolean _doc_check_path | ( | ScbPathPtr | ptr | ) |
Definition at line 37 of file scbdoc.c.
00038 { 00039 if (NULL == ptr || strnlen(ptr->scbname, SCB_MAX_PATH) <= 0) 00040 { 00041 SCB_ERROR("Invalid path!"); 00042 return FALSE; 00043 } 00044 return TRUE; 00045 }
| void scb_doc_add_map_item | ( | ScbDocPtr | doc, | |
| const ScbTBSItemPtr | ptr | |||
| ) |
Definition at line 306 of file scbdoc.c.
00307 { 00308 SCB_RET_IF(NULL == doc || NULL == ptr, "Invalid pointer(s)!"); 00309 g_array_append_val(doc->context.table, *ptr); 00310 }
| gboolean scb_doc_add_page | ( | ScbDocPtr | doc, | |
| ScbPagePtr | page | |||
| ) |
Definition at line 278 of file scbdoc.c.
00279 { 00280 ScbPagesPtr pages = scb_doc_get_pages(doc); 00281 if (NULL == pages) return FALSE; 00282 return scb_pages_add_page(pages, page); 00283 }

| void scb_doc_dump | ( | ScbDocPtr | ptr | ) |
Definition at line 329 of file scbdoc.c.
00330 { 00331 if (ptr) 00332 { 00333 scb_pages_dump(&ptr->pages); 00334 } 00335 }

| void scb_doc_free | ( | ScbDocPtr | ptr | ) |
Definition at line 72 of file scbdoc.c.
00073 { 00074 if (NULL == ptr) 00075 { 00076 return; 00077 } 00078 00079 scb_doc_free_context(ptr); 00080 scb_pages_free(&ptr->pages); 00081 g_free(ptr); 00082 }

| void scb_doc_free_context | ( | ScbDocPtr | ptr | ) |
| ScbTBState scb_doc_get_current_state | ( | ScbDocPtr | doc | ) |
Definition at line 312 of file scbdoc.c.
00313 { 00314 if (NULL == doc) return SCB_TBS_INVALID; 00315 return doc->context.curState; 00316 }
| ScbStrokeStylePtr scb_doc_get_current_stroke_style | ( | ScbDocPtr | doc | ) |
Definition at line 233 of file scbdoc.c.
00234 { 00235 SCB_RET_NULL_IF(NULL == doc, "Invalid pointer!"); 00236 return &doc->context.curStrokeStyle; 00237 }
| ScbPagePtr scb_doc_get_page | ( | ScbDocPtr | doc, | |
| ScbPageIdPtr | id | |||
| ) |
Definition at line 270 of file scbdoc.c.
00271 { 00272 ScbPagesPtr pages = scb_doc_get_pages(doc); 00273 if (NULL == pages) return NULL; 00274 return scb_pages_get_page(pages, id); 00275 }

| ScbPagesPtr scb_doc_get_pages | ( | ScbDocPtr | ptr | ) |
| void scb_doc_init_context | ( | ScbDocPtr | ptr | ) |
Definition at line 285 of file scbdoc.c.
00286 { 00287 SCB_RET_IF(NULL == ptr, "Invalid doc pointer!"); 00288 ptr->context.table = g_array_sized_new(FALSE, TRUE, 00289 sizeof(ScbTBSItem), SCB_DEF_CMD_ACT_SIZE); 00290 ptr->context.curState = SCB_TBS_SCRIBBLE; 00291 ptr->context.curStrokeStyle.color = SCB_DEV_COLOR_BLACK; 00292 ptr->context.curStrokeStyle.layer = SCB_DEF_STROKE_LAYER; 00293 ptr->context.curStrokeStyle.lineStyle = SCB_DEF_STROKE_LINESTYLE; 00294 ptr->context.curStrokeStyle.penSize = SCB_DEF_STROKE_PENSIZE; 00295 00296 ptr->context.appId = -1; 00297 }
| ScbDocPtr scb_doc_make_sure_exist | ( | ScbPathPtr | ptr | ) |
Definition at line 134 of file scbdoc.c.
00135 { 00136 if (!_doc_check_path(ptr)) return NULL; 00137 ScbDocPtr doc = NULL; 00138 00139 // is exist, just open it 00140 if (scb_path_file_exist(ptr->scbname)) 00141 { 00142 doc = scb_doc_open(ptr); 00143 if (doc) 00144 { 00145 return doc; 00146 } 00147 } 00148 00149 // something wrong with the document, have to re-create it 00150 // or construct a new one and save as... 00151 doc = scb_doc_new(); 00152 if (NULL == doc) 00153 { 00154 // it's fatal error, could do nothing 00155 return NULL; 00156 } 00157 if (scb_doc_saveAs(doc, ptr)) 00158 { 00159 return doc; 00160 } 00161 scb_doc_free(doc); 00162 return NULL; 00163 }

| ScbDocPtr scb_doc_new | ( | ) |
Definition at line 50 of file scbdoc.c.
00051 { 00052 ScbDocPtr ptr = g_new0(ScbDoc, 1); 00053 00054 if (NULL == ptr) 00055 { 00056 SCB_ERROR("Not enough memory!"); 00057 return NULL; 00058 } 00059 00060 if (!scb_pages_new(&ptr->pages)) 00061 { 00062 g_free(ptr); 00063 return NULL; 00064 } 00065 00066 scb_doc_init_context(ptr); 00067 00068 return ptr; 00069 }

| ScbDocPtr scb_doc_open | ( | ScbPathPtr | ptr | ) |
Definition at line 88 of file scbdoc.c.
00089 { 00090 // check 00091 if (!_doc_check_path(ptr)) return NULL; 00092 00093 // use lib ermanifest to open the document 00094 ScbXml xml; 00095 if (RET_OK != ermXmlOpenFile(ptr->scbname, &xml.handle)) 00096 { 00097 SCB_ERROR("Could not open the file %s!", ptr->scbname); 00098 return NULL; 00099 } 00100 SCB_TRACE("Successfully open file %s", ptr->scbname); 00101 00102 // construct the document object 00103 ScbDocPtr doc = scb_doc_new(); 00104 if (NULL == doc) 00105 { 00106 ermXmlClose(&xml.handle); 00107 return NULL; 00108 } 00109 memcpy(&doc->path, ptr, sizeof(doc->path)); 00110 SCB_TRACE("Successfully construct document object!"); 00111 00112 // construct xPath 00113 strncpy(xml.xPath, "/notes", SCB_MAX_XML_PATH); 00114 xml.index = 1; 00115 00116 // load pages 00117 if (scb_pages_load(&doc->pages, &xml)) 00118 { 00119 ermXmlClose(&xml.handle); 00120 SCB_TRACE("Successfully load all pages!"); 00121 return doc; 00122 } 00123 else 00124 { 00125 ermXmlClose(&xml.handle); 00126 scb_doc_free(doc); 00127 SCB_TRACE("Error occurs during loading pages!"); 00128 return NULL; 00129 } 00130 }

| gboolean scb_doc_save | ( | ScbDocPtr | doc | ) |
Definition at line 167 of file scbdoc.c.
00168 { 00169 SCB_RET_FALSE_IF(NULL == doc, "Invalid doc pointer!"); 00170 00171 // use lib ermanifest to create the document 00172 ScbXml xml; 00173 if (RET_OK != ermXmlCreateFile(doc->path.scbname, &xml.handle)) 00174 { 00175 SCB_ERROR("Could not create the file %s!", doc->path.scbname); 00176 return FALSE; 00177 } 00178 SCB_TRACE("Successfully create file %s", doc->path.scbname); 00179 00180 // one by one 00181 ermXmlNewString(&xml.handle, "/" , "notes", ""); 00182 SCB_TRACE("Create root node scbdoc"); 00183 00184 // notes field 00185 ermXmlNewString(&xml.handle, "/notes", "version", ""); 00186 ermXmlNewString(&xml.handle, "/notes/version", "number", SCB_LIB_VERSION); 00187 ermXmlNewString(&xml.handle, "/notes/version", "organization", SCB_LIB_ORG); 00188 00189 // screen field 00190 ermXmlNewString(&xml.handle, "/notes", "screen", ""); 00191 ermXmlNewString(&xml.handle, "/notes/screen", "units", SCB_DEF_SCREEN_UNITS); 00192 ermXmlNewInt(&xml.handle, "/notes/screen", "dpi", SCB_DEF_SCREEN_DPI); 00193 00194 // construct xPath 00195 strncpy(xml.xPath, "/notes", SCB_MAX_XML_PATH); 00196 xml.index = 0; 00197 00198 // save pages 00199 if (scb_pages_save(&doc->pages, &xml)) 00200 { 00201 ermXmlSaveAndClose(&xml.handle); 00202 SCB_TRACE("Successfully save all pages!"); 00203 return TRUE; 00204 } 00205 else 00206 { 00207 ermXmlClose(&xml.handle); 00208 SCB_TRACE("Error occurs during saving pages!"); 00209 return FALSE; 00210 } 00211 }

| gboolean scb_doc_saveAs | ( | ScbDocPtr | doc, | |
| ScbPathPtr | ptr | |||
| ) |
Definition at line 215 of file scbdoc.c.
00216 { 00217 SCB_RET_FALSE_IF(NULL == doc || NULL == ptr, "Invalid pointer(s)!"); 00218 memcpy(&doc->path, ptr, sizeof(doc->path)); 00219 return scb_doc_save(doc); 00220 }

| gboolean scb_state_is_erase | ( | ScbDocPtr | doc | ) |
Definition at line 322 of file scbdoc.c.
00323 { 00324 return SCB_TBS_ERASE == scb_doc_get_current_state(doc); 00325 }

| gboolean scb_state_is_scribble | ( | ScbDocPtr | doc | ) |
Definition at line 318 of file scbdoc.c.
00319 { 00320 return SCB_TBS_SCRIBBLE == scb_doc_get_current_state(doc); 00321 }

1.5.6