|
板凳
楼主 |
发表于 2016-3-27 23:39:00
|
只看该作者
导入服务类支持不同模块的导入:
如:
module = importService.GetModule("addressbook", 0); //vcard
module = importService.GetModule("addressbook", 2); //csv
模块列表为 m_pModules = new nsImportModuleList();中
其内部真正实现导入功能的是nsIImportModule *m_pModule;
各模块的初始加载通过 nsresult nsImportService:: DoDiscover(void) -->LoadModuleInfo(contractIdStr.get(), supportsStr.get()); -->m_pModules->AddModule(clsId, pSupports, theTitle.get(), theDescription.get());
importService.GetModule("addressbook", 2); //csv 时触发 DoDiscover nsCOMPtr<nsICategoryManager> catMan
//m_pModules列表内容
pSupports | theTitle | theDescription
[ "addressbook" | "vCard 文件 (.vcf)" | "从 vCard 格式导入一个地址簿" ]
[ "mail,addressbook,settings" | "Outlook" | "Outlook 邮件,通讯录和设置" ]
[ "settings" | "Windows Live Mail" | "Windows Live Mail 设置" ]
[ "addressbook" | "文本" | "从文本文件导入通讯录。包括:LDIF (.ldif, .ldi),tab 定界的格式或以逗号分隔的 (.csv) 格式。" ]
[ "mail,addressbook,settings" | "Outlook Express" | "Outlook Express 邮件,通讯录和设置" ]
[ "mail,addressbook,settings,filters" | "Eudora" | "Eudora 邮件,通讯录和设置" ]
catMan内容的初始化来自于组件注册,如下调用堆栈
xul.dll!nsCategoryManager::AddCategoryEntry(const char * aCategoryName=0x01d17c8c, const char * aEntryName=0x01cfba18, const char * aValue=0x01f6995c, bool aReplace=true, char * * aOldValue=0x00000000)
xul.dll!nsComponentManagerImpl::RegisterModule(const mozilla::Module * aModule=0x01d18504, mozilla::FileLocation * aFile=0x021d2078) 行 413 + 0x16 字节 C++
xul.dll!nsComponentManagerImpl::Init() 行 350 + 0xe 字节 C++
xul.dll!NS_InitXPCOM2_P(nsIServiceManager * * result=0x021a6fc0, nsIFile * binDirectory=0x003d6be0, nsIDirectoryServiceProvider * appFileLocationProvider=0x0012fca8) 行 466 + 0xb 字节 C++
xul.dll!ScopedXPCOMStartup::Initialize() 行 1174 + 0x1b 字节 C++
xul.dll!XREMain::XRE_main(int argc=1, char * * argv=0x003d4570, const nsXREAppData * aAppData=0x003d6870) 行 3894 C++
所有这些与导入相关的模块都可在 nsImportModule.cpp 中找到 -----导入相关的服务模块 thinkmail\mailnews\import
static const mozilla::Module kMailNewsImportModule = {
mozilla::Module::kVersion,
kMailNewsImportCIDs,
kMailNewsImportContracts,
kMailNewsImportCategories,
NULL,
NULL,
importModuleDtor
};
importService.GetModule("addressbook", 2); // rv = CallCreateInstance(m_cid, &m_pModule); //{A5991D01-ADA7-11d3-A9C2-00A0CC26DA63}这里主要用到的是导入模块列表m_pModules中的cid为{A5991D01-ADA7-11d3-A9C2-00A0CC26DA63}的,即:2 [ "addressbook" | "文本" | "从文本文件导入通讯录。包括:LDIF (.ldif, .ldi),tab 定界的格式或以逗号分隔的 (.csv) 格式。" ]
////////////////////////////////////////////////////////////////////////////////
// text import factories
////////////////////////////////////////////////////////////////////////////////
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTextImport)
即可找到其对应实现
nsTextImport.h nsTextImport.cpp
class nsTextImport : public nsIImportModule
{
public:
nsTextImport();
virtual ~nsTextImport();
NS_DECL_ISUPPORTS
////////////////////////////////////////////////////////////////////////////////////////
// we suppport the nsIImportModule interface
////////////////////////////////////////////////////////////////////////////////////////
NS_DECL_NSIIMPORTMODULE
protected:
nsCOMPtr<nsIStringBundle> m_stringBundle;
};
addInterface = module.GetImportInterface( "addressbook"); // 返回指向nsIImportGeneric 实现的kISupportsIID接口
NS_IMETHODIMP nsTextImport::GetImportInterface(const char *pImportType, nsISupports **ppInterface)
{
if (!strcmp(pImportType, "addressbook")) {
// create the nsIImportMail interface and return it!
nsIImportAddressBooks * pAddress = nullptr;
nsIImportGeneric * pGeneric = nullptr;
rv = ImportAddressImpl::Create(&pAddress, m_stringBundle); //pAddress = new ImportAddressImpl(aStringBundle);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv)) {
rv = impSvc->CreateNewGenericAddressBooks(&pGeneric); // new nsImportGenericAddressBooks(); pGen->QueryInterface(NS_GET_IID(nsIImportGeneric), (void **)aImportGeneric);
if (NS_SUCCEEDED(rv)) {
pGeneric->SetData("addressInterface", pAddress); // item->QueryInterface(NS_GET_IID(nsIImportAddressBooks), (void **) &m_pInterface);
rv = pGeneric->QueryInterface(kISupportsIID, (void **)ppInterface);
}
}
}
}
this.addInterface = module.GetImportInterface( "addressbook"); //内部记录到通讯录字段 //nsIImportAddressBooks m_pInterface nsImportGenericAddressBooks
this.addInterface.SetData("addressLocation", file);//内部通讯录字面和文件关联 //m_pLocation m_pInterface->SetSampleLocation(m_pLocation); ImportAddressImpl
NS_IMETHODIMP nsImportGenericAddressBooks::SetData(const char *dataId, nsISupports *item)
{
NS_PRECONDITION(dataId != nullptr, "null ptr");
if (!dataId)
return NS_ERROR_NULL_POINTER;
if (!PL_strcasecmp(dataId, "addressInterface")) {
NS_IF_RELEASE(m_pInterface);
if (item)
item->QueryInterface(NS_GET_IID(nsIImportAddressBooks), (void **) &m_pInterface);
}
if (!PL_strcasecmp(dataId, "addressBooks")) {
NS_IF_RELEASE(m_pBooks);
if (item)
item->QueryInterface(NS_GET_IID(nsISupportsArray), (void **) &m_pBooks);
}
if (!PL_strcasecmp(dataId, "addressLocation")) {
m_pLocation = nullptr;
if (item) {
nsresult rv;
m_pLocation = do_QueryInterface(item, &rv);
NS_ENSURE_SUCCESS(rv,rv);
}
if (m_pInterface)
m_pInterface->SetSampleLocation(m_pLocation);
}
if (!PL_strcasecmp(dataId, "addressDestination")) {
if (item) {
nsCOMPtr<nsISupportsCString> abString;
item->QueryInterface(NS_GET_IID(nsISupportsCString), getter_AddRefs(abString));
if (abString) {
if (m_pDestinationUri)
NS_Free(m_pDestinationUri);
m_pDestinationUri = nullptr;
nsCAutoString tempUri;
abString->GetData(tempUri);
m_pDestinationUri = ToNewCString(tempUri);
}
}
}
if (!PL_strcasecmp(dataId, "fieldMap")) {
NS_IF_RELEASE(m_pFieldMap);
if (item)
item->QueryInterface(NS_GET_IID(nsIImportFieldMap), (void **) &m_pFieldMap);
}
return NS_OK;
}
this.addInterface nsImportGenericAddressBooks
this.fieldMap = addInterface.GetData( "fieldMap"); //m_pFieldMap[nsImportFieldMap] m_pInterface[通讯录接口] m_pLocation[文件接口]
NS_IMETHODIMP nsImportGenericAddressBooks::GetData(const char *dataId, nsISupports **_retval)
{
NS_PRECONDITION(_retval != nullptr, "null ptr");
if (!_retval)
return NS_ERROR_NULL_POINTER;
nsresult rv;
*_retval = nullptr;
if (!PL_strcasecmp(dataId, "fieldMap")) {
if (m_pFieldMap) {
*_retval = m_pFieldMap;
m_pFieldMap->AddRef();
}
else {
if (m_pInterface && m_pLocation) {
bool needsIt = false;
m_pInterface->GetNeedsFieldMap(m_pLocation, &needsIt); //这里判断是不是isLDIF文件,来确认要不要打开映射关系窗口
if (needsIt) {
GetDefaultFieldMap(); //这里通过代码中设置的要映射的字段赋初值 ,然后再根据用户以前使用过的先清空默认,再调整为mailnews.import.text.fieldmap中记录的
if (m_pFieldMap) {
*_retval = m_pFieldMap;
m_pFieldMap->AddRef();
}
}
}
}
}
return NS_OK;
}
this.fieldMap.SetFieldMapSize(max);
this.fieldMap.SetFieldMap( this._listHandledInfoMap[tindex].abIndex, tindex); //先abindex [m_numFields] 后txtindex? m_pFields[index] = fieldNum; index(ab)-->fieldNum(txt)
this.fieldMap.SetFieldActive( this._listHandledInfoMap[tindex].abIndex, this._listHandledInfoMap[tindex].matchOK); m_pActive[index] = active; //如个ab字段是有效匹配的
this.addInterface.WantsProgress()
this.addInterface.BeginImport(success, error);
NS_IMETHODIMP nsImportGenericAddressBooks::WantsProgress(bool *_retval)
{
}
NS_IMETHODIMP nsImportGenericAddressBooks::BeginImport(nsISupportsString *successLog, nsISupportsString *errorLog, bool *_retval)
{
}
|
|