10#include <officecfg/Office/Common.hxx>
11#include <osl/file.hxx>
12#include <osl/security.hxx>
17#include <com/sun/star/xml/crypto/NSSInitializer.hpp>
18#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
19#include <com/sun/star/ui/dialogs/XFolderPicker2.hpp>
25 : GenericDialogController(pParent,
"cui/ui/certdialog.ui",
"CertDialog")
26 , m_xManualButton(m_xBuilder->weld_button(
"add"))
28 , m_xCertPathList(m_xBuilder->weld_tree_view(
"paths"))
29 , m_sAddDialogText(m_xBuilder->weld_label(
"certdir")->get_label())
30 , m_sManualLabel(m_xBuilder->weld_label(
"manual")->get_label())
52 OUString sActivePath = xCipherContextSupplier->getNSSPath();
53 auto aProductList = xCipherContextSupplier->getNSSProfiles();
56 const char*
const productNames[4] = {
63 for (
const auto& rNSSProfile : std::as_const(aProductList))
65 if (rNSSProfile.Type == mozilla::MozillaProductType_Default)
67 if (rNSSProfile.Name ==
"MOZILLA_CERTIFICATE_FOLDER" && !rNSSProfile.Path.isEmpty())
69 AddCertPath(
"$MOZILLA_CERTIFICATE_FOLDER", rNSSProfile.Path);
72 else if (rNSSProfile.Name ==
"MANUAL")
77 OUString sEntry = OUString::createFromAscii(
78 productNames[
static_cast<int>(rNSSProfile.Type)]) +
":" + rNSSProfile.Name;
79 AddCertPath(sEntry, rNSSProfile.Path, rNSSProfile.Path == sActivePath);
83 OUString sManualCertPath = officecfg::Office::Common::Security::Scripting::ManualCertDir::get();
84 if (!sManualCertPath.isEmpty())
87 catch (
const uno::Exception&)
94 if (sUserSetCertPath.isEmpty())
97 ::osl::DirectoryItem aUserPathItem;
98 OUString sUserSetCertURLPath;
99 osl::FileBase::getFileURLFromSystemPath(sUserSetCertPath, sUserSetCertURLPath);
100 if (::osl::FileBase::E_None == ::osl::DirectoryItem::get(sUserSetCertURLPath, aUserPathItem))
102 ::osl::FileStatus aStatus( osl_FileStatus_Mask_Validate );
103 if (::osl::FileBase::E_None == aUserPathItem.getFileStatus(aStatus))
113 std::shared_ptr< comphelper::ConfigurationChanges > batch(
115 const int nEntry = m_xCertPathList->get_selected_index();
116 officecfg::Office::Common::Security::Scripting::CertDir::set(
117 nEntry == -1 ? OUString() : m_xCertPathList->get_id(nEntry), batch);
118 officecfg::Office::Common::Security::Scripting::ManualCertDir::set(m_sManualPath, batch);
121 catch (
const uno::Exception &)
140 if (!xCipherContextSupplier->getIsNSSinitialized())
142 return (xCipherContextSupplier->getNSSPath() ==
m_xCertPathList->get_id(nEntry));
144 catch (
const uno::Exception&)
156 HandleEntryChecked(m_xCertPathList->get_iter_index_in_parent(rRowCol.first));
182 if (sCertPath == rPath)
216 if (!m_sManualPath.isEmpty())
217 osl::FileBase::getFileURLFromSystemPath(m_sManualPath, sURL);
219 osl::Security().getHomeDir(sURL);
220 xFolderPicker->setDisplayDirectory(sURL);
221 xFolderPicker->setDescription(m_sAddDialogText);
223 if (xFolderPicker->execute() == ui::dialogs::ExecutableDialogResults::OK)
225 sURL = xFolderPicker->getDirectory();
227 if (osl::FileBase::E_None == osl::FileBase::getSystemPathFromFileURL(sURL, aPath))
228 AddCertPath(m_sManualLabel, aPath);
231 catch (
const uno::Exception &)
Reference< XExecutableDialog > m_xDialog
IMPL_LINK_NOARG(CertPathDialog, OKHdl_Impl, weld::Button &, void)
IMPL_LINK(CertPathDialog, CheckHdl_Impl, const weld::TreeView::iter_col &, rRowCol, void)
std::unique_ptr< weld::TreeView > m_xCertPathList
CertPathDialog(weld::Window *pParent)
void AddCertPath(const OUString &rProfile, const OUString &rPath, bool bSelect=true)
void AddManualCertPath(const OUString &sUserSetCertPath, bool bSelect=true)
bool isActiveServicePath() const
void HandleEntryChecked(int nRow)
std::unique_ptr< weld::Button > m_xOKButton
virtual ~CertPathDialog() override
std::unique_ptr< weld::Button > m_xManualButton
static std::shared_ptr< ConfigurationChanges > create()
std::pair< const TreeIter &, int > iter_col
#define TOOLS_WARN_EXCEPTION(area, stream)
std::unique_ptr< weld::Button > m_xOKButton
#define LINK(Instance, Class, Member)
Reference< XComponentContext > getProcessComponentContext()
css::uno::Reference< css::ui::dialogs::XFolderPicker2 > createFolderPicker(const css::uno::Reference< css::uno::XComponentContext > &rContext, weld::Window *pPreferredParent)