1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <columninfo.hxx>
22 #include <fileextensions.hxx>
23 #include <metainforeader.hxx>
24 #include <utilities.hxx>
27 #include <sal/macros.h>
30 namespace /* private */
32 const SHCOLUMNINFO ColumnInfoTable
[] =
34 {{PSGUID_SUMMARYINFORMATION
, PIDSI_TITLE
}, VT_BSTR
, LVCFMT_LEFT
, 30, SHCOLSTATE_TYPE_STR
, L
"Title", L
"Title"},
35 {{PSGUID_SUMMARYINFORMATION
, PIDSI_AUTHOR
}, VT_BSTR
, LVCFMT_LEFT
, 30, SHCOLSTATE_TYPE_STR
, L
"Author", L
"Author"},
36 {{PSGUID_SUMMARYINFORMATION
, PIDSI_SUBJECT
}, VT_BSTR
, LVCFMT_LEFT
, 30, SHCOLSTATE_TYPE_STR
, L
"Subject", L
"Subject"},
37 {{PSGUID_SUMMARYINFORMATION
, PIDSI_KEYWORDS
}, VT_BSTR
, LVCFMT_LEFT
, 30, SHCOLSTATE_TYPE_STR
, L
"Keywords", L
"Keywords"},
38 {{PSGUID_SUMMARYINFORMATION
, PIDSI_COMMENTS
}, VT_BSTR
, LVCFMT_LEFT
, 30, SHCOLSTATE_TYPE_STR
, L
"Comments", L
"Comments"},
39 {{PSGUID_SUMMARYINFORMATION
, PIDSI_PAGECOUNT
},VT_BSTR
, LVCFMT_LEFT
, 30, SHCOLSTATE_TYPE_STR
, L
"Pagecount", L
"Pagecount"}
42 size_t ColumnInfoTableSize
= SAL_N_ELEMENTS(ColumnInfoTable
);
44 bool IsOOFileExtension(wchar_t const * Extension
)
46 for (size_t i
= 0; i
< OOFileExtensionTableSize
; i
++)
48 if (0 == _wcsicmp(Extension
, OOFileExtensionTable
[i
].ExtensionU
))
58 CColumnInfo::CColumnInfo(LONG RefCnt
) :
61 InterlockedIncrement(&g_DllRefCnt
);
65 CColumnInfo::~CColumnInfo()
67 InterlockedDecrement(&g_DllRefCnt
);
74 COM_DECLSPEC_NOTHROW HRESULT STDMETHODCALLTYPE
CColumnInfo::QueryInterface(REFIID riid
, void __RPC_FAR
*__RPC_FAR
*ppvObject
)
78 if (IID_IUnknown
== riid
|| IID_IColumnProvider
== riid
)
80 IUnknown
* pUnk
= this;
90 COM_DECLSPEC_NOTHROW ULONG STDMETHODCALLTYPE
CColumnInfo::AddRef()
92 return InterlockedIncrement(&m_RefCnt
);
96 COM_DECLSPEC_NOTHROW ULONG STDMETHODCALLTYPE
CColumnInfo::Release()
98 LONG refcnt
= InterlockedDecrement(&m_RefCnt
);
110 COM_DECLSPEC_NOTHROW HRESULT STDMETHODCALLTYPE
CColumnInfo::Initialize(LPCSHCOLUMNINIT
/*psci*/)
115 // Register all columns we support
116 COM_DECLSPEC_NOTHROW HRESULT STDMETHODCALLTYPE
CColumnInfo::GetColumnInfo(DWORD dwIndex
, SHCOLUMNINFO
*psci
)
118 if (dwIndex
>= ColumnInfoTableSize
)
121 // Return information on each column we support. Return S_FALSE
122 // to indicate that we have returned information on all our
123 // columns. GetColumnInfo will be called repeatedly until S_FALSE
124 // or an error is returned
125 psci
->scid
.fmtid
= ColumnInfoTable
[dwIndex
].scid
.fmtid
;
126 psci
->scid
.pid
= ColumnInfoTable
[dwIndex
].scid
.pid
;
127 ZeroMemory(psci
->wszTitle
, sizeof(psci
->wszTitle
));
128 wcsncpy(psci
->wszTitle
, ColumnInfoTable
[dwIndex
].wszTitle
,
129 SAL_N_ELEMENTS(psci
->wszTitle
) - 1);
134 COM_DECLSPEC_NOTHROW HRESULT STDMETHODCALLTYPE
CColumnInfo::GetItemData(LPCSHCOLUMNID pscid
, LPCSHCOLUMNDATA pscd
, VARIANT
*pvarData
)
136 if (IsOOFileExtension(pscd
->pwszExt
))
140 std::wstring fname
= getShortPathName( std::wstring( pscd
->wszFile
) );
142 CMetaInfoReader
meta_info_accessor(fname
);
144 VariantClear(pvarData
);
146 if (IsEqualGUID (pscid
->fmtid
, FMTID_SummaryInformation
) && pscid
->pid
== PIDSI_TITLE
)
148 pvarData
->vt
= VT_BSTR
;
149 pvarData
->bstrVal
= SysAllocString(meta_info_accessor
.getTagData( META_INFO_TITLE
).c_str());
153 else if (IsEqualGUID (pscid
->fmtid
, FMTID_SummaryInformation
) && pscid
->pid
== PIDSI_AUTHOR
)
155 pvarData
->vt
= VT_BSTR
;
156 pvarData
->bstrVal
= SysAllocString(meta_info_accessor
.getTagData( META_INFO_AUTHOR
).c_str());
160 else if (IsEqualGUID (pscid
->fmtid
, FMTID_SummaryInformation
) && pscid
->pid
== PIDSI_SUBJECT
)
162 pvarData
->vt
= VT_BSTR
;
163 pvarData
->bstrVal
= SysAllocString(meta_info_accessor
.getTagData( META_INFO_SUBJECT
).c_str());
167 else if (IsEqualGUID (pscid
->fmtid
, FMTID_SummaryInformation
) && pscid
->pid
== PIDSI_KEYWORDS
)
169 pvarData
->vt
= VT_BSTR
;
170 pvarData
->bstrVal
= SysAllocString(meta_info_accessor
.getTagData( META_INFO_KEYWORDS
).c_str());
174 else if (IsEqualGUID (pscid
->fmtid
, FMTID_SummaryInformation
) && pscid
->pid
== PIDSI_COMMENTS
)
176 pvarData
->vt
= VT_BSTR
;
177 pvarData
->bstrVal
= SysAllocString(meta_info_accessor
.getTagData( META_INFO_DESCRIPTION
).c_str());
181 else if (IsEqualGUID (pscid
->fmtid
, FMTID_SummaryInformation
) && pscid
->pid
== PIDSI_PAGECOUNT
)
183 pvarData
->vt
= VT_BSTR
;
184 pvarData
->bstrVal
= SysAllocString(meta_info_accessor
.getTagAttribute( META_INFO_DOCUMENT_STATISTIC
, META_INFO_PAGES
).c_str());
189 catch (const std::exception
&)
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */