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

📄 gtkdownloadui.cpp

📁 一个简单漂亮的C++编写的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.9 2000/01/19 22:20:30 ijr Exp $
____________________________________________________________________________*/

#include "config.h"

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

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

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)
{
    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());
}

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)
        return;

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

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

        iText[0] = (char *)displayString.c_str();  
  
        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[128];
                sprintf(outtext, "Error: %d\n", dli->GetDownloadError());
                statusString = outtext;
                break; }
            case kDownloadItemState_Done: {
                statusString = "Download Complete\0";
                break; }
            default:
                break;
        }
        iText[1] = (char *)statusString.c_str();

        gtk_clist_append(GTK_CLIST(m_List), iText);
    }

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

void set_current_sel_internal(GtkWidget *widget, int row, int column,
                              GdkEventButton *button, DownloadUI *p)
{
   p->SelChangeEvent(row);
}

void DownloadUI::CreateDownloadList(GtkWidget *box)
{
    static char *titles[] =
    {
      "Song Title", "Status"
    };

⌨️ 快捷键说明

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