]> git.vomp.tv Git - vompclient.git/blob - vquestion.cc
Demuxer::scanForVideo()
[vompclient.git] / vquestion.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "vquestion.h"
22
23 VQuestion::VQuestion(void* treplyTo)
24 {
25   replyTo = treplyTo;
26   mainText = NULL;
27   selectedOption = NO;
28
29   buttonYes.setSurfaceOffset(40, 130);
30   buttonNo.setSurfaceOffset(140, 130);
31
32   buttonYes.setText(tr("Yes"));
33   buttonNo.setText(tr("No"));
34   buttonNo.setActive(1);
35 }
36
37 VQuestion::~VQuestion()
38 {
39   if (mainText) delete[] mainText;
40 }
41
42 void VQuestion::setMainText(char* takeText)
43 {
44   int length = strlen(takeText);
45   mainText = new char[length + 1];
46   strcpy(mainText, takeText);
47 }
48
49 void VQuestion::draw()
50 {
51   View::draw();
52
53   buttonYes.setSurface(surface);
54   buttonNo.setSurface(surface);
55
56   if (mainText) drawPara(mainText, 10, 45, Colour::LIGHTTEXT);
57   buttonYes.draw();
58   buttonNo.draw();
59 }
60
61 void VQuestion::swap()
62 {
63   if (selectedOption == NO)
64   {
65     selectedOption = YES;
66     buttonYes.setActive(1);
67     buttonNo.setActive(0);
68   }
69   else if (selectedOption == YES)
70   {
71     selectedOption = NO;
72     buttonYes.setActive(0);
73     buttonNo.setActive(1);
74   }
75 }
76
77 int VQuestion::handleCommand(int command)
78 {
79   switch(command)
80   {
81     case Remote::DF_LEFT:
82     case Remote::LEFT:
83     {
84       swap();
85       draw();
86       ViewMan::getInstance()->updateView(this);
87       return 2;
88     }
89     case Remote::DF_RIGHT:
90     case Remote::RIGHT:
91     {
92       swap();
93       draw();
94       ViewMan::getInstance()->updateView(this);
95       return 2;
96     }
97     case Remote::BACK:
98     {
99       return 4;
100     }
101     case Remote::OK:
102     {
103       if (selectedOption != YES) return 4;
104
105       Message* m = new Message(); // Question/answer mech
106       m->from = this;
107       m->to = replyTo;
108       m->message = Message::QUESTION_YES;
109       Command::getInstance()->postMessageNoLock(m);
110
111       return 4;
112     }
113   }
114   return 1;
115 }
116
117 void VQuestion::setDefault(UCHAR option)
118 {
119   selectedOption = option;
120 }