1 // $Id: datafilenamedialog.cpp,v 1.13 2010/03/17 17:25:58 bobgian Exp $ 2 3 /* 4 Copyright 2003 Peter Beerli, Mary Kuhner, Jon Yamato and Joseph Felsenstein 5 6 This software is distributed free of charge for non-commercial use 7 and is copyrighted. Of course, we do not guarantee that the software 8 works, and are not responsible for any damage you may cause or have. 9 */ 10 11 #include "dialogrepeat.h" 12 #include "datafilenamedialog.h" 13 #include "errhandling.h" 14 #include "menudefs.h" 15 #include "stringx.h" 16 #include "ui_interface.h" 17 #include "ui_strings.h" 18 #include "xml.h" 19 #include <string> 20 #include <iostream> 21 DataFileNameDialog(XmlParser & parser)22DataFileNameDialog::DataFileNameDialog(XmlParser & parser) 23 : DialogRepeat() , m_dataFileName(parser.GetFileName()), m_parser(parser) 24 { 25 } 26 ~DataFileNameDialog()27DataFileNameDialog::~DataFileNameDialog() 28 { 29 } 30 maxTries()31long DataFileNameDialog::maxTries() 32 { 33 return 3; 34 } 35 displayFileName()36std::string DataFileNameDialog::displayFileName() 37 { 38 std::string displayFileName; 39 if(m_dataFileName == "") 40 { 41 displayFileName = "[No default set]\n"; 42 } 43 else 44 { 45 displayFileName = "[Default: "+ m_dataFileName + "]\n"; 46 } 47 return displayFileName; 48 } 49 beforeLoopOutputString()50std::string DataFileNameDialog::beforeLoopOutputString() 51 { 52 return ""; 53 } 54 inLoopOutputString()55std::string DataFileNameDialog::inLoopOutputString() 56 { 57 return "Enter the location of the data file\n"+displayFileName()+"\n"; 58 } 59 inLoopFailureOutputString()60std::string DataFileNameDialog::inLoopFailureOutputString() 61 { 62 return " \n \n" + m_errmsg + "\n"; 63 } 64 afterLoopSuccessOutputString()65std::string DataFileNameDialog::afterLoopSuccessOutputString() 66 { 67 std::string message = "Data file was read successfully\n\n"; 68 message += "Calculating starting values; please be patient"; 69 return message; 70 } 71 afterLoopFailureOutputString()72std::string DataFileNameDialog::afterLoopFailureOutputString() 73 { 74 return "Unable to read or find your file in "+ToString(maxTries()) 75 + " attempts.\n"; 76 } 77 handleInput(std::string input)78bool DataFileNameDialog::handleInput(std::string input) 79 { 80 if (input.size () != 0) 81 { 82 m_dataFileName = input; 83 } 84 try 85 { 86 m_parser.ParseFileData(m_dataFileName); 87 } 88 catch (const data_error& e) 89 { 90 m_errmsg = e.whatString(); 91 return false; 92 } 93 return true; 94 } 95 doFailure()96void DataFileNameDialog::doFailure() 97 { 98 throw data_error("To create a LAMARC input file, please run the converter (lam_conv)."); 99 } 100 101 //____________________________________________________________________________________ 102