Warning, file /office/calligra/libs/main/KoTemplateGroup.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 Copyright (C) 2000 Werner Trobin <trobin@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "KoTemplateGroup.h" 0021 0022 #include <KoTemplate.h> 0023 0024 #include <QFile> 0025 0026 KoTemplateGroup::KoTemplateGroup(const QString &name, const QString &dir, 0027 int _sortingWeight, bool touched) : 0028 m_name(name), m_touched(touched), m_sortingWeight(_sortingWeight) 0029 { 0030 m_dirs.append(dir); 0031 } 0032 0033 KoTemplateGroup::~KoTemplateGroup() 0034 { 0035 qDeleteAll(m_templates); 0036 } 0037 0038 bool KoTemplateGroup::isHidden() const 0039 { 0040 0041 QList<KoTemplate*>::const_iterator it = m_templates.begin(); 0042 bool hidden = true; 0043 while (it != m_templates.end() && hidden) { 0044 hidden = (*it)->isHidden(); 0045 ++it; 0046 } 0047 return hidden; 0048 } 0049 0050 void KoTemplateGroup::setHidden(bool hidden) const 0051 { 0052 foreach (KoTemplate* t, m_templates) 0053 t->setHidden(hidden); 0054 0055 m_touched = true; 0056 } 0057 0058 bool KoTemplateGroup::add(KoTemplate *t, bool force, bool touch) 0059 { 0060 0061 KoTemplate *myTemplate = find(t->name()); 0062 if (myTemplate == 0) { 0063 m_templates.append(t); 0064 m_touched = touch; 0065 return true; 0066 } else if (myTemplate && force) { 0067 //kDebug( 30003 ) <<"removing :" << myTemplate->fileName(); 0068 QFile::remove(myTemplate->fileName()); 0069 QFile::remove(myTemplate->picture()); 0070 QFile::remove(myTemplate->file()); 0071 m_templates.removeAll(myTemplate); 0072 delete myTemplate; 0073 m_templates.append(t); 0074 m_touched = touch; 0075 return true; 0076 } else if (myTemplate) { 0077 m_templates.append(t); 0078 return true; 0079 } 0080 return false; 0081 } 0082 0083 KoTemplate *KoTemplateGroup::find(const QString &name) const 0084 { 0085 QList<KoTemplate*>::const_iterator it = m_templates.begin(); 0086 KoTemplate* ret = nullptr; 0087 0088 while (it != m_templates.end()) { 0089 if ((*it)->name() == name) { 0090 ret = *it; 0091 break; 0092 } 0093 0094 ++it; 0095 } 0096 0097 return ret; 0098 } 0099