summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorAndre Fischer <af@openoffice.org>2002-09-11 12:30:12 +0000
committerAndre Fischer <af@openoffice.org>2002-09-11 12:30:12 +0000
commitcec406c64d5f934baae31ca197e512a5af3b8e8f (patch)
tree67db7753434a16970c35977d4d87c72c6257d7c1 /sd
parentcc17a6b7f6d8c7f1fbd13d221e8dd069f02a46e6 (diff)
#103070# This file replaces TemplateThread.
Diffstat (limited to 'sd')
-rw-r--r--sd/source/ui/dlg/TemplateScanner.cxx259
-rw-r--r--sd/source/ui/inc/TemplateScanner.hxx193
2 files changed, 452 insertions, 0 deletions
diff --git a/sd/source/ui/dlg/TemplateScanner.cxx b/sd/source/ui/dlg/TemplateScanner.cxx
new file mode 100644
index 000000000000..ce7249fe03db
--- /dev/null
+++ b/sd/source/ui/dlg/TemplateScanner.cxx
@@ -0,0 +1,259 @@
+/*************************************************************************
+ *
+ * $RCSfile: TemplateScanner.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: af $ $Date: 2002-09-11 13:29:40 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#include "TemplateScanner.hxx"
+
+#ifndef _OSL_TIME_H_
+#include <osl/time.h>
+#endif
+
+#ifndef _VOS_MUTEX_HXX
+#include <vos/mutex.hxx>
+#endif
+
+#ifndef _SFXAPP_HXX
+#include <sfx2/app.hxx>
+#endif
+
+#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#endif
+
+using namespace ::rtl;
+using namespace ::ucb;
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::sdbc;
+using namespace ::com::sun::star::ucb;
+
+namespace {
+const OUString TITLE = OUString::createFromAscii ("Title");
+const OUString TARGET_DIR_URL = OUString::createFromAscii ("TargetDirURL");
+const OUString DESCRIPTION = OUString::createFromAscii ("TypeDescription");
+const OUString TARGET_URL = OUString::createFromAscii ("TargetURL");
+
+const OUString DOCTEMPLATES = OUString::createFromAscii ("com.sun.star.frame.DocumentTemplates");
+
+// These strings are used to find impress templates in the tree of
+// template files. Should probably be determined dynamically.
+const OUString IMPRESS_BIN_TEMPLATE = OUString::createFromAscii ("application/vnd.stardivision.impress");
+const OUString IMPRESS_XML_TEMPLATE = OUString::createFromAscii ("application/vnd.sun.xml.impress");
+}
+
+namespace sd
+{
+
+TemplateScanner::TemplateScanner (void)
+{
+ // empty;
+}
+
+
+
+
+TemplateScanner::~TemplateScanner (void)
+{
+ // Delete all entries of the template list that have not been
+ // transferred to another object.
+ std::vector<TemplateDir*>::iterator I;
+ for (I=maFolderList.begin(); I!=maFolderList.end(); I++)
+ if (*I != NULL)
+ delete *I;
+}
+
+
+
+
+void TemplateScanner::GetTemplateRoot (void)
+{
+ Reference<lang::XMultiServiceFactory> xFactory =
+ ::comphelper::getProcessServiceFactory ();
+
+ Reference<frame::XDocumentTemplates> xTemplates (
+ xFactory->createInstance (DOCTEMPLATES), UNO_QUERY);
+
+ if (xTemplates.is())
+ mxTemplateRoot = xTemplates->getContent();
+}
+
+
+
+
+void TemplateScanner::ScanEntries (Content& rRoot, TemplateDir* pDir)
+{
+ Reference<XCommandEnvironment> aCmdEnv;
+
+ // We are interested only in three properties: the entry's name,
+ // its URL, and its content type.
+ Sequence<OUString> aProps (3);
+ aProps[0] = TITLE;
+ aProps[1] = TARGET_URL;
+ aProps[2] = DESCRIPTION;
+
+ // Create a cursor to iterate over the templates in this folders.
+ ResultSetInclude eInclude = INCLUDE_DOCUMENTS_ONLY;
+ Reference<XResultSet> xResultSet (rRoot.createCursor (aProps, eInclude));
+
+ if (xResultSet.is())
+ {
+ Reference<XContentAccess> xContentAccess (xResultSet, UNO_QUERY);
+ Reference<XRow> xRow (xResultSet, UNO_QUERY);
+
+ // Iterate over the template folder.
+ while (xResultSet->next())
+ {
+ OUString aTitle (xRow->getString (1));
+ OUString aTargetURL (xRow->getString (2));
+ OUString aContentType (xRow->getString (3));
+
+ OUString aId = xContentAccess->queryContentIdentifierString();
+ Content aContent = Content (aId, aCmdEnv);
+ if ( ! aContent.isDocument ())
+ continue;
+
+ // Check wether the entry is an impress template. If so add a
+ // new entry to the resulting list (which is created first if
+ // necessary).
+ if ( (aContentType == IMPRESS_BIN_TEMPLATE)
+ || (aContentType == IMPRESS_XML_TEMPLATE))
+ pDir->m_aEntries.push_back (
+ new TemplateEntry (aTitle, aTargetURL));
+ }
+ }
+}
+
+
+
+
+void TemplateScanner::ScanFolders (void)
+{
+ try
+ {
+ // Create content for template folders.
+ Reference<XCommandEnvironment> aCmdEnv;
+ Content aTemplateDir (mxTemplateRoot, aCmdEnv);
+
+ // Define the list of properties we are interested in.
+ Sequence<OUString> aProps (2);
+ aProps[0] = TITLE;
+ aProps[1] = TARGET_DIR_URL;
+
+ // Create an cursor to iterate over the template folders.
+ ResultSetInclude eInclude = INCLUDE_FOLDERS_ONLY;
+ Reference<XResultSet> xResultSet (aTemplateDir.createCursor (
+ aProps, eInclude));
+
+ if (xResultSet.is())
+ {
+ Reference<XContentAccess> xContentAccess (xResultSet, UNO_QUERY);
+ Reference<XRow> xRow (xResultSet, UNO_QUERY);
+
+ while (xResultSet->next())
+ {
+ OUString aTitle (xRow->getString (1));
+ OUString aTargetDir (xRow->getString (2));
+
+ OUString aId = xContentAccess->queryContentIdentifierString();
+ Content aContent = Content (aId, aCmdEnv);
+ if (aContent.isFolder())
+ {
+ // Scan the folder and insert it into the list of
+ // template folders.
+ TemplateDir* pDir = new TemplateDir (aTitle, aTargetDir);
+ if (pDir != NULL)
+ {
+ ScanEntries (aContent, pDir);
+ if (pDir->m_aEntries.empty())
+ delete pDir;
+ else
+ {
+ ::vos::OGuard aGuard(Application::GetSolarMutex());
+ maFolderList.push_back(pDir);
+ }
+ }
+ }
+ }
+ }
+ }
+ catch(::com::sun::star::uno::Exception&)
+ {
+ // Ignore all exceptions.
+ }
+}
+
+
+
+
+void TemplateScanner::Scan (void)
+{
+ GetTemplateRoot ();
+ ScanFolders ();
+}
+
+
+
+
+std::vector<TemplateDir*>& TemplateScanner::GetFolderList (void)
+{
+ return maFolderList;
+}
+
+}
diff --git a/sd/source/ui/inc/TemplateScanner.hxx b/sd/source/ui/inc/TemplateScanner.hxx
new file mode 100644
index 000000000000..716c8fac07af
--- /dev/null
+++ b/sd/source/ui/inc/TemplateScanner.hxx
@@ -0,0 +1,193 @@
+/*************************************************************************
+ *
+ * $RCSfile: TemplateScanner.hxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: af $ $Date: 2002-09-11 13:30:12 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef _TEMPLATE_SCANNER_HXX
+#define _TEMPLATE_SCANNER_HXX
+
+#ifndef _UCBHELPER_CONTENT_HXX
+#include <ucbhelper/content.hxx>
+#endif
+
+#ifndef _COM_SUN_STAR_FRAME_XDOCUMENTTEMPLATES_HPP_
+#include <com/sun/star/frame/XDocumentTemplates.hpp>
+#endif
+
+#ifndef _COMPHELPER_PROCESSFACTORY_HXX_
+#include <comphelper/processfactory.hxx>
+#endif
+
+#ifndef _COM_SUN_STAR_UCB_XCONTENTACCESS_HPP_
+#include <com/sun/star/ucb/XContentAccess.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
+#include <com/sun/star/sdbc/XRow.hpp>
+#endif
+
+#ifndef _STRING_HXX
+#include <tools/string.hxx>
+#endif
+
+#include <vector>
+
+namespace {
+/** Representation of a template or layout file.
+*/
+class TemplateEntry
+{
+public:
+ TemplateEntry (const String& rTitle, const String& rPath)
+ : m_aTitle (rTitle), m_aPath (rPath) {}
+
+ String m_aTitle;
+ String m_aPath;
+};
+
+
+
+/** Representation of a template or layout folder.
+*/
+class TemplateDir
+{
+public:
+ TemplateDir (const String & rRegion, const String & rUrl )
+ : m_aRegion(rRegion), m_aUrl(rUrl) {}
+
+ String m_aRegion;
+ String m_aUrl;
+ std::vector<TemplateEntry*> m_aEntries;
+};
+}
+
+
+namespace sd
+{
+
+/** This class scans the template folders for impress templates and puts
+ them into listboxes. While scanning the found templates are collected
+ in a local list. After completing the scan an object of this class may
+ be called to offer this list to transfer its contents to the caller.
+ Every remaining entries are deleted from the local list in the
+ destructor. An easy way to transfer the whole list is to call the swap
+ method on an STL vector with the list as argument.
+*/
+class TemplateScanner
+{
+public:
+ /** Create a new template scanner and prepare but do not execute the scanning.
+ */
+ TemplateScanner (void);
+
+ /** The destructor deletes any remaining entries of the local list of
+ templates.
+ */
+ virtual ~TemplateScanner (void);
+
+ /** Execute the actual scanning of templates. When this method
+ terminates the result can be obtained by calling the
+ <member>GetTemplateList</member> method.
+ */
+ void Scan (void);
+
+ /** Return the list of template folders. It lies in the responsibility
+ of the caller to take ownership of some or all entries and remove
+ them from the returned list. All entries that remain until the
+ destructor is called will be destroyed.
+ */
+ std::vector<TemplateDir*>& GetFolderList (void);
+
+protected:
+ /** Set the member mxTemplateRoot to the XContent that represents the
+ root of the template tree.
+ */
+ void ScanFolders (void);
+
+ /** Scan the given template folder for impress templates and insert them
+ into the given list.
+ @param rRoot
+ specifies the folder to search.
+ @param pDir
+ The list into which the entries for the impress templates are to
+ be inserted.
+ */
+ void ScanEntries (::ucb::Content& rRoot, TemplateDir* pDir);
+
+ /** Obtain the root folder of the template folder hierarchy. The result
+ is stored in mxTemplateRoot for later use.
+ */
+ void GetTemplateRoot (void);
+
+private:
+
+ /** The data structure that is to be filled with information about the
+ template files.
+ */
+ std::vector<TemplateDir*> maFolderList;
+
+ /** The root folder of the template folders.
+ */
+ com::sun::star::uno::Reference<com::sun::star::ucb::XContent>
+ mxTemplateRoot;
+};
+
+}
+
+#endif