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 <sal/config.h>
14 #include <com/sun/star/task/OfficeRestartManager.hpp>
15 #include <com/sun/star/task/XInteractionHandler.hpp>
16 #include <com/sun/star/uno/Reference.hxx>
17 #include <com/sun/star/uno/XComponentContext.hpp>
18 #include <svtools/restartdialog.hxx>
19 #include <tools/link.hxx>
20 #include <vcl/weld.hxx>
24 class RestartDialog
: public weld::GenericDialogController
{
26 RestartDialog(weld::Window
* parent
, svtools::RestartReason reason
)
27 : GenericDialogController(parent
, u
"svt/ui/restartdialog.ui"_ustr
, u
"RestartDialog"_ustr
)
28 , btnYes_(m_xBuilder
->weld_button(u
"yes"_ustr
))
29 , btnNo_(m_xBuilder
->weld_button(u
"no"_ustr
))
32 case svtools::RESTART_REASON_JAVA
:
33 reason_
= m_xBuilder
->weld_widget(u
"reason_java"_ustr
);
35 case svtools::RESTART_REASON_BIBLIOGRAPHY_INSTALL
:
36 reason_
= m_xBuilder
->weld_widget(u
"reason_bibliography_install"_ustr
);
38 case svtools::RESTART_REASON_MAILMERGE_INSTALL
:
39 reason_
= m_xBuilder
->weld_widget(u
"reason_mailmerge_install"_ustr
);
41 case svtools::RESTART_REASON_LANGUAGE_CHANGE
:
42 reason_
= m_xBuilder
->weld_widget(u
"reason_language_change"_ustr
);
44 case svtools::RESTART_REASON_ADDING_PATH
:
45 reason_
= m_xBuilder
->weld_widget(u
"reason_adding_path"_ustr
);
47 case svtools::RESTART_REASON_ASSIGNING_JAVAPARAMETERS
:
48 reason_
= m_xBuilder
->weld_widget(u
"reason_assigning_javaparameters"_ustr
);
50 case svtools::RESTART_REASON_ASSIGNING_FOLDERS
:
51 reason_
= m_xBuilder
->weld_widget(u
"reason_assigning_folders"_ustr
);
53 case svtools::RESTART_REASON_EXP_FEATURES
:
54 reason_
= m_xBuilder
->weld_widget(u
"reason_exp_features"_ustr
);
56 case svtools::RESTART_REASON_EXTENSION_INSTALL
:
57 reason_
= m_xBuilder
->weld_widget(u
"reason_extension_install"_ustr
);
59 case svtools::RESTART_REASON_THEME_CHANGE
:
60 reason_
= m_xBuilder
->weld_widget(u
"reason_theme_reload"_ustr
);
62 case svtools::RESTART_REASON_SKIA
:
63 reason_
= m_xBuilder
->weld_widget(u
"reason_skia"_ustr
);
65 case svtools::RESTART_REASON_OPENCL
:
66 reason_
= m_xBuilder
->weld_widget(u
"reason_opencl"_ustr
);
68 case svtools::RESTART_REASON_THREADING
:
69 reason_
= m_xBuilder
->weld_widget(u
"reason_threading"_ustr
);
71 case svtools::RESTART_REASON_UI_CHANGE
:
72 reason_
= m_xBuilder
->weld_widget(u
"reason_uichange"_ustr
);
75 assert(false); // this cannot happen
78 btnYes_
->connect_clicked(LINK(this, RestartDialog
, hdlYes
));
79 btnNo_
->connect_clicked(LINK(this, RestartDialog
, hdlNo
));
82 DECL_LINK(hdlYes
, weld::Button
&, void);
83 DECL_LINK(hdlNo
, weld::Button
&, void);
85 std::unique_ptr
<weld::Widget
> reason_
;
86 std::unique_ptr
<weld::Button
> btnYes_
;
87 std::unique_ptr
<weld::Button
> btnNo_
;
90 IMPL_LINK_NOARG(RestartDialog
, hdlYes
, weld::Button
&, void)
92 m_xDialog
->response(RET_OK
);
95 IMPL_LINK_NOARG(RestartDialog
, hdlNo
, weld::Button
&, void)
97 m_xDialog
->response(RET_CANCEL
);
102 bool svtools::executeRestartDialog(
103 css::uno::Reference
< css::uno::XComponentContext
> const & context
,
104 weld::Window
* parent
, RestartReason reason
)
106 auto xRestartManager
= css::task::OfficeRestartManager::get(context
);
107 if (xRestartManager
->isRestartRequested(false))
108 return true; // don't try to show another dialog when restart is already in progress
109 RestartDialog
aDlg(parent
, reason
);
111 xRestartManager
->requestRestart(
112 css::uno::Reference
< css::task::XInteractionHandler
>());
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */