📄 oggplayappview.cpp
字号:
/*
* Copyright (c) 2003 L. H. Wilden.
*
* 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 <OggOs.h>
#include "OggPlayAppView.h"
#include "OggLog.h"
#include "OggHelperFcts.h"
#include <eikclb.h> // CEikColumnListbox
#include <eikclbd.h> // CEikColumnListBoxData
#include <eiktxlbm.h> // CEikTextListBox(Model)
#include <eikmenub.h> // CEikMenuBar
#include <apgtask.h> // TApaTask
#ifdef SERIES60
#include <aknkeylock.h>
#include <aknquerydialog.h>
#endif
#ifdef SERIES80
#include <eikenv.h>
#endif
#ifdef UIQ
#include <quartzkeys.h> // EStdQuartzKeyConfirm etc.
#endif
#include "OggAbsPlayback.h"
// Time (usecs) between canvas Refresh() for graphics updating
const TInt KCallBackPeriod = 71429; // 14Hz
const TInt KOggControlFreq = 14;
// Literal for clock update
_LIT(KDateString, "%-B%:0%J%:1%T%:3%+B");
// Array of times for snooze
const TInt KSnoozeTime[4] = { 5, 10, 20, 30 };
COggPlayAppView::COggPlayAppView()
: iPosChanged(-1), iFocusControlsPresent(EFalse), iFocusControlsHeader(_FOFF(COggControl, iDlink)),
iFocusControlsIter(iFocusControlsHeader), iCycleFrequencyCounter(KOggControlFreq)
{
}
COggPlayAppView::~COggPlayAppView()
{
if (iControls)
iControls->Reset();
delete iControls;
delete iTextArray;
ClearCanvases();
if (iTimer)
iTimer->Cancel();
delete iTimer;
delete iCallBack;
if (iAlarmTimer)
iAlarmTimer->Cancel();
delete iAlarmTimer;
delete iAlarmCallBack;
delete iAlarmErrorCallBack;
delete iCanvas[1];
delete iCanvas[0];
delete iOggFiles;
}
void
COggPlayAppView::ConstructL(COggPlayAppUi *aApp, const TRect& aRect)
{
iTextArray = new(ELeave) CDesCArrayFlat(10);
iApp = aApp;
CreateWindowL();
SetRect(aRect);
SetComponentsToInheritVisibility(EFalse);
iOggFiles= new(ELeave) TOggFiles(iApp->iOggPlayback);
iControls = new(ELeave)CArrayPtrFlat<CCoeControl>(10);
// Construct the two canvases for flip-open and closed mode
// Flip-open mode:
iCanvas[0]= new(ELeave) COggCanvas;
iControls->AppendL(iCanvas[0]);
iCanvas[0]->SetContainerWindowL(*this);
iCanvas[0]->SetControlContext(this);
iCanvas[0]->SetObserver(this);
// This must be fixed at some point.
// Can't we just do set to full screen!?
// We have to support landscape too...
#if defined(SERIES90)
iCanvas[0]->SetExtent(TPoint(0, 0), TSize(640, 320));
#elif defined(SERIES80)
iCanvas[0]->SetExtent(TPoint(0, 0), TSize(640, 200));
#elif defined(SERIES60)
TPoint pBM(Position());
pBM.iY= 0;
if (CCoeEnv::Static()->ScreenDevice()->SizeInPixels() == TSize(352, 416))
iCanvas[0]->SetExtent(pBM, TSize(352, 376));
else if (CCoeEnv::Static()->ScreenDevice()->SizeInPixels() == TSize(240, 320))
iCanvas[0]->SetExtent(pBM, TSize(240, 293));
else if (CCoeEnv::Static()->ScreenDevice()->SizeInPixels() == TSize(320, 240))
iCanvas[0]->SetExtent(pBM, TSize(320, 220));
else if (CCoeEnv::Static()->ScreenDevice()->SizeInPixels() == TSize(208, 208))
iCanvas[0]->SetExtent(pBM, TSize(208, 188));
else
iCanvas[0]->SetExtent(pBM, TSize(176, 188));
#else
TPoint pBM(Position());
pBM.iY= 0;
iCanvas[0]->SetExtent(pBM, TSize(208, 320));
#endif
// Flip-closed mode:
#if defined(UIQ)
iCanvas[1]= new(ELeave) COggCanvas;
iControls->AppendL(iCanvas[1]);
iCanvas[1]->SetContainerWindowL(*this);
iCanvas[1]->SetControlContext(this);
iCanvas[1]->SetObserver(this);
pBM.iY= 0;
iCanvas[1]->SetExtent(pBM, TSize(208,208));
#endif
// Set up all the other components:
// Create the canvas refresh timer (KCallBackPeriod):
iTimer = CPeriodic::NewL(CActive::EPriorityStandard);
iCallBack = new(ELeave) TCallBack(COggPlayAppView::CallBack, this);
iAlarmCallBack = new(ELeave) TCallBack(COggPlayAppView::AlarmCallBack, this);
iAlarmErrorCallBack = new(ELeave) TCallBack(COggPlayAppView::AlarmErrorCallBack, this);
iAlarmTimer = new(ELeave) COggTimer(*iAlarmCallBack, *iAlarmErrorCallBack);
// Activate the view
ActivateL();
}
void
COggPlayAppView::ReadSkin(const TFileName& aFileName)
{
ClearCanvases();
ResetControls();
iIconFileName= aFileName.Left(aFileName.Length()-4);
iIconFileName.Append(_L(".mbm"));
#if defined(SERIES60) || defined(SERIES80) || defined(SERIES90)
TInt scaleFactor = iCanvas[0]->LoadBackgroundBitmapL(iIconFileName, 19);
TOggParser p(iCoeEnv->FsSession(), aFileName, scaleFactor);
#else
iCanvas[0]->LoadBackgroundBitmapL(iIconFileName, 19);
iCanvas[1]->LoadBackgroundBitmapL(iIconFileName, 18);
TOggParser p(iCoeEnv->FsSession(), aFileName);
#endif
if (p.iState!=TOggParser::ESuccess) {
p.ReportError();
User::Leave(-1);
return;
}
if (!p.ReadHeader()) {
p.ReportError();
User::Leave(-1);
return;
}
p.ReadToken();
if (p.iToken!=_L("FlipOpen")) {
p.iState= TOggParser::EFlipOpenExpected;
p.ReportError();
User::Leave(-1);
return;
}
p.ReadToken();
if (p.iToken!=KBeginToken) {
p.iState= TOggParser::EBeginExpected;
p.ReportError();
User::Leave(-1);
return;
}
ReadCanvas(0,p);
if (p.iState!=TOggParser::ESuccess) {
p.ReportError();
User::Leave(-1);
return;
}
p.ReadToken();
if (p.iToken==_L("FlipClosed")) {
p.ReadToken();
if (p.iToken!=KBeginToken) {
p.iState= TOggParser::EBeginExpected;
p.ReportError();
User::Leave(-1);
return;
}
ReadCanvas(1,p);
if (p.iState!=TOggParser::ESuccess) {
p.ReportError();
User::Leave(-1);
return;
}
}
iFocusControlsIter.SetToFirst();
COggControl* c=iFocusControlsIter;
if(c) c->SetFocus(ETrue);
if (iListBox[iMode])
iSelected = iListBox[iMode]->SetCurrentItemIndex(iSelected);
}
void
COggPlayAppView::ResetControls() {
iClock[0]= 0; iClock[1]= 0;
iAlarm[0]= 0; iAlarm[1]= 0;
iAlarmIcon[0]=0; iAlarmIcon[1]= 0;
iPlayed[0]= 0; iPlayed[1]= 0;
iPlayedDigits[0]= 0; iPlayedDigits[1]= 0;
iTotalDigits[0]= 0; iTotalDigits[1]= 0;
iPaused[0]= 0; iPaused[1]= 0;
iPlaying[0]= 0; iPlaying[1]= 0;
iPlayButton[0]= 0; iPlayButton[1]=0;
iPauseButton[0]= 0; iPauseButton[1]= 0;
iPlayButton2[0]= 0; iPlayButton2[1]=0;
iPauseButton2[0]= 0; iPauseButton2[1]= 0;
iStopButton[0]=0; iStopButton[1]= 0;
iNextSongButton[0]= 0; iNextSongButton[1]= 0;
iPrevSongButton[0]= 0; iPrevSongButton[1]= 0;
iListBox[0]=0; iListBox[1]= 0;
iTitle[0]=0; iTitle[1]= 0;
iAlbum[0]=0; iAlbum[1]= 0;
iArtist[0]=0; iArtist[1]= 0;
iGenre[0]=0; iGenre[1]= 0;
iTrackNumber[0]=0; iTrackNumber[1]= 0;
iFileName[0]=0; iFileName[1]= 0;
iPosition[0]= 0; iPosition[1]= 0;
iVolume[0]= 0; iVolume[1]= 0;
iAnalyzer[0]= 0; iAnalyzer[1]= 0;
iRepeatIcon[0]= 0; iRepeatIcon[1]= 0;
iRepeatButton[0]= 0; iRepeatButton[1]= 0;
iRandomIcon[0]=0; iRandomIcon[1]=0;
iRandomButton[0]=0; iRandomButton[1]=0;
iScrollBar[0]= 0; iScrollBar[1]= 0;
iAnimation[0]= 0; iAnimation[1]= 0;
iLogo[0]= 0; iLogo[1]= 0;
}
void
COggPlayAppView::ClearCanvases()
{
COggControl* oggControl;
iFocusControlsIter.SetToFirst();
while ((oggControl = iFocusControlsIter++) != NULL)
{
oggControl->iDlink.Deque();
}
if (iCanvas[0])
iCanvas[0]->ClearControls();
#if defined(UIQ)
if (iCanvas[1])
iCanvas[1]->ClearControls();
#endif
}
void
COggPlayAppView::ReadCanvas(TInt aCanvas, TOggParser& p)
{
CFont* iFont= const_cast<CFont*>(iCoeEnv->NormalFont());
iFocusControlsPresent=EFalse;
bool stop(EFalse);
while (!stop) {
stop= !p.ReadToken() || p.iToken==KEndToken;
COggControl* c=NULL;
if (p.iToken==_L("Clock")) {
_LIT(KAL,"Adding Clock");
// RDebug::Print(KAL);
p.Debug(KAL);
c= new(ELeave) COggText();
iClock[aCanvas]= (COggText*)c;
iClock[aCanvas]->SetFont(iFont);
}
else if (p.iToken==_L("Alarm")) {
_LIT(KAL,"Adding Alarm");
// RDebug::Print(KAL);
p.Debug(KAL);
c= new(ELeave) COggText();
iAlarm[aCanvas]= (COggText*)c;
iAlarm[aCanvas]->SetFont(iFont);
}
else if (p.iToken==_L("Title")) {
_LIT(KAL,"Adding Title");
// RDebug::Print(KAL);
p.Debug(KAL);
c= new(ELeave) COggText();
iTitle[aCanvas]= (COggText*)c;
iTitle[aCanvas]->SetFont(iFont);
}
else if (p.iToken==_L("Album")) {
_LIT(KAL,"Adding Album");
// RDebug::Print(KAL);
p.Debug(KAL);
c= new(ELeave) COggText();
iAlbum[aCanvas]= (COggText*)c;
iAlbum[aCanvas]->SetFont(iFont);
}
else if (p.iToken==_L("Artist")) {
_LIT(KAL,"Adding Artist");
// RDebug::Print(KAL);
p.Debug(KAL);
c= new(ELeave) COggText();
iArtist[aCanvas]= (COggText*)c;
iArtist[aCanvas]->SetFont(iFont);
}
else if (p.iToken==_L("Genre")) {
_LIT(KAL,"Adding Genre");
// RDebug::Print(KAL);
p.Debug(KAL);
c= new(ELeave) COggText();
iGenre[aCanvas]= (COggText*)c;
iGenre[aCanvas]->SetFont(iFont);
}
else if (p.iToken==_L("TrackNumber")) {
_LIT(KAL,"Adding TrackNumber");
// RDebug::Print(KAL);
p.Debug(KAL);
c= new(ELeave) COggText();
iTrackNumber[aCanvas]= (COggText*)c;
iTrackNumber[aCanvas]->SetFont(iFont);
}
else if (p.iToken==_L("FileName")) {
c= new COggText();
_LIT(KAL,"Adding FileName");
// RDebug::Print(KAL);
p.Debug(KAL);
iFileName[aCanvas]= (COggText*)c;
iFileName[aCanvas]->SetFont(iFont);
}
else if (p.iToken==_L("Played")) {
_LIT(KAL,"Adding Played");
// RDebug::Print(KAL);
p.Debug(KAL);
c= new(ELeave) COggText();
iPlayed[aCanvas]= (COggText*)c;
iPlayed[aCanvas]->SetFont(iFont);
#if defined(UIQ)
iPlayed[aCanvas]->SetText(_L("00:00 / 00:00"));
#endif
}
else if (p.iToken==_L("PlayedDigits")) {
c= new COggDigits;
iPlayedDigits[aCanvas]= (COggDigits*)c;
}
else if (p.iToken==_L("TotalDigits")) {
c= new COggDigits;
iTotalDigits[aCanvas]= (COggDigits*)c;
}
else if (p.iToken==_L("StopButton")) {
c= new(ELeave) COggButton();
// _LIT(KAL,"Adding StopButton at 0x%x");
// RDebug::Print(KAL,c);
//OGGLOG.WriteFormat(KAL,c);
iStopButton[aCanvas]= (COggButton*)c;
}
else if (p.iToken==_L("PlayButton")) {
_LIT(KAL,"Adding PlayButton");
// RDebug::Print(KAL);
p.Debug(KAL);
c= new(ELeave) COggButton();
iPlayButton[aCanvas]= (COggButton*)c;
}
else if (p.iToken==_L("PauseButton")) {
_LIT(KAL,"Adding PauseButton");
// RDebug::Print(KAL);
p.Debug(KAL);
c= new(ELeave) COggButton();
iPauseButton[aCanvas]= (COggButton*)c;
iPauseButton[aCanvas]->MakeVisible(EFalse);
}
else if (p.iToken==_L("PlayButton2")) {
c= new COggButton();
iPlayButton2[aCanvas]= (COggButton*)c;
}
else if (p.iToken==_L("PauseButton2")) {
c= new COggButton();
iPauseButton2[aCanvas]= (COggButton*)c;
}
else if (p.iToken==_L("NextSongButton")) {
c= new COggButton();
iNextSongButton[aCanvas]= (COggButton*)c;
}
else if (p.iToken==_L("PrevSongButton")) {
c= new COggButton();
iPrevSongButton[aCanvas]= (COggButton*)c;
}
else if (p.iToken==_L("PlayingIcon")) {
_LIT(KAL,"Adding PlayingIcon");
// RDebug::Print(KAL);
p.Debug(KAL);
c= new(ELeave) COggIcon();
iPlaying[aCanvas]= (COggIcon*)c;
}
else if (p.iToken==_L("PausedIcon")) {
_LIT(KAL,"Adding PausedIcon");
// RDebug::Print(KAL);
p.Debug(KAL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -