LibreOffice Module shell (master) 1
columninfo.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <global.hxx>
21#include <columninfo.hxx>
22#include <fileextensions.hxx>
23#include <metainforeader.hxx>
24#include <utilities.hxx>
25#include <config.hxx>
26
27#include <sal/macros.h>
28#include <malloc.h>
29
30namespace /* private */
31{
32 const SHCOLUMNINFO ColumnInfoTable[] =
33 {
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"}
40 };
41
42 size_t ColumnInfoTableSize = SAL_N_ELEMENTS(ColumnInfoTable);
43
44bool IsOOFileExtension(wchar_t const * Extension)
45{
46 for (size_t i = 0; i < OOFileExtensionTableSize; i++)
47 {
48 if (0 == _wcsicmp(Extension, OOFileExtensionTable[i].ExtensionU))
49 return true;
50 }
51
52 return false;
53}
54
55}
56
57
59 m_RefCnt(RefCnt)
60{
61 InterlockedIncrement(&g_DllRefCnt);
62}
63
64
66{
67 InterlockedDecrement(&g_DllRefCnt);
68}
69
70
71// IUnknown methods
72
73
74COM_DECLSPEC_NOTHROW HRESULT STDMETHODCALLTYPE CColumnInfo::QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject)
75{
76 *ppvObject = nullptr;
77
78 if (IID_IUnknown == riid || IID_IColumnProvider == riid)
79 {
80 IUnknown* pUnk = this;
81 pUnk->AddRef();
82 *ppvObject = pUnk;
83 return S_OK;
84 }
85
86 return E_NOINTERFACE;
87}
88
89
90COM_DECLSPEC_NOTHROW ULONG STDMETHODCALLTYPE CColumnInfo::AddRef()
91{
92 return InterlockedIncrement(&m_RefCnt);
93}
94
95
96COM_DECLSPEC_NOTHROW ULONG STDMETHODCALLTYPE CColumnInfo::Release()
97{
98 LONG refcnt = InterlockedDecrement(&m_RefCnt);
99
100 if (0 == m_RefCnt)
101 delete this;
102
103 return refcnt;
104}
105
106
107// IColumnProvider
108
109
110COM_DECLSPEC_NOTHROW HRESULT STDMETHODCALLTYPE CColumnInfo::Initialize(LPCSHCOLUMNINIT /*psci*/)
111{
112 return S_OK;
113}
114
115// Register all columns we support
116COM_DECLSPEC_NOTHROW HRESULT STDMETHODCALLTYPE CColumnInfo::GetColumnInfo(DWORD dwIndex, SHCOLUMNINFO *psci)
117{
118 if (dwIndex >= ColumnInfoTableSize)
119 return S_FALSE;
120
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);
130
131 return S_OK;
132}
133
134COM_DECLSPEC_NOTHROW HRESULT STDMETHODCALLTYPE CColumnInfo::GetItemData(LPCSHCOLUMNID pscid, LPCSHCOLUMNDATA pscd, VARIANT *pvarData)
135{
136 if (IsOOFileExtension(pscd->pwszExt))
137 {
138 try
139 {
140 std::wstring fname = getShortPathName( std::wstring( pscd->wszFile ) );
141
142 CMetaInfoReader meta_info_accessor(fname);
143
144 VariantClear(pvarData);
145
146 if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_TITLE)
147 {
148 pvarData->vt = VT_BSTR;
149 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_TITLE ).c_str());
150
151 return S_OK;
152 }
153 else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_AUTHOR)
154 {
155 pvarData->vt = VT_BSTR;
156 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_AUTHOR).c_str());
157
158 return S_OK;
159 }
160 else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_SUBJECT)
161 {
162 pvarData->vt = VT_BSTR;
163 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_SUBJECT).c_str());
164
165 return S_OK;
166 }
167 else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_KEYWORDS)
168 {
169 pvarData->vt = VT_BSTR;
170 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_KEYWORDS).c_str());
171
172 return S_OK;
173 }
174 else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_COMMENTS)
175 {
176 pvarData->vt = VT_BSTR;
177 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagData( META_INFO_DESCRIPTION).c_str());
178
179 return S_OK;
180 }
181 else if (IsEqualGUID (pscid->fmtid, FMTID_SummaryInformation) && pscid->pid == PIDSI_PAGECOUNT)
182 {
183 pvarData->vt = VT_BSTR;
184 pvarData->bstrVal = SysAllocString(meta_info_accessor.getTagAttribute( META_INFO_DOCUMENT_STATISTIC, META_INFO_PAGES).c_str());
185
186 return S_OK;
187 }
188 }
189 catch (const std::exception&)
190 {
191 return S_FALSE;
192 }
193 }
194
195 return S_FALSE;
196}
197
198/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual COM_DECLSPEC_NOTHROW ULONG STDMETHODCALLTYPE Release() override
Definition: columninfo.cxx:96
virtual COM_DECLSPEC_NOTHROW HRESULT STDMETHODCALLTYPE GetItemData(LPCSHCOLUMNID pscid, LPCSHCOLUMNDATA pscd, VARIANT *pvarData) override
Definition: columninfo.cxx:134
virtual COM_DECLSPEC_NOTHROW HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject) override
Definition: columninfo.cxx:74
virtual COM_DECLSPEC_NOTHROW ULONG STDMETHODCALLTYPE AddRef() override
Definition: columninfo.cxx:90
CColumnInfo(LONG RefCnt=1)
Definition: columninfo.cxx:58
virtual ~CColumnInfo()
Definition: columninfo.cxx:65
virtual COM_DECLSPEC_NOTHROW HRESULT STDMETHODCALLTYPE Initialize(LPCSHCOLUMNINIT psci) override
Definition: columninfo.cxx:110
virtual COM_DECLSPEC_NOTHROW HRESULT STDMETHODCALLTYPE GetColumnInfo(DWORD dwIndex, SHCOLUMNINFO *psci) override
Definition: columninfo.cxx:116
std::wstring getTagData(const std::wstring &TagName)
Get a specific tag content, compound tags will be returned as comma separated list.
std::wstring getTagAttribute(const std::wstring &TagName, const std::wstring &AttributeName)
Get a specific attribute content.
#define META_INFO_AUTHOR
Definition: config.hxx:35
#define META_INFO_DOCUMENT_STATISTIC
Definition: config.hxx:49
#define META_INFO_SUBJECT
Definition: config.hxx:36
#define META_INFO_KEYWORDS
Definition: config.hxx:37
#define META_INFO_TITLE
Definition: config.hxx:34
#define META_INFO_DESCRIPTION
Definition: config.hxx:39
#define META_INFO_PAGES
Definition: config.hxx:41
const FileExtensionEntry OOFileExtensionTable[]
const size_t OOFileExtensionTableSize
#define SAL_N_ELEMENTS(arr)
int i
LONG g_DllRefCnt
Definition: propertyhdl.cxx:39
#define VT_BSTR
LONG
std::wstring getShortPathName(const std::wstring &aLongName)
helper function to convert windows paths to short form.
Definition: utilities.cxx:122