LCOV - code coverage report
Current view: top level - libreoffice/cui/source/options - doclinkdialog.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 98 0.0 %
Date: 2012-12-27 Functions: 0 10 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             : #include "doclinkdialog.hxx"
      21             : #include "doclinkdialog.hrc"
      22             : 
      23             : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      24             : #include <comphelper/processfactory.hxx>
      25             : #include <cuires.hrc>
      26             : #include <svl/filenotation.hxx>
      27             : #include <vcl/msgbox.hxx>
      28             : #include <ucbhelper/content.hxx>
      29             : #include <dialmgr.hxx>
      30             : #include <tools/urlobj.hxx>
      31             : #include <sfx2/filedlghelper.hxx>
      32             : #include <sfx2/docfilt.hxx>
      33             : //......................................................................
      34             : namespace svx
      35             : {
      36             : //......................................................................
      37             : 
      38             :     using namespace ::com::sun::star;
      39             :     using namespace ::com::sun::star::uno;
      40             :     using namespace ::com::sun::star::ucb;
      41             :     using namespace ::svt;
      42             : 
      43             :     //==================================================================
      44             :     //= ODocumentLinkDialog
      45             :     //==================================================================
      46             :     //------------------------------------------------------------------
      47           0 :     ODocumentLinkDialog::ODocumentLinkDialog( Window* _pParent, sal_Bool _bCreateNew )
      48           0 :         :ModalDialog( _pParent, CUI_RES(DLG_DOCUMENTLINK) )
      49           0 :         ,m_aURLLabel        (this, CUI_RES(FT_URL))
      50           0 :         ,m_aURL             (this, CUI_RES(CMB_URL))
      51           0 :         ,m_aBrowseFile      (this, CUI_RES(PB_BROWSEFILE))
      52           0 :         ,m_aNameLabel       (this, CUI_RES(FT_NAME))
      53           0 :         ,m_aName            (this, CUI_RES(ET_NAME))
      54           0 :         ,m_aBottomLine      (this, CUI_RES(FL_BOTTOM))
      55           0 :         ,m_aOK              (this, CUI_RES(BTN_OK))
      56           0 :         ,m_aCancel          (this, CUI_RES(BTN_CANCEL))
      57           0 :         ,m_aHelp            (this, CUI_RES(BTN_HELP))
      58           0 :         ,m_bCreatingNew(_bCreateNew)
      59             :     {
      60           0 :         String sText = String( CUI_RES( m_bCreatingNew ? STR_NEW_LINK : STR_EDIT_LINK ) );
      61           0 :         SetText(sText);
      62             : 
      63           0 :         FreeResource();
      64             : 
      65           0 :         rtl::OUString sTemp("*.odb");
      66           0 :         m_aURL.SetFilter(sTemp);
      67             : 
      68           0 :         m_aName.SetModifyHdl( LINK(this, ODocumentLinkDialog, OnTextModified) );
      69           0 :         m_aURL.SetModifyHdl( LINK(this, ODocumentLinkDialog, OnTextModified) );
      70           0 :         m_aBrowseFile.SetClickHdl( LINK(this, ODocumentLinkDialog, OnBrowseFile) );
      71           0 :         m_aOK.SetClickHdl( LINK(this, ODocumentLinkDialog, OnOk) );
      72             : 
      73           0 :         m_aURL.SetDropDownLineCount(10);
      74             : 
      75           0 :         validate();
      76             : 
      77           0 :         m_aURL.SetDropDownLineCount( 5 );
      78           0 :     }
      79             : 
      80             :     //------------------------------------------------------------------
      81           0 :     void ODocumentLinkDialog::set( const String& _rName, const String& _rURL )
      82             :     {
      83           0 :         m_aName.SetText(_rName);
      84           0 :         m_aURL.SetText(_rURL);
      85           0 :         validate();
      86           0 :     }
      87             : 
      88             :     //------------------------------------------------------------------
      89           0 :     void ODocumentLinkDialog::get( String& _rName, String& _rURL ) const
      90             :     {
      91           0 :         _rName = m_aName.GetText();
      92           0 :         _rURL = m_aURL.GetText();
      93           0 :     }
      94             : 
      95             :     //------------------------------------------------------------------
      96           0 :     void ODocumentLinkDialog::validate( )
      97             :     {
      98             : 
      99           0 :         m_aOK.Enable( (0 != m_aName.GetText().Len()) && ( 0 != m_aURL.GetText().Len() ) );
     100           0 :     }
     101             : 
     102             :     //------------------------------------------------------------------
     103           0 :     IMPL_LINK_NOARG(ODocumentLinkDialog, OnOk)
     104             :     {
     105             :         // get the current URL
     106           0 :         ::rtl::OUString sURL = m_aURL.GetText();
     107           0 :         OFileNotation aTransformer(sURL);
     108           0 :         sURL = aTransformer.get(OFileNotation::N_URL);
     109             : 
     110             :         // check for the existence of the selected file
     111           0 :         sal_Bool bFileExists = sal_False;
     112             :         try
     113             :         {
     114           0 :             ::ucbhelper::Content aFile(sURL, Reference< XCommandEnvironment >(), comphelper::getProcessComponentContext());
     115           0 :             if (aFile.isDocument())
     116           0 :                 bFileExists = sal_True;
     117             :         }
     118           0 :         catch(Exception&)
     119             :         {
     120             :         }
     121             : 
     122           0 :         if (!bFileExists)
     123             :         {
     124           0 :             String sMsg = String(CUI_RES(STR_LINKEDDOC_DOESNOTEXIST));
     125           0 :             sMsg.SearchAndReplaceAscii("$file$", m_aURL.GetText());
     126           0 :             ErrorBox aError(this, WB_OK , sMsg);
     127           0 :             aError.Execute();
     128           0 :             return 0L;
     129             :         } // if (!bFileExists)
     130           0 :         INetURLObject aURL( sURL );
     131           0 :         if ( aURL.GetProtocol() != INET_PROT_FILE )
     132             :         {
     133           0 :             String sMsg = String(CUI_RES(STR_LINKEDDOC_NO_SYSTEM_FILE));
     134           0 :             sMsg.SearchAndReplaceAscii("$file$", m_aURL.GetText());
     135           0 :             ErrorBox aError(this, WB_OK , sMsg);
     136           0 :             aError.Execute();
     137           0 :             return 0L;
     138             :         }
     139             : 
     140           0 :         String sCurrentText = m_aName.GetText();
     141           0 :         if ( m_aNameValidator.IsSet() )
     142             :         {
     143           0 :             if ( !m_aNameValidator.Call( &sCurrentText ) )
     144             :             {
     145           0 :                 String sMsg = String(CUI_RES(STR_NAME_CONFLICT));
     146           0 :                 sMsg.SearchAndReplaceAscii("$file$", sCurrentText);
     147           0 :                 InfoBox aError(this, sMsg);
     148           0 :                 aError.Execute();
     149             : 
     150           0 :                 m_aName.SetSelection(Selection(0,sCurrentText.Len()));
     151           0 :                 m_aName.GrabFocus();
     152           0 :                 return 0L;
     153             :             }
     154             :         }
     155             : 
     156           0 :         EndDialog(RET_OK);
     157           0 :         return 0L;
     158             :     }
     159             : 
     160             :     //------------------------------------------------------------------
     161           0 :     IMPL_LINK_NOARG(ODocumentLinkDialog, OnBrowseFile)
     162             :     {
     163             :         ::sfx2::FileDialogHelper aFileDlg(
     164           0 :                 ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION, 0);
     165           0 :         const SfxFilter* pFilter = SfxFilter::GetFilterByName(rtl::OUString("StarOffice XML (Base)"));
     166           0 :         if ( pFilter )
     167             :         {
     168           0 :             aFileDlg.AddFilter(pFilter->GetUIName(),pFilter->GetDefaultExtension());
     169           0 :             aFileDlg.SetCurrentFilter(pFilter->GetUIName());
     170             :         }
     171             : 
     172           0 :         String sPath = m_aURL.GetText();
     173           0 :         if (sPath.Len())
     174             :         {
     175           0 :             OFileNotation aTransformer( sPath, OFileNotation::N_SYSTEM );
     176           0 :             aFileDlg.SetDisplayDirectory( aTransformer.get( OFileNotation::N_URL ) );
     177             :         }
     178             : 
     179           0 :         if (0 != aFileDlg.Execute())
     180           0 :             return 0L;
     181             : 
     182           0 :         if (0 == m_aName.GetText().Len())
     183             :         {   // default the name to the base of the chosen URL
     184           0 :             INetURLObject aParser;
     185             : 
     186           0 :             aParser.SetSmartProtocol(INET_PROT_FILE);
     187           0 :             aParser.SetSmartURL(aFileDlg.GetPath());
     188             : 
     189           0 :             m_aName.SetText(aParser.getBase(INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET));
     190             : 
     191           0 :             m_aName.SetSelection(Selection(0,m_aName.GetText().Len()));
     192           0 :             m_aName.GrabFocus();
     193             :         }
     194             :         else
     195           0 :             m_aURL.GrabFocus();
     196             : 
     197             :         // get the path in system notation
     198           0 :         OFileNotation aTransformer(aFileDlg.GetPath(), OFileNotation::N_URL);
     199           0 :         m_aURL.SetText(aTransformer.get(OFileNotation::N_SYSTEM));
     200             : 
     201           0 :         validate();
     202           0 :         return 0L;
     203             :     }
     204             : 
     205             :     //------------------------------------------------------------------
     206           0 :     IMPL_LINK_NOARG(ODocumentLinkDialog, OnTextModified)
     207             :     {
     208           0 :         validate( );
     209           0 :         return 0L;
     210             :     }
     211             : 
     212             : //......................................................................
     213             : }   // namespace svx
     214             : //......................................................................
     215             : 
     216             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10