This is the main entry point for an import. It is passed the file which contains the export data. It then opens up the file, checks the validity of the data, and then begins to parse through all of the crap.
| 59 | //* then begins to parse through all of the crap. |
| 60 | //*********************************************************** |
| 61 | void BatchImport::import(QString file) { |
| 62 | fileName = file; |
| 63 | qint32 newLid = -1; |
| 64 | errorMessage = ""; |
| 65 | |
| 66 | lastError = 0; |
| 67 | QFile xmlFile(fileName); |
| 68 | if (!xmlFile.open(QIODevice::ReadOnly)) { |
| 69 | lastError = 16; |
| 70 | errorMessage = "Cannot open file."; |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | reader = new QXmlStreamReader(&xmlFile); |
| 75 | while (!reader->atEnd()) { |
| 76 | reader->readNext(); |
| 77 | if (reader->hasError()) { |
| 78 | errorMessage = reader->errorString(); |
| 79 | QLOG_ERROR() << "************************* ERROR READING IMPORT " << errorMessage; |
| 80 | lastError = 16; |
| 81 | return; |
| 82 | } |
| 83 | if (reader->name().toString().toLower() == "noteadd" && reader->isStartElement()) { |
| 84 | newLid = addNoteNode(); |
| 85 | } |
| 86 | } |
| 87 | xmlFile.close(); |
| 88 | |
| 89 | QString id = file; |
| 90 | int pos = id.lastIndexOf("."); |
| 91 | if (pos>0) |
| 92 | id = id.mid(0,pos); |
| 93 | pos = id.lastIndexOf(QDir::separator()); |
| 94 | if (pos>0) |
| 95 | id = id.mid(pos+1); |
| 96 | CrossMemoryMapper sharedMemory(id); |
| 97 | if (!sharedMemory.attach()) |
| 98 | return; |
| 99 | |
| 100 | QString response = QString::number(newLid); |
| 101 | sharedMemory.write(response.toAscii()); |
| 102 | sharedMemory.detach(); |
| 103 | } |
| 104 | |
| 105 | |
| 106 | //*********************************************************** |