1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "ConnectionPageSetup.hxx"
31 #include "AutoControls.hrc"
32 #include "dbadminsetup.hrc"
33 #include "dbu_dlg.hrc"
34 #include <svl/itemset.hxx>
35 #include <unotools/pathoptions.hxx>
36 #include <svl/stritem.hxx>
37 #include <svl/eitem.hxx>
38 #include <svl/intitem.hxx>
39 #include "dsitems.hxx"
40 #include "dbaccess_helpid.hrc"
41 #include "localresaccess.hxx"
42 #include <osl/process.h>
43 #include <vcl/msgbox.hxx>
44 #include "dbadmin.hxx"
45 #include "dbadmin.hrc"
46 #include <comphelper/types.hxx>
47 #include <vcl/stdtext.hxx>
48 #include "sqlmessage.hxx"
49 #include "odbcconfig.hxx"
50 #include "dsselect.hxx"
51 #include <svl/filenotation.hxx>
52 #include "dbustrings.hrc"
53 #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
54 #include <com/sun/star/sdbc/XRow.hpp>
55 #include <com/sun/star/awt/XWindow.hpp>
56 #include <com/sun/star/task/XInteractionHandler.hpp>
57 #include <com/sun/star/ucb/XProgressHandler.hpp>
58 #include <com/sun/star/sdbc/XConnection.hpp>
59 #include "UITools.hxx"
60 #include <unotools/localfilehelper.hxx>
61 #include <unotools/ucbhelper.hxx>
62 #include <ucbhelper/commandenvironment.hxx>
63 #include "finteraction.hxx"
64 #include <connectivity/CommonTools.hxx>
65 #include <sfx2/docfilt.hxx>
66 #include <vcl/mnemonic.hxx>
68 //.........................................................................
71 //.........................................................................
72 using namespace ::com::sun::star::uno
;
73 using namespace ::com::sun::star::ucb
;
74 using namespace ::com::sun::star::ui::dialogs
;
75 using namespace ::com::sun::star::sdbc
;
76 using namespace ::com::sun::star::beans
;
77 using namespace ::com::sun::star::lang
;
78 using namespace ::com::sun::star::container
;
79 using namespace ::dbtools
;
80 using namespace ::svt
;
84 OGenericAdministrationPage
* OConnectionTabPageSetup::CreateDbaseTabPage( Window
* pParent
, const SfxItemSet
& _rAttrSet
)
86 OConnectionTabPageSetup
* oDBWizardPage
= new OConnectionTabPageSetup( pParent
, PAGE_DBWIZARD_DBASE
, _rAttrSet
, STR_DBASE_HELPTEXT
, STR_DBASE_HEADERTEXT
, STR_DBASE_PATH_OR_FILE
);
87 oDBWizardPage
->FreeResource();
92 OGenericAdministrationPage
* OConnectionTabPageSetup::CreateMSAccessTabPage( Window
* pParent
, const SfxItemSet
& _rAttrSet
)
94 OConnectionTabPageSetup
* oDBWizardPage
= new OConnectionTabPageSetup( pParent
, PAGE_DBWIZARD_MSACCESS
, _rAttrSet
, STR_MSACCESS_HELPTEXT
, STR_MSACCESS_HEADERTEXT
, STR_MSACCESS_MDB_FILE
);
95 oDBWizardPage
->FreeResource();
99 OGenericAdministrationPage
* OConnectionTabPageSetup::CreateADOTabPage( Window
* pParent
, const SfxItemSet
& _rAttrSet
)
101 OConnectionTabPageSetup
* oDBWizardPage
= new OConnectionTabPageSetup( pParent
, PAGE_DBWIZARD_ADO
, _rAttrSet
, STR_ADO_HELPTEXT
, STR_ADO_HEADERTEXT
, STR_COMMONURL
);
102 oDBWizardPage
->FreeResource();
103 return oDBWizardPage
;
106 OGenericAdministrationPage
* OConnectionTabPageSetup::CreateODBCTabPage( Window
* pParent
, const SfxItemSet
& _rAttrSet
)
108 OConnectionTabPageSetup
* oDBWizardPage
= new OConnectionTabPageSetup( pParent
, PAGE_DBWIZARD_ODBC
, _rAttrSet
, STR_ODBC_HELPTEXT
, STR_ODBC_HEADERTEXT
, STR_NAME_OF_ODBC_DATASOURCE
);
109 oDBWizardPage
->FreeResource();
110 return oDBWizardPage
;
113 OGenericAdministrationPage
* OConnectionTabPageSetup::CreateUserDefinedTabPage( Window
* pParent
, const SfxItemSet
& _rAttrSet
)
115 OConnectionTabPageSetup
* oDBWizardPage
= new OConnectionTabPageSetup( pParent
, PAGE_DBWIZARD_USERDEFINED
, _rAttrSet
, USHRT_MAX
, USHRT_MAX
, STR_COMMONURL
);
116 oDBWizardPage
->FreeResource();
117 return oDBWizardPage
;
121 //========================================================================
122 //= OConnectionTabPageSetup
123 //========================================================================
124 DBG_NAME(OConnectionTabPageSetup
)
125 OConnectionTabPageSetup::OConnectionTabPageSetup(Window
* pParent
, sal_uInt16 _rId
, const SfxItemSet
& _rCoreAttrs
, sal_uInt16 _nHelpTextResId
, sal_uInt16 _nHeaderResId
, sal_uInt16 _nUrlResId
)
126 :OConnectionHelper(pParent
, ModuleRes(_rId
), _rCoreAttrs
)
127 ,m_bUserGrabFocus(sal_True
)
128 ,m_aFT_HelpText(this, ModuleRes(FT_AUTOWIZARDHELPTEXT
))
130 DBG_CTOR(OConnectionTabPageSetup
, NULL
);
132 if ( USHRT_MAX
!= _nHelpTextResId
)
134 String sHelpText
= String(ModuleRes(_nHelpTextResId
));
135 m_aFT_HelpText
.SetText(sHelpText
);
138 m_aFT_HelpText
.Hide();
141 if ( USHRT_MAX
!= _nHeaderResId
)
142 SetHeaderText(FT_AUTOWIZARDHEADER
, _nHeaderResId
);
144 if ( USHRT_MAX
!= _nUrlResId
)
146 String sLabelText
= String(ModuleRes(_nUrlResId
));
147 m_aFT_Connection
.SetText(sLabelText
);
148 if ( USHRT_MAX
== _nHelpTextResId
)
150 Point aPos
= m_aFT_HelpText
.GetPosPixel();
151 Point aFTPos
= m_aFT_Connection
.GetPosPixel();
152 Point aEDPos
= m_aConnectionURL
.GetPosPixel();
153 Point aPBPos
= m_aPB_Connection
.GetPosPixel();
155 aEDPos
.Y() = aPos
.Y() + aEDPos
.Y() - aFTPos
.Y();
156 aPBPos
.Y() = aPos
.Y() + aPBPos
.Y() - aFTPos
.Y();
157 aFTPos
.Y() = aPos
.Y();
158 m_aFT_Connection
.SetPosPixel(aFTPos
);
159 m_aConnectionURL
.SetPosPixel(aEDPos
);
160 m_aPB_Connection
.SetPosPixel(aPBPos
);
164 m_aFT_Connection
.Hide();
166 m_aConnectionURL
.SetModifyHdl(LINK(this, OConnectionTabPageSetup
, OnEditModified
));
168 SetRoadmapStateValue(sal_False
);
171 // -----------------------------------------------------------------------
172 OConnectionTabPageSetup::~OConnectionTabPageSetup()
174 DBG_DTOR(OConnectionTabPageSetup
,NULL
);
177 // -----------------------------------------------------------------------
178 void OConnectionTabPageSetup::implInitControls(const SfxItemSet
& _rSet
, sal_Bool _bSaveValue
)
180 m_eType
= m_pAdminDialog
->getDatasourceType(_rSet
);
181 // special handling for oracle, this can only happen
182 // if the user enters the same url as used for Oracle and we are on the JDBC path
184 //if ( ::dbaccess::DST_ORACLE_JDBC == m_eType )
185 // m_eType = ::dbaccess::DST_JDBC;
187 OConnectionHelper::implInitControls(_rSet
, _bSaveValue
);
190 //if ( m_eType >= ::dbaccess::DST_USERDEFINE1 )
192 // String sDisplayName = m_pCollection->getTypeDisplayName(m_eType);
193 // FixedText* ppTextControls[] ={&m_aFT_Connection};
194 // for (size_t i = 0; i < sizeof(ppTextControls)/sizeof(ppTextControls[0]); ++i)
196 // ppTextControls[i]->SetText(sDisplayName);
202 // -----------------------------------------------------------------------
203 sal_Bool
OConnectionTabPageSetup::commitPage( ::svt::WizardTypes::CommitPageReason
/*_eReason*/ )
208 // -----------------------------------------------------------------------
209 sal_Bool
OConnectionTabPageSetup::FillItemSet(SfxItemSet
& _rSet
)
211 sal_Bool bChangedSomething
= sal_False
;
212 fillString(_rSet
,&m_aConnectionURL
, DSID_CONNECTURL
, bChangedSomething
);
213 return bChangedSomething
;
215 // -----------------------------------------------------------------------
216 bool OConnectionTabPageSetup::checkTestConnection()
218 return !m_aConnectionURL
.IsVisible() || (m_aConnectionURL
.GetTextNoPrefix().Len() != 0);
221 // -----------------------------------------------------------------------
222 IMPL_LINK(OConnectionTabPageSetup
, OnEditModified
, Edit
*, /*_pEdit*/)
224 SetRoadmapStateValue(checkTestConnection());
228 //.........................................................................
230 //.........................................................................
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */