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 .
20 #include "internal/global.hxx"
21 #include "internal/columninfo.hxx"
22 #include "internal/fileextensions.hxx"
23 #include "internal/metainforeader.hxx"
24 #include "internal/utilities.hxx"
25 #include "internal/config.hxx"
27 #include <sal/macros.h>
31 #pragma GCC diagnostic warning "-Wmissing-braces"
36 namespace /* private */
38 SHCOLUMNINFO ColumnInfoTable
[] =
40 {{PSGUID_SUMMARYINFORMATION
, PIDSI_TITLE
}, VT_BSTR
, LVCFMT_LEFT
, 30, SHCOLSTATE_TYPE_STR
, L
"Title", L
"Title"},
41 {{PSGUID_SUMMARYINFORMATION
, PIDSI_AUTHOR
}, VT_BSTR
, LVCFMT_LEFT
, 30, SHCOLSTATE_TYPE_STR
, L
"Author", L
"Author"},
42 {{PSGUID_SUMMARYINFORMATION
, PIDSI_SUBJECT
}, VT_BSTR
, LVCFMT_LEFT
, 30, SHCOLSTATE_TYPE_STR
, L
"Subject", L
"Subject"},
43 {{PSGUID_SUMMARYINFORMATION
, PIDSI_KEYWORDS
}, VT_BSTR
, LVCFMT_LEFT
, 30, SHCOLSTATE_TYPE_STR
, L
"Keywords", L
"Keywords"},
44 {{PSGUID_SUMMARYINFORMATION
, PIDSI_COMMENTS
}, VT_BSTR
, LVCFMT_LEFT
, 30, SHCOLSTATE_TYPE_STR
, L
"Comments", L
"Comments"},
45 {{PSGUID_SUMMARYINFORMATION
, PIDSI_PAGECOUNT
},VT_BSTR
, LVCFMT_LEFT
, 30, SHCOLSTATE_TYPE_STR
, L
"Pagecount", L
"Pagecount"}
48 size_t ColumnInfoTableSize
= sizeof(ColumnInfoTable
)/sizeof(ColumnInfoTable
[0]);
53 CColumnInfo::CColumnInfo(long RefCnt
) :
56 InterlockedIncrement(&g_DllRefCnt
);
61 CColumnInfo::~CColumnInfo()
63 InterlockedDecrement(&g_DllRefCnt
);
70 HRESULT STDMETHODCALLTYPE
CColumnInfo::QueryInterface(REFIID riid
, void __RPC_FAR
*__RPC_FAR
*ppvObject
)
74 if (IID_IUnknown
== riid
|| IID_IColumnProvider
== riid
)
76 IUnknown
* pUnk
= static_cast<IColumnProvider
*>(this);
87 ULONG STDMETHODCALLTYPE
CColumnInfo::AddRef()
89 return InterlockedIncrement(&m_RefCnt
);
94 ULONG STDMETHODCALLTYPE
CColumnInfo::Release()
96 long refcnt
= InterlockedDecrement(&m_RefCnt
);
108 HRESULT STDMETHODCALLTYPE
CColumnInfo::Initialize(LPCSHCOLUMNINIT
/*psci*/)
113 // Register all columns we support
114 HRESULT STDMETHODCALLTYPE
CColumnInfo::GetColumnInfo(DWORD dwIndex
, SHCOLUMNINFO
*psci
)
116 if (dwIndex
>= ColumnInfoTableSize
)
119 // Return information on each column we support. Return S_FALSE
120 // to indicate that we have returned information on all our
121 // columns. GetColumnInfo will be called repeatedly until S_FALSE
122 // or an error is returned
123 psci
->scid
.fmtid
= ColumnInfoTable
[dwIndex
].scid
.fmtid
;
124 psci
->scid
.pid
= ColumnInfoTable
[dwIndex
].scid
.pid
;
125 ZeroMemory(psci
->wszTitle
, sizeof(psci
->wszTitle
));
126 wcsncpy(psci
->wszTitle
, ColumnInfoTable
[dwIndex
].wszTitle
,
127 (sizeof(psci
->wszTitle
) / sizeof(psci
->wszTitle
[0]) - 1));
132 HRESULT STDMETHODCALLTYPE
CColumnInfo::GetItemData(LPCSHCOLUMNID pscid
, LPCSHCOLUMNDATA pscd
, VARIANT
*pvarData
)
134 if (IsOOFileExtension(pscd
->pwszExt
))
138 std::wstring fname
= getShortPathName( std::wstring( pscd
->wszFile
) );
140 CMetaInfoReader
meta_info_accessor(WStringToString(fname
));
142 VariantClear(pvarData
);
144 if (IsEqualGUID (pscid
->fmtid
, FMTID_SummaryInformation
) && pscid
->pid
== PIDSI_TITLE
)
146 pvarData
->vt
= VT_BSTR
;
147 pvarData
->bstrVal
= SysAllocString(meta_info_accessor
.getTagData( META_INFO_TITLE
).c_str());
151 else if (IsEqualGUID (pscid
->fmtid
, FMTID_SummaryInformation
) && pscid
->pid
== PIDSI_AUTHOR
)
153 pvarData
->vt
= VT_BSTR
;
154 pvarData
->bstrVal
= SysAllocString(meta_info_accessor
.getTagData( META_INFO_AUTHOR
).c_str());
158 else if (IsEqualGUID (pscid
->fmtid
, FMTID_SummaryInformation
) && pscid
->pid
== PIDSI_SUBJECT
)
160 pvarData
->vt
= VT_BSTR
;
161 pvarData
->bstrVal
= SysAllocString(meta_info_accessor
.getTagData( META_INFO_SUBJECT
).c_str());
165 else if (IsEqualGUID (pscid
->fmtid
, FMTID_SummaryInformation
) && pscid
->pid
== PIDSI_KEYWORDS
)
167 pvarData
->vt
= VT_BSTR
;
168 pvarData
->bstrVal
= SysAllocString(meta_info_accessor
.getTagData( META_INFO_KEYWORDS
).c_str());
172 else if (IsEqualGUID (pscid
->fmtid
, FMTID_SummaryInformation
) && pscid
->pid
== PIDSI_COMMENTS
)
174 pvarData
->vt
= VT_BSTR
;
175 pvarData
->bstrVal
= SysAllocString(meta_info_accessor
.getTagData( META_INFO_DESCRIPTION
).c_str());
179 else if (IsEqualGUID (pscid
->fmtid
, FMTID_SummaryInformation
) && pscid
->pid
== PIDSI_PAGECOUNT
)
181 pvarData
->vt
= VT_BSTR
;
182 pvarData
->bstrVal
= SysAllocString(meta_info_accessor
.getTagAttribute( META_INFO_DOCUMENT_STATISTIC
, META_INFO_PAGES
).c_str());
187 catch (const std::exception
&)
198 bool CColumnInfo::IsOOFileExtension(wchar_t* Extension
) const
200 for (size_t i
= 0; i
< OOFileExtensionTableSize
; i
++)
202 if (0 == _wcsicmp(Extension
, OOFileExtensionTable
[i
].ExtensionUnicode
))
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */