Kaydet (Commit) 9dc5234d authored tarafından Caolán McNamara's avatar Caolán McNamara

weld OConnectionTabPage

Change-Id: Icdbe5d95d0850d131018d21d0a21cb12109d565c
Reviewed-on: https://gerrit.libreoffice.org/62283
Tested-by: Jenkins
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 9844b3e6
...@@ -150,6 +150,68 @@ void OConnectionURLEdit::ShowPrefix(bool _bShowPrefix) ...@@ -150,6 +150,68 @@ void OConnectionURLEdit::ShowPrefix(bool _bShowPrefix)
m_pForcedPrefix->Show(m_bShowPrefix); m_pForcedPrefix->Show(m_bShowPrefix);
} }
DBOConnectionURLEdit::DBOConnectionURLEdit(std::unique_ptr<weld::Entry> xEntry, std::unique_ptr<weld::Label> xForcedPrefix)
: m_pTypeCollection(nullptr)
, m_bShowPrefix(false)
, m_xEntry(std::move(xEntry))
, m_xForcedPrefix(std::move(xForcedPrefix))
{
}
DBOConnectionURLEdit::~DBOConnectionURLEdit()
{
}
void DBOConnectionURLEdit::SetTextNoPrefix(const OUString& _rText)
{
m_xEntry->set_text(_rText);
}
OUString DBOConnectionURLEdit::GetTextNoPrefix() const
{
return m_xEntry->get_text();
}
void DBOConnectionURLEdit::SetText(const OUString& _rStr)
{
Selection aNoSelection(0,0);
SetText(_rStr, aNoSelection);
}
void DBOConnectionURLEdit::SetText(const OUString& _rStr, const Selection& /*_rNewSelection*/)
{
m_xForcedPrefix->show(m_bShowPrefix);
bool bIsEmpty = _rStr.isEmpty();
// calc the prefix
OUString sPrefix;
if (!bIsEmpty)
{
// determine the type of the new URL described by the new text
sPrefix = m_pTypeCollection->getPrefix(_rStr);
}
// the fixed text gets the prefix
m_xForcedPrefix->set_label(sPrefix);
// do the real SetText
OUString sNewText( _rStr );
if ( !bIsEmpty )
sNewText = m_pTypeCollection->cutPrefix( _rStr );
m_xEntry->set_text(sNewText);
}
OUString DBOConnectionURLEdit::GetText() const
{
return m_xForcedPrefix->get_label() + m_xEntry->get_text();
}
void DBOConnectionURLEdit::ShowPrefix(bool _bShowPrefix)
{
m_bShowPrefix = _bShowPrefix;
m_xForcedPrefix->show(m_bShowPrefix);
}
} // namespace dbaui } // namespace dbaui
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -98,6 +98,72 @@ namespace dbaui ...@@ -98,6 +98,72 @@ namespace dbaui
void implUpdateURLDependentStates() const; void implUpdateURLDependentStates() const;
}; };
class DBOConnectionHelper : public OGenericAdministrationPage
{
bool m_bUserGrabFocus;
public:
DBOConnectionHelper(TabPageParent pParent, const OUString& _rUIXMLDescription, const OString& _rId, const SfxItemSet& _rCoreAttrs);
virtual ~DBOConnectionHelper() override;
virtual void dispose() override;
OUString m_eType; // the type can't be changed in this class, so we hold it as member.
// setting/retrieving the current connection URL
// necessary because for some types, the URL must be decoded for display purposes
::dbaccess::ODsnTypeCollection* m_pCollection; /// the DSN type collection instance
std::unique_ptr<weld::Label> m_xFT_Connection;
std::unique_ptr<weld::Button> m_xPB_Connection;
std::unique_ptr<weld::Button> m_xPB_CreateDB;
std::unique_ptr<DBOConnectionURLEdit> m_xConnectionURL;
public:
// <method>OGenericAdministrationPage::fillControls</method>
virtual void fillControls(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList) override;
// <method>OGenericAdministrationPage::fillWindows</method>
virtual void fillWindows(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList) override;
virtual void implInitControls(const SfxItemSet& _rSet, bool _bSaveValue) override;
// setting/retrieving the current connection URL
// necessary because for some types, the URL must be decoded for display purposes
//String getURL( OConnectionURLEdit* _m_pConnection ) const;
//void setURL( const OUString& _rURL, OConnectionURLEdit* _m_pConnection );
OUString getURLNoPrefix( ) const;
void setURLNoPrefix( const OUString& _rURL );
/** checks if the path is existence
@param _rURL
The URL to check.
*/
sal_Int32 checkPathExistence(const OUString& _rURL);
IS_PATH_EXIST pathExists(const OUString& _rURL, bool bIsFile) const;
bool createDirectoryDeep(const OUString& _rPathNormalized);
void commitURL();
/** opens the FileOpen dialog and asks for a FileName
@param _aFileOpen
Executes the file open dialog, which must be filled from caller.
*/
void askForFileName(::sfx2::FileDialogHelper& _aFileOpen);
protected:
void setURL( const OUString& _rURL );
virtual bool checkTestConnection();
private:
DECL_LINK(OnBrowseConnections, weld::Button&, void);
DECL_LINK(OnCreateDatabase, weld::Button&, void);
DECL_LINK(GetFocusHdl, weld::Widget&, void);
DECL_LINK(LoseFocusHdl, weld::Widget&, void);
OUString impl_getURL() const;
void impl_setURL( const OUString& _rURL, bool _bPrefix );
void implUpdateURLDependentStates() const;
};
} // namespace dbaui } // namespace dbaui
#endif // INCLUDED_DBACCESS_SOURCE_UI_DLG_CONNECTIONHELPER_HXX #endif // INCLUDED_DBACCESS_SOURCE_UI_DLG_CONNECTIONHELPER_HXX
......
...@@ -32,32 +32,31 @@ namespace dbaui ...@@ -32,32 +32,31 @@ namespace dbaui
/** implements the connection page of the data source properties dialog. /** implements the connection page of the data source properties dialog.
*/ */
class OConnectionTabPage final : public OConnectionHelper class OConnectionTabPage final : public DBOConnectionHelper
{ {
friend class VclPtr<OConnectionTabPage>; friend class VclPtr<OConnectionTabPage>;
private: private:
// user authentication // user authentication
VclPtr<FixedText> m_pFL2; std::unique_ptr<weld::Label> m_xFL2;
VclPtr<FixedText> m_pUserNameLabel; std::unique_ptr<weld::Label> m_xUserNameLabel;
VclPtr<Edit> m_pUserName; std::unique_ptr<weld::Entry> m_xUserName;
VclPtr<CheckBox> m_pPasswordRequired; std::unique_ptr<weld::CheckButton> m_xPasswordRequired;
// jdbc driver // jdbc driver
VclPtr<FixedText> m_pFL3; std::unique_ptr<weld::Label> m_xFL3;
VclPtr<FixedText> m_pJavaDriverLabel; std::unique_ptr<weld::Label> m_xJavaDriverLabel;
VclPtr<Edit> m_pJavaDriver; std::unique_ptr<weld::Entry> m_xJavaDriver;
VclPtr<PushButton> m_pTestJavaDriver; std::unique_ptr<weld::Button> m_xTestJavaDriver;
// connection test // connection test
VclPtr<PushButton> m_pTestConnection; std::unique_ptr<weld::Button> m_xTestConnection;
// called when the test connection button was clicked // called when the test connection button was clicked
DECL_LINK(OnTestJavaClickHdl, Button*, void); DECL_LINK(OnTestJavaClickHdl, weld::Button&, void);
DECL_LINK(OnEditModified, Edit&, void); DECL_LINK(OnEditModified, weld::Entry&, void);
public: public:
virtual ~OConnectionTabPage() override; virtual ~OConnectionTabPage() override;
virtual void dispose() override;
static VclPtr<SfxTabPage> Create( TabPageParent pParent, const SfxItemSet* _rAttrSet ); static VclPtr<SfxTabPage> Create( TabPageParent pParent, const SfxItemSet* _rAttrSet );
virtual bool FillItemSet (SfxItemSet* _rCoreAttrs) override; virtual bool FillItemSet (SfxItemSet* _rCoreAttrs) override;
...@@ -68,7 +67,7 @@ namespace dbaui ...@@ -68,7 +67,7 @@ namespace dbaui
affect the type may be changed (compared to the previous URL).</p> affect the type may be changed (compared to the previous URL).</p>
*/ */
private: private:
OConnectionTabPage(vcl::Window* pParent, const SfxItemSet& _rCoreAttrs); OConnectionTabPage(TabPageParent pParent, const SfxItemSet& _rCoreAttrs);
// nControlFlags is a combination of the CBTP_xxx-constants // nControlFlags is a combination of the CBTP_xxx-constants
/** enables the test connection button, if allowed /** enables the test connection button, if allowed
......
...@@ -292,6 +292,14 @@ namespace dbaui ...@@ -292,6 +292,14 @@ namespace dbaui
_bChangedSomething = true; _bChangedSomething = true;
} }
} }
void OGenericAdministrationPage::fillString(SfxItemSet& _rSet, const dbaui::DBOConnectionURLEdit* pEdit, sal_uInt16 _nID, bool& _bChangedSomething)
{
if (pEdit && pEdit->get_value_changed_from_saved())
{
_rSet.Put(SfxStringItem(_nID, pEdit->GetText()));
_bChangedSomething = true;
}
}
IMPL_LINK_NOARG(OGenericAdministrationPage, OnTestConnectionClickHdl, Button*, void) IMPL_LINK_NOARG(OGenericAdministrationPage, OnTestConnectionClickHdl, Button*, void)
{ {
...@@ -334,6 +342,47 @@ namespace dbaui ...@@ -334,6 +342,47 @@ namespace dbaui
} }
} }
IMPL_LINK_NOARG(OGenericAdministrationPage, OnTestConnectionButtonClickHdl, weld::Button&, void)
{
OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
bool bSuccess = false;
if ( m_pAdminDialog )
{
m_pAdminDialog->saveDatasource();
OGenericAdministrationPage::implInitControls(*m_pItemSetHelper->getOutputSet(), true);
bool bShowMessage = true;
try
{
std::pair< Reference<XConnection>,bool> aConnectionPair = m_pAdminDialog->createConnection();
bShowMessage = aConnectionPair.second;
bSuccess = aConnectionPair.first.is();
::comphelper::disposeComponent(aConnectionPair.first);
}
catch(Exception&)
{
}
if ( bShowMessage )
{
MessageType eImage = MessageType::Info;
OUString aMessage,sTitle;
sTitle = DBA_RES(STR_CONNECTION_TEST);
if ( bSuccess )
{
aMessage = DBA_RES(STR_CONNECTION_SUCCESS);
}
else
{
eImage = MessageType::Error;
aMessage = DBA_RES(STR_CONNECTION_NO_SUCCESS);
}
OSQLMessageBox aMsg(GetFrameWeld(), sTitle, aMessage, MessBoxStyle::Ok, eImage);
aMsg.run();
}
if ( !bSuccess )
m_pAdminDialog->clearPassword();
}
}
// LayoutHelper // LayoutHelper
void LayoutHelper::positionBelow( const Control& _rReference, Control& _rControl, void LayoutHelper::positionBelow( const Control& _rReference, Control& _rControl,
const long _nIndentAppFont ) const long _nIndentAppFont )
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <svtools/wizardmachine.hxx> #include <svtools/wizardmachine.hxx>
#include <vcl/field.hxx> #include <vcl/field.hxx>
#include <vcl/fixed.hxx> #include <vcl/fixed.hxx>
#include <curledit.hxx>
class NumericField; class NumericField;
class Edit; class Edit;
...@@ -73,6 +74,17 @@ namespace dbaui ...@@ -73,6 +74,17 @@ namespace dbaui
virtual void Disable() override { m_pSaveValue->set_sensitive(false); } virtual void Disable() override { m_pSaveValue->set_sensitive(false); }
}; };
template <> class OSaveValueWidgetWrapper<dbaui::DBOConnectionURLEdit> : public ISaveValueWrapper
{
dbaui::DBOConnectionURLEdit* m_pSaveValue;
public:
explicit OSaveValueWidgetWrapper(dbaui::DBOConnectionURLEdit* _pSaveValue) : m_pSaveValue(_pSaveValue)
{ OSL_ENSURE(m_pSaveValue,"Illegal argument!"); }
virtual void SaveValue() override { m_pSaveValue->save_value(); }
virtual void Disable() override { m_pSaveValue->set_sensitive(false); }
};
template <class T> class ODisableWidgetWrapper : public ISaveValueWrapper template <class T> class ODisableWidgetWrapper : public ISaveValueWrapper
{ {
T* m_pSaveValue; T* m_pSaveValue;
...@@ -238,6 +250,7 @@ namespace dbaui ...@@ -238,6 +250,7 @@ namespace dbaui
*/ */
static void fillString(SfxItemSet& _rSet,Edit const * _pEdit,sal_uInt16 _nID, bool& _bChangedSomething); static void fillString(SfxItemSet& _rSet,Edit const * _pEdit,sal_uInt16 _nID, bool& _bChangedSomething);
static void fillString(SfxItemSet& _rSet,const weld::Entry* pEdit,sal_uInt16 _nID, bool& _bChangedSomething); static void fillString(SfxItemSet& _rSet,const weld::Entry* pEdit,sal_uInt16 _nID, bool& _bChangedSomething);
static void fillString(SfxItemSet& _rSet,const dbaui::DBOConnectionURLEdit* pEdit,sal_uInt16 _nID, bool& _bChangedSomething);
protected: protected:
/** This link be used for controls where the tabpage does not need to take any special action when the control /** This link be used for controls where the tabpage does not need to take any special action when the control
...@@ -251,6 +264,7 @@ namespace dbaui ...@@ -251,6 +264,7 @@ namespace dbaui
DECL_LINK(OnControlModifiedClick, Button*, void); DECL_LINK(OnControlModifiedClick, Button*, void);
DECL_LINK(ControlModifiedCheckBoxHdl, CheckBox&, void); DECL_LINK(ControlModifiedCheckBoxHdl, CheckBox&, void);
DECL_LINK(OnTestConnectionButtonClickHdl, weld::Button&, void);
DECL_LINK(OnTestConnectionClickHdl, Button*, void); DECL_LINK(OnTestConnectionClickHdl, Button*, void);
}; };
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <vcl/edit.hxx> #include <vcl/edit.hxx>
#include <vcl/fixed.hxx> #include <vcl/fixed.hxx>
#include <vcl/weld.hxx>
#include <dsntypes.hxx> #include <dsntypes.hxx>
namespace dbaui namespace dbaui
...@@ -67,6 +68,78 @@ public: ...@@ -67,6 +68,78 @@ public:
void SetTypeCollection(::dbaccess::ODsnTypeCollection* _pTypeCollection) { m_pTypeCollection = _pTypeCollection; } void SetTypeCollection(::dbaccess::ODsnTypeCollection* _pTypeCollection) { m_pTypeCollection = _pTypeCollection; }
}; };
class DBOConnectionURLEdit
{
OUString m_sSavedValue;
::dbaccess::ODsnTypeCollection* m_pTypeCollection;
OUString m_sSaveValueNoPrefix;
bool m_bShowPrefix; // when <TRUE> the prefix will be visible, otherwise not
std::unique_ptr<weld::Entry> m_xEntry;
std::unique_ptr<weld::Label> m_xForcedPrefix;
public:
DBOConnectionURLEdit(std::unique_ptr<weld::Entry> xEntry, std::unique_ptr<weld::Label> xForcedPrefix);
~DBOConnectionURLEdit();
public:
bool get_visible() const { return m_xEntry->get_visible(); }
void connect_changed(const Link<weld::Entry&, void>& rLink) { m_xEntry->connect_changed(rLink); }
void set_help_id(const OString& rName) { m_xEntry->set_help_id(rName); }
void hide()
{
m_xEntry->hide();
if (m_bShowPrefix)
m_xForcedPrefix->hide();
}
void show()
{
m_xEntry->show();
if (m_bShowPrefix)
m_xForcedPrefix->show();
}
void save_value() { m_sSavedValue = GetText(); }
bool get_value_changed_from_saved() const { return m_sSavedValue != GetText(); }
void grab_focus()
{
m_xEntry->grab_focus();
}
void set_sensitive(bool bSensitive)
{
m_xEntry->set_sensitive(bSensitive);
if (m_bShowPrefix)
m_xForcedPrefix->set_sensitive(bSensitive);
}
void connect_focus_in(const Link<weld::Widget&, void>& rLink)
{
m_xEntry->connect_focus_in(rLink);
}
void connect_focus_out(const Link<weld::Widget&, void>& rLink)
{
m_xEntry->connect_focus_out(rLink);
}
// Edit overridables
void SetText(const OUString& _rStr);
void SetText(const OUString& _rStr, const Selection& _rNewSelection);
OUString GetText() const;
/** Shows the Prefix
@param _bShowPrefix
If <TRUE/> than the prefix will be visible, otherwise not.
*/
void ShowPrefix(bool _bShowPrefix);
/// get the currently set text, excluding the prefix indicating the type
OUString GetTextNoPrefix() const;
/// set a new text, leave the current prefix unchanged
void SetTextNoPrefix(const OUString& _rText);
void SaveValueNoPrefix() { m_sSaveValueNoPrefix = GetTextNoPrefix(); }
const OUString& GetSavedValueNoPrefix() const { return m_sSaveValueNoPrefix; }
void SetTypeCollection(::dbaccess::ODsnTypeCollection* _pTypeCollection) { m_pTypeCollection = _pTypeCollection; }
};
} // namespace dbaui } // namespace dbaui
#endif // INCLUDED_DBACCESS_SOURCE_UI_INC_CURLEDIT_HXX #endif // INCLUDED_DBACCESS_SOURCE_UI_INC_CURLEDIT_HXX
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 --> <!-- Generated with glade 3.22.1 -->
<interface domain="dba"> <interface domain="dba">
<requires lib="gtk+" version="3.18"/> <requires lib="gtk+" version="3.18"/>
<requires lib="LibreOffice" version="1.0"/>
<object class="GtkBox" id="ConnectionPage"> <object class="GtkBox" id="ConnectionPage">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
...@@ -47,17 +46,6 @@ ...@@ -47,17 +46,6 @@
<property name="top_attach">0</property> <property name="top_attach">0</property>
</packing> </packing>
</child> </child>
<child>
<object class="dbulo-ConnectionURLEdit" id="browseurl">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child> <child>
<object class="GtkButton" id="create"> <object class="GtkButton" id="create">
<property name="label" translatable="yes" context="connectionpage|create">_Create New</property> <property name="label" translatable="yes" context="connectionpage|create">_Create New</property>
...@@ -84,6 +72,37 @@ ...@@ -84,6 +72,37 @@
<property name="top_attach">1</property> <property name="top_attach">1</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkEntry" id="browseurl">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="browselabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
</object> </object>
</child> </child>
</object> </object>
...@@ -133,10 +152,10 @@ ...@@ -133,10 +152,10 @@
<object class="GtkLabel" id="userNameLabel"> <object class="GtkLabel" id="userNameLabel">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes" context="connectionpage|userNameLabel">_User name:</property> <property name="label" translatable="yes" context="connectionpage|userNameLabel">_User name:</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="mnemonic_widget">userNameEntry</property> <property name="mnemonic_widget">userNameEntry</property>
<property name="xalign">1</property>
</object> </object>
<packing> <packing>
<property name="left_attach">0</property> <property name="left_attach">0</property>
...@@ -220,10 +239,10 @@ ...@@ -220,10 +239,10 @@
<object class="GtkLabel" id="javaDriverLabel"> <object class="GtkLabel" id="javaDriverLabel">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes" context="connectionpage|javaDriverLabel">_JDBC driver class:</property> <property name="label" translatable="yes" context="connectionpage|javaDriverLabel">_JDBC driver class:</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="mnemonic_widget">driverEntry</property> <property name="mnemonic_widget">driverEntry</property>
<property name="xalign">1</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment