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
Kleopatra
Commits
47ab3744
Commit
47ab3744
authored
Jun 28, 2021
by
Ingo Klöcker
Browse files
Modernize code
GnuPG-bug-id: 4717
parent
647320ea
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/commands/changeexpirycommand.cpp
View file @
47ab3744
...
...
@@ -10,25 +10,23 @@
#include <config-kleopatra.h>
#include "changeexpirycommand.h"
#include "command_p.h"
#include
<
dialogs/expirydialog.h
>
#include
"
dialogs/expirydialog.h
"
#include <Libkleo/Formatting>
#include <KLocalizedString>
#include <QGpgME/Protocol>
#include <QGpgME/ChangeExpiryJob>
#include <QDateTime>
#include <gpgme++/key.h>
#include <KLocalizedString>
#include "kleopatra_debug.h"
#include <QDateTime>
#include <QDebug>
#include <gpgme++/gpgmepp_version.h>
#if GPGMEPP_VERSION >= 0x10E01 // 1.14.1
# define CHANGEEXPIRYJOB_SUPPORTS_SUBKEYS
...
...
@@ -49,9 +47,7 @@ class ChangeExpiryCommand::Private : public Command::Private
}
public:
explicit
Private
(
ChangeExpiryCommand
*
qq
,
KeyListController
*
c
);
~
Private
();
void
init
();
~
Private
()
override
;
private:
void
slotDialogAccepted
();
...
...
@@ -84,102 +80,31 @@ const ChangeExpiryCommand::Private *ChangeExpiryCommand::d_func() const
#define q q_func()
ChangeExpiryCommand
::
Private
::
Private
(
ChangeExpiryCommand
*
qq
,
KeyListController
*
c
)
:
Command
::
Private
(
qq
,
c
),
key
(),
dialog
(),
job
()
{
}
ChangeExpiryCommand
::
Private
::~
Private
()
{
qCDebug
(
KLEOPATRA_LOG
);
}
ChangeExpiryCommand
::
ChangeExpiryCommand
(
KeyListController
*
c
)
:
Command
(
new
Private
(
this
,
c
))
:
Command
::
Private
{
qq
,
c
}
{
d
->
init
();
}
ChangeExpiryCommand
::
ChangeExpiryCommand
(
QAbstractItemView
*
v
,
KeyListController
*
c
)
:
Command
(
v
,
new
Private
(
this
,
c
))
{
d
->
init
();
}
ChangeExpiryCommand
::
ChangeExpiryCommand
(
const
GpgME
::
Key
&
key
)
:
Command
(
key
,
new
Private
(
this
,
nullptr
))
{
d
->
init
();
}
void
ChangeExpiryCommand
::
Private
::
init
()
{
}
ChangeExpiryCommand
::~
ChangeExpiryCommand
()
{
qCDebug
(
KLEOPATRA_LOG
);
}
void
ChangeExpiryCommand
::
setSubkey
(
const
GpgME
::
Subkey
&
subkey
)
{
d
->
subkey
=
subkey
;
}
void
ChangeExpiryCommand
::
doStart
()
{
const
std
::
vector
<
Key
>
keys
=
d
->
keys
();
if
(
keys
.
size
()
!=
1
||
keys
.
front
().
protocol
()
!=
GpgME
::
OpenPGP
||
!
keys
.
front
().
hasSecret
()
||
keys
.
front
().
subkey
(
0
).
isNull
())
{
d
->
finished
();
return
;
}
d
->
key
=
keys
.
front
();
if
(
!
d
->
subkey
.
isNull
()
&&
d
->
subkey
.
parent
().
primaryFingerprint
()
!=
d
->
key
.
primaryFingerprint
())
{
qDebug
()
<<
"Invalid subkey"
<<
d
->
subkey
.
fingerprint
()
<<
": Not a subkey of key"
<<
d
->
key
.
primaryFingerprint
();
d
->
finished
();
return
;
}
const
Subkey
subkey
=
!
d
->
subkey
.
isNull
()
?
d
->
subkey
:
d
->
key
.
subkey
(
0
);
d
->
ensureDialogCreated
();
Q_ASSERT
(
d
->
dialog
);
d
->
dialog
->
setDateOfExpiry
(
subkey
.
neverExpires
()
?
QDate
()
:
QDateTime
::
fromSecsSinceEpoch
(
subkey
.
expirationTime
()).
date
());
d
->
dialog
->
show
();
}
ChangeExpiryCommand
::
Private
::~
Private
()
=
default
;
void
ChangeExpiryCommand
::
Private
::
slotDialogAccepted
()
{
Q_ASSERT
(
dialog
);
static
const
QTime
END_OF_DAY
(
23
,
59
,
59
)
;
static
const
QTime
END_OF_DAY
{
23
,
59
,
59
}
;
const
QDateTime
expiry
(
dialog
->
dateOfExpiry
(),
END_OF_DAY
)
;
const
QDateTime
expiry
{
dialog
->
dateOfExpiry
(),
END_OF_DAY
}
;
qCDebug
(
KLEOPATRA_LOG
)
<<
"expiry"
<<
expiry
;
createJob
();
Q_ASSERT
(
job
);
#ifdef CHANGEEXPIRYJOB_SUPPORTS_SUBKEYS
std
::
vector
<
Subkey
>
subkeys
;
if
(
!
subkey
.
isNull
())
{
subkeys
.
push_back
(
subkey
);
}
#ifdef CHANGEEXPIRYJOB_SUPPORTS_SUBKEYS
if
(
const
Error
err
=
job
->
start
(
key
,
expiry
,
subkeys
))
{
#else
if
(
const
Error
err
=
job
->
start
(
key
,
expiry
))
{
...
...
@@ -207,14 +132,6 @@ void ChangeExpiryCommand::Private::slotResult(const Error &err)
finished
();
}
void
ChangeExpiryCommand
::
doCancel
()
{
qCDebug
(
KLEOPATRA_LOG
);
if
(
d
->
job
)
{
d
->
job
->
slotCancel
();
}
}
void
ChangeExpiryCommand
::
Private
::
ensureDialogCreated
()
{
if
(
dialog
)
{
...
...
@@ -245,8 +162,8 @@ void ChangeExpiryCommand::Private::createJob()
connect
(
j
,
&
Job
::
progress
,
q
,
&
Command
::
progress
);
connect
(
j
,
SIGNAL
(
result
(
GpgME
::
Error
))
,
q
,
SLOT
(
slotResult
(
GpgME
::
Error
))
);
connect
(
j
,
&
ChangeExpiryJob
::
result
,
q
,
[
this
]
(
const
auto
&
err
)
{
slotResult
(
err
);
}
);
job
=
j
;
}
...
...
@@ -266,6 +183,66 @@ void ChangeExpiryCommand::Private::showSuccessDialog()
i18n
(
"Expiry Date Change Succeeded"
));
}
ChangeExpiryCommand
::
ChangeExpiryCommand
(
KeyListController
*
c
)
:
Command
{
new
Private
{
this
,
c
}}
{
}
ChangeExpiryCommand
::
ChangeExpiryCommand
(
QAbstractItemView
*
v
,
KeyListController
*
c
)
:
Command
{
v
,
new
Private
{
this
,
c
}}
{
}
ChangeExpiryCommand
::
ChangeExpiryCommand
(
const
GpgME
::
Key
&
key
)
:
Command
{
key
,
new
Private
{
this
,
nullptr
}}
{
}
ChangeExpiryCommand
::~
ChangeExpiryCommand
()
=
default
;
void
ChangeExpiryCommand
::
setSubkey
(
const
GpgME
::
Subkey
&
subkey
)
{
d
->
subkey
=
subkey
;
}
void
ChangeExpiryCommand
::
doStart
()
{
const
std
::
vector
<
Key
>
keys
=
d
->
keys
();
if
(
keys
.
size
()
!=
1
||
keys
.
front
().
protocol
()
!=
GpgME
::
OpenPGP
||
!
keys
.
front
().
hasSecret
()
||
keys
.
front
().
subkey
(
0
).
isNull
())
{
d
->
finished
();
return
;
}
d
->
key
=
keys
.
front
();
if
(
!
d
->
subkey
.
isNull
()
&&
d
->
subkey
.
parent
().
primaryFingerprint
()
!=
d
->
key
.
primaryFingerprint
())
{
qDebug
()
<<
"Invalid subkey"
<<
d
->
subkey
.
fingerprint
()
<<
": Not a subkey of key"
<<
d
->
key
.
primaryFingerprint
();
d
->
finished
();
return
;
}
const
Subkey
subkey
=
!
d
->
subkey
.
isNull
()
?
d
->
subkey
:
d
->
key
.
subkey
(
0
);
d
->
ensureDialogCreated
();
Q_ASSERT
(
d
->
dialog
);
d
->
dialog
->
setDateOfExpiry
(
subkey
.
neverExpires
()
?
QDate
()
:
QDateTime
::
fromSecsSinceEpoch
(
subkey
.
expirationTime
()).
date
());
d
->
dialog
->
show
();
}
void
ChangeExpiryCommand
::
doCancel
()
{
if
(
d
->
job
)
{
d
->
job
->
slotCancel
();
}
}
#undef d
#undef q
...
...
src/dialogs/expirydialog.cpp
View file @
47ab3744
...
...
@@ -14,7 +14,6 @@
#include "ui_expirydialog.h"
#include <QDate>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QVBoxLayout>
...
...
@@ -66,19 +65,19 @@ class ExpiryDialog::Private
ExpiryDialog
*
const
q
;
public:
explicit
Private
(
ExpiryDialog
*
qq
)
:
q
(
qq
),
inUnit
(
Days
),
ui
(
q
)
:
q
{
qq
}
,
inUnit
{
Days
}
,
ui
{
q
}
{
connect
(
ui
.
inSB
,
SIGNAL
(
valueChanged
(
int
))
,
q
,
SLOT
(
slotInAmountChanged
()
)
);
connect
(
ui
.
inCB
,
SIGNAL
(
currentIndexChanged
(
int
)
),
q
,
SLOT
(
slotInUnitChanged
()
)
);
connect
(
ui
.
onCW
,
SIGNAL
(
selectionChanged
())
,
q
,
SLOT
(
slotOnDateChanged
()
)
);
connect
(
ui
.
inSB
,
&
QSpinBox
::
valueChanged
,
q
,
[
this
]
()
{
slotInAmountChanged
()
;
}
);
connect
(
ui
.
inCB
,
QOverload
<
int
>::
of
(
&
QComboBox
::
currentIndexChanged
),
q
,
[
this
]
()
{
slotInUnitChanged
()
;
}
);
connect
(
ui
.
onCW
,
&
QCalendarWidget
::
selectionChanged
,
q
,
[
this
]
()
{
slotOnDateChanged
()
;
}
);
connect
(
ui
.
onCW
,
&
QCalendarWidget
::
currentPageChanged
,
q
,
[
this
]
(
int
year
,
int
month
)
{
// We select the ame day in the month when
// We select the
s
ame day in the month when
// a page is switched.
auto
date
=
ui
.
onCW
->
selectedDate
();
if
(
!
date
.
setDate
(
year
,
month
,
date
.
day
()))
{
...
...
@@ -104,7 +103,7 @@ private:
struct
UI
:
public
Ui
::
ExpiryDialog
{
explicit
UI
(
Dialogs
::
ExpiryDialog
*
qq
)
:
Ui
::
ExpiryDialog
()
:
Ui
::
ExpiryDialog
{}
{
auto
mainWidget
=
new
QWidget
(
qq
);
...
...
@@ -128,12 +127,13 @@ private:
};
ExpiryDialog
::
ExpiryDialog
(
QWidget
*
p
)
:
QDialog
(
p
),
d
(
new
Private
(
this
))
:
QDialog
{
p
}
,
d
{
new
Private
{
this
}}
{
setWindowTitle
(
i18nc
(
"@title:window"
,
"Change Expiry"
));
}
ExpiryDialog
::~
ExpiryDialog
()
{}
ExpiryDialog
::~
ExpiryDialog
()
=
default
;
void
ExpiryDialog
::
setDateOfExpiry
(
const
QDate
&
date
)
{
...
...
@@ -153,7 +153,7 @@ QDate ExpiryDialog::dateOfExpiry() const
return
d
->
ui
.
inRB
->
isChecked
()
?
d
->
inDate
()
:
d
->
ui
.
onRB
->
isChecked
()
?
d
->
ui
.
onCW
->
selectedDate
()
:
QDate
()
;
QDate
{}
;
}
void
ExpiryDialog
::
Private
::
slotInUnitChanged
()
...
...
src/dialogs/expirydialog.h
View file @
47ab3744
...
...
@@ -11,7 +11,7 @@
#include <QDialog>
#include <
utils/pimpl_ptr
.h>
#include <
memory
.h>
class
QDate
;
...
...
@@ -26,17 +26,14 @@ class ExpiryDialog : public QDialog
Q_PROPERTY
(
QDate
dateOfExpiry
READ
dateOfExpiry
WRITE
setDateOfExpiry
)
public:
explicit
ExpiryDialog
(
QWidget
*
parent
=
nullptr
);
~
ExpiryDialog
();
~
ExpiryDialog
()
override
;
void
setDateOfExpiry
(
const
QDate
&
date
);
QDate
dateOfExpiry
()
const
;
private:
class
Private
;
kdtools
::
pimpl_ptr
<
Private
>
d
;
Q_PRIVATE_SLOT
(
d
,
void
slotInAmountChanged
())
Q_PRIVATE_SLOT
(
d
,
void
slotInUnitChanged
())
Q_PRIVATE_SLOT
(
d
,
void
slotOnDateChanged
())
std
::
unique_ptr
<
Private
>
d
;
};
}
...
...
Write
Preview
Markdown
is supported
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