Add "New Database" button for Firebird file driver dialog.

Firebird is able to create new databases from within LO hence we need
to add a new property to database configration files.

This allows use of a db creation dialog (which is opened
by using the "New Database" button) in order to allow creating new
dialogs (in addition to being able to open existing databases using
the "Browse" button).

Conflicts:
	dbaccess/source/ui/dlg/ConnectionHelper.hxx

Change-Id: I6174f3b7d9032c48286b49b5ddf125cd3b428303
This commit is contained in:
Andrzej J.R. Hunt 2013-09-20 14:36:18 +01:00
parent ee9bee5d46
commit 117b24dbbd
7 changed files with 73 additions and 3 deletions

View File

@ -275,6 +275,12 @@ sal_Bool ODsnTypeCollection::supportsBrowsing(const OUString& _sURL) const
return aFeatures.getOrDefault("SupportsBrowsing",sal_False);
}
sal_Bool ODsnTypeCollection::supportsDBCreation(const OUString& _sURL) const
{
const ::comphelper::NamedValueCollection& aFeatures = m_aDriverConfig.getMetaData(_sURL);
return aFeatures.getOrDefault("SupportsDBCreation",sal_False);
}
bool ODsnTypeCollection::needsJVM(const OUString& _sURL) const
{
const ::comphelper::NamedValueCollection& aFeatures = m_aDriverConfig.getMetaData(_sURL);

View File

@ -147,6 +147,9 @@ public:
// check if a Browse button may be shown to insert connection url
sal_Bool supportsBrowsing(const OUString& _sURL) const;
// check if a Create New Database button may be shown to insert connection url
sal_Bool supportsDBCreation(const OUString& _sURL) const;
/// check if the given data source tyoe is based on the file system - i.e. the URL is a prefix plus a file URL
sal_Bool isFileSystemBased(const OUString& _sURL) const;

View File

@ -58,6 +58,7 @@
#define PB_AUTOTESTDRIVERCLASS 80
#define PB_AUTOBROWSEURL 81
#define PB_CREATEDB 82
#define CM_AUTOFIELDSEPARATOR 80
#define CM_AUTOTEXTSEPARATOR 81
@ -132,6 +133,15 @@
HelpId = AUTO_HID2; \
TabStop = TRUE ; \
Text[ en-US ] = "Browse"; \
}; \
\
PushButton PB_CREATEDB \
{ \
Pos = MAP_APPFONT ( AUTOPAGE_X - BUTTON_WIDTH - 6 , AUTO_Y - BUTTON_HEIGHT ) ; \
Size = MAP_APPFONT ( BUTTON_WIDTH , BUTTON_HEIGHT ) ; \
HelpId = AUTO_HID2; \
TabStop = TRUE ; \
Text[ en-US ] = "Create New"; \
};
// --------------------------------------------------------------------------------------------------

View File

@ -95,6 +95,7 @@ DBG_NAME(OConnectionHelper)
,m_aFT_Connection ( this, ResId( FT_AUTOBROWSEURL, *_rId.GetResMgr() ) )
,m_aConnectionURL ( this, ResId( ET_AUTOBROWSEURL, *_rId.GetResMgr() ) )
,m_aPB_Connection ( this, ResId( PB_AUTOBROWSEURL, *_rId.GetResMgr() ) )
,m_aPB_CreateDB ( this, ResId( PB_CREATEDB, *_rId.GetResMgr() ) )
{
DBG_CTOR(OConnectionHelper,NULL);
@ -103,6 +104,7 @@ DBG_NAME(OConnectionHelper)
if (pCollectionItem)
m_pCollection = pCollectionItem->getCollection();
m_aPB_Connection.SetClickHdl(LINK(this, OConnectionHelper, OnBrowseConnections));
m_aPB_CreateDB.SetClickHdl(LINK(this, OConnectionHelper, OnCreateDatabase));
OSL_ENSURE(m_pCollection, "OConnectionHelper::OConnectionHelper : really need a DSN type collection !");
m_aConnectionURL.SetTypeCollection(m_pCollection);
}
@ -126,6 +128,9 @@ DBG_NAME(OConnectionHelper)
sal_Bool bEnableBrowseButton = m_pCollection->supportsBrowsing( m_eType );
m_aPB_Connection.Show( bEnableBrowseButton );
sal_Bool bEnableCreateButton = m_pCollection->supportsDBCreation( m_eType );
m_aPB_CreateDB.Show( bEnableCreateButton );
SFX_ITEMSET_GET(_rSet, pUrlItem, SfxStringItem, DSID_CONNECTURL, sal_True);
// forward the values to the controls
@ -308,6 +313,43 @@ DBG_NAME(OConnectionHelper)
setURLNoPrefix(aSelector.GetSelected());
break;
}
case ::dbaccess::DST_FIREBIRD:
{
const OUString sExt("*.fdb");
OUString sFilterName(ModuleRes (STR_FIREBIRD_FILTERNAME));
::sfx2::FileDialogHelper aFileDlg(
ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
0);
aFileDlg.AddFilter(sFilterName,sExt);
aFileDlg.SetCurrentFilter(sFilterName);
askForFileName(aFileDlg);
}
default:
break;
}
checkTestConnection();
return 0L;
}
IMPL_LINK(OConnectionHelper, OnCreateDatabase, PushButton*, /*_pButton*/)
{
OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
const ::dbaccess::DATASOURCE_TYPE eType = m_pCollection->determineType(m_eType);
switch ( eType )
{
case ::dbaccess::DST_FIREBIRD:
{
const OUString sExt("*.fdb");
OUString sFilterName(ModuleRes (STR_FIREBIRD_FILTERNAME));
::sfx2::FileDialogHelper aFileDlg(
ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
0);
aFileDlg.AddFilter(sFilterName,sExt);
aFileDlg.SetCurrentFilter(sFilterName);
askForFileName(aFileDlg);
}
default:
break;
}
@ -421,7 +463,8 @@ DBG_NAME(OConnectionHelper)
sal_Int32 OConnectionHelper::checkPathExistence(const OUString& _rURL)
{
IS_PATH_EXIST e_exists = pathExists(_rURL, sal_False);
if (( e_exists == PATH_NOT_EXIST) || ( e_exists == PATH_NOT_KNOWN))
if (!m_pCollection->supportsDBCreation(m_eType) &&
(( e_exists == PATH_NOT_EXIST) || ( e_exists == PATH_NOT_KNOWN)))
{
OUString sQuery(ModuleRes(STR_ASK_FOR_DIRECTORY_CREATION));
OFileNotation aTransformer(_rURL);
@ -605,6 +648,7 @@ DBG_NAME(OConnectionHelper)
{
_rControlList.push_back(new ODisableWrapper<FixedText>(&m_aFT_Connection));
_rControlList.push_back(new ODisableWrapper<PushButton>(&m_aPB_Connection));
_rControlList.push_back(new ODisableWrapper<PushButton>(&m_aPB_CreateDB));
}
void OConnectionHelper::fillControls(::std::vector< ISaveValueWrapper* >& _rControlList)

View File

@ -45,6 +45,7 @@ namespace dbaui
FixedText m_aFT_Connection;
OConnectionURLEdit m_aConnectionURL;
PushButton m_aPB_Connection;
PushButton m_aPB_CreateDB;
OUString m_eType; // the type can't be changed in this class, so we hold it as member.
public:
@ -90,6 +91,7 @@ namespace dbaui
private:
DECL_LINK(OnBrowseConnections, PushButton*);
DECL_LINK(OnCreateDatabase, PushButton*);
OUString impl_getURL( sal_Bool _bPrefix ) const;
void impl_setURL( const OUString& _rURL, sal_Bool _bPrefix );
void implUpdateURLDependentStates() const;

View File

@ -167,4 +167,9 @@ String STR_MSACCESS_2007_FILTERNAME
Text [ en-US ] = "MS Access 2007 file";
};
String STR_FIREBIRD_FILTERNAME
{
Text [ en-US ] = "Firebird Database";
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -108,11 +108,11 @@
#define STR_EXCEPTION_INFO RID_STR_DLG_START + 64
#define STR_EXCEPTION_DETAILS RID_STR_DLG_START + 65
#define STR_MSACCESS_2007_FILTERNAME RID_STR_DLG_START + 66
#define STR_FIREBIRD_FILTERNAME RID_STR_DLG_START + 67
// please adjust checking before insert new strings
#define LAST_STR_HERE RID_STR_DLG_START + 67
#define LAST_STR_HERE RID_STR_DLG_START + 68
#if LAST_STR_HERE > RID_STR_DLG_END
#error Resource-Id Overflow in #file, #line