1
/* ***** BEGIN LICENSE BLOCK *****
2
* Version: Mozilla-sample-code 1.0
4
* Copyright (c) 2002 Netscape Communications Corporation and
7
* Permission is hereby granted, free of charge, to any person obtaining a
8
* copy of this Mozilla sample software and associated documentation files
9
* (the "Software"), to deal in the Software without restriction, including
10
* without limitation the rights to use, copy, modify, merge, publish,
11
* distribute, sublicense, and/or sell copies of the Software, and to permit
12
* persons to whom the Software is furnished to do so, subject to the
13
* following conditions:
15
* The above copyright notice and this permission notice shall be included
16
* in all copies or substantial portions of the Software.
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24
* DEALINGS IN THE SOFTWARE.
28
* ***** END LICENSE BLOCK ***** */
30
// ProfilesDlg.cpp : implementation file
36
#include "ProfilesDlg.h"
39
#include "nsIProfile.h"
40
#include "nsIServiceManager.h"
45
static char THIS_FILE[] = __FILE__;
49
static void ValidateProfileName(const CString& profileName, CDataExchange* pDX)
54
PRBool exists = FALSE;
57
nsCOMPtr<nsIProfile> profileService =
58
do_GetService(NS_PROFILE_CONTRACTID, &rv);
59
rv = profileService->ProfileExists(T2CW(profileName), &exists);
62
if (NS_SUCCEEDED(rv) && exists)
65
errMsg.Format(_T("Error: A profile named \"%s\" already exists."), profileName);
66
AfxMessageBox( errMsg, MB_ICONEXCLAMATION );
71
if (profileName.FindOneOf(_T("\\/")) != -1)
73
AfxMessageBox( _T("Error: A profile name cannot contain the characters \"\\\" or \"/\"."), MB_ICONEXCLAMATION );
78
/////////////////////////////////////////////////////////////////////////////
79
// CNewProfileDlg dialog
82
CNewProfileDlg::CNewProfileDlg(CWnd* pParent /*=NULL*/)
83
: CDialog(CNewProfileDlg::IDD, pParent)
85
//{{AFX_DATA_INIT(CNewProfileDlg)
92
void CNewProfileDlg::DoDataExchange(CDataExchange* pDX)
94
CDialog::DoDataExchange(pDX);
95
//{{AFX_DATA_MAP(CNewProfileDlg)
96
DDX_CBIndex(pDX, IDC_LOCALE_COMBO, m_LocaleIndex);
97
DDX_Text(pDX, IDC_NEW_PROF_NAME, m_Name);
100
pDX->PrepareEditCtrl(IDC_NEW_PROF_NAME);
101
if (pDX->m_bSaveAndValidate)
103
ValidateProfileName(m_Name, pDX);
108
BEGIN_MESSAGE_MAP(CNewProfileDlg, CDialog)
109
//{{AFX_MSG_MAP(CNewProfileDlg)
110
// NOTE: the ClassWizard will add message map macros here
114
/////////////////////////////////////////////////////////////////////////////
115
// CNewProfileDlg message handlers
118
/////////////////////////////////////////////////////////////////////////////
119
// CRenameProfileDlg dialog
122
CRenameProfileDlg::CRenameProfileDlg(CWnd* pParent /*=NULL*/)
123
: CDialog(CRenameProfileDlg::IDD, pParent)
125
//{{AFX_DATA_INIT(CRenameProfileDlg)
131
void CRenameProfileDlg::DoDataExchange(CDataExchange* pDX)
133
CDialog::DoDataExchange(pDX);
134
//{{AFX_DATA_MAP(CRenameProfileDlg)
135
DDX_Text(pDX, IDC_NEW_NAME, m_NewName);
138
pDX->PrepareEditCtrl(IDC_NEW_NAME);
139
if (pDX->m_bSaveAndValidate)
141
ValidateProfileName(m_NewName, pDX);
146
BEGIN_MESSAGE_MAP(CRenameProfileDlg, CDialog)
147
//{{AFX_MSG_MAP(CRenameProfileDlg)
148
// NOTE: the ClassWizard will add message map macros here
152
/////////////////////////////////////////////////////////////////////////////
153
// CRenameProfileDlg message handlers
156
/////////////////////////////////////////////////////////////////////////////
157
// CProfilesDlg dialog
160
CProfilesDlg::CProfilesDlg(CWnd* pParent /*=NULL*/)
161
: CDialog(CProfilesDlg::IDD, pParent)
163
//{{AFX_DATA_INIT(CProfilesDlg)
164
m_bAtStartUp = FALSE;
165
m_bAskAtStartUp = FALSE;
170
void CProfilesDlg::DoDataExchange(CDataExchange* pDX)
172
CDialog::DoDataExchange(pDX);
173
//{{AFX_DATA_MAP(CProfilesDlg)
174
DDX_Control(pDX, IDC_LIST1, m_ProfileList);
175
DDX_Check(pDX, IDC_CHECK_ASK_AT_START, m_bAskAtStartUp);
178
if (pDX->m_bSaveAndValidate)
182
int itemIndex = m_ProfileList.GetCurSel();
183
if (itemIndex != LB_ERR)
186
m_ProfileList.GetText(itemIndex, itemText);
187
m_SelectedProfile.Assign(T2CW(itemText));
193
BEGIN_MESSAGE_MAP(CProfilesDlg, CDialog)
194
//{{AFX_MSG_MAP(CProfilesDlg)
195
ON_BN_CLICKED(IDC_PROF_NEW, OnNewProfile)
196
ON_BN_CLICKED(IDC_PROF_RENAME, OnRenameProfile)
197
ON_BN_CLICKED(IDC_PROF_DELETE, OnDeleteProfile)
198
ON_LBN_DBLCLK(IDC_LIST1, OnDblclkProfile)
202
/////////////////////////////////////////////////////////////////////////////
203
// CProfilesDlg message handlers
205
BOOL CProfilesDlg::OnInitDialog()
209
CDialog::OnInitDialog();
212
nsXPIDLString curProfileName;
214
// Fill the list of profiles
216
nsCOMPtr<nsIProfile> profileService =
217
do_GetService(NS_PROFILE_CONTRACTID, &rv);
218
profileService->GetCurrentProfile(getter_Copies(curProfileName));
220
PRInt32 selectedRow = 0;
222
PRUnichar **profileList;
223
rv = profileService->GetProfileList(&listLen, &profileList);
225
for (PRUint32 index = 0; index < listLen; index++)
227
CString tmpStr(W2T(profileList[index]));
228
m_ProfileList.AddString(tmpStr);
229
if (wcscmp(profileList[index], curProfileName.get()) == 0)
233
m_ProfileList.SetCurSel(selectedRow);
237
GetDlgItem(IDCANCEL)->EnableWindow(FALSE);
240
return TRUE; // return TRUE unless you set the focus to a control
241
// EXCEPTION: OCX Property Pages should return FALSE
244
void CProfilesDlg::OnNewProfile()
246
CNewProfileDlg dialog;
248
if (dialog.DoModal() == IDOK)
252
nsCOMPtr<nsIProfile> profileService =
253
do_GetService(NS_PROFILE_CONTRACTID, &rv);
254
ASSERT(NS_SUCCEEDED(rv));
255
if (NS_SUCCEEDED(rv))
259
rv = profileService->CreateNewProfile(T2CW(dialog.m_Name), nsnull, nsnull, PR_FALSE);
260
ASSERT(NS_SUCCEEDED(rv));
261
if (NS_SUCCEEDED(rv))
263
int item = m_ProfileList.AddString(dialog.m_Name);
264
m_ProfileList.SetCurSel(item);
265
GetDlgItem(IDOK)->EnableWindow(TRUE);
271
void CProfilesDlg::OnRenameProfile()
273
CRenameProfileDlg dialog;
275
int itemIndex = m_ProfileList.GetCurSel();
276
ASSERT(itemIndex != LB_ERR);
277
if (itemIndex == LB_ERR)
280
m_ProfileList.GetText(itemIndex, dialog.m_CurrentName);
282
if (dialog.DoModal() == IDOK)
288
nsCOMPtr<nsIProfile> profileService =
289
do_GetService(NS_PROFILE_CONTRACTID, &rv);
290
ASSERT(NS_SUCCEEDED(rv));
291
if (NS_SUCCEEDED(rv))
293
rv = profileService->RenameProfile(T2CW(dialog.m_CurrentName), T2CW(dialog.m_NewName));
294
ASSERT(NS_SUCCEEDED(rv));
299
void CProfilesDlg::OnDeleteProfile()
301
int itemIndex = m_ProfileList.GetCurSel();
302
ASSERT(itemIndex != LB_ERR);
303
if (itemIndex == LB_ERR)
306
CString selectedProfile;
307
m_ProfileList.GetText(itemIndex, selectedProfile);
310
nsCOMPtr<nsIProfile> profileService =
311
do_GetService(NS_PROFILE_CONTRACTID, &rv);
312
ASSERT(NS_SUCCEEDED(rv));
313
if (NS_SUCCEEDED(rv))
317
rv = profileService->DeleteProfile(T2CW(selectedProfile), PR_TRUE);
318
ASSERT(NS_SUCCEEDED(rv));
319
if (NS_SUCCEEDED(rv))
321
int itemCount = m_ProfileList.DeleteString(itemIndex);
323
GetDlgItem(IDOK)->EnableWindow(FALSE);
328
void CProfilesDlg::OnDblclkProfile()