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")); }
void NotificationPresenterClientQt::displayNotification(Notification* notification, const QByteArray& bytes) { NotificationWrapper* wrapper = new NotificationWrapper(); m_notifications.insert(notification, wrapper); QString title; QString message; // FIXME: download & display HTML notifications if (notification->isHTML()) message = notification->url().string(); else { title = notification->contents().title(); message = notification->contents().body(); } if (m_platformPlugin.plugin() && m_platformPlugin.plugin()->supportsExtension(QWebKitPlatformPlugin::Notifications)) wrapper->m_presenter = m_platformPlugin.createNotificationPresenter(); if (!wrapper->m_presenter) { #ifndef QT_NO_SYSTEMTRAYICON if (!dumpNotification) wrapper->m_closeTimer.startOneShot(notificationTimeout); QPixmap pixmap; if (bytes.length() && pixmap.loadFromData(bytes)) { QIcon icon(pixmap); wrapper->m_notificationIcon = new QSystemTrayIcon(icon); } else wrapper->m_notificationIcon = new QSystemTrayIcon(); #endif } sendEvent(notification, "display"); // Make sure the notification was not cancelled during handling the display event if (m_notifications.find(notification) == m_notifications.end()) return; if (wrapper->m_presenter) { wrapper->connect(wrapper->m_presenter.get(), SIGNAL(notificationClosed()), wrapper, SLOT(notificationClosed()), Qt::QueuedConnection); wrapper->connect(wrapper->m_presenter.get(), SIGNAL(notificationClicked()), wrapper, SLOT(notificationClicked())); wrapper->m_presenter->showNotification(wrapper); return; } #ifndef QT_NO_SYSTEMTRAYICON wrapper->connect(wrapper->m_notificationIcon.get(), SIGNAL(messageClicked()), wrapper, SLOT(notificationClicked())); wrapper->m_notificationIcon->show(); wrapper->m_notificationIcon->showMessage(notification->contents().title(), notification->contents().body()); #endif }
void NotificationPresenterClientQt::displayNotification(Notification* notification) { NotificationWrapper* wrapper = new NotificationWrapper(); m_notifications.insert(notification, wrapper); QString title; QString message; // FIXME: download & display HTML notifications if (notification->isHTML()) message = notification->url().string(); else { title = notification->title(); message = notification->body(); } if (m_platformPlugin.plugin() && m_platformPlugin.plugin()->supportsExtension(QWebKitPlatformPlugin::Notifications)) wrapper->m_presenter = m_platformPlugin.createNotificationPresenter(); if (!wrapper->m_presenter) { #ifndef QT_NO_SYSTEMTRAYICON if (!dumpNotification) wrapper->m_closeTimer.startOneShot(notificationTimeout); #endif } wrapper->m_displayEventTimer.startOneShot(0); // Make sure the notification was not cancelled during handling the display event if (m_notifications.find(notification) == m_notifications.end()) return; if (wrapper->m_presenter) { wrapper->connect(wrapper->m_presenter.get(), SIGNAL(notificationClosed()), wrapper, SLOT(notificationClosed()), Qt::QueuedConnection); wrapper->connect(wrapper->m_presenter.get(), SIGNAL(notificationClicked()), wrapper, SLOT(notificationClicked())); wrapper->m_presenter->showNotification(wrapper); return; } #ifndef QT_NO_SYSTEMTRAYICON wrapper->connect(m_systemTrayIcon.data(), SIGNAL(messageClicked()), wrapper, SLOT(notificationClicked())); QMetaObject::invokeMethod(m_systemTrayIcon.data(), "show"); QMetaObject::invokeMethod(m_systemTrayIcon.data(), "showMessage", Q_ARG(QString, notification->title()), Q_ARG(QString, notification->body())); #endif }