24 qDebug() <<
"Error: project file not found -- guid "
29 QFile file( filename );
30 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text) )
32 qDebug() <<
"Error: can't open file for reading"
37 QXmlStreamReader xml( &file );
41 while ( ! xml.atEnd() )
45 if ( xml.isStartElement() )
47 if ( xml.name() ==
"project" )
49 QXmlStreamAttributes a = xml.attributes();
50 projectID = a.value(
"id" ).toString().toInt();
62 qDebug() <<
"Error: xml error: \n"
74 while ( ! xml.atEnd() )
78 if ( xml.isEndElement() && xml.name() ==
"project" )
return;
80 if ( xml.isStartElement() )
82 if ( xml.name() ==
"goals" )
85 goals = xml.text().toString();
88 else if ( xml.name() ==
"molecules" )
94 else if ( xml.name() ==
"purity" )
97 purity = xml.text().toString();
100 else if ( xml.name() ==
"expense" )
103 expense = xml.text().toString();
106 else if ( xml.name() ==
"bufferComponents" )
112 else if ( xml.name() ==
"saltInformation" )
118 else if ( xml.name() ==
"AUC_questions" )
124 else if ( xml.name() ==
"expDesign" )
130 else if ( xml.name() ==
"notes" )
133 notes = xml.text().toString();
136 else if ( xml.name() ==
"description" )
149 QStringList q(
"get_project_info" );
150 q << QString::number( projectID );
184 QRegExp rx(
"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$" );
198 QFile file( filename );
199 if ( !file.open( QIODevice::WriteOnly | QIODevice::Text) )
201 qDebug() <<
"Error: can't open file for writing"
207 QXmlStreamWriter xml;
208 xml.setDevice( &file );
209 xml.setAutoFormatting(
true );
211 xml.writeStartDocument();
212 xml.writeDTD(
"<!DOCTYPE US_Project>");
213 xml.writeStartElement(
"ProjectData");
214 xml.writeAttribute(
"version",
"1.0");
217 xml.writeStartElement(
"project" );
218 xml.writeAttribute (
"id", QString::number(
projectID ) );
221 xml.writeTextElement(
"goals",
goals );
222 xml.writeTextElement(
"molecules",
molecules );
223 xml.writeTextElement(
"purity",
purity );
224 xml.writeTextElement(
"expense",
expense );
228 xml.writeTextElement(
"expDesign",
expDesign );
229 xml.writeTextElement(
"notes",
notes );
230 xml.writeTextElement(
"description",
projectDesc );
232 xml.writeEndElement ();
233 xml.writeEndDocument ();
248 QStringList q(
"get_projectID_from_GUID" );
259 q <<
"update_project2"
303 qDebug() <<
"MySQL error: " << db->
lastError();
328 QFile file( filename );
344 q <<
"get_projectID_from_GUID"
356 q <<
"delete_project"
361 qDebug() <<
"MySQL error: " << db->
lastError();
377 qDebug() <<
"Error: could not create the projects directory";
382 QStringList filter(
"P*.xml" );
383 QStringList names = dir.entryList( filter, QDir::Files, QDir::Name );
386 for (
int i = 0; i < names.size(); i++ )
388 filename = path +
"/" + names[ i ];
389 QFile file( filename );
391 if ( ! file.open( QIODevice::ReadOnly | QIODevice::Text) )
continue;
393 QXmlStreamReader xml( &file );
395 while ( ! xml.atEnd() )
399 if ( xml.isStartElement() )
401 if ( xml.name() ==
"project" )
403 QXmlStreamAttributes a = xml.attributes();
405 if ( a.value(
"guid" ).toString() == guid ) found =
true;
417 filename = QString(
"" );
430 if ( ! dir.exists( path ) )
432 if ( ! dir.mkpath( path ) )
434 qDebug() <<
"Error: Could not create default directory for projects\n"
445 const QString& path,
bool& newFile )
448 QStringList filter(
"P???????.xml" );
449 QStringList f_names = f.entryList( filter, QDir::Files, QDir::Name );
453 for (
int i = 0; i < f_names.size(); i++ )
455 QFile b_file( path +
"/" + f_names[ i ] );
457 if ( ! b_file.open( QIODevice::ReadOnly | QIODevice::Text) )
continue;
459 QXmlStreamReader xml( &b_file );
461 while ( ! xml.atEnd() )
465 if ( xml.isStartElement() )
467 if ( xml.name() ==
"project" )
469 QXmlStreamAttributes a = xml.attributes();
474 filename = path +
"/" + f_names[ i ];
483 if ( ! newFile )
return filename;
487 int number = ( f_names.size() > 0 ) ? f_names.last().mid( 1, 7 ).toInt() : 0;
489 return path +
"/P" + QString().sprintf(
"%07i", number + 1 ) +
".xml";
496 goals = QString(
"" );
504 notes = QString(
"" );
506 status = QString(
"submitted" );
513 qDebug() <<
"projectID = " <<
projectID <<
'\n'
515 <<
"goals = " <<
goals <<
'\n'
517 <<
"purity = " <<
purity <<
'\n'
518 <<
"expense = " <<
expense <<
'\n'
523 <<
"notes = " <<
notes <<
'\n'
525 <<
"status = " <<
status <<
'\n'