Bump version to 24.04.3.4
[LibreOffice.git] / fpicker / source / office / PlacesListBox.cxx
blob86bd505179a356008dbd7b9727f36025fcc30f1f
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 "PlacesListBox.hxx"
11 #include <svtools/PlaceEditDialog.hxx>
13 #include <bitmaps.hlst>
15 PlacesListBox::PlacesListBox(std::unique_ptr<weld::TreeView> xControl,
16 std::unique_ptr<weld::Button> xAdd,
17 std::unique_ptr<weld::Button> xDel,
18 SvtFileDialog* pFileDlg)
19 : mpDlg(pFileDlg)
20 , mxImpl(std::move(xControl))
21 , mxAddBtn(std::move(xAdd))
22 , mxDelBtn(std::move(xDel))
23 , mnNbEditables(0)
24 , mbUpdated( false )
26 Size aSize(mxImpl->get_approximate_digit_width() * 18,
27 mxImpl->get_height_rows(9));
28 mxImpl->set_size_request(aSize.Width(), aSize.Height());
30 mxImpl->connect_changed( LINK( this, PlacesListBox, Selection ) );
31 mxImpl->connect_row_activated( LINK( this, PlacesListBox, DoubleClick ) ) ;
32 mxImpl->connect_query_tooltip(LINK(this, PlacesListBox, QueryTooltipHdl));
35 PlacesListBox::~PlacesListBox( )
39 void PlacesListBox::AppendPlace( const PlacePtr& pPlace )
41 maPlaces.push_back( pPlace );
42 mxImpl->append_text(pPlace->GetName());
43 mxImpl->set_image(maPlaces.size() - 1, getEntryIcon(pPlace));
45 if(pPlace->IsEditable()) {
46 ++mnNbEditables;
47 mbUpdated = true;
51 bool PlacesListBox::IsUpdated() {
52 if(mbUpdated) {
53 mbUpdated = false;
54 return true;
56 return false;
59 void PlacesListBox::RemovePlace( sal_uInt16 nPos )
61 if ( nPos < maPlaces.size() )
63 if(maPlaces[nPos]->IsEditable()) {
64 --mnNbEditables;
65 mbUpdated = true;
67 maPlaces.erase( maPlaces.begin() + nPos );
68 mxImpl->remove(nPos);
72 void PlacesListBox::RemoveSelectedPlace() {
73 RemovePlace(mxImpl->get_cursor_index());
76 void PlacesListBox::SetAddHdl( const Link<weld::Button&,void>& rHdl )
78 mxAddBtn->connect_clicked( rHdl );
81 void PlacesListBox::SetDelHdl( const Link<weld::Button&,void>& rHdl )
83 mxDelBtn->connect_clicked( rHdl );
86 void PlacesListBox::SetDelEnabled( bool enabled )
88 mxDelBtn->set_sensitive( enabled );
91 OUString PlacesListBox::getEntryIcon( const PlacePtr& pPlace )
93 OUString theImage = BMP_FILEDLG_PLACE_LOCAL;
94 if ( !pPlace->IsLocal( ) )
95 theImage = BMP_FILEDLG_PLACE_REMOTE;
96 return theImage;
99 IMPL_LINK_NOARG( PlacesListBox, Selection, weld::TreeView&, void )
101 sal_uInt32 nSelected = mxImpl->get_cursor_index();
102 PlacePtr pPlace = maPlaces[nSelected];
104 if (pPlace->IsEditable())
105 mpDlg->RemovablePlaceSelected();
106 else
107 mpDlg->RemovablePlaceSelected(false);
109 updateView();
112 IMPL_LINK_NOARG( PlacesListBox, DoubleClick, weld::TreeView&, bool )
114 sal_uInt16 nSelected = mxImpl->get_cursor_index();
115 PlacePtr pPlace = maPlaces[nSelected];
116 if ( !pPlace->IsEditable() || pPlace->IsLocal( ) )
117 return true;
118 PlaceEditDialog aDlg(mpDlg->getDialog(), pPlace);
119 short aRetCode = aDlg.run();
120 switch (aRetCode)
122 case RET_OK :
124 pPlace->SetName ( aDlg.GetServerName() );
125 pPlace->SetUrl( aDlg.GetServerUrl() );
126 mbUpdated = true;
127 break;
129 case RET_NO :
131 RemovePlace(nSelected);
132 break;
134 default:
135 break;
137 return true;
140 IMPL_LINK(PlacesListBox, QueryTooltipHdl, const weld::TreeIter&, rIter, OUString)
142 const OUString sText = mxImpl->get_text(rIter);
143 for (const auto& pPlace : maPlaces)
145 if (pPlace->GetName() == sText)
146 return pPlace->GetUrlObject().GetMainURL(INetURLObject::DecodeMechanism::Unambiguous);
148 return OUString();
151 void PlacesListBox::updateView( )
153 sal_uInt32 nSelected = mxImpl->get_cursor_index();
154 PlacePtr pPlace = maPlaces[nSelected];
155 mpDlg->OpenURL_Impl( pPlace->GetUrl( ) );
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */