kmail

folderutil.cpp
1/* Copyright 2009 Klarälvdalens Datakonsult AB
2
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License as
5 published by the Free Software Foundation; either version 2 of
6 the License or (at your option) version 3 or any later version
7 accepted by the membership of KDE e.V. (or its successor approved
8 by the membership of KDE e.V.), which shall act as a proxy
9 defined in Section 14 of version 3 of the license.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19#include "folderutil.h"
20
21#include "kmfolder.h"
22#include "kmfolderimap.h"
23#include "kmfoldercachedimap.h"
24#include "kmfoldermgr.h"
25
26#include <tdemessagebox.h>
27
28using namespace KMail;
29using namespace FolderUtil;
30
31KMFolder *KMail::FolderUtil::createSubFolder( KMFolder *parentFolder, KMFolderDir *parentDir,
32 const TQString &folderName, const TQString &namespaceName,
33 KMFolderType localFolderType )
34{
35 KMFolder *newFolder = 0;
36
37 if ( parentFolder && parentFolder->folderType() == KMFolderTypeImap ) {
38 KMFolderImap* selectedStorage = static_cast<KMFolderImap*>( parentFolder->storage() );
39 KMAcctImap *anAccount = selectedStorage->account();
40 // check if a connection is available BEFORE creating the folder
41 if (anAccount->makeConnection() == ImapAccountBase::Connected) {
42 newFolder = kmkernel->imapFolderMgr()->createFolder( folderName, false, KMFolderTypeImap, parentDir );
43 if ( newFolder ) {
44 TQString imapPath, parent;
45 if ( !namespaceName.isEmpty() ) {
46 // create folder with namespace
47 parent = anAccount->addPathToNamespace( namespaceName );
48 imapPath = anAccount->createImapPath( parent, folderName );
49 } else {
50 imapPath = anAccount->createImapPath( selectedStorage->imapPath(), folderName );
51 }
52 KMFolderImap* newStorage = static_cast<KMFolderImap*>( newFolder->storage() );
53 selectedStorage->createFolder(folderName, parent); // create it on the server
54 newStorage->initializeFrom( selectedStorage, imapPath, TQString() );
55 static_cast<KMFolderImap*>(parentFolder->storage())->setAccount( selectedStorage->account() );
56 return newFolder;
57 }
58 }
59 } else if ( parentFolder && parentFolder->folderType() == KMFolderTypeCachedImap ) {
60 newFolder = kmkernel->dimapFolderMgr()->createFolder( folderName, false, KMFolderTypeCachedImap,
61 parentDir );
62 if ( newFolder ) {
63 KMFolderCachedImap* selectedStorage = static_cast<KMFolderCachedImap*>( parentFolder->storage() );
64 KMFolderCachedImap* newStorage = static_cast<KMFolderCachedImap*>( newFolder->storage() );
65 newStorage->initializeFrom( selectedStorage );
66 if ( !namespaceName.isEmpty() ) {
67 // create folder with namespace
68 TQString path = selectedStorage->account()->createImapPath(
69 namespaceName, folderName );
70 newStorage->setImapPathForCreation( path );
71 }
72 return newFolder;
73 }
74 } else {
75 // local folder
76 Q_ASSERT( localFolderType == KMFolderTypeMaildir || localFolderType == KMFolderTypeMbox );
77 newFolder = kmkernel->folderMgr()->createFolder( folderName, false, localFolderType,
78 parentDir );
79 return newFolder;
80 }
81
82 return newFolder;
83}
84
85void KMail::FolderUtil::deleteFolder( KMFolder *folderToDelete, TQWidget *parent )
86{
87 if ( folderToDelete->hasAccounts() ) {
88 // this folder has an account, so we need to change that to the inbox
89 for ( AccountList::Iterator it (folderToDelete->acctList()->begin() ),
90 end( folderToDelete->acctList()->end() ); it != end; ++it ) {
91 (*it)->setFolder( kmkernel->inboxFolder() );
92 KMessageBox::information(parent,
93 i18n("<qt>The folder you deleted was associated with the account "
94 "<b>%1</b> which delivered mail into it. The folder the account "
95 "delivers new mail into was reset to the main Inbox folder.</qt>").arg( (*it)->name()));
96 }
97 }
98 if (folderToDelete->folderType() == KMFolderTypeImap)
99 kmkernel->imapFolderMgr()->remove(folderToDelete);
100 else if (folderToDelete->folderType() == KMFolderTypeCachedImap) {
101 // Deleted by user -> tell the account (see KMFolderCachedImap::listDirectory2)
102 KMFolderCachedImap* storage = static_cast<KMFolderCachedImap*>( folderToDelete->storage() );
103 KMAcctCachedImap* acct = storage->account();
104 if ( acct )
105 acct->addDeletedFolder( folderToDelete );
106
107 kmkernel->dimapFolderMgr()->remove(folderToDelete);
108 }
109 else if (folderToDelete->folderType() == KMFolderTypeSearch)
110 kmkernel->searchFolderMgr()->remove(folderToDelete);
111 else
112 kmkernel->folderMgr()->remove(folderToDelete);
113}
KMail list that manages the contents of one directory that may contain folders and/or other directori...
Definition: kmfolderdir.h:16
Mail folder.
Definition: kmfolder.h:69
KMFolderType folderType() const
Returns the type of this folder.
Definition: kmfolder.cpp:233
bool hasAccounts() const
Returns TRUE if accounts are associated with this folder.
Definition: kmfolder.h:128
folderdiaquotatab.h
Definition: aboutdata.cpp:40