summaryrefslogtreecommitdiff
path: root/uui/source/fltdlg.cxx
blob: ebedfbc9ee391561a23af98c408d6d05e9f58196 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include "fltdlg.hxx"

#include "ids.hrc"

#include "fltdlg.hrc"

#include <com/sun/star/util/XStringWidth.hpp>
#include <cppuhelper/implbase1.hxx>
#include <unotools/localfilehelper.hxx>
#include <tools/urlobj.hxx>

#include <vcl/button.hxx>
#include <osl/mutex.hxx>
#include <vcl/svapp.hxx>

namespace uui
{

/*-************************************************************************************************************//**
    @short      initialize filter dialog with start values
    @descr      We set some neccessary information on these instance for later working and create internal structures.
                After construction user should call "SetFilters()" and "SetURL()" to fill listbox with selectable filter
                names and set file name of file, which should be used for selected filter.

    @seealso    method SetFilters()
    @seealso    method SetURL()

    @param      "pParentWindow"  , parent window for dialog
    @param      "pResMgr"        , resource manager
    @return     -

    @onerror    -
    @threadsafe no
*//*-*************************************************************************************************************/
FilterDialog::FilterDialog( Window* pParentWindow ,
                            ResMgr* pResMgr       )
    :   ModalDialog  (pParentWindow, ResId( DLG_FILTER_SELECT, *pResMgr ) )
    ,   m_ftURL      (this, ResId( FT_URL, *pResMgr))
    ,   m_lbFilters  (this, ResId( LB_FILTERS, *pResMgr))
    ,   m_btnOK      (this, ResId( BTN_OK, *pResMgr))
    ,   m_btnCancel  (this, ResId( BTN_CANCEL, *pResMgr))
    ,   m_btnHelp    (this, ResId( BTN_HELP, *pResMgr))
    ,   m_pFilterNames(NULL)
{
    FreeResource();
}

/*-************************************************************************************************************//**
    @short      set file name on dialog control
    @descr      We convert given URL (it must be an URL!) into valid file name and show it on our dialog.

    @seealso    -

    @param      "sURL", URL for showing
    @return     -

    @onerror    -
    @threadsafe no
*//*-*************************************************************************************************************/
void FilterDialog::SetURL( const String& sURL )
{
    // convert it and use given pure string as fallback if conversion failed
    m_ftURL.SetText( impl_buildUIFileName(sURL) );
}

/*-************************************************************************************************************//**
    @short      change list of filter names
    @descr      We save given pointer internal and use it to fill our listbox with given names.
                Saved list pointer is used on method "AskForFilter()" too, to find user selected item
                and return pointer into these list as result of operation.
                So it's possible to call dialog again and again for different or same filter list
                and ask user for his decision by best performance!

    @attention  Don't free memory of given list after this call till object will die ... or
                you call "ChangeFilters( NULL )"! Then we forget it too.

    @seealso    method AskForFilter()

    @param      "pFilterNames", pointer to list of filter names, which should be used for later operations.
    @return     -

    @onerror    We clear list box and forget our currently set filter information completely!
    @threadsafe no
*//*-*************************************************************************************************************/
void FilterDialog::ChangeFilters( const FilterNameList* pFilterNames )
{
    m_pFilterNames = pFilterNames;
    m_lbFilters.Clear();
    if( m_pFilterNames != NULL )
    {
        for( FilterNameListPtr pItem  = m_pFilterNames->begin();
                               pItem != m_pFilterNames->end()  ;
                               ++pItem                         )
        {
            m_lbFilters.InsertEntry( pItem->sUI );
        }
    }
}

/*-************************************************************************************************************//**
    @short      ask user for his decision
    @descr      We show the dialog and if user finish it with "OK" - we try to find selected item in internal saved
                name list (which you must set in "ChangeFilters()"!). If we return sal_True as result, you can use out
                parameter "pSelectedItem" as pointer into your FilterNameList to get selected item realy ...
                but if we return sal_False ... user has cancel the dialog ... you should not do that. pSelectedItem isnt
                set to any valid value then. We don't change them ...

    @seealso    method ChangeFilters()

    @param      "pSelectedItem", returns result of selection as pointer into set list of filter names
                                 (valid for function return sal_True only!)
    @return     true  => pSelectedItem parameter points into name list and represent use decision
                false => use has cancelled dialog (pSelectedItem isnt valid then!)

    @onerror    We return false ... but don't change pSelectedItem!
    @threadsafe no
*//*-*************************************************************************************************************/
bool FilterDialog::AskForFilter( FilterNameListPtr& pSelectedItem )
{
    bool bSelected = sal_False;

    if( m_pFilterNames != NULL )
    {
        if( ModalDialog::Execute() == RET_OK )
        {
            String sEntry = m_lbFilters.GetSelectEntry();
            if( sEntry.Len() > 0 )
            {
                int nPos = m_lbFilters.GetSelectEntryPos();
                if( nPos < (int)(m_pFilterNames->size()) )
                {
                    pSelectedItem  = m_pFilterNames->begin();
                    pSelectedItem += nPos;
                    bSelected      = ( pSelectedItem != m_pFilterNames->end() );
                }
            }
        }
    }

    return bSelected;
}

/*-************************************************************************************************************//**
    @short      helper class to calculate length of given string
    @descr      Instances of it can be used as callback for INetURLObject::getAbbreviated() method to build
                short URLs to show it on GUI. We use in ctor set OutputDevice to call special VCL method ...

    @seealso    method OutputDevice::GetTextWidth()
    @seealso    method InetURLObject::getAbbreviated()

    @param      -
    @return     -

    @onerror    -
    @threadsafe no
*//*-*************************************************************************************************************/
class StringCalculator : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XStringWidth >
{
    public:
        StringCalculator( const OutputDevice* pDevice )
            : m_pDevice( pDevice )
        {
        }

        sal_Int32 SAL_CALL queryStringWidth( const OUString& sString ) throw( ::com::sun::star::uno::RuntimeException )
        {
            return (sal_Int32)(m_pDevice->GetTextWidth(String(sString)));
        }

    private:
        const OutputDevice* m_pDevice;
};

/*-************************************************************************************************************//**
    @short      try to build short name of given URL to show it n GUI
    @descr      We detect type of given URL automaticly and build this short name depend on this type ...
                If we couldnt make it right we return full given string without any changes ...

    @seealso    class LocalFileHelper
    @seealso    method InetURLObject::getAbbreviated()

    @param      "sName", file name
    @return     A short file name ...

    @onerror    We return given name without any changes.
    @threadsafe no
*//*-*************************************************************************************************************/
String FilterDialog::impl_buildUIFileName( const String& sName )
{
    OUString sShortName( sName );

    if( ::utl::LocalFileHelper::ConvertURLToSystemPath( sName, sShortName ) == sal_True )
    {
        // it's a system file ... build short name by using osl functionality
    }
    else
    {
        // otherwise its really a url ... build short name by using INetURLObject
        ::com::sun::star::uno::Reference< ::com::sun::star::util::XStringWidth > xStringCalculator( new StringCalculator(&m_ftURL) );
        if( xStringCalculator.is() == sal_True )
        {
            INetURLObject aBuilder   ( sName );
            Size          aSize      = m_ftURL.GetOutputSize();
                          sShortName = aBuilder.getAbbreviated( xStringCalculator, aSize.Width(), INetURLObject::DECODE_UNAMBIGUOUS );
        }
    }

    return sShortName;
}

}   // namespace uui

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
core/commit/distro-configs/LibreOfficeOssFuzz.conf?h=cp-24.04.5-2&id=4da3e0a0e5b2260c26186890724978bfd00f796c'>ofz#19296 disable skia for oss-fuzzCaolán McNamara Change-Id: I85ee6689c71a445c59d6b054cd93ea1fbac5f8ba Reviewed-on: https://gerrit.libreoffice.org/84737 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com> 2019-09-30drop gtk2 supportCaolán McNamara Change-Id: Ie838cabfecfef7e3225c1555536d5c9cf3b43f15 Reviewed-on: https://gerrit.libreoffice.org/77405 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com> 2018-08-13use gold linker for oss-fuzzCaolán McNamara Change-Id: I60319d22c192b068860b1959350a602edf19aea4 Reviewed-on: https://gerrit.libreoffice.org/58916 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com> 2017-10-30related: tdf#103884 remove gltf/collada featureThorsten Behrens Change-Id: Icd26ad96c0337844ef1463dabfbe791caa00dd2d Reviewed-on: https://gerrit.libreoffice.org/43972 Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de> Tested-by: Thorsten Behrens <Thorsten.Behrens@CIB.de> 2017-03-03disable dynload expects services.rdb to list the orig library nameCaolán McNamara while ---enable-mergelibs creates a single libmergedlo.a in this mode and the services.rdb contains that I guess I could tweak cppuhelper/source/shlib.cxx and solenv/bin/native-code.py etc to work differently or just take the more well travelled road here Change-Id: I35e2626824c9b015b5a6051db659fe467c35d8ba 2017-02-24Always enable liblangtagKhaled Hosny The license should not be an issue any more since liblangtag now has an LGPL/MPLv2 dual licence. Change-Id: I4dfffcccf5d710bd16b21c3254c1449ae041b8ab Reviewed-on: https://gerrit.libreoffice.org/34511 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Eike Rathke <erack@redhat.com> 2017-02-10add --disable-pdfiumCaolán McNamara Change-Id: I9137dc0030c3c752ffc0931721bf6b0013309d39 2016-12-20use new ENABLE_NSS for code which needs nssCaolán McNamara which isn't available on a static-only build (iOS and fuzzing) and android Change-Id: I99bb7c0b45d4499579ddf73f469a762ddcae99ab Reviewed-on: https://gerrit.libreoffice.org/32182 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com> 2016-12-18necessary oss-fuzz config setupCaolán McNamara Change-Id: Id3db7c7fa74f8dd36c0385c2198efd12546004ab 2016-12-10oss-fuzz: do explicit disable-runtime-optimizationsCaolán McNamara Change-Id: I0597436bddcd79f7a44d3969b54a3ae2e02b3c70 2016-12-08oss-fuzz: disable-gui now worksCaolán McNamara Change-Id: I8c9349299e67532c60fcd1e887fc0e33e45a29b8 2016-12-05oss-fuzz woes continueCaolán McNamara Change-Id: I8307c09d5ba4fb24c0d2e273459b34edd06ae76a 2016-12-05oss-fuzz deploys in a very different env to which its builtCaolán McNamara Change-Id: Ice4956cd196424d21bf659f95f99c3e0c6928744 2016-12-05optionally enable oss-fuzz targets via --enable-fuzzersCaolán McNamara Change-Id: I16f52515a149a1e6e47cd0301a45db84ddd95885 2016-12-02sufficient to get us building in the oss-fuzz environmentCaolán McNamara we're presented with... CXX="/usr/local/bin/clang++" CC="/usr/local/bin/clang" CXXFLAGS="-g -stdlib=libc++" and out of the box we fail to build, but if we reshuffle to... CXX="/usr/local/bin/clang++ -stdlib=libc++" CC="/usr/local/bin/clang -stdlib=libc++" CXXFLAGS="-g" LDFLAGS="-lpthread" then with this distro-config we build to completion Change-Id: Ib6bee4dd69e0609e3c1238d86837a1680483ffa4 2016-12-02starting skeleton for oss-fuzz configCaolán McNamara gets vcl built anyway Change-Id: I521a53019f54d5e42c931043c758143f2f8bdb1d