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

Generated by: LCOV version 1.10