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/.
10 #include "PlaceEditDialog.hxx"
11 #include "ServerDetailsControls.hxx"
13 #include <officecfg/Office/Common.hxx>
14 #include <svtools/svtresid.hxx>
15 #include <vcl/msgbox.hxx>
17 using namespace boost
;
19 PlaceEditDialog::PlaceEditDialog( Window
* pParent
) :
20 ModalDialog( pParent
, "PlaceEditDialog", "svt/ui/placeedit.ui" ),
23 get( m_pEDServerName
, "name" );
24 get( m_pLBServerType
, "type" );
25 get( m_pEDUsername
, "login" );
27 get( m_pBTCancel
, "cancel" );
28 get( m_pBTDelete
, "delete" );
30 m_pBTOk
->SetClickHdl( LINK( this, PlaceEditDialog
, OKHdl
) );
31 m_pBTOk
->Enable( sal_False
);
33 m_pEDServerName
->SetModifyHdl( LINK( this, PlaceEditDialog
, EditHdl
) );
35 // This constructor is called when user request a place creation, so
36 // delete button is hidden.
39 m_pLBServerType
->SetSelectHdl( LINK( this, PlaceEditDialog
, SelectTypeHdl
) );
40 m_pEDUsername
->SetModifyHdl( LINK( this, PlaceEditDialog
, EditUsernameHdl
) );
45 PlaceEditDialog::PlaceEditDialog( Window
* pParent
, const boost::shared_ptr
<Place
>& pPlace
) :
46 ModalDialog( pParent
, "PlaceEditDialog", "svt/ui/placeedit.ui" ),
49 get( m_pEDServerName
, "name" );
50 get( m_pLBServerType
, "type" );
51 get( m_pEDUsername
, "login" );
53 get( m_pBTCancel
, "cancel" );
54 get( m_pBTDelete
, "delete" );
56 m_pBTOk
->SetClickHdl( LINK( this, PlaceEditDialog
, OKHdl
) );
57 m_pBTDelete
->SetClickHdl ( LINK( this, PlaceEditDialog
, DelHdl
) );
59 m_pEDServerName
->SetModifyHdl( LINK( this, PlaceEditDialog
, EditHdl
) );
60 m_pLBServerType
->SetSelectHdl( LINK( this, PlaceEditDialog
, SelectTypeHdl
) );
64 m_pEDServerName
->SetText( pPlace
->GetName() );
66 // Fill the boxes with the URL parts
67 bool bSuccess
= false;
68 for ( size_t i
= 0 ; i
< m_aDetailsContainers
.size( ) && !bSuccess
; ++i
)
70 INetURLObject
& rUrl
= pPlace
->GetUrlObject( );
71 bSuccess
= m_aDetailsContainers
[i
]->setUrl( rUrl
);
74 m_pLBServerType
->SelectEntryPos( i
);
75 SelectTypeHdl( m_pLBServerType
);
77 // Fill the Username field
78 if ( rUrl
.HasUserData( ) )
79 m_pEDUsername
->SetText( rUrl
.GetUser( ) );
84 PlaceEditDialog::~PlaceEditDialog()
88 OUString
PlaceEditDialog::GetServerUrl()
91 if ( m_pCurrentDetails
.get( ) )
93 INetURLObject aUrl
= m_pCurrentDetails
->getUrl();
94 OUString sUsername
= OUString( m_pEDUsername
->GetText( ) ).trim( );
95 if ( !sUsername
.isEmpty( ) )
96 aUrl
.SetUser( sUsername
);
97 if ( !aUrl
.HasError( ) )
98 sUrl
= aUrl
.GetMainURL( INetURLObject::NO_DECODE
);
104 boost::shared_ptr
<Place
> PlaceEditDialog::GetPlace()
106 boost::shared_ptr
<Place
> newPlace( new Place( m_pEDServerName
->GetText(), GetServerUrl(), true ) );
110 void PlaceEditDialog::InitDetails( )
112 // Create WebDAV / FTP / SSH details control
113 shared_ptr
< DetailsContainer
> pDavDetails( new DavDetailsContainer( this ) );
114 pDavDetails
->setChangeHdl( LINK( this, PlaceEditDialog
, EditHdl
) );
115 m_aDetailsContainers
.push_back( pDavDetails
);
117 shared_ptr
< DetailsContainer
> pFtpDetails( new HostDetailsContainer( this, 21, "ftp" ) );
118 pFtpDetails
->setChangeHdl( LINK( this, PlaceEditDialog
, EditHdl
) );
119 m_aDetailsContainers
.push_back( pFtpDetails
);
121 shared_ptr
< DetailsContainer
> pSshDetails( new HostDetailsContainer( this, 22, "ssh" ) );
122 pSshDetails
->setChangeHdl( LINK( this, PlaceEditDialog
, EditHdl
) );
123 m_aDetailsContainers
.push_back( pSshDetails
);
125 // Create Windows Share control
126 shared_ptr
< DetailsContainer
> pSmbDetails( new SmbDetailsContainer( this ) );
127 pSmbDetails
->setChangeHdl( LINK( this, PlaceEditDialog
, EditHdl
) );
128 m_aDetailsContainers
.push_back( pSmbDetails
);
130 // Create CMIS control
131 shared_ptr
< DetailsContainer
> pCmisDetails( new CmisDetailsContainer( this ) );
132 pCmisDetails
->setChangeHdl( LINK( this, PlaceEditDialog
, EditHdl
) );
133 m_aDetailsContainers
.push_back( pCmisDetails
);
135 // Set default to first value
136 m_pLBServerType
->SelectEntryPos( 0 );
137 SelectTypeHdl( m_pLBServerType
);
140 IMPL_LINK ( PlaceEditDialog
, OKHdl
, Button
*, EMPTYARG
)
146 IMPL_LINK ( PlaceEditDialog
, DelHdl
, Button
*, EMPTYARG
)
148 // ReUsing existing symbols...
153 IMPL_LINK ( PlaceEditDialog
, EditHdl
, void *, EMPTYARG
)
155 OUString sUrl
= GetServerUrl( );
156 OUString sName
= OUString( m_pEDServerName
->GetText() ).trim( );
157 m_pBTOk
->Enable( !sName
.isEmpty( ) && !sUrl
.isEmpty( ) );
161 IMPL_LINK ( PlaceEditDialog
, EditUsernameHdl
, void *, EMPTYARG
)
163 for ( std::vector
< boost::shared_ptr
< DetailsContainer
> >::iterator it
= m_aDetailsContainers
.begin( );
164 it
!= m_aDetailsContainers
.end( ); ++it
)
166 ( *it
)->setUsername( OUString( m_pEDUsername
->GetText() ) );
171 IMPL_LINK( PlaceEditDialog
, SelectTypeHdl
, void*, EMPTYARG
)
173 if ( m_pCurrentDetails
.get( ) )
174 m_pCurrentDetails
->show( false );
176 sal_uInt16 nPos
= m_pLBServerType
->GetSelectEntryPos( );
177 m_pCurrentDetails
= m_aDetailsContainers
[nPos
];
179 m_pCurrentDetails
->show( true );
181 SetSizePixel(GetOptimalSize());
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */