LCOV - code coverage report
Current view: top level - vcl/unx/gtk/fpicker - SalGtkPicker.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 97 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 17 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/XMultiComponentFactory.hpp>
      27             : #include <com/sun/star/uri/ExternalUriReferenceTranslator.hpp>
      28             : #include <comphelper/processfactory.hxx>
      29             : #include <rtl/process.h>
      30             : #include <osl/diagnose.h>
      31             : #include <osl/mutex.hxx>
      32             : #include <vcl/svapp.hxx>
      33             : #include <tools/urlobj.hxx>
      34             : 
      35             : #include "vcl/window.hxx"
      36             : #include "unx/gtk/gtkframe.hxx"
      37             : #include "gtk/fpicker/SalGtkPicker.hxx"
      38             : 
      39             : using namespace ::rtl;
      40             : using namespace ::com::sun::star;
      41             : using namespace ::com::sun::star::lang;
      42             : using namespace ::com::sun::star::uno;
      43             : 
      44           0 : OUString SalGtkPicker::uritounicode(const gchar* pIn)
      45             : {
      46           0 :     if (!pIn)
      47           0 :         return OUString();
      48             : 
      49           0 :     OUString sURL( pIn, strlen(pIn),
      50           0 :         RTL_TEXTENCODING_UTF8 );
      51             : 
      52           0 :     INetURLObject aURL(sURL);
      53           0 :     if (INetProtocol::File == aURL.GetProtocol())
      54             :     {
      55             :         // all the URLs are handled by office in UTF-8
      56             :         // so the Gnome FP related URLs should be converted accordingly
      57           0 :         gchar *pEncodedFileName = g_filename_from_uri(pIn, NULL, NULL);
      58           0 :         if ( pEncodedFileName )
      59             :         {
      60           0 :             OUString sEncoded(pEncodedFileName, strlen(pEncodedFileName),
      61           0 :                 osl_getThreadTextEncoding());
      62           0 :             g_free (pEncodedFileName);
      63           0 :             INetURLObject aCurrentURL(sEncoded, INetURLObject::FSYS_UNX);
      64           0 :             aCurrentURL.SetHost(aURL.GetHost());
      65           0 :             sURL = aCurrentURL.getExternalURL();
      66             :         }
      67             :         else
      68             :         {
      69           0 :             OUString aNewURL = uri::ExternalUriReferenceTranslator::create( m_xContext )->translateToInternal(sURL);
      70           0 :             if( !aNewURL.isEmpty() )
      71           0 :                 sURL = aNewURL;
      72             :         }
      73             :     }
      74           0 :     return sURL;
      75             : }
      76             : 
      77           0 : OString SalGtkPicker::unicodetouri(const OUString &rURL)
      78             : {
      79             :     // all the URLs are handled by office in UTF-8 ( and encoded with "%xx" codes based on UTF-8 )
      80             :     // so the Gnome FP related URLs should be converted accordingly
      81           0 :     OString sURL = OUStringToOString(rURL, RTL_TEXTENCODING_UTF8);
      82           0 :     INetURLObject aURL(rURL);
      83           0 :     if (INetProtocol::File == aURL.GetProtocol())
      84             :     {
      85           0 :         OUString aNewURL = uri::ExternalUriReferenceTranslator::create( m_xContext )->translateToInternal(rURL);
      86             : 
      87           0 :         if( !aNewURL.isEmpty() )
      88             :         {
      89             :             // At this point the URL should contain ascii characters only actually
      90           0 :             sURL = OUStringToOString( aNewURL, osl_getThreadTextEncoding() );
      91           0 :         }
      92             :     }
      93           0 :     return sURL;
      94             : }
      95             : 
      96             : extern "C"
      97             : {
      98           0 :     static gboolean canceldialog(RunDialog *pDialog)
      99             :     {
     100           0 :         SolarMutexGuard g;
     101           0 :         pDialog->cancel();
     102           0 :         return false;
     103             :     }
     104             : }
     105             : 
     106           0 : RunDialog::RunDialog( GtkWidget *pDialog, uno::Reference< awt::XExtendedToolkit >& rToolkit,
     107             :     uno::Reference< frame::XDesktop >& rDesktop ) :
     108             :     cppu::WeakComponentImplHelper2< awt::XTopWindowListener, frame::XTerminateListener >( maLock ),
     109           0 :     mpDialog(pDialog), mxToolkit(rToolkit), mxDesktop(rDesktop)
     110             : {
     111           0 :     GtkWindow *pParent = NULL;
     112             : 
     113           0 :     vcl::Window * pWindow = ::Application::GetActiveTopWindow();
     114           0 :     if( pWindow )
     115             :     {
     116           0 :         GtkSalFrame *pFrame = dynamic_cast<GtkSalFrame *>( pWindow->ImplGetFrame() );
     117           0 :         if( pFrame )
     118           0 :             pParent = GTK_WINDOW( pFrame->getWindow() );
     119             :     }
     120           0 :     if (pParent)
     121           0 :         gtk_window_set_transient_for( GTK_WINDOW( mpDialog ), pParent );
     122           0 : }
     123             : 
     124           0 : RunDialog::~RunDialog()
     125             : {
     126           0 :     SolarMutexGuard g;
     127             : 
     128           0 :     g_source_remove_by_user_data (this);
     129           0 : }
     130             : 
     131           0 : void SAL_CALL RunDialog::windowOpened( const ::com::sun::star::lang::EventObject& )
     132             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     133             : {
     134           0 :     SolarMutexGuard g;
     135             : 
     136           0 :     g_timeout_add_full(G_PRIORITY_HIGH_IDLE, 0, reinterpret_cast<GSourceFunc>(canceldialog), this, NULL);
     137           0 : }
     138             : 
     139           0 : void SAL_CALL RunDialog::queryTermination( const ::com::sun::star::lang::EventObject& )
     140             :         throw(::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException, std::exception)
     141             : {
     142           0 : }
     143             : 
     144           0 : void SAL_CALL RunDialog::notifyTermination( const ::com::sun::star::lang::EventObject& )
     145             :         throw(::com::sun::star::uno::RuntimeException, std::exception)
     146             : {
     147           0 :     SolarMutexGuard g;
     148             : 
     149           0 :     g_timeout_add_full(G_PRIORITY_HIGH_IDLE, 0, reinterpret_cast<GSourceFunc>(canceldialog), this, NULL);
     150           0 : }
     151             : 
     152           0 : void RunDialog::cancel()
     153             : {
     154           0 :     gtk_dialog_response( GTK_DIALOG( mpDialog ), GTK_RESPONSE_CANCEL );
     155           0 :     gtk_widget_hide( mpDialog );
     156           0 : }
     157             : 
     158           0 : gint RunDialog::run()
     159             : {
     160           0 :     if (mxToolkit.is())
     161           0 :         mxToolkit->addTopWindowListener(this);
     162             : 
     163           0 :     gint nStatus = gtk_dialog_run( GTK_DIALOG( mpDialog ) );
     164             : 
     165           0 :     if (mxToolkit.is())
     166           0 :         mxToolkit->removeTopWindowListener(this);
     167             : 
     168           0 :     if (nStatus != 1)   //PLAY
     169           0 :         gtk_widget_hide( mpDialog );
     170             : 
     171           0 :     return nStatus;
     172             : }
     173             : 
     174           0 : SalGtkPicker::SalGtkPicker( const uno::Reference<uno::XComponentContext>& xContext )
     175           0 :     : m_pDialog( 0 ), m_xContext( xContext )
     176             : {
     177           0 : }
     178             : 
     179           0 : SalGtkPicker::~SalGtkPicker()
     180             : {
     181           0 :     SolarMutexGuard g;
     182             : 
     183           0 :     if (m_pDialog)
     184             :     {
     185           0 :         gtk_widget_destroy(m_pDialog);
     186           0 :     }
     187           0 : }
     188             : 
     189           0 : void SAL_CALL SalGtkPicker::implsetDisplayDirectory( const OUString& aDirectory )
     190             :     throw( lang::IllegalArgumentException, uno::RuntimeException )
     191             : {
     192             :     OSL_ASSERT( m_pDialog != NULL );
     193             : 
     194           0 :     OString aTxt = unicodetouri(aDirectory);
     195           0 :     if( aTxt.isEmpty() ){
     196           0 :       aTxt = unicodetouri(OUString("file:///."));
     197             :     }
     198             : 
     199           0 :     if( aTxt.endsWith("/") )
     200           0 :         aTxt = aTxt.copy( 0, aTxt.getLength() - 1 );
     201             : 
     202             :     OSL_TRACE( "setting path to %s", aTxt.getStr() );
     203             : 
     204           0 :     gtk_file_chooser_set_current_folder_uri( GTK_FILE_CHOOSER( m_pDialog ),
     205           0 :         aTxt.getStr() );
     206           0 : }
     207             : 
     208           0 : OUString SAL_CALL SalGtkPicker::implgetDisplayDirectory() throw( uno::RuntimeException )
     209             : {
     210             :     OSL_ASSERT( m_pDialog != NULL );
     211             : 
     212             :     gchar* pCurrentFolder =
     213           0 :         gtk_file_chooser_get_current_folder_uri( GTK_FILE_CHOOSER( m_pDialog ) );
     214           0 :     OUString aCurrentFolderName = uritounicode(pCurrentFolder);
     215           0 :     g_free( pCurrentFolder );
     216             : 
     217           0 :     return aCurrentFolderName;
     218             : }
     219             : 
     220           0 : void SAL_CALL SalGtkPicker::implsetTitle( const OUString& aTitle ) throw( uno::RuntimeException )
     221             : {
     222             :     OSL_ASSERT( m_pDialog != NULL );
     223             : 
     224           0 :     OString aWindowTitle = OUStringToOString( aTitle, RTL_TEXTENCODING_UTF8 );
     225             : 
     226           0 :     gtk_window_set_title( GTK_WINDOW( m_pDialog ), aWindowTitle.getStr() );
     227           0 : }
     228             : 
     229             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11