Commit c8914a7b authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Allow to custom file name

parent a5724bb4
......@@ -39,7 +39,7 @@ set(PIMCOMMON_LIB_VERSION "5.13.42")
set(AKONADI_VERSION "5.13.41")
set(AKONADIMIME_LIB_VERSION "5.13.40")
set(MESSAGELIB_LIB_VERSION "5.13.40")
set(MESSAGELIB_LIB_VERSION "5.13.46")
set(KMIME_LIB_VERSION "5.13.40")
set(KMAILTRANSPORT_LIB_VERSION "5.13.40")
set(MAILIMPORTER_LIB_VERSION "5.13.40")
......
......@@ -20,6 +20,7 @@
#include "snippetcustomfileattachmentnamewidgettest.h"
#include "snippets/snippetcustomfileattachmentnamewidget.h"
#include <QLineEdit>
#include <QPushButton>
#include <QTest>
#include <QVBoxLayout>
QTEST_MAIN(SnippetCustomFileAttachmentNameWidgetTest)
......@@ -41,4 +42,9 @@ void SnippetCustomFileAttachmentNameWidgetTest::shouldHaveDefaultValues()
QLineEdit *mLineEdit = w.findChild<QLineEdit *>(QStringLiteral("mLineEdit"));
QVERIFY(mLineEdit);
QVERIFY(mLineEdit->text().isEmpty());
QPushButton *selectVariable = w.findChild<QPushButton *>(QStringLiteral("selectVariable"));
QVERIFY(selectVariable);
QVERIFY(!selectVariable->text().isEmpty());
QVERIFY(selectVariable->menu());
}
......@@ -55,3 +55,8 @@ QString SnippetCustomFileAttachmentNameDialog::result() const
{
return mCustomWidget->result();
}
void SnippetCustomFileAttachmentNameDialog::setText(const QString &str)
{
mCustomWidget->setText(str);
}
......@@ -37,6 +37,8 @@ public:
Q_REQUIRED_RESULT QString result() const;
void setText(const QString &str);
private:
SnippetCustomFileAttachmentNameWidget *mCustomWidget = nullptr;
};
......
......@@ -18,9 +18,12 @@
*/
#include "snippetcustomfileattachmentnamewidget.h"
#include <MessageComposer/ConvertSnippetVariableMenu>
#include <MessageComposer/ConvertSnippetVariablesJob>
#include <QHBoxLayout>
#include <KLocalizedString>
#include <QLineEdit>
#include <QPushButton>
using namespace MailCommon;
SnippetCustomFileAttachmentNameWidget::SnippetCustomFileAttachmentNameWidget(QWidget *parent)
: QWidget(parent)
......@@ -32,6 +35,15 @@ SnippetCustomFileAttachmentNameWidget::SnippetCustomFileAttachmentNameWidget(QWi
mLineEdit = new QLineEdit(this);
mLineEdit->setObjectName(QStringLiteral("mLineEdit"));
mainLayout->addWidget(mLineEdit);
mConvertMenu = new MessageComposer::ConvertSnippetVariableMenu(true, mLineEdit, this);
mConvertMenu->setObjectName(QStringLiteral("mConvertMenu"));
connect(mConvertMenu, &MessageComposer::ConvertSnippetVariableMenu::insertVariable, this, &SnippetCustomFileAttachmentNameWidget::insertVariable);
QPushButton *selectVariable = new QPushButton(i18n("Variables"), this);
selectVariable->setObjectName(QStringLiteral("selectVariable"));
selectVariable->setMenu(mConvertMenu->menu());
mainLayout->addWidget(selectVariable);
}
SnippetCustomFileAttachmentNameWidget::~SnippetCustomFileAttachmentNameWidget()
......@@ -39,8 +51,18 @@ SnippetCustomFileAttachmentNameWidget::~SnippetCustomFileAttachmentNameWidget()
}
void SnippetCustomFileAttachmentNameWidget::insertVariable(MessageComposer::ConvertSnippetVariablesUtil::VariableType variable)
{
mLineEdit->insert(MessageComposer::ConvertSnippetVariablesJob::convertVariables(nullptr, MessageComposer::ConvertSnippetVariablesUtil::snippetVariableFromEnum(variable)));
}
QString SnippetCustomFileAttachmentNameWidget::result() const
{
return mLineEdit->text();
}
void SnippetCustomFileAttachmentNameWidget::setText(const QString &str)
{
mLineEdit->setText(str);
}
......@@ -22,8 +22,11 @@
#include <QWidget>
#include "mailcommon_private_export.h"
#include <MessageComposer/ConvertSnippetVariablesUtil>
class QLineEdit;
namespace MessageComposer {
class ConvertSnippetVariableMenu;
}
namespace MailCommon {
class MAILCOMMON_TESTS_EXPORT SnippetCustomFileAttachmentNameWidget : public QWidget
......@@ -33,8 +36,11 @@ public:
explicit SnippetCustomFileAttachmentNameWidget(QWidget *parent = nullptr);
~SnippetCustomFileAttachmentNameWidget();
Q_REQUIRED_RESULT QString result() const;
void setText(const QString &str);
private:
void insertVariable(MessageComposer::ConvertSnippetVariablesUtil::VariableType variable);
QLineEdit *mLineEdit = nullptr;
MessageComposer::ConvertSnippetVariableMenu *mConvertMenu = nullptr;
};
}
......
......@@ -19,10 +19,12 @@
*/
#include "snippetselectattachmentwidget.h"
#include "snippetcustomfileattachmentnamedialog.h"
#include <PimCommon/SimpleStringListEditor>
#include <QVBoxLayout>
#include <QFileDialog>
#include <KLocalizedString>
#include <QPointer>
using namespace MailCommon;
SnippetSelectAttachmentWidget::SnippetSelectAttachmentWidget(QWidget *parent)
......@@ -73,6 +75,10 @@ void SnippetSelectorWidget::addNewEntry()
QString SnippetSelectorWidget::customEntry(const QString &text)
{
//TODO
QPointer<SnippetCustomFileAttachmentNameDialog> dlg = new SnippetCustomFileAttachmentNameDialog(this);
dlg->setText(text);
if (dlg->exec()) {
return dlg->result();
}
return {};
}
......@@ -51,7 +51,7 @@ SnippetWidget::SnippetWidget(QWidget *parent)
d->mUi.setupUi(d->wdg);
layout->addWidget(d->wdg);
MessageComposer::ConvertSnippetVariableMenu *variableMenu = new MessageComposer::ConvertSnippetVariableMenu(this, this);
MessageComposer::ConvertSnippetVariableMenu *variableMenu = new MessageComposer::ConvertSnippetVariableMenu(false, this, this);
d->mUi.pushButtonVariables->setMenu(variableMenu->menu());
connect(variableMenu, &MessageComposer::ConvertSnippetVariableMenu::insertVariable, this, [this](MessageComposer::ConvertSnippetVariablesUtil::VariableType type) {
d->mUi.snippetText->editor()->insertPlainText(MessageComposer::ConvertSnippetVariablesUtil::snippetVariableFromEnum(type) + QLatin1Char(' '));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment