LibreOffice Module desktop (master)  1
license_dialog.cxx
Go to the documentation of this file.
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  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 
22 #include <unotools/configmgr.hxx>
24 #include <i18nlangtag/mslangid.hxx>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <svl/lstner.hxx>
28 #include <vcl/event.hxx>
29 #include <vcl/idle.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/threadex.hxx>
32 #include <vcl/weld.hxx>
33 
34 #include "license_dialog.hxx"
35 
36 #include <functional>
37 
38 using namespace ::dp_misc;
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::uno;
41 
42 namespace dp_gui {
43 
45 {
49 
50  std::unique_ptr<weld::Label> m_xFtHead;
51  std::unique_ptr<weld::Widget> m_xArrow1;
52  std::unique_ptr<weld::Widget> m_xArrow2;
53  std::unique_ptr<weld::TextView> m_xLicense;
54  std::unique_ptr<weld::Button> m_xDown;
55  std::unique_ptr<weld::Button> m_xAcceptButton;
56  std::unique_ptr<weld::Button> m_xDeclineButton;
57 
58  void PageDown();
59  DECL_LINK(ScrollTimerHdl, Timer*, void);
60  DECL_LINK(ScrolledHdl, weld::TextView&, void);
61  DECL_LINK(ResizedHdl, Timer*, void);
62  DECL_LINK(CancelHdl, weld::Button&, void);
63  DECL_LINK(AcceptHdl, weld::Button&, void);
64  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
65  DECL_STATIC_LINK(LicenseDialogImpl, KeyReleaseHdl, const KeyEvent&, bool);
66  DECL_LINK(MousePressHdl, const MouseEvent&, bool);
67  DECL_LINK(MouseReleaseHdl, const MouseEvent&, bool);
68  DECL_LINK(SizeAllocHdl, const Size&, void);
69 
71  const OUString & sExtensionName,
72  const OUString & sLicenseText);
73 
74  bool IsEndReached() const;
75 };
76 
78  weld::Window * pParent,
79  const OUString & sExtensionName,
80  const OUString & sLicenseText)
81  : GenericDialogController(pParent, "desktop/ui/licensedialog.ui", "LicenseDialog")
82  , m_bLicenseRead(false)
83  , m_xFtHead(m_xBuilder->weld_label("head"))
84  , m_xArrow1(m_xBuilder->weld_widget("arrow1"))
85  , m_xArrow2(m_xBuilder->weld_widget("arrow2"))
86  , m_xLicense(m_xBuilder->weld_text_view("textview"))
87  , m_xDown(m_xBuilder->weld_button("down"))
88  , m_xAcceptButton(m_xBuilder->weld_button("ok"))
89  , m_xDeclineButton(m_xBuilder->weld_button("cancel"))
90 {
91  m_xArrow1->show();
92  m_xArrow2->hide();
93 
94  m_xLicense->connect_size_allocate(LINK(this, LicenseDialogImpl, SizeAllocHdl));
95  m_xLicense->set_size_request(m_xLicense->get_approximate_digit_width() * 72,
96  m_xLicense->get_height_rows(21));
97 
98  m_xLicense->set_text(sLicenseText);
99  m_xFtHead->set_label(m_xFtHead->get_label() + "\n" + sExtensionName);
100 
101  m_xAcceptButton->connect_clicked( LINK(this, LicenseDialogImpl, AcceptHdl) );
102  m_xDeclineButton->connect_clicked( LINK(this, LicenseDialogImpl, CancelHdl) );
103 
104  m_xLicense->connect_vadjustment_changed(LINK(this, LicenseDialogImpl, ScrolledHdl));
105  m_xDown->connect_mouse_press(LINK(this, LicenseDialogImpl, MousePressHdl));
106  m_xDown->connect_mouse_release(LINK(this, LicenseDialogImpl, MouseReleaseHdl));
107  m_xDown->connect_key_press(LINK(this, LicenseDialogImpl, KeyInputHdl));
108  m_xDown->connect_key_release(LINK(this, LicenseDialogImpl, KeyReleaseHdl));
109 
110  m_aRepeat.SetTimeout(Application::GetSettings().GetMouseSettings().GetButtonRepeat());
111  m_aRepeat.SetInvokeHandler(LINK(this, LicenseDialogImpl, ScrollTimerHdl));
112 
113  m_aResized.SetPriority(TaskPriority::LOWEST);
115 }
116 
117 IMPL_LINK_NOARG(LicenseDialogImpl, SizeAllocHdl, const Size&, void)
118 {
119  m_aResized.Start();
120 }
121 
123 {
124  m_xDialog->response(RET_OK);
125 }
126 
128 {
129  m_xDialog->response(RET_CANCEL);
130 }
131 
133 {
134  return m_xLicense->vadjustment_get_value() + m_xLicense->vadjustment_get_page_size() >= m_xLicense->vadjustment_get_upper();
135 }
136 
138 {
139  if (IsEndReached())
140  {
141  m_xDown->set_sensitive(false);
142  m_aRepeat.Stop();
143 
144  if (!m_bLicenseRead)
145  {
146  m_xAcceptButton->set_sensitive(true);
147  m_xAcceptButton->grab_focus();
148  m_xArrow1->hide();
149  m_xArrow2->show();
150  m_bLicenseRead = true;
151  }
152  }
153  else
154  m_xDown->set_sensitive(true);
155 }
156 
158 {
159  m_xLicense->vadjustment_set_value(m_xLicense->vadjustment_get_value() +
160  m_xLicense->vadjustment_get_page_size());
161  ScrolledHdl(*m_xLicense);
162 }
163 
164 IMPL_LINK(LicenseDialogImpl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
165 {
166  vcl::KeyCode aKeyCode = rKEvt.GetKeyCode();
167  if (aKeyCode.GetCode() == KEY_RETURN || aKeyCode.GetCode() == KEY_SPACE)
168  PageDown();
169  return false;
170 }
171 
173 {
174  ScrolledHdl(*m_xLicense);
175 }
176 
177 IMPL_LINK_NOARG(LicenseDialogImpl, ScrollTimerHdl, Timer*, void)
178 {
179  PageDown();
180 }
181 
182 IMPL_STATIC_LINK_NOARG(LicenseDialogImpl, KeyReleaseHdl, const KeyEvent&, bool)
183 {
184  return false;
185 }
186 
187 IMPL_LINK_NOARG(LicenseDialogImpl, MousePressHdl, const MouseEvent&, bool)
188 {
189  PageDown();
190  m_aRepeat.Start();
191  return false;
192 }
193 
194 IMPL_LINK_NOARG(LicenseDialogImpl, MouseReleaseHdl, const MouseEvent&, bool)
195 {
196  m_aRepeat.Stop();
197  return false;
198 }
199 
200 LicenseDialog::LicenseDialog( Sequence<Any> const& args,
202 {
204 }
205 
206 // XExecutableDialog
207 
208 void LicenseDialog::setTitle( OUString const & )
209 {
210 }
211 
213 {
215  std::bind(&LicenseDialog::solar_execute, this));
216 }
217 
219 {
221  return dlg.run();
222 }
223 
224 } // namespace dp_gui
225 
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Button > m_xDown
#define KEY_SPACE
LicenseDialogImpl(weld::Window *pParent, const OUString &sExtensionName, const OUString &sLicenseText)
virtual void SAL_CALL setTitle(OUString const &title) override
static const AllSettings & GetSettings()
std::unique_ptr< weld::Button > m_xDeclineButton
sal_uInt16 GetCode() const
RET_CANCEL
IMPL_LINK_NOARG(ExtMgrDialog, HandleCancelBtn, weld::Button &, void)
std::unique_ptr< weld::Widget > m_xArrow2
DECL_STATIC_LINK(LicenseDialogImpl, KeyReleaseHdl, const KeyEvent &, bool)
std::unique_ptr< weld::Label > m_xFtHead
virtual sal_Int16 SAL_CALL execute() override
css::uno::Reference< css::awt::XWindow > m_parent
DECL_LINK(ScrollTimerHdl, Timer *, void)
std::unique_ptr< weld::Button > m_xAcceptButton
static weld::Window * GetFrameWeld(const css::uno::Reference< css::awt::XWindow > &rWindow)
std::unique_ptr< weld::Widget > m_xArrow1
void SetTimeout(sal_uInt64 nTimeoutMs)
std::unique_ptr< weld::TextView > m_xLicense
IMPL_STATIC_LINK_NOARG(LicenseDialogImpl, KeyReleaseHdl, const KeyEvent &, bool)
LicenseDialog(css::uno::Sequence< css::uno::Any > const &args, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)
#define KEY_RETURN
RET_OK
virtual short run()
auto syncExecute(FuncT const &func) -> decltype(func())
void SetInvokeHandler(const Link< Timer *, void > &rLink)
void unwrapArgs(const css::uno::Sequence< css::uno::Any > &seq, Args &...args)
void SetPriority(TaskPriority ePriority)
Definition: dp_gui.h:50
IMPL_LINK(ExtMgrDialog, startProgress, void *, _bLockInterface, void)