00001 #include <qmessagebox.h>
00002
00003 #include "trapperparser.h"
00004 #include "trapperdoc.h"
00005 #include "generaldata.h"
00006 #include "featuredata.h"
00007 #include "qdir.h"
00008
00009 bool TrapperParser::startElement(const QString& namespaceURI,
00010 const QString& localName,
00011 const QString& qName,
00012 const QXmlAttributes& attributes)
00013 {
00014
00015 if ( qName == "TRAPPER" ) {
00016 format_ok = true;
00017 return true;
00018 }
00019 else if ( qName == "contig" && format_ok ) {
00020
00021
00022
00023
00024
00025
00026
00027 QString contigName = attributes.value("name");
00028
00029
00030
00031 QStringList contigNamesAlreadyPresent = contigNamesInProjectDir();
00032 if ( contigNamesAlreadyPresent.contains( contigName ) ) {
00033 QString message;
00034 message = QString("The contig name \"%1\" was specified in the import file, but that contig is already present in the project dir. Skipping this one").arg(contigName);
00035 QMessageBox::warning(0,"",message);
00036 return false;
00037 }
00038
00039 QString fName = projDir + "/" + contigName;
00040
00041
00042
00043
00044 current_doc = new TrapperDoc(env);
00045 current_doc->openDocument(fName);
00046
00047 return true;
00048 }
00049 else if ( format_ok ) {
00050
00051
00052
00053
00054
00055 Database::Creator<GeneralData> creator( current_doc, qName.ascii() );
00056
00057 creator.data()->readAttributes( attributes );
00058
00059 if ( qName != "ReadData" ) {
00060
00061 FeatureData* fdata = dynamic_cast<FeatureData*>(creator.data());
00062 assert( fdata );
00063 fdata->setReadRecno( current_read_recno );
00064
00065 }
00066 db_recno_t new_recno = creator.create( false );
00067 if ( qName == "ReadData" ) {
00068
00069 current_read_recno = new_recno;
00070 }
00071 return true;
00072 }
00073 return false;
00074 }
00075
00076 bool TrapperParser::endElement( const QString & namespaceURI, const QString & localName,
00077 const QString & qName)
00078 {
00079 if ( qName == "contig" ) {
00080
00081 delete current_doc;
00082
00083 }
00084 return true;
00085 }
00086
00087
00088
00089 QStringList TrapperParser::contigNamesInProjectDir()
00090 {
00091 QString contigName;
00092 QDir d( projDir );
00093 Q_ASSERT( d.exists() );
00094 d.setFilter( QDir::Dirs | QDir::NoSymLinks );
00095 d.setSorting( QDir::Name );
00096 QStringList slist = d.entryList();
00097 return slist;
00098 }