1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include "crashreportdlg.hxx"
12 #include <desktop/crashreport.hxx>
13 #include <sfx2/safemode.hxx>
14 #include <comphelper/processfactory.hxx>
15 #include <i18nlangtag/languagetag.hxx>
16 #include <unotools/configmgr.hxx>
17 #include <officecfg/Office/Common.hxx>
18 #include <vcl/svapp.hxx>
20 #include <com/sun/star/task/OfficeRestartManager.hpp>
21 #include <com/sun/star/task/XInteractionHandler.hpp>
23 IMPL_STATIC_LINK_NOARG(CrashReportDialog
, InstallLOKNotifierHdl
, void*,
24 vcl::ILibreOfficeKitNotifier
*)
29 CrashReportDialog::CrashReportDialog(weld::Window
* pParent
)
30 : GenericDialogController(pParent
, "svx/ui/crashreportdlg.ui", "CrashReportDialog")
31 , mxBtnSend(m_xBuilder
->weld_button("btn_send"))
32 , mxBtnCancel(m_xBuilder
->weld_button("btn_cancel"))
33 , mxBtnClose(m_xBuilder
->weld_button("btn_close"))
34 , mxEditPreUpload(m_xBuilder
->weld_label("ed_pre"))
35 , mxEditPostUpload(m_xBuilder
->weld_label("ed_post"))
36 , mxLinkButton(m_xBuilder
->weld_link_button("linkbutton"))
37 , mxFtBugReport(m_xBuilder
->weld_label("ed_bugreport"))
38 , mxCBSafeMode(m_xBuilder
->weld_check_button("check_safemode"))
39 , mxPrivacyPolicyButton(m_xBuilder
->weld_link_button("btnPrivacyPolicy"))
41 maLinkTemplate
= mxLinkButton
->get_uri();
43 auto nWidth
= mxEditPreUpload
->get_preferred_size().Width();
44 nWidth
= std::max(nWidth
, mxCBSafeMode
->get_size_request().Width());
45 mxEditPreUpload
->set_size_request(nWidth
, -1);
46 mxCBSafeMode
->set_size_request(nWidth
, -1);
48 mxBtnSend
->connect_clicked(LINK(this, CrashReportDialog
, BtnHdl
));
49 mxBtnCancel
->connect_clicked(LINK(this, CrashReportDialog
, BtnHdl
));
50 mxBtnClose
->connect_clicked(LINK(this, CrashReportDialog
, BtnHdl
));
52 mxPrivacyPolicyButton
->set_uri(
53 officecfg::Office::Common::Menus::PrivacyPolicyURL::get()
54 + "?type=crashreport&LOvers=" + utl::ConfigManager::getProductVersion()
55 + "&LOlocale=" + LanguageTag(utl::ConfigManager::getUILocale()).getBcp47());
57 m_xDialog
->SetInstallLOKNotifierHdl(LINK(this, CrashReportDialog
, InstallLOKNotifierHdl
));
60 CrashReportDialog::~CrashReportDialog() {}
62 short CrashReportDialog::run()
64 short nRet
= GenericDialogController::run();
66 // Check whether to go to safe mode
67 if (mxCBSafeMode
->get_active())
69 sfx2::SafeMode::putFlag();
70 css::task::OfficeRestartManager::get(comphelper::getProcessComponentContext())
71 ->requestRestart(css::uno::Reference
<css::task::XInteractionHandler
>());
76 IMPL_LINK(CrashReportDialog
, BtnHdl
, weld::Button
&, rBtn
, void)
78 if (&rBtn
== mxBtnSend
.get())
81 bool bSuccess
= CrashReporter::readSendConfig(response
);
83 OUString aCrashID
= OUString::createFromAscii(response
);
87 OUString aProcessedLink
88 = maLinkTemplate
.replaceAll("%CRASHID", aCrashID
.replaceAll("Crash-ID=", ""));
90 // vclbuilder seems to replace _ with ~ even in text
91 mxLinkButton
->set_label(aProcessedLink
.replaceAll("~", "_"));
92 mxLinkButton
->set_uri(aProcessedLink
);
96 mxEditPostUpload
->set_label(aCrashID
);
99 mxLinkButton
->set_visible(bSuccess
);
102 mxFtBugReport
->show();
103 mxEditPostUpload
->show();
104 mxBtnSend
->set_sensitive(false);
105 mxBtnCancel
->set_sensitive(false);
106 mxBtnClose
->grab_focus();
108 mxEditPreUpload
->hide();
112 m_xDialog
->resize_to_request();
114 else if (&rBtn
== mxBtnCancel
.get())
116 m_xDialog
->response(RET_CLOSE
);
118 else if (&rBtn
== mxBtnClose
.get())
120 m_xDialog
->response(RET_CLOSE
);
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */