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
PIM Messagelib
Commits
43821d20
Commit
43821d20
authored
Sep 10, 2017
by
Laurent Montel
Browse files
Coding style
parent
518e83f5
Changes
399
Expand all
Hide whitespace changes
Inline
Side-by-side
messagecomposer/src/attachment/attachmentcontrollerbase.cpp
View file @
43821d20
...
...
@@ -22,8 +22,6 @@
#include
"attachmentcontrollerbase.h"
#include
<MessageComposer/AttachmentModel>
#include
"MessageComposer/AttachmentJob"
#include
"MessageComposer/AttachmentFromPublicKeyJob"
...
...
@@ -155,8 +153,8 @@ void AttachmentControllerBase::setSelectedParts(const AttachmentPart::List &sele
{
d
->
selectedParts
=
selectedParts
;
const
int
selectedCount
=
selectedParts
.
count
();
const
bool
enableEditAction
=
(
selectedCount
==
1
)
&&
(
!
selectedParts
.
first
()
->
isMessageOrMessageCollection
());
const
bool
enableEditAction
=
(
selectedCount
==
1
)
&&
(
!
selectedParts
.
first
()
->
isMessageOrMessageCollection
());
d
->
openContextAction
->
setEnabled
(
selectedCount
>
0
);
d
->
viewContextAction
->
setEnabled
(
selectedCount
>
0
);
...
...
@@ -190,11 +188,11 @@ void AttachmentControllerBase::Private::compressJobResult(KJob *job)
if
(
ajob
->
isCompressedPartLarger
())
{
const
int
result
=
KMessageBox
::
questionYesNo
(
wParent
,
i18n
(
"The compressed attachment is larger than the original. "
"Do you want to keep the original one?"
),
QString
(
/*caption*/
),
KGuiItem
(
i18nc
(
"Do not compress"
,
"Keep"
)),
KGuiItem
(
i18n
(
"Compress"
)));
i18n
(
"The compressed attachment is larger than the original. "
"Do you want to keep the original one?"
),
QString
(
/*caption*/
),
KGuiItem
(
i18nc
(
"Do not compress"
,
"Keep"
)),
KGuiItem
(
i18n
(
"Compress"
)));
if
(
result
==
KMessageBox
::
Yes
)
{
// The user has chosen to keep the uncompressed file.
return
;
...
...
@@ -339,8 +337,8 @@ void AttachmentControllerBase::Private::createOpenWithMenu(QMenu *topMenu, Attac
KService
::
List
::
ConstIterator
end
=
offers
.
constEnd
();
for
(;
it
!=
end
;
++
it
)
{
QAction
*
act
=
MessageViewer
::
Util
::
createAppAction
(
*
it
,
// no submenu -> prefix single offer
menu
==
topMenu
,
actionGroup
,
menu
);
// no submenu -> prefix single offer
menu
==
topMenu
,
actionGroup
,
menu
);
menu
->
addAction
(
act
);
}
...
...
@@ -582,8 +580,8 @@ void AttachmentControllerBase::showContextMenu()
const
int
numberOfParts
(
d
->
selectedParts
.
count
());
QMenu
*
menu
=
new
QMenu
;
const
bool
enableEditAction
=
(
numberOfParts
==
1
)
&&
(
!
d
->
selectedParts
.
first
()
->
isMessageOrMessageCollection
());
const
bool
enableEditAction
=
(
numberOfParts
==
1
)
&&
(
!
d
->
selectedParts
.
first
()
->
isMessageOrMessageCollection
());
if
(
numberOfParts
>
0
)
{
if
(
numberOfParts
==
1
)
{
...
...
@@ -594,13 +592,13 @@ void AttachmentControllerBase::showContextMenu()
if
(
mime
.
isValid
())
{
parentMimeType
=
mime
.
allAncestors
();
}
if
((
mimetype
==
QLatin1String
(
"text/plain"
))
||
(
mimetype
==
QLatin1String
(
"image/png"
))
||
(
mimetype
==
QLatin1String
(
"image/jpeg"
))
||
parentMimeType
.
contains
(
QStringLiteral
(
"text/plain"
))
||
parentMimeType
.
contains
(
QStringLiteral
(
"image/png"
))
||
parentMimeType
.
contains
(
QStringLiteral
(
"image/jpeg"
))
)
{
if
((
mimetype
==
QLatin1String
(
"text/plain"
))
||
(
mimetype
==
QLatin1String
(
"image/png"
))
||
(
mimetype
==
QLatin1String
(
"image/jpeg"
))
||
parentMimeType
.
contains
(
QStringLiteral
(
"text/plain"
))
||
parentMimeType
.
contains
(
QStringLiteral
(
"image/png"
))
||
parentMimeType
.
contains
(
QStringLiteral
(
"image/jpeg"
))
)
{
menu
->
addAction
(
d
->
viewContextAction
);
}
d
->
createOpenWithMenu
(
menu
,
d
->
selectedParts
.
first
());
...
...
@@ -753,7 +751,7 @@ void AttachmentControllerBase::editAttachment(AttachmentPart::Ptr part, MessageV
this
,
SLOT
(
editDone
(
MessageViewer
::
EditorWatcher
*
)));
switch
(
watcher
->
start
())
{
case
MessageViewer
::
EditorWatcher
::
NoError
:
{
case
MessageViewer
::
EditorWatcher
::
NoError
:
// The attachment is being edited.
// We will clean things up in editDone().
d
->
editorPart
[
watcher
]
=
part
;
...
...
@@ -762,18 +760,16 @@ void AttachmentControllerBase::editAttachment(AttachmentPart::Ptr part, MessageV
// Delete the temp file if the composer is closed (and this object is destroyed).
tempFile
->
setParent
(
this
);
// Manages lifetime.
break
;
}
case
MessageViewer
::
EditorWatcher
::
CannotStart
:
qCWarning
(
MESSAGECOMPOSER_LOG
)
<<
"Could not start EditorWatcher."
;
Q_FALLTHROUGH
();
case
MessageViewer
::
EditorWatcher
::
Unknown
:
case
MessageViewer
::
EditorWatcher
::
Canceled
:
case
MessageViewer
::
EditorWatcher
::
NoServiceFound
:
{
case
MessageViewer
::
EditorWatcher
::
NoServiceFound
:
delete
watcher
;
delete
tempFile
;
break
;
}
}
}
void
AttachmentControllerBase
::
editAttachmentWith
(
const
AttachmentPart
::
Ptr
&
part
)
...
...
@@ -812,7 +808,7 @@ void AttachmentControllerBase::slotPutResult(KJob *job)
if
(
job
->
error
()
==
KIO
::
ERR_FILE_ALREADY_EXIST
)
{
if
(
KMessageBox
::
warningContinueCancel
(
nullptr
,
i18n
(
"File %1 exists.
\n
Do you want to replace it?"
,
_job
->
url
().
toLocalFile
()),
i18n
(
"Save to File"
),
KGuiItem
(
i18n
(
"&Replace"
)))
==
KMessageBox
::
Continue
)
{
==
KMessageBox
::
Continue
)
{
byteArrayToRemoteFile
(
_job
->
data
(),
_job
->
url
(),
true
);
}
}
else
{
...
...
@@ -839,7 +835,7 @@ void AttachmentControllerBase::attachmentProperties(const AttachmentPart::Ptr &p
void
AttachmentControllerBase
::
attachDirectory
(
const
QUrl
&
url
)
{
const
int
rc
=
KMessageBox
::
warningYesNo
(
d
->
wParent
,
i18n
(
"Do you really want to attach this directory
\"
%1
\"
?"
,
url
.
toLocalFile
()),
i18nc
(
"@title:window"
,
"Attach directory"
));
i18nc
(
"@title:window"
,
"Attach directory"
));
if
(
rc
==
KMessageBox
::
Yes
)
{
addAttachment
(
url
);
}
...
...
@@ -883,10 +879,10 @@ void AttachmentControllerBase::showAddAttachmentCompressedDirectoryDialog()
void
AttachmentControllerBase
::
showAddAttachmentFileDialog
()
{
KEncodingFileDialog
::
Result
result
=
KEncodingFileDialog
::
getOpenUrlsAndEncoding
(
QString
(),
QUrl
(),
QString
(),
d
->
wParent
,
i18nc
(
"@title:window"
,
"Attach File"
));
QUrl
(),
QString
(),
d
->
wParent
,
i18nc
(
"@title:window"
,
"Attach File"
));
if
(
!
result
.
URLs
.
isEmpty
())
{
const
QString
encoding
=
MimeTreeParser
::
NodeHelper
::
fixEncoding
(
result
.
encoding
);
const
int
numberOfFiles
(
result
.
URLs
.
count
());
...
...
@@ -898,7 +894,7 @@ void AttachmentControllerBase::showAddAttachmentFileDialog()
auto
mimeType
=
mimeDb
.
mimeTypeForUrl
(
urlWithEncoding
);
if
(
mimeType
.
name
()
==
QLatin1String
(
"inode/directory"
))
{
const
int
rc
=
KMessageBox
::
warningYesNo
(
d
->
wParent
,
i18n
(
"Do you really want to attach this directory
\"
%1
\"
?"
,
url
.
toLocalFile
()),
i18nc
(
"@title:window"
,
"Attach directory"
));
i18nc
(
"@title:window"
,
"Attach directory"
));
if
(
rc
==
KMessageBox
::
Yes
)
{
addAttachment
(
urlWithEncoding
);
}
...
...
@@ -965,7 +961,6 @@ void AttachmentControllerBase::showAttachPublicKeyDialog()
void
AttachmentControllerBase
::
attachMyPublicKey
()
{
}
void
AttachmentControllerBase
::
enableAttachPublicKey
(
bool
enable
)
...
...
@@ -985,7 +980,7 @@ void AttachmentControllerBase::setAttachOwnVcard(bool attachVcard)
bool
AttachmentControllerBase
::
attachOwnVcard
()
const
{
return
d
->
addOwnVcardAction
->
isChecked
();
return
d
->
addOwnVcardAction
->
isChecked
();
}
void
AttachmentControllerBase
::
setIdentityHasOwnVcard
(
bool
state
)
...
...
messagecomposer/src/attachment/attachmentcontrollerbase.h
View file @
43821d20
...
...
@@ -36,8 +36,7 @@
class
KActionCollection
;
class
QAction
;
namespace
MessageComposer
{
namespace
MessageComposer
{
class
AttachmentModel
;
class
MESSAGECOMPOSER_EXPORT
AttachmentControllerBase
:
public
QObject
{
...
...
@@ -109,7 +108,7 @@ private:
class
Private
;
Private
*
const
d
;
Q_PRIVATE_SLOT
(
d
,
void
attachmentRemoved
(
const
MessageCore
::
AttachmentPart
::
Ptr
&
))
Q_PRIVATE_SLOT
(
d
,
void
attachmentRemoved
(
const
MessageCore
::
AttachmentPart
::
Ptr
&
))
Q_PRIVATE_SLOT
(
d
,
void
compressJobResult
(
KJob
*
))
Q_PRIVATE_SLOT
(
d
,
void
loadJobResult
(
KJob
*
))
Q_PRIVATE_SLOT
(
d
,
void
openSelectedAttachments
())
...
...
@@ -126,7 +125,6 @@ private:
Q_PRIVATE_SLOT
(
d
,
void
updateJobResult
(
KJob
*
))
Q_PRIVATE_SLOT
(
d
,
void
attachVcardFromAddressBook
(
KJob
*
))
};
}
//
#endif // KMAIL_ATTACHMENTCONTROLLERBASE_H
messagecomposer/src/attachment/attachmentmodel.cpp
View file @
43821d20
...
...
@@ -95,8 +95,7 @@ AttachmentModel::~AttachmentModel()
delete
d
;
}
bool
AttachmentModel
::
dropMimeData
(
const
QMimeData
*
data
,
Qt
::
DropAction
action
,
int
row
,
int
column
,
const
QModelIndex
&
parent
)
bool
AttachmentModel
::
dropMimeData
(
const
QMimeData
*
data
,
Qt
::
DropAction
action
,
int
row
,
int
column
,
const
QModelIndex
&
parent
)
{
Q_UNUSED
(
row
);
Q_UNUSED
(
column
);
...
...
@@ -282,7 +281,7 @@ QVariant AttachmentModel::data(const QModelIndex &index, int role) const
default:
return
QVariant
();
}
}
else
if
(
role
==
Qt
::
ToolTipRole
)
{
}
else
if
(
role
==
Qt
::
ToolTipRole
)
{
return
QVariant
::
fromValue
(
i18nc
(
"@info:tooltip"
,
"Name: %1<br>Size: %2<br>Encoding: %3<br>MimeType=%4"
,
...
...
@@ -338,7 +337,8 @@ bool AttachmentModel::setData(const QModelIndex &index, const QVariant &value, i
if
(
role
==
Qt
::
CheckStateRole
)
{
switch
(
index
.
column
())
{
case
CompressColumn
:
{
case
CompressColumn
:
{
bool
toZip
=
value
.
toBool
();
if
(
toZip
!=
part
->
isCompressed
())
{
Q_EMIT
attachmentCompressRequested
(
part
,
toZip
);
...
...
@@ -357,7 +357,7 @@ bool AttachmentModel::setData(const QModelIndex &index, const QVariant &value, i
break
;
default:
break
;
// Do nothing.
}
;
}
}
else
{
return
false
;
}
...
...
@@ -433,10 +433,10 @@ Qt::ItemFlags AttachmentModel::flags(const QModelIndex &index) const
return
Qt
::
ItemIsDropEnabled
|
defaultFlags
;
}
if
(
index
.
column
()
==
CompressColumn
||
index
.
column
()
==
EncryptColumn
||
index
.
column
()
==
SignColumn
||
index
.
column
()
==
AutoDisplayColumn
)
{
if
(
index
.
column
()
==
CompressColumn
||
index
.
column
()
==
EncryptColumn
||
index
.
column
()
==
SignColumn
||
index
.
column
()
==
AutoDisplayColumn
)
{
return
Qt
::
ItemIsDragEnabled
|
Qt
::
ItemIsDropEnabled
|
Qt
::
ItemIsUserCheckable
|
defaultFlags
;
}
else
{
return
Qt
::
ItemIsDragEnabled
|
Qt
::
ItemIsDropEnabled
|
defaultFlags
;
...
...
@@ -469,7 +469,7 @@ QVariant AttachmentModel::headerData(int section, Qt::Orientation orientation, i
default:
qCWarning
(
MESSAGECOMPOSER_LOG
)
<<
"Bad column"
<<
section
;
return
QVariant
();
}
;
}
}
QModelIndex
AttachmentModel
::
index
(
int
row
,
int
column
,
const
QModelIndex
&
parent
)
const
...
...
messagecomposer/src/attachment/attachmentmodel.h
View file @
43821d20
...
...
@@ -29,9 +29,7 @@
#include
<MessageCore/AttachmentPart>
#include
<AkonadiCore/item.h>
namespace
MessageComposer
{
namespace
MessageComposer
{
/**
Columns:
name
...
...
@@ -77,8 +75,7 @@ public:
explicit
AttachmentModel
(
QObject
*
parent
);
~
AttachmentModel
();
bool
dropMimeData
(
const
QMimeData
*
data
,
Qt
::
DropAction
action
,
int
row
,
int
column
,
const
QModelIndex
&
parent
)
override
;
bool
dropMimeData
(
const
QMimeData
*
data
,
Qt
::
DropAction
action
,
int
row
,
int
column
,
const
QModelIndex
&
parent
)
override
;
QMimeData
*
mimeData
(
const
QModelIndexList
&
indexes
)
const
override
;
QStringList
mimeTypes
()
const
override
;
Qt
::
DropActions
supportedDropActions
()
const
override
;
...
...
@@ -111,10 +108,8 @@ public:
MessageCore
::
AttachmentPart
::
List
attachments
()
const
;
Qt
::
ItemFlags
flags
(
const
QModelIndex
&
index
)
const
override
;
QVariant
headerData
(
int
section
,
Qt
::
Orientation
orientation
,
int
role
=
Qt
::
DisplayRole
)
const
override
;
QModelIndex
index
(
int
row
,
int
column
,
const
QModelIndex
&
parent
=
QModelIndex
())
const
override
;
QVariant
headerData
(
int
section
,
Qt
::
Orientation
orientation
,
int
role
=
Qt
::
DisplayRole
)
const
override
;
QModelIndex
index
(
int
row
,
int
column
,
const
QModelIndex
&
parent
=
QModelIndex
())
const
override
;
QModelIndex
parent
(
const
QModelIndex
&
index
)
const
override
;
int
rowCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
override
;
int
columnCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
override
;
...
...
@@ -133,7 +128,6 @@ private:
friend
class
Private
;
Private
*
const
d
;
};
}
//
#endif // KMAIL_ATTACHMENTMODEL_H
messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.cpp
View file @
43821d20
...
...
@@ -30,12 +30,10 @@
RichTextComposerNgTest
::
RichTextComposerNgTest
(
QObject
*
parent
)
:
QObject
(
parent
)
{
}
RichTextComposerNgTest
::~
RichTextComposerNgTest
()
{
}
void
RichTextComposerNgTest
::
shouldHaveDefaultValue
()
...
...
@@ -55,7 +53,6 @@ void RichTextComposerNgTest::shouldForceAutoCorrection_data()
QTest
::
newRow
(
"test1"
)
<<
QStringLiteral
(
"boo bla bli. foo faa"
)
<<
QStringLiteral
(
"boo bla bli. Foo faa"
);
QTest
::
newRow
(
"test2"
)
<<
QStringLiteral
(
"boo bla bli.
\n
foo faa"
)
<<
QStringLiteral
(
"boo bla bli.
\n
Foo faa"
);
QTest
::
newRow
(
"test3"
)
<<
QStringLiteral
(
"
\n
boo bla bli.
\n
foo faa"
)
<<
QStringLiteral
(
"
\n
Boo bla bli.
\n
Foo faa"
);
}
void
RichTextComposerNgTest
::
shouldForceAutoCorrection
()
...
...
@@ -121,6 +118,7 @@ void RichTextComposerNgTest::shouldNotChangeSignatureWhenOriginalAndNewSignature
const
bool
replaceSignature
=
richtextComposerNg
.
composerSignature
()
->
replaceSignature
(
oldSignature
,
oldSignature
);
QVERIFY
(
!
replaceSignature
);
}
Q_DECLARE_METATYPE
(
KIdentityManagement
::
Signature
::
Placement
)
Q_DECLARE_METATYPE
(
KIdentityManagement
::
Signature
::
AddedTextFlag
)
Q_DECLARE_METATYPE
(
KIdentityManagement
::
Signature
::
Type
)
...
...
@@ -176,16 +174,16 @@ void RichTextComposerNgTest::shouldAddSpecificSignature_data()
QTest
::
addColumn
<
bool
>
(
"enablesignature"
);
QTest
::
addColumn
<
bool
>
(
"signaturehtml"
);
QTest
::
newRow
(
"startandaddseparatordisablenonhtml"
)
<<
QStringLiteral
(
"foo bla, bli
\n
bb"
)
<<
QStringLiteral
(
"foo bla, bli
\n
bb"
)
<<
KIdentityManagement
::
Signature
::
Start
<<
KIdentityManagement
::
Signature
::
AddSeparator
<<
false
<<
false
;
<<
KIdentityManagement
::
Signature
::
Start
<<
KIdentityManagement
::
Signature
::
AddSeparator
<<
false
<<
false
;
QTest
::
newRow
(
"startandaddseparatordisablehtml"
)
<<
QStringLiteral
(
"foo bla, bli
\n
bb"
)
<<
QStringLiteral
(
"foo bla, bli
\n
bb"
)
<<
KIdentityManagement
::
Signature
::
Start
<<
KIdentityManagement
::
Signature
::
AddSeparator
<<
false
<<
true
;
<<
KIdentityManagement
::
Signature
::
Start
<<
KIdentityManagement
::
Signature
::
AddSeparator
<<
false
<<
true
;
QTest
::
newRow
(
"startandaddseparatorenablehtml"
)
<<
QStringLiteral
(
"foo bla, bli
\n
bb"
)
<<
QStringLiteral
(
"--
\n
Signaturefoo bla, bli
\n
bb"
)
<<
KIdentityManagement
::
Signature
::
Start
<<
KIdentityManagement
::
Signature
::
AddSeparator
<<
true
<<
true
;
<<
KIdentityManagement
::
Signature
::
Start
<<
KIdentityManagement
::
Signature
::
AddSeparator
<<
true
<<
true
;
}
void
RichTextComposerNgTest
::
shouldAddSpecificSignature
()
...
...
@@ -229,7 +227,7 @@ void RichTextComposerNgTest::shouldReplaceSignature_data()
QTest
::
newRow
(
"withnewlineatbegin"
)
<<
QStringLiteral
(
"
\n
Signature
\n
new line"
)
<<
QStringLiteral
(
"foo bla, bli
\n
bb"
)
<<
KIdentityManagement
::
Signature
::
End
<<
KIdentityManagement
::
Signature
::
AddSeparator
;
QTest
::
newRow
(
"withnewlineatbeginandend"
)
<<
QStringLiteral
(
"
\n
Signature
\n
new line
\n
"
)
<<
QStringLiteral
(
"foo bla, bli
\n
bb"
)
<<
KIdentityManagement
::
Signature
::
End
<<
KIdentityManagement
::
Signature
::
AddSeparator
;
<<
KIdentityManagement
::
Signature
::
End
<<
KIdentityManagement
::
Signature
::
AddSeparator
;
//Add separator AtStart
QTest
::
newRow
(
"newlinebody-2"
)
<<
QStringLiteral
(
"Signature"
)
<<
QStringLiteral
(
"
\n
"
)
...
...
@@ -245,7 +243,7 @@ void RichTextComposerNgTest::shouldReplaceSignature_data()
QTest
::
newRow
(
"withnewlineatbegin-2"
)
<<
QStringLiteral
(
"
\n
Signature
\n
new line"
)
<<
QStringLiteral
(
"foo bla, bli
\n
bb"
)
<<
KIdentityManagement
::
Signature
::
Start
<<
KIdentityManagement
::
Signature
::
AddSeparator
;
QTest
::
newRow
(
"withnewlineatbeginandend-2"
)
<<
QStringLiteral
(
"
\n
Signature
\n
new line
\n
"
)
<<
QStringLiteral
(
"foo bla, bli
\n
bb"
)
<<
KIdentityManagement
::
Signature
::
Start
<<
KIdentityManagement
::
Signature
::
AddSeparator
;
<<
KIdentityManagement
::
Signature
::
Start
<<
KIdentityManagement
::
Signature
::
AddSeparator
;
//Add nothing End
//FIXME
...
...
@@ -262,7 +260,7 @@ void RichTextComposerNgTest::shouldReplaceSignature_data()
QTest
::
newRow
(
"withnewlineatbegin-3"
)
<<
QStringLiteral
(
"
\n
Signature
\n
new line"
)
<<
QStringLiteral
(
"foo bla, bli
\n
bb"
)
<<
KIdentityManagement
::
Signature
::
End
<<
KIdentityManagement
::
Signature
::
AddNothing
;
QTest
::
newRow
(
"withnewlineatbeginandend-3"
)
<<
QStringLiteral
(
"
\n
Signature
\n
new line
\n
"
)
<<
QStringLiteral
(
"foo bla, bli
\n
bb"
)
<<
KIdentityManagement
::
Signature
::
End
<<
KIdentityManagement
::
Signature
::
AddNothing
;
<<
KIdentityManagement
::
Signature
::
End
<<
KIdentityManagement
::
Signature
::
AddNothing
;
//Add nothing Start
QTest
::
newRow
(
"newlinebody-4"
)
<<
QStringLiteral
(
"Signature"
)
<<
QStringLiteral
(
"
\n
"
)
...
...
@@ -278,7 +276,7 @@ void RichTextComposerNgTest::shouldReplaceSignature_data()
QTest
::
newRow
(
"withnewlineatbegin-4"
)
<<
QStringLiteral
(
"
\n
Signature
\n
new line"
)
<<
QStringLiteral
(
"foo bla, bli
\n
bb"
)
<<
KIdentityManagement
::
Signature
::
Start
<<
KIdentityManagement
::
Signature
::
AddNothing
;
QTest
::
newRow
(
"withnewlineatbeginandend-4"
)
<<
QStringLiteral
(
"
\n
Signature
\n
new line
\n
"
)
<<
QStringLiteral
(
"foo bla, bli
\n
bb"
)
<<
KIdentityManagement
::
Signature
::
Start
<<
KIdentityManagement
::
Signature
::
AddNothing
;
<<
KIdentityManagement
::
Signature
::
Start
<<
KIdentityManagement
::
Signature
::
AddNothing
;
//Add newline End
QTest
::
newRow
(
"emptybody-5"
)
<<
QStringLiteral
(
"Signature"
)
<<
QString
()
...
...
@@ -294,9 +292,9 @@ void RichTextComposerNgTest::shouldReplaceSignature_data()
QTest
::
newRow
(
"withnewlineatbegin-5"
)
<<
QStringLiteral
(
"
\n
Signature
\n
new line"
)
<<
QStringLiteral
(
"foo bla, bli
\n
bb"
)
<<
KIdentityManagement
::
Signature
::
End
<<
KIdentityManagement
::
Signature
::
AddNewLines
;
QTest
::
newRow
(
"withnewlineatbeginandend-5"
)
<<
QStringLiteral
(
"
\n
Signature
\n
new line
\n
"
)
<<
QStringLiteral
(
"foo bla, bli
\n
bb"
)
<<
KIdentityManagement
::
Signature
::
End
<<
KIdentityManagement
::
Signature
::
AddNewLines
;
<<
KIdentityManagement
::
Signature
::
End
<<
KIdentityManagement
::
Signature
::
AddNewLines
;
#if 0 //Need to fix it.
//Add newline start
//Add newline start
QTest::newRow("emptybody-6") << QStringLiteral("Signature") << QString()
<< KIdentityManagement::Signature::Start << KIdentityManagement::Signature::AddNewLines;
QTest::newRow("newlinebody-6") << QStringLiteral("Signature") << QStringLiteral("\n")
...
...
@@ -310,7 +308,7 @@ void RichTextComposerNgTest::shouldReplaceSignature_data()
QTest::newRow("withnewlineatbegin-6") << QStringLiteral("\nSignature\nnew line") << QStringLiteral("foo bla, bli\nbb")
<< KIdentityManagement::Signature::Start << KIdentityManagement::Signature::AddNewLines;
QTest::newRow("withnewlineatbeginandend6") << QStringLiteral("\nSignature\nnew line\n") << QStringLiteral("foo bla, bli\nbb")
<< KIdentityManagement::Signature::Start << KIdentityManagement::Signature::AddNewLines;
<< KIdentityManagement::Signature::Start << KIdentityManagement::Signature::AddNewLines;
#endif
}
...
...
messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.h
View file @
43821d20
...
...
@@ -52,7 +52,6 @@ private Q_SLOTS:
void
shouldLoadSignatureFromCommand_data
();
void
shouldLoadSignatureFromCommand
();
};
#endif // RICHTEXTCOMPOSERNGTEST_H
messagecomposer/src/composer-ng/richtextcomposerng.cpp
View file @
43821d20
...
...
@@ -36,8 +36,8 @@ class MessageComposer::RichTextComposerNgPrivate
{
public:
RichTextComposerNgPrivate
(
RichTextComposerNg
*
q
)
:
autoCorrection
(
nullptr
)
,
richtextComposer
(
q
)
:
autoCorrection
(
nullptr
)
,
richtextComposer
(
q
)
{
richTextComposerSignatures
=
new
MessageComposer
::
RichTextComposerSignatures
(
richtextComposer
,
richtextComposer
);
}
...
...
@@ -50,10 +50,9 @@ public:
};
RichTextComposerNg
::
RichTextComposerNg
(
QWidget
*
parent
)
:
KPIMTextEdit
::
RichTextComposer
(
parent
)
,
d
(
new
MessageComposer
::
RichTextComposerNgPrivate
(
this
))
:
KPIMTextEdit
::
RichTextComposer
(
parent
)
,
d
(
new
MessageComposer
::
RichTextComposerNgPrivate
(
this
))
{
}
RichTextComposerNg
::~
RichTextComposerNg
()
...
...
@@ -85,8 +84,8 @@ void RichTextComposerNg::setAutocorrectionLanguage(const QString &lang)
static
bool
isSpecial
(
const
QTextCharFormat
&
charFormat
)
{
return
charFormat
.
isFrameFormat
()
||
charFormat
.
isImageFormat
()
||
charFormat
.
isListFormat
()
||
charFormat
.
isTableFormat
()
||
charFormat
.
isTableCellFormat
();
return
charFormat
.
isFrameFormat
()
||
charFormat
.
isImageFormat
()
||
charFormat
.
isListFormat
()
||
charFormat
.
isTableFormat
()
||
charFormat
.
isTableCellFormat
();
}
bool
RichTextComposerNg
::
processAutoCorrection
(
QKeyEvent
*
e
)
...
...
@@ -115,7 +114,6 @@ bool RichTextComposerNg::processAutoCorrection(QKeyEvent *e)
setTextCursor
(
cur
);
}
}
else
{
const
QChar
insertChar
=
spacePressed
?
QLatin1Char
(
' '
)
:
QLatin1Char
(
'\n'
);
if
(
richText
&&
!
isSpecial
(
initialTextFormat
))
{
if
((
spacePressed
&&
addSpace
)
||
!
spacePressed
)
{
...
...
@@ -186,7 +184,6 @@ void RichTextComposerNg::fillComposerTextPart(MessageComposer::TextPart *textPar
textPart
->
setCleanHtml
(
cleanHtml
);
textPart
->
setEmbeddedImages
(
composerControler
()
->
composerImages
()
->
embeddedImages
());
}
}
QString
RichTextComposerNgPrivate
::
toCleanHtml
()
const
...
...
@@ -194,25 +191,25 @@ QString RichTextComposerNgPrivate::toCleanHtml() const
QString
result
=
richtextComposer
->
toHtml
();
static
const
QString
EMPTYLINEHTML
=
QStringLiteral
(
"<p style=
\"
-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; "
"margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;
\"
> </p>"
);
"<p style=
\"
-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; "
"margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;
\"
> </p>"
);
// Qt inserts various style properties based on the current mode of the editor (underline,
// bold, etc), but only empty paragraphs *also* have qt-paragraph-type set to 'empty'.
static
const
QString
EMPTYLINEREGEX
=
QStringLiteral
(
"<p style=
\"
-qt-paragraph-type:empty;(.*)</p>"
);
"<p style=
\"
-qt-paragraph-type:empty;(.*)</p>"
);
static
const
QString
OLLISTPATTERNQT
=
QStringLiteral
(
"<ol style=
\"
margin-top: 0px; margin-bottom: 0px; margin-left: 0px;"
);
"<ol style=
\"
margin-top: 0px; margin-bottom: 0px; margin-left: 0px;"
);
static
const
QString
ULLISTPATTERNQT
=
QStringLiteral
(
"<ul style=
\"
margin-top: 0px; margin-bottom: 0px; margin-left: 0px;"
);
"<ul style=
\"
margin-top: 0px; margin-bottom: 0px; margin-left: 0px;"
);
static
const
QString
ORDEREDLISTHTML
=
QStringLiteral
(
"<ol style=
\"
margin-top: 0px; margin-bottom: 0px;"
);
"<ol style=
\"
margin-top: 0px; margin-bottom: 0px;"
);
static
const
QString
UNORDEREDLISTHTML
=
QStringLiteral
(
"<ul style=
\"
margin-top: 0px; margin-bottom: 0px;"
);
"<ul style=
\"
margin-top: 0px; margin-bottom: 0px;"
);
// fix 1 - empty lines should show as empty lines - MS Outlook treats margin-top:0px; as
// a non-existing line.
...
...
@@ -251,14 +248,9 @@ static bool isCursorAtEndOfLine(const QTextCursor &cursor)
return
!
testCursor
.
hasSelection
();
}
static
void
insertSignatureHelper
(
const
QString
&
signature
,
RichTextComposerNg
*
textEdit
,
KIdentityManagement
::
Signature
::
Placement
placement
,
bool
isHtml
,
bool
addNewlines
)
static
void
insertSignatureHelper
(
const
QString
&
signature
,
RichTextComposerNg
*
textEdit
,
KIdentityManagement
::
Signature
::
Placement
placement
,
bool
isHtml
,
bool
addNewlines
)
{
if
(
!
signature
.
isEmpty
())
{
// Save the modified state of the document, as inserting a signature
// shouldn't change this. Restore it at the end of this function.
bool
isModified
=
textEdit
->
document
()
->
isModified
();
...
...
@@ -350,8 +342,8 @@ void RichTextComposerNg::insertSignature(const KIdentityManagement::Signature &s
}
insertSignatureHelper
(
signatureStr
,
this
,
placement
,
(
signature
.
isInlinedHtml
()
&&
signature
.
type
()
==
KIdentityManagement
::
Signature
::
Inlined
),
(
signature
.
isInlinedHtml
()
&&
signature
.
type
()
==
KIdentityManagement
::
Signature
::
Inlined
),
(
addedText
&
KIdentityManagement
::
Signature
::
AddNewLines
));
// We added the text of the signature above, now it is time to add the images as well.
...
...
messagecomposer/src/composer-ng/richtextcomposerng.h
View file @
43821d20
...
...
@@ -24,13 +24,11 @@
#include
<kpimtextedit/richtextcomposer.h>
#include
<KIdentityManagement/Signature>
namespace
PimCommon
{
namespace
PimCommon
{
class
AutoCorrection
;
}
namespace
MessageComposer
{
namespace
MessageComposer
{
class
TextPart
;
class
RichTextComposerSignatures
;
class
RichTextComposerNgPrivate
;
...
...
messagecomposer/src/composer-ng/richtextcomposersignatures.cpp
View file @
43821d20
...
...
@@ -31,17 +31,17 @@ public:
RichTextComposerSignaturesPrivate
(
RichTextComposerNg
*
composer
)
:
richTextComposer
(
composer
)
{
}
void
cleanWhitespaceHelper
(
const
QRegExp
&
regExp
,
const
QString
&
newText
,
const
KIdentityManagement
::
Signature
&
sig
);
QList
<
QPair
<
int
,
int
>
>
signaturePositions
(
const
KIdentityManagement
::
Signature
&
sig
)
const
;
RichTextComposerNg
*
richTextComposer
=
nullptr
;
};
RichTextComposerSignatures
::
RichTextComposerSignatures
(
MessageComposer
::
RichTextComposerNg
*
composer
,
QObject
*
parent
)
:
QObject
(
parent
),
d
(
new
RichTextComposerSignaturesPrivate
(
composer
))
:
QObject
(
parent
)
,
d
(
new
RichTextComposerSignaturesPrivate
(
composer
))
{
}
RichTextComposerSignatures
::~
RichTextComposerSignatures
()
...
...
@@ -49,14 +49,11 @@ RichTextComposerSignatures::~RichTextComposerSignatures()
delete
d
;
}
void
RichTextComposerSignatures
::
RichTextComposerSignaturesPrivate
::
cleanWhitespaceHelper
(
const
QRegExp
&
regExp
,
const
QString
&
newText
,
const
KIdentityManagement
::
Signature
&
sig
)
void
RichTextComposerSignatures
::
RichTextComposerSignaturesPrivate
::
cleanWhitespaceHelper
(
const
QRegExp
&
regExp
,
const
QString
&
newText
,
const
KIdentityManagement
::
Signature
&
sig
)
{
int
currentSearchPosition
=
0
;
forever
{
// Find the text
QString
text
=
richTextComposer
->
document
()
->
toPlainText
();
int
currentMatch
=
regExp
.
indexIn
(
text
,
currentSearchPosition
);
...
...
@@ -79,8 +76,8 @@ void RichTextComposerSignatures::RichTextComposerSignaturesPrivate::cleanWhitesp
bool
insideSignature
=
false
;
const
QList
<
QPair
<
int
,
int
>
>
sigPositions
=
signaturePositions
(
sig
);
for
(
const
QPair
<
int
,
int
>
&
position
:
sigPositions
)
{
if
(
cursor
.
position
()
>=
position
.
first
&&
cursor
.
position
()
<=
position
.
second
)
{
if
(
cursor
.
position
()
>=
position
.
first
&&
cursor
.
position
()
<=
position
.
second
)
{
insideSignature
=
true
;
}
}
...
...
@@ -125,12 +122,10 @@ RichTextComposerSignatures::RichTextComposerSignaturesPrivate::signaturePosition
{
QList
<
QPair
<
int
,
int
>
>
signaturePositions
;
if
(
!
sig
.
rawText
().
isEmpty
())
{
QString
sigText
=
sig
.
toPlainText
();