| 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 |
#pragma once |
| 21 |
|
| 22 |
#include <rtl/ref.hxx> |
| 23 |
|
| 24 |
#include <cppuhelper/implbase.hxx> |
| 25 |
|
| 26 |
#include <com/sun/star/document/XDocumentEventListener.hpp> |
| 27 |
#include <com/sun/star/embed/XStorage.hpp> |
| 28 |
#include <com/sun/star/frame/XModel3.hpp> |
| 29 |
#include <com/sun/star/frame/XModuleManager2.hpp> |
| 30 |
#include <com/sun/star/frame/XGlobalEventBroadcaster.hpp> |
| 31 |
#include <com/sun/star/uno/XComponentContext.hpp> |
| 32 |
#include <com/sun/star/util/DateTime.hpp> |
| 33 |
#include <com/sun/star/util/XCloseListener.hpp> |
| 34 |
|
| 35 |
#include <map> |
| 36 |
#include <mutex> |
| 37 |
#include <unordered_map> |
| 38 |
#include <utility> |
| 39 |
|
| 40 |
namespace tdoc_ucp { |
| 41 |
|
| 42 |
class ContentProvider; |
| 43 |
|
| 44 |
struct StorageInfo |
| 45 |
{ |
| 46 |
OUString aTitle; |
| 47 |
css::uno::Reference< css::embed::XStorage > xStorage; |
| 48 |
css::uno::Reference< css::frame::XModel > xModel; |
| 49 |
std::unordered_map<OUString, css::util::DateTime> streamDateModified; |
| 50 |
|
| 51 |
StorageInfo() {}; // needed for STL map only. |
| 52 |
|
| 53 |
StorageInfo( |
| 54 |
OUString _aTitle, |
| 55 |
css::uno::Reference< css::embed::XStorage > _xStorage, |
| 56 |
css::uno::Reference< css::frame::XModel > _xModel ) |
| 57 |
: aTitle(std::move( _aTitle )), xStorage(std::move( _xStorage )), xModel(std::move( _xModel )) {} |
| 58 |
}; |
| 59 |
|
| 60 |
|
| 61 |
typedef std::map< OUString, StorageInfo > DocumentList; |
| 62 |
|
| 63 |
|
| 64 |
class OfficeDocumentsManager : |
| 65 |
public cppu::WeakImplHelper< css::document::XDocumentEventListener > |
| 66 |
{ |
| 67 |
class OfficeDocumentsCloseListener : |
| 68 |
public cppu::WeakImplHelper< css::util::XCloseListener > |
| 69 |
|
| 70 |
{ |
| 71 |
public: |
| 72 |
explicit OfficeDocumentsCloseListener( OfficeDocumentsManager * pMgr ) |
| 73 |
: m_pManager( pMgr ) {} |
| 74 |
|
| 75 |
// util::XCloseListener |
| 76 |
virtual void SAL_CALL queryClosing( |
| 77 |
const css::lang::EventObject& Source, |
| 78 |
sal_Bool GetsOwnership ) override; |
| 79 |
|
| 80 |
virtual void SAL_CALL notifyClosing( |
| 81 |
const css::lang::EventObject& Source ) override; |
| 82 |
|
| 83 |
// lang::XEventListener (base of util::XCloseListener) |
| 84 |
virtual void SAL_CALL disposing( |
| 85 |
const css::lang::EventObject & Source ) override; |
| 86 |
|
| 87 |
void Dispose() { m_pManager = nullptr; } |
| 88 |
|
| 89 |
private: |
| 90 |
OfficeDocumentsManager * m_pManager; |
| 91 |
}; |
| 92 |
|
| 93 |
public: |
| 94 |
OfficeDocumentsManager( |
| 95 |
const css::uno::Reference< css::uno::XComponentContext > & rxContext, |
| 96 |
ContentProvider * pDocEventListener ); |
| 97 |
virtual ~OfficeDocumentsManager() override; |
| 98 |
|
| 99 |
void destroy(); |
| 100 |
|
| 101 |
// document::XDocumentEventListener |
| 102 |
virtual void SAL_CALL documentEventOccured( |
| 103 |
const css::document::DocumentEvent & Event ) override; |
| 104 |
|
| 105 |
// lang::XEventListener (base of document::XDocumentEventListener) |
| 106 |
virtual void SAL_CALL disposing( |
| 107 |
const css::lang::EventObject & Source ) override; |
| 108 |
|
| 109 |
// Non-interface |
| 110 |
css::uno::Reference< css::embed::XStorage > |
| 111 |
queryStorage( const OUString & rDocId ); |
| 112 |
|
| 113 |
static OUString queryDocumentId( |
| 114 |
const css::uno::Reference< css::frame::XModel > & xModel ); |
| 115 |
|
| 116 |
css::uno::Reference< css::frame::XModel > |
| 117 |
queryDocumentModel( const OUString & rDocId ); |
| 118 |
|
| 119 |
css::uno::Sequence< OUString > |
| 120 |
queryDocuments(); |
| 121 |
|
| 122 |
OUString |
| 123 |
queryStorageTitle( const OUString & rDocId ); |
| 124 |
|
| 125 |
css::util::DateTime queryStreamDateModified(OUString const & uri); |
| 126 |
|
| 127 |
void updateStreamDateModified(OUString const & uri); |
| 128 |
|
| 129 |
private: |
| 130 |
void buildDocumentsList(); |
| 131 |
|
| 132 |
bool isOfficeDocument( |
| 133 |
const css::uno::Reference< css::uno::XInterface > & xDoc ); |
| 134 |
|
| 135 |
static bool isDocumentPreview( |
| 136 |
const css::uno::Reference< css::frame::XModel3 > & xModel ); |
| 137 |
|
| 138 |
static bool isWithoutOrInTopLevelFrame( |
| 139 |
const css::uno::Reference< css::frame::XModel > & xModel ); |
| 140 |
|
| 141 |
bool |
| 142 |
isBasicIDE( |
| 143 |
const css::uno::Reference< css::frame::XModel > & xModel ); |
| 144 |
|
| 145 |
static bool isHelpDocument( |
| 146 |
const css::uno::Reference< css::frame::XModel > & xModel ); |
| 147 |
|
| 148 |
std::mutex m_aMtx; |
| 149 |
css::uno::Reference< css::uno::XComponentContext > m_xContext; |
| 150 |
css::uno::Reference< css::frame::XGlobalEventBroadcaster > m_xDocEvtNotifier; |
| 151 |
css::uno::Reference< css::frame::XModuleManager2 > m_xModuleMgr; |
| 152 |
DocumentList m_aDocs; |
| 153 |
ContentProvider * const m_pDocEventListener; |
| 154 |
::rtl::Reference<OfficeDocumentsCloseListener> const m_xDocCloseListener; |
| 155 |
}; |
| 156 |
|
| 157 |
} // namespace tdoc_ucp |
| 158 |
|
| 159 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |