[6a7162]: DboxTray.cpp  Maximize  Restore  History

Download this file

301 lines (248 with data), 7.3 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/*
* Copyright (c) 2003-2008 Rony Shapiro <ronys@users.sourceforge.net>.
* All rights reserved. Use of the code is allowed under the
* Artistic License 2.0 terms, as specified in the LICENSE file
* distributed with this code, or available from
* http://www.opensource.org/licenses/artistic-license-2.0.php
*/
/// 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"
#include "resource2.h" // Menu, Toolbar & Accelerator resources
#include "resource3.h" // String resources
#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()
{
switch(app.GetSystemTrayState()) {
case ThisMfcApp::LOCKED: // User clicked UnLock
UnMinimize(true);
break;
case ThisMfcApp::UNLOCKED: // User clicked Lock
UpdateSystemTray(LOCKED);
ClearClipboardData();
ShowWindow(SW_HIDE);
m_IdleLockCountDown = 1; // lock the same way as a timer lock
OnTimer(TIMER_USERLOCK); // save db if needed, etc.
break;
case ThisMfcApp::CLOSED:
default:
ASSERT(0);
break;
}
}
void DboxMain::OnTrayClearRecentEntries()
{
m_RUEList.ClearEntries();
}
void DboxMain::OnTrayCopyUsername(UINT nID)
{
ASSERT((nID >= ID_MENUITEM_TRAYCOPYUSERNAME1) &&
(nID <= ID_MENUITEM_TRAYCOPYUSERNAMEMAX));
CItemData ci;
if (!m_RUEList.GetPWEntry(nID - ID_MENUITEM_TRAYCOPYUSERNAME1, ci))
return;
if (ci.IsShortcut()) {
// This is an shortcut
uuid_array_t entry_uuid, base_uuid;
ci.GetUUID(entry_uuid);
m_core.GetShortcutBaseUUID(entry_uuid, base_uuid);
ItemListIter iter = m_core.Find(base_uuid);
if (iter != End()) {
ci = iter->second;
}
}
const CMyString username = ci.GetUser();
if (!username.IsEmpty()) {
SetClipboardData(username);
UpdateAccessTime(&ci);
}
}
void DboxMain::OnUpdateTrayCopyUsername(CCmdUI *)
{
}
void DboxMain::OnTrayCopyPassword(UINT nID)
{
ASSERT((nID >= ID_MENUITEM_TRAYCOPYPASSWORD1) && (nID <= ID_MENUITEM_TRAYCOPYPASSWORDMAX));
CItemData ci;
if (!m_RUEList.GetPWEntry(nID - ID_MENUITEM_TRAYCOPYPASSWORD1, ci))
return;
const CItemData::EntryType entrytype = ci.GetEntryType();
if (entrytype == CItemData::Alias || entrytype == CItemData::Shortcut) {
// This is an alias/shortcut
uuid_array_t entry_uuid, base_uuid;
ci.GetUUID(entry_uuid);
if (entrytype == CItemData::Alias)
m_core.GetAliasBaseUUID(entry_uuid, base_uuid);
else
m_core.GetShortcutBaseUUID(entry_uuid, base_uuid);
ItemListIter iter = m_core.Find(base_uuid);
if (iter != End()) {
ci = iter->second;
}
}
const CMyString curPassString = ci.GetPassword();
SetClipboardData(curPassString);
UpdateAccessTime(&ci);
}
void DboxMain::OnUpdateTrayCopyPassword(CCmdUI *)
{
}
void DboxMain::OnTrayCopyNotes(UINT nID)
{
ASSERT((nID >= ID_MENUITEM_TRAYCOPYNOTES1) && (nID <= ID_MENUITEM_TRAYCOPYNOTESMAX));
CItemData ci;
if (!m_RUEList.GetPWEntry(nID - ID_MENUITEM_TRAYCOPYNOTES1, ci))
return;
if (ci.IsShortcut()) {
// This is an shortcut
uuid_array_t entry_uuid, base_uuid;
ci.GetUUID(entry_uuid);
m_core.GetShortcutBaseUUID(entry_uuid, base_uuid);
ItemListIter iter = m_core.Find(base_uuid);
if (iter != End()) {
ci = iter->second;
}
}
CString cs_text;
const CMyString notes = ci.GetNotes();
const CMyString url = ci.GetURL();
const CMyString autotype = ci.GetAutoType();
CMyString clipboard_data;
clipboard_data = notes;
if (!url.IsEmpty()) {
if (ci.IsURLEmail())
cs_text.LoadString(IDS_COPYURL);
else
cs_text.LoadString(IDS_COPYEMAIL);
clipboard_data += CMyString(cs_text);
clipboard_data += url;
}
if (!autotype.IsEmpty()) {
cs_text.LoadString(IDS_COPYAUTOTYPE);
clipboard_data += CMyString(cs_text);
clipboard_data += autotype;
}
if (!clipboard_data.IsEmpty()) {
SetClipboardData(clipboard_data);
UpdateAccessTime(&ci);
}
}
void DboxMain::OnUpdateTrayCopyNotes(CCmdUI *)
{
}
void DboxMain::OnTrayBrowse(UINT nID)
{
ASSERT((nID >= ID_MENUITEM_TRAYBROWSE1) && (nID <= ID_MENUITEM_TRAYBROWSEMAX));
CItemData ci;
if (!m_RUEList.GetPWEntry(nID - ID_MENUITEM_TRAYBROWSE1, ci))
return;
if (ci.IsShortcut()) {
// This is an shortcut
uuid_array_t entry_uuid, base_uuid;
ci.GetUUID(entry_uuid);
m_core.GetShortcutBaseUUID(entry_uuid, base_uuid);
ItemListIter iter = m_core.Find(base_uuid);
if (iter != End()) {
ci = iter->second;
}
}
if (!ci.IsURLEmpty()) {
LaunchBrowser(ci.GetURL());
}
UpdateAccessTime(&ci);
}
void DboxMain::OnUpdateTrayBrowse(CCmdUI *pCmdUI)
{
int nID = pCmdUI->m_nID;
ASSERT((nID >= ID_MENUITEM_TRAYBROWSE1) && (nID <= ID_MENUITEM_TRAYBROWSEMAX));
CItemData ci;
if (!m_RUEList.GetPWEntry(nID - ID_MENUITEM_TRAYBROWSE1, ci))
return;
if (ci.IsShortcut()) {
// This is an shortcut
uuid_array_t entry_uuid, base_uuid;
ci.GetUUID(entry_uuid);
m_core.GetShortcutBaseUUID(entry_uuid, base_uuid);
ItemListIter iter = m_core.Find(base_uuid);
if (iter != End()) {
ci = iter->second;
}
}
// Has it an embedded URL
if (ci.IsURLEmpty()) {
pCmdUI->Enable(FALSE);
} else {
const bool bIsEmail = ci.IsURLEmail();
CString cs_text = bIsEmail ? CS_SENDEMAIL : CS_BROWSEURL;
int nPos = cs_text.Find(_T("\t"));
if (nPos > 0)
cs_text = cs_text.Left(nPos);
pCmdUI->SetText(cs_text);
}
}
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;
if (!m_RUEList.GetPWEntry(nID - ID_MENUITEM_TRAYAUTOTYPE1, ci))
return;
AutoType(ci);
UpdateAccessTime(&ci);
}
void DboxMain::OnUpdateTrayAutoType(CCmdUI *)
{
}
void DboxMain::OnTrayCopyURL(UINT nID)
{
ASSERT((nID >= ID_MENUITEM_TRAYCOPYURL1) && (nID <= ID_MENUITEM_TRAYCOPYURLMAX));
CItemData ci;
if (!m_RUEList.GetPWEntry(nID - ID_MENUITEM_TRAYCOPYURL1, ci))
return;
if (ci.IsShortcut()) {
// This is an shortcut
uuid_array_t entry_uuid, base_uuid;
ci.GetUUID(entry_uuid);
m_core.GetShortcutBaseUUID(entry_uuid, base_uuid);
ItemListIter iter = m_core.Find(base_uuid);
if (iter != End()) {
ci = iter->second;
}
}
const CMyString cs_URL = ci.GetURL();
if (!cs_URL.IsEmpty())
SetClipboardData(cs_URL);
else
ClearClipboardData();
UpdateAccessTime(&ci);
}
void DboxMain::OnUpdateTrayCopyURL(CCmdUI *)
{
}
#endif /* POCKET_PC */

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks