android: Update app icon to new startcenter icon
[LibreOffice.git] / fpicker / source / office / iodlgimp.cxx
blob5b2a67e38de5064d184ad87e30c5cb7f6a4a93e8
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 <sal/config.h>
22 #include <string_view>
24 #include "fileview.hxx"
25 #include "iodlgimp.hxx"
26 #include <tools/debug.hxx>
27 #include <tools/urlobj.hxx>
28 #include <svtools/inettbc.hxx>
29 #include "iodlg.hxx"
30 #include <svtools/imagemgr.hxx>
31 #include <svl/svlresid.hxx>
32 #include <svl/svl.hrc>
33 #include <utility>
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::lang;
37 using namespace ::utl;
39 SvtFileDialogFilter_Impl::SvtFileDialogFilter_Impl( OUString aName, OUString aType )
40 : m_aName(std::move( aName ))
41 , m_aType(std::move( aType ))
43 m_aType = m_aType.toAsciiLowerCase();
46 SvtFileDialogFilter_Impl::~SvtFileDialogFilter_Impl()
50 //= SvtUpButton_Impl
51 SvtUpButton_Impl::SvtUpButton_Impl(std::unique_ptr<weld::Toolbar> xToolbar,
52 std::unique_ptr<weld::Menu> xMenu,
53 SvtFileDialog* pDlg)
54 : m_xToolbar(std::move(xToolbar))
55 , m_xMenu(std::move(xMenu))
56 , m_pDlg(pDlg)
58 m_xToolbar->set_item_menu("up_btn", m_xMenu.get());
59 m_xToolbar->connect_clicked(LINK(this, SvtUpButton_Impl, ClickHdl));
60 m_xMenu->connect_activate(LINK(this, SvtUpButton_Impl, SelectHdl));
63 void SvtUpButton_Impl::FillURLMenu()
65 SvtFileView* pBox = m_pDlg->GetView();
67 sal_uInt16 nItemId = 1;
69 aURLs.clear();
70 m_xMenu->clear();
72 // determine parent levels
73 INetURLObject aObject( pBox->GetViewURL() );
74 sal_Int32 nCount = aObject.getSegmentCount();
76 ::svtools::VolumeInfo aVolInfo( true /* volume */, false /* remote */,
77 false /* removable */, false /* floppy */,
78 false /* compact disk */ );
79 OUString aVolumeImage( SvFileInformationManager::GetFolderImageId( aVolInfo ) );
81 while ( nCount >= 1 )
83 aObject.removeSegment();
84 OUString aParentURL(aObject.GetMainURL(INetURLObject::DecodeMechanism::NONE));
86 OUString aTitle;
88 if (nCount == 1) // adjust the title of the top level entry (the workspace)
89 aTitle = SvlResId(STR_SVT_MIMETYPE_CNT_FSYSBOX);
90 else if (!m_pDlg->ContentGetTitle(aParentURL, aTitle) || aTitle.isEmpty())
91 aTitle = aObject.getName();
93 OUString aImage = ( nCount > 1 ) // if nCount == 1 means workplace, which detects the wrong image
94 ? SvFileInformationManager::GetImageId( aObject ) : aVolumeImage;
96 m_xMenu->append(OUString::number(nItemId), aTitle, aImage);
97 aURLs.push_back(aParentURL);
99 ++nItemId;
100 --nCount;
104 IMPL_LINK(SvtUpButton_Impl, SelectHdl, const OUString&, rId, void)
106 sal_uInt32 nId = rId.toUInt32();
107 if (nId)
109 --nId;
110 assert( nId <= aURLs.size() && "SvtUpButton_Impl: wrong index" );
112 m_pDlg->OpenURL_Impl(aURLs[nId]);
116 IMPL_LINK_NOARG(SvtUpButton_Impl, ClickHdl, const OUString&, void)
118 m_pDlg->PrevLevel_Impl();
121 // SvtExpFileDlg_Impl
122 SvtExpFileDlg_Impl::SvtExpFileDlg_Impl()
123 : m_pCurFilter( nullptr )
124 , m_eMode( FILEDLG_MODE_OPEN )
125 , m_eDlgType( FILEDLG_TYPE_FILEDLG )
126 , m_nStyle( PickerFlags::NONE )
127 , m_aFilterIdle("fpicker SvtExpFileDlg_Impl m_aFilterIdle")
128 , m_bDoubleClick( false )
129 , m_bMultiSelection( false )
133 SvtExpFileDlg_Impl::~SvtExpFileDlg_Impl()
137 void SvtExpFileDlg_Impl::SetStandardDir( const OUString& _rDir )
139 m_aStdDir = _rDir;
140 if (m_aStdDir.isEmpty())
141 m_aStdDir = "file:///";
144 namespace {
145 OUString lcl_DecoratedFilter( std::u16string_view _rOriginalFilter )
147 return "<" + OUString::Concat(_rOriginalFilter) + ">";
151 void SvtExpFileDlg_Impl::SetCurFilter( SvtFileDialogFilter_Impl const * pFilter, const OUString& rDisplayName )
153 DBG_ASSERT( pFilter, "SvtExpFileDlg_Impl::SetCurFilter: invalid filter!" );
154 DBG_ASSERT( ( rDisplayName == pFilter->GetName() )
155 || ( rDisplayName == lcl_DecoratedFilter( pFilter->GetName() ) ),
156 "SvtExpFileDlg_Impl::SetCurFilter: arguments are inconsistent!" );
158 m_pCurFilter = pFilter;
159 m_sCurrentFilterDisplayName = rDisplayName;
162 void SvtExpFileDlg_Impl::InsertFilterListEntry(const SvtFileDialogFilter_Impl* pFilterDesc)
164 // insert and set user data
165 OUString sId(weld::toId(pFilterDesc));
166 OUString sName = pFilterDesc->GetName();
167 if (pFilterDesc->isGroupSeparator())
168 m_xLbFilter->append_separator(sId);
169 else
170 m_xLbFilter->append(sId, sName);
173 void SvtExpFileDlg_Impl::InitFilterList( )
175 // clear the current list
176 m_xLbFilter->clear();
178 // reinit it
179 sal_uInt16 nPos = m_aFilter.size();
181 // search for the first entry which is no group separator
182 while ( nPos-- && m_aFilter[ nPos ]->isGroupSeparator() )
185 // add all following entries
186 while ( static_cast<sal_Int16>(nPos) >= 0 )
187 InsertFilterListEntry( m_aFilter[ nPos-- ].get() );
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */