From 013b278a482a1e1821715a1e2c6c7da5e7f94434 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sun, 15 Aug 2010 23:00:56 +0300 Subject: modified: main.cpp modified: new_gpg.rc modified: options.cpp modified: resource.h --- main.cpp | 194 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 193 insertions(+), 1 deletion(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 9921b65..8db3d14 100644 --- a/main.cpp +++ b/main.cpp @@ -30,7 +30,7 @@ void test() } -HWND hwndFirstRun = NULL, hwndSetDirs = NULL, hwndNewKey = NULL, hwndKeyGen = NULL; +HWND hwndFirstRun = NULL, hwndSetDirs = NULL, hwndNewKey = NULL, hwndKeyGen = NULL, hwndSelectExistingKey = NULL; int itemnum = 0; @@ -598,6 +598,188 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam, return FALSE; } +int itemnum2 = 0; + +static BOOL CALLBACK DlgProcLoadExistingKey(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) +{ + HWND hwndList=GetDlgItem(hwndDlg, IDC_EXISTING_KEY_LIST); + hwndList_g = hwndList; + LVCOLUMN col = {0}; + LVITEM item = {0}; + NMLISTVIEW * hdr = (NMLISTVIEW *) lParam; + TCHAR id[16] = {0}; + switch (msg) + { + case WM_INITDIALOG: + { + TranslateDialogDefault(hwndDlg); + col.pszText = _T("Key ID"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 50; + ListView_InsertColumn(hwndList, 0, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = _T("Email"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 30; + ListView_InsertColumn(hwndList, 1, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = _T("Name"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 250; + ListView_InsertColumn(hwndList, 2, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = _T("Creation date"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 30; + ListView_InsertColumn(hwndList, 3, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = _T("Key length"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 30; + ListView_InsertColumn(hwndList, 4, &col); + ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_FULLROWSELECT); + int i = 1, iRow = 0; + { + item.mask = LVIF_TEXT; + item.iItem = i; + item.iSubItem = 0; + item.pszText = _T(""); + {//parse gpg output + string out; + DWORD code; + string::size_type p = 0, p2 = 0, stop = 0; + { + wstring cmd = _T("--list-secret-keys"); + if(pxExecute(&cmd, "", &out, &code) == pxNotFound) + { + MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); + break; + } + } + cp866_to_cp1251(&out); + while(p != string::npos) + { + if((p = out.find("sec ", p)) == string::npos) + break; + p += 5; + if(p < stop) + break; + stop = p; + p2 = out.find("/", p) - 1; + TCHAR *tmp = mir_a2t(out.substr(p,p2-p).c_str()); + item.pszText = tmp; + iRow = ListView_InsertItem(hwndList, &item); + ListView_SetItemText(hwndList, iRow, 4, tmp); + mir_free(tmp); + p2+=2; + p = out.find(" ", p2); + tmp = mir_a2t(out.substr(p2,p-p2).c_str()); + ListView_SetItemText(hwndList, iRow, 0, tmp); + mir_free(tmp); + p = out.find("uid ", p); + p2 = out.find_first_not_of(" ", p+5); + p = out.find("<", p2); + tmp = mir_a2t(out.substr(p2,p-p2).c_str()); + ListView_SetItemText(hwndList, iRow, 2, tmp); + mir_free(tmp); + p++; + p2 = out.find(">", p); + tmp = mir_a2t(out.substr(p,p2-p).c_str()); + ListView_SetItemText(hwndList, iRow, 1, tmp); + mir_free(tmp); + p = out.find("ssb ", p2) + 6; + p = out.find(" ", p) + 1; + p2 = out.find("\n", p); + tmp = mir_a2t(out.substr(p,p2-p-1).c_str()); + ListView_SetItemText(hwndList, iRow, 3, tmp); + mir_free(tmp); + i++; + } + } + ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE);// not sure about this + ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 2, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 3, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 4, LVSCW_AUTOSIZE); + } + return TRUE; + } + + + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case IDOK: + { + ListView_GetItemText(hwndList, itemnum2, 0, id, 16); + extern HWND hPubKeyEdit; + string out; + DWORD code; + wstring cmd = _T("--export -a "); + cmd += id; + if(pxExecute(&cmd, "", &out, &code) == pxNotFound) + { + MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); + break; + } + string::size_type s = 0; + while((s = out.find("\r", s)) != string::npos) + { + out.erase(s, 1); + } + TCHAR *tmp = mir_a2t(out.c_str()); +// SetDlgItemText(hPubKeyEdit, IDC_PUBLIC_KEY_EDIT, tmp); + SetWindowText(hPubKeyEdit, tmp); + mir_free(tmp); + } + DestroyWindow(hwndDlg); + break; + case IDCANCEL: + DestroyWindow(hwndDlg); + break; + } + break; + } + + case WM_NOTIFY: + { + if(hdr && IsWindowVisible(hdr->hdr.hwndFrom) && hdr->iItem != (-1)) + { + if(hdr->hdr.code == LVN_ITEMCHANGED) + { + EnableWindow(GetDlgItem(hwndDlg, IDOK), 1); + itemnum2 = hdr->iItem; + } + } + + switch (((LPNMHDR)lParam)->code) + { + + case PSN_APPLY: + { + return TRUE; + } + } + } + break; + case WM_CLOSE: + DestroyWindow(hwndDlg); + break; + case WM_DESTROY: + hwndSelectExistingKey = NULL; + break; + + } + + return FALSE; +} + extern HINSTANCE hInst; @@ -636,6 +818,16 @@ void ShowKeyGenDialog() SetForegroundWindow(hwndKeyGen); } +void ShowSelectExistingKeyDialog() +{ + if (hwndSelectExistingKey == NULL) + { + hwndSelectExistingKey = CreateDialog(hInst, MAKEINTRESOURCE(IDD_LOAD_EXISTING_KEY), NULL, DlgProcLoadExistingKey); + } + SetForegroundWindow(hwndSelectExistingKey); +} + + -- cgit v1.2.3