summaryrefslogtreecommitdiff
path: root/plugins/New_GPG/src/ui.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-07-11 17:09:17 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-07-11 17:09:17 +0300
commitb2c91edc9646daa331de71d589e4fec6bdef4945 (patch)
tree847a77d0686d26e25b126313fbaa8262c81f8d1a /plugins/New_GPG/src/ui.cpp
parentae081843e9663b3cb36b17309fbce1d2967315f1 (diff)
GUI change:
- methods OnInitDialog, OnApply & OnClose of CDlgBase now return true if successful. return of false prevents a dialog from being loaded or left respectively; - massive code cleaning considering the 'virtual' attribute of overridden methods; - also fixes #1476 (Don't close "Create new account" window if user not set account name)
Diffstat (limited to 'plugins/New_GPG/src/ui.cpp')
-rwxr-xr-xplugins/New_GPG/src/ui.cpp320
1 files changed, 185 insertions, 135 deletions
diff --git a/plugins/New_GPG/src/ui.cpp b/plugins/New_GPG/src/ui.cpp
index 69216fcb5a..1ff5613792 100755
--- a/plugins/New_GPG/src/ui.cpp
+++ b/plugins/New_GPG/src/ui.cpp
@@ -17,29 +17,27 @@
#include "stdafx.h"
-//HWND hwndFirstRun = nullptr, hwndSetDirs = nullptr, hwndNewKey = nullptr, hwndKeyGen = nullptr, hwndSelectExistingKey = nullptr;
+/////////////////////////////////////////////////////////////////////////////////////////
-CCtrlListView *list_hwndList_g = nullptr;
-
-
-void CDlgEncryptedFileMsgBox::OnInitDialog()
+bool CDlgEncryptedFileMsgBox::OnInitDialog()
{
globals.bDecryptFiles = false;
+ return true;
}
-CDlgEncryptedFileMsgBox::CDlgEncryptedFileMsgBox() : CDlgBase(g_plugin, IDD_ENCRYPTED_FILE_MSG_BOX),
-chk_REMEMBER(this, IDC_REMEMBER),
-btn_IGNORE(this, IDC_IGNORE), btn_DECRYPT(this, IDC_DECRYPT)
+CDlgEncryptedFileMsgBox::CDlgEncryptedFileMsgBox() :
+ CDlgBase(g_plugin, IDD_ENCRYPTED_FILE_MSG_BOX),
+ chk_REMEMBER(this, IDC_REMEMBER),
+ btn_IGNORE(this, IDC_IGNORE),
+ btn_DECRYPT(this, IDC_DECRYPT)
{
btn_IGNORE.OnClick = Callback(this, &CDlgEncryptedFileMsgBox::onClick_IGNORE);
btn_DECRYPT.OnClick = Callback(this, &CDlgEncryptedFileMsgBox::onClick_DECRYPT);
}
-
void CDlgEncryptedFileMsgBox::onClick_IGNORE(CCtrlButton*)
{
- if (chk_REMEMBER.GetState())
- {
+ if (chk_REMEMBER.GetState()) {
db_set_b(NULL, MODULENAME, "bSameAction", 1);
globals.bSameAction = true;
}
@@ -49,8 +47,7 @@ void CDlgEncryptedFileMsgBox::onClick_IGNORE(CCtrlButton*)
void CDlgEncryptedFileMsgBox::onClick_DECRYPT(CCtrlButton*)
{
globals.bDecryptFiles = true;
- if (chk_REMEMBER.GetState())
- {
+ if (chk_REMEMBER.GetState()) {
db_set_b(NULL, MODULENAME, "bFileTransfers", 1);
globals.bFileTransfers = true;
db_set_b(NULL, MODULENAME, "bSameAction", 0);
@@ -59,19 +56,26 @@ void CDlgEncryptedFileMsgBox::onClick_DECRYPT(CCtrlButton*)
this->Close();
}
+/////////////////////////////////////////////////////////////////////////////////////////
-
-CDlgExportKeysMsgBox::CDlgExportKeysMsgBox() : CDlgBase(g_plugin, IDD_EXPORT_TYPE),
-btn_OK(this, IDC_OK), btn_CANCEL(this, IDC_CANCEL),
-chk_PUBLIC(this, IDC_PUBLIC), chk_PRIVATE(this, IDC_PRIVATE), chk_ALL(this, IDC_ALL)
+CDlgExportKeysMsgBox::CDlgExportKeysMsgBox() :
+ CDlgBase(g_plugin, IDD_EXPORT_TYPE),
+ btn_OK(this, IDC_OK),
+ btn_CANCEL(this, IDC_CANCEL),
+ chk_PUBLIC(this, IDC_PUBLIC),
+ chk_PRIVATE(this, IDC_PRIVATE),
+ chk_ALL(this, IDC_ALL)
{
btn_OK.OnClick = Callback(this, &CDlgExportKeysMsgBox::onClick_OK);
btn_CANCEL.OnClick = Callback(this, &CDlgExportKeysMsgBox::onClick_CANCEL);
}
-void CDlgExportKeysMsgBox::OnInitDialog()
+
+bool CDlgExportKeysMsgBox::OnInitDialog()
{
chk_PUBLIC.SetState(1);
+ return true;
}
+
void CDlgExportKeysMsgBox::onClick_OK(CCtrlButton*)
{
if (chk_PUBLIC.GetState())
@@ -87,11 +91,14 @@ void CDlgExportKeysMsgBox::onClick_CANCEL(CCtrlButton*)
this->Close();
}
+/////////////////////////////////////////////////////////////////////////////////////////
-
-CDlgChangePasswdMsgBox::CDlgChangePasswdMsgBox() : CDlgBase(g_plugin, IDD_CHANGE_PASSWD),
-btn_OK(this, ID_OK),
-edit_NEW_PASSWD1(this, IDC_NEW_PASSWD1), edit_NEW_PASSWD2(this, IDC_NEW_PASSWD2), edit_OLD_PASSWD(this, IDC_OLD_PASSWD)
+CDlgChangePasswdMsgBox::CDlgChangePasswdMsgBox() :
+ CDlgBase(g_plugin, IDD_CHANGE_PASSWD),
+ btn_OK(this, ID_OK),
+ edit_NEW_PASSWD1(this, IDC_NEW_PASSWD1),
+ edit_NEW_PASSWD2(this, IDC_NEW_PASSWD2),
+ edit_OLD_PASSWD(this, IDC_OLD_PASSWD)
{
btn_OK.OnClick = Callback(this, &CDlgChangePasswdMsgBox::onClick_OK);
}
@@ -100,8 +107,7 @@ void CDlgChangePasswdMsgBox::onClick_OK(CCtrlButton*)
{
//TODO: show some prgress
{
- if (mir_wstrcmp(edit_NEW_PASSWD1.GetText(), edit_NEW_PASSWD2.GetText()))
- {
+ if (mir_wstrcmp(edit_NEW_PASSWD1.GetText(), edit_NEW_PASSWD2.GetText())) {
MessageBox(m_hwnd, TranslateT("New passwords do not match"), TranslateT("Error"), MB_OK);
return;
}
@@ -158,18 +164,25 @@ void CDlgChangePasswdMsgBox::onClick_OK(CCtrlButton*)
this->Close();
}
-
-
-CDlgFirstRun::CDlgFirstRun() : CDlgBase(g_plugin, IDD_FIRST_RUN),
-list_KEY_LIST(this, IDC_KEY_LIST),
-btn_COPY_PUBKEY(this, IDC_COPY_PUBKEY), btn_EXPORT_PRIVATE(this, IDC_EXPORT_PRIVATE), btn_CHANGE_PASSWD(this, IDC_CHANGE_PASSWD), btn_GENERATE_RANDOM(this, IDC_GENERATE_RANDOM),
-btn_GENERATE_KEY(this, IDC_GENERATE_KEY), btn_OTHER(this, IDC_OTHER), btn_DELETE_KEY(this, IDC_DELETE_KEY), btn_OK(this, ID_OK),
-edit_KEY_PASSWORD(this, IDC_KEY_PASSWORD),
-combo_ACCOUNT(this, IDC_ACCOUNT),
-lbl_KEY_ID(this, IDC_KEY_ID), lbl_GENERATING_KEY(this, IDC_GENERATING_KEY)
+/////////////////////////////////////////////////////////////////////////////////////////
+
+CDlgFirstRun::CDlgFirstRun() :
+ CDlgBase(g_plugin, IDD_FIRST_RUN),
+ list_KEY_LIST(this, IDC_KEY_LIST),
+ btn_COPY_PUBKEY(this, IDC_COPY_PUBKEY),
+ btn_EXPORT_PRIVATE(this, IDC_EXPORT_PRIVATE),
+ btn_CHANGE_PASSWD(this, IDC_CHANGE_PASSWD),
+ btn_GENERATE_RANDOM(this, IDC_GENERATE_RANDOM),
+ btn_GENERATE_KEY(this, IDC_GENERATE_KEY),
+ btn_OTHER(this, IDC_OTHER),
+ btn_DELETE_KEY(this, IDC_DELETE_KEY),
+ btn_OK(this, ID_OK),
+ edit_KEY_PASSWORD(this, IDC_KEY_PASSWORD),
+ combo_ACCOUNT(this, IDC_ACCOUNT),
+ lbl_KEY_ID(this, IDC_KEY_ID),
+ lbl_GENERATING_KEY(this, IDC_GENERATING_KEY)
{
fp[0] = 0;
- list_hwndList_g = &list_KEY_LIST;
btn_COPY_PUBKEY.OnClick = Callback(this, &CDlgFirstRun::onClick_COPY_PUBKEY);
btn_EXPORT_PRIVATE.OnClick = Callback(this, &CDlgFirstRun::onClick_EXPORT_PRIVATE);
@@ -181,7 +194,8 @@ lbl_KEY_ID(this, IDC_KEY_ID), lbl_GENERATING_KEY(this, IDC_GENERATING_KEY)
btn_OK.OnClick = Callback(this, &CDlgFirstRun::onClick_OK);
}
-void CDlgFirstRun::OnInitDialog()
+
+bool CDlgFirstRun::OnInitDialog()
{
SetWindowPos(m_hwnd, nullptr, globals.firstrun_rect.left, globals.firstrun_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
SetCaption(TranslateT("Set own key"));
@@ -224,14 +238,15 @@ void CDlgFirstRun::OnInitDialog()
combo_ACCOUNT.OnChange = Callback(this, &CDlgFirstRun::onChange_ACCOUNT);
list_KEY_LIST.OnClick = Callback(this, &CDlgFirstRun::onChange_KEY_LIST);
+ return true;
}
+
void CDlgFirstRun::onClick_COPY_PUBKEY(CCtrlButton*)
{
int i = list_KEY_LIST.GetSelectionMark();
if (i == -1)
return;
- if (OpenClipboard(m_hwnd))
- {
+ if (OpenClipboard(m_hwnd)) {
list_KEY_LIST.GetItemText(i, 0, fp, _countof(fp));
string out;
DWORD code;
@@ -275,6 +290,7 @@ void CDlgFirstRun::onClick_COPY_PUBKEY(CCtrlButton*)
CloseClipboard();
}
}
+
void CDlgFirstRun::onClick_EXPORT_PRIVATE(CCtrlButton*)
{
{
@@ -318,6 +334,7 @@ void CDlgFirstRun::onClick_EXPORT_PRIVATE(CCtrlButton*)
file.close();
}
}
+
void CDlgFirstRun::onClick_CHANGE_PASSWD(CCtrlButton*)
{
int i = list_KEY_LIST.GetSelectionMark();
@@ -349,6 +366,7 @@ void CDlgFirstRun::onClick_CHANGE_PASSWD(CCtrlButton*)
}
}
+
void CDlgFirstRun::onClick_GENERATE_RANDOM(CCtrlButton*)
{
lbl_GENERATING_KEY.SendMsg(WM_SETFONT, (WPARAM)globals.bold_font, TRUE);
@@ -361,12 +379,14 @@ void CDlgFirstRun::onClick_GENERATE_RANDOM(CCtrlButton*)
gpg_use_new_random_key(combo_ACCOUNT.GetTextA());
this->Close();
}
+
void CDlgFirstRun::onClick_GENERATE_KEY(CCtrlButton*)
{
CDlgKeyGen *d = new CDlgKeyGen;
d->DoModal();
refresh_key_list();
}
+
void CDlgFirstRun::onClick_OTHER(CCtrlButton*)
{
void ShowLoadPublicKeyDialog(bool = false);
@@ -375,6 +395,7 @@ void CDlgFirstRun::onClick_OTHER(CCtrlButton*)
ShowLoadPublicKeyDialog(true);
refresh_key_list();
}
+
void CDlgFirstRun::onClick_DELETE_KEY(CCtrlButton*)
{
int i = list_KEY_LIST.GetSelectionMark();
@@ -456,6 +477,7 @@ void CDlgFirstRun::onClick_DELETE_KEY(CCtrlButton*)
}
list_KEY_LIST.DeleteItem(i);
}
+
void CDlgFirstRun::onClick_OK(CCtrlButton*)
{
{
@@ -485,13 +507,11 @@ void CDlgFirstRun::onClick_OK(CCtrlButton*)
params.out = &out;
params.code = &code;
params.result = &result;
- if (!gpg_launcher(params))
- {
+ if (!gpg_launcher(params)) {
delete[] name;
return;
}
- if (result == pxNotFound)
- {
+ if (result == pxNotFound) {
delete[] name;
return;
}
@@ -526,8 +546,7 @@ void CDlgFirstRun::onClick_OK(CCtrlButton*)
mir_free(buf);
}
wchar_t *passwd = mir_wstrdup(edit_KEY_PASSWORD.GetText());
- if (passwd && passwd[0])
- {
+ if (passwd && passwd[0]) {
string dbsetting = "szKey_";
char *keyid = mir_u2a(fp);
dbsetting += keyid;
@@ -543,6 +562,7 @@ void CDlgFirstRun::onClick_OK(CCtrlButton*)
globals.gpg_keyexist = isGPGKeyExist();
DestroyWindow(m_hwnd);
}
+
void CDlgFirstRun::onChange_ACCOUNT(CCtrlCombo*)
{
char *buf = mir_strdup(combo_ACCOUNT.GetTextA());
@@ -567,10 +587,10 @@ void CDlgFirstRun::onChange_ACCOUNT(CCtrlCombo*)
if (buf)
mir_free(buf);
}
+
void CDlgFirstRun::onChange_KEY_LIST(CCtrlListView::TEventInfo *ev) //TODO: check if this work
{
- if (ev->nmlv)
- {
+ if (ev->nmlv) {
NMLISTVIEW *hdr = ev->nmlv;
if (hdr->hdr.code == NM_CLICK) {
@@ -581,6 +601,7 @@ void CDlgFirstRun::onChange_KEY_LIST(CCtrlListView::TEventInfo *ev) //TODO: chec
}
}
}
+
void CDlgFirstRun::OnDestroy()
{
GetWindowRect(m_hwnd, &globals.firstrun_rect);
@@ -588,7 +609,6 @@ void CDlgFirstRun::OnDestroy()
db_set_dw(NULL, MODULENAME, "FirstrunWindowY", globals.firstrun_rect.top);
}
-
void CDlgFirstRun::refresh_key_list()
{
list_KEY_LIST.DeleteAllItems();
@@ -732,19 +752,25 @@ void CDlgFirstRun::refresh_key_list()
}
}
-
-
-CDlgGpgBinOpts::CDlgGpgBinOpts() : CDlgBase(g_plugin, IDD_BIN_PATH),
-btn_SET_BIN_PATH(this, IDC_SET_BIN_PATH), btn_SET_HOME_DIR(this, IDC_SET_HOME_DIR), btn_OK(this, ID_OK), btn_GENERATE_RANDOM(this, IDC_GENERATE_RANDOM),
-edit_BIN_PATH(this, IDC_BIN_PATH), edit_HOME_DIR(this, IDC_HOME_DIR),
-chk_AUTO_EXCHANGE(this, IDC_AUTO_EXCHANGE)
+/////////////////////////////////////////////////////////////////////////////////////////
+
+CDlgGpgBinOpts::CDlgGpgBinOpts() :
+ CDlgBase(g_plugin, IDD_BIN_PATH),
+ btn_SET_BIN_PATH(this, IDC_SET_BIN_PATH),
+ btn_SET_HOME_DIR(this, IDC_SET_HOME_DIR),
+ btn_OK(this, ID_OK),
+ btn_GENERATE_RANDOM(this, IDC_GENERATE_RANDOM),
+ edit_BIN_PATH(this, IDC_BIN_PATH),
+ edit_HOME_DIR(this, IDC_HOME_DIR),
+ chk_AUTO_EXCHANGE(this, IDC_AUTO_EXCHANGE)
{
btn_SET_BIN_PATH.OnClick = Callback(this, &CDlgGpgBinOpts::onClick_SET_BIN_PATH);
btn_SET_HOME_DIR.OnClick = Callback(this, &CDlgGpgBinOpts::onClick_SET_HOME_DIR);
btn_OK.OnClick = Callback(this, &CDlgGpgBinOpts::onClick_OK);
btn_GENERATE_RANDOM.OnClick = Callback(this, &CDlgGpgBinOpts::onClick_GENERATE_RANDOM);
}
-void CDlgGpgBinOpts::OnInitDialog()
+
+bool CDlgGpgBinOpts::OnInitDialog()
{
CMStringW path;
bool gpg_exists = false, lang_exists = false;
@@ -832,7 +858,9 @@ void CDlgGpgBinOpts::OnInitDialog()
if (gpg_exists && lang_exists && !bad_version)
MessageBox(nullptr, TranslateT("Your GPG version is supported. The language file was found.\nGPG plugin should work fine.\nPress OK to continue."), TranslateT("Info"), MB_OK);
chk_AUTO_EXCHANGE.Enable();
+ return true;
}
+
void CDlgGpgBinOpts::onClick_SET_BIN_PATH(CCtrlButton*)
{
GetFilePath(L"Choose gpg.exe", "szGpgBinPath", L"*.exe", L"EXE Executables");
@@ -840,13 +868,12 @@ void CDlgGpgBinOpts::onClick_SET_BIN_PATH(CCtrlButton*)
edit_BIN_PATH.SetText(tmp);
wchar_t mir_path[MAX_PATH];
PathToAbsoluteW(L"\\", mir_path);
- if (tmp.Find(mir_path, 0) == 0)
- {
+ if (tmp.Find(mir_path, 0) == 0) {
CMStringW path = tmp.Mid(mir_wstrlen(mir_path));
edit_BIN_PATH.SetText(path);
}
-
}
+
void CDlgGpgBinOpts::onClick_SET_HOME_DIR(CCtrlButton*)
{
GetFolderPath(L"Set home directory", "szHomePath");
@@ -863,8 +890,7 @@ void CDlgGpgBinOpts::onClick_SET_HOME_DIR(CCtrlButton*)
}
void CDlgGpgBinOpts::onClick_OK(CCtrlButton*)
{
- if (gpg_validate_paths(edit_BIN_PATH.GetText(), edit_HOME_DIR.GetText()))
- {
+ if (gpg_validate_paths(edit_BIN_PATH.GetText(), edit_HOME_DIR.GetText())) {
gpg_save_paths(edit_BIN_PATH.GetText(), edit_HOME_DIR.GetText());
globals.gpg_valid = true;
db_set_b(NULL, MODULENAME, "FirstRun", 0);
@@ -874,14 +900,13 @@ void CDlgGpgBinOpts::onClick_OK(CCtrlButton*)
this->Close();
}
}
+
void CDlgGpgBinOpts::onClick_GENERATE_RANDOM(CCtrlButton*)
{
- if (gpg_validate_paths(edit_BIN_PATH.GetText(), edit_HOME_DIR.GetText()))
- {
+ if (gpg_validate_paths(edit_BIN_PATH.GetText(), edit_HOME_DIR.GetText())) {
gpg_save_paths(edit_BIN_PATH.GetText(), edit_HOME_DIR.GetText());
globals.gpg_valid = true;
- if (gpg_use_new_random_key())
- {
+ if (gpg_use_new_random_key()) {
db_set_b(NULL, MODULENAME, "bAutoExchange", globals.bAutoExchange = chk_AUTO_EXCHANGE.GetState());
globals.gpg_valid = true;
db_set_b(NULL, MODULENAME, "FirstRun", 0);
@@ -889,24 +914,31 @@ void CDlgGpgBinOpts::onClick_GENERATE_RANDOM(CCtrlButton*)
}
}
}
+
void CDlgGpgBinOpts::OnDestroy()
{
void InitCheck();
InitCheck();
}
-CDlgNewKey::CDlgNewKey(MCONTACT _hContact, wstring _new_key) : CDlgBase(g_plugin, IDD_NEW_KEY),
-lbl_KEY_FROM(this, IDC_KEY_FROM), lbl_MESSAGE(this, IDC_MESSAGE),
-btn_IMPORT(this, ID_IMPORT), btn_IMPORT_AND_USE(this, IDC_IMPORT_AND_USE), btn_IGNORE_KEY(this, IDC_IGNORE_KEY)
+/////////////////////////////////////////////////////////////////////////////////////////
+
+CDlgNewKey::CDlgNewKey(MCONTACT _hContact, wstring _new_key) :
+ CDlgBase(g_plugin, IDD_NEW_KEY),
+ lbl_KEY_FROM(this, IDC_KEY_FROM),
+ lbl_MESSAGE(this, IDC_MESSAGE),
+ btn_IMPORT(this, ID_IMPORT),
+ btn_IMPORT_AND_USE(this, IDC_IMPORT_AND_USE),
+ btn_IGNORE_KEY(this, IDC_IGNORE_KEY)
{
hContact = _hContact;
new_key = _new_key;
btn_IMPORT.OnClick = Callback(this, &CDlgNewKey::onClick_IMPORT);
btn_IMPORT_AND_USE.OnClick = Callback(this, &CDlgNewKey::onClick_IMPORT_AND_USE);
btn_IGNORE_KEY.OnClick = Callback(this, &CDlgNewKey::onClick_IGNORE_KEY);
-
}
-void CDlgNewKey::OnInitDialog()
+
+bool CDlgNewKey::OnInitDialog()
{
//new_key_hcnt_mutex.unlock();
SetWindowPos(m_hwnd, nullptr, globals.new_key_rect.left, globals.new_key_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
@@ -919,18 +951,22 @@ void CDlgNewKey::OnInitDialog()
mir_snwprintf(tmp, 255 * sizeof(wchar_t), TranslateT("Received key from %s"), Clist_GetContactDisplayName(hContact));
lbl_KEY_FROM.SetText(tmp);
mir_free(tmp);
+ return true;
}
+
void CDlgNewKey::OnDestroy()
{
GetWindowRect(m_hwnd, &globals.new_key_rect);
db_set_dw(NULL, MODULENAME, "NewKeyWindowX", globals.new_key_rect.left);
db_set_dw(NULL, MODULENAME, "NewKeyWindowY", globals.new_key_rect.top);
}
+
void CDlgNewKey::onClick_IMPORT(CCtrlButton*)
{
ImportKey(hContact, new_key);
this->Close();
}
+
void CDlgNewKey::onClick_IMPORT_AND_USE(CCtrlButton*)
{
ImportKey(hContact, new_key);
@@ -941,22 +977,31 @@ void CDlgNewKey::onClick_IMPORT_AND_USE(CCtrlButton*)
setClistIcon(hContact);
this->Close();
}
+
void CDlgNewKey::onClick_IGNORE_KEY(CCtrlButton*)
{
this->Close();
}
-CDlgKeyGen::CDlgKeyGen() : CDlgBase(g_plugin, IDD_KEY_GEN),
-combo_KEY_TYPE(this, IDC_KEY_TYPE),
-edit_KEY_LENGTH(this, IDC_KEY_LENGTH), edit_KEY_PASSWD(this, IDC_KEY_PASSWD), edit_KEY_REAL_NAME(this, IDC_KEY_REAL_NAME), edit_KEY_EMAIL(this, IDC_KEY_EMAIL), edit_KEY_COMMENT(this, IDC_KEY_COMMENT),
-edit_KEY_EXPIRE_DATE(this, IDC_KEY_EXPIRE_DATE),
-lbl_GENERATING_TEXT(this, IDC_GENERATING_TEXT),
-btn_OK(this, IDOK), btn_CANCEL(this, IDCANCEL)
+/////////////////////////////////////////////////////////////////////////////////////////
+
+CDlgKeyGen::CDlgKeyGen() :
+ CDlgBase(g_plugin, IDD_KEY_GEN),
+ combo_KEY_TYPE(this, IDC_KEY_TYPE),
+ edit_KEY_LENGTH(this, IDC_KEY_LENGTH),
+ edit_KEY_PASSWD(this, IDC_KEY_PASSWD),
+ edit_KEY_REAL_NAME(this, IDC_KEY_REAL_NAME),
+ edit_KEY_EMAIL(this, IDC_KEY_EMAIL),
+ edit_KEY_COMMENT(this, IDC_KEY_COMMENT),
+ edit_KEY_EXPIRE_DATE(this, IDC_KEY_EXPIRE_DATE),
+ lbl_GENERATING_TEXT(this, IDC_GENERATING_TEXT),
+ btn_OK(this, IDOK), btn_CANCEL(this, IDCANCEL)
{
btn_OK.OnClick = Callback(this, &CDlgKeyGen::onClick_OK);
btn_CANCEL.OnClick = Callback(this, &CDlgKeyGen::onClick_CANCEL);
}
-void CDlgKeyGen::OnInitDialog()
+
+bool CDlgKeyGen::OnInitDialog()
{
SetWindowPos(m_hwnd, nullptr, globals.key_gen_rect.left, globals.key_gen_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
SetCaption(TranslateT("Key Generation dialog"));
@@ -965,6 +1010,7 @@ void CDlgKeyGen::OnInitDialog()
combo_KEY_TYPE.SelectString(L"RSA");
edit_KEY_EXPIRE_DATE.SetText(L"0");
edit_KEY_LENGTH.SetText(L"4096");
+ return true;
}
void CDlgKeyGen::onClick_OK(CCtrlButton*)
@@ -973,13 +1019,11 @@ void CDlgKeyGen::onClick_OK(CCtrlButton*)
wstring path;
{ //data sanity checks
wchar_t *tmp = mir_wstrdup(combo_KEY_TYPE.GetText());
- if (!tmp)
- {
+ if (!tmp) {
MessageBox(nullptr, TranslateT("You must set encryption algorithm first"), TranslateT("Error"), MB_OK);
return;
}
- if (mir_wstrlen(tmp) < 3)
- {
+ if (mir_wstrlen(tmp) < 3) {
mir_free(tmp);
tmp = nullptr;
MessageBox(nullptr, TranslateT("You must set encryption algorithm first"), TranslateT("Error"), MB_OK);
@@ -987,8 +1031,7 @@ void CDlgKeyGen::onClick_OK(CCtrlButton*)
}
mir_free(tmp);
tmp = mir_wstrdup(edit_KEY_LENGTH.GetText());
- if (!tmp)
- {
+ if (!tmp) {
MessageBox(nullptr, TranslateT("Key length must be of length from 1024 to 4096 bits"), TranslateT("Error"), MB_OK);
return;
}
@@ -999,8 +1042,7 @@ void CDlgKeyGen::onClick_OK(CCtrlButton*)
return;
}
tmp = mir_wstrdup(edit_KEY_EXPIRE_DATE.GetText());
- if (!tmp)
- {
+ if (!tmp) {
MessageBox(nullptr, TranslateT("Invalid date"), TranslateT("Error"), MB_OK);
return;
}
@@ -1011,8 +1053,7 @@ void CDlgKeyGen::onClick_OK(CCtrlButton*)
}
mir_free(tmp);
tmp = mir_wstrdup(edit_KEY_REAL_NAME.GetText());
- if (!tmp)
- {
+ if (!tmp) {
MessageBox(nullptr, TranslateT("Name must contain at least 5 characters"), TranslateT("Error"), MB_OK);
return;
}
@@ -1021,16 +1062,14 @@ void CDlgKeyGen::onClick_OK(CCtrlButton*)
mir_free(tmp);
return;
}
- else if (wcschr(tmp, '(') || wcschr(tmp, ')'))
- {
+ else if (wcschr(tmp, '(') || wcschr(tmp, ')')) {
MessageBox(nullptr, TranslateT("Name cannot contain '(' or ')'"), TranslateT("Error"), MB_OK);
mir_free(tmp);
return;
}
mir_free(tmp);
tmp = mir_wstrdup(edit_KEY_EMAIL.GetText());
- if (!tmp)
- {
+ if (!tmp) {
MessageBox(nullptr, TranslateT("Invalid Email"), TranslateT("Error"), MB_OK);
return;
}
@@ -1073,8 +1112,7 @@ void CDlgKeyGen::onClick_OK(CCtrlButton*)
f << subkeytype;
mir_free(subkeytype);
f << "\n";
- if (edit_KEY_PASSWD.GetText()[0])
- {
+ if (edit_KEY_PASSWD.GetText()[0]) {
f << "Passphrase: ";
f << toUTF8(edit_KEY_PASSWD.GetText()).c_str();
f << "\n";
@@ -1082,8 +1120,7 @@ void CDlgKeyGen::onClick_OK(CCtrlButton*)
f << "Name-Real: ";
f << toUTF8(edit_KEY_REAL_NAME.GetText()).c_str();
f << "\n";
- if (edit_KEY_COMMENT.GetText()[0])
- {
+ if (edit_KEY_COMMENT.GetText()[0]) {
f << "Name-Comment: ";
f << toUTF8(edit_KEY_COMMENT.GetText()).c_str();
f << "\n";
@@ -1129,10 +1166,12 @@ void CDlgKeyGen::onClick_OK(CCtrlButton*)
}
this->Close();
}
+
void CDlgKeyGen::onClick_CANCEL(CCtrlButton*)
{
this->Close();
}
+
void CDlgKeyGen::OnDestroy()
{
GetWindowRect(m_hwnd, &globals.key_gen_rect);
@@ -1140,20 +1179,24 @@ void CDlgKeyGen::OnDestroy()
db_set_dw(NULL, MODULENAME, "KeyGenWindowY", globals.key_gen_rect.top);
}
-CDlgLoadExistingKey::CDlgLoadExistingKey() : CDlgBase(g_plugin, IDD_LOAD_EXISTING_KEY),
-btn_OK(this, IDOK), btn_CANCEL(this, IDCANCEL),
-list_EXISTING_KEY_LIST(this, IDC_EXISTING_KEY_LIST)
+/////////////////////////////////////////////////////////////////////////////////////////
+
+CDlgLoadExistingKey::CDlgLoadExistingKey() :
+ CDlgBase(g_plugin, IDD_LOAD_EXISTING_KEY),
+ btn_OK(this, IDOK),
+ btn_CANCEL(this, IDCANCEL),
+ list_EXISTING_KEY_LIST(this, IDC_EXISTING_KEY_LIST)
{
id[0] = 0;
btn_OK.OnClick = Callback(this, &CDlgLoadExistingKey::onClick_OK);
btn_CANCEL.OnClick = Callback(this, &CDlgLoadExistingKey::onClick_CANCEL);
}
-void CDlgLoadExistingKey::OnInitDialog()
+
+bool CDlgLoadExistingKey::OnInitDialog()
{
SetWindowPos(m_hwnd, nullptr, globals.load_existing_key_rect.left, globals.load_existing_key_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
-
list_EXISTING_KEY_LIST.AddColumn(0, TranslateT("Key ID"), 50);
list_EXISTING_KEY_LIST.AddColumn(1, TranslateT("Email"), 30);
list_EXISTING_KEY_LIST.AddColumn(2, TranslateT("Name"), 250);
@@ -1177,12 +1220,11 @@ void CDlgLoadExistingKey::OnInitDialog()
params.code = &code;
params.result = &result;
if (!gpg_launcher(params))
- return;
+ return false;
if (result == pxNotFound)
- return;
+ return false;
}
- while (p != string::npos)
- {
+ while (p != string::npos) {
if ((p = out.find("pub ", p)) == string::npos)
break;
p += 5;
@@ -1202,8 +1244,7 @@ void CDlgLoadExistingKey::OnInitDialog()
p++;
p2 = out.find("\n", p);
string::size_type p3 = out.substr(p, p2 - p).find("[");
- if (p3 != string::npos)
- {
+ if (p3 != string::npos) {
p3 += p;
p2 = p3;
p2--;
@@ -1223,8 +1264,7 @@ void CDlgLoadExistingKey::OnInitDialog()
p += mir_strlen("uid ");
p2 = out.find("\n", p);
p3 = out.substr(p, p2 - p).find("<");
- if (p3 != string::npos)
- {
+ if (p3 != string::npos) {
p3 += p;
p2 = p3;
p2--;
@@ -1240,12 +1280,7 @@ void CDlgLoadExistingKey::OnInitDialog()
tmp = mir_wstrdup(toUTF16(out.substr(p, p2 - p)).c_str());
list_EXISTING_KEY_LIST.SetItemText(row, 2, tmp);
mir_free(tmp);
- // p = out.find("sub ", p2) + 6;
- // p = out.find(" ", p) + 1;
- // p2 = out.find("\n", p);
- // tmp = mir_wstrdup(toUTF16(out.substr(p,p2-p-1)).c_str());
- // ListView_SetItemText(hwndList, iRow, 3, tmp);
- // mir_free(tmp);
+
list_EXISTING_KEY_LIST.SetColumnWidth(0, LVSCW_AUTOSIZE);// not sure about this
list_EXISTING_KEY_LIST.SetColumnWidth(1, LVSCW_AUTOSIZE);
list_EXISTING_KEY_LIST.SetColumnWidth(2, LVSCW_AUTOSIZE);
@@ -1257,13 +1292,16 @@ void CDlgLoadExistingKey::OnInitDialog()
}
}
list_EXISTING_KEY_LIST.OnClick = Callback(this, &CDlgLoadExistingKey::onChange_EXISTING_KEY_LIST);
+ return true;
}
+
void CDlgLoadExistingKey::OnDestroy()
{
GetWindowRect(m_hwnd, &globals.load_existing_key_rect);
db_set_dw(NULL, MODULENAME, "LoadExistingKeyWindowX", globals.load_existing_key_rect.left);
db_set_dw(NULL, MODULENAME, "LoadExistingKeyWindowY", globals.load_existing_key_rect.top);
}
+
void CDlgLoadExistingKey::onClick_OK(CCtrlButton*)
{
int i = list_EXISTING_KEY_LIST.GetSelectionMark();
@@ -1292,6 +1330,7 @@ void CDlgLoadExistingKey::onClick_OK(CCtrlButton*)
while ((s = out.find("\r", s)) != string::npos) {
out.erase(s, 1);
}
+
std::string::size_type p1 = 0, p2 = 0;
p1 = out.find("-----BEGIN PGP PUBLIC KEY BLOCK-----");
if (p1 != std::string::npos) {
@@ -1304,12 +1343,10 @@ void CDlgLoadExistingKey::onClick_OK(CCtrlButton*)
edit_p_PubKeyEdit->SetText(tmp);
mir_free(tmp);
}
- else
- MessageBox(nullptr, TranslateT("Failed to export public key."), TranslateT("Error"), MB_OK);
+ else MessageBox(nullptr, TranslateT("Failed to export public key."), TranslateT("Error"), MB_OK);
}
- else
- MessageBox(nullptr, TranslateT("Failed to export public key."), TranslateT("Error"), MB_OK);
- // SetDlgItemText(hPubKeyEdit, IDC_PUBLIC_KEY_EDIT, tmp);
+ else MessageBox(nullptr, TranslateT("Failed to export public key."), TranslateT("Error"), MB_OK);
+
this->Close();
}
void CDlgLoadExistingKey::onClick_CANCEL(CCtrlButton*)
@@ -1323,25 +1360,32 @@ void CDlgLoadExistingKey::onChange_EXISTING_KEY_LIST(CCtrlListView::TEventInfo *
btn_OK.Enable();
}
-CDlgImportKey::CDlgImportKey(MCONTACT _hContact) : CDlgBase(g_plugin, IDD_IMPORT_KEY),
-combo_KEYSERVER(this, IDC_KEYSERVER),
-btn_IMPORT(this, IDC_IMPORT)
+/////////////////////////////////////////////////////////////////////////////////////////
+
+CDlgImportKey::CDlgImportKey(MCONTACT _hContact) :
+ CDlgBase(g_plugin, IDD_IMPORT_KEY),
+ combo_KEYSERVER(this, IDC_KEYSERVER),
+ btn_IMPORT(this, IDC_IMPORT)
{
hContact = _hContact;
btn_IMPORT.OnClick = Callback(this, &CDlgImportKey::onClick_IMPORT);
}
-void CDlgImportKey::OnInitDialog()
+
+bool CDlgImportKey::OnInitDialog()
{
SetWindowPos(m_hwnd, nullptr, globals.import_key_rect.left, globals.import_key_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
combo_KEYSERVER.AddString(L"subkeys.pgp.net");
combo_KEYSERVER.AddString(L"keys.gnupg.net");
+ return true;
}
+
void CDlgImportKey::OnDestroy()
{
GetWindowRect(m_hwnd, &globals.import_key_rect);
db_set_dw(NULL, MODULENAME, "ImportKeyWindowX", globals.import_key_rect.left);
db_set_dw(NULL, MODULENAME, "ImportKeyWindowY", globals.import_key_rect.top);
}
+
void CDlgImportKey::onClick_IMPORT(CCtrlButton*)
{
string out;
@@ -1360,31 +1404,36 @@ void CDlgImportKey::onClick_IMPORT(CCtrlButton*)
MessageBoxA(nullptr, out.c_str(), "GPG output", MB_OK);
}
+/////////////////////////////////////////////////////////////////////////////////////////
-
-CDlgKeyPasswordMsgBox::CDlgKeyPasswordMsgBox(MCONTACT _hContact) : CDlgBase(g_plugin, IDD_KEY_PASSWD),
-lbl_KEYID(this, IDC_KEYID),
-edit_KEY_PASSWORD(this, IDC_KEY_PASSWORD),
-chk_DEFAULT_PASSWORD(this, IDC_DEFAULT_PASSWORD), chk_SAVE_PASSWORD(this, IDC_SAVE_PASSWORD),
-btn_OK(this, IDOK), btn_CANCEL(this, IDCANCEL)
+CDlgKeyPasswordMsgBox::CDlgKeyPasswordMsgBox(MCONTACT _hContact) :
+ CDlgBase(g_plugin, IDD_KEY_PASSWD),
+ lbl_KEYID(this, IDC_KEYID),
+ edit_KEY_PASSWORD(this, IDC_KEY_PASSWORD),
+ chk_DEFAULT_PASSWORD(this, IDC_DEFAULT_PASSWORD),
+ chk_SAVE_PASSWORD(this, IDC_SAVE_PASSWORD),
+ btn_OK(this, IDOK),
+ btn_CANCEL(this, IDCANCEL)
{
hContact = _hContact;
btn_OK.OnClick = Callback(this, &CDlgKeyPasswordMsgBox::onClick_OK);
btn_CANCEL.OnClick = Callback(this, &CDlgKeyPasswordMsgBox::onClick_CANCEL);
}
-void CDlgKeyPasswordMsgBox::OnInitDialog()
+
+bool CDlgKeyPasswordMsgBox::OnInitDialog()
{
inkeyid = UniGetContactSettingUtf(hContact, MODULENAME, "InKeyID", "");
SetWindowPos(m_hwnd, nullptr, globals.key_password_rect.left, globals.key_password_rect.top, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
- {
- string questionstr = "Please enter password for key with ID: ";
- questionstr += inkeyid;
- mir_free(inkeyid);
- lbl_KEYID.SetTextA(questionstr.c_str());
- chk_DEFAULT_PASSWORD.Disable();
- }
+
+ string questionstr = "Please enter password for key with ID: ";
+ questionstr += inkeyid;
+ mir_free(inkeyid);
+ lbl_KEYID.SetTextA(questionstr.c_str());
+ chk_DEFAULT_PASSWORD.Disable();
+ return true;
}
+
void CDlgKeyPasswordMsgBox::OnDestroy()
{
mir_free(inkeyid);
@@ -1392,6 +1441,7 @@ void CDlgKeyPasswordMsgBox::OnDestroy()
db_set_dw(NULL, MODULENAME, "PasswordWindowX", globals.key_password_rect.left);
db_set_dw(NULL, MODULENAME, "PasswordWindowY", globals.key_password_rect.top);
}
+
void CDlgKeyPasswordMsgBox::onClick_OK(CCtrlButton*)
{
wchar_t *tmp = mir_wstrdup(edit_KEY_PASSWORD.GetText());
@@ -1415,9 +1465,9 @@ void CDlgKeyPasswordMsgBox::onClick_OK(CCtrlButton*)
mir_free(inkeyid);
DestroyWindow(m_hwnd);
}
+
void CDlgKeyPasswordMsgBox::onClick_CANCEL(CCtrlButton*)
{
globals._terminate = true;
DestroyWindow(m_hwnd);
}
-