1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
10 #include "crashreportdlg.hxx"
11
12
13 #include <config_folders.h>
14
15 #include <rtl/bootstrap.hxx>
16 #include <desktop/crashreport.hxx>
17 #include <sfx2/safemode.hxx>
18 #include <comphelper/processfactory.hxx>
19 #include <osl/file.hxx>
20
21 #include <com/sun/star/task/OfficeRestartManager.hpp>
22 #include <com/sun/star/task/XInteractionHandler.hpp>
23
CrashReportDialog(weld::Window * pParent)24 CrashReportDialog::CrashReportDialog(weld::Window* pParent)
25 : GenericDialogController(pParent, "svx/ui/crashreportdlg.ui",
26 "CrashReportDialog")
27 , mxBtnSend(m_xBuilder->weld_button("btn_send"))
28 , mxBtnCancel(m_xBuilder->weld_button("btn_cancel"))
29 , mxBtnClose(m_xBuilder->weld_button("btn_close"))
30 , mxEditPreUpload(m_xBuilder->weld_label("ed_pre"))
31 , mxEditPostUpload(m_xBuilder->weld_text_view("ed_post"))
32 , mxFtBugReport(m_xBuilder->weld_text_view("ed_bugreport"))
33 , mxCBSafeMode(m_xBuilder->weld_check_button("check_safemode"))
34 {
35 maSuccessMsg = mxEditPostUpload->get_text();
36
37 auto nWidth = mxEditPreUpload->get_preferred_size().Width();
38 nWidth = std::max(nWidth, mxCBSafeMode->get_size_request().Width());
39 mxEditPreUpload->set_size_request(nWidth, -1);
40 mxCBSafeMode->set_size_request(nWidth, -1);
41
42 mxBtnSend->connect_clicked(LINK(this, CrashReportDialog, BtnHdl));
43 mxBtnCancel->connect_clicked(LINK(this, CrashReportDialog, BtnHdl));
44 mxBtnClose->connect_clicked(LINK(this, CrashReportDialog, BtnHdl));
45 }
46
~CrashReportDialog()47 CrashReportDialog::~CrashReportDialog()
48 {
49 }
50
run()51 short CrashReportDialog::run()
52 {
53 short nRet = GenericDialogController::run();
54
55 // Check whether to go to safe mode
56 if (mxCBSafeMode->get_active())
57 {
58 sfx2::SafeMode::putFlag();
59 css::task::OfficeRestartManager::get(comphelper::getProcessComponentContext())->requestRestart(
60 css::uno::Reference< css::task::XInteractionHandler >());
61 }
62 return nRet;
63 }
64
IMPL_LINK(CrashReportDialog,BtnHdl,weld::Button &,rBtn,void)65 IMPL_LINK(CrashReportDialog, BtnHdl, weld::Button&, rBtn, void)
66 {
67 if (&rBtn == mxBtnSend.get())
68 {
69 std::string response;
70 bool bSuccess = CrashReporter::readSendConfig(response);
71
72 OUString aCrashID = OUString::createFromAscii(response.c_str());
73
74 if (bSuccess)
75 {
76 OUString aProcessedMessage = maSuccessMsg.replaceAll("%CRASHID", aCrashID.replaceAll("Crash-ID=",""));
77
78 // vclbuilder seems to replace _ with ~ even in text
79 mxEditPostUpload->set_text(aProcessedMessage.replaceAll("~", "_"));
80 }
81 else
82 {
83 mxEditPostUpload->set_text(aCrashID);
84 }
85
86 mxBtnClose->show();
87 mxFtBugReport->show();
88 mxEditPostUpload->show();
89 mxBtnSend->set_sensitive(false);
90 mxBtnCancel->set_sensitive(false);
91 mxBtnClose->grab_focus();
92
93 mxEditPreUpload->hide();
94 mxBtnSend->hide();
95 mxBtnCancel->hide();
96
97 m_xDialog->resize_to_request();
98 }
99 else if (&rBtn == mxBtnCancel.get())
100 {
101 m_xDialog->response(RET_CLOSE);
102 }
103 else if (&rBtn == mxBtnClose.get())
104 {
105 m_xDialog->response(RET_CLOSE);
106 }
107 }
108
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
110