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 #undef SC_DLLIMPLEMENTATION
21 
22 #include <dapitype.hxx>
23 #include <comphelper/lok.hxx>
24 
25 using namespace com::sun::star;
26 
ScDataPilotSourceTypeDlg(weld::Window * pParent,bool bEnableExternal)27 ScDataPilotSourceTypeDlg::ScDataPilotSourceTypeDlg(weld::Window* pParent, bool bEnableExternal)
28     : GenericDialogController(pParent, "modules/scalc/ui/selectsource.ui", "SelectSourceDialog")
29     , m_xBtnSelection(m_xBuilder->weld_radio_button("selection"))
30     , m_xBtnNamedRange(m_xBuilder->weld_radio_button("namedrange"))
31     , m_xBtnDatabase(m_xBuilder->weld_radio_button("database"))
32     , m_xBtnExternal(m_xBuilder->weld_radio_button("external"))
33     , m_xLbNamedRange(m_xBuilder->weld_combo_box("rangelb"))
34     , m_xBtnOk(m_xBuilder->weld_button("ok")) // for LOK jsdialog
35     , m_xBtnCancel(m_xBuilder->weld_button("cancel")) // for LOK jsdialog
36 {
37     m_xBtnSelection->connect_toggled( LINK(this, ScDataPilotSourceTypeDlg, RadioClickHdl) );
38     m_xBtnNamedRange->connect_toggled( LINK(this, ScDataPilotSourceTypeDlg, RadioClickHdl) );
39     m_xBtnDatabase->connect_toggled( LINK(this, ScDataPilotSourceTypeDlg, RadioClickHdl) );
40     m_xBtnExternal->connect_toggled( LINK(this, ScDataPilotSourceTypeDlg, RadioClickHdl) );
41 
42     m_xBtnOk->connect_clicked( LINK(this, ScDataPilotSourceTypeDlg, ResponseHdl ) );
43     m_xBtnCancel->connect_clicked( LINK(this, ScDataPilotSourceTypeDlg, ResponseHdl ) );
44 
45     if (!bEnableExternal)
46         m_xBtnExternal->set_sensitive(false);
47 
48     m_xBtnSelection->set_active(true);
49 
50     // Disabled unless at least one named range exists.
51     m_xLbNamedRange->set_sensitive(false);
52     m_xBtnNamedRange->set_sensitive(false);
53 
54     // Intentionally hide this button to see if anyone complains.
55     m_xBtnExternal->hide();
56 
57     if (comphelper::LibreOfficeKit::isActive())
58         m_xBtnDatabase->hide();
59 }
60 
IMPL_LINK(ScDataPilotSourceTypeDlg,ResponseHdl,weld::Button &,rButton,void)61 IMPL_LINK(ScDataPilotSourceTypeDlg, ResponseHdl, weld::Button&, rButton, void)
62 {
63     if (&rButton == m_xBtnOk.get())
64         m_xDialog->response(RET_OK);
65     else
66         m_xDialog->response(RET_CANCEL);
67 }
68 
~ScDataPilotSourceTypeDlg()69 ScDataPilotSourceTypeDlg::~ScDataPilotSourceTypeDlg()
70 {
71 }
72 
IsDatabase() const73 bool ScDataPilotSourceTypeDlg::IsDatabase() const
74 {
75     return m_xBtnDatabase->get_active();
76 }
77 
IsExternal() const78 bool ScDataPilotSourceTypeDlg::IsExternal() const
79 {
80     return m_xBtnExternal->get_active();
81 }
82 
IsNamedRange() const83 bool ScDataPilotSourceTypeDlg::IsNamedRange() const
84 {
85     return m_xBtnNamedRange->get_active();
86 }
87 
GetSelectedNamedRange() const88 OUString ScDataPilotSourceTypeDlg::GetSelectedNamedRange() const
89 {
90     return m_xLbNamedRange->get_active_text();
91 }
92 
AppendNamedRange(const OUString & rName)93 void ScDataPilotSourceTypeDlg::AppendNamedRange(const OUString& rName)
94 {
95     m_xLbNamedRange->append_text(rName);
96     if (m_xLbNamedRange->get_count() == 1)
97     {
98         // Select position 0 only for the first time.
99         m_xLbNamedRange->set_active(0);
100         m_xBtnNamedRange->set_sensitive(true);
101     }
102 }
103 
IMPL_LINK_NOARG(ScDataPilotSourceTypeDlg,RadioClickHdl,weld::Toggleable &,void)104 IMPL_LINK_NOARG(ScDataPilotSourceTypeDlg, RadioClickHdl, weld::Toggleable&, void)
105 {
106     m_xLbNamedRange->set_sensitive(m_xBtnNamedRange->get_active());
107 }
108 
ScDataPilotServiceDlg(weld::Window * pParent,const std::vector<OUString> & rServices)109 ScDataPilotServiceDlg::ScDataPilotServiceDlg(weld::Window* pParent, const std::vector<OUString>& rServices)
110     : GenericDialogController(pParent, "modules/scalc/ui/dapiservicedialog.ui", "DapiserviceDialog")
111     , m_xLbService(m_xBuilder->weld_combo_box("service"))
112     , m_xEdSource(m_xBuilder->weld_entry("source"))
113     , m_xEdName(m_xBuilder->weld_entry("name"))
114     , m_xEdUser(m_xBuilder->weld_entry("user"))
115     , m_xEdPasswd(m_xBuilder->weld_entry("password"))
116 {
117     for (const OUString& aName : rServices)
118     {
119         m_xLbService->append_text(aName);
120     }
121     m_xLbService->set_active(0);
122 }
123 
~ScDataPilotServiceDlg()124 ScDataPilotServiceDlg::~ScDataPilotServiceDlg()
125 {
126 }
127 
GetServiceName() const128 OUString ScDataPilotServiceDlg::GetServiceName() const
129 {
130     return m_xLbService->get_active_text();
131 }
132 
GetParSource() const133 OUString ScDataPilotServiceDlg::GetParSource() const
134 {
135     return m_xEdSource->get_text();
136 }
137 
GetParName() const138 OUString ScDataPilotServiceDlg::GetParName() const
139 {
140     return m_xEdName->get_text();
141 }
142 
GetParUser() const143 OUString ScDataPilotServiceDlg::GetParUser() const
144 {
145     return m_xEdUser->get_text();
146 }
147 
GetParPass() const148 OUString ScDataPilotServiceDlg::GetParPass() const
149 {
150     return m_xEdPasswd->get_text();
151 }
152 
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
154