-
Notifications
You must be signed in to change notification settings - Fork 0
/
CCWindow.cpp
116 lines (90 loc) · 3.72 KB
/
CCWindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
// Created by suteerth on 3/18/16.
//
#include "CCWindow.h"
#include "SpinEnc.h"
CoolCryptoWindow::CoolCryptoWindow() : m_MainBox(Gtk::ORIENTATION_HORIZONTAL),
buttonAndViewBox(Gtk::ORIENTATION_VERTICAL),
swEncDec("Enc/Dec") {
set_title("Encrypt All the Things!!!");
set_border_width(5);
this->encrypt = true;
//Taking care of child widgets
//This is initializing the passphase box.
m_entry.set_max_length(50);
m_entry.set_text("passphrase");
m_entry.select_region(0, m_entry.get_text_length());
//This adds the encrypt button, the m_entry and the decrypt
// button from left to rigth horizontally
buttonAndViewBox.add(m_entry);
buttonAndViewBox.add(swEncDec);
//Preparing the text view and the reference buffer
m_refTxtBuffer = Gtk::TextBuffer::create();
m_refTxtBufferDec = Gtk::TextBuffer::create();
m_refTxtBuffer->set_text("Encrypt");
m_refTxtBufferDec->set_text("Decrypt");
m_TextViewEnc.set_buffer(m_refTxtBuffer);
m_TextViewDec.set_buffer(m_refTxtBufferDec);
//This adds the text view and the previously made box to the main
m_MainBox.add(m_TextViewEnc);
m_MainBox.add(buttonAndViewBox);
m_MainBox.add(m_TextViewDec);
///*Unsure what this does*/m_VBox.pack_start(m_dec_button);
//This creates the reference buffer for the text view
this->add(m_MainBox);
show_all_children();
//Connect Sognals
m_refTxtBuffer->signal_changed().connect(sigc::mem_fun(*this,
&CoolCryptoWindow::on_enc_button_clicked));
m_refTxtBufferDec->signal_changed().connect(sigc::mem_fun(*this,
&CoolCryptoWindow::on_dec_button_clicked));
swEncDec.signal_pressed().connect(sigc::mem_fun(*this,
&CoolCryptoWindow::switch_enc_dec));
m_MainBox.signal_check_resize().connect(sigc::mem_fun(*this,
&CoolCryptoWindow::change_window_based_on_text));
}
void CoolCryptoWindow::on_enc_button_clicked() {
if (!this->encrypt)return;
Gtk::TextBuffer::iterator tit = m_refTxtBuffer->begin();
string in = tit.get_text(m_refTxtBuffer->end());
string out = in;
Vigenere encryptor(m_entry.get_text());
out = encryptor.encrypt(in);
m_refTxtBufferDec->set_text(out);
this->set_resizable(true);
this->resize(this->m_MainBox.get_width(), this->m_MainBox.get_height());
this->set_resizable(false);
}
void CoolCryptoWindow::on_dec_button_clicked() {
if (this->encrypt)return;
Gtk::TextBuffer::iterator tit = m_refTxtBufferDec->begin();
string in = tit.get_text(m_refTxtBufferDec->end());
string out = in;
Vigenere decryptor(m_entry.get_text());
out = decryptor.decrypt(in);
m_refTxtBuffer->set_text(out);
this->set_resizable(true);
this->resize(this->m_MainBox.get_width(), this->m_MainBox.get_height());
this->set_resizable(false);
}
void CoolCryptoWindow::switch_enc_dec() {
this->encrypt = !this->encrypt;
Gtk::TextBuffer::iterator tit = m_refTxtBufferDec->begin();
string in = tit.get_text(m_refTxtBufferDec->end());
if (this->encrypt) {
if (in == "") {
m_refTxtBuffer->set_text("encrypt");
}
on_enc_button_clicked();
this->swEncDec.set_label("Encrypt");
}
else {
on_dec_button_clicked();
this->swEncDec.set_label("Decrypt");
}
}
void CoolCryptoWindow::change_window_based_on_text() {
this->set_resizable(true);
this->resize(this->m_MainBox.get_width(), this->m_MainBox.get_height());
this->set_resizable(false);
}