COOPY » Guide
version 0.6.5
|
00001 #include <coopy/GnumericTextBookFactory.h> 00002 00003 using namespace coopy::store; 00004 using namespace coopy::store::gnumeric; 00005 using namespace std; 00006 00007 TextBook *GnumericTextBookFactory::open(AttachConfig& config, 00008 AttachReport& report) { 00009 //config.show(); 00010 string ext = config.ext; 00011 report.applicable = true; 00012 if (config.shouldCreate) { 00013 report.errorCreateNotImplemented("gnumeric"); 00014 return NULL; 00015 } 00016 if (config.shouldWrite && !config.shouldRead) { 00017 if (config.prevBook!=NULL) { 00018 GnumericTextBook *prev = dynamic_cast<GnumericTextBook *>(config.prevBook); 00019 if (prev!=NULL) { 00020 //printf("FAST TRACK\n"); 00021 if (config.options.check("format")) { 00022 prev->save(config.fname.c_str(),config.options.get("format").asString().c_str()); 00023 } else { 00024 prev->save(config.fname.c_str(),NULL); 00025 } 00026 report.success = true; 00027 return prev; 00028 } 00029 } 00030 } 00031 GnumericTextBook *book = new GnumericTextBook; 00032 if (book==NULL) return book; 00033 bool ok = false; 00034 if (book->load(config.fname.c_str())) { 00035 ok = true; 00036 } else { 00037 if (config.canCreate) { 00038 if (book->create()) { 00039 ok = true; 00040 } 00041 } 00042 } 00043 if (!ok) { 00044 delete book; 00045 book = NULL; 00046 } else { 00047 if (config.prevBook!=NULL) { 00048 book->copy(*config.prevBook,config.options); 00049 if (config.shouldWrite) { 00050 if (config.options.check("format")) { 00051 book->save(config.fname.c_str(),config.options.get("format").asString().c_str()); 00052 } else { 00053 book->save(config.fname.c_str(),NULL); 00054 } 00055 } 00056 } 00057 } 00058 if (book!=NULL) { 00059 report.success = true; 00060 } 00061 return book; 00062 } 00063 00064