Skip to content
API Documentation
BastionGuard™
PasswordDialog Class Reference

#include <PasswordDialogs.hpp>

Inheritance diagram for PasswordDialog:

Public Member Functions

 PasswordDialog (Gtk::Window &parent, const Glib::ustring &title)
 PasswordDialog (Gtk::Window &parent, const Glib::ustring &title, const PasswordEntry &entry, const std::string &secret)
 ~PasswordDialog () override
PasswordEntry getEntry () const
std::string getSecret () const

Private Member Functions

void build ()
void fillFrom (const PasswordEntry &entry, const std::string &secret)

Private Attributes

Gtk::Entry nameEntry_
Gtk::Entry usernameEntry_
Gtk::Entry urlEntry_
Gtk::Entry tagsEntry_
Gtk::TextView notesView_
Gtk::Entry passwordEntry_
Gtk::CheckButton showPasswordCheck_
Glib::RefPtr< Gtk::TextBuffer > notesBuffer_

Detailed Description

Definition at line 28 of file PasswordDialogs.hpp.

Constructor & Destructor Documentation

◆ PasswordDialog() [1/2]

PasswordDialog::PasswordDialog ( Gtk::Window & parent,
const Glib::ustring & title )

Definition at line 27 of file PasswordDialogs.cpp.

28: Gtk::Dialog(title, parent, true)
29{
30 build();
31}

References build().

Referenced by PasswordManagerPage::onAddClicked().

◆ PasswordDialog() [2/2]

PasswordDialog::PasswordDialog ( Gtk::Window & parent,
const Glib::ustring & title,
const PasswordEntry & entry,
const std::string & secret )

Definition at line 33 of file PasswordDialogs.cpp.

35: Gtk::Dialog(title, parent, true)
36{
37 build();
38 fillFrom(entry, secret);
39}
void fillFrom(const PasswordEntry &entry, const std::string &secret)

References build(), and fillFrom().

◆ ~PasswordDialog()

PasswordDialog::~PasswordDialog ( )
overridedefault

References getEntry(), and getSecret().

Member Function Documentation

◆ build()

void PasswordDialog::build ( )
private

Definition at line 42 of file PasswordDialogs.cpp.

42 {
43 set_default_size(520, 460);
44
45 auto* content = get_content_area();
46 content->set_spacing(8);
47 content->set_margin(12);
48
49 // Campi testo normali
50 nameEntry_.set_placeholder_text(_("Nome"));
51 nameEntry_.set_max_length(128);
52
53 usernameEntry_.set_placeholder_text(_("Username / Email"));
54 usernameEntry_.set_max_length(256);
55
56 urlEntry_.set_placeholder_text(_("URL / dominio"));
57 urlEntry_.set_max_length(512);
58
59 tagsEntry_.set_placeholder_text(_("tag1, tag2, tag3"));
60 tagsEntry_.set_max_length(256);
61 passwordEntry_.set_placeholder_text(_("Password"));
62 passwordEntry_.set_visibility(false);
63 passwordEntry_.set_input_purpose(Gtk::InputPurpose::PASSWORD);
64 passwordEntry_.set_max_length(512);
65
66 showPasswordCheck_.set_label(_("Mostra password"));
67 showPasswordCheck_.signal_toggled().connect([this]() {
68 passwordEntry_.set_visibility(showPasswordCheck_.get_active());
69 });
70
71 // Note
72 notesBuffer_ = Gtk::TextBuffer::create();
73 notesView_.set_buffer(notesBuffer_);
74 notesView_.set_wrap_mode(Gtk::WrapMode::WORD);
75 notesView_.set_vexpand(true);
76 notesView_.set_size_request(-1, 80);
77
78 auto notesFrame = Gtk::make_managed<Gtk::Frame>();
79 notesFrame->set_label(_("Note"));
80 notesFrame->set_child(notesView_);
81
82 content->append(nameEntry_);
83 content->append(usernameEntry_);
84 content->append(urlEntry_);
85 content->append(tagsEntry_);
86 content->append(passwordEntry_);
87 content->append(showPasswordCheck_);
88 content->append(*notesFrame);
89
90 add_button(_("Annulla"), Gtk::ResponseType::CANCEL);
91 add_button(_("Salva"), Gtk::ResponseType::OK);
92
93 set_default_response(Gtk::ResponseType::OK);
94}
#define _(s)
Gtk::Entry nameEntry_
Gtk::CheckButton showPasswordCheck_
Gtk::Entry usernameEntry_
Gtk::Entry tagsEntry_
Glib::RefPtr< Gtk::TextBuffer > notesBuffer_
Gtk::Entry passwordEntry_
Gtk::TextView notesView_

References _, nameEntry_, notesBuffer_, notesView_, passwordEntry_, showPasswordCheck_, tagsEntry_, urlEntry_, and usernameEntry_.

Referenced by PasswordDialog(), and PasswordDialog().

◆ fillFrom()

void PasswordDialog::fillFrom ( const PasswordEntry & entry,
const std::string & secret )
private

Definition at line 97 of file PasswordDialogs.cpp.

97 {
98 nameEntry_.set_text(entry.name);
99 usernameEntry_.set_text(entry.username);
100 urlEntry_.set_text(entry.url);
101
102 std::ostringstream tags;
103 for (size_t i = 0; i < entry.tags.size(); ++i) {
104 if (i != 0) tags << ", ";
105 tags << entry.tags[i];
106 }
107 tagsEntry_.set_text(tags.str());
108
109 notesBuffer_->set_text(entry.notes);
110 passwordEntry_.set_text(secret);
111}
std::string url
std::string username
std::vector< std::string > tags
std::string notes
std::string name

References PasswordEntry::name, nameEntry_, PasswordEntry::notes, notesBuffer_, passwordEntry_, PasswordEntry::tags, tagsEntry_, PasswordEntry::url, urlEntry_, PasswordEntry::username, and usernameEntry_.

Referenced by PasswordDialog().

◆ getEntry()

PasswordEntry PasswordDialog::getEntry ( ) const

Definition at line 114 of file PasswordDialogs.cpp.

114 {
115 PasswordEntry e;
116 e.name = nameEntry_.get_text();
117 e.username = usernameEntry_.get_text();
118 e.url = urlEntry_.get_text();
119 e.notes = notesBuffer_->get_text();
120
121 std::stringstream ss(tagsEntry_.get_text());
122 std::string item;
123 while (std::getline(ss, item, ',')) {
124 const auto start = item.find_first_not_of(" \t");
125 const auto end = item.find_last_not_of(" \t");
126 if (start != std::string::npos)
127 e.tags.push_back(item.substr(start, end - start + 1));
128 }
129
130 return e;
131}

References PasswordEntry::name, nameEntry_, PasswordEntry::notes, notesBuffer_, PasswordEntry::tags, tagsEntry_, PasswordEntry::url, urlEntry_, PasswordEntry::username, and usernameEntry_.

Referenced by ~PasswordDialog().

◆ getSecret()

std::string PasswordDialog::getSecret ( ) const

Definition at line 133 of file PasswordDialogs.cpp.

133 {
134 return passwordEntry_.get_text();
135}

References passwordEntry_.

Referenced by ~PasswordDialog().

Member Data Documentation

◆ nameEntry_

Gtk::Entry PasswordDialog::nameEntry_
private

Definition at line 39 of file PasswordDialogs.hpp.

Referenced by build(), fillFrom(), and getEntry().

◆ notesBuffer_

Glib::RefPtr<Gtk::TextBuffer> PasswordDialog::notesBuffer_
private

Definition at line 46 of file PasswordDialogs.hpp.

Referenced by build(), fillFrom(), and getEntry().

◆ notesView_

Gtk::TextView PasswordDialog::notesView_
private

Definition at line 43 of file PasswordDialogs.hpp.

Referenced by build().

◆ passwordEntry_

Gtk::Entry PasswordDialog::passwordEntry_
private

Definition at line 44 of file PasswordDialogs.hpp.

Referenced by build(), fillFrom(), and getSecret().

◆ showPasswordCheck_

Gtk::CheckButton PasswordDialog::showPasswordCheck_
private

Definition at line 45 of file PasswordDialogs.hpp.

Referenced by build().

◆ tagsEntry_

Gtk::Entry PasswordDialog::tagsEntry_
private

Definition at line 42 of file PasswordDialogs.hpp.

Referenced by build(), fillFrom(), and getEntry().

◆ urlEntry_

Gtk::Entry PasswordDialog::urlEntry_
private

Definition at line 41 of file PasswordDialogs.hpp.

Referenced by build(), fillFrom(), and getEntry().

◆ usernameEntry_

Gtk::Entry PasswordDialog::usernameEntry_
private

Definition at line 40 of file PasswordDialogs.hpp.

Referenced by build(), fillFrom(), and getEntry().


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