Index: src/MainWindow.hxx =================================================================== --- src/MainWindow.hxx (revision 14391) +++ src/MainWindow.hxx (working copy) @@ -47,6 +47,8 @@ #include #include +#include "Python.h" +#include //#define AFTER13RELEASE @@ -254,10 +256,8 @@ query.evaluateTo(&readClamVersion); #endif readClamVersion = readClamVersion.trimmed(); - - int comparision = compareVersions(readClamVersion, CLAM::GetVersion()); - - if (comparision==-1) + int comparison = compareVersions(readClamVersion, CLAM::GetVersion()); + if (comparison==-1) { int response = QMessageBox::question(this, tr("NetworkEditor"), @@ -270,15 +270,11 @@ if (response == QMessageBox::Cancel) return; if (response == QMessageBox::Yes) { - QMessageBox::warning(this, - tr("Network Editor"), - tr("Feature not implemented")); - // TODO: Updating the script + loadFromString(updateWithClamRefactor(qPrintable(filename)), filename); return; } - } - if (comparision==+1) + if (comparison==+1) { int response = QMessageBox::question(this, tr("NetworkEditor"), @@ -291,11 +287,79 @@ QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes); if (response == QMessageBox::No) return; } - + loadFromFile(filename); + } + char * updateWithClamRefactor(const std::string & filename) + { + PyObject *pModule, *pDict, *pClassClamNetwork, *pClamNetwork, *pInstanceClamNetwork, *pValue; - loadVersionChecked(filename); + Py_Initialize(); + pModule = PyImport_ImportModule("clamrefactor"); + if (pModule == NULL) + { + PyErr_Print(); + return ""; + } + pDict = PyModule_GetDict(pModule); + // Build the name of a callable class + pClassClamNetwork = PyDict_GetItemString(pDict, "ClamNetwork"); + // Create an instance of the class + if (PyCallable_Check(pClassClamNetwork)) + { + pClamNetwork = Py_BuildValue( "(s)", filename.c_str() ); + pInstanceClamNetwork = PyObject_CallObject(pClassClamNetwork, pClamNetwork); + } + if (pInstanceClamNetwork == NULL) + { + PyErr_Print(); + return ""; + } + std::string migration = "migrationScript"; //migration script file + std::ifstream ifs( migration.c_str() ); + std::string command; + while( getline(ifs, command) ) + { + pValue = PyObject_CallMethod( pInstanceClamNetwork, "runCommand", "(s)", command.c_str() ); + } + + PyObject *pModule2, *pDict2, *pClassStringIO, *pStringIO, *pInstanceStringIO; + pModule2 = PyImport_ImportModule("StringIO"); + if (pModule2 == NULL) + { + PyErr_Print(); + return ""; + } + pDict2 = PyModule_GetDict(pModule2); + pClassStringIO = PyDict_GetItemString(pDict2, "StringIO"); + if (PyCallable_Check(pClassStringIO)) + { + pStringIO = Py_BuildValue( "(s)", "" ); + pInstanceStringIO = PyObject_CallObject(pClassStringIO, pStringIO); + } + + PyObject_CallMethod(pInstanceClamNetwork, "dump", "(O)", pInstanceStringIO); + pValue = PyObject_CallMethod(pInstanceStringIO, "getvalue", NULL); + + char *cstring; + if (pValue == NULL) + { + PyErr_Print(); + return ""; + } + + PyArg_Parse(pValue, "s", &cstring); + Py_DECREF(pModule); + Py_DECREF(pModule2); + Py_DECREF(pClamNetwork); + Py_DECREF(pStringIO); + Py_DECREF(pInstanceClamNetwork); + Py_DECREF(pInstanceStringIO); + Py_DECREF(pValue); + Py_Finalize(); + + return cstring; } - void loadVersionChecked(const QString & filename) + void loadFromFile(const QString & filename) { _network.ResetConnectionReport(); @@ -332,6 +396,42 @@ _networkFile = filename; updateCaption(); } + void loadFromString(char *strNetwork, const QString & filename) + { + _network.ResetConnectionReport(); + + std::cout << "Loading " << qPrintable(filename) << "..." << std::endl; + std::istringstream istrNetwork(strNetwork); + try + { + CLAM::XMLStorage::Restore(_network, istrNetwork); + } + catch(CLAM::XmlStorageErr &e) + { + QMessageBox::critical(this, tr("Error loading the network"), + tr("

An occurred while loading the network file.

" + "

%1

").arg(e.what())); + clear(); + return; + } + _textDescriptionEdit->setText(QString::fromLocal8Bit(_network.GetDescription().c_str())); + + _playingLabel->setNetwork(&_network); + _canvas->loadNetwork(&_network); + _canvas->loadGeometriesFromXML(); + + CLAM::Network::ConnectionState connectionState = _network.GetConnectionReport(); + if (connectionState.first) + { + QMessageBox::warning(this, tr("Broken connections found"), + tr("

The following connections are broken.

" + "

%1

").arg(connectionState.second.c_str())); + } + + appendRecentFile(filename); + _networkFile = filename; + updateCaption(); + } void save(const QString & filename) { std::string localFilename = filename.toLocal8Bit().constData(); Index: SConstruct =================================================================== --- SConstruct (revision 14391) +++ SConstruct (working copy) @@ -42,6 +42,8 @@ CLAMInstallDir = env['clam_prefix'] clam_sconstoolspath = os.path.join(CLAMInstallDir,'share','clam','sconstools') +env.ParseConfig("python-config --cflags") +env.ParseConfig("python-config --libs") env.Tool('qt4', toolpath=[clam_sconstoolspath]) env.Tool('clam', toolpath=[clam_sconstoolspath]) env.Tool('nsis', toolpath=[clam_sconstoolspath]) @@ -56,7 +58,6 @@ print "Package version: ", fullVersion versionInfo.generateVersionSources(os.path.join('src','NetworkEditorVersion'), "NetworkEditor", version, fullVersion) - env['CXXFILESUFFIX'] = '.cxx' env['QT4_UICDECLSUFFIX'] = '.hxx' env.moveIntermediateInto('generated')