mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-20 09:06:45 +00:00
feat(GODT-2540): notify user of wrong IMAP password.
This commit is contained in:
@ -49,6 +49,50 @@ QIcon loadIconFromImage(QString const &path) {
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \brief Load a multi-resolution icon from a SVG file. The image is assumed to be square. SVG is rasterized in 256, 128, 64, 32 and 16px.
|
||||
///
|
||||
/// Note: QPixmap can load SVG files directly, but our SVG file are defined in small shape size and QPixmap will rasterize them a very low resolution
|
||||
/// by default (eg. 16x16), which is insufficient for some uses. As a consequence, we manually generate a multi-resolution icon that render smoothly
|
||||
/// at any acceptable resolution for an icon.
|
||||
///
|
||||
/// \param[in] path The path of the SVG file.
|
||||
/// \return The icon.
|
||||
//****************************************************************************************************************************************************
|
||||
QIcon loadIconFromSVG(QString const &path, QColor const &color = QColor()) {
|
||||
QSvgRenderer renderer(path);
|
||||
QIcon icon;
|
||||
qint32 size = 256;
|
||||
|
||||
while (size >= 16) {
|
||||
QPixmap pixmap(size, size);
|
||||
pixmap.fill(QColor(0, 0, 0, 0));
|
||||
QPainter painter(&pixmap);
|
||||
renderer.render(&painter);
|
||||
if (color.isValid()) {
|
||||
painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
|
||||
painter.fillRect(pixmap.rect(), color);
|
||||
}
|
||||
painter.end();
|
||||
icon.addPixmap(pixmap);
|
||||
size /= 2;
|
||||
}
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
//
|
||||
//****************************************************************************************************************************************************
|
||||
QIcon loadIcon(QString const& path) {
|
||||
if (path.endsWith(".svg", Qt::CaseInsensitive)) {
|
||||
return loadIconFromSVG(path);
|
||||
}
|
||||
return loadIconFromImage(path);
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \brief Retrieve the color associated with a tray icon state.
|
||||
///
|
||||
@ -95,6 +139,18 @@ QString stateText(TrayIcon::State state) {
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \brief converts a QML resource path to Qt resource path.
|
||||
/// QML resource paths are a bit different from qt resource paths
|
||||
/// \param[in] path The resource path.
|
||||
/// \return
|
||||
//****************************************************************************************************************************************************
|
||||
QString qmlResourcePathToQt(QString const &path) {
|
||||
QString result = path;
|
||||
result.replace(QRegularExpression(R"(^\.\/)"), ":/qml/");
|
||||
return result;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
|
||||
@ -111,7 +167,8 @@ TrayIcon::TrayIcon()
|
||||
connect(menu_.get(), &QMenu::aboutToShow, this, &TrayIcon::onMenuAboutToShow);
|
||||
connect(this, &TrayIcon::selectUser, &app().backend(), &QMLBackend::selectUser);
|
||||
connect(this, &TrayIcon::activated, this, &TrayIcon::onActivated);
|
||||
|
||||
// some OSes/Desktop managers will automatically show main window when clicked, but not all, so we do it manually.
|
||||
connect(this, &TrayIcon::messageClicked, &app().backend(), &QMLBackend::showMainWindow);
|
||||
this->show();
|
||||
this->setState(State::Normal, QString(), QString());
|
||||
|
||||
@ -151,7 +208,7 @@ void TrayIcon::onUserClicked() {
|
||||
throw Exception("Could not retrieve context menu's selected user.");
|
||||
}
|
||||
|
||||
emit selectUser(userID);
|
||||
emit selectUser(userID, true);
|
||||
} catch (Exception const &e) {
|
||||
app().log().error(e.qwhat());
|
||||
}
|
||||
@ -242,15 +299,23 @@ void TrayIcon::setState(TrayIcon::State state, QString const &stateString, QStri
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] title The title.
|
||||
/// \param[in] message The message.
|
||||
//****************************************************************************************************************************************************
|
||||
void TrayIcon::showErrorPopupNotification(QString const &title, QString const &message) {
|
||||
// this->showMessage(title, message, loadIconFromSVG(":/qml/icons/ic-exclamation-circle-filled.svg", errorColor));
|
||||
this->showMessage(title, message, loadIconFromSVG(":/qml/icons/ic-alert.svg"));
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] svgPath The path of the SVG file for the icon.
|
||||
/// \param[in] color The color to apply to the icon.
|
||||
//****************************************************************************************************************************************************
|
||||
void TrayIcon::generateStatusIcon(QString const &svgPath, QColor const &color) {
|
||||
// We use the SVG path as pixmap mask and fill it with the appropriate color
|
||||
QString resourcePath = svgPath;
|
||||
resourcePath.replace(QRegularExpression(R"(^\.\/)"), ":/qml/"); // QML resource path are a bit different from the Qt resources path.
|
||||
QPixmap pixmap(resourcePath);
|
||||
QPixmap pixmap(qmlResourcePathToQt(svgPath));
|
||||
QPainter painter(&pixmap);
|
||||
painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
|
||||
painter.fillRect(pixmap.rect(), color);
|
||||
@ -259,9 +324,9 @@ void TrayIcon::generateStatusIcon(QString const &svgPath, QColor const &color) {
|
||||
}
|
||||
|
||||
|
||||
//**********************************************************************************************************************
|
||||
//****************************************************************************************************************************************************
|
||||
//
|
||||
//**********************************************************************************************************************
|
||||
//****************************************************************************************************************************************************
|
||||
void TrayIcon::refreshContextMenu() {
|
||||
if (!menu_) {
|
||||
app().log().error("Native tray icon context menu is null.");
|
||||
@ -294,3 +359,5 @@ void TrayIcon::refreshContextMenu() {
|
||||
menu_->addSeparator();
|
||||
menu_->addAction(tr("&Quit Bridge"), QKeySequence("Ctrl+Q"), &app().backend(), &QMLBackend::quit);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user