mirror of
https://bitbucket.org/smil3y/kde-playground.git
synced 2025-02-23 10:22:50 +00:00
kgpg: implement password and stub progress callback
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
48723e8bd6
commit
e13a8f6ae9
3 changed files with 38 additions and 2 deletions
|
@ -16,8 +16,9 @@
|
|||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <QImageWriter>
|
||||
#include <QScopedPointer>
|
||||
#include <klocale.h>
|
||||
#include <kpassworddialog.h>
|
||||
#include <kapplication.h>
|
||||
#include <klocale.h>
|
||||
#include <kcmdlineargs.h>
|
||||
|
@ -45,6 +46,10 @@ KGPG::KGPG(QWidget *parent)
|
|||
}
|
||||
m_release = true;
|
||||
|
||||
gpgme_set_pinentry_mode(m_gpgctx, GPGME_PINENTRY_MODE_LOOPBACK); // for password callback
|
||||
gpgme_set_passphrase_cb(m_gpgctx, KGPG::gpgPasswordCallback, this);
|
||||
gpgme_set_progress_cb(m_gpgctx, KGPG::gpgProgressCallback, this);
|
||||
|
||||
connect(m_ui.startbutton, SIGNAL(clicked()), this, SLOT(slotStart()));
|
||||
}
|
||||
|
||||
|
@ -160,6 +165,31 @@ void KGPG::setError(const QString &error)
|
|||
m_ui.startbutton->setVisible(true);
|
||||
}
|
||||
|
||||
gpgme_error_t KGPG::gpgPasswordCallback(void *opaque, const char *uid_hint,
|
||||
const char *passphrase_info,
|
||||
int prev_was_bad, int fd)
|
||||
{
|
||||
// qDebug() << Q_FUNC_INFO << uid_hint << passphrase_info << prev_was_bad << fd;
|
||||
|
||||
QScopedPointer<KPasswordDialog> kpassdialog(new KPasswordDialog());
|
||||
kpassdialog->setPrompt(i18n("Enter a password"));
|
||||
if (!kpassdialog->exec()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const QByteArray bytepassword = kpassdialog->password().toLocal8Bit() + "\n";
|
||||
// TODO: ignoring possible errors here
|
||||
gpgme_io_write(fd, bytepassword.constData(), bytepassword.size());
|
||||
return 0;
|
||||
}
|
||||
|
||||
void KGPG::gpgProgressCallback(void *opaque, const char *what,
|
||||
int type, int current, int total)
|
||||
{
|
||||
// qDebug() << Q_FUNC_INFO << what << type << current << total;
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
void KGPG::start()
|
||||
{
|
||||
m_ui.progressbar->setMinimum(0);
|
||||
|
|
|
@ -61,6 +61,12 @@ public:
|
|||
|
||||
void start();
|
||||
|
||||
static gpgme_error_t gpgPasswordCallback(void *opaque, const char *uid_hint,
|
||||
const char *passphrase_info,
|
||||
int prev_was_bad, int fd);
|
||||
static void gpgProgressCallback(void *opaque, const char *what,
|
||||
int type, int current, int total);
|
||||
|
||||
private Q_SLOTS:
|
||||
void slotStart();
|
||||
|
||||
|
|
|
@ -226,7 +226,7 @@
|
|||
<item row="1" column="1" colspan="2">
|
||||
<widget class="KUrlRequester" name="destinationrequester">
|
||||
<property name="mode">
|
||||
<set>KFile::ExistingOnly|KFile::File|KFile::LocalOnly</set>
|
||||
<set>KFile::File|KFile::LocalOnly</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
Loading…
Add table
Reference in a new issue