00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "ConnectionParameterViewer.h"
00025 #include "Debug.h"
00026
00027
00028 #include <qmessagebox.h>
00029 #include <qpushbutton.h>
00030 #include <qlabel.h>
00031
00032
00033 #include <string>
00034 #include <mysql++.h>
00035 using namespace std;
00036 using namespace mysqlpp;
00037
00038
00039
00040
00041
00042
00043 ConnectionParameterViewer::ConnectionParameterViewer(QWidget* parent, DBInterface* netDBInter, unsigned int cGrpID) : QDialog(parent){
00044
00045 networkDBInterface = netDBInter;
00046 connGrpID = cGrpID;
00047
00048
00049 QString captionStr = "Connection Group Parameters [";
00050 captionStr += QString::number(connGrpID);
00051 captionStr += "]";
00052 this->setCaption(captionStr);
00053
00054
00055 mainVerticalBox = new QVBoxLayout(this, 5, 10, "vertical");
00056
00057
00058 errorState = false;
00059
00060
00061 this->setModal(false);
00062
00063
00064 string paramXmlString("");
00065 try{
00066 Query query = networkDBInterface->getQuery();
00067 query.reset();
00068 query<<"SELECT Parameters FROM ConnectionGroups WHERE ConnGrpID = "<<connGrpID;
00069 Result paramRes = query.store();
00070 Row paramRow(*paramRes.begin());
00071 paramXmlString = (std::string) paramRow["Parameters"];
00072 }
00073 catch (const BadQuery& er) {
00074 cerr<<"ConnectionParameterViewer: MYSQL QUERY EXCEPTION \""<<er.what()<<"\""<<endl;
00075 QString errorString = "Bad query selecting connection parameters: \"";
00076 errorString += er.what();
00077 errorString += "\"";
00078 QMessageBox::critical( 0, "Connection Parameter Error", errorString);
00079 errorState = true;
00080 return;
00081 }
00082 catch (const Exception& er) {
00083 cerr<<"ConnectionParameterViewer: MYSQL EXCEPTION \""<<er.what()<<"\""<<endl;
00084 QString errorString = "Exception thrown selecting network parameters: \"";
00085 errorString += er.what();
00086 errorString += "\"";
00087 QMessageBox::critical( 0, "Connection Parameter Error", errorString);
00088 errorState = true;
00089 return;
00090 }
00091
00092 QXmlSimpleReader xmlReader;
00093 QXmlInputSource xmlInput;
00094 xmlReader.setContentHandler(this);
00095 xmlReader.setErrorHandler(this);
00096
00097 if(paramXmlString != "NULL" && paramXmlString != ""){
00098 xmlInput.setData(paramXmlString);
00099 xmlReader.parse(xmlInput);
00100 if(parseError){
00101 QMessageBox::critical( 0, "Error Parsing Connection Parameters", parseErrorString);
00102 errorState = true;
00103 return;
00104 }
00105 }
00106 else{
00107 currentHBox = new QHBoxLayout();
00108 currentHBox->addWidget(new QLabel("No parameters stored.", this));
00109 currentHBox->addStretch(5);
00110 mainVerticalBox->addLayout(currentHBox);
00111 }
00112 mainVerticalBox->addStretch(5);
00113
00114
00115 QHBoxLayout *buttonBox = new QHBoxLayout();
00116 QPushButton *okButton = new QPushButton("Ok", this);
00117 buttonBox->addWidget(okButton);
00118 connect (okButton, SIGNAL(clicked()), this, SLOT(okButtonPressed()));
00119
00120 QPushButton *cancelButton = new QPushButton("Cancel", this);
00121 buttonBox->addWidget(cancelButton);
00122 connect (cancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonPressed()));
00123 mainVerticalBox->addLayout(buttonBox);
00124
00125
00126 this->resize(400, 200);
00127 }
00128
00129
00130
00131 ConnectionParameterViewer::~ConnectionParameterViewer(){
00132 #ifdef MEMORY_DEBUG
00133 cout<<"DESTROYING CONNECTION PARAMETER VIEWER"<<endl;
00134 #endif//MEMORY_DEBUG
00135 }
00136
00137
00138
00139
00140
00141
00142 bool ConnectionParameterViewer::loadError(){
00143 return errorState;
00144 }
00145
00146
00147
00148
00149
00150
00151
00152 bool ConnectionParameterViewer::characters(const QString& chars){
00153 #ifdef XML_PARSE_DEBUG
00154 cout<<"Characters: "<<chars<<" in element "<<currentElement<<endl;
00155 #endif//XML_PARSE_DEBUG
00156 if(currentElement == "description"){
00157 currentHBox->addWidget(new QLabel(chars, this));
00158 }
00159 else if(currentElement == "value"){
00160 currentHBox->addWidget(new QLabel(chars, this));
00161 currentHBox->addStretch(5);
00162 mainVerticalBox->addLayout(currentHBox);
00163 }
00164 else if(currentElement == "min_delay"){
00165 currentHBox = new QHBoxLayout();
00166 currentHBox->addWidget(new QLabel("Delay range: Min", this));
00167 currentHBox->addWidget(new QLabel(chars, this));
00168 }
00169 else if(currentElement == "max_delay"){
00170 currentHBox->addWidget(new QLabel("Max", this));
00171 currentHBox->addWidget(new QLabel(chars, this));
00172 currentHBox->addStretch(5);
00173 mainVerticalBox->addLayout(currentHBox);
00174 }
00175 else{
00176 parseError = true;
00177 parseErrorString += "Unrecognized element.";
00178 cerr<<"ConnectionParameterViewer: UNRECOGNIZED ELEMENT"<<endl;
00179 }
00180 return true;
00181 }
00182
00183
00184
00185 bool ConnectionParameterViewer::endElement( const QString&, const QString&, const QString& qName){
00186 #ifdef XML_PARSE_DEBUG
00187 cout<<"End element: "<<qName<<endl;
00188 #endif//XML_PARSE_DEBUG
00189 return true;
00190 }
00191
00192
00193
00194 bool ConnectionParameterViewer::error ( const QXmlParseException& parseEx){
00195 cerr<<"ConnectionParameterViewer: PARSING ERROR"<<endl;
00196 parseError = true;
00197 parseErrorString += parseEx.message();
00198 return true;
00199 }
00200
00201
00202
00203 QString ConnectionParameterViewer::errorString (){
00204 return QString("ConnectionParameterViewer: Default error string");
00205
00206 }
00207
00208
00209
00210 bool ConnectionParameterViewer::fatalError ( const QXmlParseException& parseEx){
00211 cerr<<"ConnectionParameterViewer: PARSING FATAL ERROR"<<endl;
00212 parseError = true;
00213 parseErrorString += parseEx.message();
00214 return true;
00215 }
00216
00217
00218
00219 bool ConnectionParameterViewer::startDocument(){
00220 parseError = false;
00221 parseErrorString = "";
00222 return true;
00223 }
00224
00225
00226
00227 bool ConnectionParameterViewer::startElement(const QString&, const QString&, const QString& qName, const QXmlAttributes&){
00228 #ifdef XML_PARSE_DEBUG
00229 cout<<"Start element: "<<qName<<endl;
00230 #endif//XML_PARSE_DEBUG
00231 currentElement = qName;
00232 if(currentElement == "parameter"){
00233 currentHBox = new QHBoxLayout();
00234 }
00235 return true;
00236 }
00237
00238
00239
00240 bool ConnectionParameterViewer::warning ( const QXmlParseException& ){
00241 cerr<<"ConnectionParameterViewer: PARSING WARNING"<<endl;
00242 return true;
00243 }
00244
00245
00246
00247
00248
00249
00250
00251 void ConnectionParameterViewer::cancelButtonPressed(){
00252 this->accept();
00253 }
00254
00255
00256
00257 void ConnectionParameterViewer::okButtonPressed(){
00258 this->accept();
00259 }
00260
00261
00262