summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.cpp80
-rw-r--r--options.cpp41
-rw-r--r--utilities.cpp20
-rw-r--r--utilities.h2
4 files changed, 93 insertions, 50 deletions
diff --git a/main.cpp b/main.cpp
index 783ba52..180bbae 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,43 +1,43 @@
-// Copyright © 2010 sss
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-
-
-
-#include "commonheaders.h"
-
-int gpg_init()
-{
- setlocale (LC_ALL, "");
- gpgme_check_version (NULL);
+// Copyright © 2010 sss
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+
+
+#include "commonheaders.h"
+
+int gpg_init()
+{
+/* setlocale (LC_ALL, "");
+ gpgme_check_version (NULL);
gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
#ifdef LC_MESSAGES
gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
-#endif
- gpgme_error_t err;
- gpgme_ctx_t ctx;
- err = gpgme_new(&ctx);
- TCHAR error[128];
- mir_sntprintf(error, 128, _T("%d"), error);
-// MessageBox(0, error, _T("info"), MB_OK);
-/* gpgme_protocol_t proto = GPGME_PROTOCOL_OpenPGP;
- char *tmp = mir_t2a(UniGetContactSettingUtf(NULL, szModuleName, "szGpgBinPath", _T("")));
- char *tmp2 = mir_t2a(UniGetContactSettingUtf(NULL, szModuleName, "szHomePath", _T("")));
- gpgme_ctx_set_engine_info(ctx, proto, tmp, tmp2);
- mir_free(tmp);
- mir_free(tmp2); */
- return 0;
-}
+#endif
+ gpgme_error_t err;
+ gpgme_ctx_t ctx;
+ err = gpgme_new(&ctx);
+ TCHAR error[128];
+ mir_sntprintf(error, 128, _T("%d"), error);
+ MessageBox(0, error, _T("info"), MB_OK);
+ gpgme_protocol_t proto = GPGME_PROTOCOL_OpenPGP;
+ char *tmp = mir_t2a(UniGetContactSettingUtf(NULL, szModuleName, "szGpgBinPath", _T("")));
+ char *tmp2 = mir_t2a(UniGetContactSettingUtf(NULL, szModuleName, "szHomePath", _T("")));
+ gpgme_ctx_set_engine_info(ctx, proto, tmp, tmp2);
+ mir_free(tmp);
+ mir_free(tmp2); */
+ return 0;
+}
diff --git a/options.cpp b/options.cpp
index 772d2d4..60cf2d9 100644
--- a/options.cpp
+++ b/options.cpp
@@ -64,6 +64,7 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
hwndList_p = hwndList;
LVCOLUMN col;
LVITEM item;
+ TCHAR *tmp;
NMLISTVIEW * hdr = (NMLISTVIEW *) lParam;
switch (msg)
{
@@ -123,14 +124,29 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
case IDC_LOAD_KEY_BUTTON:
ShowLoadPublicKeyDialog();
return TRUE;
- case IDC_SAVE_KEY_BUTTON:
- break;
case IDC_DELETE_KEY_BUTTON:
DBDeleteContactSetting(user_data[item_num+1], szModuleName, "GPGPubKey");
ListView_SetItemText(hwndList, item_num, 2, _T("not set"));
break;
default:
break;
+ case IDC_SAVE_KEY_BUTTON:
+ tmp = GetFilePath(_T("Export public key"), _T("*"), _T(".asc pubkey file"), true);
+ if(!tmp)
+ {
+ break;
+ }
+ wfstream f(tmp, std::ios::out);
+ delete [] tmp;
+ wstring str = UniGetContactSettingUtf(user_data[item_num+1], szModuleName, "GPGPubKey", _T(""));
+ wstring::size_type s = 0;
+ while((s = str.find(_T("\r"), s)) != wstring::npos)
+ {
+ str.erase(s, 1);
+ }
+ f<<str.c_str();
+ f.close();
+ break;
}
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
@@ -169,6 +185,7 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
+ TCHAR *tmp = NULL;
switch (msg)
{
case WM_INITDIALOG:
@@ -236,8 +253,7 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP
TranslateDialogDefault(hwndDlg);
tmp = UniGetContactSettingUtf(hContact, szModuleName, "GPGPubKey", _T(""));
SetDlgItemText(hwndDlg, IDC_PUBLIC_KEY_EDIT, (_tcslen(tmp) > 1)?tmp:_T(""));
- mir_free(tmp);
- return TRUE;
+ return TRUE;
}
@@ -249,7 +265,13 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP
tmp = new TCHAR [40960];
GetDlgItemText(hwndDlg, IDC_PUBLIC_KEY_EDIT, tmp, 40960);
key_buf.append(tmp);
+ key_buf.append(_T("\n")); //no new line at end of file )
delete [] tmp;
+ while((ws1 = key_buf.find(_T("\r"), ws1)) != wstring::npos)
+ {
+ key_buf.erase(ws1, 1); //remove windows specific trash
+ }
+ ws1 = 0;
if(((ws2 = key_buf.find(_T("-----END PGP PUBLIC KEY BLOCK-----"))) == wstring::npos) || ((ws1 = key_buf.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----"))) == wstring::npos))
{
MessageBox(0, _T("This is not public key"), _T("INFO"), MB_OK);
@@ -257,12 +279,19 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP
}
ws2 += _tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----"));
DBWriteContactSettingTString(hContact, szModuleName, "GPGPubKey", key_buf.substr(ws1,ws2-ws1).c_str());
- ListView_SetItemText(hwndList_p, item_num, 2, (TCHAR*)key_buf.substr(ws1,ws2-ws1).c_str());
+ tmp = new TCHAR [key_buf.length()+1];
+ _tcscpy(tmp, key_buf.substr(ws1,ws2-ws1).c_str());
+ ListView_SetItemText(hwndList_p, item_num, 2, tmp);
+ delete [] tmp;
key_buf.clear();
DestroyWindow(hwndDlg);
break;
case ID_LOAD_FROM_FILE:
tmp = GetFilePath(_T("Set file containing GPG public key"), _T("*"), _T("GPG public key file"));
+ if(!tmp)
+ {
+ break;
+ }
wfstream f(tmp, std::ios::in);
delete [] tmp;
if(!f.is_open())
@@ -275,7 +304,7 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP
tmp = new TCHAR [1024];
f.getline(tmp, 1024, '\n');
key_buf.append(tmp);
- key_buf.append(_T("\r\n"));
+ key_buf.append(_T("\n"));
delete [] tmp;
}
f.close();
diff --git a/utilities.cpp b/utilities.cpp
index 16ed0c2..44121cd 100644
--- a/utilities.cpp
+++ b/utilities.cpp
@@ -102,7 +102,7 @@ void GetFilePath(TCHAR *WindowTittle, char *szSetting, TCHAR *szExt, TCHAR *szEx
DBWriteContactSettingTString(0, szModuleName, szSetting, str);
}
-TCHAR *GetFilePath(TCHAR *WindowTittle, TCHAR *szExt, TCHAR *szExtDesc)
+TCHAR *GetFilePath(TCHAR *WindowTittle, TCHAR *szExt, TCHAR *szExtDesc, bool save_file)
{
TCHAR *str = new TCHAR [MAX_PATH+2];
OPENFILENAME ofn={0};
@@ -122,8 +122,22 @@ TCHAR *GetFilePath(TCHAR *WindowTittle, TCHAR *szExt, TCHAR *szExtDesc)
ofn.lpstrFile=str;
ofn.nMaxFile=_MAX_PATH;
ofn.nMaxFileTitle=MAX_PATH;
- if(!GetOpenFileName(&ofn))
- return _T("");
+ if(!save_file)
+ {
+ if(!GetOpenFileName(&ofn))
+ {
+ delete [] str;
+ return NULL;
+ }
+ }
+ else
+ {
+ if(!GetSaveFileName(&ofn))
+ {
+ delete [] str;
+ return NULL;
+ }
+ }
return str;
}
diff --git a/utilities.h b/utilities.h
index 8ec36db..f8d4602 100644
--- a/utilities.h
+++ b/utilities.h
@@ -18,7 +18,7 @@
#define UTILITIES_H
TCHAR* __stdcall UniGetContactSettingUtf(HANDLE hContact, const char *szModule,const char* szSetting, TCHAR* szDef);
void GetFilePath(TCHAR *WindowTittle, char *szSetting, TCHAR *szExt, TCHAR *szExtDesc);
-TCHAR *GetFilePath(TCHAR *WindowTittle, TCHAR *szExt, TCHAR *szExtDesc);
+TCHAR *GetFilePath(TCHAR *WindowTittle, TCHAR *szExt, TCHAR *szExtDesc, bool save_file = false);
void GetFolderPath(TCHAR *WindowTittle, char *szSetting);
#endif