Exemplo n.º 1
0
void UserList::drawItem(UserViewItemBase *base, QPainter *p, const QColorGroup &cg, int width, int margin)
{
    if (base->type() == GRP_ITEM){
        GroupItem *item = static_cast<GroupItem*>(base);
        p->setFont(font());
        QString text;
        if (item->id()){
            Group *grp = getContacts()->group(item->id());
            if (grp){
                text = grp->getName();
            }else{
                text = "???";
            }
        }else{
            text = i18n("Not in list");
        }
        int x = drawIndicator(p, 2 + margin, item, isGroupSelected(item->id()), cg);
        if (!CorePlugin::m_plugin->getUseSysColors())
            p->setPen(CorePlugin::m_plugin->getColorGroup());
        x = item->drawText(p, x, width, text);
        item->drawSeparator(p, x, width, cg);
        return;
    }
    if (base->type() == USR_ITEM){
        ContactItem *item = static_cast<ContactItem*>(base);
        int x = drawIndicator(p, 2 + margin, item, isSelected(item->id()), cg);
        if (!item->isSelected() || !hasFocus() || !CorePlugin::m_plugin->getUseDblClick()){
            if (CorePlugin::m_plugin->getUseSysColors()){
                if (item->status() != STATUS_ONLINE)
                    p->setPen(palette().disabled().text());
            }else{
                switch (item->status()){
                case STATUS_ONLINE:
                    break;
                case STATUS_AWAY:
                    p->setPen(CorePlugin::m_plugin->getColorAway());
                    break;
                case STATUS_NA:
                    p->setPen(CorePlugin::m_plugin->getColorNA());
                    break;
                case STATUS_DND:
                    p->setPen(CorePlugin::m_plugin->getColorDND());
                    break;
                default:
                    p->setPen(CorePlugin::m_plugin->getColorOffline());
                    break;
                }
            }
        }
        x = item->drawText(p, x, width, item->text(CONTACT_TEXT));
        return;
    }
    UserListBase::drawItem(base, p, cg, width, margin);
}
Exemplo n.º 2
0
void UserList::contentsMouseReleaseEvent(QMouseEvent *e)
{
    QListViewItem *list_item = itemAt(contentsToViewport(e->pos()));
    if (list_item == NULL)
        return;
    switch (static_cast<UserViewItemBase*>(list_item)->type()){
    case USR_ITEM:{
            ContactItem *item = static_cast<ContactItem*>(list_item);
            if (isSelected(item->id())){
                for (list<unsigned>::iterator it = selected.begin(); it != selected.end(); ++it){
                    if ((*it) == item->id()){
                        selected.erase(it);
                        break;
                    }
                }
            }else{
                selected.push_back(item->id());
            }
            item->repaint();
            item->parent()->repaint();
            emit selectChanged();
            break;
        }
    case GRP_ITEM:{
            GroupItem *item = static_cast<GroupItem*>(list_item);
            if (isGroupSelected(item->id())){
                for (QListViewItem *i = item->firstChild(); i; i = i->nextSibling()){
                    ContactItem *ci = static_cast<ContactItem*>(i);
                    list<unsigned>::iterator it;
                    for (it = selected.begin(); it != selected.end(); ++it){
                        if ((*it) == ci->id()){
                            selected.erase(it);
                            break;
                        }
                    }
                    ci->repaint();
                }
            }else{
                for (QListViewItem *i = item->firstChild(); i; i = i->nextSibling()){
                    ContactItem *ci = static_cast<ContactItem*>(i);
                    list<unsigned>::iterator it;
                    for (it = selected.begin(); it != selected.end(); ++it)
                        if ((*it) == ci->id())
                            break;
                    if (it == selected.end()){
                        selected.push_back(ci->id());
                        ci->repaint();
                    }
                }
            }
            item->repaint();
            emit selectChanged();
            break;
        }
    }
    m_pressedItem = NULL;
}
Exemplo n.º 3
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;
}
bool CheckProto_1(
    const ContactItem& contactItem,
    const ClaimType indexed,
    const ContactSectionVersion parentVersion)
{
    if (indexed) {
        if (!contactItem.has_id()) {
            std::cerr << "Verify serialized contact item failed: missing id."
                      << std::endl;
            return false;
        }
        if (MIN_PLAUSIBLE_IDENTIFIER < contactItem.id().size()) {
            std::cerr << "Verify serialized contact item failed: invalid id."
                      << std::endl;
            return false;
        }
    } else {
        if (contactItem.has_id()) {
            std::cerr << "Verify serialized contact item failed: id not blank."
                      << std::endl;
            return false;
        }
    }

    if (!contactItem.has_type()) {
        std::cerr << "Verify serialized contact item failed: missing type." << std::endl;
        return false;
    }
    if (!ValidContactItemType(parentVersion, contactItem.type())) {
        std::cerr << "Verify serialized contact item failed: invalid type." << std::endl;
        return false;
    }
    if (!contactItem.has_value()) {
        std::cerr << "Verify serialized contact item failed: missing value." << std::endl;
        return false;
    }
    for (auto& it: contactItem.attribute()) {
        if (!ValidContactItemAttribute(contactItem.version(), static_cast<ContactItemAttribute>(it))) {
            std::cerr << "Verify serialized contact item failed: invalid attribute." << std::endl;
            return false;
        }
    }

    return true;
}