Back to index

lightning-sunbird  0.9+nobinonly
nsMsgSearchValue.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 Communicator client 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  *   Alec Flett <alecf@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "MailNewsTypes.h"
00040 #include "nsMsgSearchValue.h"
00041 #include "nsReadableUtils.h"
00042 #include "nsISupportsObsolete.h"
00043 
00044 nsMsgSearchValueImpl::nsMsgSearchValueImpl(nsMsgSearchValue *aInitialValue)
00045 {
00046     mValue = *aInitialValue;
00047     if (IS_STRING_ATTRIBUTE(aInitialValue->attribute))
00048         mValue.string = nsCRT::strdup(aInitialValue->string);
00049     else
00050         mValue.string = 0;
00051 }
00052 
00053 nsMsgSearchValueImpl::~nsMsgSearchValueImpl()
00054 {
00055     if (IS_STRING_ATTRIBUTE(mValue.attribute))
00056         nsCRT::free(mValue.string);
00057 
00058 }
00059 
00060 NS_IMPL_ISUPPORTS1(nsMsgSearchValueImpl, nsIMsgSearchValue)
00061 
00062 NS_IMPL_GETSET(nsMsgSearchValueImpl, Priority, nsMsgPriorityValue, mValue.u.priority)
00063 NS_IMPL_GETSET(nsMsgSearchValueImpl, Status, PRUint32, mValue.u.msgStatus)
00064 NS_IMPL_GETSET(nsMsgSearchValueImpl, Size, PRUint32, mValue.u.size)
00065 NS_IMPL_GETSET(nsMsgSearchValueImpl, MsgKey, nsMsgKey, mValue.u.key)
00066 NS_IMPL_GETSET(nsMsgSearchValueImpl, Age, PRUint32, mValue.u.age)
00067 NS_IMPL_GETSET(nsMsgSearchValueImpl, Date, PRTime, mValue.u.date)
00068 NS_IMPL_GETSET(nsMsgSearchValueImpl, Attrib, nsMsgSearchAttribValue, mValue.attribute)
00069 NS_IMPL_GETSET(nsMsgSearchValueImpl, Label, nsMsgLabelValue, mValue.u.label)
00070 NS_IMPL_GETSET(nsMsgSearchValueImpl, JunkStatus, PRUint32, mValue.u.junkStatus)
00071 
00072 NS_IMETHODIMP
00073 nsMsgSearchValueImpl::GetFolder(nsIMsgFolder* *aResult)
00074 {
00075     NS_ENSURE_ARG_POINTER(aResult);
00076     NS_ENSURE_TRUE(mValue.attribute == nsMsgSearchAttrib::FolderInfo, NS_ERROR_ILLEGAL_VALUE);
00077     *aResult = mValue.u.folder;
00078     NS_IF_ADDREF(*aResult);
00079     return NS_OK;
00080 }
00081 
00082 NS_IMETHODIMP
00083 nsMsgSearchValueImpl::SetFolder(nsIMsgFolder* aValue)
00084 {
00085     NS_ENSURE_TRUE(mValue.attribute == nsMsgSearchAttrib::FolderInfo, NS_ERROR_ILLEGAL_VALUE);
00086     mValue.u.folder = aValue;
00087     return NS_OK;
00088 }
00089 
00090 NS_IMETHODIMP
00091 nsMsgSearchValueImpl::GetStr(PRUnichar** aResult)
00092 {
00093     NS_ENSURE_ARG_POINTER(aResult);
00094     NS_ENSURE_TRUE(IS_STRING_ATTRIBUTE(mValue.attribute), NS_ERROR_ILLEGAL_VALUE);
00095     *aResult = ToNewUnicode(NS_ConvertUTF8toUCS2(mValue.string));
00096     return NS_OK;
00097 }
00098 
00099 NS_IMETHODIMP
00100 nsMsgSearchValueImpl::SetStr(const PRUnichar* aValue)
00101 {
00102     NS_ENSURE_TRUE(IS_STRING_ATTRIBUTE(mValue.attribute), NS_ERROR_ILLEGAL_VALUE);
00103     if (mValue.string)
00104         nsCRT::free(mValue.string);
00105     mValue.string = ToNewUTF8String(nsDependentString(aValue));
00106     return NS_OK;
00107 }
00108 
00109 NS_IMETHODIMP
00110 nsMsgSearchValueImpl::ToString(PRUnichar **aResult)
00111 {
00112     NS_ENSURE_ARG_POINTER(aResult);
00113 
00114     nsAutoString resultStr;
00115     resultStr.AssignLiteral("[nsIMsgSearchValue: ");
00116     if (IS_STRING_ATTRIBUTE(mValue.attribute)) {
00117         AppendUTF8toUTF16(mValue.string, resultStr);
00118         return NS_OK;
00119     }
00120 
00121     
00122     switch (mValue.attribute) {
00123 
00124     case nsMsgSearchAttrib::Priority:
00125     case nsMsgSearchAttrib::Date:
00126     case nsMsgSearchAttrib::MsgStatus:
00127     case nsMsgSearchAttrib::MessageKey:
00128     case nsMsgSearchAttrib::Size:
00129     case nsMsgSearchAttrib::AgeInDays:
00130     case nsMsgSearchAttrib::FolderInfo:
00131     case nsMsgSearchAttrib::Label:
00132     case nsMsgSearchAttrib::JunkStatus:
00133         resultStr.AppendLiteral("type=");
00134         resultStr.AppendInt(mValue.attribute);
00135         break;
00136     default:
00137         NS_ASSERTION(0, "Unknown search value type");
00138     }        
00139 
00140     resultStr.AppendLiteral("]");
00141 
00142     *aResult = ToNewUnicode(resultStr);
00143     return NS_OK;
00144 }