summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Nabet <serval2412@yahoo.fr>2017-08-19 18:19:19 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-08-20 15:02:40 +0200
commitfe195f2c7b0c22169f265b731981bef47119f166 (patch)
tree3580c44ad08eef60502871222823a51c06eda964
parent9723634f70be3c8399d7b735d05c6cbb74a29f90 (diff)
Related tdf#111892: revamp TemplateScanner
Remove EnableSorting since it was only used with false as argument and unwind to remove too mpEntryCompare, mbSortingEnabled, InsertEntry which become useless Finally remove TemplateDir which becomes just a wrapper class for a vector Change-Id: I1e4ead009711f67fe75f3231761cc8966a39f57b Reviewed-on: https://gerrit.libreoffice.org/41333 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--sd/source/ui/dlg/TemplateScanner.cxx61
-rw-r--r--sd/source/ui/inc/TemplateScanner.hxx44
2 files changed, 8 insertions, 97 deletions
diff --git a/sd/source/ui/dlg/TemplateScanner.cxx b/sd/source/ui/dlg/TemplateScanner.cxx
index d6a447c36c14..106819e61512 100644
--- a/sd/source/ui/dlg/TemplateScanner.cxx
+++ b/sd/source/ui/dlg/TemplateScanner.cxx
@@ -107,40 +107,6 @@ int Classify (const OUString&, const OUString& rsURL)
namespace sd
{
-TemplateEntryCompare::TemplateEntryCompare():
- mpStringSorter(new comphelper::string::NaturalStringSorter(
- ::comphelper::getProcessComponentContext(),
- Application::GetSettings().GetLanguageTag().getLocale())) {}
-
-bool TemplateEntryCompare::operator()(TemplateEntry const * pA, TemplateEntry const * pB) const
-{
- return 0 > mpStringSorter->compare(pA->msTitle, pB->msTitle);
-}
-
-void TemplateDir::EnableSorting(bool bSortingEnabled)
-{
- mbSortingEnabled = bSortingEnabled;
- if (mbSortingEnabled)
- {
- if (mpEntryCompare.get() == nullptr)
- mpEntryCompare.reset(new TemplateEntryCompare);
-
- ::std::sort(maEntries.begin(), maEntries.end(), *mpEntryCompare);
- }
-}
-
-void TemplateDir::InsertEntry(TemplateEntry* pNewEntry)
-{
- if (mbSortingEnabled)
- {
- ::std::vector<TemplateEntry*>::iterator aPlaceToInsert =
- ::std::upper_bound(maEntries.begin(), maEntries.end(), pNewEntry, *mpEntryCompare);
- maEntries.insert(aPlaceToInsert, pNewEntry);
- }
- else
- maEntries.push_back(pNewEntry);
-}
-
class TemplateScanner::FolderDescriptorList
: public ::std::multiset<FolderDescriptor,FolderDescriptor::Comparator>
{
@@ -149,9 +115,7 @@ class TemplateScanner::FolderDescriptorList
TemplateScanner::TemplateScanner()
: meState(INITIALIZE_SCANNING),
maFolderContent(),
- mpTemplateDirectory(nullptr),
maFolderList(),
- mpLastAddedEntry(nullptr),
mpFolderDescriptors(new FolderDescriptorList),
mxTemplateRoot(),
mxFolderEnvironment(),
@@ -164,14 +128,6 @@ TemplateScanner::TemplateScanner()
TemplateScanner::~TemplateScanner()
{
- mpFolderDescriptors.reset();
-
- // 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 != nullptr)
- delete *I;
}
TemplateScanner::State TemplateScanner::GetTemplateRoot()
@@ -239,8 +195,7 @@ TemplateScanner::State TemplateScanner::ScanEntry()
|| (sContentType == "Impress 2.0"))
{
OUString sLocalisedTitle = SfxDocumentTemplates::ConvertResourceString(sTitle);
- mpLastAddedEntry = new TemplateEntry(sLocalisedTitle, sTargetURL);
- mpTemplateDirectory->InsertEntry(mpLastAddedEntry);
+ mpTemplateEntries.push_back(new TemplateEntry(sLocalisedTitle, sTargetURL));
}
}
@@ -249,15 +204,10 @@ TemplateScanner::State TemplateScanner::ScanEntry()
}
else
{
- if (mpTemplateDirectory->maEntries.empty())
- {
- delete mpTemplateDirectory;
- mpTemplateDirectory = nullptr;
- }
- else
+ if (!mpTemplateEntries.empty())
{
SolarMutexGuard aGuard;
- maFolderList.push_back(mpTemplateDirectory);
+ maFolderList.push_back(mpTemplateEntries);
}
// Continue with scanning the next folder.
@@ -344,9 +294,8 @@ TemplateScanner::State TemplateScanner::ScanFolder()
{
// Scan the folder and insert it into the list of template
// folders.
- mpTemplateDirectory = new TemplateDir;
- mpTemplateDirectory->EnableSorting(false);
// Continue with scanning all entries in the folder.
+ mpTemplateEntries.clear();
eNextState = INITIALIZE_ENTRY_SCAN;
}
}
@@ -394,12 +343,10 @@ void TemplateScanner::RunNextStep()
case DONE:
case ERROR:
mxTemplateRoot.clear();
- mxTemplateRoot.clear();
mxFolderEnvironment.clear();
mxEntryEnvironment.clear();
mxFolderResultSet.clear();
mxEntryResultSet.clear();
- mpLastAddedEntry = nullptr;
break;
default:
break;
diff --git a/sd/source/ui/inc/TemplateScanner.hxx b/sd/source/ui/inc/TemplateScanner.hxx
index aba6ed2c2f5a..abdc64c62313 100644
--- a/sd/source/ui/inc/TemplateScanner.hxx
+++ b/sd/source/ui/inc/TemplateScanner.hxx
@@ -55,37 +55,6 @@ public:
OUString msPath;
};
-/** Functor that compares two TemplateEntries based on their titles
-*/
-class TemplateEntryCompare
-{
-public:
- TemplateEntryCompare();
- bool operator()(TemplateEntry const * pA, TemplateEntry const * pB) const;
-
-private:
- std::shared_ptr<comphelper::string::NaturalStringSorter> mpStringSorter;
-};
-
-/** Representation of a template or layout folder.
-*/
-class TemplateDir
-{
-public:
- TemplateDir()
- : maEntries(),
- mbSortingEnabled(false), mpEntryCompare(nullptr) {}
-
- ::std::vector<TemplateEntry*> maEntries;
-
- void EnableSorting(bool bSortingEnabled);
- void InsertEntry(TemplateEntry* pNewEntry);
-
-private:
- bool mbSortingEnabled;
- std::unique_ptr<TemplateEntryCompare> mpEntryCompare;
-};
-
/** This class scans the template folders for impress templates. There are
two ways to use this class.
1. The old and deprecated way is to call Scan() to scan all templates
@@ -119,12 +88,12 @@ public:
virtual bool HasNextStep() override;
/** Return the TemplateDir object that was last added to
- mpTemplateDirectory.
+ mpTemplateEntries.
@return
<nullptr/> is returned either before the template scanning is
started or after it has ended.
*/
- const TemplateEntry* GetLastAddedEntry() const { return mpLastAddedEntry;}
+ const TemplateEntry* GetLastAddedEntry() const { return mpTemplateEntries.empty()?nullptr:mpTemplateEntries.back();}
private:
/** The current state determines which step will be executed next by
@@ -143,17 +112,12 @@ private:
State meState;
::ucbhelper::Content maFolderContent;
- TemplateDir* mpTemplateDirectory;
+ ::std::vector<TemplateEntry*> mpTemplateEntries;
/** The data structure that is to be filled with information about the
template files.
*/
- std::vector<TemplateDir*> maFolderList;
-
- /** This member points into the maFolderList to the member that was most
- recently added.
- */
- TemplateEntry* mpLastAddedEntry;
+ std::vector< ::std::vector<TemplateEntry*> > maFolderList;
/** The folders that are collected by GatherFolderList().
*/