2 Copyright 2004-2005 Chris Tallon, Andreas Vogel
4 This file is part of VOMP.
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.
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.
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
22 #include "vpicturebanner.h"
25 Colour VPicture::pictureBack=Colour(140,140,140);
26 Colour VPicture::infoBack=Colour(110,110,110);
29 class VPreader : public JpegReader {
33 VPreader(VPicture *p){
35 virtual ULONG readChunk(ULONG offset,ULONG len,char ** buf) {
36 Log::getInstance()->log("VPicture::jpegReader", Log::DEBUG, "read chunk o=%d,len=%d,buf=%p",
39 *buf=(char *)VDR::getInstance()->getImageBlock(offset,(UINT)len,&numrec);
40 Log::getInstance()->log("VPicture::jpegReader", Log::DEBUG, "got n=%d,buf=%p",
44 virtual ULONG initRead(const char *filename) {
45 Log::getInstance()->log("VPicture::jpegReader", Log::DEBUG, "load image %s",filename);
46 Video* video = Video::getInstance();
47 ULONG size=VDR::getInstance()->loadImage(filename,video->getScreenWidth(), video->getScreenHeight());
48 Log::getInstance()->log("VPicture::jpegReader", Log::DEBUG, "load image %s returned %d",filename,size);
53 VPicture::VPicture(VMediaList *p)
56 reader=new VPreader(this);
58 Video* video = Video::getInstance();
59 create(video->getScreenWidth(), video->getScreenHeight());
60 jpeg.setSurface(surface);
61 jpeg.setDimensions(area.w,area.h);
67 showtime=INITIAL_SHOWTIME;
73 jpeg.setBackgroundColour(pictureBack);
79 if (banner) ViewMan::getInstance()->removeView(banner);
80 if (fullname) delete fullname;
81 if (filename) delete filename;
82 Timers::getInstance()->cancelTimer(this,1);
83 Timers::getInstance()->cancelTimer(this,2);
84 Timers::getInstance()->cancelTimer(this,3);
91 Log::getInstance()->log("VPicture::draw", Log::DEBUG, "needDraw=%d,p=%p",
95 drawText(mediaError,20,area.h-10,Colour::LIGHTTEXT);
104 int VPicture::handleCommand(int command)
106 Timers::getInstance()->cancelTimer(this,1);
112 case Remote::SKIPBACK:
113 showPicture(VMediaList::MV_PREV);
114 ViewMan::getInstance()->updateView(this);
117 case Remote::FORWARD:
118 if (showtime > 1) showtime--;
121 case Remote::DF_DOWN:
123 case Remote::SKIPFORWARD:
124 showPicture(VMediaList::MV_NEXT);
125 ViewMan::getInstance()->updateView(this);
128 case Remote::REVERSE:
129 if (showtime < 50 ) showtime++;
145 showPicture(VMediaList::MV_NEXT);
146 ViewMan::getInstance()->updateView(this);
157 showtime=INITIAL_SHOWTIME;
164 rotate=WJpeg::ROT_90;
167 rotate=WJpeg::ROT_180;
170 rotate=WJpeg::ROT_270;
176 showPicture(VMediaList::MV_NONE,rotate);
177 ViewMan::getInstance()->updateView(this);
181 if (info) destroyInfo();
191 if (slideshow) startSlideshow();
192 // stop command getting to any more views
196 void VPicture::processMessage(Message* m)
198 if (m->message == Message::MOUSE_MOVE)
202 else if (m->message == Message::MOUSE_LBDOWN)
205 //check if press is outside this view! then simulate cancel
206 int x=(m->parameter>>16)-getScreenX();
207 int y=(m->parameter&0xFFFF)-getScreenY();
208 if (x<0 || y <0 || x>getWidth() || y>getHeight())
210 ViewMan::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
215 VPicture * VPicture::createViewer(VMediaList * mparent, bool bslideshow) {
216 Log::getInstance()->log("VPicture::createViewer", Log::DEBUG, "p=%p",
218 VPicture *vmn=new VPicture(mparent);
219 ViewMan::getInstance()->add(vmn);
220 ViewMan::getInstance()->updateView(vmn);
222 if (bslideshow) vmn->startSlideshow();
224 ViewMan::getInstance()->updateView(vmn);
228 void VPicture::startSlideshow() {
230 Timers::getInstance()->setTimerD(this,1,showtime);
233 void VPicture::showPicture(ULONG move, int rt) {
235 currentMedia=parent->getMedia(MEDIA_TYPE_PICTURE,move);
237 if (mediaError || jpeg.hasError()) destroyInfo();
239 ViewMan::getInstance()->updateView(this);
243 int VPicture::load(Media *md) {
244 jpeg.init(NULL,false,NULL);
245 mediaError=tr("No media found");
248 const char *fname=md->getFileName();
250 int len=strlen(fname)+2+strlen(parent->getDirname());
255 fullname=new char[len];
256 sprintf(fullname,"%s/%s",parent->getDirname(),fname);
257 if (filename) delete filename;
259 filename=new char[len];
260 strcpy(filename,fname);
261 Log::getInstance()->log("VPicture::load", Log::DEBUG, "filename=%s,p=%p",
263 VDR* vdr=VDR::getInstance();
264 //do we have a banner?
265 bool haveBanner=banner!=NULL && ! shortBanner;
266 if (vdr->isConnected()) {
268 jpeg.init(fullname,false,reader);
269 jpeg.setRotate(rotate);
273 //only show the banner if it was there before
274 if (haveBanner) showBanner();
276 if(banner) destroyBanner();
278 Log::getInstance()->log("VPicture::load", Log::DEBUG, "success: filename=%s,p=%p",
283 mediaError=tr("no VDR connection");
288 void VPicture::showBanner(bool loading,int shortDisplay) {
289 //if the loading flag is set,
290 //we are in the main thread - so we can (and must) safely hard destroy/create the banner
291 Timers::getInstance()->cancelTimer(this,2);
292 if (! filename || ! currentMedia) {
294 destroyBanner(!loading);
297 if (banner) destroyBanner(!loading);
298 banner= new VPictureBanner(this, loading, slideshow);
299 banner->setBackgroundColour(infoBack);
301 int len=strlen(filename)+Media::TIMEBUFLEN+20;
303 char tbuf[Media::TIMEBUFLEN];
304 snprintf(buf,len,"%c%02ds%c %s %s ",
308 currentMedia->getTimeString(tbuf),
310 banner->setText(buf);
313 banner->setText(filename);
316 if (shortDisplay != 0) shortBanner=true;
317 if (! slideshow && shortDisplay == 0) shortDisplay=8;
318 //OK we start timer if we don't load and either shortDisplay or no slideshow
319 if (! loading && shortDisplay != 0) Timers::getInstance()->setTimerD(this,2,shortDisplay);
320 if (! loading) sendViewMsg(banner,false);
322 ViewMan::getInstance()->add(banner);
323 ViewMan::getInstance()->updateView(banner);
328 void VPicture::destroyBanner(bool fromTimer) {
331 if (fromTimer) sendViewMsg(banner,true);
332 else ViewMan::getInstance()->removeView(banner);
334 if (! fromTimer) Timers::getInstance()->cancelTimer(this,2);
337 void VPicture::updateBanner(bool shortDisplay) {
338 if (banner && ! shortBanner) {
341 else if (shortDisplay) {
345 void VPicture::timercall(int clientref) {
349 if (! slideshow) return;
350 Log::getInstance()->log("VPicture::timercall", Log::DEBUG, "slideshow");
351 sendCommandMsg(Remote::PLAY);
364 void VPicture::showInfo(){
365 if (info) destroyInfo();
366 if (! currentMedia) return;
368 info->setTitleText(currentMedia->getFileName());
369 info->setDropThrough();
370 info->create(500, 300);
371 info->setBorderOn(1);
372 info->setTitleBarOn(1);
374 if (Video::getInstance()->getFormat() == Video::PAL)
375 info->setScreenPos(100, 180);
377 info->setScreenPos(100, 150);
379 char tbuf[Media::TIMEBUFLEN];
380 snprintf(buf,INFOBUF,"%s= %s\n%s= %ld x %ld\n%s= %ld kBytes\n%s= %s\n%s= %ld\n%s= 1/%ld",
381 tr("Directory"), parent->getDirname(),
382 tr("Format(px)"),jpeg.getJpegInfo(WJpeg::JPEG_WIDTH),jpeg.getJpegInfo(WJpeg::JPEG_HEIGHT),
383 tr("Filesize"),jpeg.getJpegInfo(WJpeg::JPEG_SIZE)/1000,
384 tr("Time"),currentMedia->getTimeString(tbuf),
385 tr("Rotation"),90*jpeg.getJpegInfo(WJpeg::JPEG_ROTATE),
386 tr("Scale"),jpeg.getJpegInfo(WJpeg::JPEG_SCALE));
387 info->setMainText(buf);
389 sendViewMsg(info,false);
390 Timers::getInstance()->setTimerD(this,3,8);
392 void VPicture::updateInfo(){
397 void VPicture::destroyInfo(bool fromTimer){
399 sendViewMsg(info,true);
402 if (! fromTimer) Timers::getInstance()->cancelTimer(this,3);
405 void VPicture::sendViewMsg(View *v,bool vdestroy) {
406 Message* m = new Message();
407 m->message = vdestroy?Message::CLOSE_ME:Message::ADD_VIEW;
408 m->to = ViewMan::getInstance();
410 m->parameter=(ULONG)v;
411 Command::getInstance()->postMessageFromOuterSpace(m);
413 void VPicture::sendCommandMsg(int command) {
414 Message* m = new Message();
415 m->message = Message::UDP_BUTTON;
416 m->to = Command::getInstance();
418 m->parameter=command;
419 Command::getInstance()->postMessageFromOuterSpace(m);