00001 #include "invitation.h" 00002 00003 #include "task.h" 00004 #include "user.h" 00005 #include <tools/invaliddataexception.h> 00006 00007 namespace domain 00008 { 00009 00010 struct InvitationPrivate 00011 { 00012 Task* task; 00013 User* user; 00014 Invitation::State state; 00015 }; 00016 00017 Invitation::Invitation(Task* task, User* user) : d(new InvitationPrivate()) 00018 { 00019 Q_ASSERT(task != 0); 00020 Q_ASSERT(user != 0); 00021 00022 d->task = task; 00023 d->user = user; 00024 d->state = Pending; 00025 00026 task->addInvitation(this); 00027 user->addInvitation(this); 00028 } 00029 00030 Invitation::~Invitation() 00031 { 00032 d->task->removeInvitation(this); 00033 d->user->removeInvitation(this); 00034 d->task->notify(); 00035 delete d; 00036 } 00037 00038 const Task* Invitation::task() const 00039 { 00040 return d->task; 00041 } 00042 00043 const User* Invitation::user() const 00044 { 00045 return d->user; 00046 } 00047 00048 Invitation::State Invitation::state() const 00049 { 00050 return d->state; 00051 } 00052 00053 QString Invitation::stateString() const 00054 { 00055 switch (d->state) 00056 { 00057 case Pending: return "Pending"; 00058 case Accepted: return "Accepted"; 00059 case Declined: return "Declined"; 00060 00061 default: break; //keep compiler happy 00062 } 00063 00064 return "This is embarrassing..."; 00065 } 00066 00067 void Invitation::setState(Invitation::State state) 00068 { 00069 if (state == All) 00070 throw tools::InvalidDataException("Cannot set the state to All"); 00071 00072 if (d->state != state) 00073 { 00074 d->state = state; 00075 d->task->notify(); 00076 emit dataChanged(); 00077 } 00078 } 00079 00080 } //ns domain