Back to index

lightning-sunbird  0.9+nobinonly
nsIMAPGroupRecord.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nsIMAPGroupRecord.h"
00039 #include "plstr.h"
00040 #include "prmem.h"
00041 
00042 extern int MSG_GROUPNAME_FLAG_IMAP_NOSELECT;
00043 
00044 nsIMAPGroupRecord*
00045 nsIMAPGroupRecord::Create(nsIMAPGroupRecord* parent, const char* folderName,
00046                                                  char delimiter, PRBool filledInGroup, PRBool folderIsNamespace)
00047 {
00048        char* tmp = NULL;
00049        char* partname = NULL;
00050        nsIMAPGroupRecord* result = NULL;
00051 
00052        if (folderName)
00053        {
00054               tmp = PL_strdup(folderName);
00055               partname = PL_strrchr(tmp, '/');
00056               if (!partname || !delimiter || folderIsNamespace) // if delimiter == NULL, partname is the full folderName
00057                      partname = tmp;
00058               else
00059                      partname++;
00060        }
00061 
00062 #ifdef DEBUG_slowAndParanoid
00063        if (parent->m_partname) {
00064               char* parentname = parent->GetFullName();
00065               PR_ASSERT(partname > tmp && partname[-1] == m_delimiter);
00066               partname[-1] = '\0';
00067               PR_ASSERT(PL_strcmp(parentname, tmp) == 0);
00068               partname[-1] = m_delimiter;
00069               delete [] parentname;
00070               parentname = NULL;
00071        } else {
00072               PR_ASSERT(partname == tmp);
00073        }
00074 #endif
00075 
00076        result = nsIMAPGroupRecord::CreateFromPartname(parent, partname, delimiter, filledInGroup);
00077        if (result) {
00078               result->m_flags = 0;
00079               result->SetFolderIsNamespace(folderIsNamespace);
00080        }
00081 
00082        PR_Free(tmp);
00083        return result;
00084        
00085 }
00086 
00087 
00088 nsIMAPGroupRecord*
00089 nsIMAPGroupRecord::CreateFromPartname(nsIMAPGroupRecord* parent, const char* partname, char delimiter, PRBool filledInGroup)
00090 {
00091        nsIMAPGroupRecord* result = new nsIMAPGroupRecord(parent, partname, delimiter, filledInGroup);
00092        if (result && partname && !result->m_partname) {
00093               // We ran out of memory.
00094               delete result;
00095               result = NULL;
00096        }
00097        result->InitializeSibling();
00098        return result;
00099 }
00100 
00101 
00102 nsIMAPGroupRecord::nsIMAPGroupRecord(nsIMAPGroupRecord* parent,
00103                                                                        const char* partname, char delimiter, PRBool filledInGroup) : nsMsgGroupRecord(parent, partname, 0, 0, 0, '/')
00104 {
00105        m_flags = 0;
00106        m_allGrandChildrenDiscovered = PR_FALSE;
00107        m_filledInGroup = filledInGroup;
00108        m_onlineDelimiter = delimiter;
00109 }
00110 
00111 
00112 PRBool nsIMAPGroupRecord::GetCanToggleSubscribe()
00113 {
00114        return !GetFolderIsNamespace() && !(GetFlags() & MSG_GROUPNAME_FLAG_IMAP_NOSELECT);
00115 }