fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / svtools / source / dialogs / PlaceEditDialog.cxx
blob90fdea7b0a92c875a8b6d2243a0bee70dae93190
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/.
8 */
10 #include <svtools/PlaceEditDialog.hxx>
11 #include <svtools/ServerDetailsControls.hxx>
13 #include <officecfg/Office/Common.hxx>
14 #include <svtools/svtresid.hxx>
15 #include <vcl/msgbox.hxx>
17 PlaceEditDialog::PlaceEditDialog(vcl::Window* pParent)
18 : ModalDialog(pParent, "PlaceEditDialog", "svt/ui/placeedit.ui")
19 , m_xCurrentDetails()
21 get( m_pEDServerName, "name" );
22 get( m_pLBServerType, "type" );
23 get( m_pEDUsername, "login" );
24 get( m_pBTOk, "ok" );
25 get( m_pBTCancel, "cancel" );
26 get( m_pBTDelete, "delete" );
28 m_pBTOk->SetClickHdl( LINK( this, PlaceEditDialog, OKHdl) );
29 m_pBTOk->Enable( false );
31 m_pEDServerName->SetModifyHdl( LINK( this, PlaceEditDialog, EditHdl) );
33 // This constructor is called when user request a place creation, so
34 // delete button is hidden.
35 m_pBTDelete->Hide();
37 m_pLBServerType->SetSelectHdl( LINK( this, PlaceEditDialog, SelectTypeHdl ) );
38 m_pEDUsername->SetModifyHdl( LINK( this, PlaceEditDialog, EditUsernameHdl ) );
40 InitDetails( );
43 PlaceEditDialog::PlaceEditDialog(vcl::Window* pParent, const std::shared_ptr<Place>& rPlace)
44 : ModalDialog(pParent, "PlaceEditDialog", "svt/ui/placeedit.ui")
45 , m_xCurrentDetails( )
47 get( m_pEDServerName, "name" );
48 get( m_pLBServerType, "type" );
49 get( m_pEDUsername, "login" );
50 get( m_pBTOk, "ok" );
51 get( m_pBTCancel, "cancel" );
52 get( m_pBTDelete, "delete" );
54 m_pBTOk->SetClickHdl( LINK( this, PlaceEditDialog, OKHdl) );
55 m_pBTDelete->SetClickHdl ( LINK( this, PlaceEditDialog, DelHdl) );
57 m_pEDServerName->SetModifyHdl( LINK( this, PlaceEditDialog, EditHdl) );
58 m_pLBServerType->SetSelectHdl( LINK( this, PlaceEditDialog, SelectTypeHdl ) );
60 InitDetails( );
62 m_pEDServerName->SetText(rPlace->GetName());
64 // Fill the boxes with the URL parts
65 bool bSuccess = false;
66 for (size_t i = 0 ; i < m_aDetailsContainers.size( ) && !bSuccess; ++i)
68 INetURLObject& rUrl = rPlace->GetUrlObject();
69 bSuccess = m_aDetailsContainers[i]->setUrl( rUrl );
70 if ( bSuccess )
72 m_pLBServerType->SelectEntryPos( i );
73 SelectTypeHdl( m_pLBServerType );
75 // Fill the Username field
76 if ( rUrl.HasUserData( ) )
77 m_pEDUsername->SetText( rUrl.GetUser( ) );
82 PlaceEditDialog::~PlaceEditDialog()
84 disposeOnce();
87 void PlaceEditDialog::dispose()
89 m_pEDServerName.clear();
90 m_pLBServerType.clear();
91 m_pEDUsername.clear();
92 m_pBTOk.clear();
93 m_pBTCancel.clear();
94 m_pBTDelete.clear();
95 ModalDialog::dispose();
98 OUString PlaceEditDialog::GetServerUrl()
100 OUString sUrl;
101 if (m_xCurrentDetails.get())
103 INetURLObject aUrl = m_xCurrentDetails->getUrl();
104 OUString sUsername = OUString( m_pEDUsername->GetText( ) ).trim( );
105 if ( !sUsername.isEmpty( ) )
106 aUrl.SetUser( sUsername );
107 if ( !aUrl.HasError( ) )
108 sUrl = aUrl.GetMainURL( INetURLObject::NO_DECODE );
111 return sUrl;
114 std::shared_ptr<Place> PlaceEditDialog::GetPlace()
116 return std::make_shared<Place>(m_pEDServerName->GetText(), GetServerUrl(), true);
119 void PlaceEditDialog::InitDetails( )
121 // Create WebDAV / FTP / SSH details control
122 std::shared_ptr<DetailsContainer> xDavDetails(std::make_shared<DavDetailsContainer>(this));
123 xDavDetails->setChangeHdl( LINK( this, PlaceEditDialog, EditHdl ) );
124 m_aDetailsContainers.push_back(xDavDetails);
126 std::shared_ptr<DetailsContainer> xFtpDetails(std::make_shared<HostDetailsContainer>(this, 21, "ftp"));
127 xFtpDetails->setChangeHdl( LINK( this, PlaceEditDialog, EditHdl ) );
128 m_aDetailsContainers.push_back(xFtpDetails);
130 std::shared_ptr<DetailsContainer> xSshDetails(std::make_shared<HostDetailsContainer>(this, 22, "ssh"));
131 xSshDetails->setChangeHdl( LINK( this, PlaceEditDialog, EditHdl ) );
132 m_aDetailsContainers.push_back(xSshDetails);
134 // Create Windows Share control
135 std::shared_ptr<DetailsContainer> xSmbDetails(std::make_shared<SmbDetailsContainer>(this));
136 xSmbDetails->setChangeHdl( LINK( this, PlaceEditDialog, EditHdl ) );
137 m_aDetailsContainers.push_back(xSmbDetails);
139 // Create CMIS control
140 std::shared_ptr<DetailsContainer> xCmisDetails(std::make_shared<CmisDetailsContainer>(this));
141 xCmisDetails->setChangeHdl( LINK( this, PlaceEditDialog, EditHdl ) );
142 m_aDetailsContainers.push_back(xCmisDetails);
144 // Set default to first value
145 m_pLBServerType->SelectEntryPos( 0 );
146 SelectTypeHdl( m_pLBServerType );
149 IMPL_LINK ( PlaceEditDialog, OKHdl, Button *, )
151 EndDialog( RET_OK );
152 return 1;
155 IMPL_LINK ( PlaceEditDialog, DelHdl, Button *, )
157 // ReUsing existing symbols...
158 EndDialog( RET_NO );
159 return 1;
162 IMPL_LINK_NOARG( PlaceEditDialog, EditHdl )
164 OUString sUrl = GetServerUrl( );
165 OUString sName = OUString( m_pEDServerName->GetText() ).trim( );
166 m_pBTOk->Enable( !sName.isEmpty( ) && !sUrl.isEmpty( ) );
167 return 1;
170 IMPL_LINK_NOARG( PlaceEditDialog, EditUsernameHdl )
172 for ( std::vector< std::shared_ptr< DetailsContainer > >::iterator it = m_aDetailsContainers.begin( );
173 it != m_aDetailsContainers.end( ); ++it )
175 ( *it )->setUsername( OUString( m_pEDUsername->GetText() ) );
177 return 1;
180 IMPL_LINK_NOARG( PlaceEditDialog, SelectTypeHdl )
182 if (m_xCurrentDetails.get())
183 m_xCurrentDetails->show(false);
185 sal_uInt16 nPos = m_pLBServerType->GetSelectEntryPos( );
186 m_xCurrentDetails = m_aDetailsContainers[nPos];
188 m_xCurrentDetails->show(true);
190 SetSizePixel(GetOptimalSize());
191 return 0;
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */