task.h

Go to the documentation of this file.
00001 //Name: classes.h
00002 //Created: 30.4.2006.
00003 //Author: Danko Komlen
00004 
00005 //Time saver main classes
00006 
00007 
00008 #ifndef _CLASSES_H_
00009 #define _CLASSES_H_
00010 
00017 enum task_type {
00018         ttGENERIC=1,
00019         ttDOCUMENT,
00020         ttMEETING,
00021         ttDESIGN,
00022         ttPRESENTATION,
00023         ttTRAVEL,
00024         ttFUN,
00025 };//task_type
00026 
00027 enum task_status {
00028         tsRUNNING=1,
00029         tsPAUSED,
00030         tsNOTRUNNING,
00031         tsEXCEDED,
00032         tsCOMPLETED
00033 };//task_status
00034 
00035 //BEGIN Class declaration
00042 class c_task {
00043         private:
00044                 wxString name;
00045                 task_type type;
00046                 wxString notes;
00047                 wxString command;
00048 
00049                 wxDateTime started;
00050                 int duration;
00051                 int sec;
00052                 int time;
00053                 task_status status;
00054         public:
00055                 bool msg_showed;        
00056         
00057                 c_task(wxString name);
00058                 c_task(wxString name, task_type type, wxString notes,wxString command, int duration);
00059 
00060                 wxString *get_name();
00061                 task_type get_type();
00062                 wxString get_str_type();
00063                 wxString *get_notes();
00064                 int get_duration();
00065                 wxDateTime get_started();
00066                 task_status get_status();
00067                 wxString get_str_status();
00068                 wxString *get_command();
00069                 int get_time();
00070         
00071                 void set_name(wxString nam);
00072                 void set_type(task_type typ);
00073                 void set_notes(wxString note);
00074                 void set_duration(int duratio);
00075                 void set_started(wxDateTime starte);
00076                 void set_status(task_status statu);
00077                 void set_command(wxString comm);
00078                 void inc_time();
00079                 void reset();
00080                 void save(wxTextOutputStream *text_out);
00081                 void load(wxTextInputStream *text_in);
00082 };//c_task
00083 
00090 class c_session {
00091         private:
00092                 
00093                 int task_count;
00094                 void rebuild_list();
00095         public:
00096 
00097                 c_session();
00098                 c_task *task[10];
00099                 
00100                 void new_task(wxString name);
00101                 void new_task(wxString name, task_type type, wxString notes, wxString command, int duration);
00102                 void del_task(int task_number);
00103                 void delete_all_tasks();
00104                 
00105                 void save(wxTextOutputStream *text_out);
00106                 void load(wxTextInputStream *text_in);
00107                 int get_task_count();
00108         protected:
00109                 
00110                 
00111 };//c_session
00112 //END Class declaration
00113 
00114 //BEGIN Class Members
00115 
00116 
00117 //BEGIN c_task
00118  
00119 c_task::c_task (wxString name) {
00120         msg_showed = false;
00121         set_name (name);
00122         set_type (ttGENERIC);
00123         set_notes (wxT(""));
00124         set_command (wxT(""));
00125         set_duration (10);
00126         time = 0;
00127         sec = 0;
00128         set_started (wxDateTime::Now());
00129         set_status (tsNOTRUNNING);
00130 }//c_task cstr default
00131 
00132 c_task::c_task(wxString name, task_type type, wxString notes, wxString command, int duration){
00133         msg_showed = false;
00134         set_name (name);
00135         set_type (type);
00136         set_notes (notes);
00137         set_duration (duration);
00138         set_command (command);
00139         time = 0;
00140         sec = 0;
00141         set_started (wxDateTime::Now());
00142         set_status (tsNOTRUNNING);
00143 }//c_task cstr
00144 
00145 //GET FUNCTIONS
00146 wxString  *c_task::get_name(){
00147         return &name;
00148 }//c_task::get_name
00149 
00150 task_type c_task::get_type(){
00151         return type;
00152 }//c_task::get_type
00153 
00154 wxString *c_task::get_notes(){
00155         return &notes;
00156 }//c_task::get_notes
00157 
00158 int c_task::get_duration(){
00159         return duration;
00160 }//c_task::get_duration
00161 
00162 wxDateTime c_task::get_started(){
00163         return started;
00164 }//c_task::get_started
00165 
00166 task_status c_task::get_status(){
00167         return status;
00168 }//c_task::get_status
00169 
00170 wxString *c_task::get_command(){
00171         return &command;
00172 }
00173 
00174 wxString c_task::get_str_type() {
00175         switch (type) {
00176         case (ttGENERIC): return (_T("Generic")); break;
00177         case (ttDOCUMENT): return (_T("Document")); break;
00178         case (ttMEETING): return (_T("Meeting")); break;
00179         case (ttDESIGN): return (_T("Design")); break;
00180         case (ttPRESENTATION): return (_T("Presentation")); break;
00181         case (ttTRAVEL): return (_T("Travel")); break;
00182         case (ttFUN): return (_T("Fun")); break;
00183         }
00184 }//c_task::get_str_type()
00185 
00186 wxString c_task::get_str_status() {
00187         switch (status) {
00188 
00189         case (tsRUNNING): return (_T("running")); break;
00190         case (tsPAUSED): return (_T("paused")); break;
00191         case (tsNOTRUNNING): return (_T("not running")); break;
00192         case (tsEXCEDED): return (_T("exceded")); break;
00193         case (tsCOMPLETED): return (_T("completed")); break;
00194         
00195         }
00196 }//c_task::get_str_status()
00197 
00198 int c_task::get_time() {
00199         return time * 60 + sec;
00200 }//get_time
00201 //SET FUNCTIONS
00202 void c_task::set_name(wxString nam){
00203         name = nam;
00204 }//c_task::set_name
00205 
00206 void c_task::set_type(task_type typ){
00207         type = typ;
00208 }//c_task::set_type
00209 
00210 void c_task::set_notes(wxString note){
00211         notes = note; 
00212 }//c_task::set_notes
00213 
00214 void c_task::set_duration(int duratio){
00215         duration = duratio;
00216 }//c_task::set_duration
00217 
00218 void c_task::set_started(wxDateTime starte){
00219         started = starte;
00220 }//c_task::set_started
00221 
00222 void c_task::set_status(task_status statu){
00223         status = statu;
00224 }//c_task::set_status
00225 
00226 void c_task::set_command(wxString comm){
00227         command = comm;
00228 }//c_task::set_command
00229 
00230 void c_task::inc_time(){
00231         
00232         ++sec;
00233         if (sec >= 60) {++time;sec =0;}
00234         if (time >= duration) {set_status(tsEXCEDED);}
00235 }//inc_time
00236 
00237 void c_task::reset(){
00238         time = 0;
00239         sec = 0;
00240         msg_showed = false;
00241 }//reset
00242 
00243 void c_task::save(wxTextOutputStream *text_out){
00244 
00245 
00246         *text_out << name<<endl;
00247         *text_out << (int) type << endl;
00248         *text_out << notes<<endl;
00249         *text_out << command<<endl;
00250         *text_out << started.Format()<<endl;
00251         *text_out << duration<<endl;
00252         *text_out << sec<<endl;
00253         *text_out << time<<endl;
00254         *text_out << (int) status<<endl;
00255 
00256 
00257 }//save
00258 
00259 void c_task::load(wxTextInputStream *text_in){
00260 int a;
00261 wxString date_time;
00262         name = text_in->ReadString();
00263         *text_in >> a;
00264         type = (task_type) a;
00265         notes = text_in->ReadString();
00266         command = text_in->ReadString();
00267         date_time = text_in->ReadString();
00268         started.ParseFormat(date_time);
00269         *text_in >> duration;
00270         *text_in >> sec;
00271         *text_in >> time;
00272         *text_in >> a;
00273         status = (task_status) a;
00274 
00275 }//open
00276 //END c_task0
00277 
00278 //BEGIN c_session
00279 c_session::c_session() {
00280         task_count =0;
00281 }//c_session cstr
00282 void c_session::new_task (wxString name){
00283 ++task_count;
00284 task[task_count] = new c_task(name);
00285         
00286 }//c_session::new_task
00287 
00288 void c_session::new_task (wxString name, task_type type, wxString notes, wxString command, int duration){
00289         ++task_count;
00290         task[task_count] = new c_task(name, type,notes,command,duration);
00291         
00292 }//c_session::new_task
00293 
00294 int c_session::get_task_count() {
00295         return task_count;
00296 }//get_task_count
00297 
00298 void c_session::rebuild_list() {
00299 
00300         for (int i=1;i<=task_count;++i){
00301                 if (task[i] == NULL) {
00302                         for (int j=i;j<task_count;++j){
00303                                 task[j] = task[j+1];
00304                         }//for
00305                         task[task_count] == NULL;
00306                         --task_count;
00307                 }//if
00308         }//for
00309 }//rebuild_list
00310 
00311 void c_session::del_task(int task_number){
00312         task[task_number] = NULL;
00313         //task[task_number] = task[task_count];
00314 rebuild_list();
00315 }//del_task
00316 
00317 void c_session::delete_all_tasks(){
00318 for (int i=1;i<=task_count;++i) {
00319         delete task[i];
00320 }//for
00321 
00322 }//delete_all_tasks
00323 void c_session::save(wxTextOutputStream *text_out) {
00324 *text_out << task_count<<endl;
00325         for (int i=1;i<=task_count;++i) {
00326                 task[i]->save(text_out);
00327         }//for
00328 }//save
00329 void c_session::load(wxTextInputStream *text_in){
00330 delete_all_tasks();
00331 *text_in >> task_count;
00332         for (int i=1;i<=task_count;++i) {
00333                 task[i] = new c_task(_T(""));
00334                 task[i]->load(text_in);
00335         }//for
00336 }//open
00337 
00338 //END Class Members
00339 #endif //_CLASSES_H_ 

Generated on Mon Jul 24 19:19:27 2006 for TimeSaver by  doxygen 1.4.4