Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : : *
5 : : * The contents of this file are subject to the Mozilla Public License Version
6 : : * 1.1 (the "License"); you may not use this file except in compliance with
7 : : * the License or as specified alternatively below. You may obtain a copy of
8 : : * the License at http://www.mozilla.org/MPL/
9 : : *
10 : : * Software distributed under the License is distributed on an "AS IS" basis,
11 : : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : : * for the specific language governing rights and limitations under the
13 : : * License.
14 : : *
15 : : * Major Contributor(s):
16 : : * Copyright (C) 2012 Red Hat, Inc., Caolán McNamara <caolanm@redhat.com>
17 : : * (initial developer)
18 : : *
19 : : * All Rights Reserved.
20 : : *
21 : : * For minor contributions see the git repository.
22 : : *
23 : : * Alternatively, the contents of this file may be used under the terms of
24 : : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
25 : : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
26 : : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
27 : : * instead of those above.
28 : : */
29 : :
30 : : #include <officecfg/Office/Common.hxx>
31 : : #include <osl/file.hxx>
32 : : #include <osl/security.hxx>
33 : : #include <svtools/stdctrl.hxx>
34 : : #include <unotools/securityoptions.hxx>
35 : : #include <cuires.hrc>
36 : : #include "certpath.hxx"
37 : : #include "certpath.hrc"
38 : : #include "dialmgr.hxx"
39 : :
40 : : #include <com/sun/star/mozilla/XMozillaBootstrap.hpp>
41 : : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
42 : : #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
43 : : #include <comphelper/processfactory.hxx>
44 : :
45 : : using namespace ::com::sun::star;
46 : :
47 : 0 : CertPathDialog::CertPathDialog( Window* pParent ) :
48 : 0 : ModalDialog( pParent, CUI_RES( RID_SVXDLG_CERTPATH ) )
49 [ # # ]: 0 : , m_aCertPathFL ( this, CUI_RES( FL_CERTPATH ) )
50 [ # # ]: 0 : , m_aCertPathFT ( this, CUI_RES( FT_CERTPATH ) )
51 [ # # ]: 0 : , m_aCertPathListContainer( this, CUI_RES( LB_CERTPATH ) )
52 : : , m_aCertPathList( m_aCertPathListContainer )
53 [ # # ]: 0 : , m_aAddBtn ( this, CUI_RES( PB_ADD ) )
54 [ # # ]: 0 : , m_aButtonsFL ( this, CUI_RES( FL_BUTTONS ) )
55 [ # # ]: 0 : , m_aOKBtn ( this, CUI_RES( PB_OK ) )
56 [ # # ]: 0 : , m_aCancelBtn ( this, CUI_RES( PB_CANCEL ) )
57 [ # # ]: 0 : , m_aHelpBtn ( this, CUI_RES( PB_HELP ) )
58 [ # # ]: 0 : , m_sAddDialogText(CUI_RESSTR(STR_ADDDLGTEXT))
59 [ # # ][ # # ]: 0 : , m_sManual(CUI_RESSTR(STR_MANUAL))
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
60 : : {
61 : : static long aStaticTabs[]=
62 : : {
63 : : 3, 0, 15, 75
64 : : };
65 : :
66 [ # # ]: 0 : m_aCertPathList.SvxSimpleTable::SetTabs( aStaticTabs );
67 : :
68 [ # # ][ # # ]: 0 : rtl::OUString sProfile(CUI_RESSTR(STR_PROFILE));
69 [ # # ][ # # ]: 0 : rtl::OUString sDirectory(CUI_RESSTR(STR_DIRECTORY));
70 : :
71 : 0 : rtl::OUStringBuffer sHeader;
72 [ # # ][ # # ]: 0 : sHeader.append('\t').append(sProfile).append('\t').append(sDirectory);
[ # # ][ # # ]
73 [ # # ][ # # ]: 0 : m_aCertPathList.InsertHeaderEntry( sHeader.makeStringAndClear(), HEADERBAR_APPEND, HIB_LEFT );
74 [ # # ]: 0 : m_aCertPathList.SetCheckButtonHdl( LINK( this, CertPathDialog, CheckHdl_Impl ) );
75 : :
76 [ # # ]: 0 : m_aAddBtn.SetClickHdl( LINK( this, CertPathDialog, AddHdl_Impl ) );
77 [ # # ]: 0 : m_aOKBtn.SetClickHdl( LINK( this, CertPathDialog, OKHdl_Impl ) );
78 : :
79 [ # # ]: 0 : FreeResource();
80 : :
81 : : try
82 : : {
83 : : mozilla::MozillaProductType productTypes[3] = {
84 : : mozilla::MozillaProductType_Thunderbird,
85 : : mozilla::MozillaProductType_Firefox,
86 : 0 : mozilla::MozillaProductType_Mozilla };
87 : : const char* productNames[3] = {
88 : : "thunderbird",
89 : : "firefox",
90 : 0 : "mozilla" };
91 : 0 : sal_Int32 nProduct = SAL_N_ELEMENTS(productTypes);
92 : :
93 [ # # ][ # # ]: 0 : uno::Reference<uno::XInterface> xInstance = comphelper::getProcessServiceFactory()->createInstance(
94 [ # # ]: 0 : "com.sun.star.mozilla.MozillaBootstrap");
95 : :
96 [ # # ]: 0 : uno::Reference<mozilla::XMozillaBootstrap> xMozillaBootstrap(xInstance, uno::UNO_QUERY_THROW);
97 : :
98 [ # # ]: 0 : for (sal_Int32 i = 0; i < nProduct; ++i)
99 : : {
100 [ # # ][ # # ]: 0 : ::rtl::OUString profile = xMozillaBootstrap->getDefaultProfile(productTypes[i]);
101 : :
102 [ # # ]: 0 : if (!profile.isEmpty())
103 : : {
104 [ # # ][ # # ]: 0 : ::rtl::OUString sProfilePath = xMozillaBootstrap->getProfilePath( productTypes[i], profile );
105 : 0 : rtl::OUStringBuffer sEntry;
106 [ # # ][ # # ]: 0 : sEntry.append('\t').appendAscii(productNames[i]).append(':').append(profile).append('\t').append(sProfilePath);
[ # # ][ # # ]
[ # # ][ # # ]
107 [ # # ][ # # ]: 0 : SvLBoxEntry *pEntry = m_aCertPathList.InsertEntry(sEntry.makeStringAndClear());
[ # # ][ # # ]
108 [ # # ]: 0 : rtl::OUString* pCertPath = new rtl::OUString(sProfilePath);
109 : 0 : pEntry->SetUserData(pCertPath);
110 : : }
111 [ # # ]: 0 : }
112 : : }
113 [ # # ]: 0 : catch (const uno::Exception&)
114 : : {
115 : : }
116 : :
117 [ # # ]: 0 : SvLBoxEntry *pEntry = m_aCertPathList.GetEntry(0);
118 [ # # ]: 0 : if (pEntry)
119 : : {
120 [ # # ]: 0 : m_aCertPathList.SetCheckButtonState(pEntry, SV_BUTTON_CHECKED);
121 [ # # ]: 0 : HandleCheckEntry(pEntry);
122 : : }
123 : :
124 : : try
125 : : {
126 : : rtl::OUString sUserSetCertPath =
127 [ # # ][ # # ]: 0 : officecfg::Office::Common::Security::Scripting::CertDir::get().get_value_or(rtl::OUString());
[ # # ][ # # ]
128 : :
129 [ # # ]: 0 : if (!sUserSetCertPath.isEmpty())
130 [ # # ][ # # ]: 0 : AddCertPath(m_sManual, sUserSetCertPath);
131 : : }
132 [ # # ]: 0 : catch (const uno::Exception &e)
133 : : {
134 : : SAL_WARN("cui.options", "CertPathDialog::CertPathDialog(): caught exception" << e.Message);
135 : : }
136 : :
137 : 0 : const char* pEnv = getenv("MOZILLA_CERTIFICATE_FOLDER");
138 [ # # ]: 0 : if (pEnv)
139 [ # # ][ # # ]: 0 : AddCertPath("$MOZILLA_CERTIFICATE_FOLDER", rtl::OUString(pEnv, strlen(pEnv), osl_getThreadTextEncoding()));
[ # # ]
140 : 0 : }
141 : :
142 : 0 : IMPL_LINK_NOARG(CertPathDialog, OKHdl_Impl)
143 : : {
144 [ # # ][ # # ]: 0 : fprintf(stderr, "dir is %s\n", rtl::OUStringToOString(getDirectory(), RTL_TEXTENCODING_UTF8).getStr());
145 : :
146 : : try
147 : : {
148 : : boost::shared_ptr< comphelper::ConfigurationChanges > batch(
149 [ # # ][ # # ]: 0 : comphelper::ConfigurationChanges::create());
150 : : officecfg::Office::Common::Security::Scripting::CertDir::set(
151 [ # # ]: 0 : getDirectory(), batch);
152 [ # # ][ # # ]: 0 : batch->commit();
[ # # ]
153 : : }
154 : 0 : catch (const uno::Exception &e)
155 : : {
156 : : SAL_WARN("cui.options", "CertPathDialog::OKHdl_Impl(): caught exception" << e.Message);
157 : : }
158 : :
159 : 0 : EndDialog(true);
160 : :
161 : 0 : return 0;
162 : : }
163 : :
164 : 0 : rtl::OUString CertPathDialog::getDirectory() const
165 : : {
166 : 0 : SvLBoxEntry* pEntry = m_aCertPathList.FirstSelected();
167 [ # # ]: 0 : void* pCertPath = pEntry ? pEntry->GetUserData() : NULL;
168 [ # # ]: 0 : return pCertPath ? *static_cast<rtl::OUString*>(pCertPath) : rtl::OUString();
169 : : }
170 : :
171 [ # # ][ # # ]: 0 : CertPathDialog::~CertPathDialog()
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
172 : : {
173 [ # # ]: 0 : SvLBoxEntry* pEntry = m_aCertPathList.First();
174 [ # # ]: 0 : while (pEntry)
175 : : {
176 : 0 : rtl::OUString* pCertPath = static_cast<rtl::OUString*>(pEntry->GetUserData());
177 [ # # ]: 0 : delete pCertPath;
178 [ # # ]: 0 : pEntry = m_aCertPathList.Next( pEntry );
179 : : }
180 [ # # ]: 0 : }
181 : :
182 : 0 : IMPL_LINK( CertPathDialog, CheckHdl_Impl, SvxSimpleTable *, pList )
183 : : {
184 : 0 : SvLBoxEntry* pEntry = pList ? m_aCertPathList.GetEntry(m_aCertPathList.GetCurMousePoint())
185 [ # # ]: 0 : : m_aCertPathList.FirstSelected();
186 [ # # ]: 0 : if (pEntry)
187 : 0 : m_aCertPathList.HandleEntryChecked(pEntry);
188 : 0 : return 0;
189 : : }
190 : :
191 : 0 : void CertPathDialog::HandleCheckEntry( SvLBoxEntry* _pEntry )
192 : : {
193 : 0 : m_aCertPathList.Select( _pEntry, true );
194 : 0 : SvButtonState eState = m_aCertPathList.GetCheckButtonState( _pEntry );
195 : :
196 [ # # ]: 0 : if (SV_BUTTON_CHECKED == eState)
197 : : {
198 : : // uncheck the other entries
199 : 0 : SvLBoxEntry* pEntry = m_aCertPathList.First();
200 [ # # ]: 0 : while (pEntry)
201 : : {
202 [ # # ]: 0 : if (pEntry != _pEntry)
203 : 0 : m_aCertPathList.SetCheckButtonState(pEntry, SV_BUTTON_UNCHECKED);
204 : 0 : pEntry = m_aCertPathList.Next(pEntry);
205 : : }
206 : : }
207 : : else
208 : 0 : m_aCertPathList.SetCheckButtonState(_pEntry, SV_BUTTON_CHECKED);
209 : 0 : }
210 : :
211 : 0 : void CertPathDialog::AddCertPath(const rtl::OUString &rProfile, const rtl::OUString &rPath)
212 : : {
213 [ # # ]: 0 : SvLBoxEntry* pEntry = m_aCertPathList.First();
214 [ # # ]: 0 : while (pEntry)
215 : : {
216 : 0 : rtl::OUString* pCertPath = static_cast<rtl::OUString*>(pEntry->GetUserData());
217 : : //already exists, just select the original one
218 [ # # ]: 0 : if (pCertPath->equals(rPath))
219 : : {
220 [ # # ]: 0 : m_aCertPathList.SetCheckButtonState(pEntry, SV_BUTTON_CHECKED);
221 [ # # ]: 0 : HandleCheckEntry(pEntry);
222 : 0 : return;
223 : : }
224 [ # # ]: 0 : pEntry = m_aCertPathList.Next(pEntry);
225 : : }
226 : :
227 : 0 : rtl::OUStringBuffer sEntry;
228 [ # # ][ # # ]: 0 : sEntry.append('\t').append(rProfile).append('\t').append(rPath);
[ # # ][ # # ]
229 [ # # ][ # # ]: 0 : pEntry = m_aCertPathList.InsertEntry(sEntry.makeStringAndClear());
[ # # ][ # # ]
230 [ # # ]: 0 : rtl::OUString* pCertPath = new rtl::OUString(rPath);
231 : 0 : pEntry->SetUserData(pCertPath);
232 [ # # ]: 0 : m_aCertPathList.SetCheckButtonState(pEntry, SV_BUTTON_CHECKED);
233 [ # # ]: 0 : HandleCheckEntry(pEntry);
234 : : }
235 : :
236 : 0 : IMPL_LINK_NOARG(CertPathDialog, AddHdl_Impl)
237 : : {
238 : : try
239 : : {
240 [ # # ][ # # ]: 0 : uno::Reference<uno::XInterface> xInstance = comphelper::getProcessServiceFactory()->createInstance(
241 [ # # ]: 0 : "com.sun.star.ui.dialogs.FolderPicker");
242 : :
243 [ # # ]: 0 : uno::Reference<ui::dialogs::XFolderPicker> xFolderPicker(xInstance, uno::UNO_QUERY_THROW);
244 : :
245 : 0 : rtl::OUString sURL;
246 [ # # ][ # # ]: 0 : osl::Security().getHomeDir(sURL);
[ # # ]
247 [ # # ][ # # ]: 0 : xFolderPicker->setDisplayDirectory(sURL);
248 [ # # ][ # # ]: 0 : xFolderPicker->setDescription(m_sAddDialogText);
249 : :
250 [ # # ][ # # ]: 0 : if (xFolderPicker->execute() == ui::dialogs::ExecutableDialogResults::OK)
[ # # ]
251 : : {
252 [ # # ][ # # ]: 0 : sURL = xFolderPicker->getDirectory();
253 : 0 : rtl::OUString aPath;
254 [ # # ][ # # ]: 0 : if (osl::FileBase::E_None == osl::FileBase::getSystemPathFromFileURL(sURL, aPath))
255 [ # # ]: 0 : AddCertPath(m_sManual, aPath);
256 [ # # ]: 0 : }
257 : : }
258 : 0 : catch (const uno::Exception&)
259 : : {
260 : : SAL_WARN( "cui.options", "CertPathDialog::AddHdl_Impl(): caught exception" );
261 : : }
262 : :
263 : 0 : return 0;
264 : : }
265 : :
266 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|