예제 #1
0
/**
 * Adds a participant to a convo, if that conversation dont exist, the tab and convo is created.
 * @brief MainWindow::addToConvo
 * @param fromIp ip of user that added someone to a conversation, empty if originating user is the current user.
 * @param fromName name of user that added someone to a conversation, empty if originating user is the current user.
 * @param member new participant to be added: "{name}/{ip}"
 * @param cid Conversation id.
 * @return false if member already exists in the conversation, true otherwise.
 */
bool MainWindow::addToConvo(QString fromIp, QString fromName, QString member, QString cid)
{
    Conversation* lst = 0;
    QStringList tmp = member.split("/", QString::SkipEmptyParts);
    int i = 0;
    for (; i < convos->count(); ++i)
    {
        if(convos->at(i)->getCid().compare(cid) == 0)
        {
            lst = convos->at(i);
            break;
        }
    }

    if(lst == 0)
    {
        createTab(cid, fromIp, fromName);
        lst = convos->at(convos->count()-1);
    }
    else
    {
        for (int i = 0; i < lst->count(); ++i)
        {
            if(tmp.at(1).compare(lst->at(i)->getIp()) == 0) return false;
        }
    }

    lst->add(tmp.at(1), tmp.at(0));

    if(ui->tabgrpConversations->currentIndex() == (i+1))
        ui->lstInConvo->addItem(member);

    return true;
}
예제 #2
0
/**
 * Creates a new tab, and initializes a new conversation with given ip and name.
 * @brief MainWindow::createTab
 * @param cid Conversation id.
 * @param ip IPv4 address
 * @param name Nickname
 */
void MainWindow::createTab(QString cid, QString ip, QString name)
{
    // Inflate tablelayout from file
        QFormBuilder builder;
        QFile file(FORM_TAB);
        file.open(QFile::ReadOnly);
        QWidget *tabLayout = builder.load(&file, this);
        file.close();

    // Add layout to a new tab
        QVBoxLayout *layout = new QVBoxLayout;
        layout->addWidget(tabLayout);
        QWidget *newTab = new QWidget(ui->tabgrpConversations);
        newTab->setLayout(layout);
        ui->tabgrpConversations->addTab(newTab, name + "/" + ip);

    //Add eventlisteners to new tab button, message text-box and smiley-list.
    QPushButton* btnSend = tabLayout->findChild<QPushButton*>("btnTabSend");
    connect(btnSend, SIGNAL(clicked()), this, SLOT(sendConvoMessage()));

    QTextEdit* txtMsg = tabLayout->findChild<QTextEdit*>(CONVO_TAB_MSG_ID);
    txtMsg->installEventFilter(this);

    QListWidget* lstSmil = tabLayout->findChild<QListWidget*>("lstTabSmileys");
    connect(lstSmil, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_lstSmileys_doubleClicked(QModelIndex)));
    for (int i = 0; i < smileys->count(); i++)
    {
        QListWidgetItem* qlwi = new QListWidgetItem(QIcon(RES_SMILEYS + QString::number(i) + ".png"), "");
        lstSmil->addItem(qlwi);
    }

    Conversation* c = new Conversation(cid);
    if(controller->isExternal(ip)) //External ip
    {
        c->add(ip, name, true);
    }
    else c->add(ip, name);

    convos->append(c);
}
예제 #3
0
/**
 * Called when user has been added to an existing conversation
 * between two or more participants. Creates a new tab, and
 * adds all participants to the corresponding conversation list.
 * @brief MainWindow::createExistingConvo
 * @param data "{convo_id}|{ip}|{name}|{ip}|{name}|..."
 */
void MainWindow::createExistingConvo(QString data)
{
    QStringList stuff = data.split('|', QString::SkipEmptyParts);

    createTab(stuff.at(0), stuff.at(1), stuff.at(2));
    indicateChange(convos->count());
    Conversation* newConvo = convos->at(convos->count()-1);

    for (int i = 3; i < stuff.count(); i++)
    {
        QString ip = stuff.at(i++); //Separated to avoid possibly undefined behavior.
        newConvo->add(ip, stuff.at(i));
    }
}