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

Generated by: LCOV version 1.10