示例#1
0
ChatWindow::ChatWindow(QWidget* parent) :
    QWidget(parent, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint |
            Qt::WindowCloseButtonHint),
    ui(new Ui::ChatWindow),
    numMessagesAfterLastTimeStamp(0),
    _mousePressed(false),
    _mouseStartPosition(),
    _trayIcon(parent),
    _effectPlayer()
{
    setAttribute(Qt::WA_DeleteOnClose, false);

    ui->setupUi(this);

    FlowLayout* flowLayout = new FlowLayout(0, 4, 4);
    ui->usersWidget->setLayout(flowLayout);

    ui->messagePlainTextEdit->installEventFilter(this);
    ui->messagePlainTextEdit->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);

    QTextCursor cursor(ui->messagePlainTextEdit->textCursor());

    cursor.movePosition(QTextCursor::Start);

    QTextBlockFormat format = cursor.blockFormat();
    format.setLineHeight(130, QTextBlockFormat::ProportionalHeight);

    cursor.setBlockFormat(format);

    ui->messagePlainTextEdit->setTextCursor(cursor);

    if (!AccountManager::getInstance().isLoggedIn()) {
        ui->connectingToXMPPLabel->setText(tr("You must be logged in to chat with others."));
    }

#ifdef HAVE_QXMPP
    const QXmppClient& xmppClient = XmppClient::getInstance().getXMPPClient();
    if (xmppClient.isConnected()) {
        participantsChanged();
        const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
        connect(publicChatRoom, SIGNAL(participantsChanged()), this, SLOT(participantsChanged()));
        ui->connectingToXMPPLabel->hide();
        startTimerForTimeStamps();
    } else {
        ui->numOnlineLabel->hide();
        ui->usersArea->hide();
        ui->messagesScrollArea->hide();
        ui->messagePlainTextEdit->hide();
        connect(&XmppClient::getInstance(), SIGNAL(joinedPublicChatRoom()), this, SLOT(connected()));
    }
    connect(&xmppClient, SIGNAL(messageReceived(QXmppMessage)), this, SLOT(messageReceived(QXmppMessage)));
    connect(&_trayIcon, SIGNAL(messageClicked()), this, SLOT(notificationClicked()));
#endif // HAVE_QXMPP

    QDir mentionSoundsDir(Application::resourcesPath() + mentionSoundsPath);
    _mentionSounds = mentionSoundsDir.entryList(QDir::Files);
    _trayIcon.setIcon(QIcon( Application::resourcesPath() + "/images/hifi-logo.svg"));
}
示例#2
0
ChatWindow::~ChatWindow() {
#ifdef HAVE_QXMPP
    const QXmppClient& xmppClient = XmppClient::getInstance().getXMPPClient();
    disconnect(&xmppClient, SIGNAL(joinedPublicChatRoom()), this, SLOT(connected()));
    disconnect(&xmppClient, SIGNAL(messageReceived(QXmppMessage)), this, SLOT(messageReceived(QXmppMessage)));

    const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
    disconnect(publicChatRoom, SIGNAL(participantsChanged()), this, SLOT(participantsChanged()));
#endif // HAVE_QXMPP
    delete ui;
}
示例#3
0
void XmppClient::xmppConnected() {
    _publicChatRoom = _xmppMUCManager.addRoom(DEFAULT_CHAT_ROOM);
    _publicChatRoom->setNickName(AccountManager::getInstance().getAccountInfo().getUsername());
    _publicChatRoom->join();
    emit joinedPublicChatRoom();
}