~ubuntu-branches/ubuntu/jaunty/psi/jaunty

« back to all changes in this revision

Viewing changes to iris/xmpp-im/xmpp_vcard.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-04-14 18:57:30 UTC
  • mfrom: (2.1.9 hardy)
  • Revision ID: james.westby@ubuntu.com-20080414185730-528re3zp0m2hdlhi
Tags: 0.11-8
* added CONFIG -= link_prl to .pro files and removed dependencies
  which are made unnecessary by this change
* Fix segfault when closing last chat tab with qt4.4
  (This is from upstream svn, rev. 1101) (Closes: Bug#476122)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include "xmpp_vcard.h"
22
22
 
23
 
#include "base64.h"
24
 
 
25
23
#include <qdom.h>
26
24
#include <qdatetime.h>
27
25
 
28
26
#include <qimage.h> // needed for image format recognition
29
27
#include <qbuffer.h>
 
28
#include <QImageReader>
 
29
#include <QImageWriter>
 
30
#include <QtCrypto>
30
31
 
31
32
// Justin's XML helper functions
32
33
 
89
90
//----------------------------------------------------------------------------
90
91
// VCard
91
92
//----------------------------------------------------------------------------
92
 
static QString image2type(const QByteArray &ba)
 
93
QString image2type(const QByteArray &ba)
93
94
{
94
 
        QBuffer buf(ba);
95
 
        buf.open(IO_ReadOnly);
96
 
        QString format = QImageIO::imageFormat( &buf );
 
95
        QBuffer buf;
 
96
        buf.setData(ba);
 
97
        buf.open(QIODevice::ReadOnly);
 
98
        QString format = QImageReader::imageFormat( &buf );
97
99
 
98
100
        // TODO: add more formats
99
 
        if ( format == "PNG" || format == "PsiPNG" )
 
101
        if ( format.toUpper() == "PNG" || format == "PsiPNG" )
100
102
                return "image/png";
101
 
        if ( format == "MNG" )
 
103
        if ( format.toUpper() == "MNG" )
102
104
                return "video/x-mng";
103
 
        if ( format == "GIF" )
 
105
        if ( format.toUpper() == "GIF" )
104
106
                return "image/gif";
105
 
        if ( format == "BMP" )
 
107
        if ( format.toUpper() == "BMP" )
106
108
                return "image/bmp";
107
 
        if ( format == "XPM" )
 
109
        if ( format.toUpper() == "XPM" )
108
110
                return "image/x-xpm";
109
 
        if ( format == "SVG" )
 
111
        if ( format.toUpper() == "SVG" )
110
112
                return "image/svg+xml";
111
 
        if ( format == "JPEG" )
 
113
        if ( format.toUpper() == "JPEG" )
112
114
                return "image/jpeg";
113
115
 
114
 
        qWarning("WARNING! VCard::image2type: unknown format = '%s'", format.latin1());
 
116
        qWarning(QString("WARNING! VCard::image2type: unknown format = '%1'").arg(format.isNull() ? QString("UNKNOWN") : format).toAscii());
115
117
 
116
118
        return "image/unknown";
117
119
}
301
303
 
302
304
                if ( !d->photo.isEmpty() ) {
303
305
                        w.appendChild( textTag(doc, "TYPE",     image2type(d->photo)) );
304
 
                        w.appendChild( textTag(doc, "BINVAL",   foldString( Base64::arrayToString(d->photo)) ) );
 
306
                        w.appendChild( textTag(doc, "BINVAL",   foldString( QCA::Base64().arrayToString(d->photo)) ) );
305
307
                }
306
308
                else if ( !d->photoURI.isEmpty() )
307
309
                        w.appendChild( textTag(doc, "EXTVAL",   d->photoURI) );
473
475
 
474
476
                if ( !d->logo.isEmpty() ) {
475
477
                        w.appendChild( textTag(doc, "TYPE",     image2type(d->logo)) );
476
 
                        w.appendChild( textTag(doc, "BINVAL",   foldString( Base64::arrayToString(d->logo)) ) );
 
478
                        w.appendChild( textTag(doc, "BINVAL",   foldString( QCA::Base64().arrayToString(d->logo)) ) );
477
479
                }
478
480
                else if ( !d->logoURI.isEmpty() )
479
481
                        w.appendChild( textTag(doc, "EXTVAL",   d->logoURI) );
530
532
                QDomElement w = doc->createElement("SOUND");
531
533
 
532
534
                if ( !d->sound.isEmpty() )
533
 
                        w.appendChild( textTag(doc, "BINVAL",   foldString( Base64::arrayToString(d->sound)) ) );
 
535
                        w.appendChild( textTag(doc, "BINVAL",   foldString( QCA::Base64().arrayToString(d->sound)) ) );
534
536
                else if ( !d->soundURI.isEmpty() )
535
537
                        w.appendChild( textTag(doc, "EXTVAL",   d->soundURI) );
536
538
                else if ( !d->soundPhonetic.isEmpty() )
602
604
                else if ( tag == "NICKNAME" )
603
605
                        d->nickName = i.text().stripWhiteSpace();
604
606
                else if ( tag == "PHOTO" ) {
605
 
                        d->photo = Base64::stringToArray( subTagText(i, "BINVAL") );
 
607
                        d->photo = QCA::Base64().stringToArray(subTagText(i, "BINVAL").replace("\n","")).toByteArray();
606
608
                        d->photoURI = subTagText(i, "EXTVAL");
607
609
                }
608
610
                else if ( tag == "BDAY" )
715
717
                else if ( tag == "ROLE" )
716
718
                        d->role = i.text().stripWhiteSpace();
717
719
                else if ( tag == "LOGO" ) {
718
 
                        d->logo = Base64::stringToArray( subTagText(i, "BINVAL") );
 
720
                        d->logo = QCA::Base64().stringToArray( subTagText(i, "BINVAL").replace("\n","") ).toByteArray();
719
721
                        d->logoURI = subTagText(i, "EXTVAL");
720
722
                }
721
723
                else if ( tag == "AGENT" ) {
764
766
                else if ( tag == "SORT-STRING" )
765
767
                        d->sortString = i.text().stripWhiteSpace();
766
768
                else if ( tag == "SOUND" ) {
767
 
                        d->sound = Base64::stringToArray( subTagText(i, "BINVAL") );
 
769
                        d->sound = QCA::Base64().stringToArray( subTagText(i, "BINVAL").replace("\n","") ).toByteArray();
768
770
                        d->soundURI      = subTagText(i, "EXTVAL");
769
771
                        d->soundPhonetic = subTagText(i, "PHONETIC");
770
772
                }