Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
libksieve
Commits
0922cd3e
Commit
0922cd3e
authored
Jun 23, 2017
by
Laurent Montel
Browse files
Fix load variable locale
parent
aaf364b8
Changes
9
Hide whitespace changes
Inline
Side-by-side
src/ksieveui/autocreatescripts/sieveactions/sieveactionsetvariable.cpp
View file @
0922cd3e
...
...
@@ -81,6 +81,14 @@ QUrl SieveActionSetVariable::href() const
return
SieveEditorUtil
::
helpUrl
(
SieveEditorUtil
::
strToVariableName
(
name
()));
}
void
SieveActionSetVariable
::
setLocalVariable
(
QWidget
*
w
,
const
SieveGlobalVariableActionWidget
::
VariableElement
&
var
)
{
QLineEdit
*
value
=
w
->
findChild
<
QLineEdit
*>
(
QStringLiteral
(
"value"
));
value
->
setText
(
var
.
variableValue
);
QLineEdit
*
variable
=
w
->
findChild
<
QLineEdit
*>
(
QStringLiteral
(
"variable"
));
variable
->
setText
(
AutoCreateScriptUtil
::
protectSlash
(
var
.
variableName
));
}
bool
SieveActionSetVariable
::
setParamWidgetValue
(
QXmlStreamReader
&
element
,
QWidget
*
w
,
QString
&
error
)
{
while
(
element
.
readNextStartElement
())
{
...
...
src/ksieveui/autocreatescripts/sieveactions/sieveactionsetvariable.h
View file @
0922cd3e
...
...
@@ -20,6 +20,7 @@
#define SIEVEACTIONSETVARIABLE_H
#include
"sieveaction.h"
#include
<autocreatescripts/sieveglobalvariablewidget.h>
namespace
KSieveUi
{
class
SieveActionSetVariable
:
public
SieveAction
{
...
...
@@ -34,6 +35,7 @@ public:
QString
serverNeedsCapability
()
const
override
;
QWidget
*
createParamWidget
(
QWidget
*
parent
)
const
override
;
QUrl
href
()
const
override
;
void
setLocalVariable
(
QWidget
*
w
,
const
SieveGlobalVariableActionWidget
::
VariableElement
&
var
);
private:
bool
mHasRegexCapability
;
};
...
...
src/ksieveui/autocreatescripts/sieveactionwidgetlister.cpp
View file @
0922cd3e
...
...
@@ -38,6 +38,8 @@
#include
<QWhatsThis>
#include
<QDomElement>
#include
<autocreatescripts/sieveactions/sieveactionsetvariable.h>
using
namespace
KSieveUi
;
static
int
MINIMUMACTION
=
1
;
...
...
@@ -259,6 +261,23 @@ void SieveActionWidget::updateAddRemoveButton(bool addButtonEnabled, bool remove
mRemove
->
setEnabled
(
removeButtonEnabled
);
}
void
SieveActionWidget
::
setLocaleVariable
(
const
SieveGlobalVariableActionWidget
::
VariableElement
&
var
)
{
const
int
index
=
mComboBox
->
findData
(
QStringLiteral
(
"set"
));
if
(
index
!=
-
1
)
{
mComboBox
->
setCurrentIndex
(
index
);
slotActionChanged
(
index
);
KSieveUi
::
SieveActionSetVariable
*
localVar
=
dynamic_cast
<
KSieveUi
::
SieveActionSetVariable
*>
(
mActionList
.
at
(
index
));
if
(
localVar
)
{
localVar
->
setLocalVariable
(
this
,
var
);
}
}
else
{
//error += i18n("Script contains unsupported feature \"%1\"", actionName) + QLatin1Char('\n');
//qCDebug(LIBKSIEVE_LOG) << "Condition " << actionName << " not supported";
}
}
bool
SieveActionWidget
::
setAction
(
const
QString
&
actionName
,
QXmlStreamReader
&
element
,
const
QString
&
comment
,
QString
&
error
)
{
const
int
index
=
mComboBox
->
findData
(
actionName
);
...
...
@@ -363,6 +382,17 @@ int SieveActionWidgetLister::actionNumber() const
return
widgets
().
count
();
}
void
SieveActionWidgetLister
::
loadLocalVariable
(
const
SieveGlobalVariableActionWidget
::
VariableElement
&
var
)
{
SieveActionWidget
*
w
=
qobject_cast
<
SieveActionWidget
*>
(
widgets
().
constLast
());
if
(
w
->
isConfigurated
())
{
addWidgetAfterThisWidget
(
widgets
().
constLast
());
w
=
qobject_cast
<
SieveActionWidget
*>
(
widgets
().
constLast
());
}
w
->
setLocaleVariable
(
var
);
}
void
SieveActionWidgetLister
::
loadScript
(
QXmlStreamReader
&
element
,
bool
onlyActions
,
QString
&
error
)
{
QString
comment
;
...
...
src/ksieveui/autocreatescripts/sieveactionwidgetlister.h
View file @
0922cd3e
...
...
@@ -21,7 +21,7 @@
#define SIEVEACTIONWIDGETLISTER_H
#include
<Libkdepim/KWidgetLister>
#include
"sieveglobalvariablewidget.h"
class
QPushButton
;
class
QGridLayout
;
...
...
@@ -49,6 +49,8 @@ public:
bool
isConfigurated
()
const
;
void
clear
();
void
setLocaleVariable
(
const
SieveGlobalVariableActionWidget
::
VariableElement
&
var
);
private
Q_SLOTS
:
void
slotAddWidget
();
void
slotRemoveWidget
();
...
...
@@ -87,6 +89,7 @@ public:
int
actionNumber
()
const
;
void
loadLocalVariable
(
const
SieveGlobalVariableActionWidget
::
VariableElement
&
var
);
public
Q_SLOTS
:
void
slotAddWidget
(
QWidget
*
w
);
void
slotRemoveWidget
(
QWidget
*
w
);
...
...
src/ksieveui/autocreatescripts/sieveglobalvariablewidget.cpp
View file @
0922cd3e
...
...
@@ -203,7 +203,7 @@ void SieveGlobalVariableWidget::loadScript(QXmlStreamReader &element, QString &e
mIncludeLister
->
loadScript
(
element
,
error
);
}
bool
SieveGlobalVariableWidget
::
loadSetVariable
(
QXmlStreamReader
&
element
,
QString
&
error
)
SieveGlobalVariableActionWidget
::
VariableElement
SieveGlobalVariableWidget
::
loadSetVariable
(
QXmlStreamReader
&
element
,
QString
&
error
)
{
return
mIncludeLister
->
loadSetVariable
(
element
,
error
);
}
...
...
@@ -300,8 +300,9 @@ void SieveGlobalVariableLister::loadScript(QXmlStreamReader &element, QString &e
w
->
loadScript
(
element
,
error
);
}
bool
SieveGlobalVariableLister
::
loadSetVariable
(
QXmlStreamReader
&
element
,
QString
&
/*error*/
)
SieveGlobalVariableActionWidget
::
VariableElement
SieveGlobalVariableLister
::
loadSetVariable
(
QXmlStreamReader
&
element
,
QString
&
/*error*/
)
{
SieveGlobalVariableActionWidget
::
VariableElement
var
;
QString
variableName
;
QString
variableValue
;
int
index
=
0
;
...
...
@@ -330,5 +331,9 @@ bool SieveGlobalVariableLister::loadSetVariable(QXmlStreamReader &element, QStri
globalVariableFound
=
true
;
}
}
return
globalVariableFound
;
if
(
!
globalVariableFound
)
{
var
.
variableName
=
variableName
;
var
.
variableValue
=
variableValue
;
}
return
var
;
}
src/ksieveui/autocreatescripts/sieveglobalvariablewidget.h
View file @
0922cd3e
...
...
@@ -37,6 +37,14 @@ class SieveGlobalVariableActionWidget : public QWidget
{
Q_OBJECT
public:
struct
VariableElement
{
QString
variableName
;
QString
variableValue
;
bool
isValid
()
const
{
return
!
variableName
.
isEmpty
();
}
};
explicit
SieveGlobalVariableActionWidget
(
QWidget
*
parent
=
nullptr
);
~
SieveGlobalVariableActionWidget
();
...
...
@@ -76,7 +84,7 @@ public:
void
generatedScript
(
QString
&
script
,
QStringList
&
requires
);
void
loadScript
(
QXmlStreamReader
&
element
,
QString
&
error
);
bool
loadSetVariable
(
QXmlStreamReader
&
element
,
QString
&
error
);
SieveGlobalVariableActionWidget
::
VariableElement
loadSetVariable
(
QXmlStreamReader
&
element
,
QString
&
error
);
Q_SIGNALS:
void
valueChanged
();
...
...
@@ -103,7 +111,7 @@ public:
void
generatedScript
(
QString
&
script
,
QStringList
&
requires
,
bool
inForEveryPartLoop
)
override
;
void
loadScript
(
QXmlStreamReader
&
element
,
QString
&
error
);
bool
loadSetVariable
(
QXmlStreamReader
&
element
,
QString
&
error
);
SieveGlobalVariableActionWidget
::
VariableElement
loadSetVariable
(
QXmlStreamReader
&
element
,
QString
&
error
);
private
Q_SLOTS
:
void
slotHelp
();
...
...
src/ksieveui/autocreatescripts/sievescriptblockwidget.cpp
View file @
0922cd3e
...
...
@@ -246,6 +246,13 @@ void SieveScriptBlockWidget::updateCondition()
updateWidget
();
}
void
SieveScriptBlockWidget
::
loadLocalVariable
(
const
SieveGlobalVariableActionWidget
::
VariableElement
&
var
)
{
mScriptActionLister
->
loadLocalVariable
(
var
);
mMatchCondition
=
AllCondition
;
updateCondition
();
}
void
SieveScriptBlockWidget
::
loadScript
(
QXmlStreamReader
&
element
,
bool
onlyActions
,
QString
&
error
)
{
if
(
onlyActions
)
{
...
...
src/ksieveui/autocreatescripts/sievescriptblockwidget.h
View file @
0922cd3e
...
...
@@ -21,6 +21,7 @@
#define SIEVESCRIPTBLOCKWIDGET_H
#include
"sievewidgetpageabstract.h"
#include
"sieveglobalvariablewidget.h"
class
QRadioButton
;
class
QGroupBox
;
...
...
@@ -55,6 +56,7 @@ public:
void
loadScript
(
QXmlStreamReader
&
element
,
bool
onlyActions
,
QString
&
error
);
void
loadLocalVariable
(
const
SieveGlobalVariableActionWidget
::
VariableElement
&
var
);
Q_SIGNALS:
void
addNewBlock
(
QWidget
*
widget
,
KSieveUi
::
SieveWidgetPageAbstract
::
PageType
type
);
...
...
src/ksieveui/autocreatescripts/sievescriptlistbox.cpp
View file @
0922cd3e
...
...
@@ -409,6 +409,7 @@ void SieveScriptListBox::loadBlock(QXmlStreamReader &n, SieveScriptPage *current
bool
previousElementWasAComment
=
false
;
while
(
n
.
readNextStartElement
())
{
const
QStringRef
tagName
=
n
.
name
();
//qDebug() <<"SieveScriptListBox::loadBlock tagName " << tagName;
if
(
tagName
==
QLatin1String
(
"control"
))
{
previousElementWasAComment
=
false
;
//Create a new page when before it was "onlyactions"
...
...
@@ -489,6 +490,7 @@ void SieveScriptListBox::loadBlock(QXmlStreamReader &n, SieveScriptPage *current
}
comment
+=
str
;
}
//qDebug() << " COMMENT " << comment;
}
else
if
(
tagName
==
QLatin1String
(
"action"
))
{
previousElementWasAComment
=
false
;
if
(
n
.
attributes
().
hasAttribute
(
QStringLiteral
(
"name"
)))
{
...
...
@@ -516,15 +518,17 @@ void SieveScriptListBox::loadBlock(QXmlStreamReader &n, SieveScriptPage *current
qCDebug
(
LIBKSIEVE_LOG
)
<<
" globalVariable not supported"
;
}
}
else
if
(
actionName
==
QLatin1String
(
"set"
)
&&
(
typeBlock
==
TypeBlockGlobal
))
{
//FIXME global not global variable.
if
(
currentPage
->
globalVariableWidget
())
{
if
(
!
currentPage
->
globalVariableWidget
()
->
loadSetVariable
(
n
,
error
))
{
const
SieveGlobalVariableActionWidget
::
VariableElement
var
=
currentPage
->
globalVariableWidget
()
->
loadSetVariable
(
n
,
error
);
if
(
var
.
isValid
())
{
qCDebug
(
LIBKSIEVE_LOG
)
<<
"It's not a global variable"
;
if
(
!
currentPage
||
(
typeBlock
==
TypeBlockIf
)
||
(
typeBlock
==
TypeBlockElse
)
||
(
typeBlock
==
TypeBlockElsif
))
{
currentPage
=
createNewScript
(
scriptName
.
isEmpty
()
?
createUniqName
()
:
scriptName
,
comment
);
}
typeBlock
=
TypeBlockAction
;
comment
.
clear
();
currentPage
->
blockIfWidget
()
->
load
Script
(
n
,
true
,
erro
r
);
currentPage
->
blockIfWidget
()
->
load
LocalVariable
(
va
r
);
}
}
else
{
qCDebug
(
LIBKSIEVE_LOG
)
<<
" set not supported"
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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