kmail

importjob.h
00001 /* Copyright 2009 Klarälvdalens Datakonsult AB
00002 
00003    This program is free software; you can redistribute it and/or
00004    modify it under the terms of the GNU General Public License as
00005    published by the Free Software Foundation; either version 2 of
00006    the License or (at your option) version 3 or any later version
00007    accepted by the membership of KDE e.V. (or its successor approved
00008    by the membership of KDE e.V.), which shall act as a proxy
00009    defined in Section 14 of version 3 of the license.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 #ifndef IMPORTJOB_H
00020 #define IMPORTJOB_H
00021 
00022 #include <kurl.h>
00023 
00024 #include <tqobject.h>
00025 #include <tqvaluelist.h>
00026 #include <tqptrlist.h>
00027 
00028 #include <sys/types.h>
00029 
00030 class TQWidget;
00031 class KArchive;
00032 class KArchiveDirectory;
00033 class KArchiveFile;
00034 class KMFolder;
00035 class KMMessage;
00036 
00037 namespace KPIM
00038 {
00039   class ProgressItem;
00040 }
00041 
00042 namespace KMail
00043 {
00044   class FolderJob;
00045 
00052 class ImportJob : public TQObject
00053 {
00054   Q_OBJECT
00055   TQ_OBJECT
00056 
00057   public:
00058 
00059     explicit ImportJob( TQWidget *parentWidget = 0 );
00060     ~ImportJob();
00061     void start();
00062     void setFile( const KURL &archiveFile );
00063     void setRootFolder( KMFolder *rootFolder );
00064 
00065   private slots:
00066 
00067     void importNextMessage();
00068     void cancelJob();
00069     void messagePutResult( KMail::FolderJob *job );
00070 
00071   private:
00072 
00073     struct Folder
00074     {
00075       KMFolder *parent;
00076       const KArchiveDirectory *archiveDir;
00077     };
00078 
00079     struct Messages
00080     {
00081       KMFolder *parent;
00082       TQPtrList<KArchiveFile> files;
00083     };
00084 
00085     void finish();
00086     void abort( const TQString &errorMessage );
00087     void queueFolders();
00088     void importNextDirectory();
00089     KMFolder* createSubFolder( KMFolder *parent, const TQString &folderName, mode_t permissions );
00090     KMFolder* getOrCreateSubFolder( KMFolder *parentFolder, const TQString &subFolderName,
00091                                     mode_t subFolderPermissions );
00092     void enqueueMessages( const KArchiveDirectory *dir, KMFolder *folder );
00093     void messageAdded();
00094 
00095     KArchive *mArchive;
00096 
00097     // The root folder which the user has selected as the folder to which everything should be
00098     // imported
00099     KMFolder *mRootFolder;
00100 
00101     TQWidget *mParentWidget;
00102     KURL mArchiveFile;
00103     int mNumberOfImportedMessages;
00104 
00105     // List of archive folders with their corresponding KMail parent folder that are awaiting
00106     // processing
00107     TQValueList<Folder> mQueuedDirectories;
00108 
00109     // List of list of messages and their parent folders which are awaiting processing
00110     TQValueList<Messages> mQueuedMessages;
00111 
00112     // The folder to which we are currently importing messages
00113     KMFolder *mCurrentFolder;
00114 
00115     // The message which is currently being added
00116     KMMessage *mCurrentMessage;
00117 
00118     // The archive file of the current message that is being added
00119     KArchiveFile *mCurrentMessageFile;
00120 
00121     KPIM::ProgressItem *mProgressItem;
00122     bool mAborted;
00123 };
00124 
00125 }
00126 
00127 #endif