Ejemplo n.º 1
0
void *FilterPlugin::processEvent(Event *e)
{
    if (e->type() == EventContactChanged){
        Contact *contact = (Contact*)(e->param());
        if (contact->getGroup()){
            Command cmd;
            cmd->id		= CmdIgnore;
            cmd->flags	= BTN_HIDE;
            cmd->param  = (void*)(contact->id());
            Event eShow(EventCommandShow, cmd);
            eShow.process();
        }
        return NULL;
    }
    if (e->type() == EventMessageReceived){
        Message *msg = (Message*)(e->param());
        if (!msg || (msg->type() == MessageStatus))
            return NULL;
        Contact *contact = getContacts()->contact(msg->contact());
        FilterUserData *data = NULL;
        // check if we accept only from users on the list
        if (
            ((contact == NULL) || contact->getFlags() & CONTACT_TEMPORARY) &&
	    (
	        (getFromList() && msg->type() != MessageAuthRequest && msg->type() != MessageAuthGranted && msg->type() != MessageAuthRefused)||
		( getAuthFromList() && msg->type() <= MessageContacts)
            )
	) {
            delete msg;
            delete contact;
            return msg;
        }
        if (!contact)
            return NULL;
        // check if the user is a ignored user
        if (contact->getIgnore()){
            delete msg;
            return msg;
        }

        // get filter-data
        data = (FilterUserData*)(contact->getUserData(user_data_id));
        if (data && data->SpamList.ptr && *data->SpamList.ptr){
            if (checkSpam(msg->getPlainText(), QString::fromUtf8(data->SpamList.ptr))){
                delete msg;
                return msg;
            }
        }
        return NULL;
    }
    if (e->type() == EventCheckState){
        CommandDef *cmd = (CommandDef*)(e->param());
        if (cmd->id == CmdIgnore){
            cmd->flags &= ~BTN_HIDE;
            Contact *contact = getContacts()->contact((unsigned long)(cmd->param));
            if (contact && contact->getGroup())
                cmd->flags |= BTN_HIDE;
            return e->param();
        }
        if (cmd->id == CmdIgnoreText){
            cmd->flags &= ~COMMAND_CHECKED;
            if (cmd->menu_id == MenuMsgView){
                MsgViewBase *edit = (MsgViewBase*)(cmd->param);
                if (edit->hasSelectedText())
                    return e->param();
            }else if (cmd->menu_id == MenuTextEdit){
                TextEdit *edit = ((MsgEdit*)(cmd->param))->m_edit;
                if (edit->hasSelectedText())
                    return e->param();
            }
            return NULL;
        }
        if (cmd->menu_id == MenuContactGroup){
            if (cmd->id == CmdIgnoreList){
                Contact *contact = getContacts()->contact((unsigned long)(cmd->param));
                if (contact == NULL)
                    return NULL;
                cmd->flags &= COMMAND_CHECKED;
                if (contact->getIgnore())
                    cmd->flags |= COMMAND_CHECKED;
                return e->param();
            }
        }
    }
    if (e->type() == EventCommandExec){
        CommandDef *cmd = (CommandDef*)(e->param());
        if (cmd->id == CmdIgnore){
            Contact *contact = getContacts()->contact((unsigned long)(cmd->param));
            if (contact){
                QString text = i18n("Add %1 to ignore list?") .arg(contact->getName());
                Command cmd;
                cmd->id		= CmdIgnore;
                cmd->param	= (void*)(contact->id());
                Event e(EventCommandWidget, cmd);
                QWidget *w = (QWidget*)(e.process());
                BalloonMsg::ask((void*)(contact->id()), text, w, SLOT(addToIgnore(void*)), NULL, NULL, this);
            }
            return e->param();
        }
Ejemplo n.º 2
0
void TreeTools<T>::getVectorTable_v2( TreeNode<T> *roo, TreeNode<T> *par, std::vector<std::string> &table, const char* (*eShow)(T), unsigned int level, int place, bool isLeft, \
                              int goTillLevel, DataShowMode dm, PointerShowMode pm, BranchShowMode bm )
{
    mout.setCanPrint(false);

    if(goTillLevel > 0 ? level >= goTillLevel : 0)
        return; //if level limit reach3d
    mout.setCanPrint(DebDef::Debug_TreeTools_getVectorTable);

    if(place < 0) place = 0;
    mout<<"\n[GetVectorTable()]: level= "<<level<<", place= "<<place<<", roo= "<<roo<<"\n";

    std::string thisLevel1, thisLevel2;
    std::string valueStr;

    if(roo) //data show modes, roo must exist
    {
        valueStr += "("; //begin getting valuestr
        if(dm != DataShowMode::None && dm != DataShowMode::Height) //value must be print'd
        {
            valueStr += ( eShow ? std::string( eShow(roo->getValue()) ) : Fun::toString(roo->getValue()) );
        }
        if(dm == DataShowMode::ValueNCounter || dm == DataShowMode::AllData) //counter
        {
            valueStr += "," + Fun::toString(roo->getCount());
        }
        if(dm == DataShowMode::AllData || dm == DataShowMode::Height || dm == DataShowMode::ValueNHeight) //height
        {
            valueStr += "," + Fun::toString(roo->getHeight());
        }
        valueStr += ")"; //end valuestr
    }
    else if(pm == NullOnly) //pointer show modes
    {
        valueStr += "(NULL)";
    }

    if(pm == PointerShowMode::AllPointers)
    {
        if(valueStr.size() > 0)
            valueStr += ":";
        valueStr += Fun::toString( roo ); //get address string
    }

    mout<<"Set thisLevel's\n";
    if(level*2 + 1 < table.size())
    {
        thisLevel1 = table[level*2];     //level with rodykles (\ and /)
        thisLevel2 = table[level*2 + 1]; //level with values
    }

    int curPlace = place - valueStr.size()/2;
    if(curPlace < 0) curPlace = 0;

    mout<<"Set curPlace, = "<<curPlace<<"\n";
    if( level > 0 && (pm != PointerShowMode::NoPointers ? 1 : (int)roo) ) // set rodykles
    {
        mout<<"Level>0, setting rodykl string\n";
        if(place >= thisLevel1.size())
        {
            thisLevel1 += (place - thisLevel1.size() > 0 ? std::string(place - thisLevel1.size(), char(32)) : std::string());
            thisLevel1 += (isLeft ? "/" : "\\");
        }
        else //thisLevel1.size() > place
        {
            //thisLevel1.insert( place, (isLeft ? "/" : "\\") );
            thisLevel1 += (isLeft ? "/" : "\\");
        }
    }

    mout<<"Setting value string\n";
    if(curPlace >= thisLevel2.size())
    {
        thisLevel2 += ( (curPlace - thisLevel2.size() > 0) ? std::string(curPlace - thisLevel2.size(), char(32)) : std::string() );
        thisLevel2 += valueStr;
    }
    else
    {
        //thisLevel2.insert( curPlace, valueStr );
        thisLevel2 += valueStr;
    }

    //thisLevel2 += "|- " + valueStr + " -";
    mout<<"Set table stuff\n";
    if(level*2 + 1 < table.size()) //it's here
    {
        table[level*2] = thisLevel1;
        table[level*2 + 1] = thisLevel2;
    }
    else //it's still not here
    {
        table.push_back( thisLevel1 );
        table.push_back( thisLevel2 );
    }

    if( !roo || roo == par)
    {
        mout.setCanPrint(true);
        return; //important! - if parent != current (roo)
    }

    mout<<"Startz0ring r3cursi0n: roo->leftChild= "<<roo->getLeftChild()<<", roo->rightChild= "<<roo->getRightChild()<<"\n";

    //TODO: Optimize new positions more.

    int spaces = (roo->getHeight() - level)*2;
    if(spaces < 0) spaces = 0;

    if(/*roo != roo->getLeftChild() &&*/ (level==0 ? (bm != RightOnStart) : 1) && bm != Right) //everything except when branchMode == right only
        getVectorTable_v2(roo->getLeftChild(), roo, table, eShow, level+1, curPlace - 1 - spaces, true, goTillLevel, dm, pm, bm );

    if(/*roo != roo->getRightChild() &&*/ (level==0 ? (bm != LeftOnStart) : 1) && bm != Left)
        getVectorTable_v2(roo->getRightChild(), roo, table, eShow, level+1, curPlace + valueStr.size() + spaces, false, goTillLevel, dm, pm, bm);

    mout.setCanPrint(true);
}