summaryrefslogtreecommitdiff
path: root/svx/source/dialog/crashreportdlg.cxx
blob: c446aee7570fc664f23ab902b01ba22d35343989 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include "crashreportdlg.hxx"


#include <config_folders.h>

#include <rtl/bootstrap.hxx>
#include <desktop/crashreport.hxx>
#include <desktop/minidump.hxx>
#include <sfx2/safemode.hxx>
#include <comphelper/processfactory.hxx>
#include <osl/file.hxx>

#include <com/sun/star/task/OfficeRestartManager.hpp>
#include <com/sun/star/task/XInteractionHandler.hpp>

CrashReportDialog::CrashReportDialog(vcl::Window* pParent):
    Dialog(pParent, "CrashReportDialog",
            "svx/ui/crashreportdlg.ui")
{
    get(mpBtnSend, "btn_send");
    get(mpBtnCancel, "btn_cancel");
    get(mpBtnClose, "btn_close");
    get(mpEditPreUpload, "ed_pre");
    get(mpEditPostUpload, "ed_post");
    get(mpBugReportMailto, "bugreport_mailto");
    get(mpCBSafeMode, "check_safemode");

    maSuccessMsg = mpEditPostUpload->GetText();

    mpBtnSend->SetClickHdl(LINK(this, CrashReportDialog, BtnHdl));
    mpBtnCancel->SetClickHdl(LINK(this, CrashReportDialog, BtnHdl));
    mpBtnClose->SetClickHdl(LINK(this, CrashReportDialog, BtnHdl));
    mpEditPostUpload->SetReadOnly();
}

CrashReportDialog::~CrashReportDialog()
{
    disposeOnce();
}

void CrashReportDialog::dispose()
{
    mpBtnSend.clear();
    mpBtnCancel.clear();
    mpBtnClose.clear();
    mpEditPreUpload.clear();
    mpEditPostUpload.clear();
    mpBugReportMailto.clear();
    mpCBSafeMode.clear();

    Dialog::dispose();
}

bool CrashReportDialog::Close()
{
    // Check whether to go to safe mode
    if (mpCBSafeMode->IsChecked())
    {
        sfx2::SafeMode::putFlag();
        css::task::OfficeRestartManager::get(comphelper::getProcessComponentContext())->requestRestart(
            css::uno::Reference< css::task::XInteractionHandler >());
    }

    return Dialog::Close();
}

IMPL_LINK(CrashReportDialog, BtnHdl, Button*, pBtn, void)
{
    if (pBtn == mpBtnSend.get())
    {
        std::string ini_path = CrashReporter::getIniFileName();

        std::string response;
        bool bSuccess = crashreport::readConfig(ini_path, response);

        OUString aCrashID = OUString::createFromAscii(response.c_str());

        if (bSuccess)
        {
            OUString aProcessedMessage = maSuccessMsg.replaceAll("%CRASHID", aCrashID.replaceAll("Crash-ID=",""));

            // vclbuilder seems to replace _ with ~ even in text
            mpEditPostUpload->SetText(aProcessedMessage.replaceAll("~", "_"));
        }
        else
        {
            mpEditPostUpload->SetText(aCrashID);
        }

        mpBtnClose->Show();
        mpBugReportMailto->SetURL(mpFtBugReport->GetURL().replaceAll("%CRASHID", aCrashID.replaceAll("Crash-ID=","")));
        mpBugReportMailto->Show();
        mpEditPreUpload->Hide();
        mpEditPostUpload->Show();
        mpBtnSend->Hide();
        mpBtnSend->Disable();
        mpBtnCancel->Hide();
        mpBtnCancel->Disable();
        mpBtnClose->GrabFocus();

        setOptimalLayoutSize();
    }
    else if (pBtn == mpBtnCancel.get())
    {
        Close();
    }
    else if (pBtn == mpBtnClose.get())
    {
        Close();
    }
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */