COM-121
Volker Birk 2020-07-02 20:20:56 +02:00
parent b3a9ee13be
commit 109c68b61f
6 changed files with 145 additions and 7 deletions

98
CMainWindow.cpp Normal file
View File

@ -0,0 +1,98 @@
#include "stdafx.h"
#include "CMainWindow.h"
static const GUID nidGUID =
{ 0xa4dbdbe1, 0x4051, 0x4d89, { 0xb1, 0x17, 0x62, 0x82, 0x18, 0x5a, 0x61, 0x5c } };
LRESULT CMainWindow::OnCreate(UINT, WPARAM, LPARAM, BOOL&)
{
// remove leftoff before creating a new one
BOOL _b;
OnDestroy(0, 0, 0, _b);
NOTIFYICONDATA nid = {};
nid.cbSize = sizeof(nid);
nid.uFlags = NIF_ICON | NIF_TIP | NIF_GUID | NIF_MESSAGE;
nid.hWnd = m_hWnd;
nid.guidItem = nidGUID;
StringCchCopy(nid.szTip, ARRAYSIZE(nid.szTip), _T("p≡p Updates"));
nid.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_LOGO));
nid.uCallbackMessage = WM_PEP_NOTIFICATION;
Shell_NotifyIcon(NIM_ADD, &nid);
nid = {};
nid.cbSize = sizeof(nid);
nid.uVersion = NOTIFYICON_VERSION_4;
Shell_NotifyIcon(NIM_SETVERSION, &nid);
return S_OK;
}
LRESULT CMainWindow::OnDestroy(UINT, WPARAM, LPARAM, BOOL&)
{
NOTIFYICONDATA nid = {};
nid.cbSize = sizeof(nid);
nid.uFlags = NIF_ICON | NIF_GUID;
nid.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_LOGO));
nid.guidItem = nidGUID;
Shell_NotifyIcon(NIM_DELETE, &nid);
return S_OK;
}
HMENU _menuContext = NULL;
LRESULT CMainWindow::OnNotification(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
auto event = LOWORD(lParam);
auto icon_id = HIWORD(lParam);
auto x = GET_X_LPARAM(wParam);
auto y = GET_Y_LPARAM(wParam);
HMENU menuContext;
MENUINFO info;
switch (event) {
case WM_CONTEXTMENU:
case WM_RBUTTONDOWN:
menuContext = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_POPUPMENU));
info = {};
info.cbSize = sizeof(info);
info.fMask = MIM_APPLYTOSUBMENUS | MIM_STYLE;
info.dwStyle = MNS_AUTODISMISS | MNS_NOTIFYBYPOS;
SetMenuInfo(menuContext, &info);
_menuContext = GetSubMenu(menuContext, 0);
SetForegroundWindow(m_hWnd); // this is utter nonsense, but required by TrackPopupMenuEx
POINT point;
GetCursorPos(&point);
TrackPopupMenuEx(_menuContext, TPM_LEFTALIGN | TPM_BOTTOMALIGN, point.x, point.y, m_hWnd, NULL);
PostMessage(WM_NULL, 0, 0); // this is utter nonsense, but required by TrackPopupMenuEx
DestroyMenu(menuContext);
bHandled = true;
break;
default:
bHandled = false;
}
return S_OK;
}
static const auto UPDATE_NOW = 1;
LRESULT CMainWindow::OnMenuCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
auto index = wParam;
HMENU hMenu = (HMENU)lParam;
switch (index) {
case UPDATE_NOW:
::MessageBox(NULL, _T("update now"), _T("update now"), MB_ICONINFORMATION);
bHandled = true;
break;
default:
bHandled = false;
}
return S_OK;
}

29
CMainWindow.h Normal file
View File

@ -0,0 +1,29 @@
#pragma once
#include "stdafx.h"
using namespace ATL;
#define WM_PEP_NOTIFICATION WM_USER + 23
class CMainWindow :
public CWindowImpl<CMainWindow>
{
bool _schedule_updates;
public:
CMainWindow() :
_schedule_updates(true), CWindowImpl<CMainWindow>() { }
DECLARE_WND_CLASS(_T("pEpCOMServerAdapterMainWndClass"))
BEGIN_MSG_MAP(CMainWindow)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
MESSAGE_HANDLER(WM_PEP_NOTIFICATION, OnNotification)
MESSAGE_HANDLER(WM_MENUCOMMAND, OnMenuCommand)
END_MSG_MAP()
LRESULT OnCreate(UINT /*nMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnDestroy(UINT /*nMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnNotification(UINT /*nMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnMenuCommand(UINT /*nMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
};

View File

@ -429,7 +429,7 @@ STDMETHODIMP CpEpEngine::GetMessageTrustwords(
char* _words = NULL;
if (result == S_OK) {
auto status = ::get_message_trustwords(
auto status = cache.api(::get_message_trustwords,
session(),
_msg,
_keylist,
@ -857,7 +857,7 @@ STDMETHODIMP CpEpEngine::KeyResetIdentity(struct pEpIdentity ident, BSTR fpr)
string _fpr = utf8_string(fpr);
PEP_STATUS status = ::key_reset_identity(session(), _ident, _fpr.c_str());
PEP_STATUS status = cache.api(::key_reset_identity, session(), _ident, _fpr.c_str());
free_identity(_ident);
@ -878,7 +878,7 @@ STDMETHODIMP CpEpEngine::KeyResetUser(BSTR userId, BSTR fpr)
string _userId = utf8_string(userId);
string _fpr = utf8_string(fpr);
PEP_STATUS status = ::key_reset_user(session(), _userId.c_str(), _fpr.c_str());
PEP_STATUS status = cache.api(::key_reset_user, session(), _userId.c_str(), _fpr.c_str());
if (status == PEP_OUT_OF_MEMORY)
return E_OUTOFMEMORY;
@ -894,7 +894,7 @@ STDMETHODIMP CpEpEngine::KeyResetUser(BSTR userId, BSTR fpr)
STDMETHODIMP CpEpEngine::KeyResetAllOwnKeys()
{
PEP_STATUS status = ::key_reset_all_own_keys(session());
PEP_STATUS status = cache.api(::key_reset_all_own_keys, session());
if (status == PEP_OUT_OF_MEMORY)
return E_OUTOFMEMORY;
@ -924,7 +924,7 @@ STDMETHODIMP CpEpEngine::KeyResetTrust(struct pEpIdentity *ident)
return FAIL(ex.what());;
}
PEP_STATUS status = ::key_reset_trust(session(), _ident);
PEP_STATUS status = cache.api(::key_reset_trust, session(), _ident);
free_identity(_ident);
if (status == PEP_OUT_OF_MEMORY)
@ -1973,7 +1973,7 @@ STDMETHODIMP CpEpEngine::DisableIdentityForSync(struct pEpIdentity * ident)
if (_ident == NULL)
return E_OUTOFMEMORY;
PEP_STATUS status = ::disable_identity_for_sync(session(), _ident);
PEP_STATUS status = cache.api(::disable_identity_for_sync, session(), _ident);
::free_identity(_ident);
@ -2100,7 +2100,7 @@ STDMETHODIMP CpEpEngine::ConfigPassphraseForNewKeys(VARIANT_BOOL enable, BSTR pa
_passphrase = utf8_string(passphrase);
passphrase_for_new_keys = _passphrase;
PEP_STATUS status = ::config_passphrase_for_new_keys(session(), enable, cache.add(_passphrase));
PEP_STATUS status = ::config_passphrase_for_new_keys(session(), enable, cache.add_stored(_passphrase));
if (status == PEP_STATUS_OK)
return S_OK;

BIN
logo.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

View File

@ -46,6 +46,9 @@
<ClCompile Include="LocalJSONAdapter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="CMainWindow.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
@ -84,6 +87,9 @@
<ClInclude Include="..\pEpJSONServerAdapter\server\adapter-library.hh">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="CMainWindow.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="pEpCOMServerAdapter.rc">
@ -112,4 +118,9 @@
<Filter>Source Files</Filter>
</Midl>
</ItemGroup>
<ItemGroup>
<Image Include="logo.ico">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
</Project>