Browse Source

Show preparation state for the current Qt conversation only

master
evgeny 2 weeks ago
parent
commit
e4a57970f0
  1. 34
      tools/chatgui/src/inputbar.cpp
  2. 9
      tools/chatgui/src/inputbar.h

34
tools/chatgui/src/inputbar.cpp

@ -100,9 +100,9 @@ InputBar::InputBar(EmojiPanel *emojiPanel, AudioRecorder *recorder, QWidget *par
m_attachPreview->hide(); m_attachPreview->hide();
mainLayout->addWidget(m_attachPreview); mainLayout->addWidget(m_attachPreview);
m_videoProgressTimer = new QTimer(this); m_preparationLabel = new QLabel(this);
m_videoProgressTimer->setInterval(150); m_preparationLabel->hide();
connect(m_videoProgressTimer, &QTimer::timeout, this, &InputBar::onVideoProgressTick); mainLayout->addWidget(m_preparationLabel);
auto *layout = new QHBoxLayout(); auto *layout = new QHBoxLayout();
layout->setSpacing(4); layout->setSpacing(4);
@ -260,9 +260,7 @@ void InputBar::onSendClicked() {
snprintf(request->source, sizeof(request->source), "%s", source.constData()); snprintf(request->source, sizeof(request->source), "%s", source.constData());
snprintf(request->info.name, sizeof(request->info.name), "%s", name.constData()); snprintf(request->info.name, sizeof(request->info.name), "%s", name.constData());
emit submitAttachment(m_channelIdForRecord, request); emit submitAttachment(m_channelIdForRecord, request);
m_attachPreviewLabel->setText(QString::fromUtf8("\xF0\x9F\x8E\xAC Перекодирование… 0%")); m_attachPreview->hide();
m_attachPreview->show();
m_videoProgressTimer->start();
} else { } else {
GUI_INFO("send: file=%s name=%s", qPrintable(m_pendingAttachSrc), qPrintable(m_pendingAttachName)); GUI_INFO("send: file=%s name=%s", qPrintable(m_pendingAttachSrc), qPrintable(m_pendingAttachName));
emit sendFileAttachment(m_channelIdForRecord, m_pendingAttachSrc, m_pendingAttachDest, m_pendingAttachName); emit sendFileAttachment(m_channelIdForRecord, m_pendingAttachSrc, m_pendingAttachDest, m_pendingAttachName);
@ -287,6 +285,7 @@ void InputBar::setRecordingContext(const QString& mediaDirBase, const QString& c
if (m_channelIdForRecord != channelId) clearPendingAttachment(); if (m_channelIdForRecord != channelId) clearPendingAttachment();
m_mediaDirBase = mediaDirBase; m_mediaDirBase = mediaDirBase;
m_channelIdForRecord = channelId; m_channelIdForRecord = channelId;
showPreparation();
} }
void InputBar::setDmMode(bool enabled) { void InputBar::setDmMode(bool enabled) {
@ -407,18 +406,25 @@ void InputBar::clearPendingAttachment() {
m_pendingAttachSize = 0; m_pendingAttachSize = 0;
m_pendingAttachAsVideo = false; m_pendingAttachAsVideo = false;
m_pendingAttachAsImage = false; m_pendingAttachAsImage = false;
m_videoProgressTimer->stop();
m_attachPreview->hide(); m_attachPreview->hide();
} }
void InputBar::onVideoProgressTick() { void InputBar::updatePreparation(const QString& target, const QByteArray& job, int state) {
int p = video_transcode_get_progress(); if (state == 0) { m_preparations[target].insert(job); m_preparationErrors.remove(target); }
if (p < 0) { else {
m_videoProgressTimer->stop(); m_preparations[target].remove(job);
m_attachPreview->hide(); if (m_preparations[target].isEmpty()) m_preparations.remove(target);
return; if (state == 2) m_preparationErrors.insert(target);
} }
m_attachPreviewLabel->setText(QString::fromUtf8("\xF0\x9F\x8E\xAC Перекодирование… %1%").arg(p / 10)); showPreparation();
}
void InputBar::showPreparation() {
QString status;
if (!m_preparations.value(m_channelIdForRecord).isEmpty()) status = QString::fromUtf8("Подготовка медиа…");
else if (m_preparationErrors.contains(m_channelIdForRecord)) status = QString::fromUtf8("Не удалось подготовить вложение");
m_preparationLabel->setText(status);
m_preparationLabel->setVisible(!status.isEmpty());
} }
void InputBar::resizeEvent(QResizeEvent* event) { void InputBar::resizeEvent(QResizeEvent* event) {

9
tools/chatgui/src/inputbar.h

@ -1,6 +1,8 @@
#pragma once #pragma once
#include <QWidget> #include <QWidget>
#include <QHash>
#include <QSet>
class QTextEdit; class QTextEdit;
class QPushButton; class QPushButton;
@ -22,6 +24,7 @@ public:
/* Общий composer для канала и PM. */ /* Общий composer для канала и PM. */
void setDmMode(bool enabled); void setDmMode(bool enabled);
void setMediaEnabled(bool enabled); void setMediaEnabled(bool enabled);
void updatePreparation(const QString& target, const QByteArray& job, int state);
signals: signals:
void sendMessage(const QString &text); void sendMessage(const QString &text);
@ -42,7 +45,6 @@ private slots:
void onPttReleased(); void onPttReleased();
void onAttachClicked(); void onAttachClicked();
void clearPendingAttachment(); void clearPendingAttachment();
void onVideoProgressTick();
void updateRecordingUI(int ms); void updateRecordingUI(int ms);
void showRecordOverlay(); void showRecordOverlay();
void hideRecordOverlay(); void hideRecordOverlay();
@ -75,5 +77,8 @@ private:
qint64 m_pendingAttachSize = 0; qint64 m_pendingAttachSize = 0;
bool m_pendingAttachAsVideo = false; bool m_pendingAttachAsVideo = false;
bool m_pendingAttachAsImage = false; bool m_pendingAttachAsImage = false;
QTimer *m_videoProgressTimer = nullptr; QLabel* m_preparationLabel = nullptr;
QHash<QString, QSet<QByteArray>> m_preparations;
QSet<QString> m_preparationErrors;
void showPreparation();
}; };

Loading…
Cancel
Save