00001 #include "invitationreplier.h" 00002 00003 #include "models/invitationmodel.h" 00004 #include <domain/taskmanagerdata.h> 00005 #include <tools/stringexception.h> 00006 00007 using namespace control; 00008 00009 ControllerInterface::ActionType InvitationReplier::actionType() const 00010 { 00011 return ModifyAction; 00012 } 00013 00014 ControllerInterface::DataType InvitationReplier::dataType() const 00015 { 00016 return InvitationData; 00017 } 00018 00019 QString InvitationReplier::description() const 00020 { 00021 return "Accept/Decline invitation"; 00022 } 00023 00024 QString InvitationReplier::name() const 00025 { 00026 return "InvitationReplier"; 00027 } 00028 00029 bool InvitationReplier::userIsValid() const 00030 { 00031 return userHasLoggedIn() && !userIsAdmin(); 00032 } 00033 00034 void InvitationReplier::execute() 00035 { 00036 InvitationModel pending(data, user(), domain::Invitation::Pending); 00037 InvitationModel accepted(data, user(), domain::Invitation::Accepted); 00038 00039 data::SelectionData data = ui->getInvitationSelection(&pending, &accepted); 00040 00041 if (!data.processData) 00042 return; 00043 00044 if (data.selection.isEmpty()) 00045 { 00046 ui->showWarning("No invitation selected"); 00047 return; 00048 } 00049 00050 Q_ASSERT(data.selection.size() == 1); 00051 00052 QStringList options = QStringList() << "Accept" << "Decline"; 00053 data::StringInputData choice = ui->getChoice( 00054 options, "Would you like to accept or decline this invitation?"); 00055 00056 if (!choice.processData) 00057 return; 00058 00059 domain::Invitation* invitation = this->data->invitation( 00060 pending.invitationForIndex(data.selection.first())); 00061 00062 try 00063 { 00064 if (choice.data == "Accept") 00065 invitation->setState(domain::Invitation::Accepted); 00066 else 00067 invitation->setState(domain::Invitation::Declined); 00068 } 00069 catch (tools::StringException& e) 00070 { 00071 ui->showError(e.message()); 00072 } 00073 } 00074 00075 Q_EXPORT_PLUGIN2(controller_invitationreplier, InvitationReplier)