Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License or as specified alternatively below. You may obtain a copy of
8 : * the License at http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * Major Contributor(s):
16 : * [ Copyright (C) 2012 Julien Levesy <jlevesy@gmail.com> (initial developer) ]
17 : *
18 : * All Rights Reserved.
19 : *
20 : * For minor contributions see the git repository.
21 : *
22 : * Alternatively, the contents of this file may be used under the terms of
23 : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : * instead of those above.
27 : */
28 :
29 : #include "PlaceEditDialog.hxx"
30 : #include "ServerDetailsControls.hxx"
31 :
32 : #include <officecfg/Office/Common.hxx>
33 : #include <svtools/svtresid.hxx>
34 : #include <vcl/msgbox.hxx>
35 :
36 : using namespace boost;
37 :
38 0 : PlaceEditDialog::PlaceEditDialog( Window* pParent ) :
39 : ModalDialog( pParent, "PlaceEditDialog", "svt/ui/placeedit.ui" ),
40 0 : m_pCurrentDetails( )
41 : {
42 0 : get( m_pEDServerName, "name" );
43 0 : get( m_pLBServerType, "type" );
44 0 : get( m_pEDUsername, "login" );
45 0 : get( m_pBTOk, "ok" );
46 0 : get( m_pBTCancel, "cancel" );
47 0 : get( m_pBTDelete, "delete" );
48 :
49 0 : m_pBTOk->SetClickHdl( LINK( this, PlaceEditDialog, OKHdl) );
50 0 : m_pBTOk->Enable( sal_False );
51 :
52 0 : m_pEDServerName->SetModifyHdl( LINK( this, PlaceEditDialog, EditHdl) );
53 :
54 : // This constructor is called when user request a place creation, so
55 : // delete button is hidden.
56 0 : m_pBTDelete->Hide();
57 :
58 0 : m_pLBServerType->SetSelectHdl( LINK( this, PlaceEditDialog, SelectTypeHdl ) );
59 0 : m_pEDUsername->SetModifyHdl( LINK( this, PlaceEditDialog, EditUsernameHdl ) );
60 :
61 0 : InitDetails( );
62 0 : }
63 :
64 0 : PlaceEditDialog::PlaceEditDialog( Window* pParent, const boost::shared_ptr<Place>& pPlace ) :
65 : ModalDialog( pParent, "PlaceEditDialog", "svt/ui/placeedit.ui" ),
66 0 : m_pCurrentDetails( )
67 : {
68 0 : get( m_pEDServerName, "name" );
69 0 : get( m_pLBServerType, "type" );
70 0 : get( m_pEDUsername, "login" );
71 0 : get( m_pBTOk, "ok" );
72 0 : get( m_pBTCancel, "cancel" );
73 0 : get( m_pBTDelete, "delete" );
74 :
75 0 : m_pBTOk->SetClickHdl( LINK( this, PlaceEditDialog, OKHdl) );
76 0 : m_pBTDelete->SetClickHdl ( LINK( this, PlaceEditDialog, DelHdl) );
77 :
78 0 : m_pEDServerName->SetModifyHdl( LINK( this, PlaceEditDialog, EditHdl) );
79 0 : m_pLBServerType->SetSelectHdl( LINK( this, PlaceEditDialog, SelectTypeHdl ) );
80 :
81 0 : InitDetails( );
82 :
83 0 : m_pEDServerName->SetText( pPlace->GetName() );
84 :
85 : // Fill the boxes with the URL parts
86 0 : bool bSuccess = false;
87 0 : for ( size_t i = 0 ; i < m_aDetailsContainers.size( ) && !bSuccess; ++i )
88 : {
89 0 : INetURLObject& rUrl = pPlace->GetUrlObject( );
90 0 : bSuccess = m_aDetailsContainers[i]->setUrl( rUrl );
91 0 : if ( bSuccess )
92 : {
93 0 : m_pLBServerType->SelectEntryPos( i );
94 0 : SelectTypeHdl( m_pLBServerType );
95 :
96 : // Fill the Username field
97 0 : if ( rUrl.HasUserData( ) )
98 0 : m_pEDUsername->SetText( rUrl.GetUser( ) );
99 : }
100 : }
101 0 : }
102 :
103 0 : PlaceEditDialog::~PlaceEditDialog()
104 : {
105 0 : }
106 :
107 0 : rtl::OUString PlaceEditDialog::GetServerUrl()
108 : {
109 0 : rtl::OUString sUrl;
110 0 : if ( m_pCurrentDetails.get( ) )
111 : {
112 0 : INetURLObject aUrl = m_pCurrentDetails->getUrl();
113 0 : rtl::OUString sUsername = rtl::OUString( m_pEDUsername->GetText( ) ).trim( );
114 0 : if ( !sUsername.isEmpty( ) )
115 0 : aUrl.SetUser( sUsername );
116 0 : if ( !aUrl.HasError( ) )
117 0 : sUrl = aUrl.GetMainURL( INetURLObject::NO_DECODE );
118 : }
119 :
120 0 : return sUrl;
121 : }
122 :
123 0 : boost::shared_ptr<Place> PlaceEditDialog::GetPlace()
124 : {
125 0 : boost::shared_ptr<Place> newPlace( new Place( m_pEDServerName->GetText(), GetServerUrl(), true ) );
126 0 : return newPlace;
127 : }
128 :
129 0 : void PlaceEditDialog::InitDetails( )
130 : {
131 : // Create WebDAV / FTP / SSH details control
132 0 : shared_ptr< DetailsContainer > pDavDetails( new DavDetailsContainer( this ) );
133 0 : pDavDetails->setChangeHdl( LINK( this, PlaceEditDialog, EditHdl ) );
134 0 : m_aDetailsContainers.push_back( pDavDetails );
135 :
136 0 : shared_ptr< DetailsContainer > pFtpDetails( new HostDetailsContainer( this, 21, "ftp" ) );
137 0 : pFtpDetails->setChangeHdl( LINK( this, PlaceEditDialog, EditHdl ) );
138 0 : m_aDetailsContainers.push_back( pFtpDetails );
139 :
140 0 : shared_ptr< DetailsContainer > pSshDetails( new HostDetailsContainer( this, 22, "ssh" ) );
141 0 : pSshDetails->setChangeHdl( LINK( this, PlaceEditDialog, EditHdl ) );
142 0 : m_aDetailsContainers.push_back( pSshDetails );
143 :
144 : // Create Windows Share control
145 0 : shared_ptr< DetailsContainer > pSmbDetails( new SmbDetailsContainer( this ) );
146 0 : pSmbDetails->setChangeHdl( LINK( this, PlaceEditDialog, EditHdl ) );
147 0 : m_aDetailsContainers.push_back( pSmbDetails );
148 :
149 : // Create CMIS control
150 0 : shared_ptr< DetailsContainer > pCmisDetails( new CmisDetailsContainer( this ) );
151 0 : pCmisDetails->setChangeHdl( LINK( this, PlaceEditDialog, EditHdl ) );
152 0 : m_aDetailsContainers.push_back( pCmisDetails );
153 :
154 : // Set default to first value
155 0 : m_pLBServerType->SelectEntryPos( 0 );
156 0 : SelectTypeHdl( m_pLBServerType );
157 0 : }
158 :
159 0 : IMPL_LINK ( PlaceEditDialog, OKHdl, Button *, EMPTYARG )
160 : {
161 0 : EndDialog( RET_OK );
162 0 : return 1;
163 : }
164 :
165 0 : IMPL_LINK ( PlaceEditDialog, DelHdl, Button *, EMPTYARG )
166 : {
167 : // ReUsing existing symbols...
168 0 : EndDialog( RET_NO );
169 0 : return 1;
170 : }
171 :
172 0 : IMPL_LINK ( PlaceEditDialog, EditHdl, void *, EMPTYARG )
173 : {
174 0 : rtl::OUString sUrl = GetServerUrl( );
175 0 : rtl::OUString sName = rtl::OUString( m_pEDServerName->GetText() ).trim( );
176 0 : m_pBTOk->Enable( !sName.isEmpty( ) && !sUrl.isEmpty( ) );
177 0 : return 1;
178 : }
179 :
180 0 : IMPL_LINK ( PlaceEditDialog, EditUsernameHdl, void *, EMPTYARG )
181 : {
182 0 : for ( std::vector< boost::shared_ptr< DetailsContainer > >::iterator it = m_aDetailsContainers.begin( );
183 0 : it != m_aDetailsContainers.end( ); ++it )
184 : {
185 0 : ( *it )->setUsername( rtl::OUString( m_pEDUsername->GetText() ) );
186 : }
187 0 : return 1;
188 : }
189 :
190 0 : IMPL_LINK( PlaceEditDialog, SelectTypeHdl, void*, EMPTYARG )
191 : {
192 0 : if ( m_pCurrentDetails.get( ) )
193 0 : m_pCurrentDetails->show( false );
194 :
195 0 : sal_uInt16 nPos = m_pLBServerType->GetSelectEntryPos( );
196 0 : m_pCurrentDetails = m_aDetailsContainers[nPos];
197 :
198 0 : m_pCurrentDetails->show( true );
199 :
200 0 : SetSizePixel( GetOptimalSize( WINDOWSIZE_MINIMUM ) );
201 0 : return 0;
202 108 : }
203 :
204 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|