bool PropertyParser::startElement( const QString & /* namespaceUrl */, const QString & /* localName */, const QString& elementName, const QXmlAttributes& attribute ) { // If debugging, print each element and its attributes as encountered. m_indent += " "; if ( m_debug ) { std::cout << m_indent << "<" << elementName; for ( int id = 0; id < attribute.length(); id++ ) { std::cout << " " << attribute.localName(id) << "=\"" << attribute.value(id) << "\""; } std::cout << " >" << std::endl; } // Skip all elements until <BehavePlus> is found. if ( ! m_elements ) { if ( elementName == "BehavePlus" ) { push( elementName ); return( true ); } trError( "PropertyParser:unknownDocument" ); return( false ); } // <property> elements if ( elementName == "property" ) { push( elementName ); if ( ! handleProperty( elementName, attribute ) ) { return( false ); } } // Ignore all other tags else { trError( "PropertyParser:unknownElement", elementName ); return( false ); } return( true ); }
bool PropertyParser::handleProperty( const QString &elementName, const QXmlAttributes& attribute ) { int id; QString name, value; // "name" attribute is required if ( ( id = attribute.index( "name" ) ) < 0 ) { trError( "PropertyParser:missingName", elementName, "name" ); return( false ); } name = attribute.value( id ); // "value" attribute is required if ( ( id = attribute.index( "value" ) ) < 0 ) { trError( "PropertyParser:missingAttribute", elementName, name, "value" ); return( false ); } if ( ( value = attribute.value( id ) ) == "(null)" ) { value = ""; } // Find this property in the local Property directory and update it Property *property; if ( ( property = m_propDict->find( name ) ) > 0 ) { if ( ! m_propDict->update( name, value ) ) { trError( "PropertyParser:badValue", elementName, name, "value", value ); return( false ); } } // Report unknown <property> names here. else { trError( "PropertyParser:badValue", elementName, name, "name", name ); return( false ); } return( true ); }
/// A file transfer request was received. void QxmppPeer::trFileReceived( QXmppTransferJob * job ) { if ( !m_logHandler.empty() ) { std::ostringstream out; out << "Got transfer request from: "; out << job->jid().toStdString(); m_logHandler( out.str() ); } if ( m_inFileHandler.empty() ) { job->abort(); return; } std::string fileName = job->fileInfo().name().toStdString(); QIODevice * device = m_inFileHandler( fileName ); if ( !device ) return; job->accept( device ); bool check; Q_UNUSED(check); check = connect( job, SIGNAL( error(QXmppTransferJob::Error) ), this, SLOT( trError(QXmppTransferJob::Error) ) ); Q_ASSERT(check); check = connect(job, SIGNAL( finished() ), this, SLOT( trFinished()) ); Q_ASSERT(check); check = connect( job, SIGNAL( progress(qint64,qint64) ), this, SLOT( trProgress(qint64,qint64) ) ); Q_ASSERT(check); m_hash[ job ] = device; }
void QxmppPeer::slotSendFile( const QString & jid, const QString & fileName, QIODevice * dev ) { if ( !dev->isOpen() ) { bool res = dev->open( QIODevice::ReadOnly ); if ( !res ) { if ( !m_logHandler.empty() ) { std::ostringstream out; out << "Error: failed to open QIODevice for reading"; m_logHandler( out.str() ); } } } QXmppTransferFileInfo info; info.setName( fileName ); info.setSize( dev->size() ); QXmppTransferJob * job = m_trManager->sendFile( jid, dev, info ); bool check; check = connect(job, SIGNAL( error(QXmppTransferJob::Error) ), this, SLOT( trError(QXmppTransferJob::Error) ) ); Q_ASSERT(check); check = connect(job, SIGNAL( finished() ), this, SLOT( trFinished() ) ); Q_ASSERT(check); check = connect(job, SIGNAL( progress(qint64,qint64) ), this, SLOT( trProgress(qint64,qint64) ) ); Q_ASSERT( check ); Q_UNUSED( check ); m_hash[ job ] = dev; }