QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
ImportKeyDialog Class Reference

Dialog for importing GPG keys from file or clipboard. More...

#include <importkeydialog.h>

Inheritance diagram for ImportKeyDialog:
Collaboration diagram for ImportKeyDialog:

Public Member Functions

 ImportKeyDialog (const QString &gpgExe, QWidget *parent=nullptr)
 Construct an ImportKeyDialog.
 ~ImportKeyDialog () override
 Destroys the dialog and its generated UI.
auto importedKeyId () const -> QString
 Get the imported key id on success.

Static Public Member Functions

static auto parseGpgImportOutput (const QString &output) -> QString
 Parse GPG import output to extract a key id or fingerprint.

Private Slots

void on_fileButton_clicked ()
 "From file" button: picks a file, reads it as a regular file of at most 16 MiB, requires the -----BEGIN PGP armor header and loads the text into the input field. Binary keyrings are refused with a hint to gpg --armor --export first.
void on_pasteButton_clicked ()
 "From clipboard" button: replaces the input field with the clipboard text, unless the clipboard is empty.
void on_importButton_clicked ()
 "Import" button: runs importFromString() on the trimmed input and closes the dialog with accept() on success.
void on_inputTextEdit_textChanged ()
 Enables the Import button only while the input field holds non-blank text.

Private Member Functions

auto importFromString (const QString &input) -> bool
 Feeds input to gpg --status-fd 1 --import --batch --yes via Executor::executeBlocking() and records the imported key id.
void showError (const QString &message)
 Shows message in a plain-text warning box (gpg's stderr quotes user IDs, which must not be read as markup).
void showSuccess (const QString &keyId)
 Shows the "imported, now verify the fingerprint" information box.

Private Attributes

QScopedPointer< Ui::ImportKeyDialog > ui
 Generated form (importkeydialog.ui); owned.
QString m_importedKeyId
 Key id or fingerprint of the last successful import; empty until then. Read back through importedKeyId().
QString m_gpgExe
 Path of the gpg binary to run; empty means plain gpg on PATH.

Detailed Description

Dialog for importing GPG keys from file or clipboard.

Allows users to import GPG public keys without leaving QtPass. Offers two import paths: from file or from clipboard text.

Definition at line 27 of file importkeydialog.h.

Constructor & Destructor Documentation

◆ ImportKeyDialog()

ImportKeyDialog::ImportKeyDialog ( const QString & gpgExe,
QWidget * parent = nullptr )
explicit

Construct an ImportKeyDialog.

Parameters
gpgExePath to the gpg executable (falls back to "gpg" if empty).
parentOptional parent widget.

Definition at line 44 of file importkeydialog.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~ImportKeyDialog()

ImportKeyDialog::~ImportKeyDialog ( )
overridedefault

Destroys the dialog and its generated UI.

Here is the call graph for this function:

Member Function Documentation

◆ importedKeyId()

auto ImportKeyDialog::importedKeyId ( ) const -> QString

Get the imported key id on success.

Returns
The imported key id (or fingerprint when GnuPG status output provides one), or empty if import failed.

Definition at line 52 of file importkeydialog.cpp.

Here is the caller graph for this function:

◆ importFromString()

bool ImportKeyDialog::importFromString ( const QString & input) -> bool
private

Feeds input to gpg --status-fd 1 --import --batch --yes via Executor::executeBlocking() and records the imported key id.

Parameters
inputArmored key text, trimmed.
Returns
true when gpg exited with 0 and a key id could be parsed from its output; false after showError() otherwise.

Definition at line 138 of file importkeydialog.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_fileButton_clicked

void ImportKeyDialog::on_fileButton_clicked ( )
privateslot

"From file" button: picks a file, reads it as a regular file of at most 16 MiB, requires the -----BEGIN PGP armor header and loads the text into the input field. Binary keyrings are refused with a hint to gpg --armor --export first.

Definition at line 56 of file importkeydialog.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_importButton_clicked

void ImportKeyDialog::on_importButton_clicked ( )
privateslot

"Import" button: runs importFromString() on the trimmed input and closes the dialog with accept() on success.

Definition at line 122 of file importkeydialog.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_inputTextEdit_textChanged

void ImportKeyDialog::on_inputTextEdit_textChanged ( )
privateslot

Enables the Import button only while the input field holds non-blank text.

Definition at line 133 of file importkeydialog.cpp.

Here is the caller graph for this function:

◆ on_pasteButton_clicked

void ImportKeyDialog::on_pasteButton_clicked ( )
privateslot

"From clipboard" button: replaces the input field with the clipboard text, unless the clipboard is empty.

Definition at line 111 of file importkeydialog.cpp.

Here is the caller graph for this function:

◆ parseGpgImportOutput()

auto ImportKeyDialog::parseGpgImportOutput ( const QString & output) -> QString
static

Parse GPG import output to extract a key id or fingerprint.

Prefers locale-independent status lines ([GNUPG:] IMPORT_OK and [GNUPG:] IMPORTED) when present, then falls back to the human-readable "gpg: key ...: imported" line (English locale only).

Parameters
outputCombined stdout/stderr from gpg --import --status-fd 1.
Returns
The imported key id or fingerprint, or empty if not found.

Definition at line 167 of file importkeydialog.cpp.

Here is the caller graph for this function:

◆ showError()

void ImportKeyDialog::showError ( const QString & message)
private

Shows message in a plain-text warning box (gpg's stderr quotes user IDs, which must not be read as markup).

Parameters
messageThe error text.

Definition at line 197 of file importkeydialog.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ showSuccess()

void ImportKeyDialog::showSuccess ( const QString & keyId)
private

Shows the "imported, now verify the fingerprint" information box.

Parameters
keyIdThe imported key id or fingerprint.

Definition at line 203 of file importkeydialog.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ m_gpgExe

QString ImportKeyDialog::m_gpgExe
private

Path of the gpg binary to run; empty means plain gpg on PATH.

Definition at line 93 of file importkeydialog.h.

◆ m_importedKeyId

QString ImportKeyDialog::m_importedKeyId
private

Key id or fingerprint of the last successful import; empty until then. Read back through importedKeyId().

Definition at line 91 of file importkeydialog.h.

◆ ui

QScopedPointer<Ui::ImportKeyDialog> ImportKeyDialog::ui
private

Generated form (importkeydialog.ui); owned.

Definition at line 88 of file importkeydialog.h.


The documentation for this class was generated from the following files: