LibreOffice Module dbaccess (master) 1
admincontrols.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#include "admincontrols.hxx"
21#include <dsitems.hxx>
22
23#include <svl/eitem.hxx>
24#include <svl/stritem.hxx>
25#include <svl/intitem.hxx>
26#include <vcl/svapp.hxx>
27
28namespace dbaui
29{
30
31 // MySQLNativeSettings
33 : m_xBuilder(Application::CreateBuilder(pParent, "dbaccess/ui/mysqlnativesettings.ui"))
34 , m_xContainer(m_xBuilder->weld_widget("MysqlNativeSettings"))
35 , m_xDatabaseNameLabel(m_xBuilder->weld_label("dbnamelabel"))
36 , m_xDatabaseName(m_xBuilder->weld_entry("dbname"))
37 , m_xHostPortRadio(m_xBuilder->weld_radio_button("hostport"))
38 , m_xSocketRadio(m_xBuilder->weld_radio_button("socketlabel"))
39 , m_xNamedPipeRadio(m_xBuilder->weld_radio_button("namedpipelabel"))
40 , m_xHostNameLabel(m_xBuilder->weld_label("serverlabel"))
41 , m_xHostName(m_xBuilder->weld_entry("server"))
42 , m_xPortLabel(m_xBuilder->weld_label("portlabel"))
43 , m_xPort(m_xBuilder->weld_spin_button("port"))
44 , m_xDefaultPort(m_xBuilder->weld_label("defaultport"))
45 , m_xSocket(m_xBuilder->weld_entry("socket"))
46 , m_xNamedPipe(m_xBuilder->weld_entry("namedpipe"))
47 , m_aControlModificationLink(rControlModificationLink)
48 {
49 m_xDatabaseName->connect_changed( LINK(this, MySQLNativeSettings, EditModifyHdl) );
50 m_xHostName->connect_changed( LINK(this, MySQLNativeSettings, EditModifyHdl) );
51 m_xPort->connect_value_changed( LINK(this, MySQLNativeSettings, SpinModifyHdl) );
52 m_xSocket->connect_changed( LINK(this, MySQLNativeSettings, EditModifyHdl) );
53 m_xNamedPipe->connect_changed( LINK(this, MySQLNativeSettings, EditModifyHdl) );
54 m_xSocketRadio->connect_toggled( LINK(this, MySQLNativeSettings, RadioToggleHdl) );
55 m_xNamedPipeRadio->connect_toggled( LINK(this, MySQLNativeSettings, RadioToggleHdl) );
56 m_xHostPortRadio->connect_toggled( LINK(this, MySQLNativeSettings, RadioToggleHdl) );
57
58 // sockets are available on Unix systems only, named pipes only on Windows
59#ifdef UNX
60 m_xNamedPipeRadio->hide();
61 m_xNamedPipe->hide();
62#else
63 m_xSocketRadio->hide();
64 m_xSocket->hide();
65#endif
66 m_xContainer->show();
67 }
68
69 IMPL_LINK(MySQLNativeSettings, RadioToggleHdl, weld::Toggleable&, rRadioButton, void)
70 {
71 m_aControlModificationLink.Call(&rRadioButton);
72
73 const bool bHostPortRadio = m_xHostPortRadio->get_active();
74 m_xHostNameLabel->set_sensitive(bHostPortRadio);
75 m_xHostName->set_sensitive(bHostPortRadio);
76 m_xPortLabel->set_sensitive(bHostPortRadio);
77 m_xPort->set_sensitive(bHostPortRadio);
78 m_xDefaultPort->set_sensitive(bHostPortRadio);
79
80 m_xSocket->set_sensitive(m_xSocketRadio->get_active());
81 m_xNamedPipe->set_sensitive(m_xNamedPipeRadio->get_active());
82 }
83
84 IMPL_LINK(MySQLNativeSettings, EditModifyHdl, weld::Entry&, rEdit, void)
85 {
86 m_aControlModificationLink.Call(&rEdit);
87 }
88
89 IMPL_LINK(MySQLNativeSettings, SpinModifyHdl, weld::SpinButton&, rEdit, void)
90 {
91 m_aControlModificationLink.Call(&rEdit);
92 }
93
94 void MySQLNativeSettings::fillControls( std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList )
95 {
96 _rControlList.emplace_back(new OSaveValueWidgetWrapper<weld::Entry>(m_xDatabaseName.get()));
97 _rControlList.emplace_back(new OSaveValueWidgetWrapper<weld::Entry>(m_xHostName.get()));
98 _rControlList.emplace_back(new OSaveValueWidgetWrapper<weld::Entry>(m_xPort.get()));
99 _rControlList.emplace_back(new OSaveValueWidgetWrapper<weld::Entry>(m_xSocket.get()));
100 _rControlList.emplace_back(new OSaveValueWidgetWrapper<weld::Entry>(m_xNamedPipe.get()));
101 }
102
103 void MySQLNativeSettings::fillWindows( std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList )
104 {
105 _rControlList.emplace_back( new ODisableWidgetWrapper<weld::Label>( m_xDatabaseNameLabel.get() ) );
106 _rControlList.emplace_back( new ODisableWidgetWrapper<weld::Label>( m_xHostNameLabel.get() ) );
107 _rControlList.emplace_back( new ODisableWidgetWrapper<weld::Label>( m_xPortLabel.get() ) );
108 _rControlList.emplace_back( new ODisableWidgetWrapper<weld::Label>( m_xDefaultPort.get() ) );
109 _rControlList.emplace_back( new ODisableWidgetWrapper<weld::RadioButton>( m_xSocketRadio.get() ) );
110 _rControlList.emplace_back( new ODisableWidgetWrapper<weld::RadioButton>( m_xNamedPipeRadio.get() ) );
111 }
112
114 {
115 bool bChangedSomething = false;
116
117 OGenericAdministrationPage::fillString( *_rSet, m_xHostName.get(), DSID_CONN_HOSTNAME, bChangedSomething );
119 OGenericAdministrationPage::fillInt32 ( *_rSet, m_xPort.get(), DSID_MYSQL_PORTNUMBER, bChangedSomething );
120#ifdef UNX
121 OGenericAdministrationPage::fillString( *_rSet, m_xSocket.get(), DSID_CONN_SOCKET, bChangedSomething );
122#else
123 OGenericAdministrationPage::fillString( *_rSet, m_xNamedPipe.get(), DSID_NAMED_PIPE, bChangedSomething );
124#endif
125
126 return bChangedSomething;
127 }
128
130 {
131 const SfxBoolItem* pInvalid = _rSet.GetItem<SfxBoolItem>(DSID_INVALID_SELECTION);
132 bool bValid = !pInvalid || !pInvalid->GetValue();
133 if ( !bValid )
134 return;
135
136 const SfxStringItem* pDatabaseName = _rSet.GetItem<SfxStringItem>(DSID_DATABASENAME);
137 const SfxStringItem* pHostName = _rSet.GetItem<SfxStringItem>(DSID_CONN_HOSTNAME);
138 const SfxInt32Item* pPortNumber = _rSet.GetItem<SfxInt32Item>(DSID_MYSQL_PORTNUMBER);
139 const SfxStringItem* pSocket = _rSet.GetItem<SfxStringItem>(DSID_CONN_SOCKET);
140 const SfxStringItem* pNamedPipe = _rSet.GetItem<SfxStringItem>(DSID_NAMED_PIPE);
141
142 m_xDatabaseName->set_text( pDatabaseName->GetValue() );
143 m_xDatabaseName->save_value();
144
145 m_xHostName->set_text( pHostName->GetValue() );
146 m_xHostName->save_value();
147
148 m_xPort->set_value( pPortNumber->GetValue() );
149 m_xPort->save_value();
150
151 m_xSocket->set_text( pSocket->GetValue() );
152 m_xSocket->save_value();
153
154 m_xNamedPipe->set_text( pNamedPipe->GetValue() );
155 m_xNamedPipe->save_value();
156
157 // if a socket (on Unix) or a pipe name (on Windows) is given, this is preferred over
158 // the port
159#ifdef UNX
160 weld::RadioButton& rSocketPipeRadio = *m_xSocketRadio;
161 const SfxStringItem* pSocketPipeItem = pSocket;
162#else
163 weld::RadioButton& rSocketPipeRadio = *m_xNamedPipeRadio;
164 const SfxStringItem* pSocketPipeItem = pNamedPipe;
165#endif
166 const OUString& rSocketPipe( pSocketPipeItem->GetValue() );
167 if (!rSocketPipe.isEmpty())
168 rSocketPipeRadio.set_active(true);
169 else
170 m_xHostPortRadio->set_active(true);
171 }
172
174 {
175 if (m_xDatabaseName->get_text().isEmpty())
176 return false;
177
178 if ( m_xHostPortRadio->get_active()
179 && ( ( m_xHostName->get_text().isEmpty() )
180 || ( m_xPort->get_text().isEmpty() )
181 )
182 )
183 return false;
184
185#ifdef UNX
186 if ( ( m_xSocketRadio->get_active() )
187 && ( m_xSocket->get_text().isEmpty() )
188 )
189#else
190 if ( ( m_xNamedPipeRadio->get_active() )
191 && ( m_xNamedPipe->get_text().isEmpty() )
192 )
193#endif
194 return false;
195
196 return true;
197 }
198
199} // namespace dbaui
200
201/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const OUString & GetValue() const
bool GetValue() const
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
std::unique_ptr< weld::SpinButton > m_xPort
std::unique_ptr< weld::Label > m_xDatabaseNameLabel
std::unique_ptr< weld::Widget > m_xContainer
std::unique_ptr< weld::RadioButton > m_xNamedPipeRadio
void fillControls(std::vector< std::unique_ptr< ISaveValueWrapper > > &_rControlList)
MySQLNativeSettings(weld::Widget *pParent, const Link< weld::Widget *, void > &rControlModificationLink)
std::unique_ptr< weld::Entry > m_xDatabaseName
std::unique_ptr< weld::Entry > m_xHostName
std::unique_ptr< weld::Label > m_xHostNameLabel
std::unique_ptr< weld::Entry > m_xSocket
std::unique_ptr< weld::Label > m_xPortLabel
std::unique_ptr< weld::Entry > m_xNamedPipe
bool FillItemSet(SfxItemSet *rCoreAttrs)
std::unique_ptr< weld::RadioButton > m_xHostPortRadio
std::unique_ptr< weld::RadioButton > m_xSocketRadio
void fillWindows(std::vector< std::unique_ptr< ISaveValueWrapper > > &_rControlList)
void implInitControls(const SfxItemSet &_rSet)
std::unique_ptr< weld::Label > m_xDefaultPort
static void fillString(SfxItemSet &_rSet, const weld::Entry *pEdit, TypedWhichId< SfxStringItem > _nID, bool &_bChangedSomething)
fills the String value into the item set when the value changed.
Definition: adminpages.cxx:219
static void fillInt32(SfxItemSet &_rSet, const weld::SpinButton *pEdit, TypedWhichId< SfxInt32Item > _nID, bool &_bChangedSomething)
fills the int value into the item set when the value changed.
Definition: adminpages.cxx:211
virtual void set_active(bool active)=0
#define DSID_DATABASENAME
Definition: dsitems.hxx:84
#define DSID_INVALID_SELECTION
Definition: dsitems.hxx:39
#define DSID_CONN_SOCKET
Definition: dsitems.hxx:88
#define DSID_CONN_HOSTNAME
Definition: dsitems.hxx:64
#define DSID_NAMED_PIPE
Definition: dsitems.hxx:90
#define DSID_MYSQL_PORTNUMBER
Definition: dsitems.hxx:73
IMPL_LINK(OApplicationController, OnSelectContainer, void *, _pType, void)
Reference< XNameAccess > m_xContainer
Definition: objectnames.cxx:80