Commit a6badad4 authored by Andreas Traczyk's avatar Andreas Traczyk

refacto: use new lrc database adaptations

Gitlab: #407
Change-Id: Iaf8df3e4648df4adf26a3b5e437ecaf306b34fd4
parent 76320730
......@@ -863,6 +863,33 @@ CallWidget::showChatView(const std::string& accountId, const lrc::api::conversat
setupChatView(convInfo);
}
void
CallWidget::setConversationProfileData(const lrc::api::conversation::Info& convInfo)
{
auto convModel = LRCInstance::getCurrentConversationModel();
auto accInfo = &LRCInstance::getCurrentAccountInfo();
auto contactUri = convInfo.participants.front();
try {
auto& contact = accInfo->contactModel->getContact(contactUri);
auto bestName = Utils::bestNameForConversation(convInfo, *convModel);
ui->messageView->setInvitation(
(contact.profileInfo.type == lrc::api::profile::Type::PENDING),
bestName,
contactUri
);
if (!contact.profileInfo.avatar.empty()) {
ui->messageView->setSenderImage(contactUri, contact.profileInfo.avatar);
} else {
auto avatar = Utils::conversationPhoto(convInfo.uid, *accInfo);
QByteArray ba;
QBuffer bu(&ba);
avatar.save(&bu, "PNG");
std::string avatarString = ba.toBase64().toStdString();
ui->messageView->setSenderImage(contactUri, avatarString);
}
} catch (...) {}
}
void
CallWidget::setupChatView(const lrc::api::conversation::Info& convInfo)
{
......@@ -898,8 +925,6 @@ CallWidget::setupChatView(const lrc::api::conversation::Info& convInfo)
ui->sendContactRequestButton->setVisible(shouldShowSendContactRequestBtn);
ui->messageView->setMessagesVisibility(false);
ui->messageView->clear();
ui->messageView->setInvitation(false);
Utils::oneShotConnect(ui->messageView, &MessageWebView::messagesCleared,
[this, convInfo] {
auto convModel = LRCInstance::getCurrentConversationModel();
......@@ -908,33 +933,10 @@ CallWidget::setupChatView(const lrc::api::conversation::Info& convInfo)
[this] {
ui->messageView->setMessagesVisibility(true);
});
// Contact Avatars
auto accInfo = &LRCInstance::getCurrentAccountInfo();
auto contactUri = convInfo.participants.front();
try {
auto& contact = accInfo->contactModel->getContact(contactUri);
auto bestName = Utils::bestNameForConversation(convInfo, *convModel);
ui->messageView->setInvitation(
(contact.profileInfo.type == lrc::api::profile::Type::PENDING),
bestName,
accInfo->contactModel->getContactProfileId(contact.profileInfo.uri)
);
if (!contact.profileInfo.avatar.empty()) {
ui->messageView->setSenderImage(
accInfo->contactModel->getContactProfileId(contactUri),
contact.profileInfo.avatar);
} else {
auto avatar = Utils::conversationPhoto(convInfo.uid, *accInfo);
QByteArray ba;
QBuffer bu(&ba);
avatar.save(&bu, "PNG");
std::string avatarString = ba.toBase64().toStdString();
ui->messageView->setSenderImage(
accInfo->contactModel->getContactProfileId(contactUri),
avatarString);
}
} catch (...) {}
setConversationProfileData(convInfo);
});
ui->messageView->setInvitation(false);
ui->messageView->clear();
}
void
......@@ -1272,15 +1274,21 @@ CallWidget::connectAccount(const std::string& accId)
auto& contactModel = LRCInstance::getCurrentAccountInfo().contactModel;
disconnect(contactAddedConnection_);
contactAddedConnection_ = connect(contactModel.get(), &lrc::api::ContactModel::contactAdded,
[this, &contactModel](const std::string & contactId) {
[this, &contactModel](const std::string & contactUri) {
auto convModel = LRCInstance::getCurrentConversationModel();
auto currentConversation = Utils::getConversationFromUid(LRCInstance::getSelectedConvUid(),
*convModel);
if (currentConversation == convModel->allFilteredConversations().end()) {
return;
}
if (contactId == contactModel.get()->getContact((*currentConversation).participants.at(0)).profileInfo.uri) {
if (contactUri == contactModel.get()->getContact((*currentConversation).participants.at(0)).profileInfo.uri) {
// update call screen
auto avatarImg = QPixmap::fromImage(imageForConv((*currentConversation).uid));
ui->callingPhoto->setPixmap(avatarImg);
ui->callerPhoto->setPixmap(avatarImg);
// update conversation
ui->messageView->clear();
setConversationProfileData(*currentConversation);
ui->messageView->printHistory(*convModel, currentConversation->interactions);
}
});
......
......@@ -72,6 +72,7 @@ public slots:
void settingsButtonClicked();
void showChatView(const QModelIndex& nodeIdx);
void showChatView(const std::string & accountId, const lrc::api::conversation::Info & convInfo);
void setConversationProfileData(const lrc::api::conversation::Info & convInfo);
void setupChatView(const lrc::api::conversation::Info& convInfo);
void slotAcceptInviteClicked(const QModelIndex& index);
void slotBlockInviteClicked(const QModelIndex& index);
......
This diff is collapsed.
......@@ -34,8 +34,15 @@ protected:
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
private:
void paintConversationItem(QPainter* painter, const QStyleOptionViewItem& option, const QRect& rect, const QModelIndex& index) const;
void paintRingInviteConversationItem(QPainter* painter, const QStyleOptionViewItem& option, const QRect& rect, const QModelIndex& index) const;
void paintConversationItem(QPainter* painter,
const QStyleOptionViewItem& option,
const QRect& rect,
const QModelIndex& index,
const bool isTemporary) const;
void paintInvitationItem( QPainter* painter,
const QStyleOptionViewItem& option,
const QRect& rect,
const QModelIndex& index) const;
constexpr static int sizeImage_ = 48;
constexpr static int cellHeight_ = 60;
......@@ -44,5 +51,7 @@ private:
constexpr static int fontSize_ = 11;
constexpr static int infoTextWidth_ = 176;
QPixmap* searchIcon_;
mutable std::map<int, bool> highlightMap_;
};
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/><path d="M0 0h24v24H0z" fill="none"/></svg>
\ No newline at end of file
......@@ -48,17 +48,21 @@
using namespace lrc::api;
using migrateCallback = std::function<void()>;
class LRCInstance : public QObject
{
Q_OBJECT
public:
static LRCInstance& instance() {
static LRCInstance instance_;
static LRCInstance& instance(migrateCallback willMigrate = {},
migrateCallback didMigrate = {}) {
static LRCInstance instance_(willMigrate, didMigrate);
return instance_;
};
static void init() {
instance();
static void init(migrateCallback willMigrate = {},
migrateCallback didMigrate = {}) {
instance(willMigrate, didMigrate);
};
static Lrc& getAPI() {
return *(instance().lrc_);
......@@ -174,6 +178,10 @@ public:
return instance().getCurrentAccountInfo().confProperties;
}
static void subscribeToDebugReceived() {
instance().lrc_->subscribeToDebugReceived();
}
signals:
/// emit once at least one valid account is loaded
void accountOnBoarded();
......@@ -182,8 +190,9 @@ private:
std::unique_ptr<Lrc> lrc_;
AccountListModel accountListModel_;
LRCInstance() {
lrc_ = std::make_unique<Lrc>();
LRCInstance(migrateCallback willMigrateCb = {},
migrateCallback didMigrateCb = {}) {
lrc_ = std::make_unique<Lrc>(willMigrateCb, didMigrateCb);
};
std::string selectedAccountId_;
......
......@@ -19,24 +19,23 @@
#include "mainwindow.h"
#include "globalinstances.h"
#include "downloadmanager.h"
#include "lrcinstance.h"
#include "pixbufmanipulator.h"
#include "runguard.h"
#include "utils.h"
#include "splashscreen.h"
#include <QApplication>
#include <QFile>
#include <QMessageBox>
#include "globalinstances.h"
#include <QFontDatabase>
#include <QLibraryInfo>
#include <QTranslator>
#include <ciso646>
#include "downloadmanager.h"
#include "lrcinstance.h"
#include "pixbufmanipulator.h"
#include "runguard.h"
#include "utils.h"
#ifdef Q_OS_WIN
#include <windows.h>
#endif
......@@ -134,35 +133,6 @@ main(int argc, char* argv[])
auto startMinimized = false;
QString uri = "";
#if defined _MSC_VER && !COMPILE_ONLY
gnutls_global_init();
#endif
GlobalInstances::setPixmapManipulator(std::make_unique<PixbufManipulator>());
LRCInstance::init();
QFile debugFile(qApp->applicationDirPath() + "/" + "jami.log");
for (auto string : QCoreApplication::arguments()) {
if (string.startsWith("jami:")) {
uri = string;
} else {
if (string == "-m" || string == "--minimized") {
startMinimized = true;
}
if (string == "-f" || string == "--file") {
debugFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
debugFile.close();
fileDebug(debugFile);
}
#ifdef _MSC_VER
if (string == "-c" || string == "--vsconsole") {
vsConsoleDebug();
}
#endif
}
}
auto appDir = qApp->applicationDirPath() + "/";
const auto locale_name = QLocale::system().name();
const auto locale_lang = locale_name.split('_')[0];
......@@ -206,6 +176,63 @@ main(int argc, char* argv[])
}
#endif
#if defined _MSC_VER && !COMPILE_ONLY
gnutls_global_init();
#endif
GlobalInstances::setPixmapManipulator(std::make_unique<PixbufManipulator>());
SplashScreen* splash = new SplashScreen();
std::atomic_bool isMigrating = false;
LRCInstance::init(
[&splash, &a, &isMigrating] {
splash->setupUI(
QPixmap(":/images/logo-jami-standard-coul.png"),
QString("Jami - ") + QObject::tr("Migration needed"),
QObject::tr("Migration in progress... This may take a while."),
QColor(232, 232, 232)
);
splash->show();
isMigrating = true;
while (isMigrating) {
a.processEvents();
}
},
[&splash, &isMigrating] {
while (!isMigrating) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
isMigrating = false;
});
splash->hide();
LRCInstance::subscribeToDebugReceived();
QFile debugFile(qApp->applicationDirPath() + "/" + "jami.log");
for (auto string : QCoreApplication::arguments()) {
if (string.startsWith("jami:")) {
uri = string;
} else {
if (string == "-m" || string == "--minimized") {
startMinimized = true;
}
auto dbgFile = string == "-f" || string == "--file";
auto dbgConsole = string == "-c" || string == "--vsconsole";
if (dbgFile || dbgConsole) {
if (dbgFile) {
debugFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
debugFile.close();
fileDebug(debugFile);
}
#ifdef _MSC_VER
if (dbgConsole) {
vsConsoleDebug();
}
#endif
}
}
}
QFontDatabase::addApplicationFont(":/images/FontAwesome.otf");
MainWindow::instance().createThumbBar();
......@@ -218,9 +245,12 @@ main(int argc, char* argv[])
}
QObject::connect(&a, &QApplication::aboutToQuit, [&guard] { guard.release(); });
splash->finish(&MainWindow::instance());
splash->deleteLater();
auto ret = a.exec();
LRCInstance::reset();
#ifdef Q_OS_WIN
FreeConsole();
#endif
......@@ -230,4 +260,4 @@ main(int argc, char* argv[])
GlobalSystemTray::instance().hide();
return ret;
}
}
\ No newline at end of file
......@@ -311,6 +311,9 @@ MessageWebView::printNewInteraction(lrc::api::ConversationModel& conversationMod
const lrc::api::interaction::Info& interaction)
{
auto interactionObject = interactionToJsonInteractionObject(conversationModel, msgId, interaction).toUtf8();
if (interactionObject.isEmpty()) {
return;
}
QString s = QString::fromLatin1("addMessage(%1);")
.arg(interactionObject.constData());
page()->runJavaScript(s, QWebEngineScript::MainWorld);
......@@ -322,6 +325,9 @@ MessageWebView::updateInteraction(lrc::api::ConversationModel& conversationModel
const lrc::api::interaction::Info& interaction)
{
auto interactionObject = interactionToJsonInteractionObject(conversationModel, msgId, interaction).toUtf8();
if (interactionObject.isEmpty()) {
return;
}
QString s = QString::fromLatin1("updateMessage(%1);")
.arg(interactionObject.constData());
page()->runJavaScript(s, QWebEngineScript::MainWorld);
......
......@@ -89,40 +89,41 @@ PixbufManipulator::decorationRole(const lrc::api::conversation::Info & conversat
{
QImage photo;
auto contacts = conversationInfo.participants;
if (!contacts.empty()) {
try {
// Get first contact photo
auto contactUri = contacts.front();
auto contactInfo = accountInfo.contactModel->getContact(contactUri);
auto contactPhoto = contactInfo.profileInfo.avatar;
auto bestName = Utils::bestNameForContact(contactInfo);
auto bestId = Utils::bestIdForContact(contactInfo);
if (accountInfo.profileInfo.type == lrc::api::profile::Type::SIP &&
contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY) {
photo = Utils::fallbackAvatar(IMAGE_SIZE, QString(), QString());
}
else if (accountInfo.profileInfo.type == lrc::api::profile::Type::SIP) {
photo = Utils::fallbackAvatar(IMAGE_SIZE,
QString::fromStdString("sip:" + bestId),
QString());
}
else if (contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY && contactInfo.profileInfo.uri.empty()) {
photo = Utils::fallbackAvatar(IMAGE_SIZE, QString(), QString());
}
else if (!contactPhoto.empty()) {
QByteArray byteArray(contactPhoto.c_str(), contactPhoto.length());
photo = personPhoto(byteArray, nullptr).value<QImage>();
}
else {
if (contacts.empty()) {
return QVariant::fromValue(photo);
}
try {
// Get first contact photo
auto contactUri = contacts.front();
auto contactInfo = accountInfo.contactModel->getContact(contactUri);
auto contactPhoto = contactInfo.profileInfo.avatar;
auto bestName = Utils::bestNameForContact(contactInfo);
auto bestId = Utils::bestIdForContact(contactInfo);
if (accountInfo.profileInfo.type == lrc::api::profile::Type::SIP &&
contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY) {
photo = Utils::fallbackAvatar(IMAGE_SIZE, QString(), QString());
} else if (contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY && contactInfo.profileInfo.uri.empty()) {
photo = Utils::fallbackAvatar(IMAGE_SIZE, QString(), QString());
} else if (!contactPhoto.empty()) {
QByteArray byteArray(contactPhoto.c_str(), contactPhoto.length());
photo = personPhoto(byteArray, nullptr).value<QImage>();
if (photo.isNull()) {
auto avatarName = contactInfo.profileInfo.uri == bestName ?
QString() :
QString::fromStdString(bestName);
photo = Utils::fallbackAvatar(IMAGE_SIZE,
QString::fromStdString("ring:" + bestId),
QString::fromStdString("ring:" + contactInfo.profileInfo.uri),
avatarName);
}
} else {
auto avatarName = contactInfo.profileInfo.uri == bestName ?
QString() :
QString::fromStdString(bestName);
photo = Utils::fallbackAvatar(IMAGE_SIZE,
QString::fromStdString("ring:" + contactInfo.profileInfo.uri),
avatarName);
}
catch (...) {}
}
catch (...) {}
return QVariant::fromValue(Utils::scaleAndFrame(photo, IMAGE_SIZE));
}
\ No newline at end of file
......@@ -47,7 +47,7 @@
<file>images/icons/ic_person_add_white_24dp.png</file>
<file>images/icons/ic_phone_24px.svg</file>
<file>images/icons/ic_photo_camera_white_24dp_2x.png</file>
<file>images/icons/ic_search_black_18dp_2x.png</file>
<file>images/icons/ic_baseline-search-24px.svg</file>
<file>images/icons/ic_send_24px.svg</file>
<file>images/icons/ic_send_white_24dp.png</file>
<file>images/icons/ic_settings_white_48dp_2x.png</file>
......
......@@ -235,6 +235,7 @@
<ClCompile Include="currentaccountcombobox.cpp" />
<ClCompile Include="aboutdialog.cpp" />
<ClCompile Include="levelmeter.cpp" />
<ClCompile Include="splashscreen.cpp" />
<ClCompile Include="updatedownloaddialog.cpp" />
<ClCompile Include="downloadmanager.cpp" />
<ClCompile Include="accountitemdelegate.cpp" />
......@@ -507,6 +508,10 @@
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;$(ProjectDir)..\ring-daemon\contrib\msvc\include;$(ProjectDir)..\daemon\contrib\msvc\include;$(ProjectDir)..\ring-lrc\src;$(ProjectDir)..\lrc\src;$(ProjectDir)winsparkle\include;$(ProjectDir)qrencode-win32\qrencode-win32;$(QTDIR)\include;$(QTDIR)\include\QtSvg;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtWinExtras;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtXml;$(QTDIR)\include\QtNetwork;$(QTDIR)\include\QtWebEngineWidgets;$(QTDIR)\include\QtWebChannel;$(QTDIR)\include\QtCore;$(QTDIR)\mkspecs\win32-msvc;.\release</IncludePath>
<IncludePath Condition="'$(Configuration)|$(Platform)'=='ReleaseCompile|x64'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;$(ProjectDir)..\ring-daemon\contrib\msvc\include;$(ProjectDir)..\daemon\contrib\msvc\include;$(ProjectDir)..\ring-lrc\src;$(ProjectDir)..\lrc\src;$(ProjectDir)winsparkle\include;$(ProjectDir)qrencode-win32\qrencode-win32;$(QTDIR)\include;$(QTDIR)\include\QtSvg;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtWinExtras;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtXml;$(QTDIR)\include\QtNetwork;$(QTDIR)\include\QtWebEngineWidgets;$(QTDIR)\include\QtWebChannel;$(QTDIR)\include\QtCore;$(QTDIR)\mkspecs\win32-msvc;.\release</IncludePath>
</QtMoc>
<QtMoc Include="splashscreen.h">
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;$(ProjectDir)..\ring-daemon\contrib\msvc\include;$(ProjectDir)..\daemon\contrib\msvc\include;$(ProjectDir)..\ring-lrc\src;$(ProjectDir)..\lrc\src;$(ProjectDir)qrencode-win32\qrencode-win32;$(QTDIR)\include;$(QTDIR)\include\QtSvg;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtWinExtras;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtXml;$(QTDIR)\include\QtNetwork;$(QTDIR)\include\QtWebEngineWidgets;$(QTDIR)\include\QtWebChannel;$(QTDIR)\include\QtCore;$(QTDIR)\mkspecs\win32-msvc;.\release</IncludePath>
<IncludePath Condition="'$(Configuration)|$(Platform)'=='ReleaseCompile|x64'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;$(ProjectDir)..\ring-daemon\contrib\msvc\include;$(ProjectDir)..\daemon\contrib\msvc\include;$(ProjectDir)..\ring-lrc\src;$(ProjectDir)..\lrc\src;$(ProjectDir)winsparkle\include;$(ProjectDir)qrencode-win32\qrencode-win32;$(QTDIR)\include;$(QTDIR)\include\QtSvg;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtWinExtras;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtXml;$(QTDIR)\include\QtNetwork;$(QTDIR)\include\QtWebEngineWidgets;$(QTDIR)\include\QtWebChannel;$(QTDIR)\include\QtCore;$(QTDIR)\mkspecs\win32-msvc;.\release</IncludePath>
</QtMoc>
<ClInclude Include="utils.h" />
<QtMoc Include="videooverlay.h">
</QtMoc>
......
......@@ -213,6 +213,9 @@
<ClCompile Include="contactpickeritemdelegate.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="splashscreen.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="levelmeter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
......@@ -374,6 +377,9 @@
<QtMoc Include="levelmeter.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="splashscreen.h">
<Filter>Generated Files</Filter>
</QtMoc>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="debug\moc_predefs.h.cbt">
......
......@@ -29,7 +29,7 @@ RingContactLineEdit::RingContactLineEdit(QWidget* parent) :
setFrame(false);
addAction(QIcon(":images/icons/ic_search_black_18dp_2x.png"), QLineEdit::ActionPosition::LeadingPosition);
addAction(QIcon(":images/icons/ic_baseline-search-24px.svg"), QLineEdit::ActionPosition::LeadingPosition);
}
RingContactLineEdit::~RingContactLineEdit()
......
......@@ -19,6 +19,7 @@
#include "smartlistselectorbuttonnotifier.h"
#include "lrcinstance.h"
#include "utils.h"
#include "ringthemeutils.h"
#include "api/conversationmodel.h"
......@@ -56,7 +57,7 @@ SmartlistSelectorButtonNotifier::paintEvent(QPaintEvent *event)
auto ringConversations = convModel->getFilteredConversations(Type::RING);
std::for_each(ringConversations.begin(), ringConversations.end(),
[&totalUnreadMessages, convModel](const auto& conversation) {
totalUnreadMessages += convModel->getNumberOfUnreadMessagesFor(conversation.uid);
totalUnreadMessages += conversation.unreadMessages;
});
break;
}
......
/***************************************************************************
* Copyright (C) 2019 by Savoir-faire Linux *
* Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#include "splashscreen.h"
#include <QEvent>
#include <QMovie>
constexpr static const int textSectionHeight = 48;
SplashScreen::SplashScreen()
{
this->installEventFilter(this);
}
SplashScreen::~SplashScreen()
{
if (spinner_) {
disconnect(spinner_);
delete spinner_;
}
}
void
SplashScreen::setupUI(const QPixmap& logo,
const QString& headerText,
const QString& footerText,
const QColor& bgColor,
const QColor& textColor)
{
logo_ = logo;
headerText_ = headerText;
footerText_ = footerText;
bgColor_ = bgColor;
textColor_ = textColor;
spinner_ = new QMovie(":/images/waiting.gif");
connect(spinner_, &QMovie::frameChanged,
[this](int frame) {
Q_UNUSED(frame);
update();
});
spinner_->start();
QFont font;
font.setFamily("Arial");
font.setPixelSize(16);
setFont(font);
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::SplashScreen);
QFontMetrics fontMetrics(font);
auto baseWidth = logo_.width();
auto baseHeight = logo_.height()
+ textSectionHeight * 2
+ spinner_->frameRect().height() * 3;
QPixmap bgPixmap(baseWidth, baseHeight);
bgPixmap.fill(Qt::transparent);
QSplashScreen::setPixmap(bgPixmap);
}
bool SplashScreen::eventFilter(QObject *target, QEvent *e)
{
Q_UNUSED(target)
if ((e->type() == QEvent::MouseButtonPress) ||
(e->type() == QEvent::MouseButtonDblClick) ||
(e->type() == QEvent::MouseButtonRelease) ||
(e->type() == QEvent::KeyPress) ||
(e->type() == QEvent::KeyRelease))
return true;
return false;
}
void SplashScreen::paintEvent(QPaintEvent* e)
{
Q_UNUSED(e);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
auto rect = QRect(0, 0, this->geometry().width(), this->geometry().height());
// background
QPainterPath path;
path.addRoundedRect(rect, 10, 10);
painter.fillPath(path, bgColor_);
// footer text
QFont font(this->font());
font.setWeight(QFont::Weight::DemiBold);
painter.setFont(font);
painter.setPen(textColor_);
auto textRect = QRect(rect.x(), 0,
rect.width(), textSectionHeight);
painter.drawText(textRect, Qt::AlignCenter, headerText_);
// logo
painter.drawPixmap(0, textSectionHeight, logo_);
// footer text
font.setWeight(QFont::Weight::Normal);
painter.setFont(font);
painter.setPen(textColor_);
textRect = QRect(rect.x(), rect.y() + textSectionHeight + logo_.height(),
rect.width(), textSectionHeight);
painter.drawText(textRect, Qt::AlignCenter, footerText_);
// spinner
auto spinnerRect = QRect(rect.x() + rect.width() / 2 - textSectionHeight / 2,
textRect.y() + textSectionHeight,
spinner_->frameRect().width(), spinner_->frameRect().height());
painter.drawPixmap(spinnerRect, spinner_->currentPixmap());
QSplashScreen::paintEvent(e);
}
/***************************************************************************
* Copyright (C) 2019 by Savoir-faire Linux *
* Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#pragma once
#include <QSplashScreen>
#include <QPainter>
class SplashScreen : public QSplashScreen
{
Q_OBJECT;
public:
SplashScreen();
~SplashScreen();
void setupUI(const QPixmap& logo,
const QString& headerText = "",
const QString& footerText = "",
const QColor& bgColor = Qt::white,
const QColor& textColor = Qt::black);
protected:
bool eventFilter(QObject *target, QEvent *e);
void paintEvent(QPaintEvent* e) override;
private:
QString headerText_;
QPixmap logo_;
QString footerText_;
QColor bgColor_;
QColor textColor_;
QMovie* spinner_;
};
......@@ -711,6 +711,10 @@ div.last_message > span {
min-width: 16px;
}
.message_in .sender_image_cell {
min-width: 56px;
}
.dummy_cell {
padding: 0;
}
......@@ -1145,8 +1149,8 @@ pre {
/* Media interactions */
.media_wrapper img {
max-width: 200px;
max-height: 200px;
max-width: 300px;
max-height: 300px;
}
}
......
......@@ -161,8 +161,9 @@ function showInvitation(contactAlias, contactId) {
if (!inviteImage.classList.contains('invite_sender_image')) {
inviteImage.classList.add('invite_sender_image');
}
if (!inviteImage.classList.contains(`invite_sender_image_${contactId}`)) {
inviteImage.classList.add(`invite_sender_image_${contactId}`);
const className = `invite_sender_image_${contactId}`.replace(/@/g, "_").replace(/\./g, "_")
if (!inviteImage.classList.contains(className)) {
inviteImage.classList.add(className);
}
hasInvitation = true
invitationText.innerHTML = "<span id='invite_contact_name'>" + contactAlias + "</span> is not in your contacts<br/>"
......@@ -629,6 +630,7 @@ function updateFileInteraction(message_div, message_object, forceTypeToFile = fa
message_div.insertBefore(new_wrapper, message_div.querySelector(".menu_interaction"))
message_div.querySelector("img").id = message_id
message_div.querySelector("img").msg_obj = message_object
addSenderImage(message_div, message_object["type"], message_object["sender_contact_method"]);