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 <qobject.h>
00025 #include <qvaluelist.h>
00026 #include <qptrlist.h>
00027 
00028 #include <sys/types.h>
00029 
00030 class QWidget;
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 QObject
00053 {
00054   Q_OBJECT
00055 
00056   public:
00057 
00058     explicit ImportJob( QWidget *parentWidget = 0 );
00059     ~ImportJob();
00060     void start();
00061     void setFile( const KURL &archiveFile );
00062     void setRootFolder( KMFolder *rootFolder );
00063 
00064   private slots:
00065 
00066     void importNextMessage();
00067     void cancelJob();
00068     void messagePutResult( KMail::FolderJob *job );
00069 
00070   private:
00071 
00072     struct Folder
00073     {
00074       KMFolder *parent;
00075       const KArchiveDirectory *archiveDir;
00076     };
00077 
00078     struct Messages
00079     {
00080       KMFolder *parent;
00081       QPtrList<KArchiveFile> files;
00082     };
00083 
00084     void finish();
00085     void abort( const QString &errorMessage );
00086     void queueFolders();
00087     void importNextDirectory();
00088     KMFolder* createSubFolder( KMFolder *parent, const QString &folderName, mode_t permissions );
00089     KMFolder* getOrCreateSubFolder( KMFolder *parentFolder, const QString &subFolderName,
00090                                     mode_t subFolderPermissions );
00091     void enqueueMessages( const KArchiveDirectory *dir, KMFolder *folder );
00092     void messageAdded();
00093 
00094     KArchive *mArchive;
00095 
00096     // The root folder which the user has selected as the folder to which everything should be
00097     // imported
00098     KMFolder *mRootFolder;
00099 
00100     QWidget *mParentWidget;
00101     KURL mArchiveFile;
00102     int mNumberOfImportedMessages;
00103 
00104     // List of archive folders with their corresponding KMail parent folder that are awaiting
00105     // processing
00106     QValueList<Folder> mQueuedDirectories;
00107 
00108     // List of list of messages and their parent folders which are awaiting processing
00109     QValueList<Messages> mQueuedMessages;
00110 
00111     // The folder to which we are currently importing messages
00112     KMFolder *mCurrentFolder;
00113 
00114     // The message which is currently being added
00115     KMMessage *mCurrentMessage;
00116 
00117     // The archive file of the current message that is being added
00118     KArchiveFile *mCurrentMessageFile;
00119 
00120     KPIM::ProgressItem *mProgressItem;
00121     bool mAborted;
00122 };
00123 
00124 }
00125 
00126 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys