Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[040794]: DboxTray.cpp Maximize Restore History

Download this file

DboxTray.cpp    249 lines (210 with data), 5.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/// file DboxTray.cpp
//
// Tray-related methods of DboxMain
//-----------------------------------------------------------------------------
#include "PasswordSafe.h"
#include "ThisMfcApp.h"
#if defined(POCKET_PC)
#include "pocketpc/resource.h"
#else
#include <errno.h>
#include "resource.h"
#endif
#include "DboxMain.h"
#include "RUEList.h"
#include "corelib/pwsprefs.h"
#include "corelib/pwscore.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////// New System Tray Commands /////////////////////
#ifndef POCKET_PC
void
DboxMain::OnTrayLockUnLock()
{
CString cMenuString;
CMyString passkey;
int rc;
if (!app.GetSystemTrayState() == UNLOCKED) { // User clicked UnLock
rc = GetAndCheckPassword(m_core.GetCurFile(), passkey, GCP_NORMAL); // OK, CANCEL, HELP
if (rc != PWScore::SUCCESS)
return;
rc = m_core.ReadCurFile(passkey);
if (rc == PWScore::SUCCESS) {
m_needsreading = false;
startLockCheckTimer();
UpdateSystemTray(UNLOCKED);
RefreshList();
return;
} else {
m_needsreading = true;
UpdateSystemTray(LOCKED);
app.ClearClipboardData();
ShowWindow(SW_MINIMIZE);
if (PWSprefs::GetInstance()->
GetPref(PWSprefs::UseSystemTray))
ShowWindow(SW_HIDE);
return;
}
} else { // User clicked Lock
UpdateSystemTray(LOCKED);
app.ClearClipboardData();
ShowWindow(SW_MINIMIZE);
ShowWindow(SW_HIDE);
}
}
void
DboxMain::OnUpdateTrayLockUnLockCommand(CCmdUI *pCmdUI)
{
const CString csUnLock = _T("Unlock Database");
const CString csLock = _T("Lock Database");
// Set text to "UnLock" or "Lock"
if (app.GetSystemTrayState() == ThisMfcApp::UNLOCKED)
pCmdUI->SetText(csLock);
else
pCmdUI->SetText(csUnLock);
// If dialog visible - obviously unlocked and no need to have option to lock
if (this->IsWindowVisible() == FALSE)
pCmdUI->Enable(TRUE);
else
pCmdUI->Enable(FALSE);
}
void
DboxMain::OnTrayClearRecentEntries()
{
m_RUEList.ClearEntries();
}
void
DboxMain::OnUpdateTrayClearRecentEntries(CCmdUI *pCmdUI)
{
if (pCmdUI->m_pSubMenu != NULL) {
// disable or enable entire popup for "Recent Entries"
// CCmdUI::Enable is a no-op for this case, so we
// must do what it would have done.
pCmdUI->m_pMenu->EnableMenuItem(pCmdUI->m_nIndex,
MF_BYPOSITION |
(app.GetSystemTrayState() == ThisMfcApp::UNLOCKED ? MF_ENABLED : MF_GRAYED));
return;
}
// otherwise enable
if (m_RUEList.GetCount() != 0)
pCmdUI->Enable(TRUE);
else
pCmdUI->Enable(FALSE);
}
void
DboxMain::OnTrayCopyUsername(UINT nID)
{
ASSERT((nID >= ID_MENUITEM_TRAYCOPYUSERNAME1) &&
(nID <= ID_MENUITEM_TRAYCOPYUSERNAMEMAX));
CItemData ci;
m_RUEList.GetPWEntry(nID - ID_MENUITEM_TRAYCOPYUSERNAME1, ci);
if (&ci == NULL) return;
const CMyString username = ci.GetUser();
if (!username.IsEmpty()) {
ToClipboard(username);
UpdateAccessTime(&ci);
}
}
void
DboxMain::OnUpdateTrayCopyUsername(CCmdUI *)
{
}
void
DboxMain::OnTrayCopyPassword(UINT nID)
{
ASSERT((nID >= ID_MENUITEM_TRAYCOPYPASSWORD1) && (nID <= ID_MENUITEM_TRAYCOPYPASSWORDMAX));
CItemData ci;
m_RUEList.GetPWEntry(nID - ID_MENUITEM_TRAYCOPYPASSWORD1, ci);
if (&ci == NULL) return;
const CMyString curPassString = ci.GetPassword();
ToClipboard(curPassString);
UpdateAccessTime(&ci);
}
void
DboxMain::OnUpdateTrayCopyPassword(CCmdUI *)
{
}
void
DboxMain::OnTrayCopyNotes(UINT nID)
{
ASSERT((nID >= ID_MENUITEM_TRAYCOPYNOTESFLD1) && (nID <= ID_MENUITEM_TRAYCOPYNOTESFLDMAX));
CItemData ci;
m_RUEList.GetPWEntry(nID - ID_MENUITEM_TRAYCOPYNOTESFLD1, ci);
if (&ci == NULL)
return;
const CMyString notes = ci.GetNotes();
const CMyString url = ci.GetURL();
const CMyString autotype = ci.GetAutoType();
CMyString clipboard_data;
clipboard_data = notes;
if (!url.IsEmpty()) {
clipboard_data += _T("\r\nURL: ");
clipboard_data += url;
}
if (!autotype.IsEmpty()) {
clipboard_data += _T("\r\nAutotype: ");
clipboard_data += autotype;
}
if (!clipboard_data.IsEmpty()) {
ToClipboard(clipboard_data);
UpdateAccessTime(&ci);
}
}
void
DboxMain::OnUpdateTrayCopyNotes(CCmdUI *)
{
}
void
DboxMain::OnTrayBrowse(UINT nID)
{
ASSERT((nID >= ID_MENUITEM_TRAYBROWSE1) && (nID <= ID_MENUITEM_TRAYBROWSEMAX));
CItemData ci;
m_RUEList.GetPWEntry(nID - ID_MENUITEM_TRAYBROWSE1, ci);
if (&ci == NULL) return;
CMyString browseURL = ci.GetURL();
if (!browseURL.IsEmpty()) {
LaunchBrowser(browseURL);
}
UpdateAccessTime(&ci);
}
void
DboxMain::OnUpdateTrayBrowse(CCmdUI *pCmdUI)
{
int nID = pCmdUI->m_nID;
ASSERT((nID >= ID_MENUITEM_TRAYBROWSE1) && (nID <= ID_MENUITEM_TRAYBROWSEMAX));
CItemData ci;
m_RUEList.GetPWEntry(nID - ID_MENUITEM_TRAYBROWSE1, ci);
if (&ci == NULL) return;
// Has it an embedded URL
if (ci.GetURL().IsEmpty()) {
pCmdUI->Enable(FALSE);
}
}
void
DboxMain::OnTrayDeleteEntry(UINT nID)
{
ASSERT((nID >= ID_MENUITEM_TRAYDELETE1) && (nID <= ID_MENUITEM_TRAYDELETEMAX));
m_RUEList.DeleteRUEntry(nID - ID_MENUITEM_TRAYDELETE1);
}
void
DboxMain::OnUpdateTrayDeleteEntry(CCmdUI *)
{
}
void
DboxMain::OnTrayAutoType(UINT nID)
{
ASSERT((nID >= ID_MENUITEM_TRAYAUTOTYPE1) && (nID <= ID_MENUITEM_TRAYAUTOTYPEMAX));
CItemData ci;
m_RUEList.GetPWEntry(nID - ID_MENUITEM_TRAYAUTOTYPE1, ci);
if (&ci == NULL) return;
AutoType(ci);
UpdateAccessTime(&ci);
}
void
DboxMain::OnUpdateTrayAutoType(CCmdUI *)
{
}
#endif