00001 #include "resourcecreator.h" 00002 00003 #include <controldata.h> 00004 00005 #include <domain/taskmanagerdata.h> 00006 #include <domain/resourcetype.h> 00007 00008 #include <tools/stringexception.h> 00009 00010 using namespace control; 00011 00012 ControllerInterface::ActionType ResourceCreator::actionType() const 00013 { 00014 return CreateAction; 00015 } 00016 00017 ControllerInterface::DataType ResourceCreator::dataType() const 00018 { 00019 return ResourceData; 00020 } 00021 00022 QString ResourceCreator::description() const 00023 { 00024 return "Create Resource"; 00025 } 00026 00027 QString ResourceCreator::name() const 00028 { 00029 return "ResourceCreator"; 00030 } 00031 00032 bool ResourceCreator::userIsValid() const 00033 { 00034 return userHasLoggedIn() && !userIsAdmin(); 00035 } 00036 00037 void ResourceCreator::execute() 00038 { 00039 QList<domain::ResourceType*> types = data->resourceTypes(); 00040 QMap<QString, domain::ResourceType*> typeMap; 00041 00042 Q_FOREACH (domain::ResourceType* type, types) 00043 typeMap[type->name()] = type; 00044 00045 data::ResourceDetails details = ui->getResourceDetails(typeMap.keys()); 00046 00047 if (!details.processData) 00048 return; 00049 00050 try 00051 { 00052 data->createResource(details.description, typeMap[details.type]); 00053 } 00054 catch (tools::StringException e) 00055 { 00056 ui->showError(e.message()); 00057 } 00058 } 00059 00060 Q_EXPORT_PLUGIN2(controller_resourcecreator, ResourceCreator)