~ubuntu-branches/ubuntu/edgy/psi/edgy

« back to all changes in this revision

Viewing changes to libpsi/iconset/iconset.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2005-09-14 16:33:49 UTC
  • mfrom: (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050914163349-3zacov4afysz5cw5
Tags: 0.9.3-2ubuntu1
* Sync with debian
* Applied patch to psi.desktop to start psi without gpg-agent use (known
  issue)
* Updated README.Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include "iconset.h"
22
22
#include "zip.h"
23
23
 
 
24
#include <qobject.h>
24
25
#include <qfile.h>
25
26
#include <qfileinfo.h>
26
27
#include <qtimer.h>
576
577
}
577
578
 
578
579
//!
 
580
//! Returns the number of current animation frame.
 
581
//! \sa setAnim()
 
582
int Icon::framenumber() const
 
583
{
 
584
        if ( d->anim )
 
585
                return d->anim->framenumber();
 
586
 
 
587
        return 0;
 
588
}
 
589
 
 
590
//!
579
591
//! Returns name of the Icon.
580
592
//! \sa setName()
581
593
const QString &Icon::name() const
667
679
        if ( isAnim ) {
668
680
                Anim *anim = new Anim(ba);
669
681
                setAnim(*anim);
 
682
                ret = anim->numFrames();
670
683
                delete anim; // shared data rules ;)
671
 
                ret = true;
672
684
        }
673
685
 
674
686
        if ( !ret && d->impix.loadFromData(ba) )
760
772
{
761
773
private:
762
774
        static QPtrList<Iconset> *iconsets;
 
775
        static QPixmap *emptyPixmap;
763
776
 
764
777
public:
765
778
        static void registerIconset(const Iconset *);
773
786
//! \endif
774
787
 
775
788
QPtrList<Iconset> *IconsetFactoryPrivate::iconsets = 0;
 
789
QPixmap *IconsetFactoryPrivate::emptyPixmap = 0;
776
790
 
777
791
void IconsetFactoryPrivate::registerIconset(const Iconset *i)
778
792
{
790
804
        if ( iconsets && iconsets->find(i) >= 0 ) {
791
805
                //qWarning("IconsetFactoryPrivate::unregisterIconset(): %s", i->fileName().latin1());
792
806
                iconsets->remove ( i );
 
807
        }
793
808
 
794
 
                if ( !iconsets->count() ) {
 
809
        if ( !iconsets || !iconsets->count() ) {
 
810
                if ( iconsets ) {
795
811
                        delete iconsets;
796
812
                        iconsets = 0;
797
813
                }
 
814
 
 
815
                if ( emptyPixmap ) {
 
816
                        delete emptyPixmap;
 
817
                        emptyPixmap = 0;
 
818
                }
798
819
        }
799
820
}
800
821
 
840
861
}
841
862
 
842
863
//!
 
864
//! Returns QPixmap of first animation frame of the specified Icon, or the empty
 
865
//! QPixmap, if that Icon wasn't found in IconsetFactory.
 
866
//! This function is faster than the call to IconsetFactory::icon() and cast to QPixmap,
 
867
//! because the intermediate Icon object is not created and destroyed.
 
868
const QPixmap &IconsetFactory::iconPixmap(const QString &name)
 
869
{
 
870
        const Icon *i = iconPtr(name);
 
871
        if ( i )
 
872
                return i->impix().pixmap();
 
873
 
 
874
        if ( !IconsetFactoryPrivate::emptyPixmap )
 
875
                IconsetFactoryPrivate::emptyPixmap = new QPixmap();
 
876
        return *IconsetFactoryPrivate::emptyPixmap;
 
877
}
 
878
 
 
879
//!
843
880
//! Returns list of all Icon names that are in IconsetFactory.
844
881
const QStringList IconsetFactory::icons()
845
882
{
1010
1047
 
1011
1048
        static int icon_counter; // used to give unique names to icons
1012
1049
 
1013
 
        void loadIcon(const QDomElement &i, const QString &dir)
 
1050
        // will return 'true' when icon is loaded ok
 
1051
        bool loadIcon(const QDomElement &i, const QString &dir)
1014
1052
        {
1015
1053
                Icon icon;
1016
1054
 
1183
1221
 
1184
1222
                if ( loadSuccess )
1185
1223
                        append( name, new Icon(icon) );
 
1224
 
 
1225
                return loadSuccess;
1186
1226
        }
1187
1227
 
 
1228
        // would return 'true' on success
1188
1229
        bool load(const QDomDocument &doc, const QString dir)
1189
1230
        {
1190
1231
                QDomElement base = doc.documentElement();
1191
1232
                if ( base.tagName() != "icondef" )
1192
1233
                        return false;
1193
1234
 
 
1235
                bool success = true;
 
1236
 
1194
1237
                for(QDomNode node = base.firstChild(); !node.isNull(); node = node.nextSibling()) {
1195
1238
                        QDomElement i = node.toElement();
1196
1239
                        if( i.isNull() )
1201
1244
                                loadMeta (i, dir);
1202
1245
                        }
1203
1246
                        else if ( tag == "icon" ) {
1204
 
                                loadIcon (i, dir);
 
1247
                                bool ret = loadIcon (i, dir);
 
1248
                                if ( !ret )
 
1249
                                        success = false;
1205
1250
                        }
1206
1251
                        else if ( tag == "x" ) {
1207
1252
                                info.insert( i.attribute("xmlns"), new QString(i.text()) );
1208
1253
                        }
1209
1254
                }
1210
1255
 
1211
 
                return true;
 
1256
                return success;
1212
1257
        }
1213
1258
};
1214
1259
//! \endif