1*f8e2c85aSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f8e2c85aSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f8e2c85aSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f8e2c85aSAndrew Rist  * distributed with this work for additional information
6*f8e2c85aSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f8e2c85aSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f8e2c85aSAndrew Rist  * "License"); you may not use this file except in compliance
9*f8e2c85aSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f8e2c85aSAndrew Rist  *
11*f8e2c85aSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f8e2c85aSAndrew Rist  *
13*f8e2c85aSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f8e2c85aSAndrew Rist  * software distributed under the License is distributed on an
15*f8e2c85aSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f8e2c85aSAndrew Rist  * KIND, either express or implied.  See the License for the
17*f8e2c85aSAndrew Rist  * specific language governing permissions and limitations
18*f8e2c85aSAndrew Rist  * under the License.
19*f8e2c85aSAndrew Rist  *
20*f8e2c85aSAndrew Rist  *************************************************************/
21*f8e2c85aSAndrew Rist 
22*f8e2c85aSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_shell.hxx"
26cdf0e10cSrcweir #include "internal/global.hxx"
27cdf0e10cSrcweir #include "internal/columninfo.hxx"
28cdf0e10cSrcweir #include "internal/fileextensions.hxx"
29cdf0e10cSrcweir #include "internal/metainforeader.hxx"
30cdf0e10cSrcweir #include "internal/utilities.hxx"
31cdf0e10cSrcweir #include "internal/config.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <malloc.h>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //----------------------------
36cdf0e10cSrcweir //
37cdf0e10cSrcweir //----------------------------
38cdf0e10cSrcweir 
39cdf0e10cSrcweir namespace /* private */
40cdf0e10cSrcweir {
41cdf0e10cSrcweir 	SHCOLUMNINFO ColumnInfoTable[] =
42cdf0e10cSrcweir 	{
43cdf0e10cSrcweir 		{{PSGUID_SUMMARYINFORMATION, PIDSI_TITLE},    VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Title",    L"Title"},
44cdf0e10cSrcweir 		{{PSGUID_SUMMARYINFORMATION, PIDSI_AUTHOR},   VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Author",   L"Author"},
45cdf0e10cSrcweir 		{{PSGUID_SUMMARYINFORMATION, PIDSI_SUBJECT},  VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Subject",  L"Subject"},
46cdf0e10cSrcweir 		{{PSGUID_SUMMARYINFORMATION, PIDSI_KEYWORDS}, VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Keywords", L"Keywords"},
47cdf0e10cSrcweir 		{{PSGUID_SUMMARYINFORMATION, PIDSI_COMMENTS}, VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Comments", L"Comments"},
48cdf0e10cSrcweir 		{{PSGUID_SUMMARYINFORMATION, PIDSI_PAGECOUNT},VT_BSTR, LVCFMT_LEFT, 30, SHCOLSTATE_TYPE_STR, L"Pagecount", L"Pagecount"}
49cdf0e10cSrcweir 	};
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 	size_t ColumnInfoTableSize = sizeof(ColumnInfoTable)/sizeof(ColumnInfoTable[0]);
52cdf0e10cSrcweir }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir //----------------------------
55cdf0e10cSrcweir //
56cdf0e10cSrcweir //----------------------------
57cdf0e10cSrcweir 
58cdf0e10cSrcweir CColumnInfo::CColumnInfo(long RefCnt) :
59cdf0e10cSrcweir 	m_RefCnt(RefCnt)
60cdf0e10cSrcweir {
61cdf0e10cSrcweir 	InterlockedIncrement(&g_DllRefCnt);
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir //----------------------------
65cdf0e10cSrcweir //
66cdf0e10cSrcweir //----------------------------
67cdf0e10cSrcweir 
68cdf0e10cSrcweir CColumnInfo::~CColumnInfo()
69cdf0e10cSrcweir {
70cdf0e10cSrcweir 	InterlockedDecrement(&g_DllRefCnt);
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir //-----------------------------
74cdf0e10cSrcweir // IUnknown methods
75cdf0e10cSrcweir //-----------------------------
76cdf0e10cSrcweir 
77cdf0e10cSrcweir HRESULT STDMETHODCALLTYPE CColumnInfo::QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject)
78cdf0e10cSrcweir {
79cdf0e10cSrcweir 	*ppvObject = 0;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 	if (IID_IUnknown == riid || IID_IColumnProvider == riid)
82cdf0e10cSrcweir 	{
83cdf0e10cSrcweir 		IUnknown* pUnk = static_cast<IColumnProvider*>(this);
84cdf0e10cSrcweir 		pUnk->AddRef();
85cdf0e10cSrcweir 		*ppvObject = pUnk;
86cdf0e10cSrcweir 		return S_OK;
87cdf0e10cSrcweir 	}
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	return E_NOINTERFACE;
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir //----------------------------
93cdf0e10cSrcweir //
94cdf0e10cSrcweir //----------------------------
95cdf0e10cSrcweir 
96cdf0e10cSrcweir ULONG STDMETHODCALLTYPE CColumnInfo::AddRef(void)
97cdf0e10cSrcweir {
98cdf0e10cSrcweir 	return InterlockedIncrement(&m_RefCnt);
99cdf0e10cSrcweir }
100cdf0e10cSrcweir 
101cdf0e10cSrcweir //----------------------------
102cdf0e10cSrcweir //
103cdf0e10cSrcweir //----------------------------
104cdf0e10cSrcweir 
105cdf0e10cSrcweir ULONG STDMETHODCALLTYPE CColumnInfo::Release( void)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir 	long refcnt = InterlockedDecrement(&m_RefCnt);
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	if (0 == m_RefCnt)
110cdf0e10cSrcweir 		delete this;
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 	return refcnt;
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir //-----------------------------
116cdf0e10cSrcweir // IColumnProvider
117cdf0e10cSrcweir //-----------------------------
118cdf0e10cSrcweir 
119cdf0e10cSrcweir HRESULT STDMETHODCALLTYPE CColumnInfo::Initialize(LPCSHCOLUMNINIT /*psci*/)
120cdf0e10cSrcweir {
121cdf0e10cSrcweir 	return S_OK;
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir //-----------------------------
125cdf0e10cSrcweir // Register all columns we support
126cdf0e10cSrcweir //-----------------------------
127cdf0e10cSrcweir 
128cdf0e10cSrcweir HRESULT STDMETHODCALLTYPE CColumnInfo::GetColumnInfo(DWORD dwIndex, SHCOLUMNINFO *psci)
129cdf0e10cSrcweir {
130cdf0e10cSrcweir 	if (dwIndex >= ColumnInfoTableSize)
131cdf0e10cSrcweir 		return S_FALSE;
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 	//  Return information on each column we support. Return S_FALSE
134cdf0e10cSrcweir     //  to indicate that we have returned information on all our
135cdf0e10cSrcweir     //  columns. GetColumnInfo will be called repeatedly until S_FALSE
136cdf0e10cSrcweir     //  or an error is returned
137cdf0e10cSrcweir 	psci->scid.fmtid = ColumnInfoTable[dwIndex].scid.fmtid;
138cdf0e10cSrcweir 	psci->scid.pid   = ColumnInfoTable[dwIndex].scid.pid;
139cdf0e10cSrcweir     ZeroMemory(psci->wszTitle, sizeof(psci->wszTitle));
140cdf0e10cSrcweir     wcsncpy(psci->wszTitle, ColumnInfoTable[dwIndex].wszTitle, (sizeof(psci->wszTitle) - 1));
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 	//wcscpy(psci->wszTitle, ColumnInfoTable[dwIndex].wszTitle);
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 	return S_OK;
145cdf0e10cSrcweir }
146cdf0e10cSrcweir 
147cdf0e10cSrcweir //-----------------------------
148cdf0e10cSrcweir //
149cdf0e10cSrcweir //-----------------------------
150cdf0e10cSrcweir 
151cdf0e10cSrcweir HRESULT STDMETHODCALLTYPE CColumnInfo::GetItemData(LPCSHCOLUMNID pscid, LPCSHCOLUMNDATA pscd, VARIANT *pvarData)
152cdf0e10cSrcweir {
153cdf0e10cSrcweir 	if (IsOOFileExtension(pscd->pwszExt))
154cdf0e10cSrcweir 	{
155cdf0e10cSrcweir 		try
156cdf0e10cSrcweir 		{
157cdf0e10cSrcweir 		    std::wstring fname = getShortPathName( std::wstring( pscd->wszFile ) );
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 			CMetaInfoReader meta_info_accessor(WStringToString(fname));
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 			VariantClear(pvarData);
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 			if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_TITLE)
164cdf0e10cSrcweir 			{
165cdf0e10cSrcweir 				pvarData->vt = VT_BSTR;
166cdf0e10cSrcweir 				pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_TITLE ).c_str());
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 				return S_OK;
169cdf0e10cSrcweir 			}
170cdf0e10cSrcweir 			else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_AUTHOR)
171cdf0e10cSrcweir 			{
172cdf0e10cSrcweir 				pvarData->vt = VT_BSTR;
173cdf0e10cSrcweir 				pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_AUTHOR).c_str());
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 				return S_OK;
176cdf0e10cSrcweir 			}
177cdf0e10cSrcweir 			else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_SUBJECT)
178cdf0e10cSrcweir 			{
179cdf0e10cSrcweir 				pvarData->vt = VT_BSTR;
180cdf0e10cSrcweir 				pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_SUBJECT).c_str());
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 				return S_OK;
183cdf0e10cSrcweir 			}
184cdf0e10cSrcweir 			else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_KEYWORDS)
185cdf0e10cSrcweir 			{
186cdf0e10cSrcweir 				pvarData->vt = VT_BSTR;
187cdf0e10cSrcweir 				pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_KEYWORDS).c_str());
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 				return S_OK;
190cdf0e10cSrcweir 			}
191cdf0e10cSrcweir 			else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_COMMENTS)
192cdf0e10cSrcweir 			{
193cdf0e10cSrcweir 				pvarData->vt = VT_BSTR;
194cdf0e10cSrcweir 				pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_DESCRIPTION).c_str());
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 				return S_OK;
197cdf0e10cSrcweir 			}
198cdf0e10cSrcweir 			else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_PAGECOUNT)
199cdf0e10cSrcweir 			{
200cdf0e10cSrcweir 				pvarData->vt = VT_BSTR;
201cdf0e10cSrcweir 				pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagAttribute( META_INFO_DOCUMENT_STATISTIC, META_INFO_PAGES).c_str());
202cdf0e10cSrcweir 
203cdf0e10cSrcweir 				return S_OK;
204cdf0e10cSrcweir 			}
205cdf0e10cSrcweir 		}
206cdf0e10cSrcweir 		catch (const std::exception&)
207cdf0e10cSrcweir 		{
208cdf0e10cSrcweir 			return S_FALSE;
209cdf0e10cSrcweir 		}
210cdf0e10cSrcweir 	}
211cdf0e10cSrcweir 
212cdf0e10cSrcweir 	return S_FALSE;
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir //-----------------------------
216cdf0e10cSrcweir //
217cdf0e10cSrcweir //-----------------------------
218cdf0e10cSrcweir 
219cdf0e10cSrcweir bool CColumnInfo::IsOOFileExtension(wchar_t* Extension) const
220cdf0e10cSrcweir {
221cdf0e10cSrcweir 	for (size_t i = 0; i < OOFileExtensionTableSize; i++)
222cdf0e10cSrcweir 	{
223cdf0e10cSrcweir 		if (0 == _wcsicmp(Extension, OOFileExtensionTable[i].ExtensionUnicode))
224cdf0e10cSrcweir 			return true;
225cdf0e10cSrcweir 	}
226cdf0e10cSrcweir 
227cdf0e10cSrcweir 	return false;
228cdf0e10cSrcweir }
229