00001 #include "usercreator.h"
00002
00003 #include <controldata.h>
00004
00005 #include <domain/taskmanagerdata.h>
00006 #include <domain/usertype.h>
00007
00008 #include <tools/stringexception.h>
00009
00010
00011 #include <QDebug>
00012
00013 using namespace control;
00014
00015 ControllerInterface::ActionType UserCreator::actionType() const
00016 {
00017 return CreateAction;
00018 }
00019
00020 ControllerInterface::DataType UserCreator::dataType() const
00021 {
00022 return UserData;
00023 }
00024
00025 QString UserCreator::description() const
00026 {
00027 return "Create user";
00028 }
00029
00030 bool UserCreator::userIsValid() const
00031 {
00032 return userIsAdmin();
00033 }
00034
00035 void UserCreator::execute()
00036 {
00037 QList<domain::UserType*> types = data->userTypes();
00038
00039 if (types.isEmpty())
00040 {
00041 ui->showError("No known user types, load a theme first");
00042 return;
00043 }
00044
00045 QMap<QString, domain::UserType*> typesMap;
00046
00047 Q_FOREACH (domain::UserType* type, types)
00048 typesMap[type->name()] = type;
00049
00050 data::StringInputData type = ui->getChoice(typesMap.keys(), "Choose a type of user");
00051
00052 if (!type.processData)
00053 return;
00054
00055 data::StringInputData name = ui->getText("Enter a username.");
00056
00057 if (!name.processData)
00058 return;
00059
00060 try
00061 {
00062 data->createUser(typesMap[type], name);
00063 }
00064 catch (tools::StringException e)
00065 {
00066 ui->showError(e.message());
00067 }
00068 }
00069
00070 QString UserCreator::name() const
00071 {
00072 return "UserCreator";
00073 }
00074
00075 Q_EXPORT_PLUGIN2(controller_usercreator, UserCreator)