|
// =====================================================================================
|
|
//
|
|
// Filename: FilesUpload.h
|
|
//
|
|
// Description:
|
|
//
|
|
// Version: 1.0
|
|
// Created: 2010年07月19日 17时06分04秒
|
|
// Revision: none
|
|
// Compiler: g++
|
|
//
|
|
// Author: 宋志民 (Song Zhi-Min), cszhmsong@gmail.com
|
|
// Company: 希科系统开发小组(CxServer Development Team)
|
|
//
|
|
// =====================================================================================
|
|
|
|
#ifndef FILES_UPLOAD_H_
|
|
#define FILES_UPLOAD_H_
|
|
|
|
#include <WCompositeWidget>
|
|
#include <WContainerWidget>
|
|
#include <WTable>
|
|
|
|
#include "Option.h"
|
|
#include "File.h"
|
|
#include "FileUploadItem.h"
|
|
|
|
class FileUploadItem;
|
|
|
|
using namespace Wt;
|
|
using namespace Cs;
|
|
|
|
/**
|
|
* @addtogroup utils
|
|
*/
|
|
/*@{*/
|
|
|
|
/*! \class FilesUpload FilesUpload.h "utils/FilesUpload.h"
|
|
* \brief A files upload widget for uploading files as necessary.
|
|
*/
|
|
class FilesUpload : public WCompositeWidget {
|
|
|
|
public:
|
|
|
|
/*! \brief Creates a file upload widget with min and max files.
|
|
*
|
|
* we should be sure that min_ >= 0 and max_ >= 1 and min_ <= max_, otherwise it will does not work correctly.
|
|
*
|
|
* if min_ = 0, that means this is !mandatory, the constructor will just create only one FileUploadItem,
|
|
* and furthermore, it is hidden, which is shown by clicked() of uploadFile_ option. This indeed does not
|
|
* need user have to upload some files.
|
|
*
|
|
* else min_ > 0 (min_>=1), that means this is mandatory for user who must upload at least min_ files,
|
|
* the constructor will create (min_+1) FileUploadItem, in which the last one is prepared, hidden for
|
|
* uploading more, at the same time the others are shown and hiding their cancel button(because they are
|
|
* mandatory).
|
|
*
|
|
* \note min_ must be less than or equal to max_!
|
|
*/
|
|
FilesUpload(int min, int max, WContainerWidget *parent = 0);
|
|
|
|
/*! \brief Destructor, deletes the tmp files.
|
|
*/
|
|
~FilesUpload();
|
|
|
|
/*! \brief Returns the files uploaded.
|
|
*/
|
|
std::vector<File> files() const;
|
|
|
|
/*! \brief Returns whether upload done.
|
|
*/
|
|
bool uploadDone();
|
|
|
|
private slots:
|
|
|
|
/*! \brief Uploads another one.
|
|
*
|
|
* This function mainly starts to a new FileUploadItem, surely when the number of FileUploadItem <= max_;
|
|
* \note this number is always more than max_ by 1.
|
|
*
|
|
* So, when the number equals (max_+1), uploadOtherFile_ option will hide, and the last FileUploadItem
|
|
* will hide also, which is never used.
|
|
*/
|
|
void uploadMore();
|
|
|
|
/*! \brief Cancels the file upload, i.e. removes the given FileUploadItem.
|
|
*/
|
|
void cancelFileItem(FileUploadItem *fileItem);
|
|
|
|
/*! \brief Removes the file uploaded.
|
|
*/
|
|
void removeFileItem(FileUploadItem *fileItem);
|
|
|
|
/*! \brief Updates the widget after cancelFileItem() or removeFileItem().
|
|
*
|
|
* \note This function is used always after deleting the fileItem, so rest sum of FileUploadItem can directly
|
|
* compare with min_ and max_(in thinking).
|
|
*
|
|
* if min_ = 0, when the rest sum is 1, we should go back to the initial status, hide the uploadOtherFile_
|
|
* and show the uploadFile_; if rest sum > 1, we just update the text rest number of uploadOtherFile_ and
|
|
* be sure uploadOtherFile_ is shown.
|
|
*
|
|
* else min_ > 0 (min_ >= 1), when the rest sum == min_, we must be sure there are min_ FileUploadItem are
|
|
* shown and hideCancel(). So this time, we must show the min_(th) one and uploadMore() to prepare one.
|
|
* if rest sum > min_, we just update the text rest number of uploadOtherFile_ and be sure uploadOtherFile_
|
|
* is shown.
|
|
*/
|
|
void update();
|
|
|
|
/*! \brief Clears the container and files.
|
|
*
|
|
* \sa FilesManager
|
|
*/
|
|
void clear();
|
|
|
|
private:
|
|
|
|
/*! \brief Creates the files upload widget.
|
|
*/
|
|
void createUi();
|
|
|
|
/*! \brief Deletes(unlink) the tmp files.
|
|
*/
|
|
void deltmp();
|
|
|
|
int min_;
|
|
int max_;
|
|
WContainerWidget *layout_;
|
|
WTable *edits_;
|
|
Option *uploadFile_;
|
|
Text *uploadOtherFile_;
|
|
int filesPending_;
|
|
int filesFailed_;
|
|
|
|
std::vector<FileUploadItem *> files_;
|
|
|
|
friend class FileUploadItem;
|
|
friend class FilesManager;
|
|
};
|
|
|
|
/*@}*/
|
|
#endif // FILES_UPLOAD_H_
|