summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikalaiR <nikolay.romanovich@narod.ru>2016-02-27 15:28:11 +0000
committerMikalaiR <nikolay.romanovich@narod.ru>2016-02-27 15:28:11 +0000
commit2814cd2a0f6ed89dab0c4dca6b8dbb2c7523bef9 (patch)
tree07be53471abaafa30b04d0973882695739053488
parentb5516cbe14bd01912dc2917be0f9f892bdbd74c4 (diff)
dbx_lmdb: gui rewritted to ui_utils
git-svn-id: http://svn.miranda-ng.org/main/trunk@16362 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--plugins/Dbx_mdb/src/dbcrypt.cpp75
-rw-r--r--plugins/Dbx_mdb/src/dbintf.h7
-rw-r--r--plugins/Dbx_mdb/src/ui.cpp122
-rw-r--r--plugins/Dbx_mdb/src/ui.h133
4 files changed, 175 insertions, 162 deletions
diff --git a/plugins/Dbx_mdb/src/dbcrypt.cpp b/plugins/Dbx_mdb/src/dbcrypt.cpp
index 1a4fe39276..31d7f69dda 100644
--- a/plugins/Dbx_mdb/src/dbcrypt.cpp
+++ b/plugins/Dbx_mdb/src/dbcrypt.cpp
@@ -45,10 +45,14 @@ CRYPTO_PROVIDER* CDbxMdb::SelectProvider()
}
else pProv = ppProvs[0];
- txn_ptr txn(m_pMdbEnv);
- MDB_val key = { sizeof(DBKEY_PROVIDER), DBKEY_PROVIDER }, value = { mir_strlen(pProv->pszName) + 1, pProv->pszName };
- mdb_put(txn, m_dbCrypto, &key, &value, 0);
- txn.commit();
+ for (;; Remap())
+ {
+ txn_ptr txn(m_pMdbEnv);
+ MDB_val key = { sizeof(DBKEY_PROVIDER), DBKEY_PROVIDER }, value = { mir_strlen(pProv->pszName) + 1, pProv->pszName };
+ mdb_put(txn, m_dbCrypto, &key, &value, 0);
+ if (txn.commit())
+ break;
+ }
return pProv;
}
@@ -102,7 +106,7 @@ int CDbxMdb::InitCrypt()
key.mv_size = sizeof(DBKEY_IS_ENCRYPTED); key.mv_data = DBKEY_IS_ENCRYPTED;
if (mdb_get(txn, m_dbCrypto, &key, &value) == MDB_SUCCESS)
- m_bEncrypted = *(const BYTE*)value.mv_data != 0;
+ m_bEncrypted = *(const bool*)value.mv_data;
else
m_bEncrypted = false;
@@ -116,11 +120,14 @@ void CDbxMdb::StoreKey()
BYTE *pKey = (BYTE*)_alloca(iKeyLength);
m_crypto->getKey(pKey, iKeyLength);
- txn_ptr txn(m_pMdbEnv);
- MDB_val key = { sizeof(DBKEY_KEY), DBKEY_KEY }, value = { iKeyLength, pKey };
- mdb_put(txn, m_dbCrypto, &key, &value, 0);
- txn.commit();
-
+ for (;; Remap())
+ {
+ txn_ptr txn(m_pMdbEnv);
+ MDB_val key = { sizeof(DBKEY_KEY), DBKEY_KEY }, value = { iKeyLength, pKey };
+ mdb_put(txn, m_dbCrypto, &key, &value, 0);
+ if (txn.commit())
+ break;
+ }
SecureZeroMemory(pKey, iKeyLength);
}
@@ -139,39 +146,31 @@ void CDbxMdb::SetPassword(LPCTSTR ptszPassword)
/////////////////////////////////////////////////////////////////////////////////////////
-void CDbxMdb::ToggleEncryption()
+int CDbxMdb::EnableEncryption(bool bEncrypted)
{
- HANDLE hSave1 = hSettingChangeEvent; hSettingChangeEvent = NULL;
- HANDLE hSave2 = hEventAddedEvent; hEventAddedEvent = NULL;
- HANDLE hSave3 = hEventDeletedEvent; hEventDeletedEvent = NULL;
- HANDLE hSave4 = hEventFilterAddedEvent; hEventFilterAddedEvent = NULL;
+ if (m_bEncrypted == bEncrypted)
+ return 0;
mir_cslock lck(m_csDbAccess);
- ToggleSettingsEncryption(NULL);
- ToggleEventsEncryption(NULL);
-
- for (MCONTACT contactID = FindFirstContact(); contactID; contactID = FindNextContact(contactID)) {
- ToggleSettingsEncryption(contactID);
- ToggleEventsEncryption(contactID);
+ for (MCONTACT contactID = FindFirstContact(); contactID; contactID = FindNextContact(contactID))
+ {
+ EnableContactEncryption(contactID, bEncrypted);
}
- m_bEncrypted = !m_bEncrypted;
-
- txn_ptr txn(m_pMdbEnv);
- MDB_val key = { sizeof(DBKEY_IS_ENCRYPTED), DBKEY_IS_ENCRYPTED }, value = { sizeof(BYTE), &m_bEncrypted };
- mdb_put(txn, m_dbCrypto, &key, &value, 0);
- txn.commit();
-
- hSettingChangeEvent = hSave1;
- hEventAddedEvent = hSave2;
- hEventDeletedEvent = hSave3;
- hEventFilterAddedEvent = hSave4;
-}
-
-void CDbxMdb::ToggleSettingsEncryption(MCONTACT /*contactID*/)
-{
+ for (;; Remap())
+ {
+ txn_ptr txn(m_pMdbEnv);
+ MDB_val key = { sizeof(DBKEY_IS_ENCRYPTED), DBKEY_IS_ENCRYPTED }, value = { sizeof(bool), &bEncrypted };
+ MDB_CHECK(mdb_put(txn, m_dbCrypto, &key, &value, 0), 1);
+ if (txn.commit())
+ break;
+ }
+ m_bEncrypted = bEncrypted;
+ return 0;
}
-void CDbxMdb::ToggleEventsEncryption(MCONTACT /*contactID*/)
+int CDbxMdb::EnableContactEncryption(MCONTACT hContact, bool bEncrypted)
{
-}
+ //TODO: encrypt/decrypt all contact events and settings
+ return 0;
+} \ No newline at end of file
diff --git a/plugins/Dbx_mdb/src/dbintf.h b/plugins/Dbx_mdb/src/dbintf.h
index 2514431260..2c05fb6f46 100644
--- a/plugins/Dbx_mdb/src/dbintf.h
+++ b/plugins/Dbx_mdb/src/dbintf.h
@@ -147,7 +147,6 @@ struct CDbxMdb : public MIDatabase, public MIDatabaseChecker, public MZeroedObje
void DatabaseCorruption(const TCHAR *ptszText);
- void ToggleEncryption(void);
void StoreKey(void);
void SetPassword(const TCHAR *ptszPassword);
void UpdateMenuItem(void);
@@ -158,7 +157,7 @@ struct CDbxMdb : public MIDatabase, public MIDatabaseChecker, public MZeroedObje
__forceinline bool isEncrypted() const { return m_bEncrypted; }
__forceinline bool usesPassword() const { return m_bUsesPassword; }
-
+ int EnableEncryption(bool bEnable);
public:
STDMETHODIMP_(BOOL) IsRelational(void) { return TRUE; }
STDMETHODIMP_(void) SetCacheSafetyMode(BOOL);
@@ -324,11 +323,9 @@ protected:
MDB_dbi m_dbCrypto;
-
int InitCrypt(void);
- void ToggleEventsEncryption(MCONTACT contactID);
- void ToggleSettingsEncryption(MCONTACT contactID);
+ int EnableContactEncryption(MCONTACT, bool bEnable);
CRYPTO_PROVIDER* SelectProvider();
void GenerateNewKey();
diff --git a/plugins/Dbx_mdb/src/ui.cpp b/plugins/Dbx_mdb/src/ui.cpp
index 353a2d01a9..67fc6a5610 100644
--- a/plugins/Dbx_mdb/src/ui.cpp
+++ b/plugins/Dbx_mdb/src/ui.cpp
@@ -23,21 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
-struct DlgChangePassParam
-{
- CDbxMdb *db;
- TCHAR newPass[100];
- unsigned short wrongPass;
-};
-
-#define MS_DB_CHANGEPASSWORD "DB/UI/ChangePassword"
-
-static IconItem iconList[] =
-{
- { LPGEN("Logo"), "logo", IDI_LOGO },
- { LPGEN("Password"), "password", IDI_ICONPASS }
-};
-
static HGENMENU hSetPwdMenu;
static UINT oldLangID;
@@ -56,74 +41,13 @@ void LanguageChanged(HWND hwndDlg)
/////////////////////////////////////////////////////////////////////////////////////////
-static INT_PTR CALLBACK sttEnterPassword(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- DlgChangePassParam *param = (DlgChangePassParam*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
-
- switch (uMsg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
- SendDlgItemMessage(hwndDlg, IDC_HEADERBAR, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(g_hInst, MAKEINTRESOURCE(iconList[0].defIconID)));
-
- param = (DlgChangePassParam*)lParam;
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
-
- if (param->wrongPass) {
- if (param->wrongPass > 2) {
- HWND hwndCtrl = GetDlgItem(hwndDlg, IDC_USERPASS);
- EnableWindow(hwndCtrl, FALSE);
- hwndCtrl = GetDlgItem(hwndDlg, IDOK);
- EnableWindow(hwndCtrl, FALSE);
- SetDlgItemText(hwndDlg, IDC_HEADERBAR, TranslateT("Too many errors!"));
- }
- else SetDlgItemText(hwndDlg, IDC_HEADERBAR, TranslateT("Password is not correct!"));
- }
- else SetDlgItemText(hwndDlg, IDC_HEADERBAR, TranslateT("Please type in your password"));
-
- oldLangID = 0;
- SetTimer(hwndDlg, 1, 200, NULL);
- LanguageChanged(hwndDlg);
- return TRUE;
-
- case WM_CTLCOLORSTATIC:
- if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_LANG)) {
- SetTextColor((HDC)wParam, GetSysColor(COLOR_HIGHLIGHTTEXT));
- SetBkMode((HDC)wParam, TRANSPARENT);
- return (BOOL)GetSysColorBrush(COLOR_HIGHLIGHT);
- }
- return FALSE;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDCANCEL:
- EndDialog(hwndDlg, IDCANCEL);
- break;
-
- case IDOK:
- GetDlgItemText(hwndDlg, IDC_USERPASS, param->newPass, _countof(param->newPass));
- EndDialog(hwndDlg, IDOK);
- }
- break;
-
- case WM_TIMER:
- LanguageChanged(hwndDlg);
- return FALSE;
-
- case WM_DESTROY:
- KillTimer(hwndDlg, 1);
- DestroyIcon((HICON)SendMessage(hwndDlg, WM_GETICON, ICON_SMALL, 0));
- }
-
- return FALSE;
-}
-
bool CDbxMdb::EnterPassword(const BYTE *pKey, const size_t keyLen)
{
DlgChangePassParam param = { this };
+ CEnterPasswordDialog dlg(&param);
while (true)
{
- // Esc pressed
- if (IDOK != DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_LOGIN), 0, sttEnterPassword, (LPARAM)&param))
+ if (-128 != dlg.DoModal())
return false;
m_crypto->setPassword(pass_ptrA(mir_utf8encodeT(param.newPass)));
@@ -250,52 +174,14 @@ static INT_PTR ChangePassword(void* obj, WPARAM, LPARAM)
/////////////////////////////////////////////////////////////////////////////////////////
-INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- CDbxMdb *db = (CDbxMdb *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
-
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
-
- db = (CDbxMdb*)lParam;
- CheckRadioButton(hwndDlg, IDC_STANDARD, IDC_TOTAL, IDC_STANDARD + db->isEncrypted());
- return TRUE;
-
- case WM_COMMAND:
- if (HIWORD(wParam) == BN_CLICKED && (HWND)lParam == GetFocus()) {
- if (LOWORD(wParam) == IDC_USERPASS)
- CallService(MS_DB_CHANGEPASSWORD, 0, 0);
- else
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- }
- break;
-
- case WM_NOTIFY:
- if (((LPNMHDR)lParam)->code == PSN_APPLY) {
- if (IsDlgButtonChecked(hwndDlg, IDC_TOTAL) != (UINT)db->isEncrypted()) {
- db->ToggleEncryption();
- CheckRadioButton(hwndDlg, IDC_STANDARD, IDC_TOTAL, IDC_STANDARD + db->isEncrypted());
- }
- break;
- }
- break;
- }
-
- return FALSE;
-}
static int OnOptionsInit(PVOID obj, WPARAM wParam, LPARAM)
{
OPTIONSDIALOGPAGE odp = { sizeof(odp) };
odp.position = -790000000;
- odp.hInstance = g_hInst;
- odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS);
odp.flags = ODPF_BOLDGROUPS;
odp.pszTitle = LPGEN("Database");
- odp.pfnDlgProc = DlgProcOptions;
- odp.dwInitParam = (LPARAM)obj;
+ odp.pDialog = new COptionsDialog((CDbxMdb*)obj);
Options_AddPage(wParam, &odp);
return 0;
}
@@ -311,7 +197,7 @@ static int OnModulesLoaded(PVOID obj, WPARAM, LPARAM)
{
CDbxMdb *db = (CDbxMdb*)obj;
- Icon_Register(g_hInst, LPGEN("Database"), iconList, _countof(iconList), "mmap");
+ Icon_Register(g_hInst, LPGEN("Database"), iconList, _countof(iconList), "lmdb");
HookEventObj(ME_OPT_INITIALISE, OnOptionsInit, db);
diff --git a/plugins/Dbx_mdb/src/ui.h b/plugins/Dbx_mdb/src/ui.h
index 007104377e..c29659b3d2 100644
--- a/plugins/Dbx_mdb/src/ui.h
+++ b/plugins/Dbx_mdb/src/ui.h
@@ -1,4 +1,48 @@
+static IconItem iconList[] =
+{
+ { LPGEN("Logo"), "logo", IDI_LOGO },
+ { LPGEN("Password"), "password", IDI_ICONPASS }
+};
+
+#define MS_DB_CHANGEPASSWORD "DB/UI/ChangePassword"
+
+class COptionsDialog : public CDlgBase
+{
+ CCtrlCheck m_chkStandart;
+ CCtrlCheck m_chkTotal;
+ CCtrlButton m_btnChangePass;
+ CDbxMdb *m_db;
+
+ void OnInitDialog()
+ {
+ m_chkStandart.SetState(!m_db->isEncrypted());
+ m_chkTotal.SetState(m_db->isEncrypted());
+ m_btnChangePass.SetTextA(Translate(m_db->GetMenuTitle()));
+ }
+
+ void OnApply()
+ {
+ m_db->EnableEncryption(m_chkTotal.GetState() != 0);
+ m_chkStandart.SetState(!m_db->isEncrypted());
+ m_chkTotal.SetState(m_db->isEncrypted());
+ }
+
+ void ChangePass(CCtrlButton*)
+ {
+ CallService(MS_DB_CHANGEPASSWORD, 0, 0);
+ }
+public:
+ COptionsDialog(CDbxMdb *db) :
+ CDlgBase(g_hInst, IDD_OPTIONS),
+ m_chkStandart(this, IDC_STANDARD),
+ m_chkTotal(this, IDC_TOTAL),
+ m_btnChangePass(this, IDC_USERPASS),
+ m_db(db)
+ {
+ m_btnChangePass.OnClick = Callback(this, &COptionsDialog::ChangePass);
+ }
+};
class CSelectCryptoDialog : public CDlgBase
{
@@ -45,4 +89,91 @@ public:
{
return m_selected;
}
-}; \ No newline at end of file
+};
+
+struct DlgChangePassParam
+{
+ CDbxMdb *db;
+ TCHAR newPass[100];
+ unsigned short wrongPass;
+};
+
+class CEnterPasswordDialog : public CDlgBase
+{
+ CCtrlData m_header;
+ CCtrlData m_language;
+ CCtrlEdit m_passwordEdit;
+ CCtrlButton m_buttonOK;
+
+ DlgChangePassParam *m_param;
+
+ INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
+ {
+ if (msg == WM_TIMER)
+ {
+ UINT LangID = (UINT)GetKeyboardLayout(0);
+ char Lang[3] = { 0 };
+ GetLocaleInfoA(MAKELCID((LangID & 0xffffffff), SORT_DEFAULT), LOCALE_SABBREVLANGNAME, Lang, 2);
+ Lang[0] = toupper(Lang[0]);
+ Lang[1] = tolower(Lang[1]);
+ m_language.SetTextA(Lang);
+ return FALSE;
+ }
+ else if (msg == WM_CTLCOLORSTATIC)
+ {
+ if ((HWND)lParam == m_language.GetHwnd()) {
+ SetTextColor((HDC)wParam, GetSysColor(COLOR_HIGHLIGHTTEXT));
+ SetBkMode((HDC)wParam, TRANSPARENT);
+ return (BOOL)GetSysColorBrush(COLOR_HIGHLIGHT);
+ }
+ }
+ return CDlgBase::DlgProc(msg, wParam, lParam);
+ }
+
+ void OnInitDialog()
+ {
+ m_header.SendMsg(WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(g_hInst, MAKEINTRESOURCE(iconList[0].defIconID)));
+ if (m_param->wrongPass)
+ {
+ if (m_param->wrongPass > 2)
+ {
+ m_passwordEdit.Disable();
+ m_buttonOK.Disable();
+ m_header.SetText(TranslateT("Too many errors!"));
+ }
+ else
+ {
+ m_header.SetText(TranslateT("Password is not correct!"));
+ }
+ }
+ else
+ {
+ m_header.SetText(TranslateT("Please type in your password"));
+ }
+ SetTimer(m_hwnd, 1, 200, NULL);
+ }
+
+ void OnOK(CCtrlButton*)
+ {
+ m_passwordEdit.GetText(m_param->newPass, _countof(m_param->newPass));
+ EndDialog(m_hwnd, -128);
+ }
+
+ void OnDestroy()
+ {
+ KillTimer(m_hwnd, 1);
+ }
+
+public:
+ CEnterPasswordDialog(DlgChangePassParam *param) :
+ CDlgBase(g_hInst, IDD_LOGIN),
+ m_header(this, IDC_HEADERBAR),
+ m_language(this, IDC_LANG),
+ m_passwordEdit(this, IDC_USERPASS),
+ m_buttonOK(this, IDOK),
+ m_param(param)
+ {
+ m_buttonOK.OnClick = Callback(this, &CEnterPasswordDialog::OnOK);
+ }
+
+};