[994dbc]: / DboxTray.cpp  Maximize  Restore  History

Download this file

216 lines (179 with data), 4.8 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
/*
* Copyright (c) 2003-2007 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;
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 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;
CString cs_text;
if (!m_RUEList.GetPWEntry(nID - ID_MENUITEM_TRAYCOPYNOTES1, ci))
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()) {
cs_text.LoadString(IDS_COPYURL);
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.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;
// Has it an embedded URL
if (ci.IsURLEmpty()) {
pCmdUI->Enable(FALSE);
} else {
const bool bIsEmail = ci.GetURL().Find(_T("mailto:")) != -1;
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 *)
{
}
#endif /* POCKET_PC */