Logo Search packages:      
Sourcecode: maxemumtvguide version File versions  Download package

programview.cpp

/***************************************************************************
 *   Copyright (C) 2005 by Robert Maxe                                     *
 *   mutex@spray.se                                                        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
//-----------------------------------------------------------------------------------------------------------------------
#include <kmessagebox.h>

#include <klocale.h>
#include <kpopupmenu.h>
#include <qdatetime.h>
#include <qtextbrowser.h>
#include <qprogressbar.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qptrlist.h>
#include <qcursor.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include "programview.h"
#include "programitem.h"
#include "channelitem.h"
#include "mainwidget.h"
#include "program.h"
#include "favouritemaster.h"
//-----------------------------------------------------------------------------------------------------------------------
ProgramView::ProgramView(MainWidget *parent, ProgramMaster *programMaster, KListView *lv, QPtrList<Program> *programs, QWidget *frame)
      : BaseView(parent, programMaster, lv, programs, frame)
{
      m_dates.setAutoDelete(true);
      m_date = m_parent->cb_date;

      connect(m_parent->pb_yesterday, SIGNAL(clicked()), this, SLOT(yesterdayClicked()));
      connect(m_parent->pb_today, SIGNAL(clicked()), this, SLOT(todayClicked()));
      connect(m_parent->pb_tomorrow, SIGNAL(clicked()), this, SLOT(tomorrowClicked()));
      connect(m_date, SIGNAL(activated(int)), this, SLOT(rebuild()));
      rebuildCBDates();
}
//-----------------------------------------------------------------------------------------------------------------------
//void ProgramView::loadSettings(KConfig *cfg) { }
//-----------------------------------------------------------------------------------------------------------------------
//void ProgramView::saveSettings(KConfig *cfg) { }
//-----------------------------------------------------------------------------------------------------------------------
bool ProgramView::rebuild()
{
      Program *program;
      QString start, first;

      updateDesc();
      saveSelection();
      m_lv->clear();
      for(uint i=0; i<m_programs->count(); i++) {
            program = m_programs->at(i);
            if(ProgramMaster::isWithinTimeframe(program, m_parent->prefs()->cb_daystart->currentItem(), m_dates.at(m_date->currentItem()))) {
                  if(first.isEmpty())
                        first = program->startDT().toString("yyyy-MM-dd");
                  start = program->startDT().toString("hh:mm");
                  if(!(program->startDT().toString("yyyy-MM-dd")).contains(first))
                        start += "+";
                  new ProgramItem(m_parent, m_lv, program, start, program->title(), program->duration().toString("h:mm"), program->channel()->customName());
            }
      }
      m_lv->sort();
      if(!refresh())
            return(false);
      restoreSelection();
      updateDesc();
      return(true);
}
//-----------------------------------------------------------------------------------------------------------------------
void ProgramView::filter(ProgramItem *pi)
{
      BaseView::filter(pi);
      if(pi->isVisible())
            hideNonFavs(pi);
}
//-----------------------------------------------------------------------------------------------------------------------
void ProgramView::showPopupMenu(KListView*, QListViewItem *item, const QPoint&)
{
      KPopupMenu *programMenu = new KPopupMenu(m_parent);
      FavouriteMaster *favouriteMaster = m_parent->favouriteMaster();
      BlistMaster *blistMaster = m_parent->blistMaster();
      Program *program = NULL;

      if(item) program = ((ProgramItem*)item)->program();

      if(program && favouriteMaster->isFavourite(program->title())) {
            programMenu->insertItem(i18n("Remove from Favourites"), favouriteMaster, SLOT(removeFavourite()), Key_Space);
      } else {
            int a = programMenu->insertItem(i18n("Add to Favourites"), favouriteMaster, SLOT(addFavourite()), Key_Space);
            programMenu->setItemEnabled(a, (item?true:false));
      }
      programMenu->insertSeparator();
      int b = programMenu->insertItem(i18n("Blacklist"), blistMaster, SLOT(addBlacklist()), CTRL+Key_B);
      programMenu->setItemEnabled(b, (item?true:false));
      programMenu->insertSeparator();
      
      programMenu->setCheckable(true);
      int h = programMenu->insertItem(i18n("Hide Past"), this, SLOT(toggleHidePast()), CTRL+Key_H);
      int f = programMenu->insertItem(i18n("Favourites Only"), this, SLOT(toggleFavsOnly()), CTRL+Key_F);
      programMenu->setItemChecked(h, m_hidePast);
      programMenu->setItemChecked(f, m_favsOnly);
      programMenu->insertSeparator();
      int d = programMenu->insertItem(i18n("Day View..."), m_parent, SLOT(setView(int)), Key_F1, 0);
      programMenu->insertItem(i18n("Full View..."), m_parent, SLOT(setView(int)), Key_F2, 2);
      programMenu->insertItem(i18n("Search View..."), m_parent, SLOT(setView(int)), Key_F3, 1);
      programMenu->setItemEnabled(d, false);
      programMenu->insertSeparator();
      int fo = programMenu->insertItem(i18n("Forum..."), m_parent, SLOT(setView(int)), Key_F4, 3);
      programMenu->setItemEnabled(fo, (item?true:false));

      programMenu->exec(QCursor::pos());

      delete programMenu;
}
//-----------------------------------------------------------------------------------------------------------------------
void ProgramView::yesterdayClicked()
{
      if(m_date->currentItem() > 0)
            m_date->setCurrentItem(m_date->currentItem()-1);
      rebuild();
}
//-----------------------------------------------------------------------------------------------------------------------
void ProgramView::todayClicked()
{
      m_date->setCurrentItem(m_todayIdx);
      rebuild();
}
//-----------------------------------------------------------------------------------------------------------------------
void ProgramView::tomorrowClicked()
{
      if(m_date->count() > m_date->currentItem()-1)
            m_date->setCurrentItem(m_date->currentItem()+1);
      rebuild();
}
//-----------------------------------------------------------------------------------------------------------------------
void ProgramView::aboutToShow()
{
      updateDesc();
      if(!refresh())
            rebuild();
}
//-----------------------------------------------------------------------------------------------------------------------
void ProgramView::rebuildCBDates()
{
      QDate today(QDate::currentDate()), qdate;
      QStringList dates;
      QString date;
      int currIdx = m_date->currentItem();
      m_todayIdx = 0;

      m_date->clear();
      m_dates.clear();
      if(!m_programs->count()) return;

      for(uint i=0; i<m_programs->count(); i++) {
            date = (m_programs->at(i)->start()).left(8);
            if((dates.grep(date, false)).isEmpty()) {
                  dates.append(date);
                  qdate.setYMD(date.left(4).toInt(), date.right(4).left(2).toInt(), date.right(2).toInt());
                  m_dates.append(new QDate(qdate));
                  if(qdate == today.addDays(-1))
                        m_date->insertItem(qdate.toString("  dddd") + " " + i18n("(yesterday)"));
                  else if(qdate == today) {
                        m_date->insertItem(qdate.toString("  dddd") + " " + i18n("(today)"));
                        m_todayIdx = (int)m_dates.count()-1;
                  } else if(qdate == today.addDays(1))
                        m_date->insertItem(qdate.toString("  dddd") + " " + i18n("(tomorrow)"));
                  else
                        m_date->insertItem(qdate.toString("  dddd") + " " + QString::number(qdate.day())
                              + " (" + (qdate>today?"+":"") + QString::number(today.daysTo(qdate)) + ")");
            }
      }
      if(currIdx <= 0)
            m_date->setCurrentItem(m_todayIdx);
      else
            m_date->setCurrentItem(currIdx);
}
//-----------------------------------------------------------------------------------------------------------------------
void ProgramView::daystartPassed()
{
      QDate today(QDate::currentDate()), selDate(*m_dates.at(m_date->currentItem()));

      if(today.daysTo(selDate) == -1)
            tomorrowClicked();
}
//-----------------------------------------------------------------------------------------------------------------------

Generated by  Doxygen 1.6.0   Back to index