MythTV  0.26-pre
imageview.cpp
Go to the documentation of this file.
00001 // -*- Mode: c++ -*-
00002 /* ============================================================
00003  * File  : imageview.cpp
00004  * Description : 
00005  * 
00006  * Copyright 2004-2006 Renchi Raju, Daniel Kristjansson
00007  *
00008  * This program is free software; you can redistribute it
00009  * and/or modify it under the terms of the GNU General
00010  * Public License as published bythe Free Software Foundation;
00011  * either version 2, or (at your option)
00012  * any later version.
00013  * 
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  * 
00019  * ============================================================ */
00020 
00021 // Qt headers
00022 #include <QDir>
00023 
00024 // MythTV plugin headers
00025 #include <mythcontext.h>
00026 #include <lcddevice.h>
00027 #include <mythuihelper.h>
00028 
00029 // MythGallery headers
00030 #include "imageview.h"
00031 #include "galleryutil.h"
00032 #include "thumbgenerator.h"
00033 
00034 ImageView::ImageView(const ThumbList &itemList,
00035                      int *pos, int slideShow, int sortorder)
00036     : m_screenSize(640,480),
00037       m_wmult(1.0f),
00038       m_hmult(1.0f),
00039       m_pos(*pos),
00040       m_savedPos(pos),
00041       m_itemList(itemList),
00042       m_movieState(0),
00043       m_zoom(1.0f),
00044 
00045       // Info variables
00046       m_info_show(false),
00047       m_info_show_short(false),
00048 
00049       // Common slideshow variables
00050       m_slideshow_running(false),
00051       m_slideshow_sequencing(slideShow),
00052       m_slideshow_sequencing_inc_order(sortorder),
00053       m_slideshow_sequence(NULL),
00054       m_slideshow_frame_delay(2),
00055       m_slideshow_frame_delay_state(m_slideshow_frame_delay * 1000),
00056       m_slideshow_timer(NULL),
00057 
00058       // Common effect state variables
00059       m_effect_running(false),
00060       m_effect_current_frame(0),
00061       m_effect_method(QString::null),
00062       m_effect_random(false)
00063 {
00064 
00065     int xbase, ybase, screenwidth, screenheight;
00066     GetMythUI()->GetScreenSettings(xbase, screenwidth,  m_wmult,
00067                                 ybase, screenheight, m_hmult);
00068     m_screenSize = QSize(screenwidth, screenheight);
00069 
00070     // --------------------------------------------------------------------
00071 
00072     bool recurse = gCoreContext->GetNumSetting("GalleryRecursiveSlideshow", 0);
00073 
00074     ThumbItem *origItem = NULL;
00075     if (m_pos < m_itemList.size())
00076         origItem = m_itemList.at(m_pos);
00077 
00078     // FIXME this looks wrong
00079     //remove all dirs from m_itemList;
00080     ThumbItem *item;
00081     for (int x = 0; x < m_itemList.size(); x++)
00082     {
00083         item = m_itemList.at(x);
00084         if (item->IsDir())
00085         {
00086             if (recurse)
00087                 GalleryUtil::LoadDirectory(m_itemList, item->GetPath(),
00088                                            sortorder, recurse, NULL, NULL);
00089             m_itemList.takeAt(x);
00090         }
00091     }
00092 
00093     // --------------------------------------------------------------------
00094 
00095     // since we remove dirs item position might have changed
00096     if (origItem) 
00097         m_pos = m_itemList.indexOf(origItem);
00098 
00099     m_pos = (!origItem || (m_pos == -1)) ? 0 : m_pos;
00100 
00101     // --------------------------------------------------------------------
00102 
00103     m_slideshow_frame_delay = gCoreContext->GetNumSetting("SlideshowDelay", 0);
00104     m_slideshow_frame_delay = (!m_slideshow_frame_delay) ?
00105         2 : m_slideshow_frame_delay;
00106     m_slideshow_frame_delay_state = m_slideshow_frame_delay * 1000;
00107 
00108     // --------------------------------------------------------------------
00109 
00110     if (slideShow > 1)
00111     {
00112         m_slideshow_sequence = new SequenceShuffle(m_itemList.size());
00113         m_slideshow_mode = "Random Slideshow";
00114         m_pos = 0;
00115     }
00116     else
00117     {
00118         m_slideshow_sequence = new SequenceInc(m_itemList.size());
00119         m_slideshow_mode = "Slideshow";
00120     }
00121 
00122     m_pos = m_slideshow_sequence->index(m_pos);
00123 }
00124 
00125 ImageView::~ImageView()
00126 {
00127     UpdateLCD(NULL);
00128 
00129     if (m_slideshow_sequence)
00130     {
00131         delete m_slideshow_sequence;
00132         m_slideshow_sequence = NULL;
00133     }
00134 
00135     *m_savedPos = m_pos;
00136 }
00137 
00138 QString ImageView::GetRandomEffect(void) const
00139 {
00140     QMap<QString,QString> tmpMap = m_effect_map;
00141     tmpMap.remove("none");
00142     tmpMap.remove("Ken Burns (gl)");
00143     QStringList t = tmpMap.keys();
00144     int i = (int) ( (float)(t.count()) * random() / (RAND_MAX + 1.0f) );
00145     return tmpMap[t[i]];
00146 }
00147 
00148 void ImageView::UpdateLCD(const ThumbItem *item)
00149 {
00150     LCD *lcd = LCD::Get();
00151     if (!lcd)
00152         return;
00153 
00154     if (!item)
00155     {
00156         lcd->setFunctionLEDs(FUNC_PHOTO, false);
00157         lcd->switchToTime();
00158         return;
00159     }
00160     lcd->setFunctionLEDs(FUNC_PHOTO, true);
00161 
00162     QString name = item->GetName();
00163     QString desc = QString::number(m_pos + 1) + " / " +
00164         QString::number(m_itemList.size());
00165 
00166     QList<LCDTextItem> textItems;
00167     textItems.append(LCDTextItem(
00168                          1, ALIGN_CENTERED, name, "Generic", true));
00169     textItems.append(LCDTextItem(
00170                          2, ALIGN_CENTERED, desc, "Generic", false));
00171 
00172     lcd->switchToGeneric(textItems);
00173 }
00174 
00175 QString ImageView::GetDescriptionStatus(void) const
00176 {
00177     if (m_slideshow_running)
00178         return " [" + QObject::tr(m_slideshow_mode) + "]";
00179 
00180     return "";
00181 }
00182 
00183 void ImageView::GetScreenShot(QImage& image, const ThumbItem *item)
00184 {
00185     QFileInfo fi(item->GetPath());
00186     QString screenshot = QString("%1%2-screenshot.jpg")
00187                                 .arg(ThumbGenerator::getThumbcacheDir(fi.path()))
00188                                 .arg(item->GetName());
00189 
00190     if (QFile::exists(screenshot))
00191     {
00192         QImage img(screenshot);
00193         image = img;
00194     }
00195     else
00196     {
00197         QImage *img = GetMythUI()->LoadScaleImage("gallery-moviethumb.png");
00198         if (img)
00199         {
00200             image = *img;
00201         }
00202     }
00203 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends