00001 #include <opie2/oresource.h>
00002
00003 #include "ircchannellist.h"
00004 #include "ircchannelperson.h"
00005
00006 IRCChannelList::IRCChannelList(IRCChannel *channel, QWidget *parent, const char *name, WFlags f) : QListBox(parent, name, f) {
00007 m_channel = channel;
00008 }
00009
00010 void IRCChannelList::update() {
00011 QPixmap op = Opie::Core::OResource::loadPixmap( "opieirc/op" );
00012 QPixmap hop = Opie::Core::OResource::loadPixmap( "opieirc/hop" );
00013 QPixmap voice = Opie::Core::OResource::loadPixmap( "opieirc/voice" );
00014 QListIterator<IRCChannelPerson> it = m_channel->people();
00015 clear();
00016 for (; it.current(); ++it) {
00017 IRCChannelPerson *person = it.current();
00018 if (person->flags() & IRCChannelPerson::PERSON_FLAG_OP) {
00019 insertItem(op, "1" + person->nick());
00020 } else if (person->flags() & IRCChannelPerson::PERSON_FLAG_HALFOP) {
00021 insertItem(op, "2" + person->nick());
00022 } else if (person->flags() & IRCChannelPerson::PERSON_FLAG_VOICE) {
00023 insertItem(voice, "3" + person->nick());
00024 } else {
00025 insertItem("4" + person->nick());
00026 }
00027 }
00028 sort();
00029 adjustNicks();
00030 }
00031
00032
00033 bool IRCChannelList::hasPerson(QString nick) {
00034 for (unsigned int i=0; i<count(); i++) {
00035 if (text(i) == nick)
00036 return TRUE;
00037 }
00038 return FALSE;
00039 }
00040
00041 bool IRCChannelList::removePerson(QString nick) {
00042 for (unsigned int i=0; i<count(); i++) {
00043 if (text(i) == nick){
00044 removeItem(i);
00045 return TRUE;
00046 }
00047 }
00048 return FALSE;
00049 }
00050
00051 void IRCChannelList::adjustNicks() {
00052 QString txt;
00053 QPixmap pm;
00054
00055 for(unsigned int i=0; i<count(); i++) {
00056 txt = text(i).remove(0,1);
00057 if(pixmap(i)) {
00058 pm = *pixmap(i);
00059 removeItem(i);
00060 insertItem(pm, txt, i);
00061 }
00062 else {
00063 removeItem(i);
00064 insertItem(txt, i);
00065 }
00066 }
00067 }