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 const offerSafeMode
= officecfg::Office::Common::Misc::OfferSafeMode::get();
44 mxCBSafeMode
->set_visible(offerSafeMode
);
46 auto nWidth
= mxEditPreUpload
->get_preferred_size().Width();
49 nWidth
= std::max(nWidth
, mxCBSafeMode
->get_size_request().Width());
51 mxEditPreUpload
->set_size_request(nWidth
, -1);
52 mxCBSafeMode
->set_size_request(nWidth
, -1);
54 mxBtnSend
->connect_clicked(LINK(this, CrashReportDialog
, BtnHdl
));
55 mxBtnCancel
->connect_clicked(LINK(this, CrashReportDialog
, BtnHdl
));
56 mxBtnClose
->connect_clicked(LINK(this, CrashReportDialog
, BtnHdl
));
58 mxPrivacyPolicyButton
->set_uri(
59 officecfg::Office::Common::Menus::PrivacyPolicyURL::get()
60 + "?type=crashreport&LOvers=" + utl::ConfigManager::getProductVersion()
61 + "&LOlocale=" + LanguageTag(utl::ConfigManager::getUILocale()).getBcp47());
63 m_xDialog
->SetInstallLOKNotifierHdl(LINK(this, CrashReportDialog
, InstallLOKNotifierHdl
));
66 CrashReportDialog::~CrashReportDialog() {}
68 short CrashReportDialog::run()
70 short nRet
= GenericDialogController::run();
72 // Check whether to go to safe mode
73 if (mxCBSafeMode
->get_active())
75 sfx2::SafeMode::putFlag();
76 css::task::OfficeRestartManager::get(comphelper::getProcessComponentContext())
77 ->requestRestart(css::uno::Reference
<css::task::XInteractionHandler
>());
82 IMPL_LINK(CrashReportDialog
, BtnHdl
, weld::Button
&, rBtn
, void)
84 if (&rBtn
== mxBtnSend
.get())
87 bool bSuccess
= CrashReporter::readSendConfig(response
);
89 OUString aCrashID
= OUString::createFromAscii(response
);
93 OUString aProcessedLink
94 = maLinkTemplate
.replaceAll("%CRASHID", aCrashID
.replaceAll("Crash-ID=", ""));
96 // vclbuilder seems to replace _ with ~ even in text
97 mxLinkButton
->set_label(aProcessedLink
.replaceAll("~", "_"));
98 mxLinkButton
->set_uri(aProcessedLink
);
102 mxEditPostUpload
->set_label(aCrashID
);
105 mxLinkButton
->set_visible(bSuccess
);
108 mxFtBugReport
->show();
109 mxEditPostUpload
->show();
110 mxBtnSend
->set_sensitive(false);
111 mxBtnCancel
->set_sensitive(false);
112 mxBtnClose
->grab_focus();
114 mxEditPreUpload
->hide();
118 m_xDialog
->resize_to_request();
120 else if (&rBtn
== mxBtnCancel
.get())
122 m_xDialog
->response(RET_CLOSE
);
124 else if (&rBtn
== mxBtnClose
.get())
126 m_xDialog
->response(RET_CLOSE
);
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */