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

📄 downloadui.cpp

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

    Portions Copyright (C) 1999 EMusic.com

    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: downloadui.cpp,v 1.28 2001/01/18 17:30:55 ijr Exp $
____________________________________________________________________________*/

/* system headers */
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <stdio.h>
#include <math.h>

#include <string>
#include <iostream>
#include <sstream>

using namespace std;

/* project headers */
#include "config.h"
#include "thread.h"
#include "downloadui.h"
#include "event.h"
#include "eventdata.h"
#include "playlist.h"
#include "errors.h"
#include "help.h"
#include "resource.h"
#include "utility.h"
#include "debug.h"

static const int32 kProgressHeight = 8;
static const int32 kProgressWidth = 7;

static const int32 kPrePadding = 4;
static const int32 kElementPadding = 5;
static const int32 kPostPadding = 5;
static const int32 kMinProgressWidth = 3;
static const int32 kTotalPadding = kPrePadding + kElementPadding + kPostPadding;

static const char *szEMusicText = 
   "The Download Manager enables you to download music from the downloadable "
   "page at the EMusic site and other sites that support RMP/"
   "RealJukebox downloads.";
static const char *szEMusicURLText = "Go to your EMusic Collection page";
static const char *szEMusicURL = "https://secure.emusic.com/perl/secure/downloadables.pl";

static const char *szFreeAmpText = 
   "The Download Manager enables you to download music from sites that "
   "support the RMP or RealJukebox download format. To try it check "
   "out the free music at:";
   
static const char *szFreeAmpURLText = "http://www.emusic.com/music/free.html";
static const char *szFreeAmpURL = "http://www.emusic.com/music/free.html";

HINSTANCE g_hInstance = NULL;

BOOL CALLBACK MainProc( HWND hwnd, 
                        UINT msg, 
                        WPARAM wParam, 
                        LPARAM lParam ); 

LRESULT WINAPI 
ProgressWndProc(HWND hwnd, 
                UINT msg, 
                WPARAM wParam, 
                LPARAM lParam);

LRESULT WINAPI 
FreeTracksWndProc(HWND hwnd, 
                  UINT msg, 
                  WPARAM wParam, 
                  LPARAM lParam);
LRESULT WINAPI 
ListWndProc(HWND hwnd, 
            UINT msg, 
            WPARAM wParam, 
            LPARAM lParam);

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

INT WINAPI DllMain (HINSTANCE hInst,
                    ULONG ul_reason_being_called,
                    LPVOID lpReserved)
{
    switch (ul_reason_being_called)
    {
        case DLL_PROCESS_ATTACH:
            g_hInstance = hInst;
            break;

        case DLL_THREAD_ATTACH:
            break;

        case DLL_THREAD_DETACH:
            break;

        case DLL_PROCESS_DETACH:
            break;
    }

    return 1;                 
}


DownloadUI::DownloadUI(FAContext *context):UserInterface()
{
    m_context = context;
    m_prefs = context->prefs;
    m_plm = m_context->plm;
    m_target = m_context->target;
    m_propManager = m_context->props;
    m_dlm = m_context->downloadManager;
    m_overURL = false;
    m_duringUpdate = false;

    m_totalItems = 0;
    m_doneItems = 0;
    m_totalBytes = 0;
    m_doneBytes = 0;

    m_uiSemaphore = new Semaphore();

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

    m_progressBitmap = NULL;

    m_uiSemaphore->Wait();
}

DownloadUI::~DownloadUI()
{
    if(m_progressBitmap)
        DeleteObject(m_progressBitmap);

    if(m_handCursor)
        DestroyCursor(m_handCursor);

    delete m_uiSemaphore;
    delete m_uiThread;
}

Error DownloadUI::AcceptEvent(Event* event)
{
    Error result = kError_UnknownErr;

    if(event) 
    {
        switch(event->Type()) 
        {
            case CMD_Cleanup: 
            {
                LV_ITEM item;
                
                if (m_hwndList)
                {
                    uint32 itemCount = ListView_GetItemCount(m_hwndList);
                    for(uint32 i = 0; i < itemCount; i++)
                    {
                        item.mask = LVIF_PARAM;
                        item.iItem = i;
                        item.lParam = 0;

                        if(ListView_GetItem(m_hwndList, &item))
                        {
                            DownloadItem* dli = (DownloadItem*)item.lParam;

                            if(dli->GetState() == kDownloadItemState_Downloading)
                            {
                                m_dlm->CancelDownload(dli, true);  
                            }
                        }
                    }
                }

                PostMessage(m_hwnd, WM_QUIT, 0, 0);
                m_uiThread->Join();
                
                m_target->AcceptEvent(new Event(INFO_ReadyToDieUI));
                break; 
            }

            case CMD_ToggleDownloadUI:
            {
                BOOL visible = IsWindowVisible(m_hwnd);
                ShowWindow(m_hwnd, (visible ? SW_HIDE: SW_SHOW));

                if(!visible)
                    SetForegroundWindow(m_hwnd);
                
                break;
            }
            
            case INFO_DownloadItemAdded: 
            {
                DownloadItemAddedEvent* dliae = (DownloadItemAddedEvent*)event;
                
                LV_ITEM item;
               
                item.mask = LVIF_PARAM | LVIF_STATE;
                item.state = 0;
                item.stateMask = 0;
                item.iItem = ListView_GetItemCount(m_hwndList);
                item.iSubItem = 0;
                item.lParam = (LPARAM)dliae->Item();

                ListView_InsertItem(m_hwndList, &item);

                UpdateOverallProgress();

                // bring window into view
                ShowWindow(m_hwnd, SW_SHOW);
                SetForegroundWindow(m_hwnd);

                if (m_dlm->IsPaused())
                   m_dlm->ResumeDownloads();
               
                break; 
            }

            case INFO_DownloadItemRemoved: 
            {
                DownloadItemRemovedEvent* dlire = (DownloadItemRemovedEvent*)event;

                uint32 itemCount = ListView_GetItemCount(m_hwndList);

                if(itemCount)
                {
                    LV_ITEM item;

                    for(uint32 i = 0; i < itemCount; i++)
                    {
                        item.mask = LVIF_PARAM;
                        item.iItem = i;
                        item.lParam = 0;

                        if(ListView_GetItem(m_hwndList, &item))
                        {
                            if(dlire->Item() == (DownloadItem*)item.lParam)
                            {
                                ListView_RedrawItems(m_hwndList, i, i);
                                UpdateWindow(m_hwndList);
                                break;
                            }
                        }
                    }
                }

                UpdateOverallProgress();

                break; 
            }

            case INFO_DownloadItemNewState: 
            {
                DownloadItemNewStateEvent* dlinse = (DownloadItemNewStateEvent*)event;

                uint32 itemCount = ListView_GetItemCount(m_hwndList);

                if(itemCount)
                {
                    LV_ITEM item;

                    for(uint32 i = 0; i < itemCount; i++)
                    {
                        item.mask = LVIF_PARAM;
                        item.iItem = i;
                        item.lParam = 0;

                        if(ListView_GetItem(m_hwndList, &item))
                        {
                            if(dlinse->Item() == (DownloadItem*)item.lParam)
                            {
                                if (dlinse->Item()->GetState() == 
                                    kDownloadItemState_Downloading)
                                {    
                                    SetButtonStates(dlinse->Item());
                                    ListView_SetItemState(m_hwndList, i, 
                                        LVIS_SELECTED | LVIS_FOCUSED, 
                                        LVIS_SELECTED | LVIS_FOCUSED);
                                    ListView_EnsureVisible(m_hwndList, i, false);
                                }    
                            
                                ListView_RedrawItems(m_hwndList, i, i);
                                UpdateWindow(m_hwndList);
                                break;
                            }
                        }
                    }
                }

                UpdateOverallProgress();

                break; 
            }

            case INFO_DownloadItemProgress: 
            {
                DownloadItemProgressEvent* dlipe = (DownloadItemProgressEvent*)event;

                uint32 itemCount = ListView_GetItemCount(m_hwndList);

                if(itemCount)
                {
                    LV_ITEM item;

                    for(uint32 i = 0; i < itemCount; i++)
                    {
                        item.mask = LVIF_PARAM;
                        item.iItem = i;
                        item.lParam = 0;

                        if(ListView_GetItem(m_hwndList, &item))
                        {
                            if(dlipe->Item() == (DownloadItem*)item.lParam)
                            {
                                m_duringUpdate = true;
                                ListView_RedrawItems(m_hwndList, i, i);
                                UpdateWindow(m_hwndList);
                                m_duringUpdate = false;
                                break;
                            }
                        }
                    }
                }

                UpdateOverallProgress();

                break; 
            }
            
            default:
                break;
        }

        result = kError_NoErr;

    } 

    return result;
}

void DownloadUI::ParseArgs(int32 argc, char** argv)
{
    /*
    char *arg = NULL;
    int32 count = 0;

    for(int32 i = 1;i < argc; i++) 
    {
        arg = argv[i];

        if(arg[0] == '-') 
        {
            switch(arg[1]) 
            {
                
            }
        }
       
    }
    */
}

void DownloadUI::CreateUI()
{
    InitCommonControls();

    HWND hwnd;
    MSG msg;

    hwnd = CreateDialogParam( g_hInstance, 
                    MAKEINTRESOURCE(IDD_DIALOG),
                    NULL,
                    MainProc, 
                    (LPARAM)this);

    while(GetMessage(&msg,NULL,0,0))
    {
        if(hwnd)
        {
            IsDialogMessage(hwnd, &msg);
        }
    }
    ImageList_Destroy(m_noteImage);
    DestroyWindow(hwnd);
    m_hwnd = NULL;
    m_hwndList = NULL;

    m_target->AcceptEvent(new Event(CMD_QuitPlayer));
}

⌨️ 快捷键说明

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