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

📄 gtkdownloadui.cpp

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

        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: gtkdownloadui.cpp,v 1.16 2000/09/28 08:08:02 ijr Exp $
____________________________________________________________________________*/

#include "config.h"

#include <gtk/gtk.h>
#include <sys/stat.h>
#include <strstream>
#include <iostream>

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

#include "utility.h"
#include "downloadui.h"
#include "help.h"
#include "utility.h"
#include "gtkmessagedialog.h"

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";

void DownloadUI::ToggleVisEvent(void)
{
    m_initialized = false;
    isVisible = false;
    m_currentindex = 0;
}

void toggle_vis_internal(GtkWidget *widget, DownloadUI *p)
{
    p->ToggleVisEvent();
}

void DownloadUI::CloseWindow(void)
{
    bool close = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_closeComplete));
    m_prefs->SetPrefBoolean(kCloseDLMOnCompletePref, close);
    gtk_widget_destroy(m_downloadUI);
}

void close_internal(GtkWidget *widget, DownloadUI *p)
{
    p->CloseWindow();
}

void DownloadUI::UpdateInfo(void)
{
    if (!isVisible)
        return;

    DownloadItem *dli = downloadList[m_currentindex];

    if (!dli) {
        gtk_label_set_text(GTK_LABEL(artist), "");
        gtk_label_set_text(GTK_LABEL(album), "");
        gtk_label_set_text(GTK_LABEL(title), "");
        gtk_label_set_text(GTK_LABEL(genre), "");
        gtk_label_set_text(GTK_LABEL(playlist), "");
        gtk_label_set_text(GTK_LABEL(name), "");
        gtk_label_set_text(GTK_LABEL(size), "");
        return;
    }

    gtk_label_set_text(GTK_LABEL(artist), dli->GetMetaData().Artist().c_str());
    gtk_label_set_text(GTK_LABEL(album), dli->GetMetaData().Album().c_str());
    gtk_label_set_text(GTK_LABEL(title), dli->GetMetaData().Title().c_str());
    gtk_label_set_text(GTK_LABEL(genre), dli->GetMetaData().Genre().c_str());
    gtk_label_set_text(GTK_LABEL(playlist), dli->PlaylistName().c_str());
    gtk_label_set_text(GTK_LABEL(name), dli->DestinationFile().c_str());
    float total;
    char totsize[64];
    
    total = dli->GetTotalBytes();
    if (total >= 1048576) {
        total /= 1048576;
        sprintf(totsize, "%.2f MB", total);;
    }
    else if(total >= 1024) {
        total /= 1024;
        sprintf(totsize, "%.2f KB", total);
    }
    else
        sprintf(totsize, "%.2f Bytes", total);
 
    string display = totsize;

    gtk_label_set_text(GTK_LABEL(size), display.c_str());
}

string DownloadUI::StatusString(DownloadItem *dli)
{
    string statusString;

    switch (dli->GetState()) {
        case kDownloadItemState_Queued: {
            char outtext[128];
            float total;

            total = dli->GetTotalBytes();

            if (total >= 1048576) {
                total /= 1048576;
                sprintf(outtext, "Queued (%.2f MB)", total);
            }
            else if (total >= 1024) {
                total /= 1024;
                sprintf(outtext, "Queued (%.2f KB)", total);
            }
            else
                sprintf(outtext, "Queued (%.2f Bytes)", total);

            statusString = outtext;
            break; }
        case kDownloadItemState_Downloading: {
            float total;
            float recvd;
            uint32 percent;
            char outtext[128];

            total = dli->GetTotalBytes();
            recvd = dli->GetBytesReceived();
            percent = (uint32)(recvd/total*100);

            if (total >= 1048576) {
                total /= 1048576;
                recvd /= 1048576;
                sprintf(outtext, "%d%% (%.2f of %.2f MB)", percent, recvd, total);
            }
            else if(total >= 1024) {
                total /= 1024;
                recvd /= 1024;
                sprintf(outtext, "%d%% (%.2f of %.2f KB)", percent, recvd, total);
            }
            else
                sprintf(outtext, "%d%% (%.2f of %.2f Bytes)", percent, recvd, total);

            statusString = outtext;
            break; }
        case kDownloadItemState_Cancelled: {
            statusString = "Cancelled";
            break; }
        case kDownloadItemState_Paused: {
            char outtext[128];
            float total;
            float recvd;
            uint32 percent;

            total = dli->GetTotalBytes();
            recvd = dli->GetBytesReceived();
            percent = (uint32)(recvd/total*100);

            if (total >= 1048576) {
                total /= 1048576;
                recvd /= 1048576;
                sprintf(outtext, "Paused (%.2f of %.2f MB - %d%%)", recvd, total, percent);
            }
            else if(total >= 1024) {
                total /= 1024;
                recvd /= 1024;
                sprintf(outtext, "Paused (%.2f of %.2f KB - %d%%)", recvd, total, percent);
            }
            else
                sprintf(outtext, "Paused (%.2f of %.2f Bytes - %d%%)", recvd, total, percent);

            statusString = outtext;
            break; }
        case kDownloadItemState_Error: {
            char outtext[1024];
            sprintf(outtext, "Error: %s\n", ErrorString[dli->GetDownloadError()]);
            statusString = outtext;
            break; }
        case kDownloadItemState_Done: {
            statusString = "Download Complete\0";
            break; }
        default:
            break;
    }
    return statusString;
}

void DownloadUI::UpdateDownloadList(void)
{
    if (!m_List || !isVisible)
        return;

    gtk_clist_freeze(GTK_CLIST(m_List));
    gtk_clist_clear(GTK_CLIST(m_List));

    uint32 iLoop = downloadList.size();

    if (iLoop == 0) {
        gtk_clist_thaw(GTK_CLIST(m_List));
        return;
    }

    for (uint32 i = 0; i < iLoop; i++) {
        DownloadItem *dli = downloadList[i];
        char *iText[2];

        string displayString = dli->GetMetaData().Title();

        iText[0] = (char *)displayString.c_str();  
        iText[1] = (char *)StatusString(dli).c_str();

        int row = gtk_clist_append(GTK_CLIST(m_List), iText);
        gtk_clist_set_row_data(GTK_CLIST(m_List), row, (gpointer)dli);
    }

    gtk_clist_select_row(GTK_CLIST(m_List), m_currentindex, 0);
    SelChangeEvent(m_currentindex);
    gtk_clist_thaw(GTK_CLIST(m_List));
}

void DownloadUI::AddItem(DownloadItem *dli)
{
    if (!dli || !m_List || !isVisible)
        return;

    char *iText[2];
    string displayString = dli->GetMetaData().Title();

    iText[0] = (char *)displayString.c_str();
    iText[1] = (char *)StatusString(dli).c_str();

    int row = gtk_clist_append(GTK_CLIST(m_List), iText);
    gtk_clist_set_row_data(GTK_CLIST(m_List), row, (gpointer)dli);
}

void DownloadUI::UpdateItem(DownloadItem *dli)
{
    if (!dli || !m_List || !isVisible)
        return;

    int row = gtk_clist_find_row_from_data(GTK_CLIST(m_List), (gpointer)dli);

    if (row < 0)
        return;

    char *iText[2];
    iText[0] = (char *)StatusString(dli).c_str();
    if (gtk_clist_get_text(GTK_CLIST(m_List), row, 1, &iText[1])) {
        if (!strcmp(iText[0], iText[1]))
            return;

⌨️ 快捷键说明

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