diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-02-05 15:35:35 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-02-05 22:43:05 +0100 |
commit | 29a66fe8cde3e18bf4d1c3d7a1f2077ea54548be (patch) | |
tree | efa032d617b6771bac09a5d5867634a0e605ab6e /cui | |
parent | 2877657777926dbc66f4844cc94e37e74fd546cd (diff) |
weld WebConnectionInfoDialog
Change-Id: Idff8a0589075c8b7c774f187f5082fd954251d77
Reviewed-on: https://gerrit.libreoffice.org/67420
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'cui')
-rw-r--r-- | cui/source/options/optinet2.cxx | 4 | ||||
-rw-r--r-- | cui/source/options/webconninfo.cxx | 189 | ||||
-rw-r--r-- | cui/source/options/webconninfo.hxx | 44 | ||||
-rw-r--r-- | cui/uiconfig/ui/storedwebconnectiondialog.ui | 100 |
4 files changed, 129 insertions, 208 deletions
diff --git a/cui/source/options/optinet2.cxx b/cui/source/options/optinet2.cxx index c269d87fdda5..bee5e2d64d14 100644 --- a/cui/source/options/optinet2.cxx +++ b/cui/source/options/optinet2.cxx @@ -784,8 +784,8 @@ IMPL_LINK_NOARG(SvxSecurityTabPage, ShowPasswordsHdl, Button*, void) if ( xMasterPasswd->isPersistentStoringAllowed() && xMasterPasswd->authorizateWithMasterPassword(xTmpHandler) ) { - ScopedVclPtrInstance< svx::WebConnectionInfoDialog > aDlg(this); - aDlg->Execute(); + svx::WebConnectionInfoDialog aDlg(GetDialogFrameWeld()); + aDlg.run(); } } catch (const Exception&) diff --git a/cui/source/options/webconninfo.cxx b/cui/source/options/webconninfo.cxx index 18a2cd7fbca9..5bb56294cfc3 100644 --- a/cui/source/options/webconninfo.cxx +++ b/cui/source/options/webconninfo.cxx @@ -35,125 +35,49 @@ using namespace ::com::sun::star; namespace svx { - -// class PasswordTable --------------------------------------------------- - -PasswordTable::PasswordTable(SvSimpleTableContainer& rParent, WinBits nBits) - : SvSimpleTable(rParent, nBits | WB_NOINITIALSELECTION) -{ -} - -void PasswordTable::InsertHeaderItem(sal_uInt16 nColumn, const OUString& rText, HeaderBarItemBits nBits) -{ - GetTheHeaderBar().InsertItem( nColumn, rText, 0, nBits ); -} - -void PasswordTable::Resort( bool bForced ) -{ - sal_uInt16 nColumn = GetSelectedCol(); - if ( 0 == nColumn || bForced ) // only the first column is sorted - { - HeaderBarItemBits nBits = GetTheHeaderBar().GetItemBits(1); - bool bUp = ( ( nBits & HeaderBarItemBits::UPARROW ) == HeaderBarItemBits::UPARROW ); - SvSortMode eMode = SortAscending; - - if ( bUp ) - { - nBits &= ~HeaderBarItemBits::UPARROW; - nBits |= HeaderBarItemBits::DOWNARROW; - eMode = SortDescending; - } - else - { - nBits &= ~HeaderBarItemBits::DOWNARROW; - nBits |= HeaderBarItemBits::UPARROW; - } - GetTheHeaderBar().SetItemBits( 1, nBits ); - SvTreeList* pListModel = GetModel(); - pListModel->SetSortMode( eMode ); - pListModel->Resort(); - } -} - -void PasswordTable::Resize() -{ - SvSimpleTable::Resize(); - if (isInitialLayout(this)) - setColWidths(); -} - -void PasswordTable::setColWidths() -{ - HeaderBar &rBar = GetTheHeaderBar(); - if (rBar.GetItemCount() < 2) - return; - long nUserNameWidth = 12 + - std::max(rBar.GetTextWidth(rBar.GetItemText(2)), - GetTextWidth("XXXXXXXXXXXX")); - long nWebSiteWidth = std::max( - 12 + rBar.GetTextWidth(rBar.GetItemText(1)), - GetSizePixel().Width() - nUserNameWidth); - long aStaticTabs[]= { 0, nWebSiteWidth }; - SvSimpleTable::SetTabs(SAL_N_ELEMENTS(aStaticTabs), aStaticTabs, MapUnit::MapPixel); -} - // class WebConnectionInfoDialog ----------------------------------------- - -WebConnectionInfoDialog::WebConnectionInfoDialog(vcl::Window* pParent) - : ModalDialog(pParent, "StoredWebConnectionDialog", "cui/ui/storedwebconnectiondialog.ui") +WebConnectionInfoDialog::WebConnectionInfoDialog(weld::Window* pParent) + : GenericDialogController(pParent, "cui/ui/storedwebconnectiondialog.ui", "StoredWebConnectionDialog") , m_nPos( -1 ) + , m_xRemoveBtn(m_xBuilder->weld_button("remove")) + , m_xRemoveAllBtn(m_xBuilder->weld_button("removeall")) + , m_xChangeBtn(m_xBuilder->weld_button("change")) + , m_xPasswordsLB(m_xBuilder->weld_tree_view("logins")) { - get(m_pRemoveBtn, "remove"); - get(m_pRemoveAllBtn, "removeall"); - get(m_pChangeBtn, "change"); - - SvSimpleTableContainer *pPasswordsLBContainer = get<SvSimpleTableContainer>("logins"); - m_pPasswordsLB = VclPtr<PasswordTable>::Create(*pPasswordsLBContainer, 0); - - long const aStaticTabs[]= { 0, 0 }; - m_pPasswordsLB->SetTabs( SAL_N_ELEMENTS(aStaticTabs), aStaticTabs ); - m_pPasswordsLB->InsertHeaderItem( 1, get<FixedText>("website")->GetText(), - HeaderBarItemBits::LEFT | HeaderBarItemBits::FIXEDPOS | HeaderBarItemBits::CLICKABLE | HeaderBarItemBits::UPARROW ); - m_pPasswordsLB->InsertHeaderItem( 2, get<FixedText>("username")->GetText(), - HeaderBarItemBits::LEFT | HeaderBarItemBits::FIXEDPOS ); - pPasswordsLBContainer->set_height_request(m_pPasswordsLB->GetTextHeight()*8); + std::vector<int> aWidths; + aWidths.push_back(m_xPasswordsLB->get_approximate_digit_width() * 50); + m_xPasswordsLB->set_column_fixed_widths(aWidths); + m_xPasswordsLB->set_size_request(m_xPasswordsLB->get_approximate_digit_width() * 70, + m_xPasswordsLB->get_height_rows(8)); - m_pPasswordsLB->SetHeaderBarClickHdl( LINK( this, WebConnectionInfoDialog, HeaderBarClickedHdl ) ); + m_xPasswordsLB->connect_column_clicked(LINK(this, WebConnectionInfoDialog, HeaderBarClickedHdl)); FillPasswordList(); - m_pRemoveBtn->SetClickHdl( LINK( this, WebConnectionInfoDialog, RemovePasswordHdl ) ); - m_pRemoveAllBtn->SetClickHdl( LINK( this, WebConnectionInfoDialog, RemoveAllPasswordsHdl ) ); - m_pChangeBtn->SetClickHdl( LINK( this, WebConnectionInfoDialog, ChangePasswordHdl ) ); - m_pPasswordsLB->SetSelectHdl( LINK( this, WebConnectionInfoDialog, EntrySelectedHdl ) ); + m_xRemoveBtn->connect_clicked( LINK( this, WebConnectionInfoDialog, RemovePasswordHdl ) ); + m_xRemoveAllBtn->connect_clicked( LINK( this, WebConnectionInfoDialog, RemoveAllPasswordsHdl ) ); + m_xChangeBtn->connect_clicked( LINK( this, WebConnectionInfoDialog, ChangePasswordHdl ) ); + m_xPasswordsLB->connect_changed( LINK( this, WebConnectionInfoDialog, EntrySelectedHdl ) ); - m_pRemoveBtn->Enable( false ); - m_pChangeBtn->Enable( false ); + m_xRemoveBtn->set_sensitive( false ); + m_xChangeBtn->set_sensitive( false ); - HeaderBarClickedHdl( nullptr ); + m_xPasswordsLB->make_sorted(); } WebConnectionInfoDialog::~WebConnectionInfoDialog() { - disposeOnce(); } -void WebConnectionInfoDialog::dispose() +IMPL_LINK(WebConnectionInfoDialog, HeaderBarClickedHdl, int, nColumn, void) { - m_pPasswordsLB.disposeAndClear(); - m_pRemoveBtn.clear(); - m_pRemoveAllBtn.clear(); - m_pChangeBtn.clear(); - ModalDialog::dispose(); -} - -IMPL_LINK( WebConnectionInfoDialog, HeaderBarClickedHdl, SvSimpleTable*, pTable, void ) -{ - m_pPasswordsLB->Resort( nullptr == pTable ); + if (nColumn == 0) // only the first column is sorted + { + m_xPasswordsLB->set_sort_order(!m_xPasswordsLB->get_sort_order()); + } } - void WebConnectionInfoDialog::FillPasswordList() { try @@ -173,10 +97,9 @@ void WebConnectionInfoDialog::FillPasswordList() { for ( sal_Int32 nUserInd = 0; nUserInd < aURLEntries[nURLInd].UserList.getLength(); nUserInd++ ) { - SvTreeListEntry* pEntry = m_pPasswordsLB->InsertEntry( - aURLEntries[nURLInd].Url + "\t" + - aURLEntries[nURLInd].UserList[nUserInd].UserName); - pEntry->SetUserData( reinterpret_cast<void*>(nCount++) ); + m_xPasswordsLB->append(OUString::number(nCount), aURLEntries[nURLInd].Url); + m_xPasswordsLB->set_text(nCount, aURLEntries[nURLInd].UserList[nUserInd].UserName, 1); + ++nCount; } } @@ -188,9 +111,9 @@ void WebConnectionInfoDialog::FillPasswordList() for ( sal_Int32 nURLIdx = 0; nURLIdx < aUrls.getLength(); nURLIdx++ ) { - SvTreeListEntry* pEntry = m_pPasswordsLB->InsertEntry( - aUrls[nURLIdx] + "\t*"); - pEntry->SetUserData( reinterpret_cast<void*>(nCount++) ); + m_xPasswordsLB->append(OUString::number(nCount), aUrls[nURLIdx]); + m_xPasswordsLB->set_text(nCount, "*"); + ++nCount; } } } @@ -199,20 +122,20 @@ void WebConnectionInfoDialog::FillPasswordList() } -IMPL_LINK_NOARG(WebConnectionInfoDialog, RemovePasswordHdl, Button*, void) +IMPL_LINK_NOARG(WebConnectionInfoDialog, RemovePasswordHdl, weld::Button&, void) { try { - SvTreeListEntry* pEntry = m_pPasswordsLB->GetCurEntry(); - if ( pEntry ) + int nEntry = m_xPasswordsLB->get_selected_index(); + if (nEntry != -1) { - OUString aURL = SvTabListBox::GetEntryText( pEntry, 0 ); - OUString aUserName = SvTabListBox::GetEntryText( pEntry, 1 ); + OUString aURL = m_xPasswordsLB->get_text(nEntry, 0); + OUString aUserName = m_xPasswordsLB->get_text(nEntry, 1); uno::Reference< task::XPasswordContainer2 > xPasswdContainer( task::PasswordContainer::create(comphelper::getProcessComponentContext())); - sal_Int32 nPos = static_cast<sal_Int32>(reinterpret_cast<sal_IntPtr>(pEntry->GetUserData())); + int nPos = m_xPasswordsLB->get_id(nEntry).toInt32(); if ( nPos < m_nPos ) { xPasswdContainer->removePersistent( aURL, aUserName ); @@ -221,15 +144,15 @@ IMPL_LINK_NOARG(WebConnectionInfoDialog, RemovePasswordHdl, Button*, void) { xPasswdContainer->removeUrl( aURL ); } - m_pPasswordsLB->RemoveEntry( pEntry ); + + m_xPasswordsLB->remove(nEntry); } } catch( uno::Exception& ) {} } - -IMPL_LINK_NOARG(WebConnectionInfoDialog, RemoveAllPasswordsHdl, Button*, void) +IMPL_LINK_NOARG(WebConnectionInfoDialog, RemoveAllPasswordsHdl, weld::Button&, void) { try { @@ -244,30 +167,28 @@ IMPL_LINK_NOARG(WebConnectionInfoDialog, RemoveAllPasswordsHdl, Button*, void) for ( sal_Int32 nURLIdx = 0; nURLIdx < aUrls.getLength(); nURLIdx++ ) xPasswdContainer->removeUrl( aUrls[ nURLIdx ] ); - m_pPasswordsLB->Clear(); + m_xPasswordsLB->clear(); } catch( uno::Exception& ) {} } - -IMPL_LINK_NOARG(WebConnectionInfoDialog, ChangePasswordHdl, Button*, void) +IMPL_LINK_NOARG(WebConnectionInfoDialog, ChangePasswordHdl, weld::Button&, void) { try { - SvTreeListEntry* pEntry = m_pPasswordsLB->GetCurEntry(); - if ( pEntry ) + int nEntry = m_xPasswordsLB->get_selected_index(); + if (nEntry != -1) { - OUString aURL = SvTabListBox::GetEntryText( pEntry, 0 ); - OUString aUserName = SvTabListBox::GetEntryText( pEntry, 1 ); + OUString aURL = m_xPasswordsLB->get_text(nEntry, 0); + OUString aUserName = m_xPasswordsLB->get_text(nEntry, 1); ::comphelper::SimplePasswordRequest* pPasswordRequest = new ::comphelper::SimplePasswordRequest; uno::Reference< task::XInteractionRequest > rRequest( pPasswordRequest ); - auto xWindow = VCLUnoHelper::GetInterface(this); uno::Reference< task::XInteractionHandler > xInteractionHandler( - task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(), xWindow), + task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(), m_xDialog->GetXWindow()), uno::UNO_QUERY ); xInteractionHandler->handle( rRequest ); @@ -288,27 +209,25 @@ IMPL_LINK_NOARG(WebConnectionInfoDialog, ChangePasswordHdl, Button*, void) } -IMPL_LINK_NOARG(WebConnectionInfoDialog, EntrySelectedHdl, SvTreeListBox*, void) +IMPL_LINK_NOARG(WebConnectionInfoDialog, EntrySelectedHdl, weld::TreeView&, void) { - SvTreeListEntry* pEntry = m_pPasswordsLB->GetCurEntry(); - if ( !pEntry ) + int nEntry = m_xPasswordsLB->get_selected_index(); + if (nEntry == -1) { - m_pRemoveBtn->Enable( false ); - m_pChangeBtn->Enable( false ); + m_xRemoveBtn->set_sensitive(false); + m_xChangeBtn->set_sensitive(false); } else { - m_pRemoveBtn->Enable(); + m_xRemoveBtn->set_sensitive(true); // url container entries (-> use system credentials) have // no password - sal_Int32 nPos = static_cast<sal_Int32>(reinterpret_cast<sal_IntPtr>(pEntry->GetUserData())); - m_pChangeBtn->Enable( nPos < m_nPos ); + int nPos = m_xPasswordsLB->get_id(nEntry).toInt32(); + m_xChangeBtn->set_sensitive(nPos < m_nPos); } } - } - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cui/source/options/webconninfo.hxx b/cui/source/options/webconninfo.hxx index 792d66cb2a1c..95d524c8a3bc 100644 --- a/cui/source/options/webconninfo.hxx +++ b/cui/source/options/webconninfo.hxx @@ -18,47 +18,31 @@ #ifndef INCLUDED_CUI_SOURCE_OPTIONS_WEBCONNINFO_HXX #define INCLUDED_CUI_SOURCE_OPTIONS_WEBCONNINFO_HXX -#include <vcl/button.hxx> -#include <vcl/dialog.hxx> -#include <vcl/fixed.hxx> -#include <svtools/simptabl.hxx> +#include <vcl/weld.hxx> namespace svx { - - - class PasswordTable : public SvSimpleTable - { - public: - PasswordTable(SvSimpleTableContainer& rParent, WinBits nBits); - - void InsertHeaderItem(sal_uInt16 nColumn, const OUString& rText, HeaderBarItemBits nBits); - void setColWidths(); - void Resort( bool bForced ); - virtual void Resize() override; - }; - - class WebConnectionInfoDialog : public ModalDialog + class WebConnectionInfoDialog : public weld::GenericDialogController { private: - VclPtr<PasswordTable> m_pPasswordsLB; - VclPtr<PushButton> m_pRemoveBtn; - VclPtr<PushButton> m_pRemoveAllBtn; - VclPtr<PushButton> m_pChangeBtn; - sal_Int32 m_nPos; + sal_Int32 m_nPos; + + std::unique_ptr<weld::Button> m_xRemoveBtn; + std::unique_ptr<weld::Button> m_xRemoveAllBtn; + std::unique_ptr<weld::Button> m_xChangeBtn; + std::unique_ptr<weld::TreeView> m_xPasswordsLB; - DECL_LINK( HeaderBarClickedHdl, SvSimpleTable*, void ); - DECL_LINK( RemovePasswordHdl, Button*, void ); - DECL_LINK( RemoveAllPasswordsHdl, Button*, void ); - DECL_LINK( ChangePasswordHdl, Button*, void ); - DECL_LINK( EntrySelectedHdl, SvTreeListBox*, void ); + DECL_LINK( HeaderBarClickedHdl, int, void ); + DECL_LINK( RemovePasswordHdl, weld::Button&, void ); + DECL_LINK( RemoveAllPasswordsHdl, weld::Button&, void ); + DECL_LINK( ChangePasswordHdl, weld::Button&, void ); + DECL_LINK( EntrySelectedHdl, weld::TreeView&, void ); void FillPasswordList(); public: - explicit WebConnectionInfoDialog( vcl::Window* pParent ); + explicit WebConnectionInfoDialog(weld::Window* pParent); virtual ~WebConnectionInfoDialog() override; - virtual void dispose() override; }; diff --git a/cui/uiconfig/ui/storedwebconnectiondialog.ui b/cui/uiconfig/ui/storedwebconnectiondialog.ui index 685df0e160a4..69f2c30b9b79 100644 --- a/cui/uiconfig/ui/storedwebconnectiondialog.ui +++ b/cui/uiconfig/ui/storedwebconnectiondialog.ui @@ -1,14 +1,26 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- Generated with glade 3.18.3 --> +<!-- Generated with glade 3.22.1 --> <interface domain="cui"> <requires lib="gtk+" version="3.18"/> - <requires lib="LibreOffice" version="1.0"/> + <object class="GtkTreeStore" id="liststore1"> + <columns> + <!-- column-name text --> + <column type="gchararray"/> + <!-- column-name text2 --> + <column type="gchararray"/> + <!-- column-name id --> + <column type="gchararray"/> + </columns> + </object> <object class="GtkDialog" id="StoredWebConnectionDialog"> <property name="can_focus">False</property> <property name="border_width">6</property> <property name="title" translatable="yes" context="storedwebconnectiondialog|StoredWebConnectionDialog">Stored Web Connection Information</property> <property name="resizable">False</property> <property name="type_hint">dialog</property> + <child> + <placeholder/> + </child> <child internal-child="vbox"> <object class="GtkBox" id="dialog-vbox1"> <property name="can_focus">False</property> @@ -66,8 +78,8 @@ <object class="GtkLabel" id="label1"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="xalign">0</property> <property name="label" translatable="yes" context="storedwebconnectiondialog|label1">Web login information (passwords are never shown)</property> + <property name="xalign">0</property> </object> <packing> <property name="left_attach">0</property> @@ -75,32 +87,53 @@ </packing> </child> <child> - <object class="GtkGrid" id="grid3"> - <property name="can_focus">False</property> - <property name="no_show_all">True</property> + <object class="GtkScrolledWindow"> + <property name="visible">True</property> + <property name="can_focus">True</property> <property name="hexpand">True</property> - <property name="column_spacing">12</property> + <property name="vexpand">True</property> + <property name="shadow_type">in</property> <child> - <object class="GtkLabel" id="website"> + <object class="GtkTreeView" id="logins"> <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes" context="storedwebconnectiondialog|website">Website</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="vexpand">True</property> + <property name="model">liststore1</property> + <property name="search_column">0</property> + <property name="show_expanders">False</property> + <child internal-child="selection"> + <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> + <property name="title" translatable="yes" context="storedwebconnectiondialog|website">Website</property> + <property name="clickable">True</property> + <property name="sort_indicator">True</property> + <child> + <object class="GtkCellRendererText" id="cellrenderer4"/> + <attributes> + <attribute name="text">0</attribute> + </attributes> + </child> + </object> + </child> + <child> + <object class="GtkTreeViewColumn" id="treeviewcolumn1"> + <property name="resizable">True</property> + <property name="spacing">6</property> + <property name="title" translatable="yes" context="storedwebconnectiondialog|username">User name</property> + <child> + <object class="GtkCellRendererText" id="cellrenderer1"/> + <attributes> + <attribute name="text">1</attribute> + </attributes> + </child> + </object> + </child> </object> - <packing> - <property name="left_attach">0</property> - <property name="top_attach">0</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="username"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes" context="storedwebconnectiondialog|username">User name</property> - </object> - <packing> - <property name="left_attach">1</property> - <property name="top_attach">0</property> - </packing> </child> </object> <packing> @@ -109,21 +142,6 @@ </packing> </child> <child> - <object class="svtlo-SvSimpleTableContainer" id="logins"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="hexpand">True</property> - <property name="vexpand">True</property> - <child internal-child="selection"> - <object class="GtkTreeSelection" id="Simple Table Container-selection1"/> - </child> - </object> - <packing> - <property name="left_attach">0</property> - <property name="top_attach">2</property> - </packing> - </child> - <child> <object class="GtkButtonBox" id="buttonbox1"> <property name="visible">True</property> <property name="can_focus">False</property> @@ -175,7 +193,7 @@ </object> <packing> <property name="left_attach">0</property> - <property name="top_attach">3</property> + <property name="top_attach">2</property> </packing> </child> </object> |