android: Update app icon to new startcenter icon
[LibreOffice.git] / dbaccess / source / ui / dlg / admincontrols.cxx
blobde515f9e3777f2a41f0daba63cd9cfb98e342089
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
28 namespace dbaui
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
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();
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 );
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
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();
133 if ( !bValid )
134 return;
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
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);
173 bool MySQLNativeSettings::canAdvance() const
175 if (m_xDatabaseName->get_text().isEmpty())
176 return false;
178 if ( m_xHostPortRadio->get_active()
179 && ( ( m_xHostName->get_text().isEmpty() )
180 || ( m_xPort->get_text().isEmpty() )
183 return false;
185 #ifdef UNX
186 if ( ( m_xSocketRadio->get_active() )
187 && ( m_xSocket->get_text().isEmpty() )
189 #else
190 if ( ( m_xNamedPipeRadio->get_active() )
191 && ( m_xNamedPipe->get_text().isEmpty() )
193 #endif
194 return false;
196 return true;
199 } // namespace dbaui
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */