Browse Source

Show preparation state for the current Qt conversation only

master
evgeny 1 day 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();
mainLayout->addWidget(m_attachPreview);
m_videoProgressTimer = new QTimer(this);
m_videoProgressTimer->setInterval(150);
connect(m_videoProgressTimer, &QTimer::timeout, this, &InputBar::onVideoProgressTick);
m_preparationLabel = new QLabel(this);
m_preparationLabel->hide();
mainLayout->addWidget(m_preparationLabel);
auto *layout = new QHBoxLayout();
layout->setSpacing(4);
@ -260,9 +260,7 @@ void InputBar::onSendClicked() {
snprintf(request->source, sizeof(request->source), "%s", source.constData());
snprintf(request->info.name, sizeof(request->info.name), "%s", name.constData());
emit submitAttachment(m_channelIdForRecord, request);
m_attachPreviewLabel->setText(QString::fromUtf8("\xF0\x9F\x8E\xAC Перекодирование… 0%"));
m_attachPreview->show();
m_videoProgressTimer->start();
m_attachPreview->hide();
} else {
GUI_INFO("send: file=%s name=%s", qPrintable(m_pendingAttachSrc), qPrintable(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();
m_mediaDirBase = mediaDirBase;
m_channelIdForRecord = channelId;
showPreparation();
}
void InputBar::setDmMode(bool enabled) {
@ -407,18 +406,25 @@ void InputBar::clearPendingAttachment() {
m_pendingAttachSize = 0;
m_pendingAttachAsVideo = false;
m_pendingAttachAsImage = false;
m_videoProgressTimer->stop();
m_attachPreview->hide();
}
void InputBar::onVideoProgressTick() {
int p = video_transcode_get_progress();
if (p < 0) {
m_videoProgressTimer->stop();
m_attachPreview->hide();
return;
void InputBar::updatePreparation(const QString& target, const QByteArray& job, int state) {
if (state == 0) { m_preparations[target].insert(job); m_preparationErrors.remove(target); }
else {
m_preparations[target].remove(job);
if (m_preparations[target].isEmpty()) m_preparations.remove(target);
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) {

9
tools/chatgui/src/inputbar.h

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