LCOV - code coverage report
Current view: top level - extensions/source/abpilot - typeselectionpage.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 106 0.0 %
Date: 2014-04-11 Functions: 0 12 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 "typeselectionpage.hxx"
      21             : #include "addresssettings.hxx"
      22             : #include "abspilot.hxx"
      23             : #include <vcl/msgbox.hxx>
      24             : #include <com/sun/star/sdbc/XDriver.hpp>
      25             : #include <com/sun/star/sdbc/DriverManager.hpp>
      26             : #include <comphelper/processfactory.hxx>
      27             : 
      28             : namespace abp
      29             : {
      30             :     using namespace ::com::sun::star::uno;
      31             :     using namespace ::com::sun::star::sdbc;
      32             : 
      33             :     // TypeSelectionPage
      34           0 :     TypeSelectionPage::TypeSelectionPage( OAddessBookSourcePilot* _pParent )
      35             :         :AddressBookSourcePage(_pParent, ModuleRes(RID_PAGE_SELECTABTYPE))
      36             :         ,m_aHint                (this,  ModuleRes(FT_TYPE_HINTS))
      37             :         ,m_aTypeSep             (this,  ModuleRes(FL_TYPE))
      38             :         ,m_aEvolution           (this,  ModuleRes(RB_EVOLUTION))
      39             :         ,m_aEvolutionGroupwise  (this,  ModuleRes(RB_EVOLUTION_GROUPWISE))
      40             :         ,m_aEvolutionLdap       (this,  ModuleRes(RB_EVOLUTION_LDAP))
      41             :         ,m_aMORK                (this,  ModuleRes(RB_MORK))
      42             :         ,m_aThunderbird         (this,  ModuleRes(RB_THUNDERBIRD))
      43             :         ,m_aKab                 (this,  ModuleRes(RB_KAB))
      44             :         ,m_aMacab               (this,  ModuleRes(RB_MACAB))
      45             :         ,m_aLDAP                (this,  ModuleRes(RB_LDAP))
      46             :         ,m_aOutlook             (this,  ModuleRes(RB_OUTLOOK))
      47             :         ,m_aOE                  (this,  ModuleRes(RB_OUTLOOKEXPRESS))
      48           0 :         ,m_aOther               (this,  ModuleRes(RB_OTHER))
      49             :     {
      50           0 :         FreeResource();
      51             : 
      52           0 :         Point aTopLeft( LogicToPixel( Point( 15, 68 ), MAP_APPFONT ) );
      53           0 :         Size  aItemSize( LogicToPixel( Size( 0, 8 ), MAP_APPFONT ) );
      54           0 :         aItemSize.Width() = GetOutputSizePixel().Width() - 30;
      55             : 
      56             :         //TODO:  For now, try to keep offering the same choices like before the
      57             :         // Mozilla/MORK cleanup, even if the status of what driver actually
      58             :         // provides which functionality is somewhat unclear, see the discussions
      59             :         // of fdo#57285 "Address Book Data Source Wizard lists 'Mac OS X address
      60             :         // book' on Linux" and fdo#57322 "Moz-free LDAP Address Book driver."
      61             :         // In accordance with ancient OOo 3.3, this is as follows:
      62             :         //
      63             :         // On Linux:
      64             :         // - EVOLUTION, EVOLUTION_GROUPWISE, EVOLUTION_LDAP (if applicable)
      65             :         // - MORK (via mork driver, which is built unconditionally)
      66             :         // - KAB (if applicable)
      67             :         // - OTHER
      68             :         //
      69             :         // On Mac OS X:
      70             :         // - MACAB (if applicable)
      71             :         // - MORK (via mork driver, which is built unconditionally)
      72             :         // - OTHER
      73             :         //
      74             :         // On Windows:
      75             :         // - MORK, THUNDERBIRD, LDAP, OUTLOOK, OUTLOOKEXPRESS (via mozab driver,
      76             :         //   if WITH_MOZILLA)
      77             :         // - OTHER
      78             : 
      79           0 :         bool bWithMozilla = false;
      80           0 :         bool bHaveEvolution = false;
      81           0 :         bool bHaveKab = false;
      82           0 :         bool bHaveMacab = false;
      83           0 :         bool bWithMork = false;
      84             : 
      85             : #if defined WNT
      86             : #if defined WITH_MOZILLA
      87             :         bWithMozilla = true;
      88             : #endif
      89             : #else
      90           0 :         bWithMork = true;
      91             : 
      92           0 :         Reference< XDriverManager2 > xManager = DriverManager::create( _pParent->getORB() );
      93             : 
      94             :         try
      95             :         {
      96             :             // check whether Evolution is available
      97           0 :             Reference< XDriver > xDriver( xManager->getDriverByURL(OUString("sdbc:address:evolution:local")) );
      98           0 :             if ( xDriver.is() )
      99           0 :                 bHaveEvolution = true;
     100             :         }
     101           0 :         catch (...)
     102             :         {
     103             :         }
     104             : 
     105             :         // check whether KDE address book is available
     106             :         try
     107             :         {
     108           0 :             Reference< XDriver > xDriver( xManager->getDriverByURL(OUString("sdbc:address:kab")) );
     109           0 :             if ( xDriver.is() )
     110           0 :                 bHaveKab = true;
     111             :         }
     112           0 :         catch (...)
     113             :         {
     114             :         }
     115             : 
     116             :         try
     117             :         {
     118             :             // check whether Mac OS X address book is available
     119           0 :             Reference< XDriver > xDriver( xManager->getDriverByURL(OUString("sdbc:address:macab")) );
     120           0 :             if ( xDriver.is() )
     121           0 :                 bHaveMacab = true;
     122             :         }
     123           0 :         catch(...)
     124             :         {
     125             :         }
     126             : 
     127             : #endif
     128             : 
     129             :         // Items are displayed in list order
     130           0 :         m_aAllTypes.push_back( ButtonItem( &m_aEvolution, AST_EVOLUTION, bHaveEvolution ) );
     131           0 :         m_aAllTypes.push_back( ButtonItem( &m_aEvolutionGroupwise, AST_EVOLUTION_GROUPWISE, bHaveEvolution ) );
     132           0 :         m_aAllTypes.push_back( ButtonItem( &m_aEvolutionLdap, AST_EVOLUTION_LDAP, bHaveEvolution ) );
     133           0 :         m_aAllTypes.push_back( ButtonItem( &m_aMORK, AST_MORK, bWithMozilla || bWithMork) );
     134           0 :         m_aAllTypes.push_back( ButtonItem( &m_aThunderbird, AST_THUNDERBIRD, bWithMozilla || bWithMork) );
     135           0 :         m_aAllTypes.push_back( ButtonItem( &m_aKab, AST_KAB, bHaveKab ) );
     136           0 :         m_aAllTypes.push_back( ButtonItem( &m_aMacab, AST_MACAB, bHaveMacab ) );
     137           0 :         m_aAllTypes.push_back( ButtonItem( &m_aLDAP, AST_LDAP, bWithMozilla ) );
     138           0 :         m_aAllTypes.push_back( ButtonItem( &m_aOutlook, AST_OUTLOOK, bWithMozilla ) );
     139           0 :         m_aAllTypes.push_back( ButtonItem( &m_aOE, AST_OE, bWithMozilla ) );
     140           0 :         m_aAllTypes.push_back( ButtonItem( &m_aOther, AST_OTHER, true ) );
     141             : 
     142           0 :         Link aTypeSelectionHandler = LINK(this, TypeSelectionPage, OnTypeSelected );
     143           0 :         const Size aSpacing( LogicToPixel( Size( 0, 3 ), MAP_APPFONT ) );
     144           0 :         if ( ! m_aAllTypes.empty() )
     145             :         {
     146           0 :             ButtonItem aItem = m_aAllTypes[0];
     147           0 :             aItem.m_pItem->SetStyle( aItem.m_pItem->GetStyle() | WB_GROUP );
     148             :         }
     149           0 :         for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
     150           0 :               loop != m_aAllTypes.end(); ++loop )
     151             :         {
     152           0 :             ButtonItem aItem = *loop;
     153           0 :             if (!aItem.m_bVisible)
     154           0 :                 aItem.m_pItem->Hide();
     155             :             else
     156             :             {
     157           0 :                 aItem.m_pItem->SetPosPixel( aTopLeft );
     158           0 :                 aTopLeft.Y() += aItemSize.Height() + aSpacing.Height();
     159           0 :                 aItem.m_pItem->SetClickHdl( aTypeSelectionHandler );
     160           0 :                 aItem.m_pItem->Show();
     161             :             }
     162           0 :         }
     163           0 :     }
     164             : 
     165             : 
     166           0 :     TypeSelectionPage::~TypeSelectionPage()
     167             :     {
     168           0 :         for ( ::std::vector< ButtonItem >::iterator loop = m_aAllTypes.begin();
     169           0 :               loop != m_aAllTypes.end(); ++loop )
     170             :         {
     171           0 :             loop->m_bVisible = false;
     172             :         }
     173           0 :     }
     174             : 
     175             : 
     176           0 :     void TypeSelectionPage::ActivatePage()
     177             :     {
     178           0 :         AddressBookSourcePage::ActivatePage();
     179             : 
     180           0 :         for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
     181           0 :               loop != m_aAllTypes.end(); ++loop )
     182             :         {
     183           0 :             const ButtonItem& rItem = (*loop);
     184           0 :             if( rItem.m_pItem->IsChecked() && rItem.m_bVisible )
     185             :             {
     186           0 :                 rItem.m_pItem->GrabFocus();
     187           0 :                 break;
     188             :             }
     189             :         }
     190             : 
     191           0 :         getDialog()->enableButtons(WZB_PREVIOUS, false);
     192           0 :     }
     193             : 
     194             : 
     195           0 :     void TypeSelectionPage::DeactivatePage()
     196             :     {
     197           0 :         AddressBookSourcePage::DeactivatePage();
     198           0 :         getDialog()->enableButtons(WZB_PREVIOUS, true);
     199           0 :     }
     200             : 
     201             : 
     202           0 :     void TypeSelectionPage::selectType( AddressSourceType _eType )
     203             :     {
     204           0 :         for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
     205           0 :               loop != m_aAllTypes.end(); ++loop )
     206             :         {
     207           0 :             ButtonItem aItem = (*loop);
     208           0 :             aItem.m_pItem->Check( _eType == aItem.m_eType );
     209             :         }
     210           0 :     }
     211             : 
     212             : 
     213           0 :     AddressSourceType TypeSelectionPage::getSelectedType() const
     214             :     {
     215           0 :         for ( ::std::vector< ButtonItem >::const_iterator loop = m_aAllTypes.begin();
     216           0 :               loop != m_aAllTypes.end(); ++loop )
     217             :         {
     218           0 :             ButtonItem aItem = (*loop);
     219           0 :             if ( aItem.m_pItem->IsChecked() )
     220           0 :                 return aItem.m_eType;
     221             :         }
     222             : 
     223           0 :         return AST_INVALID;
     224             :     }
     225             : 
     226             : 
     227           0 :     void TypeSelectionPage::initializePage()
     228             :     {
     229           0 :         AddressBookSourcePage::initializePage();
     230             : 
     231           0 :         const AddressSettings& rSettings = getSettings();
     232           0 :         selectType(rSettings.eType);
     233           0 :     }
     234             : 
     235             : 
     236           0 :     bool TypeSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
     237             :     {
     238           0 :         if (!AddressBookSourcePage::commitPage(_eReason))
     239           0 :             return false;
     240             : 
     241           0 :         if (AST_INVALID == getSelectedType( ))
     242             :         {
     243           0 :             ErrorBox aError(this, ModuleRes(RID_ERR_NEEDTYPESELECTION));
     244           0 :             aError.Execute();
     245           0 :             return false;
     246             :         }
     247             : 
     248           0 :         AddressSettings& rSettings = getSettings();
     249           0 :         rSettings.eType = getSelectedType();
     250             : 
     251           0 :         return true;
     252             :     }
     253             : 
     254             : 
     255           0 :     bool TypeSelectionPage::canAdvance() const
     256             :     {
     257           0 :         return  AddressBookSourcePage::canAdvance()
     258           0 :             &&  (AST_INVALID != getSelectedType());
     259             :     }
     260             : 
     261             : 
     262           0 :     IMPL_LINK( TypeSelectionPage, OnTypeSelected, void*, /*NOTINTERESTEDIN*/ )
     263             :     {
     264           0 :         getDialog()->typeSelectionChanged( getSelectedType() );
     265           0 :         updateDialogTravelUI();
     266           0 :         return 0L;
     267             :     }
     268             : 
     269             : 
     270             : }   // namespace abp
     271             : 
     272             : 
     273             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10