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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "admincontrols.hxx"
21 #include <dsitems.hxx>
23 #include <svl/eitem.hxx>
24 #include <svl/stritem.hxx>
25 #include <svl/intitem.hxx>
26 #include <vcl/svapp.hxx>
31 // MySQLNativeSettings
32 MySQLNativeSettings::MySQLNativeSettings(weld::Widget
* pParent
, const Link
<weld::Widget
*,void>& rControlModificationLink
)
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
)
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
) );
58 // sockets are available on Unix systems only, named pipes only on Windows
60 m_xNamedPipeRadio
->hide();
63 m_xSocketRadio
->hide();
69 IMPL_LINK(MySQLNativeSettings
, RadioToggleHdl
, weld::Toggleable
&, rRadioButton
, void)
71 m_aControlModificationLink
.Call(&rRadioButton
);
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
);
80 m_xSocket
->set_sensitive(m_xSocketRadio
->get_active());
81 m_xNamedPipe
->set_sensitive(m_xNamedPipeRadio
->get_active());
84 IMPL_LINK(MySQLNativeSettings
, EditModifyHdl
, weld::Entry
&, rEdit
, void)
86 m_aControlModificationLink
.Call(&rEdit
);
89 IMPL_LINK(MySQLNativeSettings
, SpinModifyHdl
, weld::SpinButton
&, rEdit
, void)
91 m_aControlModificationLink
.Call(&rEdit
);
94 void MySQLNativeSettings::fillControls( std::vector
< std::unique_ptr
<ISaveValueWrapper
> >& _rControlList
)
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()));
103 void MySQLNativeSettings::fillWindows( std::vector
< std::unique_ptr
<ISaveValueWrapper
> >& _rControlList
)
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() ) );
113 bool MySQLNativeSettings::FillItemSet( SfxItemSet
* _rSet
)
115 bool bChangedSomething
= false;
117 OGenericAdministrationPage::fillString( *_rSet
, m_xHostName
.get(), DSID_CONN_HOSTNAME
, bChangedSomething
);
118 OGenericAdministrationPage::fillString( *_rSet
, m_xDatabaseName
.get(), DSID_DATABASENAME
, bChangedSomething
);
119 OGenericAdministrationPage::fillInt32 ( *_rSet
, m_xPort
.get(), DSID_MYSQL_PORTNUMBER
, bChangedSomething
);
121 OGenericAdministrationPage::fillString( *_rSet
, m_xSocket
.get(), DSID_CONN_SOCKET
, bChangedSomething
);
123 OGenericAdministrationPage::fillString( *_rSet
, m_xNamedPipe
.get(), DSID_NAMED_PIPE
, bChangedSomething
);
126 return bChangedSomething
;
129 void MySQLNativeSettings::implInitControls(const SfxItemSet
& _rSet
)
131 const SfxBoolItem
* pInvalid
= _rSet
.GetItem
<SfxBoolItem
>(DSID_INVALID_SELECTION
);
132 bool bValid
= !pInvalid
|| !pInvalid
->GetValue();
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
);
142 m_xDatabaseName
->set_text( pDatabaseName
->GetValue() );
143 m_xDatabaseName
->save_value();
145 m_xHostName
->set_text( pHostName
->GetValue() );
146 m_xHostName
->save_value();
148 m_xPort
->set_value( pPortNumber
->GetValue() );
149 m_xPort
->save_value();
151 m_xSocket
->set_text( pSocket
->GetValue() );
152 m_xSocket
->save_value();
154 m_xNamedPipe
->set_text( pNamedPipe
->GetValue() );
155 m_xNamedPipe
->save_value();
157 // if a socket (on Unix) or a pipe name (on Windows) is given, this is preferred over
160 weld::RadioButton
& rSocketPipeRadio
= *m_xSocketRadio
;
161 const SfxStringItem
* pSocketPipeItem
= pSocket
;
163 weld::RadioButton
& rSocketPipeRadio
= *m_xNamedPipeRadio
;
164 const SfxStringItem
* pSocketPipeItem
= pNamedPipe
;
166 const OUString
& rSocketPipe( pSocketPipeItem
->GetValue() );
167 if (!rSocketPipe
.isEmpty())
168 rSocketPipeRadio
.set_active(true);
170 m_xHostPortRadio
->set_active(true);
173 bool MySQLNativeSettings::canAdvance() const
175 if (m_xDatabaseName
->get_text().isEmpty())
178 if ( m_xHostPortRadio
->get_active()
179 && ( ( m_xHostName
->get_text().isEmpty() )
180 || ( m_xPort
->get_text().isEmpty() )
186 if ( ( m_xSocketRadio
->get_active() )
187 && ( m_xSocket
->get_text().isEmpty() )
190 if ( ( m_xNamedPipeRadio
->get_active() )
191 && ( m_xNamedPipe
->get_text().isEmpty() )
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */