Impress Remote: allow removal of authorised remotes.
Previously authorising a device meant that it would have access forever -- we now list previously authorised remotes in the remote dialog, along with controls to allow removal of such remotes. Change-Id: I4179739f3a2ba0a8fe19c2a0cd0cbbece9cb4352
This commit is contained in:
parent
f82c524f76
commit
6216eee4b9
7 changed files with 158 additions and 27 deletions
|
@ -148,7 +148,7 @@
|
|||
#define STR_SLIDE_TRANSITION_PANE RID_GLOB_START+228
|
||||
|
||||
#define RID_SLIDESORTER_ICONS RID_GLOB_START+227
|
||||
|
||||
#define STR_DEAUTHORISE_CLIENT RID_GLOB_START+229
|
||||
#endif // _SDGLOB_HRC
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
|
|
@ -453,4 +453,9 @@ String STR_ENTER_PIN
|
|||
Text [ en-US ] = "Enter PIN:";
|
||||
};
|
||||
|
||||
String STR_DEAUTHORISE_CLIENT
|
||||
{
|
||||
Text [ en-US ] = "Remove client authorisation";
|
||||
};
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
|
|
@ -25,20 +25,6 @@ RemoteDialog::RemoteDialog( Window *pWindow )
|
|||
get(m_pButtonClose, "close");
|
||||
get(m_pClientBox, "tree");
|
||||
|
||||
#ifdef ENABLE_SDREMOTE
|
||||
RemoteServer::ensureDiscoverable();
|
||||
|
||||
vector<::boost::shared_ptr<ClientInfo>> aClients( RemoteServer::getClients() );
|
||||
|
||||
const vector<::boost::shared_ptr<ClientInfo>>::const_iterator aEnd( aClients.end() );
|
||||
|
||||
for ( vector<::boost::shared_ptr<ClientInfo>>::const_iterator aIt( aClients.begin() );
|
||||
aIt != aEnd; ++aIt )
|
||||
{
|
||||
m_pClientBox->addEntry( *aIt );
|
||||
}
|
||||
#endif
|
||||
|
||||
m_pButtonConnect->SetClickHdl( LINK( this, RemoteDialog, HandleConnectButton ) );
|
||||
SetCloseHdl( LINK( this, RemoteDialog, CloseHdl ) );
|
||||
m_pButtonClose->SetClickHdl( LINK( this, RemoteDialog, CloseHdl ) );
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "svtools/controldims.hrc"
|
||||
|
||||
#include "RemoteDialogClientBox.hxx"
|
||||
|
@ -30,6 +32,8 @@
|
|||
|
||||
#include "glob.hrc"
|
||||
|
||||
using namespace std;
|
||||
|
||||
using namespace ::com::sun::star;
|
||||
|
||||
namespace sd {
|
||||
|
@ -72,12 +76,15 @@ ClientBox::ClientBox( Window* pParent, WinBits nStyle ) :
|
|||
m_nActiveHeight( 0 ),
|
||||
m_nExtraHeight( 2 ),
|
||||
m_aPinBox( this, 0 ),
|
||||
m_aDeauthoriseButton( this ),
|
||||
m_aScrollBar( this, WB_VERT )
|
||||
{
|
||||
m_aScrollBar.SetScrollHdl( LINK( this, ClientBox, ScrollHdl ) );
|
||||
m_aScrollBar.EnableDrag();
|
||||
|
||||
m_aPinBox.SetUseThousandSep(false);
|
||||
m_aDeauthoriseButton.SetText( SD_RESSTR(STR_DEAUTHORISE_CLIENT) );
|
||||
m_aDeauthoriseButton.SetClickHdl( LINK( this, ClientBox, DeauthoriseHdl ) );
|
||||
|
||||
SetPaintTransparent( true );
|
||||
SetPosPixel( Point( RSC_SP_DLG_INNERBORDER_LEFT, RSC_SP_DLG_INNERBORDER_TOP ) );
|
||||
|
@ -103,6 +110,8 @@ ClientBox::ClientBox( Window* pParent, WinBits nStyle ) :
|
|||
|
||||
m_xRemoveListener = new ClientRemovedListener( this );
|
||||
|
||||
populateEntries();
|
||||
|
||||
Show();
|
||||
}
|
||||
|
||||
|
@ -332,18 +341,30 @@ void ClientBox::DrawRow( const Rectangle& rRect, const TClientBoxEntry pEntry )
|
|||
Size aSize = LogicToPixel( Size( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ),
|
||||
MapMode( MAP_APPFONT ) );
|
||||
m_aPinBox.SetSizePixel( aSize );
|
||||
m_aDeauthoriseButton.SetSizePixel( m_aDeauthoriseButton.GetOptimalSize() );
|
||||
const Rectangle aRect( GetEntryRect( m_nActive ) );
|
||||
Size aBtnSize( m_aPinBox.GetSizePixel() );
|
||||
Point aBtnPos( aRect.Left(),
|
||||
aRect.Bottom() - TOP_OFFSET - aBtnSize.Height() );
|
||||
OUString sPinText(SD_RESSTR(STR_ENTER_PIN));
|
||||
DrawText( Rectangle( aBtnPos.X(), aBtnPos.Y(), rRect.Right(), rRect.Bottom() - TOP_OFFSET),
|
||||
sPinText, 0 );
|
||||
|
||||
aBtnPos = Point( aRect.Left() + GetTextWidth( sPinText ),
|
||||
aRect.Bottom() - TOP_OFFSET - aBtnSize.Height() );
|
||||
bool bAlreadyAuthorised = pEntry->m_pClientInfo->mbIsAlreadyAuthorised;
|
||||
|
||||
if ( !bAlreadyAuthorised )
|
||||
{
|
||||
OUString sPinText(SD_RESSTR(STR_ENTER_PIN));
|
||||
DrawText( Rectangle( aBtnPos.X(), aBtnPos.Y(), rRect.Right(), rRect.Bottom() - TOP_OFFSET),
|
||||
sPinText, 0 );
|
||||
|
||||
aBtnPos = Point( aRect.Left() + GetTextWidth( sPinText ),
|
||||
aRect.Bottom() - TOP_OFFSET - aBtnSize.Height() );
|
||||
|
||||
}
|
||||
m_aPinBox.SetPosPixel( aBtnPos );
|
||||
m_aPinBox.Show( !bAlreadyAuthorised );
|
||||
|
||||
aBtnPos.Move( 20, 0 );
|
||||
m_aDeauthoriseButton.SetPosPixel( aBtnPos );
|
||||
m_aDeauthoriseButton.Show( bAlreadyAuthorised );
|
||||
|
||||
// long nExtraHeight = 0;
|
||||
|
||||
|
@ -476,6 +497,15 @@ void ClientBox::Paint( const Rectangle &/*rPaintRect*/ )
|
|||
|
||||
const ::osl::MutexGuard aGuard( m_entriesMutex );
|
||||
|
||||
// If we have just removed the last entry (via deauthorise)
|
||||
// then we need to make sure we hide the button (usually
|
||||
// this would all be dealt with in in DrawRow, but that
|
||||
// won't be called for 0 items).
|
||||
if ( m_vEntries.size() == 0 )
|
||||
{
|
||||
m_aDeauthoriseButton.Show( false );
|
||||
}
|
||||
|
||||
typedef std::vector< TClientBoxEntry >::iterator ITER;
|
||||
for ( ITER iIndex = m_vEntries.begin(); iIndex < m_vEntries.end(); ++iIndex )
|
||||
{
|
||||
|
@ -671,6 +701,44 @@ long ClientBox::addEntry( ::boost::shared_ptr<ClientInfo> pClientInfo )
|
|||
return nPos;
|
||||
}
|
||||
|
||||
void ClientBox::clearEntries()
|
||||
{
|
||||
selectEntry( -1 );
|
||||
m_bHasActive = false;
|
||||
|
||||
const ::osl::MutexGuard aGuard( m_entriesMutex );
|
||||
|
||||
m_vEntries.clear();
|
||||
if ( IsReallyVisible() )
|
||||
Invalidate();
|
||||
m_bNeedsRecalc = true;
|
||||
}
|
||||
|
||||
void ClientBox::populateEntries()
|
||||
{
|
||||
const ::osl::MutexGuard aGuard( m_entriesMutex );
|
||||
|
||||
clearEntries();
|
||||
|
||||
#ifdef ENABLE_SDREMOTE
|
||||
RemoteServer::ensureDiscoverable();
|
||||
|
||||
vector<::boost::shared_ptr<ClientInfo>> aClients( RemoteServer::getClients() );
|
||||
|
||||
const vector<::boost::shared_ptr<ClientInfo>>::const_iterator aEnd( aClients.end() );
|
||||
|
||||
for ( vector<::boost::shared_ptr<ClientInfo>>::const_iterator aIt( aClients.begin() );
|
||||
aIt != aEnd; ++aIt )
|
||||
{
|
||||
addEntry( *aIt );
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( IsReallyVisible() )
|
||||
Invalidate();
|
||||
m_bNeedsRecalc = true;
|
||||
}
|
||||
|
||||
void ClientBox::DoScroll( long nDelta )
|
||||
{
|
||||
m_nTopIndex += nDelta;
|
||||
|
@ -690,6 +758,20 @@ IMPL_LINK( ClientBox, ScrollHdl, ScrollBar*, pScrBar )
|
|||
return 1;
|
||||
}
|
||||
|
||||
IMPL_LINK_NOARG( ClientBox, DeauthoriseHdl )
|
||||
{
|
||||
long aSelected = GetActiveEntryIndex();
|
||||
if ( aSelected < 0 )
|
||||
return 1;
|
||||
TClientBoxEntry aEntry = GetEntryData(aSelected);
|
||||
|
||||
#ifdef ENABLE_SDREMOTE
|
||||
RemoteServer::deauthoriseClient( aEntry->m_pClientInfo );
|
||||
#endif
|
||||
populateEntries();
|
||||
return 1;
|
||||
}
|
||||
|
||||
} //namespace dp_gui
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "rtl/ustring.hxx"
|
||||
#include "vcl/scrbar.hxx"
|
||||
#include "vcl/fixed.hxx"
|
||||
#include "vcl/button.hxx"
|
||||
#include "vcl/dialog.hxx"
|
||||
#include "vcl/field.hxx"
|
||||
|
||||
|
@ -98,8 +99,10 @@ class ClientBox:
|
|||
long m_nExtraHeight;
|
||||
Size m_aOutputSize;
|
||||
Link m_aClickHdl;
|
||||
Link m_aDeauthoriseHdl;
|
||||
|
||||
NumericBox m_aPinBox;
|
||||
PushButton m_aDeauthoriseButton;
|
||||
|
||||
ScrollBar m_aScrollBar;
|
||||
|
||||
|
@ -125,7 +128,7 @@ class ClientBox:
|
|||
void DeleteRemoved();
|
||||
|
||||
DECL_DLLPRIVATE_LINK( ScrollHdl, ScrollBar* );
|
||||
|
||||
DECL_DLLPRIVATE_LINK( DeauthoriseHdl, void * );
|
||||
//Index starts with 1.
|
||||
//Throws an com::sun::star::lang::IllegalArgumentException, when the index is invalid.
|
||||
void checkIndex(sal_Int32 pos) const;
|
||||
|
@ -158,11 +161,13 @@ public:
|
|||
long addEntry( ::boost::shared_ptr<ClientInfo> pClientInfo );
|
||||
void updateEntry( const ::boost::shared_ptr<ClientInfo> pPackageInfo );
|
||||
void removeEntry( const ::boost::shared_ptr<ClientInfo> pPackageInfo );
|
||||
void clearEntries();
|
||||
|
||||
void prepareChecking();
|
||||
void checkEntries();
|
||||
|
||||
OUString getPin();
|
||||
void populateEntries();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -46,10 +46,15 @@ namespace sd
|
|||
OUString mName;
|
||||
OUString mAddress;
|
||||
|
||||
bool mbIsAlreadyAuthorised;
|
||||
|
||||
enum PROTOCOL { NETWORK = 1, BLUETOOTH };
|
||||
ClientInfo( const OUString& rName, const OUString& rAddress ) :
|
||||
ClientInfo( const OUString& rName,
|
||||
const OUString& rAddress,
|
||||
const bool bIsAlreadyAuthorised ) :
|
||||
mName( rName ),
|
||||
mAddress( rAddress ) {}
|
||||
mAddress( rAddress ),
|
||||
mbIsAlreadyAuthorised( bIsAlreadyAuthorised ) {}
|
||||
|
||||
virtual ~ClientInfo() {};
|
||||
};
|
||||
|
@ -71,6 +76,7 @@ namespace sd
|
|||
SD_DLLPUBLIC static std::vector< ::boost::shared_ptr< ClientInfo > > getClients();
|
||||
SD_DLLPUBLIC static bool connectClient( ::boost::shared_ptr< ClientInfo > pClient,
|
||||
const OUString& aPin );
|
||||
SD_DLLPUBLIC static void deauthoriseClient( ::boost::shared_ptr< ClientInfo > pClient );
|
||||
|
||||
/// ensure that discoverability (eg. for Bluetooth) is enabled
|
||||
SD_DLLPUBLIC static void ensureDiscoverable();
|
||||
|
|
|
@ -54,9 +54,10 @@ namespace sd {
|
|||
|
||||
ClientInfoInternal( const OUString& rName,
|
||||
const OUString& rAddress,
|
||||
const bool bIsAlreadyAuthorised,
|
||||
BufferedStreamSocket *pSocket,
|
||||
const OUString& rPin ):
|
||||
ClientInfo( rName, rAddress ),
|
||||
ClientInfo( rName, rAddress, bIsAlreadyAuthorised ),
|
||||
mpStreamSocket( pSocket ),
|
||||
mPin( rPin ) {}
|
||||
};
|
||||
|
@ -127,8 +128,8 @@ void RemoteServer::execute()
|
|||
::boost::shared_ptr< ClientInfoInternal > pClient(
|
||||
new ClientInfoInternal(
|
||||
OStringToOUString( aName, RTL_TEXTENCODING_UTF8 ),
|
||||
aAddress, pSocket, OStringToOUString( aPin,
|
||||
RTL_TEXTENCODING_UTF8 ) );
|
||||
aAddress, false, pSocket, OStringToOUString( aPin,
|
||||
RTL_TEXTENCODING_UTF8 ) ) );
|
||||
mAvailableClients.push_back( pClient );
|
||||
|
||||
// Read off any additional non-empty lines
|
||||
|
@ -247,6 +248,23 @@ std::vector< ::boost::shared_ptr< ClientInfo > > RemoteServer::getClients()
|
|||
MutexGuard aGuard( sDataMutex );
|
||||
aClients.assign( spServer->mAvailableClients.begin(),
|
||||
spServer->mAvailableClients.end() );
|
||||
|
||||
// We also need to provide authorised clients (no matter whether or not
|
||||
// they are actually available), so that they can be de-authorised if
|
||||
// necessary. We specifically want these to be at the end of the list
|
||||
// since the user is more likely to be trying to connect a new remote
|
||||
// than removing an existing remote.
|
||||
// We can also be sure that pre-authorised clients will not be on the
|
||||
// available clients list, as they get automatially connected if seen.
|
||||
// TODO: we should probably add some sort of extra labelling to mark
|
||||
// authorised AND connected client.
|
||||
Reference< XNameAccess > const xConfig = officecfg::Office::Impress::Misc::AuthorisedRemotes::get();
|
||||
Sequence< OUString > aNames = xConfig->getElementNames();
|
||||
for ( int i = 0; i < aNames.getLength(); i++ )
|
||||
{
|
||||
aClients.push_back( ::boost::shared_ptr< ClientInfo > ( new ClientInfo( aNames[i], "", true ) ) );
|
||||
}
|
||||
|
||||
return aClients;
|
||||
}
|
||||
|
||||
|
@ -257,7 +275,12 @@ bool RemoteServer::connectClient( ::boost::shared_ptr< ClientInfo > pClient, con
|
|||
return false;
|
||||
|
||||
ClientInfoInternal* apClient = dynamic_cast< ClientInfoInternal* >( pClient.get() );
|
||||
ClientInfoInternal *apClient = (ClientInfoInternal*) pClient;
|
||||
if ( !apClient )
|
||||
// could happen if we try to "connect" an already authorised client
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( apClient->mPin.equals( aPin ) )
|
||||
{
|
||||
// Save in settings first
|
||||
|
@ -312,6 +335,30 @@ bool RemoteServer::connectClient( ::boost::shared_ptr< ClientInfo > pClient, con
|
|||
}
|
||||
}
|
||||
|
||||
void RemoteServer::deauthoriseClient( ::boost::shared_ptr< ClientInfo > pClient )
|
||||
{
|
||||
// TODO: we probably want to forcefully disconnect at this point too?
|
||||
// But possibly via a separate function to allow just disconnecting from
|
||||
// the UI.
|
||||
|
||||
SAL_INFO( "sdremote", "RemoteServer::deauthoriseClient called" );
|
||||
if ( !spServer )
|
||||
return;
|
||||
|
||||
if ( !pClient->mbIsAlreadyAuthorised )
|
||||
// We can't remove unauthorised clients from the authorised list...
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
boost::shared_ptr< ConfigurationChanges > aChanges = ConfigurationChanges::create();
|
||||
Reference< XNameContainer > const xConfig =
|
||||
officecfg::Office::Impress::Misc::AuthorisedRemotes::get( aChanges );
|
||||
|
||||
xConfig->removeByName( pClient->mName );
|
||||
aChanges->commit();
|
||||
}
|
||||
|
||||
void SdDLL::RegisterRemotes()
|
||||
{
|
||||
SAL_INFO( "sdremote", "SdDLL::RegisterRemotes called" );
|
||||
|
|
Loading…
Reference in a new issue