LCOV - code coverage report
Current view: top level - vcl/unx/gtk/fpicker - SalGtkFilePicker.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 904 0.0 %
Date: 2014-04-14 Functions: 0 81 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #ifdef AIX
      21             : #define _LINUX_SOURCE_COMPAT
      22             : #include <sys/timer.h>
      23             : #undef _LINUX_SOURCE_COMPAT
      24             : #endif
      25             : 
      26             : #include <config_vclplug.h>
      27             : 
      28             : #include <com/sun/star/awt/Toolkit.hpp>
      29             : #include <com/sun/star/frame/Desktop.hpp>
      30             : #include <com/sun/star/uno/XComponentContext.hpp>
      31             : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
      32             : #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
      33             : #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
      34             : #include <osl/diagnose.h>
      35             : #include <osl/process.h>
      36             : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      37             : #include <com/sun/star/ui/dialogs/ControlActions.hpp>
      38             : #include <com/sun/star/uno/Any.hxx>
      39             : #include <comphelper/string.hxx>
      40             : #include <osl/mutex.hxx>
      41             : #include "unx/gtk/gtkinst.hxx"
      42             : 
      43             : #include <vcl/svapp.hxx>
      44             : 
      45             : #include <tools/urlobj.hxx>
      46             : 
      47             : #include <algorithm>
      48             : #include <set>
      49             : #include <string.h>
      50             : 
      51             : #include "gtk/fpicker/SalGtkFilePicker.hxx"
      52             : 
      53             : // namespace directives
      54             : 
      55             : using namespace ::com::sun::star;
      56             : using namespace ::com::sun::star::ui::dialogs;
      57             : using namespace ::com::sun::star::ui::dialogs::TemplateDescription;
      58             : using namespace ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds;
      59             : using namespace ::com::sun::star::ui::dialogs::CommonFilePickerElementIds;
      60             : using namespace ::com::sun::star::lang;
      61             : using namespace ::com::sun::star::beans;
      62             : using namespace ::com::sun::star::uno;
      63             : 
      64           0 : static void expandexpanders(GtkContainer *pWidget)
      65             : {
      66           0 :     GList *pChildren = gtk_container_get_children(pWidget);
      67           0 :     for( GList *p = pChildren; p; p = p->next )
      68             :     {
      69           0 :         if (GTK_IS_CONTAINER(GTK_WIDGET(p->data)))
      70           0 :             expandexpanders(GTK_CONTAINER(GTK_WIDGET(p->data)));
      71           0 :         if (GTK_IS_EXPANDER(GTK_WIDGET(p->data)))
      72           0 :             gtk_expander_set_expanded(GTK_EXPANDER(GTK_WIDGET(p->data)), true);
      73             :     }
      74           0 :     g_list_free(pChildren);
      75           0 : }
      76             : 
      77           0 : void SalGtkFilePicker::dialog_mapped_cb(GtkWidget *, SalGtkFilePicker *pobjFP)
      78             : {
      79           0 :     pobjFP->InitialMapping();
      80           0 : }
      81             : 
      82           0 : void SalGtkFilePicker::InitialMapping()
      83             : {
      84           0 :     if (!mbPreviewState )
      85             :     {
      86           0 :         gtk_widget_hide( m_pPreview );
      87           0 :         gtk_file_chooser_set_preview_widget_active( GTK_FILE_CHOOSER( m_pDialog ), false);
      88             :     }
      89           0 :     gtk_widget_set_size_request (m_pPreview, -1, -1);
      90           0 : }
      91             : 
      92           0 : SalGtkFilePicker::SalGtkFilePicker( const uno::Reference< uno::XComponentContext >& xContext ) :
      93             :     SalGtkPicker( xContext ),
      94             :     SalGtkFilePicker_Base( m_rbHelperMtx ),
      95             :     m_pFilterList( NULL ),
      96             :     m_pVBox ( NULL ),
      97             :     mnHID_FolderChange( 0 ),
      98             :     mnHID_SelectionChange( 0 ),
      99             :     bVersionWidthUnset( false ),
     100             :     mbPreviewState( false ),
     101             :     mHID_Preview( 0 ),
     102             :     m_pPreview( NULL ),
     103             :     m_pPseudoFilter( NULL ),
     104             :     m_PreviewImageWidth( 256 ),
     105           0 :     m_PreviewImageHeight( 256 )
     106             : {
     107             :     int i;
     108             : 
     109           0 :     for( i = 0; i < TOGGLE_LAST; i++ )
     110             :     {
     111           0 :         m_pToggles[i] = NULL;
     112           0 :         mbToggleVisibility[i] = false;
     113             :     }
     114             : 
     115           0 :     for( i = 0; i < BUTTON_LAST; i++ )
     116             :     {
     117           0 :         m_pButtons[i] = NULL;
     118           0 :         mbButtonVisibility[i] = false;
     119             :     }
     120             : 
     121           0 :     for( i = 0; i < LIST_LAST; i++ )
     122             :     {
     123           0 :         m_pHBoxs[i] = NULL;
     124           0 :         m_pAligns[i] = NULL;
     125           0 :         m_pLists[i] = NULL;
     126           0 :         m_pListLabels[i] = NULL;
     127           0 :         mbListVisibility[i] = false;
     128             :     }
     129             : 
     130           0 :     OUString aFilePickerTitle = getResString( FILE_PICKER_TITLE_OPEN );
     131             : 
     132             :     m_pDialog = gtk_file_chooser_dialog_new(
     133             :             OUStringToOString( aFilePickerTitle, RTL_TEXTENCODING_UTF8 ).getStr(),
     134             :             NULL,
     135             :             GTK_FILE_CHOOSER_ACTION_OPEN,
     136             :             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
     137             :             GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
     138           0 :             (char *)NULL );
     139             : 
     140           0 :     gtk_dialog_set_default_response( GTK_DIALOG (m_pDialog), GTK_RESPONSE_ACCEPT );
     141             : 
     142             : #if ENABLE_GNOME_VFS || ENABLE_GIO
     143           0 :     gtk_file_chooser_set_local_only( GTK_FILE_CHOOSER( m_pDialog ), false );
     144             : #endif
     145           0 :     gtk_file_chooser_set_select_multiple( GTK_FILE_CHOOSER( m_pDialog ), false );
     146             : 
     147           0 :     m_pVBox = gtk_vbox_new( false, 0 );
     148             : 
     149             :     // We don't want clickable items to have a huge hit-area
     150           0 :     GtkWidget *pHBox = gtk_hbox_new( false, 0 );
     151           0 :     GtkWidget *pThinVBox = gtk_vbox_new( false, 0 );
     152             : 
     153           0 :     gtk_box_pack_end (GTK_BOX( m_pVBox ), pHBox, false, false, 0);
     154           0 :     gtk_box_pack_start (GTK_BOX( pHBox ), pThinVBox, false, false, 0);
     155           0 :     gtk_widget_show( pHBox );
     156           0 :     gtk_widget_show( pThinVBox );
     157             : 
     158           0 :     OUString aLabel;
     159             : 
     160           0 :     for( i = 0; i < TOGGLE_LAST; i++ )
     161             :     {
     162           0 :         m_pToggles[i] = gtk_check_button_new();
     163             : 
     164             : #define LABEL_TOGGLE( elem ) \
     165             :         case elem : \
     166             :             aLabel = getResString( CHECKBOX_##elem ); \
     167             :             setLabel( CHECKBOX_##elem, aLabel ); \
     168             :             break
     169             : 
     170           0 :           switch( i ) {
     171             : 
     172           0 :         LABEL_TOGGLE( AUTOEXTENSION );
     173           0 :         LABEL_TOGGLE( PASSWORD );
     174           0 :         LABEL_TOGGLE( FILTEROPTIONS );
     175           0 :         LABEL_TOGGLE( READONLY );
     176           0 :         LABEL_TOGGLE( LINK );
     177           0 :         LABEL_TOGGLE( PREVIEW );
     178           0 :         LABEL_TOGGLE( SELECTION );
     179             :             default:
     180             :                 OSL_TRACE("Handle unknown control %d", i);
     181           0 :                 break;
     182             :         }
     183             : 
     184           0 :         gtk_box_pack_end( GTK_BOX( pThinVBox ), m_pToggles[i], false, false, 0 );
     185             :     }
     186             : 
     187           0 :     for( i = 0; i < LIST_LAST; i++ )
     188             :     {
     189           0 :         m_pHBoxs[i] = gtk_hbox_new( false, 0 );
     190             : 
     191           0 :         m_pAligns[i] = gtk_alignment_new(0, 0, 0, 1);
     192             : 
     193           0 :         m_pListStores[i] = gtk_list_store_new (1, G_TYPE_STRING);
     194           0 :         m_pLists[i] = gtk_combo_box_new_with_model(GTK_TREE_MODEL(m_pListStores[i]));
     195           0 :         g_object_unref (m_pListStores[i]); // owned by the widget.
     196           0 :         GtkCellRenderer *pCell = gtk_cell_renderer_text_new ();
     197             :         gtk_cell_layout_pack_start(
     198           0 :                 GTK_CELL_LAYOUT(m_pLists[i]), pCell, TRUE);
     199             :         gtk_cell_layout_set_attributes(
     200           0 :             GTK_CELL_LAYOUT (m_pLists[i]), pCell, "text", 0, NULL);
     201             : 
     202           0 :         m_pListLabels[i] = gtk_label_new( "" );
     203             : 
     204             : #define LABEL_LIST( elem ) \
     205             :         case elem : \
     206             :             aLabel = getResString( LISTBOX_##elem##_LABEL ); \
     207             :             setLabel( LISTBOX_##elem##_LABEL, aLabel ); \
     208             :             break
     209             : 
     210           0 :           switch( i )
     211             :         {
     212           0 :             LABEL_LIST( VERSION );
     213           0 :             LABEL_LIST( TEMPLATE );
     214           0 :             LABEL_LIST( IMAGE_TEMPLATE );
     215             :             default:
     216             :                 OSL_TRACE("Handle unknown control %d", i);
     217           0 :                 break;
     218             :         }
     219             : 
     220           0 :         gtk_container_add( GTK_CONTAINER( m_pAligns[i]), m_pLists[i] );
     221           0 :         gtk_box_pack_end( GTK_BOX( m_pHBoxs[i] ), m_pAligns[i], false, false, 0 );
     222             : 
     223           0 :         gtk_box_pack_end( GTK_BOX( m_pHBoxs[i] ), m_pListLabels[i], false, false, 0 );
     224             : 
     225           0 :         gtk_box_pack_end( GTK_BOX( m_pVBox ), m_pHBoxs[i], false, false, 0 );
     226             :     }
     227             : 
     228           0 :     aLabel = getResString( FILE_PICKER_FILE_TYPE );
     229             :     m_pFilterExpander = gtk_expander_new_with_mnemonic(
     230           0 :         OUStringToOString( aLabel, RTL_TEXTENCODING_UTF8 ).getStr());
     231             : 
     232           0 :     gtk_box_pack_end( GTK_BOX( m_pVBox ), m_pFilterExpander, false, true, 0 );
     233             : 
     234           0 :     GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);
     235           0 :     gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
     236           0 :         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
     237           0 :     gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
     238           0 :         GTK_SHADOW_IN);
     239           0 :     gtk_container_add (GTK_CONTAINER (m_pFilterExpander), scrolled_window);
     240           0 :     gtk_widget_show (scrolled_window);
     241             : 
     242           0 :     OString sExpand(getenv("SAL_EXPANDFPICKER"));
     243           0 :     sal_Int32 nExpand  = sExpand.toInt32();
     244           0 :     switch (nExpand)
     245             :     {
     246             :         default:
     247             :         case 0:
     248           0 :             break;
     249             :         case 1:
     250           0 :             gtk_expander_set_expanded(GTK_EXPANDER(m_pFilterExpander), true);
     251           0 :             break;
     252             :         case 2:
     253           0 :             expandexpanders(GTK_CONTAINER(m_pDialog));
     254           0 :             gtk_expander_set_expanded(GTK_EXPANDER(m_pFilterExpander), true);
     255           0 :             break;
     256             :     }
     257             : 
     258             :     m_pFilterStore = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_STRING,
     259           0 :         G_TYPE_STRING, G_TYPE_STRING);
     260           0 :     m_pFilterView = gtk_tree_view_new_with_model (GTK_TREE_MODEL(m_pFilterStore));
     261           0 :     gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(m_pFilterView), false);
     262           0 :     gtk_tree_view_set_rules_hint (GTK_TREE_VIEW(m_pFilterView), true);
     263             : 
     264             :     GtkTreeViewColumn *column;
     265             :     GtkCellRenderer *cell;
     266             : 
     267           0 :     for (i = 0; i < 2; ++i)
     268             :     {
     269           0 :         column = gtk_tree_view_column_new ();
     270           0 :         cell = gtk_cell_renderer_text_new ();
     271           0 :         gtk_tree_view_column_set_expand (column, true);
     272           0 :         gtk_tree_view_column_pack_start (column, cell, false);
     273           0 :         gtk_tree_view_column_set_attributes (column, cell, "text", i, (char *)NULL);
     274           0 :         gtk_tree_view_append_column (GTK_TREE_VIEW(m_pFilterView), column);
     275             :     }
     276             : 
     277           0 :     gtk_container_add (GTK_CONTAINER (scrolled_window), m_pFilterView);
     278           0 :     gtk_widget_show (m_pFilterView);
     279             : 
     280           0 :     gtk_file_chooser_set_extra_widget( GTK_FILE_CHOOSER( m_pDialog ), m_pVBox );
     281             : 
     282           0 :     m_pPreview = gtk_image_new();
     283           0 :     gtk_file_chooser_set_preview_widget( GTK_FILE_CHOOSER( m_pDialog ), m_pPreview );
     284             : 
     285           0 :     g_signal_connect( G_OBJECT( m_pToggles[PREVIEW] ), "toggled",
     286           0 :                       G_CALLBACK( preview_toggled_cb ), this );
     287           0 :     g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW(m_pFilterView)), "changed",
     288           0 :                       G_CALLBACK ( type_changed_cb ), this);
     289           0 :     g_signal_connect( G_OBJECT( m_pDialog ), "notify::filter",
     290           0 :                       G_CALLBACK( filter_changed_cb ), this);
     291           0 :     g_signal_connect( G_OBJECT( m_pFilterExpander ), "activate",
     292           0 :                       G_CALLBACK( expander_changed_cb ), this);
     293           0 :     g_signal_connect (G_OBJECT( m_pDialog ), "map",
     294           0 :                       G_CALLBACK (dialog_mapped_cb), this);
     295             : 
     296           0 :     gtk_widget_show( m_pVBox );
     297             : 
     298           0 :     PangoLayout  *layout = gtk_widget_create_pango_layout (m_pFilterView, NULL);
     299             :     guint ypad;
     300             :     PangoRectangle row_height;
     301           0 :     pango_layout_set_markup (layout, "All Files", -1);
     302           0 :     pango_layout_get_pixel_extents (layout, NULL, &row_height);
     303           0 :     g_object_unref (layout);
     304             : 
     305           0 :     g_object_get (cell, "ypad", &ypad, (char *)NULL);
     306           0 :     guint height = (row_height.height + 2*ypad) * 5;
     307           0 :     gtk_widget_set_size_request (m_pFilterView, -1, height);
     308           0 :     gtk_widget_set_size_request (m_pPreview, 1, height);
     309             : 
     310           0 :     gtk_file_chooser_set_preview_widget_active( GTK_FILE_CHOOSER( m_pDialog ), true);
     311           0 : }
     312             : 
     313             : // XFilePickerNotifier
     314             : 
     315           0 : void SAL_CALL SalGtkFilePicker::addFilePickerListener( const uno::Reference<XFilePickerListener>& xListener )
     316             :     throw( uno::RuntimeException, std::exception )
     317             : {
     318           0 :     SolarMutexGuard g;
     319             : 
     320             :     OSL_ENSURE(!m_xListener.is(),
     321             :             "SalGtkFilePicker only talks with one listener at a time...");
     322           0 :     m_xListener = xListener;
     323           0 : }
     324             : 
     325           0 : void SAL_CALL SalGtkFilePicker::removeFilePickerListener( const uno::Reference<XFilePickerListener>& )
     326             :     throw( uno::RuntimeException, std::exception )
     327             : {
     328           0 :     SolarMutexGuard g;
     329             : 
     330           0 :     m_xListener.clear();
     331           0 : }
     332             : 
     333             : // XEventListener
     334             : 
     335           0 : void SAL_CALL SalGtkFilePicker::disposing( const lang::EventObject& aEvent ) throw( uno::RuntimeException )
     336             : {
     337             :     // no member access => no mutex needed
     338             : 
     339           0 :     uno::Reference<XFilePickerListener> xFilePickerListener( aEvent.Source, ::com::sun::star::uno::UNO_QUERY );
     340             : 
     341           0 :     if( xFilePickerListener.is() )
     342           0 :         removeFilePickerListener( xFilePickerListener );
     343           0 : }
     344             : 
     345             : // FilePicker Event functions
     346             : 
     347           0 : void SalGtkFilePicker::impl_fileSelectionChanged( FilePickerEvent aEvent )
     348             : {
     349             :     OSL_TRACE( "file selection changed");
     350           0 :     if (m_xListener.is()) m_xListener->fileSelectionChanged( aEvent );
     351           0 : }
     352             : 
     353           0 : void SalGtkFilePicker::impl_directoryChanged( FilePickerEvent aEvent )
     354             : {
     355             :     OSL_TRACE("directory changed");
     356           0 :     if (m_xListener.is()) m_xListener->directoryChanged( aEvent );
     357           0 : }
     358             : 
     359           0 : void SalGtkFilePicker::impl_controlStateChanged( FilePickerEvent aEvent )
     360             : {
     361             :     OSL_TRACE("control state changed");
     362           0 :     if (m_xListener.is()) m_xListener->controlStateChanged( aEvent );
     363           0 : }
     364             : 
     365           0 : struct FilterEntry
     366             : {
     367             : protected:
     368             :     OUString     m_sTitle;
     369             :     OUString     m_sFilter;
     370             : 
     371             :     UnoFilterList       m_aSubFilters;
     372             : 
     373             : public:
     374           0 :     FilterEntry( const OUString& _rTitle, const OUString& _rFilter )
     375             :         :m_sTitle( _rTitle )
     376           0 :         ,m_sFilter( _rFilter )
     377             :     {
     378           0 :     }
     379             : 
     380           0 :     OUString     getTitle() const { return m_sTitle; }
     381           0 :     OUString     getFilter() const { return m_sFilter; }
     382             : 
     383             :     /// determines if the filter has sub filter (i.e., the filter is a filter group in real)
     384             :     bool        hasSubFilters( ) const;
     385             : 
     386             :     /** retrieves the filters belonging to the entry
     387             :     @return
     388             :         the number of sub filters
     389             :     */
     390             :     sal_Int32       getSubFilters( UnoFilterList& _rSubFilterList );
     391             : 
     392             :     // helpers for iterating the sub filters
     393           0 :     const UnoFilterEntry*   beginSubFilters() const { return m_aSubFilters.getConstArray(); }
     394           0 :     const UnoFilterEntry*   endSubFilters() const { return m_aSubFilters.getConstArray() + m_aSubFilters.getLength(); }
     395             : };
     396             : 
     397           0 : bool FilterEntry::hasSubFilters() const
     398             : {
     399           0 :     return( 0 < m_aSubFilters.getLength() );
     400             : }
     401             : 
     402           0 : sal_Int32 FilterEntry::getSubFilters( UnoFilterList& _rSubFilterList )
     403             : {
     404           0 :     _rSubFilterList = m_aSubFilters;
     405           0 :     return m_aSubFilters.getLength();
     406             : }
     407             : 
     408             : static bool
     409           0 : isFilterString( const OUString &rFilterString, const char *pMatch )
     410             : {
     411           0 :         sal_Int32 nIndex = 0;
     412           0 :         OUString aToken;
     413           0 :         bool bIsFilter = true;
     414             : 
     415           0 :         OUString aMatch(OUString::createFromAscii(pMatch));
     416             : 
     417           0 :         do
     418             :         {
     419           0 :             aToken = rFilterString.getToken( 0, ';', nIndex );
     420           0 :             if( !aToken.match( aMatch ) )
     421             :             {
     422           0 :                 bIsFilter = false;
     423           0 :                 break;
     424             :             }
     425             :         }
     426           0 :         while( nIndex >= 0 );
     427             : 
     428           0 :         return bIsFilter;
     429             : }
     430             : 
     431             : static OUString
     432           0 : shrinkFilterName( const OUString &rFilterName, bool bAllowNoStar = false )
     433             : {
     434             :     int i;
     435           0 :     int nBracketLen = -1;
     436           0 :     int nBracketEnd = -1;
     437           0 :     const sal_Unicode *pStr = rFilterName.getStr();
     438           0 :     OUString aRealName = rFilterName;
     439             : 
     440           0 :     for( i = aRealName.getLength() - 1; i > 0; i-- )
     441             :     {
     442           0 :         if( pStr[i] == ')' )
     443           0 :             nBracketEnd = i;
     444           0 :         else if( pStr[i] == '(' )
     445             :         {
     446           0 :             nBracketLen = nBracketEnd - i;
     447           0 :             if( nBracketEnd <= 0 )
     448           0 :                 continue;
     449           0 :             if( isFilterString( rFilterName.copy( i + 1, nBracketLen - 1 ), "*." ) )
     450           0 :                 aRealName = aRealName.replaceAt( i, nBracketLen + 1, OUString() );
     451           0 :             else if (bAllowNoStar)
     452             :             {
     453           0 :                 if( isFilterString( rFilterName.copy( i + 1, nBracketLen - 1 ), ".") )
     454           0 :                     aRealName = aRealName.replaceAt( i, nBracketLen + 1, OUString() );
     455             :             }
     456             :         }
     457             :     }
     458             : 
     459           0 :     return aRealName;
     460             : }
     461             : 
     462             : static void
     463           0 : dialog_remove_buttons( GtkDialog *pDialog )
     464             : {
     465           0 :     g_return_if_fail( GTK_IS_DIALOG( pDialog ) );
     466             : 
     467             :     GtkWidget *pActionArea;
     468             : 
     469             : #if GTK_CHECK_VERSION(3,0,0)
     470             :     pActionArea = gtk_dialog_get_action_area( pDialog );
     471             : #else
     472           0 :     pActionArea = pDialog->action_area;
     473             : #endif
     474             : 
     475             :     GList *pChildren =
     476           0 :         gtk_container_get_children( GTK_CONTAINER( pActionArea ) );
     477             : 
     478           0 :     for( GList *p = pChildren; p; p = p->next )
     479           0 :         gtk_widget_destroy( GTK_WIDGET( p->data ) );
     480             : 
     481           0 :     g_list_free( pChildren );
     482             : }
     483             : 
     484             : namespace {
     485             : 
     486             :     struct FilterTitleMatch : public ::std::unary_function< FilterEntry, bool >
     487             :     {
     488             :     protected:
     489             :         const OUString& rTitle;
     490             : 
     491             :     public:
     492           0 :         FilterTitleMatch( const OUString& _rTitle ) : rTitle( _rTitle ) { }
     493             : 
     494           0 :         bool operator () ( const FilterEntry& _rEntry )
     495             :         {
     496             :             bool bMatch;
     497           0 :             if( !_rEntry.hasSubFilters() )
     498             :                 // a real filter
     499           0 :                 bMatch = (_rEntry.getTitle() == rTitle)
     500           0 :                       || (shrinkFilterName(_rEntry.getTitle()) == rTitle);
     501             :             else
     502             :                 // a filter group -> search the sub filters
     503             :                 bMatch =
     504           0 :                     _rEntry.endSubFilters() != ::std::find_if(
     505             :                         _rEntry.beginSubFilters(),
     506             :                         _rEntry.endSubFilters(),
     507             :                         *this
     508           0 :                     );
     509             : 
     510           0 :             return bMatch ? true : false;
     511             :         }
     512           0 :         bool operator () ( const UnoFilterEntry& _rEntry )
     513             :         {
     514           0 :             OUString aShrunkName = shrinkFilterName( _rEntry.First );
     515           0 :             return aShrunkName == rTitle ? true : false;
     516             :         }
     517             :     };
     518             : }
     519             : 
     520           0 : bool SalGtkFilePicker::FilterNameExists( const OUString& rTitle )
     521             : {
     522           0 :     bool bRet = false;
     523             : 
     524           0 :     if( m_pFilterList )
     525             :         bRet =
     526           0 :             m_pFilterList->end() != ::std::find_if(
     527             :                 m_pFilterList->begin(),
     528             :                 m_pFilterList->end(),
     529             :                 FilterTitleMatch( rTitle )
     530           0 :             );
     531             : 
     532           0 :     return bRet;
     533             : }
     534             : 
     535           0 : bool SalGtkFilePicker::FilterNameExists( const UnoFilterList& _rGroupedFilters )
     536             : {
     537           0 :     bool bRet = false;
     538             : 
     539           0 :     if( m_pFilterList )
     540             :     {
     541           0 :         const UnoFilterEntry* pStart = _rGroupedFilters.getConstArray();
     542           0 :         const UnoFilterEntry* pEnd = pStart + _rGroupedFilters.getLength();
     543           0 :         for( ; pStart != pEnd; ++pStart )
     544           0 :             if( m_pFilterList->end() != ::std::find_if(
     545             :                         m_pFilterList->begin(),
     546             :                         m_pFilterList->end(),
     547           0 :                         FilterTitleMatch( pStart->First ) ) )
     548           0 :                 break;
     549             : 
     550           0 :         bRet = pStart != pEnd;
     551             :     }
     552             : 
     553           0 :     return bRet;
     554             : }
     555             : 
     556           0 : void SalGtkFilePicker::ensureFilterList( const OUString& _rInitialCurrentFilter )
     557             : {
     558           0 :     if( !m_pFilterList )
     559             :     {
     560           0 :         m_pFilterList = new FilterList;
     561             : 
     562             :         // set the first filter to the current filter
     563           0 :         if ( m_aCurrentFilter.isEmpty() )
     564           0 :             m_aCurrentFilter = _rInitialCurrentFilter;
     565             :     }
     566           0 : }
     567             : 
     568           0 : void SAL_CALL SalGtkFilePicker::appendFilter( const OUString& aTitle, const OUString& aFilter )
     569             :     throw( lang::IllegalArgumentException, uno::RuntimeException, std::exception )
     570             : {
     571           0 :     SolarMutexGuard g;
     572             : 
     573             :     OSL_ASSERT( m_pDialog != NULL );
     574             : 
     575           0 :     if( FilterNameExists( aTitle ) )
     576           0 :             throw IllegalArgumentException();
     577             : 
     578             :     // ensure that we have a filter list
     579           0 :     ensureFilterList( aTitle );
     580             : 
     581             :     // append the filter
     582           0 :     m_pFilterList->insert( m_pFilterList->end(), FilterEntry( aTitle, aFilter ) );
     583           0 : }
     584             : 
     585           0 : void SAL_CALL SalGtkFilePicker::setCurrentFilter( const OUString& aTitle )
     586             :     throw( lang::IllegalArgumentException, uno::RuntimeException, std::exception )
     587             : {
     588           0 :     SolarMutexGuard g;
     589             : 
     590             :     OSL_ASSERT( m_pDialog != NULL );
     591             : 
     592             :     OSL_TRACE( "Setting current filter to %s\n",
     593             :         OUStringToOString( aTitle, RTL_TEXTENCODING_UTF8 ).getStr() );
     594             : 
     595           0 :     if( aTitle != m_aCurrentFilter )
     596             :     {
     597           0 :         m_aCurrentFilter = aTitle;
     598           0 :         SetCurFilter( m_aCurrentFilter );
     599             :         OSL_TRACE( "REALLY Setting current filter to %s\n",
     600             :             OUStringToOString( aTitle, RTL_TEXTENCODING_UTF8 ).getStr() );
     601             : 
     602           0 :     }
     603             : 
     604             :     // TODO m_pImpl->setCurrentFilter( aTitle );
     605           0 : }
     606             : 
     607           0 : void SalGtkFilePicker::updateCurrentFilterFromName(const gchar* filtername)
     608             : {
     609           0 :     OUString aFilterName(filtername, strlen(filtername), RTL_TEXTENCODING_UTF8);
     610           0 :     FilterList::iterator aEnd = m_pFilterList->end();
     611           0 :     for (FilterList::iterator aIter = m_pFilterList->begin(); aIter != aEnd; ++aIter)
     612             :     {
     613           0 :         if (aFilterName == shrinkFilterName( aIter->getTitle()))
     614             :         {
     615           0 :             m_aCurrentFilter = aIter->getTitle();
     616           0 :             break;
     617             :         }
     618           0 :     }
     619           0 : }
     620             : 
     621           0 : void SalGtkFilePicker::UpdateFilterfromUI()
     622             : {
     623             :     // Update the filtername from the users selection if they have had a chance to do so.
     624             :     // If the user explicitly sets a type then use that, if not then take the implicit type
     625             :     // from the filter of the files glob on which he is currently searching
     626           0 :     if (!mnHID_FolderChange || !mnHID_SelectionChange)
     627           0 :         return;
     628             : 
     629           0 :     GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(m_pFilterView));
     630             :     GtkTreeIter iter;
     631             :     GtkTreeModel *model;
     632           0 :     if (gtk_tree_selection_get_selected (selection, &model, &iter))
     633             :     {
     634             :         gchar *title;
     635           0 :         gtk_tree_model_get (model, &iter, 2, &title, -1);
     636           0 :         updateCurrentFilterFromName(title);
     637           0 :         g_free (title);
     638             :     }
     639           0 :     else if( GtkFileFilter *filter = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(m_pDialog)))
     640             :     {
     641           0 :         if (m_pPseudoFilter != filter)
     642           0 :             updateCurrentFilterFromName(gtk_file_filter_get_name( filter ));
     643             :         else
     644           0 :             updateCurrentFilterFromName(OUStringToOString( m_aInitialFilter, RTL_TEXTENCODING_UTF8 ).getStr());
     645             :     }
     646             : }
     647             : 
     648           0 : OUString SAL_CALL SalGtkFilePicker::getCurrentFilter() throw( uno::RuntimeException, std::exception )
     649             : {
     650           0 :     SolarMutexGuard g;
     651             : 
     652             :     OSL_ASSERT( m_pDialog != NULL );
     653             : 
     654             :     OSL_TRACE( "GetCURRENTfilter" );
     655             : 
     656           0 :     UpdateFilterfromUI();
     657             : 
     658             :     OSL_TRACE( "Returning current filter of %s\n",
     659             :         OUStringToOString( m_aCurrentFilter, RTL_TEXTENCODING_UTF8 ).getStr() );
     660             : 
     661           0 :     return m_aCurrentFilter;
     662             : }
     663             : 
     664             : // XFilterGroupManager functions
     665             : 
     666           0 : void SAL_CALL SalGtkFilePicker::appendFilterGroup( const OUString& /*sGroupTitle*/, const uno::Sequence<beans::StringPair>& aFilters )
     667             :     throw( lang::IllegalArgumentException, uno::RuntimeException, std::exception )
     668             : {
     669           0 :     SolarMutexGuard g;
     670             : 
     671             :     OSL_ASSERT( m_pDialog != NULL );
     672             : 
     673             :     // TODO m_pImpl->appendFilterGroup( sGroupTitle, aFilters );
     674             :     // check the names
     675           0 :     if( FilterNameExists( aFilters ) )
     676             :         // TODO: a more precise exception message
     677           0 :             throw IllegalArgumentException();
     678             : 
     679             :     // ensure that we have a filter list
     680           0 :     OUString sInitialCurrentFilter;
     681           0 :     if( aFilters.getLength() )
     682           0 :         sInitialCurrentFilter = aFilters[0].First;
     683             : 
     684           0 :     ensureFilterList( sInitialCurrentFilter );
     685             : 
     686             :     // append the filter
     687           0 :     const StringPair* pSubFilters   = aFilters.getConstArray();
     688           0 :     const StringPair* pSubFiltersEnd = pSubFilters + aFilters.getLength();
     689           0 :     for( ; pSubFilters != pSubFiltersEnd; ++pSubFilters )
     690           0 :         m_pFilterList->insert( m_pFilterList->end(), FilterEntry( pSubFilters->First, pSubFilters->Second ) );
     691             : 
     692           0 : }
     693             : 
     694             : // XFilePicker functions
     695             : 
     696           0 : void SAL_CALL SalGtkFilePicker::setMultiSelectionMode( sal_Bool bMode ) throw( uno::RuntimeException, std::exception )
     697             : {
     698           0 :     SolarMutexGuard g;
     699             : 
     700             :     OSL_ASSERT( m_pDialog != NULL );
     701             : 
     702           0 :     gtk_file_chooser_set_select_multiple( GTK_FILE_CHOOSER(m_pDialog), bMode );
     703           0 : }
     704             : 
     705           0 : void SAL_CALL SalGtkFilePicker::setDefaultName( const OUString& aName )
     706             :     throw( uno::RuntimeException, std::exception )
     707             : {
     708           0 :     SolarMutexGuard g;
     709             : 
     710             :     OSL_ASSERT( m_pDialog != NULL );
     711             : 
     712           0 :     OString aStr = OUStringToOString( aName, RTL_TEXTENCODING_UTF8 );
     713           0 :     GtkFileChooserAction eAction = gtk_file_chooser_get_action( GTK_FILE_CHOOSER( m_pDialog ) );
     714             : 
     715             :     // set_current_name launches a Gtk critical error if called for other than save
     716           0 :     if( GTK_FILE_CHOOSER_ACTION_SAVE == eAction )
     717           0 :         gtk_file_chooser_set_current_name( GTK_FILE_CHOOSER( m_pDialog ), aStr.getStr() );
     718           0 : }
     719             : 
     720           0 : void SAL_CALL SalGtkFilePicker::setDisplayDirectory( const OUString& rDirectory )
     721             :     throw( lang::IllegalArgumentException, uno::RuntimeException, std::exception )
     722             : {
     723           0 :     SolarMutexGuard g;
     724             : 
     725           0 :     implsetDisplayDirectory(rDirectory);
     726           0 : }
     727             : 
     728           0 : OUString SAL_CALL SalGtkFilePicker::getDisplayDirectory() throw( uno::RuntimeException, std::exception )
     729             : {
     730           0 :     SolarMutexGuard g;
     731             : 
     732           0 :     return implgetDisplayDirectory();
     733             : }
     734             : 
     735           0 : uno::Sequence<OUString> SAL_CALL SalGtkFilePicker::getFiles() throw( uno::RuntimeException, std::exception )
     736             : {
     737             :     // no member access => no mutex needed
     738             : 
     739           0 :     uno::Sequence< OUString > aFiles = getSelectedFiles();
     740             :     /*
     741             :       The previous multiselection API design was completely broken
     742             :       and unimplementable for some hetrogenous pseudo-URIs eg. search:
     743             :       Thus crop unconditionally to a single selection.
     744             :     */
     745           0 :     aFiles.realloc (1);
     746           0 :     return aFiles;
     747             : }
     748             : 
     749             : namespace
     750             : {
     751             : 
     752           0 : bool lcl_matchFilter( const rtl::OUString& rFilter, const rtl::OUString& rExt )
     753             : {
     754           0 :     const int nCount = comphelper::string::getTokenCount( rFilter, ';' );
     755             : 
     756           0 :     for ( int n = 0; n != nCount; ++n )
     757             :     {
     758           0 :         const rtl::OUString aToken = comphelper::string::getToken( rFilter, n, ';' );
     759           0 :         if ( aToken == rExt )
     760           0 :             return true;
     761           0 :     }
     762             : 
     763           0 :     return false;
     764             : }
     765             : 
     766             : }
     767             : 
     768           0 : uno::Sequence<OUString> SAL_CALL SalGtkFilePicker::getSelectedFiles() throw( uno::RuntimeException, std::exception )
     769             : {
     770           0 :     SolarMutexGuard g;
     771             : 
     772             :     OSL_ASSERT( m_pDialog != NULL );
     773             : 
     774           0 :     GSList* pPathList = gtk_file_chooser_get_uris( GTK_FILE_CHOOSER(m_pDialog) );
     775             : 
     776           0 :     int nCount = g_slist_length( pPathList );
     777           0 :     int nIndex = 0;
     778             :     OSL_TRACE( "GETFILES called %d files", nCount );
     779             : 
     780             :     // get the current action setting
     781             :     GtkFileChooserAction eAction = gtk_file_chooser_get_action(
     782           0 :         GTK_FILE_CHOOSER( m_pDialog ));
     783             : 
     784           0 :     uno::Sequence< OUString > aSelectedFiles(nCount);
     785             : 
     786             :     // Convert to OOo
     787           0 :     for( GSList *pElem = pPathList; pElem; pElem = pElem->next)
     788             :     {
     789           0 :         gchar *pURI = reinterpret_cast<gchar*>(pElem->data);
     790           0 :         aSelectedFiles[ nIndex ] = uritounicode(pURI);
     791             : 
     792           0 :         if( GTK_FILE_CHOOSER_ACTION_SAVE == eAction )
     793             :         {
     794           0 :             OUString sFilterName;
     795           0 :             sal_Int32 nTokenIndex = 0;
     796           0 :             bool bExtensionTypedIn = false;
     797             : 
     798           0 :             GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(m_pFilterView));
     799             :             GtkTreeIter iter;
     800             :             GtkTreeModel *model;
     801           0 :             if (gtk_tree_selection_get_selected (selection, &model, &iter))
     802             :             {
     803             :                 gchar *title;
     804           0 :                 gtk_tree_model_get (model, &iter, 2, &title, -1);
     805           0 :                 sFilterName = OUString( title, strlen( title), RTL_TEXTENCODING_UTF8 );
     806           0 :                 g_free (title);
     807             :             }
     808             :             else
     809             :             {
     810           0 :                 if( aSelectedFiles[nIndex].indexOf('.') > 0 )
     811             :                 {
     812           0 :                     OUString sExtension;
     813           0 :                     nTokenIndex = 0;
     814           0 :                     do
     815           0 :                         sExtension = aSelectedFiles[nIndex].getToken( 0, '.', nTokenIndex );
     816           0 :                     while( nTokenIndex >= 0 );
     817             : 
     818           0 :                     if( sExtension.getLength() >= 3 ) // 3 = typical/minimum extension length
     819             :                     {
     820           0 :                         static const OUString aStarDot( "*." );
     821             : 
     822           0 :                         OUString aNewFilter;
     823           0 :                         OUString aOldFilter = getCurrentFilter();
     824           0 :                         bool bChangeFilter = true;
     825           0 :                         for ( FilterList::iterator aListIter = m_pFilterList->begin();
     826           0 :                               aListIter != m_pFilterList->end();
     827             :                               ++aListIter
     828             :                         )
     829             :                         {
     830           0 :                             if( lcl_matchFilter( aListIter->getFilter(), aStarDot+sExtension ) )
     831             :                             {
     832           0 :                                 if( aNewFilter.isEmpty() )
     833           0 :                                     aNewFilter = aListIter->getTitle();
     834             : 
     835           0 :                                 if( aOldFilter == aListIter->getTitle() )
     836           0 :                                     bChangeFilter = false;
     837             : 
     838           0 :                                 bExtensionTypedIn = true;
     839             :                             }
     840             :                         }
     841           0 :                         if( bChangeFilter && bExtensionTypedIn )
     842           0 :                             setCurrentFilter( aNewFilter );
     843           0 :                     }
     844             :                 }
     845             : 
     846           0 :                 GtkFileFilter *filter = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(m_pDialog));
     847           0 :                 if (m_pPseudoFilter != filter)
     848             :                 {
     849           0 :                     const gchar* filtername = filter ? gtk_file_filter_get_name(filter) : NULL;
     850           0 :                     if (filtername)
     851           0 :                         sFilterName = OUString(filtername, strlen( filtername ), RTL_TEXTENCODING_UTF8);
     852             :                     else
     853           0 :                         sFilterName = OUString();
     854             :                 }
     855             :                 else
     856           0 :                     sFilterName = m_aInitialFilter;
     857             :             }
     858             : 
     859             :             OSL_TRACE( "2: current filter is %s\n",
     860             :                 OUStringToOString( sFilterName, RTL_TEXTENCODING_UTF8 ).getStr() );
     861             : 
     862             :             FilterList::iterator aListIter = ::std::find_if(
     863           0 :                 m_pFilterList->begin(), m_pFilterList->end(), FilterTitleMatch(sFilterName) );
     864             : 
     865           0 :             OUString aFilter;
     866           0 :             if (aListIter != m_pFilterList->end())
     867           0 :                 aFilter = aListIter->getFilter();
     868             : 
     869             :             OSL_TRACE( "turned into %s\n",
     870             :                 OUStringToOString( aFilter, RTL_TEXTENCODING_UTF8 ).getStr() );
     871             : 
     872           0 :             nTokenIndex = 0;
     873           0 :             OUString sToken;
     874             :             //   OUString strExt;
     875           0 :             do
     876             :             {
     877           0 :                 sToken = aFilter.getToken( 0, '.', nTokenIndex );
     878             : 
     879           0 :                 if ( sToken.lastIndexOf( ';' ) != -1 )
     880             :                 {
     881           0 :                     sal_Int32 nZero = 0;
     882           0 :                     OUString aCurrentToken = sToken.getToken( 0, ';', nZero);
     883             : 
     884           0 :                     sToken = aCurrentToken;
     885           0 :                     break;
     886             :                 }
     887             :             }
     888           0 :             while( nTokenIndex >= 0 );
     889             : 
     890           0 :             if( !bExtensionTypedIn && ( sToken != "*" ) )
     891             :             {
     892             :                 //if the filename does not already have the auto extension, stick it on
     893           0 :                 OUString sExtension = "." + sToken;
     894           0 :                 OUString &rBase = aSelectedFiles[nIndex];
     895           0 :                 sal_Int32 nExtensionIdx = rBase.getLength() - sExtension.getLength();
     896             :                 OSL_TRACE( "idx are %d %d", rBase.lastIndexOf( sExtension ), nExtensionIdx );
     897             : 
     898           0 :                 if( rBase.lastIndexOf( sExtension ) != nExtensionIdx )
     899           0 :                     rBase += sExtension;
     900           0 :             }
     901             : 
     902             :         }
     903             : 
     904           0 :         nIndex++;
     905           0 :         g_free( pURI );
     906             :     }
     907             : 
     908           0 :     g_slist_free( pPathList );
     909             : 
     910           0 :     return aSelectedFiles;
     911             : }
     912             : 
     913             : // XExecutableDialog functions
     914             : 
     915           0 : void SAL_CALL SalGtkFilePicker::setTitle( const OUString& rTitle ) throw( uno::RuntimeException, std::exception )
     916             : {
     917           0 :     SolarMutexGuard g;
     918             : 
     919           0 :     implsetTitle(rTitle);
     920           0 : }
     921             : 
     922           0 : sal_Int16 SAL_CALL SalGtkFilePicker::execute() throw( uno::RuntimeException, std::exception )
     923             : {
     924           0 :     SolarMutexGuard g;
     925             : 
     926             :     OSL_TRACE( "1: HERE WE ARE");
     927             :     OSL_ASSERT( m_pDialog != NULL );
     928             : 
     929           0 :     sal_Int16 retVal = 0;
     930             : 
     931           0 :     SetFilters();
     932             : 
     933             :     mnHID_FolderChange =
     934           0 :         g_signal_connect( GTK_FILE_CHOOSER( m_pDialog ), "current-folder-changed",
     935           0 :             G_CALLBACK( folder_changed_cb ), ( gpointer )this );
     936             : 
     937             :     mnHID_SelectionChange =
     938           0 :         g_signal_connect( GTK_FILE_CHOOSER( m_pDialog ), "selection-changed",
     939           0 :             G_CALLBACK( selection_changed_cb ), ( gpointer )this );
     940             : 
     941           0 :     int btn = GTK_RESPONSE_NO;
     942             : 
     943             :     uno::Reference< awt::XExtendedToolkit > xToolkit(
     944             :         awt::Toolkit::create(m_xContext),
     945           0 :         UNO_QUERY_THROW );
     946             : 
     947             :     uno::Reference< frame::XDesktop > xDesktop(
     948             :         frame::Desktop::create(m_xContext),
     949           0 :         UNO_QUERY_THROW );
     950             : 
     951           0 :     RunDialog* pRunDialog = new RunDialog(m_pDialog, xToolkit, xDesktop);
     952           0 :     uno::Reference < awt::XTopWindowListener > xLifeCycle(pRunDialog);
     953           0 :     while( GTK_RESPONSE_NO == btn )
     954             :     {
     955           0 :         btn = GTK_RESPONSE_YES; // we dont want to repeat unless user clicks NO for file save.
     956             : 
     957           0 :         gint nStatus = pRunDialog->run();
     958           0 :         switch( nStatus )
     959             :         {
     960             :             case GTK_RESPONSE_ACCEPT:
     961           0 :                 if( GTK_FILE_CHOOSER_ACTION_SAVE == gtk_file_chooser_get_action( GTK_FILE_CHOOSER( m_pDialog ) ) )
     962             :                 {
     963           0 :                     Sequence < OUString > aPathSeq = getFiles();
     964           0 :                     if( aPathSeq.getLength() == 1 )
     965             :                     {
     966           0 :                         OString sFileName = unicodetouri( aPathSeq[0] );
     967           0 :                         gchar *gFileName = g_filename_from_uri ( sFileName.getStr(), NULL, NULL );
     968           0 :                         if( g_file_test( gFileName, G_FILE_TEST_IS_REGULAR ) )
     969             :                         {
     970           0 :                             INetURLObject aFileObj( OStringToOUString(sFileName, RTL_TEXTENCODING_UTF8) );
     971             : 
     972             :                             OString baseName(
     973             :                               OUStringToOString(
     974             :                                 aFileObj.getName(
     975             :                                   INetURLObject::LAST_SEGMENT,
     976             :                                   true,
     977             :                                   INetURLObject::DECODE_WITH_CHARSET
     978             :                                 ),
     979             :                                 RTL_TEXTENCODING_UTF8
     980             :                               )
     981           0 :                             );
     982             :                             OString aMsg(
     983             :                               OUStringToOString(
     984             :                                 getResString( FILE_PICKER_OVERWRITE_PRIMARY ),
     985             :                                 RTL_TEXTENCODING_UTF8
     986             :                               )
     987           0 :                             );
     988           0 :                             OString toReplace("$filename$");
     989             : 
     990           0 :                             aMsg = aMsg.replaceAt(
     991             :                               aMsg.indexOf( toReplace ),
     992             :                               toReplace.getLength(),
     993             :                               baseName
     994           0 :                             );
     995             : 
     996             :                             GtkWidget *dlg = gtk_message_dialog_new( NULL,
     997             :                                 GTK_DIALOG_MODAL,
     998             :                                 GTK_MESSAGE_QUESTION,
     999             :                                 GTK_BUTTONS_YES_NO,
    1000             :                                 "%s",
    1001             :                                 aMsg.getStr()
    1002           0 :                             );
    1003             : 
    1004           0 :                             sal_Int32 nSegmentCount = aFileObj.getSegmentCount();
    1005           0 :                             if (nSegmentCount >= 2)
    1006             :                             {
    1007             :                                 OString dirName(
    1008             :                                   OUStringToOString(
    1009             :                                     aFileObj.getName(
    1010             :                                       nSegmentCount-2,
    1011             :                                       true,
    1012             :                                       INetURLObject::DECODE_WITH_CHARSET
    1013             :                                     ),
    1014             :                                     RTL_TEXTENCODING_UTF8
    1015             :                                   )
    1016           0 :                                 );
    1017             : 
    1018           0 :                                 aMsg =
    1019             :                                   OUStringToOString(
    1020             :                                     getResString( FILE_PICKER_OVERWRITE_SECONDARY ),
    1021             :                                     RTL_TEXTENCODING_UTF8
    1022           0 :                                   );
    1023             : 
    1024           0 :                                 toReplace = "$dirname$";
    1025             : 
    1026           0 :                                 aMsg = aMsg.replaceAt(
    1027             :                                   aMsg.indexOf( toReplace ),
    1028             :                                   toReplace.getLength(),
    1029             :                                   dirName
    1030           0 :                                 );
    1031             : 
    1032           0 :                                 gtk_message_dialog_format_secondary_text( GTK_MESSAGE_DIALOG( dlg ), "%s", aMsg.getStr() );
    1033             :                             }
    1034             : 
    1035           0 :                             gtk_window_set_title( GTK_WINDOW( dlg ),
    1036             :                                 OUStringToOString(getResString(FILE_PICKER_TITLE_SAVE ),
    1037           0 :                                 RTL_TEXTENCODING_UTF8 ).getStr() );
    1038             : 
    1039           0 :                             RunDialog* pAnotherDialog = new RunDialog(dlg, xToolkit, xDesktop);
    1040           0 :                             uno::Reference < awt::XTopWindowListener > xAnotherLifeCycle(pAnotherDialog);
    1041           0 :                             btn = pAnotherDialog->run();
    1042             : 
    1043           0 :                             gtk_widget_destroy( dlg );
    1044             :                         }
    1045           0 :                         g_free (gFileName);
    1046             : 
    1047           0 :                         if( btn == GTK_RESPONSE_YES )
    1048           0 :                             retVal = ExecutableDialogResults::OK;
    1049           0 :                     }
    1050             :                 }
    1051             :                 else
    1052           0 :                     retVal = ExecutableDialogResults::OK;
    1053           0 :                 break;
    1054             : 
    1055             :             case GTK_RESPONSE_CANCEL:
    1056           0 :                 retVal = ExecutableDialogResults::CANCEL;
    1057           0 :                 break;
    1058             : 
    1059             :             case 1: //PLAY
    1060             :                 {
    1061           0 :                     FilePickerEvent evt;
    1062           0 :                     evt.ElementId = PUSHBUTTON_PLAY;
    1063             :                     OSL_TRACE( "filter_changed, isn't it great %p", this);
    1064           0 :                     impl_controlStateChanged( evt );
    1065           0 :                     btn = GTK_RESPONSE_NO;
    1066             :                 }
    1067           0 :                 break;
    1068             : 
    1069             :             default:
    1070           0 :                 retVal = 0;
    1071           0 :                 break;
    1072             :         }
    1073             :     }
    1074             : 
    1075           0 :     if (mnHID_FolderChange)
    1076           0 :         g_signal_handler_disconnect(GTK_FILE_CHOOSER( m_pDialog ), mnHID_FolderChange);
    1077           0 :     if (mnHID_SelectionChange)
    1078           0 :         g_signal_handler_disconnect(GTK_FILE_CHOOSER( m_pDialog ), mnHID_SelectionChange);
    1079             : 
    1080           0 :     return retVal;
    1081             : }
    1082             : 
    1083             : // cf. offapi/com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.idl
    1084           0 : GtkWidget *SalGtkFilePicker::getWidget( sal_Int16 nControlId, GType *pType )
    1085             : {
    1086             :     OSL_TRACE("control id is %d", nControlId);
    1087           0 :     GType      tType = GTK_TYPE_TOGGLE_BUTTON; //prevent waring by initializing
    1088           0 :     GtkWidget *pWidget = 0;
    1089             : 
    1090             : #define MAP_TOGGLE( elem ) \
    1091             :         case ExtendedFilePickerElementIds::CHECKBOX_##elem: \
    1092             :             pWidget = m_pToggles[elem]; tType = GTK_TYPE_TOGGLE_BUTTON; \
    1093             :             break
    1094             : #define MAP_BUTTON( elem ) \
    1095             :         case ExtendedFilePickerElementIds::PUSHBUTTON_##elem: \
    1096             :             pWidget = m_pButtons[elem]; tType = GTK_TYPE_BUTTON; \
    1097             :             break
    1098             : #define MAP_LIST( elem ) \
    1099             :         case ExtendedFilePickerElementIds::LISTBOX_##elem: \
    1100             :             pWidget = m_pLists[elem]; tType = GTK_TYPE_COMBO_BOX; \
    1101             :             break
    1102             : #define MAP_LIST_LABEL( elem ) \
    1103             :         case ExtendedFilePickerElementIds::LISTBOX_##elem##_LABEL: \
    1104             :             pWidget = m_pListLabels[elem]; tType = GTK_TYPE_LABEL; \
    1105             :             break
    1106             : 
    1107           0 :     switch( nControlId )
    1108             :     {
    1109           0 :         MAP_TOGGLE( AUTOEXTENSION );
    1110           0 :         MAP_TOGGLE( PASSWORD );
    1111           0 :         MAP_TOGGLE( FILTEROPTIONS );
    1112           0 :         MAP_TOGGLE( READONLY );
    1113           0 :         MAP_TOGGLE( LINK );
    1114           0 :         MAP_TOGGLE( PREVIEW );
    1115           0 :         MAP_TOGGLE( SELECTION );
    1116           0 :         MAP_BUTTON( PLAY );
    1117           0 :         MAP_LIST( VERSION );
    1118           0 :         MAP_LIST( TEMPLATE );
    1119           0 :         MAP_LIST( IMAGE_TEMPLATE );
    1120           0 :         MAP_LIST_LABEL( VERSION );
    1121           0 :         MAP_LIST_LABEL( TEMPLATE );
    1122           0 :         MAP_LIST_LABEL( IMAGE_TEMPLATE );
    1123             :     default:
    1124             :         OSL_TRACE("Handle unknown control %d", nControlId);
    1125           0 :         break;
    1126             :     }
    1127             : #undef MAP
    1128             : 
    1129           0 :     if( pType )
    1130           0 :         *pType = tType;
    1131           0 :     return pWidget;
    1132             : }
    1133             : 
    1134             : // XFilePickerControlAccess functions
    1135             : 
    1136           0 : static void HackWidthToFirst(GtkComboBox *pWidget)
    1137             : {
    1138             :     GtkRequisition requisition;
    1139           0 :     gtk_widget_size_request(GTK_WIDGET(pWidget), &requisition);
    1140           0 :     gtk_widget_set_size_request(GTK_WIDGET(pWidget), requisition.width, -1);
    1141           0 : }
    1142             : 
    1143           0 : static void ComboBoxAppendText(GtkComboBox *pCombo, const OUString &rStr)
    1144             : {
    1145             :   GtkTreeIter aIter;
    1146           0 :   GtkListStore *pStore = GTK_LIST_STORE(gtk_combo_box_get_model(pCombo));
    1147           0 :   OString aStr = OUStringToOString(rStr, RTL_TEXTENCODING_UTF8);
    1148           0 :   gtk_list_store_append(pStore, &aIter);
    1149           0 :   gtk_list_store_set(pStore, &aIter, 0, aStr.getStr(), -1);
    1150           0 : }
    1151             : 
    1152           0 : void SalGtkFilePicker::HandleSetListValue(GtkComboBox *pWidget, sal_Int16 nControlAction, const uno::Any& rValue)
    1153             : {
    1154           0 :     switch (nControlAction)
    1155             :     {
    1156             :         case ControlActions::ADD_ITEM:
    1157             :             {
    1158           0 :                 OUString sItem;
    1159           0 :                 rValue >>= sItem;
    1160           0 :                 ComboBoxAppendText(pWidget, sItem);
    1161           0 :                 if (!bVersionWidthUnset)
    1162             :                 {
    1163           0 :                     HackWidthToFirst(pWidget);
    1164           0 :                     bVersionWidthUnset = true;
    1165           0 :                 }
    1166             :             }
    1167           0 :             break;
    1168             :         case ControlActions::ADD_ITEMS:
    1169             :             {
    1170           0 :                 Sequence< OUString > aStringList;
    1171           0 :                 rValue >>= aStringList;
    1172           0 :                 sal_Int32 nItemCount = aStringList.getLength();
    1173           0 :                 for (sal_Int32 i = 0; i < nItemCount; ++i)
    1174             :                 {
    1175           0 :                     ComboBoxAppendText(pWidget,aStringList[i]);
    1176           0 :                     if (!bVersionWidthUnset)
    1177             :                     {
    1178           0 :                         HackWidthToFirst(pWidget);
    1179           0 :                         bVersionWidthUnset = true;
    1180             :                     }
    1181           0 :                 }
    1182             :             }
    1183           0 :             break;
    1184             :         case ControlActions::DELETE_ITEM:
    1185             :             {
    1186           0 :                 sal_Int32 nPos=0;
    1187           0 :                 rValue >>= nPos;
    1188             : 
    1189             :                 GtkTreeIter aIter;
    1190           0 :                 GtkListStore *pStore = GTK_LIST_STORE(
    1191             :                         gtk_combo_box_get_model(GTK_COMBO_BOX(pWidget)));
    1192           0 :                 if(gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(pStore), &aIter, NULL, nPos))
    1193           0 :                     gtk_list_store_remove(pStore, &aIter);
    1194             :             }
    1195           0 :             break;
    1196             :         case ControlActions::DELETE_ITEMS:
    1197             :             {
    1198           0 :                 gtk_combo_box_set_active(pWidget, -1);
    1199           0 :                 GtkListStore *pStore = GTK_LIST_STORE(
    1200             :                         gtk_combo_box_get_model(GTK_COMBO_BOX(pWidget)));
    1201           0 :                 gtk_list_store_clear(pStore);
    1202             :             }
    1203           0 :             break;
    1204             :         case ControlActions::SET_SELECT_ITEM:
    1205             :             {
    1206           0 :                 sal_Int32 nPos=0;
    1207           0 :                 rValue >>= nPos;
    1208           0 :                 gtk_combo_box_set_active(pWidget, nPos);
    1209             :             }
    1210           0 :             break;
    1211             :         default:
    1212             :             OSL_TRACE("undocumented/unimplemented ControlAction for a list");
    1213           0 :             break;
    1214             :     }
    1215             : 
    1216             :     //I think its best to make it insensitive unless there is the chance to
    1217             :     //actually select something from the list.
    1218             :     gint nItems = gtk_tree_model_iter_n_children(
    1219           0 :                     gtk_combo_box_get_model(pWidget), NULL);
    1220           0 :     gtk_widget_set_sensitive(GTK_WIDGET(pWidget), nItems > 1 ? true : false);
    1221           0 : }
    1222             : 
    1223           0 : uno::Any SalGtkFilePicker::HandleGetListValue(GtkComboBox *pWidget, sal_Int16 nControlAction) const
    1224             : {
    1225           0 :     uno::Any aAny;
    1226           0 :     switch (nControlAction)
    1227             :     {
    1228             :         case ControlActions::GET_ITEMS:
    1229             :             {
    1230           0 :                 Sequence< OUString > aItemList;
    1231             : 
    1232           0 :                 GtkTreeModel *pTree = gtk_combo_box_get_model(pWidget);
    1233             :                 GtkTreeIter iter;
    1234           0 :                 if (gtk_tree_model_get_iter_first(pTree, &iter))
    1235             :                 {
    1236             :                     sal_Int32 nSize = gtk_tree_model_iter_n_children(
    1237           0 :                         pTree, NULL);
    1238             : 
    1239           0 :                     aItemList.realloc(nSize);
    1240           0 :                     for (sal_Int32 i=0; i < nSize; ++i)
    1241             :                     {
    1242             :                         gchar *item;
    1243             :                         gtk_tree_model_get(gtk_combo_box_get_model(pWidget),
    1244           0 :                             &iter, 0, &item, -1);
    1245           0 :                         aItemList[i] = OUString(item, strlen(item), RTL_TEXTENCODING_UTF8);
    1246           0 :                         g_free(item);
    1247           0 :                         gtk_tree_model_iter_next(pTree, &iter);
    1248             :                     }
    1249             :                 }
    1250           0 :                 aAny <<= aItemList;
    1251             :             }
    1252           0 :             break;
    1253             :         case ControlActions::GET_SELECTED_ITEM:
    1254             :             {
    1255             :                 GtkTreeIter iter;
    1256           0 :                 if (gtk_combo_box_get_active_iter(pWidget, &iter))
    1257             :                 {
    1258             :                         gchar *item;
    1259             :                         gtk_tree_model_get(gtk_combo_box_get_model(pWidget),
    1260           0 :                             &iter, 0, &item, -1);
    1261           0 :                         OUString sItem(item, strlen(item), RTL_TEXTENCODING_UTF8);
    1262           0 :                         aAny <<= sItem;
    1263           0 :                         g_free(item);
    1264             :                 }
    1265             :             }
    1266           0 :             break;
    1267             :         case ControlActions::GET_SELECTED_ITEM_INDEX:
    1268             :             {
    1269           0 :                 gint nActive = gtk_combo_box_get_active(pWidget);
    1270           0 :                 aAny <<= static_cast< sal_Int32 >(nActive);
    1271             :             }
    1272           0 :             break;
    1273             :         default:
    1274             :             OSL_TRACE("undocumented/unimplemented ControlAction for a list");
    1275           0 :             break;
    1276             :     }
    1277           0 :     return aAny;
    1278             : }
    1279             : 
    1280           0 : void SAL_CALL SalGtkFilePicker::setValue( sal_Int16 nControlId, sal_Int16 nControlAction, const uno::Any& rValue )
    1281             :     throw( uno::RuntimeException, std::exception )
    1282             : {
    1283           0 :     SolarMutexGuard g;
    1284             : 
    1285             :     OSL_ASSERT( m_pDialog != NULL );
    1286             : 
    1287             :     OSL_TRACE( "SETTING VALUE %d", nControlAction );
    1288             :     GType tType;
    1289             :     GtkWidget *pWidget;
    1290             : 
    1291           0 :     if( !( pWidget = getWidget( nControlId, &tType ) ) )
    1292             :         OSL_TRACE("enable unknown control %d", nControlId);
    1293           0 :     else if( tType == GTK_TYPE_TOGGLE_BUTTON )
    1294             :     {
    1295           0 :         bool bChecked = false;
    1296           0 :         rValue >>= bChecked;
    1297           0 :         gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( pWidget ), bChecked );
    1298             :     }
    1299           0 :     else if( tType == GTK_TYPE_COMBO_BOX )
    1300           0 :         HandleSetListValue(GTK_COMBO_BOX(pWidget), nControlAction, rValue);
    1301             :     else
    1302             :     {
    1303             :         OSL_TRACE("Can't set value on button / list %d %d\n",
    1304             :             nControlId, nControlAction);
    1305           0 :     }
    1306           0 : }
    1307             : 
    1308           0 : uno::Any SAL_CALL SalGtkFilePicker::getValue( sal_Int16 nControlId, sal_Int16 nControlAction )
    1309             :     throw( uno::RuntimeException, std::exception )
    1310             : {
    1311           0 :     SolarMutexGuard g;
    1312             : 
    1313             :     OSL_ASSERT( m_pDialog != NULL );
    1314             : 
    1315           0 :     uno::Any aRetval;
    1316             : 
    1317             :     GType tType;
    1318             :     GtkWidget *pWidget;
    1319             : 
    1320           0 :     if( !( pWidget = getWidget( nControlId, &tType ) ) )
    1321             :         OSL_TRACE("enable unknown control %d", nControlId);
    1322           0 :     else if( tType == GTK_TYPE_TOGGLE_BUTTON )
    1323           0 :         aRetval <<= bool( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( pWidget ) ) );
    1324           0 :     else if( tType == GTK_TYPE_COMBO_BOX )
    1325           0 :         aRetval = HandleGetListValue(GTK_COMBO_BOX(pWidget), nControlAction);
    1326             :     else
    1327             :         OSL_TRACE("Can't get value on button / list %d %d\n",
    1328             :             nControlId, nControlAction );
    1329             : 
    1330           0 :     return aRetval;
    1331             : }
    1332             : 
    1333           0 : void SAL_CALL SalGtkFilePicker::enableControl( sal_Int16 nControlId, sal_Bool bEnable )
    1334             : throw( uno::RuntimeException, std::exception )
    1335             : {
    1336           0 :     SolarMutexGuard g;
    1337             : 
    1338             :     OSL_ASSERT( m_pDialog != NULL );
    1339             : 
    1340             :     GtkWidget *pWidget;
    1341             : 
    1342           0 :     if ( nControlId == ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR )
    1343           0 :         gtk_expander_set_expanded( GTK_EXPANDER( m_pFilterExpander ), bEnable );
    1344           0 :     else if( ( pWidget = getWidget( nControlId ) ) )
    1345             :     {
    1346           0 :         if( bEnable )
    1347             :         {
    1348             :             OSL_TRACE( "enable" );
    1349           0 :             gtk_widget_set_sensitive( pWidget, true );
    1350             :         }
    1351             :         else
    1352             :         {
    1353             :             OSL_TRACE( "disable" );
    1354           0 :             gtk_widget_set_sensitive( pWidget, false );
    1355             :         }
    1356             :     }
    1357             :     else
    1358           0 :         OSL_TRACE("enable unknown control %d", nControlId );
    1359           0 : }
    1360             : 
    1361           0 : void SAL_CALL SalGtkFilePicker::setLabel( sal_Int16 nControlId, const OUString& rLabel )
    1362             :     throw( uno::RuntimeException, std::exception )
    1363             : {
    1364           0 :     SolarMutexGuard g;
    1365             : 
    1366             :     OSL_ASSERT( m_pDialog != NULL );
    1367             : 
    1368             :     GType tType;
    1369             :     GtkWidget *pWidget;
    1370             : 
    1371           0 :     if( !( pWidget = getWidget( nControlId, &tType ) ) )
    1372             :     {
    1373             :           OSL_TRACE("Set label on unknown control %d", nControlId);
    1374           0 :         return;
    1375             :     }
    1376             : 
    1377           0 :     OString aTxt = OUStringToOString( rLabel.replace('~', '_'), RTL_TEXTENCODING_UTF8 );
    1378           0 :     if (nControlId == ExtendedFilePickerElementIds::PUSHBUTTON_PLAY)
    1379             :     {
    1380             : #ifdef GTK_STOCK_MEDIA_PLAY
    1381           0 :         if (msPlayLabel.isEmpty())
    1382           0 :             msPlayLabel = rLabel;
    1383           0 :         if (msPlayLabel == rLabel)
    1384           0 :             gtk_button_set_label(GTK_BUTTON(pWidget), GTK_STOCK_MEDIA_PLAY);
    1385             :         else
    1386           0 :             gtk_button_set_label(GTK_BUTTON(pWidget), GTK_STOCK_MEDIA_STOP);
    1387             : #else
    1388             :         gtk_button_set_label(GTK_BUTTON(pWidget), aTxt.getStr());
    1389             : #endif
    1390             :     }
    1391           0 :     else if( tType == GTK_TYPE_TOGGLE_BUTTON || tType == GTK_TYPE_BUTTON || tType == GTK_TYPE_LABEL )
    1392             :         g_object_set( pWidget, "label", aTxt.getStr(),
    1393           0 :                       "use_underline", true, (char *)NULL );
    1394             :     else
    1395           0 :         OSL_TRACE("Can't set label on list");
    1396             : }
    1397             : 
    1398           0 : OUString SAL_CALL SalGtkFilePicker::getLabel( sal_Int16 nControlId )
    1399             :     throw( uno::RuntimeException, std::exception )
    1400             : {
    1401           0 :     SolarMutexGuard g;
    1402             : 
    1403             :     OSL_ASSERT( m_pDialog != NULL );
    1404             : 
    1405             :     GType tType;
    1406           0 :     OString aTxt;
    1407             :     GtkWidget *pWidget;
    1408             : 
    1409           0 :     if( !( pWidget = getWidget( nControlId, &tType ) ) )
    1410             :         OSL_TRACE("Get label on unknown control %d", nControlId);
    1411           0 :     else if( tType == GTK_TYPE_TOGGLE_BUTTON || tType == GTK_TYPE_BUTTON || tType == GTK_TYPE_LABEL )
    1412           0 :         aTxt = gtk_button_get_label( GTK_BUTTON( pWidget ) );
    1413             :     else
    1414             :         OSL_TRACE("Can't get label on list");
    1415             : 
    1416           0 :     return OStringToOUString( aTxt, RTL_TEXTENCODING_UTF8 );
    1417             : }
    1418             : 
    1419             : // XFilePreview functions
    1420             : 
    1421           0 : uno::Sequence<sal_Int16> SAL_CALL SalGtkFilePicker::getSupportedImageFormats() throw( uno::RuntimeException, std::exception )
    1422             : {
    1423           0 :     SolarMutexGuard g;
    1424             : 
    1425             :     OSL_ASSERT( m_pDialog != NULL );
    1426             : 
    1427             :     // TODO return m_pImpl->getSupportedImageFormats();
    1428           0 :     return uno::Sequence<sal_Int16>();
    1429             : }
    1430             : 
    1431           0 : sal_Int32 SAL_CALL SalGtkFilePicker::getTargetColorDepth() throw( uno::RuntimeException, std::exception )
    1432             : {
    1433           0 :     SolarMutexGuard g;
    1434             : 
    1435             :     OSL_ASSERT( m_pDialog != NULL );
    1436             : 
    1437             :     // TODO return m_pImpl->getTargetColorDepth();
    1438           0 :     return 0;
    1439             : }
    1440             : 
    1441           0 : sal_Int32 SAL_CALL SalGtkFilePicker::getAvailableWidth() throw( uno::RuntimeException, std::exception )
    1442             : {
    1443           0 :     SolarMutexGuard g;
    1444             : 
    1445             :     OSL_ASSERT( m_pDialog != NULL );
    1446             : 
    1447           0 :     return m_PreviewImageWidth;
    1448             : }
    1449             : 
    1450           0 : sal_Int32 SAL_CALL SalGtkFilePicker::getAvailableHeight() throw( uno::RuntimeException, std::exception )
    1451             : {
    1452           0 :     SolarMutexGuard g;
    1453             : 
    1454             :     OSL_ASSERT( m_pDialog != NULL );
    1455             : 
    1456           0 :     return m_PreviewImageHeight;
    1457             : }
    1458             : 
    1459           0 : void SAL_CALL SalGtkFilePicker::setImage( sal_Int16 /*aImageFormat*/, const uno::Any& /*aImage*/ )
    1460             :     throw( lang::IllegalArgumentException, uno::RuntimeException, std::exception )
    1461             : {
    1462           0 :     SolarMutexGuard g;
    1463             : 
    1464           0 :     OSL_ASSERT( m_pDialog != NULL );
    1465             : 
    1466             :     // TODO m_pImpl->setImage( aImageFormat, aImage );
    1467           0 : }
    1468             : 
    1469           0 : void SalGtkFilePicker::implChangeType( GtkTreeSelection *selection )
    1470             : {
    1471           0 :     OUString aLabel = getResString( FILE_PICKER_FILE_TYPE );
    1472             : 
    1473             :     GtkTreeIter iter;
    1474             :     GtkTreeModel *model;
    1475           0 :     if (gtk_tree_selection_get_selected (selection, &model, &iter))
    1476             :     {
    1477             :         gchar *title;
    1478           0 :         gtk_tree_model_get (model, &iter, 2, &title, -1);
    1479           0 :         aLabel += ": ";
    1480           0 :         aLabel += OUString( title, strlen(title), RTL_TEXTENCODING_UTF8 );
    1481           0 :         g_free (title);
    1482             :     }
    1483           0 :     gtk_expander_set_label (GTK_EXPANDER (m_pFilterExpander),
    1484           0 :         OUStringToOString( aLabel, RTL_TEXTENCODING_UTF8 ).getStr());
    1485           0 :     FilePickerEvent evt;
    1486           0 :     evt.ElementId = LISTBOX_FILTER;
    1487           0 :     impl_controlStateChanged( evt );
    1488           0 : }
    1489             : 
    1490           0 : void SalGtkFilePicker::type_changed_cb( GtkTreeSelection *selection, SalGtkFilePicker *pobjFP )
    1491             : {
    1492           0 :     pobjFP->implChangeType(selection);
    1493           0 : }
    1494             : 
    1495           0 : void SalGtkFilePicker::unselect_type()
    1496             : {
    1497           0 :     gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_pFilterView)));
    1498           0 : }
    1499             : 
    1500           0 : void SalGtkFilePicker::expander_changed_cb( GtkExpander *expander, SalGtkFilePicker *pobjFP )
    1501             : {
    1502           0 :     if (gtk_expander_get_expanded(expander))
    1503           0 :         pobjFP->unselect_type();
    1504           0 : }
    1505             : 
    1506           0 : void SalGtkFilePicker::filter_changed_cb( GtkFileChooser *, GParamSpec *,
    1507             :     SalGtkFilePicker *pobjFP )
    1508             : {
    1509           0 :     FilePickerEvent evt;
    1510           0 :     evt.ElementId = LISTBOX_FILTER;
    1511             :     OSL_TRACE( "filter_changed, isn't it great %p", pobjFP );
    1512           0 :     pobjFP->impl_controlStateChanged( evt );
    1513           0 : }
    1514             : 
    1515           0 : void SalGtkFilePicker::folder_changed_cb( GtkFileChooser *, SalGtkFilePicker *pobjFP )
    1516             : {
    1517           0 :     FilePickerEvent evt;
    1518             :     OSL_TRACE( "folder_changed, isn't it great %p", pobjFP );
    1519           0 :     pobjFP->impl_directoryChanged( evt );
    1520           0 : }
    1521             : 
    1522           0 : void SalGtkFilePicker::selection_changed_cb( GtkFileChooser *, SalGtkFilePicker *pobjFP )
    1523             : {
    1524           0 :     FilePickerEvent evt;
    1525             :     OSL_TRACE( "selection_changed, isn't it great %p", pobjFP );
    1526           0 :     pobjFP->impl_fileSelectionChanged( evt );
    1527           0 : }
    1528             : 
    1529           0 : void SalGtkFilePicker::update_preview_cb( GtkFileChooser *file_chooser, SalGtkFilePicker* pobjFP )
    1530             : {
    1531             :     GtkWidget *preview;
    1532             :     char *filename;
    1533             :     GdkPixbuf *pixbuf;
    1534           0 :     gboolean have_preview = false;
    1535             : 
    1536           0 :     preview = pobjFP->m_pPreview;
    1537           0 :     filename = gtk_file_chooser_get_preview_filename( file_chooser );
    1538             : 
    1539           0 :     if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( pobjFP->m_pToggles[PREVIEW] ) ) && g_file_test( filename, G_FILE_TEST_IS_REGULAR ) )
    1540             :     {
    1541             :         pixbuf = gdk_pixbuf_new_from_file_at_size(
    1542             :                 filename,
    1543             :                 pobjFP->m_PreviewImageWidth,
    1544           0 :                 pobjFP->m_PreviewImageHeight, NULL );
    1545             : 
    1546           0 :         have_preview = ( pixbuf != NULL );
    1547             : 
    1548           0 :         gtk_image_set_from_pixbuf( GTK_IMAGE( preview ), pixbuf );
    1549           0 :         if( pixbuf )
    1550           0 :             g_object_unref( G_OBJECT( pixbuf ) );
    1551             : 
    1552             :     }
    1553             : 
    1554           0 :     gtk_file_chooser_set_preview_widget_active( file_chooser, have_preview );
    1555             : 
    1556           0 :     if( filename )
    1557           0 :         g_free( filename );
    1558           0 : }
    1559             : 
    1560           0 : sal_Bool SAL_CALL SalGtkFilePicker::setShowState( sal_Bool bShowState ) throw( uno::RuntimeException, std::exception )
    1561             : {
    1562           0 :     SolarMutexGuard g;
    1563             : 
    1564             :     OSL_ASSERT( m_pDialog != NULL );
    1565             : 
    1566             :     // TODO return m_pImpl->setShowState( bShowState );
    1567           0 :     if( bool(bShowState) != mbPreviewState )
    1568             :     {
    1569           0 :         if( bShowState )
    1570             :         {
    1571             :             // Show
    1572           0 :             if( !mHID_Preview )
    1573             :             {
    1574           0 :                 mHID_Preview = g_signal_connect(
    1575             :                     GTK_FILE_CHOOSER( m_pDialog ), "update-preview",
    1576           0 :                     G_CALLBACK( update_preview_cb ), ( gpointer )this );
    1577             :             }
    1578           0 :             gtk_widget_show( m_pPreview );
    1579             :         }
    1580             :         else
    1581             :         {
    1582             :             // Hide
    1583           0 :             gtk_widget_hide( m_pPreview );
    1584             :         }
    1585             : 
    1586             :         // also emit the signal
    1587           0 :         g_signal_emit_by_name( G_OBJECT( m_pDialog ), "update-preview" );
    1588             : 
    1589           0 :         mbPreviewState = bShowState;
    1590             :     }
    1591           0 :     return true;
    1592             : }
    1593             : 
    1594           0 : sal_Bool SAL_CALL SalGtkFilePicker::getShowState() throw( uno::RuntimeException, std::exception )
    1595             : {
    1596           0 :     SolarMutexGuard g;
    1597             : 
    1598             :     OSL_ASSERT( m_pDialog != NULL );
    1599             : 
    1600           0 :     return mbPreviewState;
    1601             : }
    1602             : 
    1603             : // XInitialization
    1604             : 
    1605           0 : void SAL_CALL SalGtkFilePicker::initialize( const uno::Sequence<uno::Any>& aArguments )
    1606             :     throw( uno::Exception, uno::RuntimeException, std::exception )
    1607             : {
    1608             :     // parameter checking
    1609           0 :     uno::Any aAny;
    1610           0 :     if( 0 == aArguments.getLength() )
    1611             :         throw lang::IllegalArgumentException(
    1612             :             OUString( "no arguments" ),
    1613           0 :             static_cast<XFilePicker2*>( this ), 1 );
    1614             : 
    1615           0 :     aAny = aArguments[0];
    1616             : 
    1617           0 :     if( ( aAny.getValueType() != ::getCppuType( ( sal_Int16* )0 ) ) &&
    1618           0 :          (aAny.getValueType() != ::getCppuType( ( sal_Int8* )0 ) ) )
    1619             :          throw lang::IllegalArgumentException(
    1620             :             OUString( "invalid argument type" ),
    1621           0 :             static_cast<XFilePicker2*>( this ), 1 );
    1622             : 
    1623           0 :     sal_Int16 templateId = -1;
    1624           0 :     aAny >>= templateId;
    1625             : 
    1626           0 :     GtkFileChooserAction eAction = GTK_FILE_CHOOSER_ACTION_OPEN;
    1627           0 :     const gchar *first_button_text = GTK_STOCK_OPEN;
    1628             : 
    1629           0 :     SolarMutexGuard g;
    1630             : 
    1631             :     //   TODO: extract full semantic from
    1632             :     //   svtools/source/filepicker/filepicker.cxx (getWinBits)
    1633           0 :     switch( templateId )
    1634             :     {
    1635             :         case FILEOPEN_SIMPLE:
    1636           0 :             eAction = GTK_FILE_CHOOSER_ACTION_OPEN;
    1637           0 :             first_button_text = GTK_STOCK_OPEN;
    1638             :             OSL_TRACE( "3all true" );
    1639           0 :             break;
    1640             :         case FILESAVE_SIMPLE:
    1641           0 :             eAction = GTK_FILE_CHOOSER_ACTION_SAVE;
    1642           0 :             first_button_text = GTK_STOCK_SAVE;
    1643             :             OSL_TRACE( "2all true" );
    1644           0 :                 break;
    1645             :         case FILESAVE_AUTOEXTENSION_PASSWORD:
    1646           0 :             eAction = GTK_FILE_CHOOSER_ACTION_SAVE;
    1647           0 :             first_button_text = GTK_STOCK_SAVE;
    1648           0 :             mbToggleVisibility[PASSWORD] = true;
    1649             :             OSL_TRACE( "1all true" );
    1650             :             // TODO
    1651           0 :             break;
    1652             :         case FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS:
    1653           0 :             eAction = GTK_FILE_CHOOSER_ACTION_SAVE;
    1654           0 :             first_button_text = GTK_STOCK_SAVE;
    1655           0 :             mbToggleVisibility[PASSWORD] = true;
    1656           0 :             mbToggleVisibility[FILTEROPTIONS] = true;
    1657             :             OSL_TRACE( "4all true" );
    1658             :             // TODO
    1659           0 :                 break;
    1660             :         case FILESAVE_AUTOEXTENSION_SELECTION:
    1661           0 :             eAction = GTK_FILE_CHOOSER_ACTION_SAVE; // SELECT_FOLDER ?
    1662           0 :             first_button_text = GTK_STOCK_SAVE;
    1663           0 :             mbToggleVisibility[SELECTION] = true;
    1664             :             OSL_TRACE( "5all true" );
    1665             :             // TODO
    1666           0 :                 break;
    1667             :         case FILESAVE_AUTOEXTENSION_TEMPLATE:
    1668           0 :             eAction = GTK_FILE_CHOOSER_ACTION_SAVE;
    1669           0 :             first_button_text = GTK_STOCK_SAVE;
    1670           0 :             mbListVisibility[TEMPLATE] = true;
    1671             :             OSL_TRACE( "6all true" );
    1672             :             // TODO
    1673           0 :                 break;
    1674             :         case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
    1675           0 :             eAction = GTK_FILE_CHOOSER_ACTION_OPEN;
    1676           0 :             first_button_text = GTK_STOCK_OPEN;
    1677           0 :             mbToggleVisibility[LINK] = true;
    1678           0 :             mbToggleVisibility[PREVIEW] = true;
    1679           0 :             mbListVisibility[IMAGE_TEMPLATE] = true;
    1680             :             // TODO
    1681           0 :                 break;
    1682             :         case FILEOPEN_PLAY:
    1683           0 :             eAction = GTK_FILE_CHOOSER_ACTION_OPEN;
    1684           0 :             first_button_text = GTK_STOCK_OPEN;
    1685           0 :             mbButtonVisibility[PLAY] = true;
    1686             :             // TODO
    1687           0 :                 break;
    1688             :         case FILEOPEN_READONLY_VERSION:
    1689           0 :             eAction = GTK_FILE_CHOOSER_ACTION_OPEN;
    1690           0 :             first_button_text = GTK_STOCK_OPEN;
    1691           0 :             mbToggleVisibility[READONLY] = true;
    1692           0 :             mbListVisibility[VERSION] = true;
    1693           0 :             break;
    1694             :         case FILEOPEN_LINK_PREVIEW:
    1695           0 :             eAction = GTK_FILE_CHOOSER_ACTION_OPEN;
    1696           0 :             first_button_text = GTK_STOCK_OPEN;
    1697           0 :             mbToggleVisibility[LINK] = true;
    1698           0 :             mbToggleVisibility[PREVIEW] = true;
    1699             :             // TODO
    1700           0 :                 break;
    1701             :         case FILESAVE_AUTOEXTENSION:
    1702           0 :             eAction = GTK_FILE_CHOOSER_ACTION_SAVE;
    1703           0 :             first_button_text = GTK_STOCK_SAVE;
    1704             :             OSL_TRACE( "7all true" );
    1705             :             // TODO
    1706           0 :                 break;
    1707             :         default:
    1708             :                 throw lang::IllegalArgumentException(
    1709             :                 OUString( "Unknown template" ),
    1710             :                 static_cast< XFilePicker2* >( this ),
    1711           0 :                 1 );
    1712             :     }
    1713             : 
    1714           0 :     if( GTK_FILE_CHOOSER_ACTION_SAVE == eAction )
    1715             :     {
    1716           0 :         OUString aFilePickerTitle(getResString( FILE_PICKER_TITLE_SAVE ));
    1717           0 :         gtk_window_set_title ( GTK_WINDOW( m_pDialog ),
    1718           0 :             OUStringToOString( aFilePickerTitle, RTL_TEXTENCODING_UTF8 ).getStr() );
    1719             :     }
    1720             : 
    1721           0 :     gtk_file_chooser_set_action( GTK_FILE_CHOOSER( m_pDialog ), eAction);
    1722           0 :     dialog_remove_buttons( GTK_DIALOG( m_pDialog ) );
    1723           0 :     gtk_dialog_add_button( GTK_DIALOG( m_pDialog ), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL );
    1724           0 :     for( int nTVIndex = 0; nTVIndex < BUTTON_LAST; nTVIndex++ )
    1725             :     {
    1726           0 :         if( mbButtonVisibility[nTVIndex] )
    1727             :         {
    1728             : #ifdef GTK_STOCK_MEDIA_PLAY
    1729           0 :             m_pButtons[ nTVIndex ] = gtk_dialog_add_button( GTK_DIALOG( m_pDialog ), GTK_STOCK_MEDIA_PLAY, 1 );
    1730             : #else
    1731             :             OString aPlay = OUStringToOString( getResString( PUSHBUTTON_PLAY ), RTL_TEXTENCODING_UTF8 );
    1732             :             m_pButtons[ nTVIndex ] = gtk_dialog_add_button( GTK_DIALOG( m_pDialog ), aPlay.getStr(), 1 );
    1733             : #endif
    1734             :         }
    1735             :     }
    1736           0 :     gtk_dialog_add_button( GTK_DIALOG( m_pDialog ), first_button_text, GTK_RESPONSE_ACCEPT );
    1737             : 
    1738           0 :     gtk_dialog_set_default_response( GTK_DIALOG (m_pDialog), GTK_RESPONSE_ACCEPT );
    1739             : 
    1740             :     // Setup special flags
    1741           0 :     for( int nTVIndex = 0; nTVIndex < TOGGLE_LAST; nTVIndex++ )
    1742             :     {
    1743           0 :         if( mbToggleVisibility[nTVIndex] )
    1744           0 :             gtk_widget_show( m_pToggles[ nTVIndex ] );
    1745             :     }
    1746             : 
    1747           0 :     for( int nTVIndex = 0; nTVIndex < LIST_LAST; nTVIndex++ )
    1748             :     {
    1749           0 :         if( mbListVisibility[nTVIndex] )
    1750             :         {
    1751           0 :             gtk_widget_set_sensitive( m_pLists[ nTVIndex ], false );
    1752           0 :             gtk_widget_show( m_pLists[ nTVIndex ] );
    1753           0 :             gtk_widget_show( m_pListLabels[ nTVIndex ] );
    1754           0 :             gtk_widget_show( m_pAligns[ nTVIndex ] );
    1755           0 :             gtk_widget_show( m_pHBoxs[ nTVIndex ] );
    1756             :         }
    1757           0 :     }
    1758           0 : }
    1759             : 
    1760           0 : void SalGtkFilePicker::preview_toggled_cb( GObject *cb, SalGtkFilePicker* pobjFP )
    1761             : {
    1762           0 :     if( pobjFP->mbToggleVisibility[PREVIEW] )
    1763           0 :         pobjFP->setShowState( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( cb ) ) );
    1764           0 : }
    1765             : 
    1766             : // XCancellable
    1767             : 
    1768           0 : void SAL_CALL SalGtkFilePicker::cancel() throw( uno::RuntimeException, std::exception )
    1769             : {
    1770           0 :     SolarMutexGuard g;
    1771             : 
    1772           0 :     OSL_ASSERT( m_pDialog != NULL );
    1773             : 
    1774             :     // TODO m_pImpl->cancel();
    1775           0 : }
    1776             : 
    1777             : // Misc
    1778             : 
    1779           0 : void SalGtkFilePicker::SetCurFilter( const OUString& rFilter )
    1780             : {
    1781             :     // Get all the filters already added
    1782           0 :     GSList *filters = gtk_file_chooser_list_filters ( GTK_FILE_CHOOSER( m_pDialog ) );
    1783           0 :     bool bFound = false;
    1784             : 
    1785           0 :     for( GSList *iter = filters; !bFound && iter; iter = iter->next )
    1786             :     {
    1787           0 :         GtkFileFilter* pFilter = reinterpret_cast<GtkFileFilter *>( iter->data );
    1788           0 :         G_CONST_RETURN gchar * filtername = gtk_file_filter_get_name( pFilter );
    1789           0 :         OUString sFilterName( filtername, strlen( filtername ), RTL_TEXTENCODING_UTF8 );
    1790             : 
    1791           0 :         OUString aShrunkName = shrinkFilterName( rFilter );
    1792           0 :         if( aShrunkName.equals( sFilterName) )
    1793             :         {
    1794             :             OSL_TRACE( "actually setting %s", filtername );
    1795           0 :             gtk_file_chooser_set_filter( GTK_FILE_CHOOSER( m_pDialog ), pFilter );
    1796           0 :             bFound = true;
    1797             :         }
    1798           0 :     }
    1799             : 
    1800           0 :     g_slist_free( filters );
    1801           0 : }
    1802             : 
    1803             : extern "C"
    1804             : {
    1805             : static gboolean
    1806           0 : case_insensitive_filter (const GtkFileFilterInfo *filter_info, gpointer data)
    1807             : {
    1808           0 :     gboolean bRetval = false;
    1809           0 :     const char *pFilter = (const char *) data;
    1810             : 
    1811           0 :     g_return_val_if_fail( data != NULL, false );
    1812           0 :     g_return_val_if_fail( filter_info != NULL, false );
    1813             : 
    1814           0 :     if( !filter_info->uri )
    1815           0 :         return false;
    1816             : 
    1817           0 :     const char *pExtn = strrchr( filter_info->uri, '.' );
    1818           0 :     if( !pExtn )
    1819           0 :         return false;
    1820           0 :     pExtn++;
    1821             : 
    1822           0 :     if( !g_ascii_strcasecmp( pFilter, pExtn ) )
    1823           0 :         bRetval = true;
    1824             : 
    1825             :     SAL_INFO( "vcl.gtk", "'" << filter_info->uri << "' match extn '" << pExtn << "' vs '" << pFilter << "' yeilds " << bRetval );
    1826             : 
    1827           0 :     return bRetval;
    1828             : }
    1829             : }
    1830             : 
    1831           0 : GtkFileFilter* SalGtkFilePicker::implAddFilter( const OUString& rFilter, const OUString& rType )
    1832             : {
    1833           0 :     GtkFileFilter *filter = gtk_file_filter_new();
    1834             : 
    1835           0 :     OUString aShrunkName = shrinkFilterName( rFilter );
    1836           0 :     OString aFilterName = OUStringToOString( aShrunkName, RTL_TEXTENCODING_UTF8 );
    1837           0 :     gtk_file_filter_set_name( filter, aFilterName.getStr() );
    1838             : 
    1839           0 :     static const OUString aStarDot( "*." );
    1840           0 :     OUString aTokens;
    1841             : 
    1842           0 :     bool bAllGlob = rType.equalsAscii( "*.*" ) || rType.equalsAscii( "*" );
    1843           0 :     if (bAllGlob)
    1844           0 :         gtk_file_filter_add_pattern( filter, "*" );
    1845             :     else
    1846             :     {
    1847           0 :         sal_Int32 nIndex = 0;
    1848           0 :         OUString aToken;
    1849           0 :         do
    1850             :         {
    1851           0 :             aToken = rType.getToken( 0, ';', nIndex );
    1852             :             // Assume all have the "*.<extn>" syntax
    1853           0 :             sal_Int32 nStarDot = aToken.lastIndexOf( aStarDot );
    1854           0 :             if (nStarDot >= 0)
    1855           0 :                 aToken = aToken.copy( nStarDot + 2 );
    1856           0 :             if (!aToken.isEmpty())
    1857             :             {
    1858           0 :                 if (!aTokens.isEmpty())
    1859           0 :                     aTokens += ",";
    1860           0 :                 aTokens = aTokens += aToken;
    1861             :                 gtk_file_filter_add_custom (filter, GTK_FILE_FILTER_URI,
    1862             :                     case_insensitive_filter,
    1863           0 :                     g_strdup( OUStringToOString(aToken, RTL_TEXTENCODING_UTF8).getStr() ),
    1864           0 :                     (GDestroyNotify) g_free );
    1865             : 
    1866             :                 OSL_TRACE( "fustering with %s", OUStringToOString( aToken, RTL_TEXTENCODING_UTF8 ).getStr());
    1867             :             }
    1868             : #if OSL_DEBUG_LEVEL > 0
    1869             :             else
    1870             :             {
    1871             :                 g_warning( "Duff filter token '%s'\n",
    1872             :                     OUStringToOString(
    1873             :                         rType.getToken( 0, ';', nIndex ), RTL_TEXTENCODING_UTF8 ).getStr() );
    1874             :             }
    1875             : #endif
    1876             :         }
    1877           0 :         while( nIndex >= 0 );
    1878             :     }
    1879             : 
    1880           0 :     gtk_file_chooser_add_filter( GTK_FILE_CHOOSER( m_pDialog ), filter );
    1881             : 
    1882           0 :     if (!bAllGlob)
    1883             :     {
    1884             :         GtkTreeIter iter;
    1885           0 :         gtk_list_store_append (m_pFilterStore, &iter);
    1886             :         gtk_list_store_set (m_pFilterStore, &iter,
    1887             :             0, OUStringToOString(shrinkFilterName( rFilter, true ), RTL_TEXTENCODING_UTF8).getStr(),
    1888             :             1, OUStringToOString(aTokens, RTL_TEXTENCODING_UTF8).getStr(),
    1889             :             2, aFilterName.getStr(),
    1890             :             3, OUStringToOString(rType, RTL_TEXTENCODING_UTF8).getStr(),
    1891           0 :             -1);
    1892             :     }
    1893           0 :     return filter;
    1894             : }
    1895             : 
    1896           0 : void SalGtkFilePicker::implAddFilterGroup( const OUString& /*_rFilter*/, const Sequence< StringPair >& _rFilters )
    1897             : {
    1898             :     // Gtk+ has no filter group concept I think so ...
    1899             :     // implAddFilter( _rFilter, String() );
    1900           0 :     const StringPair* pSubFilters   = _rFilters.getConstArray();
    1901           0 :     const StringPair* pSubFiltersEnd = pSubFilters + _rFilters.getLength();
    1902           0 :     for( ; pSubFilters != pSubFiltersEnd; ++pSubFilters )
    1903           0 :         implAddFilter( pSubFilters->First, pSubFilters->Second );
    1904           0 : }
    1905             : 
    1906           0 : void SalGtkFilePicker::SetFilters()
    1907             : {
    1908           0 :     if (m_aInitialFilter.isEmpty())
    1909           0 :         m_aInitialFilter = m_aCurrentFilter;
    1910             : 
    1911           0 :     OUString sPseudoFilter;
    1912           0 :     if( GTK_FILE_CHOOSER_ACTION_SAVE == gtk_file_chooser_get_action( GTK_FILE_CHOOSER( m_pDialog ) ) )
    1913             :     {
    1914           0 :         std::set<OUString> aAllFormats;
    1915           0 :         if( m_pFilterList && !m_pFilterList->empty() )
    1916             :         {
    1917           0 :             for (   FilterList::iterator aListIter = m_pFilterList->begin();
    1918           0 :                     aListIter != m_pFilterList->end();
    1919             :                     ++aListIter
    1920             :                 )
    1921             :             {
    1922           0 :                 if( aListIter->hasSubFilters() )
    1923             :                 {   // it's a filter group
    1924           0 :                     UnoFilterList aSubFilters;
    1925           0 :                     aListIter->getSubFilters( aSubFilters );
    1926           0 :                     const StringPair* pSubFilters   = aSubFilters.getConstArray();
    1927           0 :                     const StringPair* pSubFiltersEnd = pSubFilters + aSubFilters.getLength();
    1928           0 :                     for( ; pSubFilters != pSubFiltersEnd; ++pSubFilters )
    1929           0 :                         aAllFormats.insert(pSubFilters->Second);
    1930             :                 }
    1931             :                 else
    1932           0 :                     aAllFormats.insert(aListIter->getFilter());
    1933             :             }
    1934             :         }
    1935           0 :         if (aAllFormats.size() > 1)
    1936             :         {
    1937           0 :             OUString sAllFilter;
    1938           0 :             std::set<OUString>::const_iterator aEnd = aAllFormats.end();
    1939           0 :             for (std::set<OUString>::const_iterator aIter = aAllFormats.begin(); aIter != aEnd; ++aIter)
    1940             :             {
    1941           0 :                 if (!sAllFilter.isEmpty())
    1942           0 :                     sAllFilter += OUString(';');
    1943           0 :                 sAllFilter += *aIter;
    1944             :             }
    1945           0 :             sPseudoFilter = getResString(FILE_PICKER_ALLFORMATS);
    1946           0 :             m_pPseudoFilter = implAddFilter( sPseudoFilter, sAllFilter );
    1947           0 :         }
    1948             :     }
    1949             : 
    1950           0 :     if( m_pFilterList && !m_pFilterList->empty() )
    1951             :     {
    1952           0 :         for (   FilterList::iterator aListIter = m_pFilterList->begin();
    1953           0 :                 aListIter != m_pFilterList->end();
    1954             :                 ++aListIter
    1955             :             )
    1956             :         {
    1957           0 :             if( aListIter->hasSubFilters() )
    1958             :             {   // it's a filter group
    1959             : 
    1960           0 :                 UnoFilterList aSubFilters;
    1961           0 :                 aListIter->getSubFilters( aSubFilters );
    1962             : 
    1963           0 :                 implAddFilterGroup( aListIter->getTitle(), aSubFilters );
    1964             :             }
    1965             :             else
    1966             :             {
    1967             :                 // it's a single filter
    1968             : 
    1969           0 :                 implAddFilter( aListIter->getTitle(), aListIter->getFilter() );
    1970             :             }
    1971             :         }
    1972             :     }
    1973             : 
    1974           0 :     if (gtk_tree_model_iter_n_children(GTK_TREE_MODEL(m_pFilterStore), NULL)) //If m_pFilterStore is not empty
    1975           0 :         gtk_widget_show( m_pFilterExpander );
    1976             :     else
    1977           0 :         gtk_widget_hide( m_pFilterExpander );
    1978             : 
    1979             :     // set the default filter
    1980           0 :     if (!sPseudoFilter.isEmpty())
    1981           0 :         SetCurFilter( sPseudoFilter );
    1982           0 :     else if(!m_aCurrentFilter.isEmpty())
    1983           0 :         SetCurFilter( m_aCurrentFilter );
    1984             : 
    1985           0 :     OSL_TRACE( "end setting filters");
    1986           0 : }
    1987             : 
    1988           0 : SalGtkFilePicker::~SalGtkFilePicker()
    1989             : {
    1990           0 :     SolarMutexGuard g;
    1991             : 
    1992             :     int i;
    1993             : 
    1994           0 :     for( i = 0; i < TOGGLE_LAST; i++ )
    1995           0 :         gtk_widget_destroy( m_pToggles[i] );
    1996             : 
    1997           0 :     for( i = 0; i < LIST_LAST; i++ )
    1998             :     {
    1999           0 :         gtk_widget_destroy( m_pListLabels[i] );
    2000           0 :         gtk_widget_destroy( m_pAligns[i] ); //m_pAligns[i] owns m_pLists[i]
    2001           0 :         gtk_widget_destroy( m_pHBoxs[i] );
    2002             :     }
    2003             : 
    2004           0 :     delete m_pFilterList;
    2005             : 
    2006           0 :     gtk_widget_destroy( m_pVBox );
    2007           0 : }
    2008             : 
    2009             : using namespace ::com::sun::star;
    2010             : 
    2011             : uno::Reference< ui::dialogs::XFilePicker2 >
    2012           0 : GtkInstance::createFilePicker( const com::sun::star::uno::Reference<
    2013             :                                         com::sun::star::uno::XComponentContext > &xMSF )
    2014             : {
    2015             :     return uno::Reference< ui::dialogs::XFilePicker2 >(
    2016           0 :                 new SalGtkFilePicker( xMSF ) );
    2017           0 : }
    2018             : 
    2019             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10