All the changes added to the original OpenOffice.org source code provided in this page, are :
- Under LGPL License V3, ( and you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation)
- Copyright Eric Bachard January 2010
Important: If you use this information, don't forget everything you'll find here is under CC by-sa License, and you must mention your sources in what you write ...
Below, you'll find a technical description of the New password protected preferences feature. It is question of OpenOffice.org source code (mainly C++). More precisely, you'll find there the new SfxPasswordDialog implementation, the new UI (green/red padlocks), the description of how read/write a password, a boolean, a value in the Common.cxu file (mostly UNO stuff), the description of the changes in the classes : OfaMiscTabPage (add buttons, and manage them), OfaTreeOptionsDialog (managing the changes in the prefs, depending the state of the feature, enabled/disabled).
The pre-requisites to read this article still have to be defined, but if the reader is not used with some notions, we invite him to have a look at the OpenOffice.org wiki to complete his knowledge, and read this article in the best conditions.
DRAFT, NEEDS MORE WORK
The idea is to protect the preferences using a password (default password is prof), to avoid the children changing something in the prefs, causing disorder.
Children love to experiment. Most of them have good skills for that, but this is not what the teacher expects :-) So, the goal of this feature, is to implement, intelligently, a protection for the preferences, who :
- avoids the children to modify something
- but allow them to click, and see whatever they want (in read only mode)
Important : this feature is only a protection to avoid children hacking the OOo4Kids, but not a security (the password is readable in Common.xcu)
The Rules :
- The default password, if enabled, is : prof
- By default, the preferences are unlocked
- To activate the protection, just click on the "Click to avoid modifications".
=> Be carefull : the protection will be validated once you close the dialog box, and this change is not reversible ! Means once activated, you'll need the password to disable that.
The views :
- A green padlock displayed on the bottom of the view, means : unlocked preferences
- A red padlock displayed on the bottom of the view, means : locked preferences
(green) Padlock unlocked
- Anybody can read the preferences, and look what are the current choices.
- To be able to modify the preferences, the need is to click on the red padlock (click on the green padlock will do nothing).Then, the click will trigger a dialog box, asking for a password (remember: default password, is prof. If the entered password is ok , the padlock becomes green, and the user is able to modify whatever he wants in the prefs. The password is valid until the Tool -> Options dialog box is closed.
- Once the right password has been entered, and the green padlock appeared, the user will be able to disable the "password in the prefs features".
(red) Padlock locked
Disable the protection
Change the password
Attention : the toolbars will stay customizable.
Example of Scenarios
=> Work in progress
Concerned modules :
- officecfg : the modified .xcu ( Common.cxu) + the modified .xcs is inside.
- sfx2 : the SfxPasswordDialog modal dialog is implemented there. Other methods have been added, and a fix for the returned value has been added. We'll instanciate a SfxPasswordDialog in two cases : enter the password and change the password. The minimal length of the password will be set to 4 letters.
- svx : the misc tabpage (OaMiscTabPage class) and the treeoptions (OfaTreeOptionsDialog) dialogs will be used. The former will host the set/get the information about :
- whether the password feature is enabled or not
- whether the feature was never used before or not
- read/write the password in the .xcu
- the later (treeoptions) will manage the possible/not possible modifications, depending on the state (enabled/disabled) of the feature.
- the view will be implemented in treeopt.src, and will be based on ImageButton controls.
- the padlock itself will be a pair of ImageButton playing ping-pong ( Hide()/Show() ) depending on the feature is enabled or not
To keep the clean state, and separate the changes from OpenOffice.org, the new file passwd_OOo4Kids.cxx has been added in sfx2/source/dialog
New methods and roles
Added in SfxPasswordDialog class
- OUString SfxPasswordDialog::getUserPrefsPassword()
Comment : an OUString, who returns the password contained in the Common.xcu, in the UserPrefsPassword property. This method is a public method of the SfxPasswordDialog class.
- void SfxPasswordDialog::setUserPrefsPassword( OUString aPassword )
Comment : a void public method of SfxPasswordDialog, to write the new password in the .xcu, in the UserPrefsPassword property.
Added in OfaMiscTabPage class
- bool OfaMiscTabPage::getUserPrefsPasswordBoolProperty( USER_PASSWD_PREFS_PROPERTY aUserPrefsPasswordProperty )
Comment : a getter, as bool, who returns the state ( true, false) of both in UserPrefsPasswordFeatureEnabled and UserPrefsPasswordNeverModified properties, to know whether the feature is or not enabled, or whether it was used at least once. The need is to enable/disable the "Change the password" feature, accordingly to the returned value.
- void OfaMiscTabPage::setUserPrefsPasswordBoolProperty( USER_PASSWD_PREFS_PROPERTY aUserPrefsPasswordProperty, bool aBool )
Comment : a setter, as void, used to write a bool value both in UserPrefsPasswordFeatureEnabled and UserPrefsPasswordNeverModified properties, in the Common.xcu
- IMPL_LINK( OfaMiscTabPage, aChangePrefsPasswordBtnHdl_Impl, PushButton*, EMPTYARG )
Comment : a callback, used to perform the action : open the "Change the password dialog box", if and only if the button is enabled
- IMPL_LINK( OfaMiscTabPage, aPrefsPasswordCBHdl_Impl, CheckBox*, EMPTYARG )
Comment : a callback, used to perform the action : set/unset the checkbox "Activate the password", if and only if the user is allowed to modify the preferences
- bool OfaMiscTabPage::IsPadlockLocked()
Comment : public OfaMiscTabPage method, used to retrieve the state of the prefs (locked/unlocked)
Added in OfaTreeOptionsDialog class
- IMPL_LINK( OfaTreeOptionsDialog, PadlockHdl_Impl, ImageButton *, EMPTYARG )
Comment : a callback used to perform the action lock / unlock the preferences when the user clicks on the padlock, whatever its color is.
- void OfaTreeOptionsDialog::loadImage( const ResId& i_rId, ImageButton& i_rButton )
Comment : load the image on the ImageButton control. WARNING : used more than once for a button, caused garbage and undefined behavior.
- void OfaTreeOptionsDialog::SetPadlockImage()
Comment : method called in the OfaTreeOptions constructor.
- Password entered length : short int
- The password itself : OUString
- New password : OUString
- Confirmed new password: OUString
- Password container : Common.xcu
- Password feature enabled container : Common.xcu
- Entered password validation "Ok" : button
- Entered password validation "Cancel" : button
- Validation new password "Ok" : button
- Validation new password "Cancel" : button
- Closed lock : button + image == ImageButton
- Open lock : button + image == ImageButton
- Size : aPadlockButtonImageSize (the same for both ImageButtons)
- Modal dialog box "Enter a password", with buttons "Ok", "Cancel" and one writable text area
- Modal dialog box "Enter new password", with buttons "Confirm new password", "Ok", "Cancel" and two writable text areas
- treeopt.cxx: contains the framework of the options, including the OK button to be controlled and managed, while the optgdlg.cxx contains the tabpages, and all associated actions ( IMPL_LINK ( ) ).
The controller should be based on:
- DONE Set / Reset / avoid changes in the preferences
- DONE Read / Write the password in the .xcu
- DONE create a new class inherited from sfx2 password
- DONE replace the old treeopt.cxx with a new one, including booleans and the new behavior
- DONE inactive prefs will be events driven: infinite look (modal Window) waiting for hit the lock or esc to cancel the prefs modification
- DONE implement the padlock image in the view, using two ImageButton + QuickHelpText. Only one button is displayed at the same time. Show(), Hide() are used to play ping pong with those ImageButtons.
As we are talking about preferences of OOo4Kids : I think we have also to review the content and the layout of this dialog box.
- there are too many settings
- the organisation is very confusing sometime
This is a critical related OpenOffice globaly. I think we have to keep only the majors setting and to make it clear to understand.
Another idea could be to have a Preference panel for the children with a reduce set of settings and another one with more options for the teachers. Of course it will not replace the password options proposed in this page but be a complement. Lafonjm 21 avril 2009 à 09:10 (CEST)