Hydra 0.20
hydra.src/desktop/FileOp.h
00001 
00002 /*
00003  * Copyright (c) 2009 Aleksander B. Demko
00004  * This source code is distributed under the MIT license.
00005  * See the accompanying file LICENSE.MIT.txt for details.
00006  */
00007 
00008 #ifndef __INCLUDED_HYDRADESKTOP_FILEOP_H__
00009 #define __INCLUDED_HYDRADESKTOP_FILEOP_H__
00010 
00011 #include <QWidget>
00012 
00013 #include <hydra/FileOp.h>
00014 
00015 namespace desktop
00016 {
00017   class FileOp;
00018 
00019   class FileOpGuiTest;
00020   class FileOpDisk;
00021   class FileOpDB;
00022   //class FileOpEvents;
00023 
00024   int guiFileOpFiles(QWidget *parent, int op, const QStringList &srcfiles, 
00025       const QString &destDir, FileOp *handler = 0);
00026 };
00027 
00028 /**
00029  * This provides a common interface to file operations.
00030  * Subclasses can do various things, providing a nice consistance
00031  * interface for callers to use.
00032  *
00033  * @author Aleksander Demko
00034  */ 
00035 class desktop::FileOp
00036 {
00037   public:
00038     enum {
00039       Op_Del = 1,
00040       Op_Move,
00041       Op_Copy,
00042     };
00043 
00044   public:
00045     virtual ~FileOp();
00046 
00047     // returns true on success
00048     virtual bool delFile(const QString &srcfile) = 0;
00049     // returns true on success
00050     virtual bool moveFile(const QString &srcfile, const QString &destfile) = 0;
00051     // returns true on success
00052     virtual bool copyFile(const QString &srcfile, const QString &destfile) = 0;
00053     // returns true on success
00054     virtual bool delDir(const QString &dirname) = 0;
00055 
00056     /**
00057      * Perform one file operation, based on the op field, which is one
00058      * of Op_Del, Op_Move or Op_Copy
00059      *
00060      * @author Aleksander Demko
00061      */ 
00062     bool opFile(int op, const QString &srcfile, const QString &destfile);
00063 };
00064 
00065 /**
00066  * This class 
00067  * @author Aleksander Demko
00068  */ 
00069 class desktop::FileOpGuiTest : public desktop::FileOp
00070 {
00071   public:
00072     // this may be thrown by any of the following functions
00073     class UserCanceled
00074     {
00075     };
00076 
00077   public:
00078     FileOpGuiTest(QWidget *parent);
00079 
00080     // returns true on success (ie. continue to perform this operation)
00081     virtual bool delFile(const QString &srcfile);
00082     // returns true on success (ie. continue to perform this operation)
00083     virtual bool moveFile(const QString &srcfile, const QString &destfile);
00084     // returns true on success (ie. continue to perform this operation)
00085     virtual bool copyFile(const QString &srcfile, const QString &destfile);
00086     // returns true on success
00087     virtual bool delDir(const QString &dirname);
00088 
00089   private:
00090     QWidget *dm_parent;
00091     bool dm_overwrite_all;
00092     bool dm_overwrite_none;
00093     bool dm_skip_errors;
00094 };
00095 
00096 /**
00097  * Performs the actual operations on the file system (disk)
00098  *
00099  * @author Aleksander Demko
00100  */ 
00101 class desktop::FileOpDisk : public desktop::FileOp
00102 {
00103   public:
00104     FileOpDisk(void);
00105 
00106     // returns true on success
00107     virtual bool delFile(const QString &srcfile);
00108     // returns true on success
00109     virtual bool moveFile(const QString &srcfile, const QString &destfile);
00110     // returns true on success
00111     virtual bool copyFile(const QString &srcfile, const QString &destfile);
00112     // returns true on success
00113     virtual bool delDir(const QString &dirname);
00114 };
00115 
00116 class desktop::FileOpDB : public desktop::FileOp
00117 {
00118   public:
00119     FileOpDB(void);
00120 
00121     // returns true on success
00122     virtual bool delFile(const QString &srcfile);
00123     // returns true on success
00124     virtual bool moveFile(const QString &srcfile, const QString &destfile);
00125     // returns true on success
00126     virtual bool copyFile(const QString &srcfile, const QString &destfile);
00127     // returns true on success
00128     virtual bool delDir(const QString &dirname);
00129 };
00130 
00131 #endif
00132 
 All Classes Namespaces Functions Variables