/src/libreoffice/svtools/source/dialogs/restartdialog.cxx
Line | Count | Source |
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 <sal/config.h> |
11 | | |
12 | | #include <cassert> |
13 | | |
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> |
21 | | |
22 | | namespace { |
23 | | |
24 | | class RestartDialog : public weld::GenericDialogController{ |
25 | | public: |
26 | | RestartDialog(weld::Window* parent, svtools::RestartReason reason) |
27 | 0 | : GenericDialogController(parent, u"svt/ui/restartdialog.ui"_ustr, u"RestartDialog"_ustr) |
28 | 0 | , btnYes_(m_xBuilder->weld_button(u"yes"_ustr)) |
29 | 0 | , btnNo_(m_xBuilder->weld_button(u"no"_ustr)) |
30 | 0 | { |
31 | 0 | switch (reason) { |
32 | 0 | case svtools::RESTART_REASON_JAVA: |
33 | 0 | reason_ = m_xBuilder->weld_widget(u"reason_java"_ustr); |
34 | 0 | break; |
35 | 0 | case svtools::RESTART_REASON_BIBLIOGRAPHY_INSTALL: |
36 | 0 | reason_ = m_xBuilder->weld_widget(u"reason_bibliography_install"_ustr); |
37 | 0 | break; |
38 | 0 | case svtools::RESTART_REASON_MAILMERGE_INSTALL: |
39 | 0 | reason_ = m_xBuilder->weld_widget(u"reason_mailmerge_install"_ustr); |
40 | 0 | break; |
41 | 0 | case svtools::RESTART_REASON_LANGUAGE_CHANGE: |
42 | 0 | reason_ = m_xBuilder->weld_widget(u"reason_language_change"_ustr); |
43 | 0 | break; |
44 | 0 | case svtools::RESTART_REASON_ADDING_PATH: |
45 | 0 | reason_ = m_xBuilder->weld_widget(u"reason_adding_path"_ustr); |
46 | 0 | break; |
47 | 0 | case svtools::RESTART_REASON_ASSIGNING_JAVAPARAMETERS: |
48 | 0 | reason_ = m_xBuilder->weld_widget(u"reason_assigning_javaparameters"_ustr); |
49 | 0 | break; |
50 | 0 | case svtools::RESTART_REASON_ASSIGNING_FOLDERS: |
51 | 0 | reason_ = m_xBuilder->weld_widget(u"reason_assigning_folders"_ustr); |
52 | 0 | break; |
53 | 0 | case svtools::RESTART_REASON_EXP_FEATURES: |
54 | 0 | reason_ = m_xBuilder->weld_widget(u"reason_exp_features"_ustr); |
55 | 0 | break; |
56 | 0 | case svtools::RESTART_REASON_EXTENSION_INSTALL: |
57 | 0 | reason_ = m_xBuilder->weld_widget(u"reason_extension_install"_ustr); |
58 | 0 | break; |
59 | 0 | case svtools::RESTART_REASON_THEME_CHANGE: |
60 | 0 | reason_ = m_xBuilder->weld_widget(u"reason_theme_reload"_ustr); |
61 | 0 | break; |
62 | 0 | case svtools::RESTART_REASON_SKIA: |
63 | 0 | reason_ = m_xBuilder->weld_widget(u"reason_skia"_ustr); |
64 | 0 | break; |
65 | 0 | case svtools::RESTART_REASON_CALCULATION: |
66 | 0 | reason_ = m_xBuilder->weld_widget(u"reason_calculation"_ustr); |
67 | 0 | break; |
68 | 0 | case svtools::RESTART_REASON_UI_CHANGE: |
69 | 0 | reason_ = m_xBuilder->weld_widget(u"reason_uichange"_ustr); |
70 | 0 | break; |
71 | 0 | default: |
72 | 0 | assert(false); // this cannot happen |
73 | 0 | } |
74 | 0 | reason_->show(); |
75 | 0 | btnYes_->connect_clicked(LINK(this, RestartDialog, hdlYes)); |
76 | 0 | btnNo_->connect_clicked(LINK(this, RestartDialog, hdlNo)); |
77 | 0 | } |
78 | | private: |
79 | | DECL_LINK(hdlYes, weld::Button&, void); |
80 | | DECL_LINK(hdlNo, weld::Button&, void); |
81 | | |
82 | | std::unique_ptr<weld::Widget> reason_; |
83 | | std::unique_ptr<weld::Button> btnYes_; |
84 | | std::unique_ptr<weld::Button> btnNo_; |
85 | | }; |
86 | | |
87 | | IMPL_LINK_NOARG(RestartDialog, hdlYes, weld::Button&, void) |
88 | 0 | { |
89 | 0 | m_xDialog->response(RET_OK); |
90 | 0 | } |
91 | | |
92 | | IMPL_LINK_NOARG(RestartDialog, hdlNo, weld::Button&, void) |
93 | 0 | { |
94 | 0 | m_xDialog->response(RET_CANCEL); |
95 | 0 | } |
96 | | |
97 | | } |
98 | | |
99 | | bool svtools::executeRestartDialog( |
100 | | css::uno::Reference< css::uno::XComponentContext > const & context, |
101 | | weld::Window* parent, RestartReason reason) |
102 | 0 | { |
103 | 0 | auto xRestartManager = css::task::OfficeRestartManager::get(context); |
104 | 0 | if (xRestartManager->isRestartRequested(false)) |
105 | 0 | return true; // don't try to show another dialog when restart is already in progress |
106 | 0 | RestartDialog aDlg(parent, reason); |
107 | 0 | if (aDlg.run()) { |
108 | 0 | xRestartManager->requestRestart( |
109 | 0 | css::uno::Reference< css::task::XInteractionHandler >()); |
110 | 0 | return true; |
111 | 0 | } |
112 | 0 | return false; |
113 | 0 | } |
114 | | |
115 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |