Kaydet (Commit) 69e890b1 authored tarafından Caolán McNamara's avatar Caolán McNamara

weld ODatasourceSelectDialog

Change-Id: I33a45f6d68c4a6cba63301dbb6c94ea661365a9a
Reviewed-on: https://gerrit.libreoffice.org/68651
Tested-by: Jenkins
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 4a88213b
...@@ -310,16 +310,16 @@ namespace dbaui ...@@ -310,16 +310,16 @@ namespace dbaui
aProfiles.insert(pArray[index]); aProfiles.insert(pArray[index]);
// execute the select dialog // execute the select dialog
ScopedVclPtrInstance< ODatasourceSelectDialog > aSelector(GetParent(), aProfiles); ODatasourceSelectDialog aSelector(GetFrameWeld(), aProfiles);
OUString sOldProfile=getURLNoPrefix(); OUString sOldProfile=getURLNoPrefix();
if (!sOldProfile.isEmpty()) if (!sOldProfile.isEmpty())
aSelector->Select(sOldProfile); aSelector.Select(sOldProfile);
else else
aSelector->Select(xMozillaBootstrap->getDefaultProfile(profileType)); aSelector.Select(xMozillaBootstrap->getDefaultProfile(profileType));
if ( RET_OK == aSelector->Execute() ) if (RET_OK == aSelector.run())
setURLNoPrefix(aSelector->GetSelected()); setURLNoPrefix(aSelector.GetSelected());
break; break;
} }
case ::dbaccess::DST_FIREBIRD: case ::dbaccess::DST_FIREBIRD:
......
...@@ -168,11 +168,11 @@ namespace dbaui ...@@ -168,11 +168,11 @@ namespace dbaui
{ {
aEnumeration.getDatasourceNames(aOdbcDatasources); aEnumeration.getDatasourceNames(aOdbcDatasources);
// execute the select dialog // execute the select dialog
ScopedVclPtrInstance< ODatasourceSelectDialog > aSelector(GetParent(), aOdbcDatasources); ODatasourceSelectDialog aSelector(GetFrameWeld(), aOdbcDatasources);
if (!_sCurr.isEmpty()) if (!_sCurr.isEmpty())
aSelector->Select(_sCurr); aSelector.Select(_sCurr);
if ( RET_OK == aSelector->Execute() ) if (RET_OK == aSelector.run())
_sReturn = aSelector->GetSelected(); _sReturn = aSelector.GetSelected();
} }
return true; return true;
} }
......
...@@ -42,115 +42,101 @@ using namespace ::com::sun::star::sdbcx; ...@@ -42,115 +42,101 @@ using namespace ::com::sun::star::sdbcx;
using namespace ::com::sun::star::ui::dialogs; using namespace ::com::sun::star::ui::dialogs;
using namespace ::comphelper; using namespace ::comphelper;
ODatasourceSelectDialog::ODatasourceSelectDialog(vcl::Window* _pParent, const std::set<OUString>& _rDatasources) ODatasourceSelectDialog::ODatasourceSelectDialog(weld::Window* _pParent, const std::set<OUString>& _rDatasources)
: ModalDialog(_pParent, "ChooseDataSourceDialog", : GenericDialogController(_pParent, "dbaccess/ui/choosedatasourcedialog.ui", "ChooseDataSourceDialog")
"dbaccess/ui/choosedatasourcedialog.ui") , m_xDatasource(m_xBuilder->weld_tree_view("treeview"))
, m_xOk(m_xBuilder->weld_button("ok"))
, m_xCancel(m_xBuilder->weld_button("cancel"))
, m_xManageDatasources(m_xBuilder->weld_button("organize"))
{ {
get(m_pDatasource, "treeview"); m_xDatasource->set_size_request(-1, m_xDatasource->get_height_rows(6));
m_pDatasource->set_height_request(m_pDatasource->GetTextHeight() * 6);
get(m_pOk, "ok");
get(m_pCancel, "cancel");
fillListBox(_rDatasources); fillListBox(_rDatasources);
#ifdef HAVE_ODBC_ADMINISTRATION #ifdef HAVE_ODBC_ADMINISTRATION
get(m_pManageDatasources, "organize");
m_pManageDatasources->Show();
// allow ODBC datasource management // allow ODBC datasource management
m_pManageDatasources->Show(); m_xManageDatasources->show();
m_pManageDatasources->Enable(); m_xManageDatasources->set_sensitive(true);
m_pManageDatasources->SetClickHdl(LINK(this,ODatasourceSelectDialog,ManageClickHdl)); m_xManageDatasources->connect_clicked(LINK(this,ODatasourceSelectDialog,ManageClickHdl));
#endif #endif
m_pDatasource->SetDoubleClickHdl(LINK(this,ODatasourceSelectDialog,ListDblClickHdl)); m_xDatasource->connect_row_activated(LINK(this,ODatasourceSelectDialog,ListDblClickHdl));
} }
ODatasourceSelectDialog::~ODatasourceSelectDialog() ODatasourceSelectDialog::~ODatasourceSelectDialog()
{ {
disposeOnce();
}
void ODatasourceSelectDialog::dispose()
{
m_pDatasource.clear();
m_pOk.clear();
m_pCancel.clear();
#if defined HAVE_ODBC_ADMINISTRATION
m_pManageDatasources.clear();
#endif
ModalDialog::dispose();
} }
IMPL_LINK(ODatasourceSelectDialog, ListDblClickHdl, weld::TreeView&, rListBox, void)
IMPL_LINK( ODatasourceSelectDialog, ListDblClickHdl, ListBox&, rListBox, void )
{ {
if (rListBox.GetSelectedEntryCount()) if (rListBox.n_children())
EndDialog(RET_OK); m_xDialog->response(RET_OK);
} }
bool ODatasourceSelectDialog::Close() short ODatasourceSelectDialog::run()
{ {
short nRet = GenericDialogController::run();
#ifdef HAVE_ODBC_ADMINISTRATION #ifdef HAVE_ODBC_ADMINISTRATION
if ( m_pODBCManagement.get() && m_pODBCManagement->isRunning() ) if (m_xODBCManagement.get())
return false; m_xODBCManagement->disableCallback();
#endif #endif
return nRet;
return ModalDialog::Close();
} }
#ifdef HAVE_ODBC_ADMINISTRATION #ifdef HAVE_ODBC_ADMINISTRATION
IMPL_LINK_NOARG(ODatasourceSelectDialog, ManageClickHdl, Button*, void) IMPL_LINK_NOARG(ODatasourceSelectDialog, ManageClickHdl, weld::Button&, void)
{ {
if ( !m_pODBCManagement.get() ) if ( !m_xODBCManagement.get() )
m_pODBCManagement.reset( new OOdbcManagement( LINK( this, ODatasourceSelectDialog, ManageProcessFinished ) ) ); m_xODBCManagement.reset( new OOdbcManagement( LINK( this, ODatasourceSelectDialog, ManageProcessFinished ) ) );
if ( !m_pODBCManagement->manageDataSources_async() ) if ( !m_xODBCManagement->manageDataSources_async() )
{ {
// TODO: error message // TODO: error message
m_pDatasource->GrabFocus(); m_xDatasource->grab_focus();
m_pManageDatasources->Disable(); m_xManageDatasources->set_sensitive(false);
return; return;
} }
m_pDatasource->Disable(); m_xDatasource->set_sensitive(false);
m_pOk->Disable(); m_xOk->set_sensitive(false);
m_pCancel->Disable(); m_xCancel->set_sensitive(false);
m_pManageDatasources->Disable(); m_xManageDatasources->set_sensitive(false);
SAL_WARN_IF( !m_pODBCManagement->isRunning(), "dbaccess.ui", "ODatasourceSelectDialog::ManageClickHdl: success, but not running - you were *fast*!" ); SAL_WARN_IF( !m_xODBCManagement->isRunning(), "dbaccess.ui", "ODatasourceSelectDialog::ManageClickHdl: success, but not running - you were *fast*!" );
} }
IMPL_LINK_NOARG( ODatasourceSelectDialog, ManageProcessFinished, void*, void ) IMPL_LINK_NOARG( ODatasourceSelectDialog, ManageProcessFinished, void*, void )
{ {
m_xODBCManagement->receivedCallback();
std::set<OUString> aOdbcDatasources; std::set<OUString> aOdbcDatasources;
OOdbcEnumeration aEnumeration; OOdbcEnumeration aEnumeration;
aEnumeration.getDatasourceNames( aOdbcDatasources ); aEnumeration.getDatasourceNames( aOdbcDatasources );
fillListBox( aOdbcDatasources ); fillListBox( aOdbcDatasources );
m_pDatasource->Enable(); m_xDatasource->set_sensitive(true);
m_pOk->Enable(); m_xOk->set_sensitive(true);
m_pCancel->Enable(); m_xCancel->set_sensitive(true);
m_pManageDatasources->Enable(); m_xManageDatasources->set_sensitive(true);
} }
#endif #endif
void ODatasourceSelectDialog::fillListBox(const std::set<OUString>& _rDatasources) void ODatasourceSelectDialog::fillListBox(const std::set<OUString>& _rDatasources)
{ {
OUString sSelected; OUString sSelected;
if (m_pDatasource->GetEntryCount()) if (m_xDatasource->n_children())
sSelected = m_pDatasource->GetSelectedEntry(); sSelected = m_xDatasource->get_selected_text();
m_pDatasource->Clear(); m_xDatasource->clear();
// fill the list // fill the list
for (auto const& datasource : _rDatasources) for (auto const& datasource : _rDatasources)
{ {
m_pDatasource->InsertEntry(datasource); m_xDatasource->append_text(datasource);
} }
if (m_pDatasource->GetEntryCount()) if (m_xDatasource->n_children())
{ {
if (!sSelected.isEmpty()) if (!sSelected.isEmpty())
m_pDatasource->SelectEntry(sSelected); m_xDatasource->select_text(sSelected);
else // select the first entry else // select the first entry
m_pDatasource->SelectEntryPos(0); m_xDatasource->select(0);
} }
} }
......
...@@ -24,11 +24,8 @@ ...@@ -24,11 +24,8 @@
#include "odbcconfig.hxx" #include "odbcconfig.hxx"
#include <commontypes.hxx> #include <commontypes.hxx>
#include <vcl/dialog.hxx>
#include <vcl/lstbox.hxx>
#include <vcl/button.hxx>
#include <vcl/fixed.hxx>
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <vcl/weld.hxx>
#include <memory> #include <memory>
...@@ -37,35 +34,33 @@ namespace dbaui ...@@ -37,35 +34,33 @@ namespace dbaui
{ {
// ODatasourceSelector // ODatasourceSelector
class ODatasourceSelectDialog final : public ModalDialog class ODatasourceSelectDialog final : public weld::GenericDialogController
{ {
VclPtr<ListBox> m_pDatasource; std::unique_ptr<weld::TreeView> m_xDatasource;
VclPtr<OKButton> m_pOk; std::unique_ptr<weld::Button> m_xOk;
VclPtr<CancelButton> m_pCancel; std::unique_ptr<weld::Button> m_xCancel;
std::unique_ptr<weld::Button> m_xManageDatasources;
#ifdef HAVE_ODBC_ADMINISTRATION #ifdef HAVE_ODBC_ADMINISTRATION
VclPtr<PushButton> m_pManageDatasources; std::unique_ptr<OOdbcManagement> m_xODBCManagement;
std::unique_ptr< OOdbcManagement >
m_pODBCManagement;
#endif #endif
public: public:
ODatasourceSelectDialog( vcl::Window* _pParent, const std::set<OUString>& _rDatasources ); ODatasourceSelectDialog(weld::Window* pParent, const std::set<OUString>& rDatasources);
virtual ~ODatasourceSelectDialog() override; virtual ~ODatasourceSelectDialog() override;
virtual void dispose() override;
OUString GetSelected() const { OUString GetSelected() const {
return m_pDatasource->GetSelectedEntry(); return m_xDatasource->get_selected_text();
} }
void Select( const OUString& _rEntry ) { void Select( const OUString& _rEntry ) {
m_pDatasource->SelectEntry(_rEntry); m_xDatasource->select_text(_rEntry);
} }
virtual bool Close() override; virtual short run() override;
private: private:
DECL_LINK( ListDblClickHdl, ListBox&, void ); DECL_LINK( ListDblClickHdl, weld::TreeView&, void );
#ifdef HAVE_ODBC_ADMINISTRATION #ifdef HAVE_ODBC_ADMINISTRATION
DECL_LINK(ManageClickHdl, Button*, void); DECL_LINK(ManageClickHdl, weld::Button&, void);
DECL_LINK( ManageProcessFinished, void*, void ); DECL_LINK(ManageProcessFinished, void*, void);
#endif #endif
void fillListBox(const std::set<OUString>& _rDatasources); void fillListBox(const std::set<OUString>& _rDatasources);
}; };
......
...@@ -233,14 +233,33 @@ class ProcessTerminationWait : public ::osl::Thread ...@@ -233,14 +233,33 @@ class ProcessTerminationWait : public ::osl::Thread
{ {
oslProcess m_hProcessHandle; oslProcess m_hProcessHandle;
Link<void*,void> m_aFinishHdl; Link<void*,void> m_aFinishHdl;
ImplSVEvent* m_nEventId;
public: public:
ProcessTerminationWait( oslProcess _hProcessHandle, const Link<void*,void>& _rFinishHdl ) ProcessTerminationWait( oslProcess _hProcessHandle, const Link<void*,void>& _rFinishHdl )
:m_hProcessHandle( _hProcessHandle ) : m_hProcessHandle( _hProcessHandle )
,m_aFinishHdl( _rFinishHdl ) , m_aFinishHdl( _rFinishHdl )
, m_nEventId(nullptr)
{ {
} }
void disableCallback()
{
// if finished event not posted yet, disable by turning it to a no-op Link
m_aFinishHdl = Link<void*, void>();
if (m_nEventId)
{
// already posted, remove it
Application::RemoveUserEvent(m_nEventId);
m_nEventId = nullptr;
}
}
void receivedCallback()
{
m_nEventId = nullptr;
}
protected: protected:
virtual void SAL_CALL run() override virtual void SAL_CALL run() override
{ {
...@@ -248,7 +267,7 @@ protected: ...@@ -248,7 +267,7 @@ protected:
osl_joinProcess( m_hProcessHandle ); osl_joinProcess( m_hProcessHandle );
osl_freeProcessHandle( m_hProcessHandle ); osl_freeProcessHandle( m_hProcessHandle );
Application::PostUserEvent( m_aFinishHdl ); m_nEventId = Application::PostUserEvent( m_aFinishHdl );
} }
}; };
...@@ -285,6 +304,18 @@ bool OOdbcManagement::manageDataSources_async() ...@@ -285,6 +304,18 @@ bool OOdbcManagement::manageDataSources_async()
return true; return true;
} }
void OOdbcManagement::disableCallback()
{
if (m_pProcessWait.get())
m_pProcessWait->disableCallback();
}
void OOdbcManagement::receivedCallback()
{
if (m_pProcessWait.get())
m_pProcessWait->receivedCallback();
}
bool OOdbcManagement::isRunning() const bool OOdbcManagement::isRunning() const
{ {
return ( m_pProcessWait.get() && m_pProcessWait->isRunning() ); return ( m_pProcessWait.get() && m_pProcessWait->isRunning() );
......
...@@ -98,6 +98,8 @@ public: ...@@ -98,6 +98,8 @@ public:
bool manageDataSources_async(); bool manageDataSources_async();
bool isRunning() const; bool isRunning() const;
void disableCallback();
void receivedCallback();
}; };
#endif #endif
......
<?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"/>
<object class="GtkTreeStore" id="liststore2">
<columns>
<!-- column-name text -->
<column type="gchararray"/>
<!-- column-name id -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkDialog" id="ChooseDataSourceDialog"> <object class="GtkDialog" id="ChooseDataSourceDialog">
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="border_width">6</property> <property name="border_width">6</property>
<property name="title" translatable="yes" context="choosedatasourcedialog|ChooseDataSourceDialog">Data Source</property> <property name="title" translatable="yes" context="choosedatasourcedialog|ChooseDataSourceDialog">Data Source</property>
<property name="resizable">False</property> <property name="resizable">False</property>
<property name="modal">True</property>
<property name="default_width">0</property>
<property name="default_height">0</property>
<property name="type_hint">dialog</property> <property name="type_hint">dialog</property>
<child>
<placeholder/>
</child>
<child internal-child="vbox"> <child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1"> <object class="GtkBox" id="dialog-vbox1">
<property name="can_focus">False</property> <property name="can_focus">False</property>
...@@ -96,10 +110,10 @@ ...@@ -96,10 +110,10 @@
<object class="GtkLabel" id="label1"> <object class="GtkLabel" id="label1">
<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">0</property>
<property name="label" translatable="yes" context="choosedatasourcedialog|label1">Choose a data source:</property> <property name="label" translatable="yes" context="choosedatasourcedialog|label1">Choose a data source:</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="mnemonic_widget">treeview:border</property> <property name="mnemonic_widget">treeview</property>
<property name="xalign">0</property>
</object> </object>
<packing> <packing>
<property name="left_attach">0</property> <property name="left_attach">0</property>
...@@ -107,14 +121,39 @@ ...@@ -107,14 +121,39 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkTreeView" id="treeview:border"> <object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="treeview">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="vexpand">True</property> <property name="vexpand">True</property>
<property name="model">liststore2</property>
<property name="headers_visible">False</property>
<property name="search_column">1</property>
<property name="show_expanders">False</property> <property name="show_expanders">False</property>
<child internal-child="selection"> <child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection1"/> <object class="GtkTreeSelection" id="Macro Library List-selection2"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn5">
<property name="resizable">True</property>
<property name="spacing">6</property>
<child>
<object class="GtkCellRendererText" id="cellrenderer4"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child> </child>
</object> </object>
<packing> <packing>
...@@ -135,6 +174,7 @@ ...@@ -135,6 +174,7 @@
<action-widget response="-5">ok</action-widget> <action-widget response="-5">ok</action-widget>
<action-widget response="-6">cancel</action-widget> <action-widget response="-6">cancel</action-widget>
<action-widget response="-11">help</action-widget> <action-widget response="-11">help</action-widget>
<action-widget response="101">organize</action-widget>
</action-widgets> </action-widgets>
</object> </object>
</interface> </interface>
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