⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 freeamptheme.cpp

📁 FreeAMP(MP3播放)程序源代码-用来研究MP3解码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*____________________________________________________________________________
        
   FreeAmp - The Free MP3 Player

   Copyright (C) 1999 EMusic.com
   Portions Copyright (C) 1999 Valters Vingolds

   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., 675 Mass Ave, Cambridge, MA 02139, USA.
        
   $Id: FreeAmpTheme.cpp,v 1.160 2001/01/24 20:47:24 ijr Exp $
____________________________________________________________________________*/

// The debugger can't handle symbols more than 255 characters long.
// STL often creates symbols longer than that.
// When symbols are longer than 255 characters, the warning is disabled.
#ifdef WIN32
#pragma warning(disable:4786) 
#endif

#include <stdio.h> 
#include <sys/types.h>
#include <sys/stat.h>
#ifndef WIN32
#include <unistd.h>
#define _stat stat
#ifndef _S_IFDIR
#define _S_IFDIR S_IFDIR
#endif
#endif
#if defined(WIN32)
#define STRICT
#endif
#include "config.h"
#include "downloadmanager.h"

#ifdef __QNX__
#include <strings.h>
#endif

#ifdef HAVE_GTK
#include "GTKUtility.h"
#include "GTKPreferenceWindow.h"
#elif defined(WIN32)
#include "Win32Window.h"
#include "Win32PreferenceWindow.h"
#include "win32updatemanager.h"
#include "resource.h"
extern HINSTANCE g_hinst;
#elif defined(__BEOS__)
#include "BeOSPreferenceWindow.h"
#include "win32impl.h"
#endif

#include "FreeAmpTheme.h"
#include "MessageDialog.h"
#include "eventdata.h"
#include "event.h"
#include "debug.h"
#include "PreferenceWindow.h"
#include "playlist.h"
#include "player.h"
#include "help.h"
#include "properties.h"
#include "missingfile.h"
#include "utility.h"

void WorkerThreadStart(void* arg);

#define DB Debug_v("%s:%d\n", __FILE__, __LINE__);

const char *szWelcomeMsg = "Welcome to "the_BRANDING"!";
const char *szParseError = "Parsing the Theme description failed. Cause: ";
const char *szCantFindHelpError = "Cannot find the help files. Please make "
                                  "sure that the help files are properly "
                                  "installed, and you are not running "
                                  the_BRANDING" from the build directory.";
const char *szKeepThemeMessage = "Would you like to keep this theme?";

struct OptionsArgs
{
   FreeAmpTheme *pThis;
   uint32        uDefaultPage;
}; 

extern    "C"
{
   UserInterface *Initialize(FAContext * context)
   {
      return new FreeAmpTheme(context);
   }
}

FreeAmpTheme::FreeAmpTheme(FAContext * context)
             :Theme(context)
{
   char   szTemp[255];
   uint32 iLen = 255;
   
   m_pContext = context;
   m_iCurrentSeconds = 0;
   m_iTotalSeconds = -1;
   m_iSeekSeconds = 0;
   m_bSeekInProgress = false;
   m_bVolumeChangeInProgress = false;
   m_iVolume = -1;
   m_iBalance = -1;
   m_iSeekPos = -1;
   m_iMuteVolume = -1;
   m_bPlayShown = true;
   m_oTitle = string("");
   m_eTimeDisplayState = kNormal;
   m_eTitleDisplayState = kNameArtist;
   m_oStreamInfo = string("");
   m_pUpdateMan = NULL;
   m_pUpdateThread = NULL;
   m_pOptionsThread = NULL;
   m_bInOptions = false;
   m_bShowBuffers = m_bPaused = m_bBufferingUp = false;
   m_iFramesSinceSeek = 2;
   m_fSecondsPerFrame = 0;
   m_sigState = kIdle;

   m_eq = new Equalizer(context);
   m_eq->LoadSettings();

#if defined( WIN32 )
    m_pUpdateMan = new Win32UpdateManager(m_pContext);
    m_pUpdateMan->DetermineLocalVersions();
    m_pUpdateMan->SetPlatform(string("WIN32"));
#if defined( _M_ALPHA )
     m_pUpdateMan->SetArchitecture(string("ALPHA"));
#else
     m_pUpdateMan->SetArchitecture(string("X86"));
#endif // _M_ALPHA

#endif // WIN32

   m_pContext->prefs->GetPrefString(kWindowModePref, szTemp, &iLen);
   if (iLen > 0)
      m_oCurrentWindow = string(szTemp);
   else   
      m_oCurrentWindow = string("MainWindow");

   LoadFreeAmpTheme();

}

FreeAmpTheme::~FreeAmpTheme()
{

    if (m_eq)
    {
        m_eq->SaveSettings();
        delete m_eq;
        m_eq = NULL;
    }
    if (m_pOptionsThread)
    {  
        delete m_pOptionsThread;
        m_pOptionsThread = NULL;
    }
#if defined( WIN32 )
    delete m_pUpdateMan;
#endif // WIN32
}

Error FreeAmpTheme::Init(int32 startup_type)
{
    assert(this);

    m_iStartupType = startup_type;

    m_uiThread = Thread::CreateThread();
    m_uiThread->Create(WorkerThreadStart, this);

    return kError_NoErr;
}

void FreeAmpTheme::WorkerThread(void)
{
    char   szTemp[255];
    uint32 iLen = 255;
    Error  eRet;
    int32  iValue;

    m_pContext->prefs->GetPrefInt32(kTimeDisplayPref, &iValue);
    if (iValue)
       m_eTimeDisplayState = kTimeRemaining;
    iValue = -1;
    m_pContext->prefs->GetPrefInt32(kMetadataDisplayPref, &iValue);
    if (iValue < 0)
       iValue = 1;
    m_eTitleDisplayState = (TitleDisplayState)iValue;
    
    m_pContext->prefs->GetPrefString(kMainWindowPosPref, szTemp, &iLen);
    sscanf(szTemp, " %d , %d", &m_oWindowPos.x, &m_oWindowPos.y);

#ifdef WIN32

    bool checkForUpdates = false;

    m_pContext->prefs->GetPrefBoolean(kCheckForUpdatesPref, &checkForUpdates);

    if(checkForUpdates)
    {
        m_pUpdateThread = Thread::CreateThread();
        m_pUpdateThread->Create(update_thread, this);
    }

#endif

    eRet = Theme::Run(m_oWindowPos);
    if (!IsError(eRet))
    {
       sprintf(szTemp, "%d,%d", m_oWindowPos.x, m_oWindowPos.y);
       m_pContext->prefs->SetPrefString(kMainWindowPosPref, szTemp);
       m_pContext->prefs->SetPrefString(kWindowModePref, m_oCurrentWindow.c_str());
    }
    else     
       m_pContext->target->AcceptEvent(new Event(CMD_QuitPlayer));
   
    m_pContext->prefs->SetPrefInt32(kTimeDisplayPref, 
                                    m_eTimeDisplayState == kTimeRemaining);
    m_pContext->prefs->SetPrefInt32(kMetadataDisplayPref, 
                                    (int)m_eTitleDisplayState);
}

void WorkerThreadStart(void* arg)
{
    FreeAmpTheme* ui = (FreeAmpTheme*)arg;
    ui->WorkerThread();
}

void FreeAmpTheme::LoadFreeAmpTheme(void)
{
   char    *szTemp;
   uint32   iLen = 255;
   string   oThemePath("");
   Error    eRet;
   struct  _stat buf;

   szTemp = new char[iLen];
   m_pContext->prefs->GetPrefString(kThemePathPref, szTemp, &iLen);

    if (strlen(szTemp) < 1) 
        strcpy(szTemp, BRANDING_DEFAULT_THEME);
 
   if (_stat(szTemp, &buf) < 0)
   {
      // If the theme doesn't exist, let's try to prepend the install/theme dir
      char   *dir;
      uint32  len = _MAX_PATH;

      dir = new char[_MAX_PATH];
   
      m_pContext->prefs->GetPrefString(kInstallDirPref, dir, &len);
      oThemePath = string(dir);
#if defined(unix)
      oThemePath += string(BRANDING_SHARE_PATH);
#endif
      oThemePath += string(DIR_MARKER_STR);    
      oThemePath += string("themes");
      oThemePath += string(DIR_MARKER_STR);    

      delete [] dir;
   }
   oThemePath += szTemp;
  
   // Save the theme.
   m_themeCache = oThemePath;

   eRet = LoadTheme(oThemePath, m_oCurrentWindow);
   
   if (IsError(eRet) && eRet != kError_InvalidParam)					   
   {
       MessageDialog oBox(m_pContext);
       string        oErr, oMessage(szParseError);

       GetErrorString(oErr);
       oMessage += oErr;
       oBox.Show(oMessage.c_str(), string(BRANDING), kMessageOk);
       m_pContext->target->AcceptEvent(new Event(CMD_QuitPlayer));
   }
   else if (eRet == kError_InvalidParam)
   {
       m_pContext->target->AcceptEvent(new Event(CMD_QuitPlayer));
   }
   else
      m_pContext->prefs->SetPrefString(kThemePathPref, oThemePath.c_str());

   iLen = 255; 
   m_pContext->prefs->GetPrefString(kThemeDefaultFontPref, szTemp, &iLen);
   SetDefaultFont(string(szTemp));
   
   delete [] szTemp;    
}


Error FreeAmpTheme::Close(void)
{
    Theme::Close();
    
    if (!m_uiThread)
       return kError_NoErr;
    
    m_uiThread->Join();
    delete m_uiThread;
    m_uiThread = NULL;

    return kError_NoErr;
}

Error FreeAmpTheme::AcceptEvent(Event * e)
{
   if (m_pWindow && m_pWindow->DisallowOutsideMessages())
      return kError_NoErr;

   switch (e->Type())
   {
      case INFO_ErrorMessage:
      {
         MessageDialog      oBox(m_pContext);
         ErrorMessageEvent *pEvent = (ErrorMessageEvent *)e;
         
         string oDesc(pEvent->GetErrorMessage());
  
         oBox.Show(oDesc.c_str(), string(BRANDING), kMessageOk);
         break;
      }
      case INFO_StatusMessage:
      {
         StatusMessageEvent *pEvent = (StatusMessageEvent *)e;
         
         string oDesc(pEvent->GetStatusMessage());
         m_pWindow->ControlStringValue("Info", true, oDesc);
         break;
      }
      case CMD_Cleanup:
      {
         string oName("MainWindow");
      	 Close();
         m_pContext->target->AcceptEvent(new Event(INFO_ReadyToDieUI));
         
         break;
      }   
      case INFO_Playing:
      {
         bool bEnable;
         int  iState;
         
         iState = 1;
         m_pWindow->ControlIntValue(string("PlayPause"), true, iState);
         iState = 1;
         m_pWindow->ControlIntValue(string("PlayStop"), true, iState);
         iState = 0;
         m_pWindow->ControlIntValue(string("MPause"), true, iState);
         bEnable = false;
         m_pWindow->ControlEnable(string("Play"), true, bEnable);
         bEnable = true;
         m_pWindow->ControlEnable(string("Pause"), true, bEnable);
         bEnable = true;
         m_pWindow->ControlEnable(string("Stop"), true, bEnable);
   
         bEnable = true;
         m_pWindow->ControlEnable(string("Volume"), true, bEnable);
         m_pWindow->ControlEnable(string("Mute"), true, bEnable);
         m_pWindow->ControlEnable(string("Balance"), true, bEnable);
         
         bEnable = false;
         m_pWindow->ControlEnable(string("StopIndicator"), true, bEnable);
         m_pWindow->ControlEnable(string("PauseIndicator"), true, bEnable);
         bEnable = true;
         m_pWindow->ControlEnable(string("PlayIndicator"), true, bEnable);

         m_bPlayShown = false;
         m_bPaused = false;
         
         break;
      }   
      case INFO_Paused:
      case INFO_Stopped:
      {
         int iState = 0;
         bool bEnable = true;
         string oEmpty("");
         
         iState = 0;
         m_pWindow->ControlIntValue(string("PlayPause"), true, iState);
         m_bPaused = e->Type() == INFO_Paused;
         iState = e->Type() == INFO_Paused ? 1 : 0;
         m_pWindow->ControlIntValue(string("PlayStop"), true, iState);
         iState = e->Type() == INFO_Paused ? 1 : 0;
         m_pWindow->ControlIntValue(string("MPause"), true, iState);
         bEnable = true;
         m_pWindow->ControlEnable(string("Play"), true, bEnable);
         
         
         bEnable = false;
         m_pWindow->ControlEnable(string("Pause"), true, bEnable);
         bEnable = false;
         m_pWindow->ControlEnable(string("Stop"), true, bEnable);
         m_bPlayShown = true;
         m_pWindow->ControlStringValue("BufferInfo", true, oEmpty);
         m_oStreamInfo = "";
         m_pWindow->ControlStringValue("StreamInfo", true, oEmpty);
         
         if (e->Type() == INFO_Stopped)
         {
            m_iSeekPos = 0;
            m_iTotalSeconds = -1;
            m_iCurrentSeconds = -1;
            m_pWindow->ControlIntValue(string("Seek"), true, m_iSeekPos);
            UpdateTimeDisplay(m_iCurrentSeconds);
            
            if ((int32)m_pContext->plm->GetCurrentIndex() < 0)
            {
                m_oTitle = szWelcomeMsg;
                
                m_pWindow->ControlStringValue("Title", true, m_oTitle);
                
                string title = BRANDING;
                m_pWindow->SetTitle(title);
            }    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -