1 /*
2  * %kadu copyright begin%
3  * Copyright 2012, 2013, 2014 Rafał Przemysław Malinowski (rafal.przemyslaw.malinowski@gmail.com)
4  * %kadu copyright end%
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <QtCore/QDir>
21 #include <QtCore/QFile>
22 #include <QtCore/QFileInfo>
23 #include <QtCore/QRegExp>
24 #include <QtGui/QTextBlock>
25 #include <QtGui/QTextDocument>
26 
27 #include "formatted-string/formatted-string-visitor.h"
28 #include "icons/icons-manager.h"
29 #include "protocols/services/chat-image-service.h"
30 #include "services/image-storage-service.h"
31 
32 #include "composite-formatted-string.h"
33 
CompositeFormattedString(std::vector<std::unique_ptr<FormattedString>> && items)34 CompositeFormattedString::CompositeFormattedString(std::vector<std::unique_ptr<FormattedString>> &&items) :
35 		Items{std::move(items)}
36 {
37 }
38 
~CompositeFormattedString()39 CompositeFormattedString::~CompositeFormattedString()
40 {
41 }
42 
operator ==(const FormattedString & compareTo)43 bool CompositeFormattedString::operator == (const FormattedString &compareTo)
44 {
45 	const CompositeFormattedString *compareToPointer = dynamic_cast<const CompositeFormattedString *>(&compareTo);
46 	if (!compareToPointer)
47 		return false;
48 
49 	if (Items.size() != compareToPointer->Items.size())
50 		return false;
51 
52 	int size = Items.size();
53 	for (int i = 0; i < size; i++)
54 		if (*Items.at(i) != *compareToPointer->Items.at(i))
55 			return false;
56 
57 	return true;
58 }
59 
accept(FormattedStringVisitor * visitor) const60 void CompositeFormattedString::accept(FormattedStringVisitor *visitor) const
61 {
62 	visitor->beginVisit(this);
63 
64 	for (auto &&item : Items)
65 		item->accept(visitor);
66 
67 	visitor->endVisit(this);
68 }
69 
items() const70 const std::vector<std::unique_ptr<FormattedString>> & CompositeFormattedString::items() const
71 {
72 	return Items;
73 }
74 
isEmpty() const75 bool CompositeFormattedString::isEmpty() const
76 {
77 	for (auto &&item : Items)
78 		if (!item->isEmpty())
79 			return false;
80 
81 	return true;
82 }
83