QVariant OnlineUsersModel::data(const QModelIndex& index, int role) const
{
    user_cache_t::const_iterator ii = m_users.find(index.internalId());
    Q_ASSERT(ii != m_users.end());
    if(ii == m_users.end())
        return QVariant();

    const User& user = ii.value();
    TTCHAR channel[TT_STRLEN] = {0};

    switch(role)
    {
    case Qt::DisplayRole :
        switch(index.column())
        {
        case COLUMN_USERID :
            return user.nUserID;
        case COLUMN_NICKNAME :
            return _Q(user.szNickname);
        case COLUMN_STATUSMSG :
            return _Q(user.szStatusMsg);
        case COLUMN_USERNAME :
            return _Q(user.szUsername);
        case COLUMN_CHANNEL :
            TT_GetChannelPath(ttInst, user.nChannelID, channel);
            return _Q(channel);
        case COLUMN_IPADDRESS :
            return _Q(user.szIPAddress);
        case COLUMN_VERSION :
            return getVersion(user);
        }
        break;
    }
    return QVariant();
}
BOOL COnlineUsersDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    TRANSLATE(*this, IDD);

    //load accelerators
    m_hAccel = ::LoadAccelerators(AfxGetResourceHandle(), (LPCTSTR)IDR_ACCELERATOR3);
    if (!m_hAccel)
        MessageBox(_T("The accelerator table was not loaded"));

    m_wndUsers.SetExtendedStyle(m_wndUsers.GetExtendedStyle() | LVS_EX_FULLROWSELECT);

    m_wndUsers.InsertColumn(COLUMN_USERID, _T("ID"));
    m_wndUsers.SetColumnWidth(COLUMN_USERID, 45);
    m_wndUsers.InsertColumn(COLUMN_NICKNAME, _T("Nickname"));
    m_wndUsers.SetColumnWidth(COLUMN_NICKNAME, 100);
    m_wndUsers.InsertColumn(COLUMN_STATUSMSG, _T("Status message"));
    m_wndUsers.SetColumnWidth(COLUMN_STATUSMSG, 100);
    m_wndUsers.InsertColumn(COLUMN_USERNAME, _T("Username"));
    m_wndUsers.SetColumnWidth(COLUMN_USERNAME, 65);
    m_wndUsers.InsertColumn(COLUMN_CHANNEL, _T("Channel"));
    m_wndUsers.SetColumnWidth(COLUMN_CHANNEL, 100);
    m_wndUsers.InsertColumn(COLUMN_IPADDRESS, _T("IP-address"));
    m_wndUsers.SetColumnWidth(COLUMN_IPADDRESS, 100);
    m_wndUsers.InsertColumn(COLUMN_VERSION_, _T("Version"));
    m_wndUsers.SetColumnWidth(COLUMN_VERSION_, 100);

    int nUsers = 0;
    TT_GetServerUsers(ttInst, NULL, &nUsers);

    std::vector<User> users;
    if(nUsers)
    {
        users.resize(nUsers);
        TT_GetServerUsers(ttInst, &users[0], &nUsers);
        for(size_t i=0;i<nUsers;i++)
        {
            CString s;
            s.Format(_T("%d"), users[i].nUserID);
            int iIndex = m_wndUsers.InsertItem(i, s, 0);
            m_wndUsers.SetItemText(iIndex, COLUMN_NICKNAME, users[i].szNickname);
            m_wndUsers.SetItemText(iIndex, COLUMN_STATUSMSG, users[i].szStatusMsg);
            m_wndUsers.SetItemText(iIndex, COLUMN_USERNAME, users[i].szUsername);
            TTCHAR szChannel[TT_STRLEN] = _T("");
            TT_GetChannelPath(ttInst, users[i].nChannelID, szChannel);
            m_wndUsers.SetItemText(iIndex, COLUMN_CHANNEL, szChannel);
            m_wndUsers.SetItemText(iIndex, COLUMN_IPADDRESS, users[i].szIPAddress);
            m_wndUsers.SetItemText(iIndex, COLUMN_VERSION_, GetVersion(users[i]));
            m_wndUsers.SetItemData(iIndex, users[i].nUserID);
        }
    }

    return TRUE;  // return TRUE unless you set the focus to a control
    // EXCEPTION: OCX Property Pages should return FALSE
}
Exemple #3
0
void ChatTextEdit::joinedChannel(int channelid)
{
    TTCHAR buff[TT_STRLEN];
    Channel chan;
    if(!TT_GetChannel(ttInst, channelid, &chan))
        return;
    if(!TT_GetChannelPath(ttInst, channelid, buff))
        return;

    appendPlainText("");

    QString dt = getTimeStamp();
    
    QTextCharFormat format = textCursor().charFormat();
    QTextCharFormat original = format;
    QTextCursor cursor = textCursor();
    
    //show 'joined new channel' in bold
    QFont font = format.font();
    font.setBold(true);
    format.setFont(font);
    cursor.setCharFormat(format);
    QString line = dt + tr("Joined new channel");
    setTextCursor(cursor);
    appendPlainText(line);
    //revert bold
    font.setBold(false);
    format.setFont(font);
    
    //show channel name in green
    line = tr("Channel: %1").arg(_Q(buff));
    format.setForeground(QBrush(Qt::darkGreen));
    cursor.setCharFormat(format);
    setTextCursor(cursor);
    appendPlainText(line);

    //show topic in blue
    line = tr("Topic: %1").arg(_Q(chan.szTopic));
    format.setForeground(QBrush(Qt::darkBlue));
    cursor.setCharFormat(format);
    setTextCursor(cursor);
    appendPlainText(line);

    //show disk quota in red
    line = tr("Disk quota: %1 KBytes").arg(chan.nDiskQuota/1024);
    format.setForeground(QBrush(Qt::darkRed));
    cursor.setCharFormat(format);
    setTextCursor(cursor);
    appendPlainText(line);

    //revert to original
    cursor.setCharFormat(original);
    setTextCursor(cursor);
    limitText();
}
Exemple #4
0
QString ChatTextEdit::addTextMessage(const TextMessage& msg)
{
    User user;
    if(!TT_GetUser(ttInst, msg.nFromUserID, &user))
        return QString();

    QString dt = getTimeStamp();
    QString line = dt;

    switch(msg.nMsgType)
    {
    case MSGTYPE_USER :
        line += QString("<%1> %2").arg(getDisplayName(user)).arg(_Q(msg.szMessage));
        break;
    case MSGTYPE_CHANNEL :
        if(msg.nChannelID != TT_GetMyChannelID(ttInst))
        {
            TTCHAR chpath[TT_STRLEN] = {};
            TT_GetChannelPath(ttInst, msg.nChannelID, chpath);
            line += QString("<%1->%2> %3").arg(getDisplayName(user))
                           .arg(_Q(chpath)).arg(_Q(msg.szMessage));
        }
        else
            line += QString("<%1> %2").arg(getDisplayName(user))
                           .arg(_Q(msg.szMessage));
        break;
    case MSGTYPE_BROADCAST :
        line += QString("<%1->BROADCAST> %2").arg(getDisplayName(user))
                       .arg(_Q(msg.szMessage));
        break;
    case MSGTYPE_CUSTOM : break;
    }

    if(TT_GetMyUserID(ttInst) == msg.nFromUserID)
    {
        QTextCharFormat format = textCursor().charFormat();
        QTextCharFormat original = format;
        format.setForeground(QBrush(Qt::darkGray));
        QTextCursor cursor = textCursor();
        cursor.setCharFormat(format);
        setTextCursor(cursor);
        appendPlainText(line);
        cursor.setCharFormat(original);
        setTextCursor(cursor);
    }
    else
        appendPlainText(line);
    limitText();

    return line;
}
Exemple #5
0
void FileTransferDlg::updateFileTransfer(const FileTransfer& transfer)
{
    if(m_localfilename.isEmpty())
        m_localfilename = _Q(transfer.szLocalFilePath);

    setWindowTitle(_Q(transfer.szRemoteFileName));
    ui.filenameLabel->setText(_Q(transfer.szRemoteFileName));
    if(transfer.nFileSize>=1024)
        ui.filesizeLabel->setText(QString("%1 KBytes")
                                    .arg(transfer.nFileSize/1024));
    else
        ui.filesizeLabel->setText(QString("%1 Bytes").arg(transfer.nFileSize));
    double percent = 100.0;
    if(transfer.nFileSize)
        percent = transfer.nTransferred * 100 / transfer.nFileSize;
    ui.transferredLabel->setText(QString("%1/%2 - %3 %")
        .arg(transfer.nTransferred).arg(transfer.nFileSize).arg(percent));

    ui.progressBar->setValue((int)percent);

    int diff = transfer.nTransferred - m_lastTransferred;
    m_lastTransferred = transfer.nTransferred;

    double elapsed = m_start.secsTo(QTime::currentTime());
    double throughput = 0.0;
    if(elapsed)
    {
        throughput = transfer.nTransferred / elapsed;
        throughput /= 1024.0;
    }
    ui.throughputLabel->setText(tr("%1 KBytes/second, last second %2 bytes")
                                .arg(throughput).arg(diff));

    if(transfer.bInbound)
        ui.destinationLabel->setText(_Q(transfer.szLocalFilePath));
    else
    {
        TTCHAR chanpath[TT_STRLEN] = {0};
        TT_GetChannelPath(ttInst, transfer.nChannelID, chanpath);
        ui.destinationLabel->setText(_Q(chanpath));
    }
}
void COnlineUsersDlg::MenuCommand(UINT uCmd)
{
    int nUserID =  0;
    int count = m_wndUsers.GetItemCount();
    for(int i=0;i<count;i++)
    {
        if(m_wndUsers.GetItemState(i, LVIS_SELECTED) == LVIS_SELECTED)
            nUserID = m_wndUsers.GetItemData(i);
    }

    User user = {0};
    TT_GetUser(ttInst, nUserID, &user);
    Channel chan = {0};
    TT_GetChannel(ttInst, user.nChannelID, &chan);

    switch(uCmd)
    {
    case ID_POPUP_KICKANDBAN :
        TT_DoBanUser(ttInst, nUserID, 0);
        TT_DoKickUser(ttInst, nUserID, 0);
        break;
    case ID_POPUP_KICK :
        TT_DoKickUser(ttInst, nUserID, user.nChannelID);
        break;
    case ID_POPUP_OP :
        TT_DoChannelOpEx(ttInst, nUserID, user.nChannelID, chan.szOpPassword, 
                         !TT_IsChannelOperator(ttInst, nUserID, user.nChannelID));
        break;
    case ID_POPUP_COPYUSERINFORMATION :
    {
        User user;
        if(TT_GetUser(ttInst, nUserID, &user))
        {
            CString szText;
            CString szUserID;
            szUserID.Format(_T("%d"), user.nUserID);
            TTCHAR szChannel[TT_STRLEN] = _T("");
            TT_GetChannelPath(ttInst, user.nChannelID, szChannel);
            szText = szUserID;
            szText += _T("\t");
            szText += user.szNickname;
            szText += _T("\t");
            szText += user.szStatusMsg;
            szText += _T("\t");
            szText += user.szUsername;
            szText += _T("\t");
            szText += szChannel;
            szText += _T("\t");
            szText += user.szIPAddress;
            szText += _T("\t");
            szText += GetVersion(user);

            OpenClipboard();
            EmptyClipboard();
            HGLOBAL hglbCopy;
            hglbCopy = GlobalAlloc(GMEM_MOVEABLE,
                                   (szText.GetLength() + 1) * sizeof(TCHAR));
            if(hglbCopy)
            {
                LPVOID szStr = GlobalLock(hglbCopy);
                memcpy(szStr, szText.GetBuffer(), (szText.GetLength() + 1) * sizeof(TCHAR));
                GlobalUnlock(hglbCopy);
#if defined(UNICODE) || defined(_UNICODE)
                SetClipboardData(CF_UNICODETEXT, hglbCopy);
#else
                SetClipboardData(CF_TEXT, hglbCopy);
#endif
            }
            CloseClipboard();
        }
    }
    }
}