Author: dmacvicar Date: Thu Aug 2 18:31:11 2007 New Revision: 6407 URL: http://svn.opensuse.org/viewcvs/zypp?rev=6407&view=rev Log: play around reading a continous xml stream Modified: trunk/updater-kde/updater/zypp/ZYppUpdater.cpp trunk/updater-kde/updater/zypp/ZYppUpdater.h Modified: trunk/updater-kde/updater/zypp/ZYppUpdater.cpp URL: http://svn.opensuse.org/viewcvs/zypp/trunk/updater-kde/updater/zypp/ZYppUpdater.cpp?rev=6407&r1=6406&r2=6407&view=diff ============================================================================== --- trunk/updater-kde/updater/zypp/ZYppUpdater.cpp (original) +++ trunk/updater-kde/updater/zypp/ZYppUpdater.cpp Thu Aug 2 18:31:11 2007 @@ -69,7 +69,8 @@ kdDebug() << "Initializing zypp backend" << endl; _xml_reader.setContentHandler(this); - + resetXmlStream(); + //_xml_source.setData( "<stream>" ); } UpdaterCapabilities ZYppUpdater::capabilities() @@ -127,6 +128,15 @@ } +void ZYppUpdater::resetXmlStream() +{ + // remove if 2 programs are run at the same time + _xml_source.setData(QString()); + _last_xml_parse_code = true; + _xml_reader.parse( &_xml_source, + true /* incremental parsing*/); +} + void ZYppUpdater::slotInstSourceProcessExited( KProcess *p ) { delete p; @@ -232,19 +242,26 @@ void ZYppUpdater::slotReceivedStdout(KProcess *proc, char *buffer, int buflen) { + if ( buflen <= 0 ) + { + kdDebug() << "got empty buffer. Buffer stays at " << _xml_source.data().length() << endl; + return; + } kdDebug() << "got data... Xml buffer size (before): " << _xml_source.data().length() << endl; // refill the xml data _xml_source.setData( QString::fromUtf8(buffer, buflen) ); kdDebug() << "Xml buffer size (after): " << _xml_source.data().length() << endl; // continue incremental parsing - if ( buflen > 0 ) - _last_xml_parse_code = _xml_reader.parseContinue(); + + + _last_xml_parse_code = _xml_reader.parseContinue(); if ( !_last_xml_parse_code ) { kdDebug() << "Incremental parsing error. should we reset the Xml source? buffer size: " << _xml_source.data().length() << endl; - //_xml_source.reset() + kdDebug() << errorString() << endl; + resetXmlStream(); } } @@ -291,11 +308,8 @@ emit(updateApplet(APPLET_CHECKING, 0, 0)); return; } - // remove if 2 programs are run at the same time - _xml_source.setData(QString()); - _last_xml_parse_code = true; - _xml_reader.parse( &_xml_source, - true /* incremental parsing*/); + + resetXmlStream(); _process = new KProcess; *_process << "/usr/sbin/zypp-checkpatches-wrapper"; @@ -351,13 +365,16 @@ void ZYppUpdater::startInstall() { - if ( _process ) + if ( _process ) { // TODO update still running kdDebug() << "Process still running. Will not run this time." << endl; return; } + + resetXmlStream(); + if (!_patchList || !_packageList) { kdDebug() << "!_patchList || !_packageList!!! " << endl; @@ -510,19 +527,26 @@ // { // _found_update_status_tag = true; // } - if ( qName == "messages") - { - _state = Messages; - } if ( qName == "errors") { _state = Errors; } - if ( (qName == "message") && (_state == Messages ) ) + if ( (qName == "message") && (_state == Unknown ) ) { _state = Message; _message = true; } + if ( (qName == "progress")) + { + _state = Progress; + if ( atts.value("type") == "done" ) + emit showProgress(false); + else + { + emit showProgress(true); + emit setProgress( atts.value("value").toInt(), 100, atts.value("name")); + } + } if ( (qName == "error") && (_state == Errors ) ) { _state = Error; @@ -550,18 +574,21 @@ } if ( qName == "description" ) { - _state = UpdateDescription; + if ( _state == Update ) + _state = UpdateDescription; return true; } if ( qName == "summary" ) { - _state = UpdateSummary; + if ( _state == Update ) + _state = UpdateSummary; // ignore sources for now return true; } if ( qName == "license" ) { - _state = UpdateLicense; + if ( _state == Update ) + _state = UpdateLicense; return true; } if ( qName == "source" ) @@ -600,14 +627,16 @@ _error_buffer += "\n"; _state = Errors; } - if ( (qName == "message") && (_state == Messages) ) + if ( (qName == "message") && (_state == Message ) ) { _message_buffer += "\n"; - _state = Messages; + _state = Unknown; } - if ( (qName == "messages") ) + if ( ( qName == "progress" )) { _state = Unknown; + _xml_source.setData(QString()); + _last_xml_parse_code = true; } if ( (qName == "errors") ) { Modified: trunk/updater-kde/updater/zypp/ZYppUpdater.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/updater-kde/updater/zypp/ZYppUpdater.h?rev=6407&r1=6406&r2=6407&view=diff ============================================================================== --- trunk/updater-kde/updater/zypp/ZYppUpdater.h (original) +++ trunk/updater-kde/updater/zypp/ZYppUpdater.h Thu Aug 2 18:31:11 2007 @@ -67,8 +67,8 @@ UpdateLicense, Errors, Error, - Messages, Message, + Progress, } XmlState; class ZYppUpdater : public Updater, public QXmlDefaultHandler @@ -147,7 +147,7 @@ void slotInstallProcessExited( KProcess * ); void slotInstallReceivedStdout(KProcess *, char *, int ) ; - + void resetXmlStream(); private: -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org