LCOV - code coverage report
Current view: top level - libreoffice/vcl/unx/gtk/fpicker - SalGtkPicker.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 110 0.0 %
Date: 2012-12-17 Functions: 0 19 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/lang/DisposedException.hpp>
      27             : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
      28             : #include <com/sun/star/uri/XExternalUriReferenceTranslator.hpp>
      29             : #include <com/sun/star/lang/SystemDependent.hpp>
      30             : #include <com/sun/star/awt/XSystemDependentWindowPeer.hpp>
      31             : #include <com/sun/star/awt/SystemDependentXWindow.hpp>
      32             : #include <com/sun/star/beans/NamedValue.hpp>
      33             : #include <com/sun/star/container/XNameAccess.hpp>
      34             : #include <comphelper/processfactory.hxx>
      35             : #include <cppuhelper/interfacecontainer.h>
      36             : #include <rtl/process.h>
      37             : #include <osl/diagnose.h>
      38             : #include <com/sun/star/uno/Any.hxx>
      39             : #include <osl/mutex.hxx>
      40             : #include <vcl/svapp.hxx>
      41             : #include <tools/urlobj.hxx>
      42             : #include <stdio.h>
      43             : 
      44             : #include "vcl/window.hxx"
      45             : #include "unx/gtk/gtkframe.hxx"
      46             : #include "gtk/fpicker/SalGtkPicker.hxx"
      47             : 
      48             : using namespace ::rtl;
      49             : using namespace ::com::sun::star;
      50             : using namespace ::com::sun::star::lang;
      51             : using namespace ::com::sun::star::uno;
      52             : 
      53           0 : rtl::OUString SalGtkPicker::uritounicode(const gchar* pIn)
      54             : {
      55           0 :     if (!pIn)
      56           0 :         return rtl::OUString();
      57             : 
      58           0 :     rtl::OUString sURL( const_cast<const sal_Char *>(pIn), strlen(pIn),
      59           0 :         RTL_TEXTENCODING_UTF8 );
      60             : 
      61           0 :     INetURLObject aURL(sURL);
      62           0 :     if (INET_PROT_FILE == aURL.GetProtocol())
      63             :     {
      64             :         // all the URLs are handled by office in UTF-8
      65             :         // so the Gnome FP related URLs should be converted accordingly
      66           0 :         gchar *pEncodedFileName = g_filename_from_uri(pIn, NULL, NULL);
      67           0 :         if ( pEncodedFileName )
      68             :         {
      69           0 :             rtl::OUString sEncoded(pEncodedFileName, strlen(pEncodedFileName),
      70           0 :                 osl_getThreadTextEncoding());
      71           0 :             INetURLObject aCurrentURL(sEncoded, INetURLObject::FSYS_UNX);
      72           0 :             aCurrentURL.SetHost(aURL.GetHost());
      73           0 :             sURL = aCurrentURL.getExternalURL();
      74             :         }
      75             :         else
      76             :         {
      77           0 :             OUString aNewURL = uno::Reference<uri::XExternalUriReferenceTranslator>(uno::Reference<XMultiComponentFactory>(comphelper::getProcessServiceFactory(), UNO_QUERY_THROW)->createInstanceWithContext(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uri.ExternalUriReferenceTranslator")), m_xContext), UNO_QUERY_THROW)->translateToInternal(sURL);
      78           0 :             if( !aNewURL.isEmpty() )
      79           0 :                 sURL = aNewURL;
      80             :         }
      81             :     }
      82           0 :     return sURL;
      83             : }
      84             : 
      85           0 : rtl::OString SalGtkPicker::unicodetouri(const rtl::OUString &rURL)
      86             : {
      87             :     // all the URLs are handled by office in UTF-8 ( and encoded with "%xx" codes based on UTF-8 )
      88             :     // so the Gnome FP related URLs should be converted accordingly
      89           0 :     OString sURL = OUStringToOString(rURL, RTL_TEXTENCODING_UTF8);
      90           0 :     INetURLObject aURL(rURL);
      91           0 :     if (INET_PROT_FILE == aURL.GetProtocol())
      92             :     {
      93           0 :         OUString aNewURL = uno::Reference<uri::XExternalUriReferenceTranslator>(uno::Reference<XMultiComponentFactory>(comphelper::getProcessServiceFactory(), UNO_QUERY_THROW)->createInstanceWithContext(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uri.ExternalUriReferenceTranslator")), m_xContext ), UNO_QUERY_THROW)->translateToExternal( rURL );
      94             : 
      95           0 :         if( !aNewURL.isEmpty() )
      96             :         {
      97             :             // At this point the URL should contain ascii characters only actually
      98           0 :             sURL = OUStringToOString( aNewURL, osl_getThreadTextEncoding() );
      99           0 :         }
     100             :     }
     101           0 :     return sURL;
     102             : }
     103             : 
     104             : extern "C"
     105             : {
     106           0 :     static gboolean canceldialog(RunDialog *pDialog)
     107             :     {
     108           0 :         GdkThreadLock lock;
     109           0 :         pDialog->cancel();
     110           0 :         return false;
     111             :     }
     112             : }
     113             : 
     114           0 : RunDialog::RunDialog( GtkWidget *pDialog, uno::Reference< awt::XExtendedToolkit >& rToolkit,
     115             :     uno::Reference< frame::XDesktop >& rDesktop ) :
     116             :     cppu::WeakComponentImplHelper2< awt::XTopWindowListener, frame::XTerminateListener >( maLock ),
     117           0 :     mpDialog(pDialog), mxToolkit(rToolkit), mxDesktop(rDesktop)
     118             : {
     119           0 :     GtkWindow *pParent = NULL;
     120             : 
     121           0 :     ::Window * pWindow = ::Application::GetActiveTopWindow();
     122           0 :     if( pWindow )
     123             :     {
     124           0 :         GtkSalFrame *pFrame = dynamic_cast<GtkSalFrame *>( pWindow->ImplGetFrame() );
     125           0 :         if( pFrame )
     126           0 :             pParent = GTK_WINDOW( pFrame->getWindow() );
     127             :     }
     128           0 :     if (pParent)
     129           0 :         gtk_window_set_transient_for( GTK_WINDOW( mpDialog ), pParent );
     130           0 : }
     131             : 
     132           0 : RunDialog::~RunDialog()
     133             : {
     134           0 :     SolarMutexGuard g;
     135             : 
     136           0 :     g_source_remove_by_user_data (this);
     137           0 : }
     138             : 
     139           0 : void SAL_CALL RunDialog::windowOpened( const ::com::sun::star::lang::EventObject& )
     140             :     throw (::com::sun::star::uno::RuntimeException)
     141             : {
     142           0 :     SolarMutexGuard g;
     143             : 
     144           0 :     g_timeout_add_full(G_PRIORITY_HIGH_IDLE, 0, (GSourceFunc)canceldialog, this, NULL);
     145           0 : }
     146             : 
     147           0 : void SAL_CALL RunDialog::queryTermination( const ::com::sun::star::lang::EventObject& )
     148             :         throw(::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException)
     149             : {
     150           0 : }
     151             : 
     152           0 : void SAL_CALL RunDialog::notifyTermination( const ::com::sun::star::lang::EventObject& )
     153             :         throw(::com::sun::star::uno::RuntimeException)
     154             : {
     155           0 :     SolarMutexGuard g;
     156             : 
     157           0 :     g_timeout_add_full(G_PRIORITY_HIGH_IDLE, 0, (GSourceFunc)canceldialog, this, NULL);
     158           0 : }
     159             : 
     160           0 : void RunDialog::cancel()
     161             : {
     162           0 :     gtk_dialog_response( GTK_DIALOG( mpDialog ), GTK_RESPONSE_CANCEL );
     163           0 :     gtk_widget_hide( mpDialog );
     164           0 : }
     165             : 
     166           0 : gint RunDialog::run()
     167             : {
     168           0 :     if (mxToolkit.is())
     169           0 :         mxToolkit->addTopWindowListener(this);
     170             : 
     171           0 :     gint nStatus = gtk_dialog_run( GTK_DIALOG( mpDialog ) );
     172             : 
     173           0 :     if (mxToolkit.is())
     174           0 :         mxToolkit->removeTopWindowListener(this);
     175             : 
     176           0 :     if (nStatus != 1)   //PLAY
     177           0 :         gtk_widget_hide( mpDialog );
     178             : 
     179           0 :     return nStatus;
     180             : }
     181             : 
     182             : // FIXME: this is pretty nasty ... we try to tell gtk+'s
     183             : // gettext the locale it should use via the environment
     184           0 : void SalGtkPicker::setGtkLanguage()
     185             : {
     186             :     static bool bSet = false;
     187           0 :     if (bSet)
     188           0 :         return;
     189             : 
     190             :     /* FIXME-BCP47: let LanguageTag create glibc locale string! */
     191           0 :     ::com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILanguageTag().getLocale();
     192           0 :     rtl::OUStringBuffer aBuffer;
     193           0 :     aBuffer.append( aLocale.Language );
     194           0 :     aBuffer.appendAscii( "_" );
     195           0 :     aBuffer.append( aLocale.Country );
     196           0 :     aBuffer.appendAscii( ".UTF-8" );
     197             : 
     198           0 :     if (aBuffer.getLength() > 8)
     199             :     {
     200           0 :         rtl::OUString envVar( RTL_CONSTASCII_USTRINGPARAM( "LANGUAGE" ) );
     201           0 :         osl_setEnvironment( envVar.pData, aBuffer.makeStringAndClear().pData );
     202             :     }
     203           0 :     bSet = true;
     204             : }
     205             : 
     206           0 : SalGtkPicker::SalGtkPicker( const uno::Reference<uno::XComponentContext>& xContext )
     207           0 :     : m_pDialog( 0 ), m_xContext( xContext )
     208             : {
     209           0 :     setGtkLanguage();
     210           0 : }
     211             : 
     212           0 : SalGtkPicker::~SalGtkPicker()
     213             : {
     214           0 :     SolarMutexGuard g;
     215             : 
     216           0 :     if (m_pDialog)
     217             :     {
     218           0 :         gtk_widget_destroy(m_pDialog);
     219           0 :     }
     220           0 : }
     221             : 
     222           0 : void SAL_CALL SalGtkPicker::implsetDisplayDirectory( const rtl::OUString& aDirectory )
     223             :     throw( lang::IllegalArgumentException, uno::RuntimeException )
     224             : {
     225             :     OSL_ASSERT( m_pDialog != NULL );
     226             : 
     227           0 :     OString aTxt = unicodetouri(aDirectory);
     228             : 
     229           0 :     if( aTxt.lastIndexOf('/') == aTxt.getLength() - 1 )
     230           0 :         aTxt = aTxt.copy( 0, aTxt.getLength() - 1 );
     231             : 
     232             :     OSL_TRACE( "setting path to %s", aTxt.getStr() );
     233             : 
     234           0 :     gtk_file_chooser_set_current_folder_uri( GTK_FILE_CHOOSER( m_pDialog ),
     235           0 :         aTxt.getStr() );
     236           0 : }
     237             : 
     238           0 : rtl::OUString SAL_CALL SalGtkPicker::implgetDisplayDirectory() throw( uno::RuntimeException )
     239             : {
     240             :     OSL_ASSERT( m_pDialog != NULL );
     241             : 
     242             :     gchar* pCurrentFolder =
     243           0 :         gtk_file_chooser_get_current_folder_uri( GTK_FILE_CHOOSER( m_pDialog ) );
     244           0 :     ::rtl::OUString aCurrentFolderName = uritounicode(pCurrentFolder);
     245           0 :     g_free( pCurrentFolder );
     246             : 
     247           0 :     return aCurrentFolderName;
     248             : }
     249             : 
     250           0 : void SAL_CALL SalGtkPicker::implsetTitle( const rtl::OUString& aTitle ) throw( uno::RuntimeException )
     251             : {
     252             :     OSL_ASSERT( m_pDialog != NULL );
     253             : 
     254           0 :     ::rtl::OString aWindowTitle = OUStringToOString( aTitle, RTL_TEXTENCODING_UTF8 );
     255             : 
     256           0 :     gtk_window_set_title( GTK_WINDOW( m_pDialog ), aWindowTitle.getStr() );
     257           0 : }
     258             : 
     259           0 : uno::Reference< uno::XInterface > SalGtkPicker::createInstance( const rtl::OUString &rName )
     260             : {
     261           0 :     return m_xContext->getServiceManager()->createInstanceWithContext( rName, m_xContext );
     262             : }
     263             : 
     264             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10