]> git.vomp.tv Git - vompclient.git/blob - vrecmove.cc
Fix text corruption in channel number display on live tv
[vompclient.git] / vrecmove.cc
1 /*
2     Copyright 2006 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #include "vrecmove.h"
22
23 #include "defines.h"
24 #include "recording.h"
25 #include "remote.h"
26 #include "vinfo.h"
27 #include "colour.h"
28 #include "video.h"
29 #include "i18n.h"
30 #include "command.h"
31 #include "wsymbol.h"
32 #include "recman.h"
33 #include "directory.h"
34 #include "message.h"
35 #include "boxstack.h"
36
37 VRecMove::VRecMove(RecMan* trecman)
38 {
39   recman = trecman;
40
41   setSize(260, 210);
42   createBuffer();
43   if (Video::getInstance()->getFormat() == Video::PAL)
44   {
45     setPosition(220, 160);
46   }
47   else
48   {
49     setPosition(210, 130);
50   }
51
52   setTitleBarOn(1);
53   setBorderOn(1);
54   setTitleText(tr("Move recording"));
55   setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
56
57   sl.setPosition(10, 30 + 5);
58   sl.setSize(area.w - 40, area.h - 30 - 15);
59   add(&sl);
60
61   Directory* dir = recman->getRootDir();
62   sl.addOption("/", (ULONG)dir, 1);
63   addDirs(dir, "");
64 }
65
66 VRecMove::~VRecMove()
67 {
68 }
69
70 void VRecMove::setParent(void* tparent)
71 {
72   parent = tparent;
73 }
74
75 void VRecMove::addDirs(Directory* dir,const char* prefix)
76 {
77   Directory* currentDir;
78   for(DirectoryList::iterator i = dir->dirList.begin(); i != dir->dirList.end(); i++)
79   {
80     currentDir = *i;
81     char* title = new char[strlen(prefix) + strlen(currentDir->name) + 2]; // one for the null, one for '/'
82     sprintf(title, "%s%s", prefix, currentDir->name);
83     sl.addOption(title, (ULONG)currentDir, 0);
84
85     strcat(title, "/");
86     addDirs(*i, title);
87     delete[] title;
88   }
89 }
90
91 void VRecMove::draw()
92 {
93   TBBoxx::draw();
94
95   rectangle(area.w - 30, 30 + 5, 20, area.h - 30 - 15, DrawStyle::VIEWBACKGROUND);
96   WSymbol w;
97   TEMPADD(&w);
98
99   w.nextSymbol = WSymbol::SMALLUP;
100   w.setPosition(area.w - 28, 30 + 7);
101   w.draw();
102
103   w.nextSymbol = WSymbol::SMALLDOWN;
104   w.setPosition(area.w - 28, area.h - 26);
105   w.draw();
106 }
107
108 int VRecMove::handleCommand(int command)
109 {
110   switch(command)
111   {
112     case Remote::DF_UP:
113     case Remote::UP:
114     {
115       sl.up();
116       sl.draw();
117       BoxStack::getInstance()->update(this);
118       return 2;
119     }
120     case Remote::DF_DOWN:
121     case Remote::DOWN:
122     {
123       sl.down();
124       sl.draw();
125       BoxStack::getInstance()->update(this);
126       return 2;
127     }
128     case Remote::OK:
129     {
130       Message* m = new Message();
131       m->message = Message::MOVE_RECORDING;
132       m->to = parent;
133       m->parameter.num = sl.getCurrentOptionData();
134       Command::getInstance()->postMessageNoLock(m);
135
136       return 4;
137     }
138     case Remote::BACK:
139     {
140       return 4;
141     }
142   }
143   // stop command getting to any more views
144   return 1;
145 }
146
147 void VRecMove::processMessage(Message* m)
148 {
149   if (m->message == Message::MOUSE_MOVE)
150   {
151     if (sl.mouseMove((m->parameter.num>>16)-getScreenX(),(m->parameter.num&0xFFFF)-getScreenY()))
152     {
153       sl.draw();
154       BoxStack::getInstance()->update(this);
155     }
156   }
157   else if (m->message == Message::MOUSE_LBDOWN)
158   {
159     if (sl.mouseLBDOWN((m->parameter.num>>16)-getScreenX(),(m->parameter.num&0xFFFF)-getScreenY()))
160     {
161       BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
162     }
163     else
164     {
165       //check if press is outside this view! then simulate cancel
166       int x=(m->parameter.num>>16)-getScreenX();
167       int y=(m->parameter.num&0xFFFF)-getScreenY();
168       if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
169       {
170         BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
171       }
172     }
173   }
174 }