Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
KMail
Commits
eceec032
Commit
eceec032
authored
Sep 21, 2020
by
Laurent Montel
😁
Browse files
Use new widget
parent
c6cc5c52
Pipeline
#35063
canceled with stage
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/collectionpage/collectiontemplatespage.cpp
View file @
eceec032
...
...
@@ -5,6 +5,7 @@
*/
#include
"collectiontemplatespage.h"
#include
"collectiontemplateswidget.h"
#include
<MailCommon/MailKernel>
#include
<MailCommon/FolderSettings>
...
...
@@ -13,8 +14,6 @@
#include
<AkonadiCore/collection.h>
#include
<KLocalizedString>
#include
<QPushButton>
#include
<QCheckBox>
using
namespace
Akonadi
;
using
namespace
MailCommon
;
...
...
@@ -40,78 +39,18 @@ bool CollectionTemplatesPage::canHandle(const Collection &collection) const
void
CollectionTemplatesPage
::
init
()
{
QVBoxLayout
*
topLayout
=
new
QVBoxLayout
(
this
);
QHBoxLayout
*
topItems
=
new
QHBoxLayout
;
topItems
->
setContentsMargins
(
0
,
0
,
0
,
0
);
topLayout
->
addLayout
(
topItems
);
mCustom
=
new
QCheckBox
(
i18n
(
"&Use custom message templates in this folder"
),
this
);
connect
(
mCustom
,
&
QCheckBox
::
clicked
,
this
,
&
CollectionTemplatesPage
::
slotChanged
);
topItems
->
addWidget
(
mCustom
,
Qt
::
AlignLeft
);
mWidget
=
new
TemplateParser
::
TemplatesConfiguration
(
this
,
QStringLiteral
(
"folder-templates"
));
connect
(
mWidget
,
&
TemplateParser
::
TemplatesConfiguration
::
changed
,
this
,
&
CollectionTemplatesPage
::
slotChanged
);
mWidget
->
setEnabled
(
false
);
// Move the help label outside of the templates configuration widget,
// so that the help can be read even if the widget is not enabled.
topItems
->
addStretch
(
9
);
topItems
->
addWidget
(
mWidget
->
helpLabel
(),
Qt
::
AlignRight
);
topLayout
->
addWidget
(
mWidget
);
QHBoxLayout
*
btns
=
new
QHBoxLayout
();
QPushButton
*
copyGlobal
=
new
QPushButton
(
i18n
(
"&Copy Global Templates"
),
this
);
copyGlobal
->
setEnabled
(
false
);
btns
->
addWidget
(
copyGlobal
);
topLayout
->
addLayout
(
btns
);
connect
(
mCustom
,
&
QCheckBox
::
toggled
,
mWidget
,
&
TemplateParser
::
TemplatesConfiguration
::
setEnabled
);
connect
(
mCustom
,
&
QCheckBox
::
toggled
,
copyGlobal
,
&
QPushButton
::
setEnabled
);
connect
(
copyGlobal
,
&
QPushButton
::
clicked
,
this
,
&
CollectionTemplatesPage
::
slotCopyGlobal
);
topLayout
->
setContentsMargins
({});
mCollectionTemplateWidget
=
new
CollectionTemplatesWidget
(
this
);
topLayout
->
addWidget
(
mCollectionTemplateWidget
);
}
void
CollectionTemplatesPage
::
load
(
const
Collection
&
col
)
{
const
QSharedPointer
<
FolderSettings
>
fd
=
FolderSettings
::
forCollection
(
col
,
false
);
if
(
!
fd
)
{
return
;
}
mCollectionId
=
QString
::
number
(
col
.
id
());
TemplateParser
::
Templates
t
(
mCollectionId
);
mCustom
->
setChecked
(
t
.
useCustomTemplates
());
mIdentity
=
fd
->
identity
();
mWidget
->
loadFromFolder
(
mCollectionId
,
mIdentity
);
mChanged
=
false
;
}
void
CollectionTemplatesPage
::
save
(
Collection
&
)
{
if
(
mChanged
&&
!
mCollectionId
.
isEmpty
())
{
TemplateParser
::
Templates
t
(
mCollectionId
);
//qCDebug(KMAIL_LOG) << "use custom templates for folder" << fid <<":" << mCustom->isChecked();
t
.
setUseCustomTemplates
(
mCustom
->
isChecked
());
t
.
save
();
mWidget
->
saveToFolder
(
mCollectionId
);
}
mCollectionTemplateWidget
->
load
(
col
);
}
void
CollectionTemplatesPage
::
s
lotCopyGlobal
(
)
void
CollectionTemplatesPage
::
s
ave
(
Collection
&
col
)
{
if
(
mIdentity
)
{
mWidget
->
loadFromIdentity
(
mIdentity
);
}
else
{
mWidget
->
loadFromGlobal
();
}
mCollectionTemplateWidget
->
save
(
col
);
}
void
CollectionTemplatesPage
::
slotChanged
()
{
mChanged
=
true
;
}
src/collectionpage/collectiontemplatespage.h
View file @
eceec032
...
...
@@ -8,11 +8,7 @@
#define COLLECTIONTEMPLATESPAGE_H
#include
<AkonadiWidgets/collectionpropertiespage.h>
class
QCheckBox
;
namespace
TemplateParser
{
class
TemplatesConfiguration
;
}
class
CollectionTemplatesWidget
;
template
<
typename
T
>
class
QSharedPointer
;
class
CollectionTemplatesPage
:
public
Akonadi
::
CollectionPropertiesPage
...
...
@@ -30,11 +26,7 @@ private:
void
slotCopyGlobal
();
void
slotChanged
();
void
init
();
QCheckBox
*
mCustom
=
nullptr
;
TemplateParser
::
TemplatesConfiguration
*
mWidget
=
nullptr
;
QString
mCollectionId
;
uint
mIdentity
=
0
;
bool
mChanged
=
false
;
CollectionTemplatesWidget
*
mCollectionTemplateWidget
=
nullptr
;
};
AKONADI_COLLECTION_PROPERTIES_PAGE_FACTORY
(
CollectionTemplatesPageFactory
,
CollectionTemplatesPage
)
...
...
src/collectionpage/collectiontemplateswidget.cpp
View file @
eceec032
...
...
@@ -9,7 +9,9 @@
#include
<KLocalizedString>
#include
"templatesconfiguration_kfg.h"
#include
<MailCommon/FolderSettings>
#include
<QCheckBox>
#include
<QSharedPointer>
#include
<QVBoxLayout>
#include
<TemplateParser/TemplatesConfiguration>
...
...
@@ -53,7 +55,7 @@ CollectionTemplatesWidget::~CollectionTemplatesWidget()
}
void
CollectionTemplatesWidget
::
save
(
const
Akonadi
::
Collection
&
collection
)
void
CollectionTemplatesWidget
::
save
(
const
Akonadi
::
Collection
&
)
{
if
(
mChanged
&&
!
mCollectionId
.
isEmpty
())
{
TemplateParser
::
Templates
t
(
mCollectionId
);
...
...
@@ -78,3 +80,22 @@ void CollectionTemplatesWidget::slotChanged()
{
mChanged
=
true
;
}
void
CollectionTemplatesWidget
::
load
(
const
Akonadi
::
Collection
&
col
)
{
const
QSharedPointer
<
MailCommon
::
FolderSettings
>
fd
=
MailCommon
::
FolderSettings
::
forCollection
(
col
,
false
);
if
(
!
fd
)
{
return
;
}
mCollectionId
=
QString
::
number
(
col
.
id
());
TemplateParser
::
Templates
t
(
mCollectionId
);
mCustom
->
setChecked
(
t
.
useCustomTemplates
());
mIdentity
=
fd
->
identity
();
mWidget
->
loadFromFolder
(
mCollectionId
,
mIdentity
);
mChanged
=
false
;
}
src/collectionpage/collectiontemplateswidget.h
View file @
eceec032
...
...
@@ -21,7 +21,8 @@ class CollectionTemplatesWidget : public QWidget
public:
explicit
CollectionTemplatesWidget
(
QWidget
*
parent
=
nullptr
);
~
CollectionTemplatesWidget
();
void
save
(
const
Akonadi
::
Collection
&
collection
);
void
save
(
const
Akonadi
::
Collection
&
);
void
load
(
const
Akonadi
::
Collection
&
col
);
private:
void
slotCopyGlobal
();
void
slotChanged
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment