/*
 * download.h by Matthias Braun <matze@braunis.de>
 *
 * Copyright (C) 2002 Atomic Blue (info@planeshift.it, http://www.atomicblue.org) 
 *
 *
 * 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 (version 2 of the License)
 * 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.
 *
 */
#ifndef __UPDATER_DOWNLOAD_H__
#define __UPDATER_DOWNLOAD_H__

#include <curl/types.h>
#include <curl/curl.h>
#include <csutil/csstring.h>
#include "psupdaterengine.h"

namespace updater
{

class StatusCallback
{
public:
    /// Gives percent from 0-100 and a descriptive string
    virtual void StatusUpdate (float percent, const char* string);
};

class Downloader
{
public:
    Downloader ();
    ~Downloader ();

    void SetProxy (bool active, const char* host = NULL, int port=0);
    void SetCallback (StatusCallback* callback);
    bool DownloadFile (const char* dest, const char* url, 
               bool progress = false,bool changemirrors = true);

    psUpdaterEngine* GetEngine() {return eng;}

    csTicks GetStartTick(){ return start;}

private:
    static int ProgressCallback (void* clientp, double total,
        double now, double uptotal, double upnow);
        
    
    bool NextMirror(const char* dest, const char* url, bool progress);

    StatusCallback* callback;
    bool progress;
    int lastprogress;
    CURL* curl;
    char* curlerror;
    csString tempfile;
    psUpdaterEngine*   eng;
    csTicks start;
};

} // end of namespace updater

#endif

