Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 85 additions & 25 deletions src/3rdparty/kmessagewidget/kmessagewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class KMessageWidgetPrivate
QFrame *content = nullptr;
QLabel *iconLabel = nullptr;
QLabel *textLabel = nullptr;
QLabel *titleLabel = nullptr;
QLabel *titelIcon = nullptr;
QToolButton *closeButton = nullptr;
QTimeLine *timeLine = nullptr;
QIcon icon;
Expand All @@ -49,6 +51,9 @@ class KMessageWidgetPrivate
void slotTimeLineFinished();

[[nodiscard]] int bestContentHeight() const;

private:
void applyNMCStylesheets() const;
};

void KMessageWidgetPrivate::init(KMessageWidget *q_ptr)
Expand All @@ -73,11 +78,24 @@ void KMessageWidgetPrivate::init(KMessageWidget *q_ptr)
iconLabel->hide();

textLabel = new QLabel(content);
textLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
textLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
textLabel->setFixedWidth(500);
textLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
QObject::connect(textLabel, &QLabel::linkActivated, q, &KMessageWidget::linkActivated);
QObject::connect(textLabel, &QLabel::linkHovered, q, &KMessageWidget::linkHovered);

// Titel-Label konfigurieren
titleLabel = new QLabel(content);
titleLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
titleLabel->setText(QCoreApplication::translate("", "E2E_ENCRYPTION"));
titleLabel->setStyleSheet("font-size: 13px; font-weight: 600;");

// Icon-Label konfigurieren
titelIcon = new QLabel(content);
titelIcon->setFixedSize(24, 24);
titelIcon->setPixmap(QIcon(QStringLiteral(":/client/theme/NMCIcons/cloud-security.svg")).pixmap(24, 24));
titelIcon->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

auto *closeAction = new QAction(q);
closeAction->setText(KMessageWidget::tr("&Close"));
closeAction->setToolTip(KMessageWidget::tr("Close message"));
Expand All @@ -86,8 +104,6 @@ void KMessageWidgetPrivate::init(KMessageWidget *q_ptr)
QObject::connect(closeAction, &QAction::triggered, q, &KMessageWidget::animatedHide);

closeButton = new QToolButton(content);
closeButton->setAutoRaise(true);
closeButton->setDefaultAction(closeAction);

q->setMessageType(KMessageWidget::Information);
}
Expand All @@ -104,37 +120,53 @@ void KMessageWidgetPrivate::createLayout()
Q_FOREACH (QAction *action, q->actions()) {
auto *button = new QToolButton(content);
button->setDefaultAction(action);
button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
button->setToolButtonStyle(Qt::ToolButtonTextOnly);
buttons.append(button);
}

// AutoRaise reduces visual clutter, but we don't want to turn it on if
// there are other buttons, otherwise the close button will look different
// from the others.
closeButton->setAutoRaise(buttons.isEmpty());
// closeButton->setAutoRaise(buttons.isEmpty());

if (wordWrap) {
// NMC customization: make sure we always enter the first case
if (true) {
auto *layout = new QGridLayout(content);
// Set alignment to make sure icon does not move down if text wraps
layout->addWidget(iconLabel, 0, 0, 1, 1, Qt::AlignHCenter | Qt::AlignTop);
layout->addWidget(textLabel, 0, 1);
layout->setContentsMargins(8, 4, 8, 4);
layout->setSpacing(0);
content->setFixedHeight(84);

auto *titleLayout = new QHBoxLayout();
titleLayout->setSpacing(8);
titleLayout->setContentsMargins(0, 0, 0, 0);
titleLayout->addWidget(titleLabel);
titleLayout->addWidget(titelIcon);

layout->addLayout(titleLayout, 0, 0, 1, 1, Qt::AlignLeft | Qt::AlignVCenter);

textLabel->setWordWrap(true);
layout->addWidget(textLabel, 1, 0);

auto *spacerItem = new QSpacerItem(1, 1, QSizePolicy::Fixed, QSizePolicy::Expanding);
layout->addItem(spacerItem, 2, 0);

if (buttons.isEmpty()) {
// Use top-vertical alignment like the icon does.
layout->addWidget(closeButton, 0, 2, 1, 1, Qt::AlignHCenter | Qt::AlignTop);
// layout->addWidget(closeButton, 0, 2, 1, 1, Qt::AlignHCenter | Qt::AlignTop);
} else {
// Use an additional layout in row 1 for the buttons.
auto *buttonLayout = new QHBoxLayout;
buttonLayout->addStretch();
auto *buttonLayout = new QVBoxLayout;
buttonLayout->setContentsMargins(0, 0, 0, 0);
buttonLayout->setSpacing(4);
Q_FOREACH (QToolButton *button, buttons) {
// For some reason, calling show() is necessary if wordwrap is true,
// otherwise the buttons do not show up. It is not needed if
// wordwrap is false.
button->show();
buttonLayout->addWidget(button);
}
buttonLayout->addWidget(closeButton);
layout->addItem(buttonLayout, 1, 0, 1, 2);
layout->addItem(buttonLayout, 0, 1, 3, 1, Qt::AlignRight);
applyNMCStylesheets();
}
} else {
auto *layout = new QHBoxLayout(content);
Expand All @@ -144,8 +176,6 @@ void KMessageWidgetPrivate::createLayout()
for (QToolButton *button : std::as_const(buttons)) {
layout->addWidget(button);
}

layout->addWidget(closeButton);
};

if (q->isVisible()) {
Expand All @@ -163,10 +193,10 @@ void KMessageWidgetPrivate::applyStyleSheet()
// The following RGB color values come from the "default" scheme in kcolorscheme.cpp
switch (messageType) {
case KMessageWidget::Positive:
bgBaseColor.setRgb(39, 174, 96); // Window: ForegroundPositive
bgBaseColor.setRgb(204, 250, 225); // Window: ForegroundPositive
break;
case KMessageWidget::Information:
bgBaseColor.setRgb(61, 174, 233); // Window: ForegroundActive
bgBaseColor.setRgb(211, 215, 249); // Window: ForegroundActive
break;
case KMessageWidget::Warning:
bgBaseColor.setRgb(246, 116, 0); // Window: ForegroundNeutral
Expand All @@ -175,13 +205,11 @@ void KMessageWidgetPrivate::applyStyleSheet()
bgBaseColor.setRgb(218, 68, 83); // Window: ForegroundNegative
break;
}
const qreal bgBaseColorAlpha = 0.2;
const qreal bgBaseColorAlpha = 1.0;
bgBaseColor.setAlphaF(bgBaseColorAlpha);

const QPalette palette = QGuiApplication::palette();
const QColor windowColor = palette.window().color();
const QColor textColor = palette.text().color();
const QColor border = bgBaseColor;

// Generate a final background color from overlaying bgBaseColor over windowColor
const int newRed = qRound(bgBaseColor.red() * bgBaseColorAlpha) + qRound(windowColor.red() * (1 - bgBaseColorAlpha));
Expand All @@ -197,14 +225,15 @@ void KMessageWidgetPrivate::applyStyleSheet()
"border: 2px solid %2;"
"margin: %3px;"
"}"
".QLabel { color: %4; }"
".QLabel { color: black; }"
)
.arg(bgFinalColor.name())
.arg(border.name())
.arg(bgFinalColor.name())
// DefaultFrameWidth returns the size of the external margin + border width. We know our border is 1px, so we subtract this from the frame normal QStyle FrameWidth to get our margin
.arg(q->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, q) - 1)
.arg(textColor.name())
);

applyNMCStylesheets();
}

void KMessageWidgetPrivate::updateLayout()
Expand Down Expand Up @@ -258,6 +287,36 @@ int KMessageWidgetPrivate::bestContentHeight() const
return height;
}

void KMessageWidgetPrivate::applyNMCStylesheets() const
{
// Set button color and size
if (!buttons.empty()) {
const QString stylesheet = QStringLiteral(
"QToolButton{width: 180px; height: 32px; border-radius: 4px; font-size: %1px; color: %2; background-color: %3;} "
"QToolButton:hover { background-color: %4;}"
);

switch (messageType) {
case KMessageWidget::Positive:
for (QToolButton *button : buttons) {
button->setStyleSheet(stylesheet.arg("13", "white", "#00b367", "#00a461"));
}
break;
case KMessageWidget::Information:
for (QToolButton *button : buttons) {
button->setStyleSheet(stylesheet.arg("13", "white", "#216bff", "#0819bd"));
}
break;
case KMessageWidget::Warning:
// Optional: Add styling here if needed
break;
case KMessageWidget::Error:
// Optional: Add styling here if needed
break;
}
}
}

//---------------------------------------------------------------------
// KMessageWidget
//---------------------------------------------------------------------
Expand Down Expand Up @@ -383,7 +442,8 @@ bool KMessageWidget::isCloseButtonVisible() const

void KMessageWidget::setCloseButtonVisible(bool show)
{
d->closeButton->setVisible(show);
Q_UNUSED(show)
d->closeButton->setVisible(false);
updateGeometry();
}

Expand Down
27 changes: 7 additions & 20 deletions src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,7 @@ void AccountSettings::slotE2eEncryptionMnemonicReady()
}

_ui->encryptionMessage->setMessageType(KMessageWidget::Positive);
_ui->encryptionMessage->setText(tr("Encryption is set-up. Remember to <b>Encrypt</b> a folder to end-to-end encrypt any new files added to it."));
_ui->encryptionMessage->setIcon(Theme::createColorAwareIcon(QStringLiteral(":/client/theme/lock.svg")));
_ui->encryptionMessage->setText(QCoreApplication::translate("", "E2E_ENCRYPTION_ACTIVE"));
_ui->encryptionMessage->show();
}

Expand Down Expand Up @@ -410,8 +409,7 @@ bool AccountSettings::canEncryptOrDecrypt(const FolderStatusModel::SubFolderInfo

if (!_accountState->account()->e2e() || !_accountState->account()->e2e()->isInitialized()) {
QMessageBox msgBox;
msgBox.setText(tr("You cannot encrypt this folder because the end-to-end encryption is not set-up yet on this device.\n"
"Would you like to do this now?"));
msgBox.setText(QCoreApplication::translate("", "E2E_MNEMONIC_TEXT2"));
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
const auto ret = msgBox.exec();
Expand Down Expand Up @@ -1093,17 +1091,12 @@ void AccountSettings::displayMnemonic(const QString &mnemonic)
Ui_Dialog ui{};
ui.setupUi(&widget);
widget.setWindowTitle(tr("End-to-end encryption mnemonic"));
ui.label->setText(
tr("To protect your Cryptographic Identity, we encrypt it with a mnemonic of 12 dictionary words. "
"Please note it down and keep it safe. "
"You will need it to set-up the synchronization of encrypted folders on your other devices."));
QFont monoFont(QStringLiteral("Monospace"));
monoFont.setStyleHint(QFont::TypeWriter);
ui.lineEdit->setFont(monoFont);
widget.setWindowFlags(Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
ui.label->setText(QCoreApplication::translate("", "E2E_MNEMONIC_TEXT"));
ui.lineEdit->setText(mnemonic);
ui.lineEdit->setReadOnly(true);

ui.lineEdit->setStyleSheet(QStringLiteral("QLineEdit{ color: black; background: lightgrey; border-style: inset;}"));
ui.lineEdit->setStyleSheet(QStringLiteral("QLineEdit{ color: black; background: lightgrey; border-style: inset; padding: 5px;}"));

ui.lineEdit->focusWidget();
ui.lineEdit->selectAll();
Expand All @@ -1120,10 +1113,7 @@ void AccountSettings::forgetEncryptionOnDeviceForAccount(const AccountPtr &accou
{
QMessageBox dialog;
dialog.setWindowTitle(tr("Forget the end-to-end encryption on this device"));
dialog.setText(tr("Do you want to forget the end-to-end encryption settings for %1 on this device?").arg(account->davUser()));
dialog.setInformativeText(tr("Forgetting end-to-end encryption will remove the sensitive data and all the encrypted files from this device."
"<br>"
"However, the encrypted files will remain on the server and all your other devices, if configured."));
dialog.setText(QCoreApplication::translate("", "E2E_MNEMONIC_TEXT4"));
dialog.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
dialog.setDefaultButton(QMessageBox::Ok);
dialog.adjustSize();
Expand Down Expand Up @@ -1692,9 +1682,7 @@ void AccountSettings::setupE2eEncryption()

connect(_accountState->account()->e2e(), &ClientSideEncryption::initializationFinished, this, [this] {
if (!_accountState->account()->e2e()->getPublicKey().isNull()) {
_ui->encryptionMessage->setText(tr("End-to-end encryption has been initialized on this account with another device."
"<br>"
"Enter the unique mnemonic to have the encrypted folders synchronize on this device as well."));
_ui->encryptionMessage->setText(QCoreApplication::translate("", "E2E_ENCRYPTION_START"));
}
});
_accountState->account()->setE2eEncryptionKeysGenerationAllowed(false);
Expand Down Expand Up @@ -1751,7 +1739,6 @@ void AccountSettings::setupE2eEncryptionMessage()
{
_ui->encryptionMessage->setMessageType(KMessageWidget::Information);
_ui->encryptionMessage->setText(tr("This account supports end-to-end encryption, but it needs to be set up first."));
_ui->encryptionMessage->setIcon(Theme::createColorAwareIcon(QStringLiteral(":/client/theme/info.svg")));
_ui->encryptionMessage->hide();

auto *const actionSetupE2e = addActionToEncryptionMessage(tr("Set up encryption"), e2EeUiActionSetupEncryptionId);
Expand Down
10 changes: 5 additions & 5 deletions src/gui/socketapi/socketapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,20 +556,20 @@ void SocketApi::processEncryptRequest(const QString &localFile)

auto job = new OCC::EncryptFolderJob(account, folder->journalDb(), choppedPath, choppedPath, folder->remotePath(), rec.numericFileId());
job->setParent(this);
connect(job, &OCC::EncryptFolderJob::finished, this, [fileData, job](const int status) {
connect(job, &OCC::EncryptFolderJob::finished, this, [fileData, account](const int status) {
if (status == OCC::EncryptFolderJob::Error) {
const int ret = QMessageBox::critical(
nullptr,
tr("Failed to encrypt folder"),
tr("Could not encrypt the following folder: \"%1\".\n\n"
"Server replied with error: %2").arg(fileData.folderRelativePath, job->errorString()),
QCoreApplication::translate("", "E2E_MNEMONIC_TEXT3").arg(account->prettyName()),
QMessageBox::Ok
);
Q_UNUSED(ret)
} else {
const int ret = QMessageBox::information(nullptr,
tr("Folder encrypted successfully").arg(fileData.folderRelativePath),
tr("The following folder was encrypted successfully: \"%1\"").arg(fileData.folderRelativePath));
tr("Folder encrypted successfully"),
tr("The following folder was encrypted successfully: \"%1\"")
.arg(fileData.folderRelativePath));
Q_UNUSED(ret)
}
});
Expand Down
10 changes: 3 additions & 7 deletions src/libsync/clientsideencryption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2272,15 +2272,11 @@ void ClientSideEncryption::decryptPrivateKey(const QByteArray &key) {
return;
}

QString msg = tr("Please enter your end-to-end encryption passphrase:<br>"
"<br>"
"Username: %2<br>"
"Account: %3<br>")
.arg(Utility::escape(_account->credentials()->user()),
Utility::escape(_account->displayName()));
QString msg = QCoreApplication::translate("", "E2E_MNEMONIC_PASSPHRASE");

QInputDialog dialog;
dialog.setWindowTitle(tr("Enter E2E passphrase"));
dialog.setWindowTitle(tr(""));
dialog.setWindowFlags(Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
dialog.setLabelText(msg);
dialog.setTextEchoMode(QLineEdit::Normal);

Expand Down
Loading