summaryrefslogtreecommitdiff
path: root/noncore/net/opieirc/ircchannellist.cpp
blob: 3982f30ac99986f46d15f5fdc9d6dd4101a8702b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <opie2/oresource.h>

#include "ircchannellist.h"
#include "ircchannelperson.h"

IRCChannelList::IRCChannelList(IRCChannel *channel, QWidget *parent, const char *name, WFlags f) : QListBox(parent, name, f) {
    m_channel = channel;
}

void IRCChannelList::update() {
    QPixmap op = Opie::Core::OResource::loadPixmap( "opieirc/op" );
    QPixmap hop = Opie::Core::OResource::loadPixmap( "opieirc/hop" );
    QPixmap voice = Opie::Core::OResource::loadPixmap( "opieirc/voice" );
    QListIterator<IRCChannelPerson> it = m_channel->people();
    clear();
    for (; it.current(); ++it) {
        IRCChannelPerson *person = it.current();
        if (person->flags() & IRCChannelPerson::PERSON_FLAG_OP) {
            insertItem(op, "1" + person->nick());
        } else if (person->flags() & IRCChannelPerson::PERSON_FLAG_HALFOP) {
            insertItem(op, "2" + person->nick());
        } else if (person->flags() & IRCChannelPerson::PERSON_FLAG_VOICE) {
            insertItem(voice, "3" + person->nick());
        } else {
            insertItem("4" + person->nick());
        }
    }
    sort();
    adjustNicks();
}


bool IRCChannelList::hasPerson(QString nick) {
    for (unsigned int i=0; i<count(); i++) {
        if (text(i) == nick)
            return TRUE;
    }
    return FALSE;
}

bool IRCChannelList::removePerson(QString nick) {
    for (unsigned int i=0; i<count(); i++) {
        if (text(i) == nick){
            removeItem(i);
            return TRUE;
            }
    }
    return FALSE;
}

void IRCChannelList::adjustNicks() {
    QString txt;
    QPixmap pm;

    for(unsigned int i=0; i<count(); i++) {
        txt = text(i).remove(0,1);
        if(pixmap(i)) {
            pm = *pixmap(i);
            removeItem(i);
            insertItem(pm, txt, i);
        }
        else {
            removeItem(i);
            insertItem(txt, i);
        }
    }
}