Admin/user mode - adapt GUI to current privileges
I need to handle a custom (nothing to do with OS user rights) admin mode where the whole GUI has to be shown while some elements would have to be hidden to regular users in standard mode.
This user level should be application wide and I was wondering if there is a standard way to handle this.
I tried to search this forum (and google) but found nothing relevant. I think I am not using the correct keywords to describe this kind of behavior.
-There is no Qt builtin API in order to detect this. You will have to use the native API of Windows/Mac OS X/Linux.-
Is it about detecting that you're in admin mode or about hiding/disabling stuff and you know already whether you're admin or not?
A trick I have used in the past, is to abuse the dynamic properties feature of Qt. Designer allows you to set additional properties on any widget. You could give your admin widgets such a property. Then, when you show a form, you check if you are in admin mode. If so, you make sure you make all widgets that refer to this mode visible, and otherwise you hide them. You can do that by simply looping over all widgets in a form. Note that this may not work in all cases, and that it can result in bad UI if you hide UI elements that are important for your layout.
Where you store if you are in admin mode, is up to you. It depends on your application structure what the most logical place is for such information. Perhaps a subclassed QApplication, but perhaps you already have some kind of application object around.
Edit: I think I interpretted the question differently from Volker. Do you mean that you want to react to OS-level priveledges (like: user has admin rights at the system level), or that you want to change your UI based on application-level rights?
I will edit first post. I want to handle my own admin level, it has nothing to do with OS-level user rights.
Thanks for your answers guys.
Ah, ok. Now I understand. In that case I would store the admin mode true/false as a property in the QApplication object:
You'll have to loop over the relevant widgets in your forms' classes to hide or disable the controls manually. I personally would go for just disabling them, as that does not have any impact on the layout of your forms. If you need to hide them, maybe because showing off the data in it would dispose confidential data, then make sure, that it does not impact your layout.
Unfortunately I have to hide them, because part of the idea is to keep the interface as simple as possible for basic users.
When porting applications to Qt I'm used to implement a kind of login-info class that stores some info about the user that is currently logged in. Then I can simply exclude widgets using a
@setVisible( loginInfo.isAdministrator() );@
or something like that. Depending on your component, you can even avoid to insert it in the layout, or create it at all. As volker suggested, I prefer to disable components rather than removing them. This will waste a few resources, but will give also the user an idea of what he cannot do due to privileges without having to complain that a feature as not been implemented at all.
This is very close to a problem I have. I am planning on using the system to create and manage users some of which will have more rights than others within my application. What I can not find using my favourite search machine is how I can determine within Qt who is logged in (and what his user group is)
Not very platform independent (sorry) but the idea is to give different groups different rights and users attached to a group gain those rights without having to specify it in detail for each new user.
Is there a means of determining the current logged in user and her group from within Qt?