Ejemplo n.º 1
0
ContactItem *UserListBase::findContactItem(unsigned id, QListViewItem *p)
{
    for (QListViewItem *item = p ? p->firstChild() : firstChild(); item; item = item->nextSibling()){
        UserViewItemBase *i = static_cast<UserViewItemBase*>(item);
        if (i->type() == USR_ITEM){
            ContactItem *contactItem = static_cast<ContactItem*>(item);
            if (contactItem->id() == id)
                return contactItem;
        }
        if (item->isExpandable()){
            ContactItem *res = findContactItem(id, item);
            if (res)
                return res;
        }
    }
    return NULL;
}
Ejemplo n.º 2
0
void UserListBase::drawUpdates()
{
    m_bDirty = false;
    updTimer->stop();
    QListViewItem *item;
    list<unsigned long>::iterator it;
    for (it = updGroups.begin(); it != updGroups.end(); ++it){
        Group *group = getContacts()->group(*it);
        if (group == NULL)
            continue;
        switch (m_groupMode){
        case 1:
            item = findGroupItem(group->id());
            if (item){
                static_cast<GroupItem*>(item)->update(group);
                repaintItem(item);
            }else{
                new GroupItem(this, group, true);
            }
            break;
        case 2:
            for (item = firstChild(); item; item = item->nextSibling()){
                UserViewItemBase *i = static_cast<UserViewItemBase*>(item);
                if (i->type() != DIV_ITEM) continue;
                DivItem *divItem = static_cast<DivItem*>(i);
                GroupItem *grpItem = findGroupItem(group->id(), divItem);
                if (grpItem){
                    grpItem->update(group);
                    repaintItem(grpItem);
                }else{
                    new GroupItem(divItem, group, divItem->state() == DIV_OFFLINE);
                }
            }
            break;
        }
    }
    updGroups.clear();
    DivItem *itemOnline  = NULL;
    DivItem *itemOffline = NULL;
    if (updContacts.size()){
        if (m_groupMode != 1){
            for (item = firstChild(); item != NULL; item = item->nextSibling()){
                UserViewItemBase *i = static_cast<UserViewItemBase*>(item);
                if (i->type() != DIV_ITEM) continue;
                DivItem *divItem = static_cast<DivItem*>(i);
                if (divItem->state() == DIV_ONLINE)
                    itemOnline = divItem;
                if (divItem->state() == DIV_OFFLINE)
                    itemOffline = divItem;
            }
        }
    }
    for (it = updContacts.begin(); it != updContacts.end(); ++it){
        Contact *contact = getContacts()->contact(*it);
        if (contact == NULL)
            continue;
        ContactItem *contactItem;
        GroupItem *grpItem;
        unsigned style;
        string icons;
        unsigned status = getUserStatus(contact, style, icons);
        unsigned unread = getUnread(contact->id());
		bool bShow = false;
		ListUserData *data = (ListUserData*)(contact->getUserData(CorePlugin::m_plugin->list_data_id));
		if (data && data->ShowAllways)
			bShow = true;
        switch (m_groupMode){
        case 0:
            if (status == STATUS_OFFLINE){
                if (itemOnline){
                    contactItem = findContactItem(contact->id(), itemOnline);
                    if (contactItem){
                        deleteItem(contactItem);
                        if (itemOnline->firstChild() == NULL){
                            deleteItem(itemOnline);
                            itemOnline = NULL;
                        }
                    }
                }
                if ((unread == 0) && !bShow && m_bShowOnline){
                    if (itemOffline){
                        contactItem = findContactItem(contact->id(), itemOffline);
                        if (contactItem){
                            deleteItem(contactItem);
                            if (itemOffline->firstChild() == NULL){
                                deleteItem(itemOffline);
                                itemOffline = NULL;
                            }
                        }
                    }
                    break;
                }
                if (itemOffline == NULL){
                    itemOffline = new DivItem(this, DIV_OFFLINE);
                    setOpen(itemOffline, true);
                }
                contactItem = findContactItem(contact->id(), itemOffline);
                if (contactItem){
                    if (contactItem->update(contact, status, style, icons.c_str(), unread))
                        addSortItem(itemOffline);
                    repaintItem(contactItem);
                }else{
                    contactItem = new ContactItem(itemOffline, contact, status, style, icons.c_str(), unread);
                }
            }else{
                if (itemOffline){
                    contactItem = findContactItem(contact->id(), itemOffline);
                    if (contactItem){
                        deleteItem(contactItem);
                        if (itemOffline->firstChild() == NULL){
                            deleteItem(itemOffline);
                            itemOffline = NULL;
                        }
                    }
                }
                if (itemOnline == NULL){
                    itemOnline = new DivItem(this, DIV_ONLINE);
                    setOpen(itemOnline, true);
                }
                contactItem = findContactItem(contact->id(), itemOnline);
                if (contactItem){
                    if (contactItem->update(contact, status, style, icons.c_str(), unread))
                        addSortItem(itemOnline);
                    repaintItem(contactItem);
                }else{
                    contactItem = new ContactItem(itemOnline, contact, status, style, icons.c_str(), unread);
                }
            }
            break;
        case 1:
            contactItem = findContactItem(contact->id());
            grpItem = NULL;
            if (contactItem){
                grpItem = static_cast<GroupItem*>(contactItem->parent());
                if (((status == STATUS_OFFLINE) && (unread == 0) && !bShow && m_bShowOnline) ||
                        (contact->getGroup() != grpItem->id())){
                    grpItem->m_nContacts--;
                    if (contactItem->m_bOnline)
                        grpItem->m_nContactsOnline--;
                    addGroupForUpdate(grpItem->id());
                    deleteItem(contactItem);
                    contactItem = NULL;
                    grpItem = NULL;
                }
            }
            if ((status != STATUS_OFFLINE) || unread || bShow || !m_bShowOnline){
                if (grpItem == NULL)
                    grpItem = findGroupItem(contact->getGroup());
                if (grpItem){
                    if (contactItem){
                        if (contactItem->update(contact, status, style, icons.c_str(), unread))
                            addSortItem(grpItem);
                        repaintItem(contactItem);
                        if (!m_bShowOnline &&
                                (contactItem->m_bOnline != (status != STATUS_OFFLINE))){
                            if (status == STATUS_OFFLINE){
                                grpItem->m_nContactsOnline--;
                                contactItem->m_bOnline = false;
                            }else{
                                grpItem->m_nContactsOnline++;
                                contactItem->m_bOnline = true;
                            }
                            addGroupForUpdate(grpItem->id());
                        }
                    }else{
                        contactItem = new ContactItem(grpItem, contact, status, style, icons.c_str(), unread);
                        grpItem->m_nContacts++;
                        if (!m_bShowOnline && (status != STATUS_OFFLINE)){
                            grpItem->m_nContactsOnline++;
                            contactItem->m_bOnline = true;
                        }
                        addGroupForUpdate(grpItem->id());
                    }
                }
            }
            break;
        case 2:
            contactItem = findContactItem(contact->id(), itemOnline);
            grpItem = NULL;
            if (contactItem){
                grpItem = static_cast<GroupItem*>(contactItem->parent());
                if ((status == STATUS_OFFLINE) || (grpItem->id() != contact->getGroup())){
                    grpItem->m_nContacts--;
                    addGroupForUpdate(grpItem->id());
                    deleteItem(contactItem);
                    contactItem = NULL;
                }
            }
            if (itemOffline){
                contactItem = findContactItem(contact->id(), itemOffline);
                grpItem = NULL;
                if (contactItem){
                    grpItem = static_cast<GroupItem*>(contactItem->parent());
                    if ((status != STATUS_OFFLINE) || (grpItem->id() != contact->getGroup())){
                        grpItem->m_nContacts--;
                        addGroupForUpdate(grpItem->id());
                        deleteItem(contactItem);
                        contactItem = NULL;
                        if (m_bShowOnline && (grpItem->firstChild() == NULL)){
                            deleteItem(grpItem);
                            grpItem = NULL;
                            if (itemOffline->firstChild() == NULL){
                                deleteItem(itemOffline);
                                itemOffline = NULL;
                            }
                        }
                    }
                }
            }
            if ((unread == 0) && !bShow && (status == STATUS_OFFLINE) && m_bShowOnline)
                break;
            DivItem *divItem;
            if (status == STATUS_OFFLINE){
                if (itemOffline == NULL){
                    itemOffline = new DivItem(this, DIV_OFFLINE);
                    setOpen(itemOffline, true);
                }
                divItem = itemOffline;
            }else{
                divItem = itemOnline;
            }
            grpItem = findGroupItem(contact->getGroup(), divItem);
            if (grpItem == NULL){
                Group *grp = getContacts()->group(contact->getGroup());
                if (grp == NULL)
                    break;
                grpItem = new GroupItem(divItem, grp, true);
            }
            contactItem = findContactItem(contact->id(), grpItem);
            if (contactItem){
                if (contactItem->update(contact, status, style, icons.c_str(), unread))
                    addSortItem(grpItem);
            }else{
                new ContactItem(grpItem, contact, status, style, icons.c_str(), unread);
                grpItem->m_nContacts++;
                addGroupForUpdate(grpItem->id());
            }
        }
    }
    updContacts.clear();
    for (list<QListViewItem*>::iterator it_sort = sortItems.begin(); it_sort != sortItems.end(); ++it_sort){
        (*it_sort)->sort();
    }
    sortItems.clear();
}
Ejemplo n.º 3
0
void *UserListBase::processEvent(Event *e)
{
    if (e->type() == EventRepaintView)
        viewport()->repaint();
    if (m_bInit){
        switch (e->type()){
        case EventGroupCreated:{
                Group *g = (Group*)(e->param());
                addGroupForUpdate(g->id());
                break;
            }
        case EventGroupChanged:{
                Group *g = (Group*)(e->param());
                addGroupForUpdate(g->id());
                break;
            }
        case EventGroupDeleted:{
                Group *g = (Group*)(e->param());
                for (list<unsigned long>::iterator it = updGroups.begin(); it != updGroups.end(); ++it){
                    if (*it == g->id()){
                        updGroups.erase(it);
                        break;
                    }
                }
                QListViewItem *item = findGroupItem(g->id());
                deleteItem(item);
                break;
            }
        case EventContactCreated:{
                Contact *c = (Contact*)(e->param());
                if (!c->getIgnore() && (c->getTemporary() == 0))
                    addContactForUpdate(c->id());
                break;
            }
        case EventContactStatus:
        case EventContactChanged:{
                Contact *c = (Contact*)(e->param());
                if (!c->getIgnore() && (c->getTemporary() == 0)){
                    addContactForUpdate(c->id());
                }else{
                    Event e(EventContactDeleted, c);
                    processEvent(&e);
                }
                break;
            }
        case EventMessageReceived:{
                Message *msg = (Message*)(e->param());
                if (msg->type() == MessageStatus){
                    Contact *contact = getContacts()->contact(msg->contact());
                    if (contact)
                        addContactForUpdate(contact->id());
                }
                break;
            }
        case EventContactDeleted:{
                Contact *g = (Contact*)(e->param());
                for (list<unsigned long>::iterator it = updContacts.begin(); it != updContacts.end(); ++it){
                    if (*it == g->id()){
                        updContacts.erase(it);
                        break;
                    }
                }
                ContactItem *item = findContactItem(g->id());
                if (item){
                    if (m_groupMode){
                        GroupItem *grpItem = static_cast<GroupItem*>(item->parent());
                        grpItem->m_nContacts--;
                        if (item->m_bOnline)
                            grpItem->m_nContactsOnline--;
                        addGroupForUpdate(grpItem->id());
                        deleteItem(item);
                        if ((m_groupMode == 2) &&
                                (grpItem->firstChild() == NULL) &&
                                m_bShowOnline){
                            DivItem *div = static_cast<DivItem*>(grpItem->parent());
                            if (div->state() == DIV_OFFLINE){
                                deleteItem(grpItem);
                                if (div->firstChild() == NULL)
                                    deleteItem(div);
                            }
                        }
                    }else{
                        QListViewItem *p = item->parent();
                        deleteItem(item);
                        if (p->firstChild() == NULL)
                            deleteItem(p);
                    }
                }
                break;
            }
        }
    }
    return ListView::processEvent(e);
}
Ejemplo n.º 4
0
void *UserView::processEvent(Event *e)
{
    switch (e->type()){
    case EventInit:
        m_bInit = true;
        fill();
        break;
    case EventContactOnline:
        if (m_bInit){
            Contact *contact = (Contact*)(e->param());
            bool bStart = blinks.empty();
            list<BlinkCount>::iterator it;
            for (it = blinks.begin(); it != blinks.end(); ++it){
                if ((*it).id == contact->id())
                    break;
            }
            if (it != blinks.end()){
                (*it).count = BLINK_COUNT;
                return NULL;
            }
            BlinkCount bc;
            bc.id = contact->id();
            bc.count = BLINK_COUNT;
            blinks.push_back(bc);
            if (bStart)
                blinkTimer->start(BLINK_TIMEOUT);
            return NULL;
        }
        break;
    case EventMessageDeleted:
    case EventMessageRead:
    case EventMessageReceived:{
            Message *msg = (Message*)(e->param());
            addContactForUpdate(msg->contact());
            break;
        }
    case EventCommandExec:{
            CommandDef *cmd = (CommandDef*)(e->param());
            if (cmd->menu_id == MenuContact){
                Contact *contact = getContacts()->contact((unsigned)(cmd->param));
                if (contact){
                    if (cmd->id == CmdContactDelete){
                        QListViewItem *item = findContactItem(contact->id());
                        if (item){
                            ensureItemVisible(item);
                            QRect rc = itemRect(item);
                            QPoint p = viewport()->mapToGlobal(rc.topLeft());
                            rc = QRect(p.x(), p.y(), rc.width(), rc.height());
                            BalloonMsg::ask((void*)contact->id(),
                                            i18n("Delete \"%1\"?") .arg(contact->getName()),
                                            this, SLOT(deleteContact(void*)), NULL, &rc);
                        }
                        return e->param();
                    }
                    if (cmd->id == CmdContactRename){
                        QListViewItem *item = findContactItem(contact->id());
                        if (item){
                            setCurrentItem(item);
                            renameContact();
                        }
                        return e->param();
                    }
                    if (cmd->id == CmdShowAlways){
                        ListUserData *data = (ListUserData*)(contact->getUserData(CorePlugin::m_plugin->list_data_id, true));
                        if (data){
                            bool bShow = false;
                            if (cmd->flags & COMMAND_CHECKED)
                                bShow = true;
                            if ((data->ShowAlways != 0) != bShow){
                                data->ShowAlways = bShow;
                                Event e(EventContactChanged, contact);
                                e.process();
                            }
                        }
                        return e->param();
                    }
                    if (cmd->id == CmdClose){
                        UserWnd *wnd = NULL;
                        QWidgetList  *list = QApplication::topLevelWidgets();
                        QWidgetListIt it(*list);
                        QWidget * w;
                        while ((w = it.current()) != NULL){
                            if (w->inherits("Container")){
                                Container *c =  static_cast<Container*>(w);
                                wnd = c->wnd((unsigned)(cmd->param));
                                if (wnd)
                                    break;
                            }
                            ++it;
                        }
                        delete list;
                        if (wnd){
                            delete wnd;
                            return e->param();
                        }
                    }
                    if (cmd->id > CmdSendMessage){
                        Command c;
                        c->id	   = cmd->id - CmdSendMessage;
                        c->menu_id = MenuMessage;
                        c->param   = (void*)(contact->id());
                        Event eCmd(EventCommandExec, c);
                        if (eCmd.process())
                            return e->param();
                    }
                }
            }
            if (cmd->menu_id == MenuContactGroup){
                Contact *contact = getContacts()->contact((unsigned)(cmd->param));
                if (contact){
                    Group *grp = getContacts()->group(cmd->id - CmdContactGroup);
                    if (grp && (grp->id() != contact->getGroup())){
                        contact->setGroup(grp->id());
                        Event eChanged(EventContactChanged, contact);
                        eChanged.process();
                        return e->param();
                    }
                }
            }
            if (cmd->menu_id == MenuContainer){
                Contact *contact = getContacts()->contact((unsigned)(cmd->param));
                if (contact){
                    Container *from = NULL;
                    Container *to = NULL;
                    QWidgetList  *list = QApplication::topLevelWidgets();
                    QWidgetListIt it(*list);
                    QWidget * w;
                    unsigned max_id = 0;
                    while ((w = it.current()) != NULL){
                        if (w->inherits("Container")){
                            Container *c = static_cast<Container*>(w);
                            if (c->getId() == cmd->id)
                                to = c;
                            if (c->wnd(contact->id()))
                                from = c;
                            if (!(c->getId() & CONTAINER_GRP)){
                                if (max_id < c->getId())
                                    max_id = c->getId();
                            }
                        }
                        ++it;
                    }
                    if (from && to && (from == to))
                        return e->param();
                    UserWnd *userWnd = NULL;
                    if (from){
                        userWnd = from->wnd(contact->id());
                        from->removeUserWnd(userWnd);
                    }
                    if (userWnd == NULL)
                        userWnd = new UserWnd(contact->id(), NULL, true);
                    if (to == NULL)
                        to = new Container(max_id + 1);
                    to->addUserWnd(userWnd);
                    to->setNoSwitch();
                    raiseWindow(to);
                }
                return e->param();
            }
            if (cmd->id == CmdOnline){
                CorePlugin::m_plugin->setShowOnLine((cmd->flags & COMMAND_CHECKED) != 0);
                m_bShowOnline = (cmd->flags & COMMAND_CHECKED);
                if (cmd->menu_id){
                    CommandDef c = *cmd;
                    c.bar_id	= ToolBarMain;
                    c.bar_grp   = 0x4000;
                    Event eCmd(EventCommandChange, &c);
                    eCmd.process();
                }
                fill();
            }
            if (cmd->id == CmdGrpOff)
                setGroupMode(0);
            if (cmd->id == CmdGrpMode1)
                setGroupMode(1);
            if (cmd->id == CmdGrpMode2)
                setGroupMode(2);
            if (cmd->id == CmdGrpCreate){
                if (CorePlugin::m_plugin->getGroupMode()){
                    Group *g = getContacts()->group(0, true);
                    drawUpdates();
                    QListViewItem *item = findGroupItem(g->id());
                    if (item){
                        setCurrentItem(item);
                        QTimer::singleShot(0, this, SLOT(renameGroup()));
                    }
                }
                return e->param();
            }
            if (cmd->id == CmdGrpRename){
                QListViewItem *item = findGroupItem((unsigned)(cmd->param));
                if (item){
                    setCurrentItem(item);
                    renameGroup();
                }
                return e->param();
            }
            if (cmd->id == CmdGrpUp){
                unsigned grp_id = (unsigned)(cmd->param);
                getContacts()->moveGroup(grp_id, true);
                QListViewItem *item = findGroupItem(grp_id);
                if (item){
                    ensureItemVisible(item);
                    setCurrentItem(item);
                }
                return e->param();
            }
            if (cmd->id == CmdGrpDown){
                unsigned grp_id = (unsigned)(cmd->param);
                getContacts()->moveGroup(grp_id, false);
                QListViewItem *item = findGroupItem(grp_id);
                if (item){
                    ensureItemVisible(item);
                    setCurrentItem(item);
                }
                return e->param();
            }
            if (cmd->id == CmdGrpDelete){
                unsigned grp_id = (unsigned)(cmd->param);
                QListViewItem *item = findGroupItem(grp_id);
                Group *g = getContacts()->group(grp_id);
                if (item && g){
                    ensureItemVisible(item);
                    QRect rc = itemRect(item);
                    QPoint p = viewport()->mapToGlobal(rc.topLeft());
                    rc = QRect(p.x(), p.y(), rc.width(), rc.height());
                    BalloonMsg::ask((void*)grp_id,
                                    i18n("Delete \"%1\"?") .arg(g->getName()),
                                    this, SLOT(deleteGroup(void*)), NULL, &rc);
                }