Follow-on fix for bug 457825. Use sheet principal for agent and user sheets. r=dbaron...
[wine-gecko.git] / embedding / qa / testembed / ProfilesDlg.cpp
blobd2c017df11d80d6d6b40f5b8a5c039633a091ecb
1 // ProfilesDlg.cpp : implementation file
2 //
4 #include "stdafx.h"
5 #include <afxpriv.h>
6 #include "Testembed.h"
7 #include "ProfilesDlg.h"
9 // Mozilla
10 #include "nsIProfile.h"
11 #include "nsIServiceManager.h"
13 #ifdef _DEBUG
14 #define new DEBUG_NEW
15 #undef THIS_FILE
16 static char THIS_FILE[] = __FILE__;
17 #endif
19 // Static Routines
20 static void ValidateProfileName(const CString& profileName, CDataExchange* pDX)
22 USES_CONVERSION;
24 nsresult rv;
25 PRBool exists = FALSE;
28 //NS_WITH_SERVICE(nsIProfile, profileService, NS_PROFILE_CONTRACTID, &rv);
29 nsCOMPtr<nsIProfile> profileService(do_GetService(NS_PROFILE_CONTRACTID));
30 rv = profileService->ProfileExists(T2W(profileName), &exists);
33 if (NS_SUCCEEDED(rv) && exists)
35 CString errMsg;
37 errMsg.Format(_T("Error: A profile named \"%s\" already exists."), (const char *)profileName);
38 AfxMessageBox( errMsg, MB_ICONEXCLAMATION );
39 errMsg.Empty();
40 pDX->Fail();
43 if (profileName.FindOneOf("\\/") != -1)
45 AfxMessageBox( _T("Error: A profile name cannot contain the characters \"\\\" or \"/\"."), MB_ICONEXCLAMATION );
46 pDX->Fail();
50 /////////////////////////////////////////////////////////////////////////////
51 // CNewProfileDlg dialog
54 CNewProfileDlg::CNewProfileDlg(CWnd* pParent /*=NULL*/)
55 : CDialog(CNewProfileDlg::IDD, pParent)
57 //{{AFX_DATA_INIT(CNewProfileDlg)
58 m_LocaleIndex = -1;
59 m_Name = _T("");
60 //}}AFX_DATA_INIT
64 void CNewProfileDlg::DoDataExchange(CDataExchange* pDX)
66 CDialog::DoDataExchange(pDX);
67 //{{AFX_DATA_MAP(CNewProfileDlg)
68 DDX_CBIndex(pDX, IDC_LOCALE_COMBO, m_LocaleIndex);
69 DDX_Text(pDX, IDC_NEW_PROF_NAME, m_Name);
70 //}}AFX_DATA_MAP
72 pDX->PrepareEditCtrl(IDC_NEW_PROF_NAME);
73 if (pDX->m_bSaveAndValidate)
75 ValidateProfileName(m_Name, pDX);
80 BEGIN_MESSAGE_MAP(CNewProfileDlg, CDialog)
81 //{{AFX_MSG_MAP(CNewProfileDlg)
82 // NOTE: the ClassWizard will add message map macros here
83 //}}AFX_MSG_MAP
84 END_MESSAGE_MAP()
86 /////////////////////////////////////////////////////////////////////////////
87 // CNewProfileDlg message handlers
90 /////////////////////////////////////////////////////////////////////////////
91 // CRenameProfileDlg dialog
94 CRenameProfileDlg::CRenameProfileDlg(CWnd* pParent /*=NULL*/)
95 : CDialog(CRenameProfileDlg::IDD, pParent)
97 //{{AFX_DATA_INIT(CRenameProfileDlg)
98 m_NewName = _T("");
99 //}}AFX_DATA_INIT
103 void CRenameProfileDlg::DoDataExchange(CDataExchange* pDX)
105 CDialog::DoDataExchange(pDX);
106 //{{AFX_DATA_MAP(CRenameProfileDlg)
107 DDX_Text(pDX, IDC_NEW_NAME, m_NewName);
108 //}}AFX_DATA_MAP
110 pDX->PrepareEditCtrl(IDC_NEW_NAME);
111 if (pDX->m_bSaveAndValidate)
113 ValidateProfileName(m_NewName, pDX);
118 BEGIN_MESSAGE_MAP(CRenameProfileDlg, CDialog)
119 //{{AFX_MSG_MAP(CRenameProfileDlg)
120 // NOTE: the ClassWizard will add message map macros here
121 //}}AFX_MSG_MAP
122 END_MESSAGE_MAP()
124 /////////////////////////////////////////////////////////////////////////////
125 // CRenameProfileDlg message handlers
128 /////////////////////////////////////////////////////////////////////////////
129 // CProfilesDlg dialog
132 CProfilesDlg::CProfilesDlg(CWnd* pParent /*=NULL*/)
133 : CDialog(CProfilesDlg::IDD, pParent)
135 //{{AFX_DATA_INIT(CProfilesDlg)
136 m_bAtStartUp = TRUE;
137 m_bAskAtStartUp = TRUE;
138 //}}AFX_DATA_INIT
142 void CProfilesDlg::DoDataExchange(CDataExchange* pDX)
144 CDialog::DoDataExchange(pDX);
145 //{{AFX_DATA_MAP(CProfilesDlg)
146 DDX_Control(pDX, IDC_LIST1, m_ProfileList);
147 DDX_Check(pDX, IDC_CHECK_ASK_AT_START, m_bAskAtStartUp);
148 //}}AFX_DATA_MAP
150 if (pDX->m_bSaveAndValidate)
152 USES_CONVERSION;
154 int itemIndex = m_ProfileList.GetCurSel();
155 if (itemIndex != LB_ERR)
157 CString itemText;
158 m_ProfileList.GetText(itemIndex, itemText);
159 m_SelectedProfile.Assign(T2W(itemText));
165 BEGIN_MESSAGE_MAP(CProfilesDlg, CDialog)
166 //{{AFX_MSG_MAP(CProfilesDlg)
167 ON_BN_CLICKED(IDC_PROF_NEW, OnNewProfile)
168 ON_BN_CLICKED(IDC_PROF_RENAME, OnRenameProfile)
169 ON_BN_CLICKED(IDC_PROF_DELETE, OnDeleteProfile)
170 //}}AFX_MSG_MAP
171 END_MESSAGE_MAP()
173 /////////////////////////////////////////////////////////////////////////////
174 // CProfilesDlg message handlers
176 BOOL CProfilesDlg::OnInitDialog()
178 USES_CONVERSION;
180 CDialog::OnInitDialog();
182 nsCAutoString cStr;
183 nsXPIDLString curProfileName;
185 // Fill the list of profiles
186 nsresult rv;
187 //NS_WITH_SERVICE(nsIProfile, profileService, NS_PROFILE_CONTRACTID, &rv);
188 nsCOMPtr<nsIProfile> profileService(do_GetService(NS_PROFILE_CONTRACTID));
189 profileService->GetCurrentProfile(getter_Copies(curProfileName));
191 PRInt32 selectedRow = 0;
192 PRUint32 listLen;
193 PRUnichar **profileList;
194 rv = profileService->GetProfileList(&listLen, &profileList);
196 for (PRUint32 index = 0; index < listLen; index++)
198 CString tmpStr(W2T(profileList[index]));
199 m_ProfileList.AddString(tmpStr);
200 if (nsCRT::strcmp(profileList[index], curProfileName.get()) == 0)
201 selectedRow = index;
204 m_ProfileList.SetCurSel(selectedRow);
206 if (m_bAtStartUp)
208 GetDlgItem(IDCANCEL)->EnableWindow(FALSE);
211 return TRUE; // return TRUE unless you set the focus to a control
212 // EXCEPTION: OCX Property Pages should return FALSE
215 void CProfilesDlg::OnNewProfile()
217 CNewProfileDlg dialog;
219 if (dialog.DoModal() == IDOK)
221 nsresult rv;
223 //NS_WITH_SERVICE(nsIProfile, profileService, NS_PROFILE_CONTRACTID, &rv);
224 nsCOMPtr<nsIProfile> profileService(do_GetService(NS_PROFILE_CONTRACTID,&rv));
225 ASSERT(NS_SUCCEEDED(rv));
226 if (NS_SUCCEEDED(rv))
228 USES_CONVERSION;
230 rv = profileService->CreateNewProfile(T2W(dialog.m_Name), nsnull, nsnull, PR_FALSE);
231 ASSERT(NS_SUCCEEDED(rv));
232 if (NS_SUCCEEDED(rv))
234 int item = m_ProfileList.AddString(dialog.m_Name);
235 m_ProfileList.SetCurSel(item);
236 GetDlgItem(IDOK)->EnableWindow(TRUE);
242 void CProfilesDlg::OnRenameProfile()
244 CRenameProfileDlg dialog;
246 int itemIndex = m_ProfileList.GetCurSel();
247 ASSERT(itemIndex != LB_ERR);
248 if (itemIndex == LB_ERR)
249 return;
251 m_ProfileList.GetText(itemIndex, dialog.m_CurrentName);
253 if (dialog.DoModal() == IDOK)
255 USES_CONVERSION;
257 nsresult rv;
259 //NS_WITH_SERVICE(nsIProfile, profileService, NS_PROFILE_CONTRACTID, &rv);
260 nsCOMPtr<nsIProfile> profileService(do_GetService(NS_PROFILE_CONTRACTID,&rv));
261 ASSERT(NS_SUCCEEDED(rv));
262 if (NS_SUCCEEDED(rv))
264 rv = profileService->RenameProfile(T2W(dialog.m_CurrentName), T2W(dialog.m_NewName));
265 ASSERT(NS_SUCCEEDED(rv));
270 void CProfilesDlg::OnDeleteProfile()
272 int itemIndex = m_ProfileList.GetCurSel();
274 ASSERT(itemIndex != LB_ERR);
275 if (itemIndex == LB_ERR)
276 return;
278 CString selectedProfile;
279 m_ProfileList.GetText(itemIndex, selectedProfile);
281 nsresult rv;
282 //NS_WITH_SERVICE(nsIProfile, profileService, NS_PROFILE_CONTRACTID, &rv);
283 nsCOMPtr<nsIProfile> profileService(do_GetService(NS_PROFILE_CONTRACTID,&rv));
285 ASSERT(NS_SUCCEEDED(rv));
286 if (NS_SUCCEEDED(rv))
288 USES_CONVERSION;
290 rv = profileService->DeleteProfile(T2W(selectedProfile), PR_TRUE);
291 ASSERT(NS_SUCCEEDED(rv));
292 if (NS_SUCCEEDED(rv))
294 int itemCount = m_ProfileList.DeleteString(itemIndex);
295 if (itemCount == 0)
296 GetDlgItem(IDOK)->EnableWindow(FALSE);