Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

AlertWindow.h

Go to the documentation of this file.
00001 /*
00002 12345678901234567890123456789012345678901234567890123456789012345678901234567890
00003 */
00004 #ifndef Impala_Application_SDash_AlertWindow_h
00005 #define Impala_Application_SDash_AlertWindow_h
00006 
00007 #ifndef OglGui_Window_h
00008 #include "OglGui/Window.h"
00009 #endif
00010 
00011 #ifndef OglGui_Button_h
00012 #include "OglGui/Button.h"
00013 #endif
00014 
00015 #ifndef OglGui_TitledWindow_h
00016 #include "OglGui/TitledWindow.h"
00017 #endif
00018 
00019 #ifndef OglGui_ScrollWnd_h
00020 #include "OglGui/ScrollWnd.h"
00021 #endif
00022 
00023 #ifndef OglGui_TextEditLineScroller_h
00024 #include "OglGui/TextEditLineScroller.h"
00025 #endif
00026 
00027 #ifndef OglGui_ViewStrip_h
00028 #include "OglGui/ViewStrip.h"
00029 #endif
00030 
00031 #include "Util/StringParser.h"
00032 
00033 #ifndef RICHARD
00034 #include "Application/sdash/AlertRelay.h"
00035 #endif
00036 
00037 namespace Impala {
00038 namespace Application {
00039 namespace SDash {
00040 
00041 using namespace OglGui;
00042 
00043 class AlertWindow : public  TitledWindow,
00044                     public  ButtonListener,
00045                     public  ImagesListener,
00046                     public  WindowListener
00047 {
00048 public:
00049     AlertWindow(Window* parent, int x, int y, int w, int h, strconst title, const std::string& ipAddress) :
00050       TitledWindow(parent, x, y, w, h, title)
00051 #ifndef RICHARD
00052       , mIpAddress(ipAddress), mAlertRelay(AlertRelay(ipAddress))
00053 #endif
00054     {
00055         Init(w, h);
00056     }
00057 
00058     AlertWindow(Window *parent, const std::string& ipAddress) 
00059         : TitledWindow(parent, 
00060         (parent->Width() - 400)/2, 
00061         (parent->Height() - 800)/2, 
00062         400, 800, "New message")
00063 #ifndef RICHARD
00064         , mAlertRelay(AlertRelay(ipAddress))
00065 #endif
00066     {
00067         Init(400, 800);
00068     }
00069 
00070     void AddMailTo(strconst str)
00071     {
00072         int         wndW = mMailToWindow->W();
00073         int         wndH = mMailToWindow->H();
00074         int         wndY = mMailToWindow->Y();
00075         int         y    = wndH - (mMailToCheckBoxes.size()+1) * 24;
00076         CheckBox*   cB   = new CheckBox(mMailToWindow, 6, y, wndW-12, 20, str);
00077         mMailToCheckBoxes.push_back(cB);
00078     }
00079 
00080     void SetMailToSelected(int id, bool set=true)
00081     {
00082         mMailToCheckBoxes[id]->SetSelected(set);
00083     }
00084 
00085     void SetMailToStatus(int status[6])
00086     {
00087         for (int i = 0; i < 6; i++)
00088         {
00089             mMailToStatus[i] = status[i];
00090         }
00091     }
00092 
00093     void SetSelectedImages(const ViewStrip* vStrip)
00094     {
00095         viewSys.DeleteViews(mImagesStrip->GetOGLWND());
00096         mImagesStrip->LayoutViews();
00097         viewSys.DeleteViews(mAttachStrip->GetOGLWND());
00098         mAttachStrip->LayoutViews();
00099         OGLWND* oglWnd = vStrip->GetOGLWND();
00100         LIST* obj;
00101         ForAllElements(obj, oglWnd->objectList)
00102         {
00103             OGLVIEW*    srcView = (OGLVIEW*) obj->info;
00104             View*       view = mImagesStrip->AddImage(srcView->im);
00105             OGLVIEW*    oglView = view->GetOGLVIEW2D();
00106 
00107             oglView->UserData1 = srcView->UserData1;
00108             oglView->UserData2 = srcView->UserData2;
00109             oglView->UserData3 = srcView->UserData3;
00110         }
00111     }
00112 
00113     void ToAttachments(OGLVIEW* oglView)
00114     {
00115         if (!mAttachStrip->FindViewWithImage(oglView->im))
00116         {
00117             View*       view = mAttachStrip->AddImage(oglView->im);
00118             OGLVIEW*    dstView = view->GetOGLVIEW2D();
00119             dstView->UserData1 = oglView->UserData1;
00120             dstView->UserData2 = oglView->UserData2;
00121             dstView->UserData3 = oglView->UserData3; 
00122         }
00123     }
00124 
00125     virtual void
00126     ImageSelectionEvent(Window* src, int imIndex, int msg, int btn, int state, void* userData)
00127     {
00128         if (state&oglControl)
00129             return;
00130         if (userData == (void*)2) // mImagesStrip. Sending to mAttachStrip
00131             ToAttachments(mImagesStrip->FindIndexView(imIndex));
00132     }
00133 
00134     TextEdit* SubjectEditor()       { return mSubjectLine->TextEditor(); }
00135     TextEdit* BodyEditor()          { return mFreeText; }
00136 
00137     void SubjectString(strconst str)
00138     {
00139         mSubjectLine->TextEditor()->SetText(str);
00140     }
00141 
00142     void Urgency(int i)
00143     {
00144         mUrgencyRadioGroup->SetActiveRadio(i);
00145     }
00146 
00147     void BodyString(strconst str)
00148     {
00149         mFreeText->SetText(str);
00150     }
00151 
00152     std::string BodyString()
00153     {
00154         return mFreeText->GetText();
00155     }
00156 
00157     void FromString(strconst str)
00158     {
00159         mFromText->SetText(str);
00160     }
00161 
00162     virtual void ButtonSelectionEvent(Button *src, void* userData)
00163     {
00164         if (src == mSubmitButton)
00165         {
00166             std::string msg;
00167             std::string subjectText = mSubjectLine->TextEditor()->GetText();
00168 
00169             AddFieldToMsg(msg, EscapePipes(subjectText.substr(0, 20))); // lenth may excess 20 as a result of inserting esc chars
00170 
00171             // bepaal file naam vd kaart obv. geselecteerde (beschikbare) agenten en beschikbare jpg's ?!
00172             int demoReceiverId = 0;
00173             for (int i = 0; i < mMailToCheckBoxes.size(); i++)
00174                 if (mMailToCheckBoxes[i]->GetSelected())
00175                 {
00176                     demoReceiverId = i;
00177                     break;
00178                 }
00179             //AddFieldToMsg(msg, "politie" + MakeString(demoReceiverId) + ".png");
00180             AddFieldToMsg(msg, "politie" + MakeString(demoReceiverId) + ".jpg");
00181 
00185             //if (mTargetCamLocation <= 6 || mTargetCamLocation == 12)
00186             //    demoReceiverId = 1;
00187             //else
00188             //    demoReceiverId = 2;
00189             //AddFieldToMsg(msg, "p" + MakeString(demoReceiverId) + "_cam" + MakeString(mTargetCamLocation) + ".png");
00190 
00191             AddFieldToMsg(msg, MakeCsv(EscapePipes((mFromText->GetText()))));
00192 
00193             int urgencyId = mUrgencyRadioGroup->GetActiveRadio();
00194             std::string urgency = mUrgencyStrings[urgencyId];
00195             StringToLower(urgency);
00196             AddFieldToMsg(msg, urgency);
00197 
00198             const std::string& locations = mLastLocations->GetText();
00199             int lastLocSep = locations.find_last_of("\n"); // last location only
00200             std::string lastLocation = locations.substr(lastLocSep + 1);
00201             int endPosOfAddressPrefix = lastLocation.find_first_of("]");
00202             AddFieldToMsg(msg, lastLocation.substr(endPosOfAddressPrefix + 2));
00203 
00204             AddFieldToMsg(msg, EscapePipes(subjectText));
00205 
00206             AddFieldToMsg(msg, lastLocation.substr(0, endPosOfAddressPrefix + 1) + "\n" + EscapePipes(mFreeText->GetText()));
00207 
00208             // collect attachment file info
00209             char buffer[128];
00210             std::string attachmentNames;
00211             OGLWND* oglWnd = mAttachStrip->GetOGLWND();
00212             LIST* obj;
00213             int cnt = 0;
00214             ForAllElements(obj, oglWnd->objectList)
00215             {
00216                 OGLVIEW* srcView = (OGLVIEW*) obj->info;
00217                 int videoId = (int)(long long) srcView->UserData1;
00218                 int frameNr = (int)(long long) srcView->UserData2;
00219                 int roiNr = (int)(long long) srcView->UserData3;
00220                 sprintf(buffer, "video%i/roi_%i_%i_%i.jpg", videoId, videoId, frameNr, roiNr);
00221                 if (cnt++ > 0)
00222                     attachmentNames += ",";
00223                 attachmentNames += std::string(buffer);
00224             }
00225             AddFieldToMsg(msg, attachmentNames);
00226 
00227             // extra field; currently static value;
00228             // rework once we take selected officers into account
00229             AddFieldToMsg(msg, mMailToStatus[demoReceiverId] == 1 ? "beschikbaar" : "onbeschikbaar");
00230 #ifndef RICHARD
00231             if (mAlertRelay.IsReady())
00232                 mAlertRelay.Relay(msg);
00233 
00234             //{
00235             //    AlertRelay relay(mIpAddress);
00236             //    if (relay.IsReady())
00237             //        relay.Relay(msg);
00238             //}
00239 #endif
00240         }
00241 
00242         if (src == mSubmitButton || src == mCancelButton)
00243         {
00244             mPane->SetBackground(oglGUI_BG & 0x00ffffff);
00245             mFadeOut = true;
00246         }
00247 
00248         if (src == mAddAllButton)
00249             TaggedToAttachments(visibleTag);
00250     }
00251 
00252     void SpotLocations(
00253         const std::vector<int>& videoTrack,
00254         const std::vector<const std::string* const>& addressTrack, 
00255         const std::vector<int>& timeTrackInSec)
00256     {
00257         int trackLength = videoTrack.size();
00258         std::string locationsString;
00259         //locationsString += "Last locations:\n";
00260         int camNr = -1;
00261         for (int i = 0; i < trackLength; i++)
00262         {
00263             int hours = timeTrackInSec[i] / 3600;
00264             int minutes = (timeTrackInSec[i] % 3600) / 60;
00265             camNr = 1 + videoTrack[i];
00266             if (i > 0)
00267                 locationsString += "\n";
00268             // SK: quick 'n dirty
00269             locationsString += MakeString(hours) + ":" + MakeString(minutes) + " [cam " + MakeString(camNr) + "] " + *(addressTrack[i]);
00270         }
00271         mLastLocations->SetText(locationsString);
00272 
00273         mTargetCamLocation = camNr; // last location of the track
00274     }
00275 
00276     void ChangeBackground(Window* wnd)
00277     {
00278         ULONG bg = wnd->GetBackground();
00279         bg = ((bg&0x00ffffff) | (mOpacity<<24));
00280         wnd->SetBackground(bg);
00281     }
00282 
00283     void TaggedToAttachments(int tag)
00284     {
00285         int i = 0;
00286         while(OGLVIEW* oglView = mImagesStrip->FindIndexView(i))
00287         {
00288             if (viewSys.HasTags(oglView, tag))
00289                 ToAttachments(oglView);
00290             i++;
00291         }
00292     }
00293 
00294     virtual void
00295     WindowKeyboardEvent(Window *src, int c, int state, void* userData)
00296     {
00297         ViewStrip* vStrip = (ViewStrip*)src;
00298         if (c == oglDELETE)
00299             ((ViewStrip*)src)->LayoutViews();
00300         if (c == 's')
00301             TaggedToAttachments(selectedTag);
00302     }
00303 
00304     virtual void DisplayFunc()
00305     {
00306         if (!mFadeOut && mOpacity < 255)
00307             mOpacity += 15;
00308         if (mFadeOut && ((mOpacity -= 15) <=0))
00309             SetVisible(mFadeOut=false);
00310 
00311         ChangeBackground(mPane);
00312         ChangeBackground(mFreeText);
00313         ChangeBackground(mFromText);
00314         ChangeBackground(mSubjectLine->TextEditor());
00315 
00316         int state = mSubmitButton->GetState();
00317         int hasObjects = mAttachStrip->GetOGLWND()->objectList != 0;
00318 
00319         mSubmitButton->SetState(hasObjects ? (state?state:1) : 0);
00320 
00321         TitledWindow::DisplayFunc();
00322     }
00323 
00324 
00325 private:
00326 
00327     void Init(int w, int h)
00328     {
00329         SetDimensions(w, h);
00330         SetRoundness(0,0,0,0);
00331         mPane = ContentPane();
00332         mPane->GetOGLWND()->noMouseInput = true;
00333         mPane->SetBackground(oglGUI_BG & 0xe0ffffff);
00334         int paneW = mPane->W();
00335         int paneH = mPane->H();
00336         int tmpW;
00337         int y;
00338 
00339         mToText = new StaticText(mPane,6,paneH-28,120,24,"To:");
00340         mToText->SetAlign(oglLeftAlign,oglTopAlign);
00341 
00342         tmpW = paneW-132;
00343         mMailToScrollWnd = new ScrollWnd(mPane,126,paneH-112,tmpW,108,true,0);
00344         mMailToWindow = new Window(mMailToScrollWnd->ContentHolder(), 0,-100, 1000, 200);
00345         mMailToScrollWnd->ReplaceContentPane(mMailToWindow);
00346 
00347         y = mMailToScrollWnd->Y()-28;
00348         mUrgencyText = new StaticText(mPane, 6, y, tmpW, 24, "Priority:");
00349         mUrgencyText->SetAlign(oglLeftAlign, oglTopAlign);
00350 
00351         tmpW +=4;
00352         mUrgencyRadioGroup = new RadioGroup(mPane, 124, y, tmpW, 26);
00353         mUrgencyRadioGroup->SetBorderType(0);
00354         mUrgencyRadioGroup->SetButtonDimensions((tmpW-14)/3, 24);
00355 
00356         mUrgencyStrings[0] = "Low";
00357         mUrgencyStrings[1] = "Medium";
00358         mUrgencyStrings[2] = "High";
00359 
00360         for (int i=0; i<3; i++)
00361             mUrgencyRadioGroup->Add(mUrgencyStrings[i], BEV_RAISED, true);
00362         mUrgencyRadioGroup->RepositionViewports();
00363         mUrgencyRadioGroup->SetReposChildren(false,false);
00364 
00365         tmpW-=4;
00366         y = mUrgencyRadioGroup->Y()-24;
00367         mSubjectText = new StaticText(mPane,6,y,120,24,"Subject:");
00368         mSubjectText->SetAlign(oglLeftAlign, oglTopAlign);
00369 
00370         mSubjectLine = new TextEditLineScroller(mPane,124,y,tmpW,20," ");
00371         //SubjectString("Vandalisme");
00372  
00373         y = mSubjectLine->Y()-104;
00374         mFreeText = new TextEdit(mPane,6,y,paneW-12,100," ");
00375         mFreeText->SetBorderType(BEV_ETCHED);
00376         //mFreeText->SetText("Beschadiging van parkeerautomaat");
00377 
00378         y = mFreeText->Y()-19;
00379         (new StaticText(mPane, 6,y, 200, 16, "Last locations:"))->SetAlign(oglLeftAlign,oglBottomAlign);
00380         y = mFreeText->Y()-78;
00381         mLastLocations = new TextEdit(mPane,6,y,paneW-12,60," ",2);
00382         mLastLocations->SetBorderType(BEV_ETCHED);
00383         mLastLocations->SetBackground(0);
00384         //mLastLocations->SetText("Laatste locaties:\n13:58 cam 103: Mathenesserstr.\n13:59 cam 105: Zuid marconiplein");
00385 
00386         y = mLastLocations->Y()-19;
00387         (new StaticText(mPane, 6,y, 200, 16, "From:"))->SetAlign(oglLeftAlign,oglBottomAlign);
00388         y = mLastLocations->Y()-62;
00389         mFromText = new TextEdit(mPane,6,y,paneW-12,44," ",0);
00390         mFromText->SetBorderType(BEV_ETCHED);
00391         //mFromText->SetText("Afzender:\nG.E. de Vaart,\ncamera surveillance Rotterdam");
00392 
00393         y = mFromText->Y()-166;
00394         mAttachGb = new GroupBox(mPane,6,y,paneW-12,162,"Attachments:");
00395         mAttachGb->SetBorderFillShaded(DEEP_SHADE_UP);
00396         mAttachStrip = new ViewStrip(mAttachGb,4,4,paneW-20,140);
00397         oglSys.AllowPicking(mAttachStrip->GetOGLWND(),1,1);
00398         oglSys.SetAllowDeleteView(mAttachStrip->GetOGLWND(),1);
00399         mAttachStrip->SetViewTags((FlexViewTags) & ~movableTag);
00400         mAttachStrip->SetMargin(4);
00401         mAttachStrip->Spacing(4);
00402         mAttachStrip->SetImagesListener(this,(void*)1);
00403         mAttachStrip->SetWindowListener(this,(void*)1);
00404 
00405         y = mAttachGb->Y()-26;
00406         mSubmitButton = new Button(mPane,6,y,100,24,"Send",BEV_ETCHED,true);
00407         mSubmitButton->SetButtonListener(this,(void*)this);
00408 
00409         mCancelButton = new Button(mPane,112,y,100,24,"Cancel",BEV_ETCHED,true);
00410         mCancelButton->SetButtonListener(this,(void*)this);
00411 
00412 
00413         y = mSubmitButton->Y()-166;
00414         mImagesGb = new GroupBox(mPane,6,y,paneW-12,164,"Add to message:");
00415         mImagesGb->SetBorderFillShaded(DEEP_SHADE_UP);
00416         mImagesStrip = new ViewStrip(mImagesGb,4,4,paneW-20,140);
00417         oglSys.AllowPicking(mImagesStrip->GetOGLWND(),1,1);
00418         oglSys.SetAllowDeleteView(mImagesStrip->GetOGLWND(),1);
00419         mImagesStrip->SetViewTags((FlexViewTags) & ~movableTag);
00420         mImagesStrip->SetMargin(4);
00421         mImagesStrip->Spacing(4);
00422         mImagesStrip->SetImagesListener(this,(void*)2);
00423         mImagesStrip->SetWindowListener(this,(void*)2);
00424 
00425         mAddAllButton =
00426             new Button(mImagesGb,paneW-80,144,64,18,"Add all",BEV_ETCHED,true);
00427         mAddAllButton->SetButtonListener(this);
00428 
00429         mPane->ScaleChildren(0,1);
00430         mPane->SetAllowChildScaling(false);
00431 
00432         mFadeOut = false;
00433         mOpacity = 0;
00434     }
00435 
00436     void AddFieldToMsg(std::string& msg, const std::string& addition)
00437     {
00438         if (!msg.empty())
00439             msg += "|";
00440 
00441         if (addition.empty())
00442             msg += " "; // prevent consecutive separator chars, which screws up parsing 
00443         else 
00444             msg += addition; 
00445     }
00446 
00447     // Replaces newlines by comma's
00448     // SK: inefficient impl, but better readable while designing...
00449     std::string MakeCsv(const std::string& stringWithNewLines)
00450     {
00451         Util::StringParser parser(stringWithNewLines);
00452         std::string asCsv;
00453         std::string sub = parser.GetString('\n', false);
00454         asCsv += sub;
00455         while (!parser.TheEnd())
00456         {
00457             sub = parser.GetString('\n', false);
00458             if (!sub.empty())
00459             {
00460                 asCsv += ",";;
00461                 asCsv += sub;
00462             }
00463         }
00464         return asCsv;
00465     }
00466 
00467     // escapes pipe chars '|' with a pipe char
00468     std::string EscapePipes(const std::string& someText)
00469     {
00470         std::string escPipes;
00471         int pos = 0;
00472         int pos2 = 0;
00473         while (pos != std::string::npos && pos < someText.size())
00474         {
00475             pos2 = someText.find_first_of('|', pos);
00476             if (pos2 != std::string::npos)
00477                 escPipes += someText.substr(pos, (++pos2 - pos)) + "|";
00478             else
00479                 escPipes += someText.substr(pos);
00480             pos = pos2;
00481         }
00482         return escPipes;
00483     }
00484 
00485     std::vector<CheckBox*>      mMailToCheckBoxes;
00486     ScrollWnd*                  mMailToScrollWnd;
00487     Window*                     mMailToWindow;
00488     int                         mMailToStatus[6];
00489 
00490     Window*                     mPane;
00491     StaticText*                 mToText;
00492 
00493     StaticText*                 mUrgencyText;
00494     RadioGroup*                 mUrgencyRadioGroup;
00495     std::string                 mUrgencyStrings[3];
00496     Button*                     mUrgencyButtons[3];
00497 
00498     StaticText*                 mSubjectText;
00499     TextEditLineScroller*       mSubjectLine;
00500 
00501     TextEdit*                   mFreeText;
00502     TextEdit*                   mLastLocations;
00503     TextEdit*                   mFromText;
00504 
00505     GroupBox*                   mAttachGb;
00506     ViewStrip*                  mAttachStrip;
00507 
00508     Button*                     mSubmitButton;
00509     Button*                     mCancelButton;
00510 
00511     Button*                     mAddAllButton;
00512 
00513     GroupBox*                   mImagesGb;
00514     ViewStrip*                  mImagesStrip;
00515 
00516     bool                        mFadeOut;
00517     ULONG                       mOpacity;
00518 
00519     int                         mTargetCamLocation;
00520 
00521 #ifndef RICHARD
00522     AlertRelay                 mAlertRelay;
00523     std::string                mIpAddress;
00524 #endif
00525 
00526 };
00527 
00528 } // namespace SDash
00529 } // namespace Application
00530 } // namespace Impala
00531 
00532 #endif

Generated on Fri Mar 19 09:30:37 2010 for ImpalaSrc by  doxygen 1.5.1