1 /**************************************************************************
2 * Otter Browser: Web browser controlled by the user, not vice-versa.
3 * Copyright (C) 2015 - 2018 Michal Dutkiewicz aka Emdek <michal@emdek.pl>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 **************************************************************************/
19 
20 #include "ToolBarsManager.h"
21 #include "JsonSettings.h"
22 #include "SessionsManager.h"
23 #include "Utils.h"
24 #include "../ui/ToolBarDialog.h"
25 
26 #include <QtCore/QFile>
27 #include <QtCore/QJsonArray>
28 #include <QtCore/QJsonObject>
29 #include <QtCore/QMetaEnum>
30 #include <QtWidgets/QMessageBox>
31 
32 namespace Otter
33 {
34 
35 ToolBarsManager* ToolBarsManager::m_instance(nullptr);
36 QMap<int, QString> ToolBarsManager::m_identifiers;
37 QVector<ToolBarsManager::ToolBarDefinition> ToolBarsManager::m_definitions;
38 int ToolBarsManager::m_toolBarIdentifierEnumerator(0);
39 bool ToolBarsManager::m_areToolBarsLocked(false);
40 bool ToolBarsManager::m_isLoading(false);
41 
ToolBarsManager(QObject * parent)42 ToolBarsManager::ToolBarsManager(QObject *parent) : QObject(parent),
43 	m_saveTimer(0)
44 {
45 	Q_UNUSED(QT_TRANSLATE_NOOP("actions", "Menu Bar"))
46 	Q_UNUSED(QT_TRANSLATE_NOOP("actions", "Bookmarks Bar"))
47 	Q_UNUSED(QT_TRANSLATE_NOOP("actions", "Tab Bar"))
48 	Q_UNUSED(QT_TRANSLATE_NOOP("actions", "Address Bar"))
49 	Q_UNUSED(QT_TRANSLATE_NOOP("actions", "Navigation Bar"))
50 	Q_UNUSED(QT_TRANSLATE_NOOP("actions", "Progress Bar"))
51 	Q_UNUSED(QT_TRANSLATE_NOOP("actions", "Sidebar"))
52 	Q_UNUSED(QT_TRANSLATE_NOOP("actions", "Status Bar"))
53 	Q_UNUSED(QT_TRANSLATE_NOOP("actions", "Error Console"))
54 
55 	connect(SettingsManager::getInstance(), &SettingsManager::optionChanged, this, &ToolBarsManager::handleOptionChanged);
56 }
57 
createInstance()58 void ToolBarsManager::createInstance()
59 {
60 	if (!m_instance)
61 	{
62 		m_instance = new ToolBarsManager(QCoreApplication::instance());
63 		m_toolBarIdentifierEnumerator = ToolBarsManager::staticMetaObject.indexOfEnumerator(QLatin1String("ToolBarIdentifier").data());
64 		m_areToolBarsLocked = SettingsManager::getOption(SettingsManager::Interface_LockToolBarsOption).toBool();
65 	}
66 }
67 
timerEvent(QTimerEvent * event)68 void ToolBarsManager::timerEvent(QTimerEvent *event)
69 {
70 	if (event->timerId() == m_saveTimer)
71 	{
72 		killTimer(m_saveTimer);
73 
74 		m_saveTimer = 0;
75 
76 		if (m_definitions.isEmpty())
77 		{
78 			return;
79 		}
80 
81 		QJsonArray definitionsArray;
82 		const QMap<ToolBarVisibility, QString> visibilityModes({{AlwaysVisibleToolBar, QLatin1String("visible")}, {OnHoverVisibleToolBar, QLatin1String("hover")}, {AutoVisibilityToolBar, QLatin1String("auto")}, {AlwaysHiddenToolBar, QLatin1String("hidden")}});
83 
84 		for (int i = 0; i < m_definitions.count(); ++i)
85 		{
86 			if (m_definitions.at(i).isDefault || m_definitions.at(i).wasRemoved)
87 			{
88 				continue;
89 			}
90 
91 			const QString identifier(getToolBarName(m_definitions.at(i).identifier));
92 
93 			if (identifier.isEmpty())
94 			{
95 				continue;
96 			}
97 
98 			QJsonObject definitionObject({{QLatin1String("identifier"), QJsonValue(identifier)}, {QLatin1String("title"), QJsonValue(m_definitions.at(i).title)}, {QLatin1String("normalVisibility"), QJsonValue(visibilityModes.value(m_definitions.at(i).normalVisibility))}, {QLatin1String("fullScreenVisibility"), QJsonValue(visibilityModes.value(m_definitions.at(i).fullScreenVisibility))}});
99 
100 			switch (m_definitions.at(i).type)
101 			{
102 				case BookmarksBarType:
103 					definitionObject.insert(QLatin1String("bookmarksPath"), QJsonValue(m_definitions.at(i).bookmarksPath));
104 
105 					break;
106 				case SideBarType:
107 					definitionObject.insert(QLatin1String("currentPanel"), QJsonValue(m_definitions.at(i).currentPanel));
108 					definitionObject.insert(QLatin1String("panels"), QJsonArray::fromStringList(m_definitions.at(i).panels));
109 
110 					break;
111 				default:
112 					break;
113 			}
114 
115 			switch (m_definitions.at(i).location)
116 			{
117 				case Qt::LeftToolBarArea:
118 					definitionObject.insert(QLatin1String("location"), QJsonValue(QLatin1String("left")));
119 
120 					break;
121 				case Qt::RightToolBarArea:
122 					definitionObject.insert(QLatin1String("location"), QJsonValue(QLatin1String("right")));
123 
124 					break;
125 				case Qt::TopToolBarArea:
126 					definitionObject.insert(QLatin1String("location"), QJsonValue(QLatin1String("top")));
127 
128 					break;
129 				case Qt::BottomToolBarArea:
130 					definitionObject.insert(QLatin1String("location"), QJsonValue(QLatin1String("bottom")));
131 
132 					break;
133 				default:
134 					break;
135 			}
136 
137 			switch (m_definitions.at(i).buttonStyle)
138 			{
139 				case Qt::ToolButtonTextOnly:
140 					definitionObject.insert(QLatin1String("buttonStyle"), QJsonValue(QLatin1String("textOnly")));
141 
142 					break;
143 				case Qt::ToolButtonTextBesideIcon:
144 					definitionObject.insert(QLatin1String("buttonStyle"), QJsonValue(QLatin1String("textBesideIcon")));
145 
146 					break;
147 				case Qt::ToolButtonTextUnderIcon:
148 					definitionObject.insert(QLatin1String("buttonStyle"), QJsonValue(QLatin1String("textUnderIcon")));
149 
150 					break;
151 				case Qt::ToolButtonFollowStyle:
152 					definitionObject.insert(QLatin1String("buttonStyle"), QJsonValue(QLatin1String("auto")));
153 
154 					break;
155 				default:
156 					definitionObject.insert(QLatin1String("buttonStyle"), QJsonValue(QLatin1String("iconOnly")));
157 
158 					break;
159 			}
160 
161 			if (m_definitions.at(i).iconSize > 0)
162 			{
163 				definitionObject.insert(QLatin1String("iconSize"), QJsonValue(m_definitions.at(i).iconSize));
164 			}
165 
166 			if (m_definitions.at(i).maximumButtonSize > 0)
167 			{
168 				definitionObject.insert(QLatin1String("maximumButtonSize"), QJsonValue(m_definitions.at(i).maximumButtonSize));
169 			}
170 
171 			if (m_definitions.at(i).panelSize > 0)
172 			{
173 				definitionObject.insert(QLatin1String("panelSize"), QJsonValue(m_definitions.at(i).panelSize));
174 			}
175 
176 			definitionObject.insert(QLatin1String("row"), QJsonValue(m_definitions.at(i).row));
177 
178 			if (m_definitions.at(i).hasToggle)
179 			{
180 				definitionObject.insert(QLatin1String("hasToggle"), QJsonValue(true));
181 			}
182 
183 			if (!m_definitions.at(i).entries.isEmpty())
184 			{
185 				QJsonArray actionsArray;
186 
187 				for (int j = 0; j < m_definitions.at(i).entries.count(); ++j)
188 				{
189 					actionsArray.append(encodeEntry(m_definitions.at(i).entries.at(j)));
190 				}
191 
192 				definitionObject.insert(QLatin1String("actions"), actionsArray);
193 			}
194 
195 			definitionsArray.append(definitionObject);
196 		}
197 
198 		JsonSettings settings;
199 		settings.setArray(definitionsArray);
200 		settings.save(SessionsManager::getWritableDataPath(QLatin1String("toolBars.json")));
201 	}
202 }
203 
ensureInitialized()204 void ToolBarsManager::ensureInitialized()
205 {
206 	if (m_isLoading || !m_definitions.isEmpty())
207 	{
208 		return;
209 	}
210 
211 	m_isLoading = true;
212 
213 	const QString bundledToolBarsPath(SessionsManager::getReadableDataPath(QLatin1String("toolBars.json"), true));
214 	const QHash<QString, ToolBarsManager::ToolBarDefinition> bundledDefinitions(loadToolBars(bundledToolBarsPath, true));
215 
216 	m_definitions.reserve(OtherToolBar);
217 
218 	for (int i = 0; i < OtherToolBar; ++i)
219 	{
220 		m_definitions.append(bundledDefinitions.value(getToolBarName(i)));
221 	}
222 
223 	const QString localToolBarsPath(SessionsManager::getReadableDataPath(QLatin1String("toolBars.json")));
224 
225 	if (localToolBarsPath != bundledToolBarsPath && QFile::exists(localToolBarsPath))
226 	{
227 		const QHash<QString, ToolBarDefinition> localDefinitions(loadToolBars(localToolBarsPath, false));
228 
229 		if (!localDefinitions.isEmpty())
230 		{
231 			QHash<QString, ToolBarDefinition>::const_iterator iterator;
232 
233 			for (iterator = localDefinitions.constBegin(); iterator != localDefinitions.constEnd(); ++iterator)
234 			{
235 				int identifier(getToolBarIdentifier(iterator.key()));
236 
237 //TODO Drop after migration
238 				if (identifier < 0 && iterator.key() == QLatin1String("NavigationBar") && !localDefinitions.contains(QLatin1String("AddressBar")))
239 				{
240 					identifier = AddressBar;
241 				}
242 
243 				if (identifier >= 0)
244 				{
245 					ToolBarDefinition definition(iterator.value());
246 					definition.identifier = identifier;
247 
248 					if (m_definitions[identifier] == definition)
249 					{
250 						continue;
251 					}
252 
253 					m_definitions[identifier] = definition;
254 				}
255 				else
256 				{
257 					identifier = m_definitions.count();
258 
259 					m_identifiers[identifier] = iterator.key();
260 
261 					m_definitions.append(iterator.value());
262 					m_definitions[identifier].identifier = identifier;
263 				}
264 			}
265 		}
266 	}
267 
268 	for (int i = 0; i < OtherToolBar; ++i)
269 	{
270 		if (m_definitions.count() > i)
271 		{
272 			m_definitions[i].identifier = i;
273 		}
274 	}
275 
276 	bool hasMenuBar(false);
277 
278 	for (int i = 0; i < m_definitions[MenuBar].entries.count(); ++i)
279 	{
280 		if (m_definitions[MenuBar].entries.at(i).action == QLatin1String("MenuBarWidget"))
281 		{
282 			hasMenuBar = true;
283 
284 			break;
285 		}
286 	}
287 
288 	if (!hasMenuBar)
289 	{
290 		ToolBarDefinition::Entry definition;
291 		definition.action = QLatin1String("MenuBarWidget");
292 
293 		m_definitions[MenuBar].entries.prepend(definition);
294 	}
295 
296 	bool hasTabBar(false);
297 
298 	for (int i = 0; i < m_definitions[TabBar].entries.count(); ++i)
299 	{
300 		if (m_definitions[TabBar].entries.at(i).action == QLatin1String("TabBarWidget"))
301 		{
302 			hasTabBar = true;
303 
304 			break;
305 		}
306 	}
307 
308 	if (!hasTabBar)
309 	{
310 		ToolBarDefinition::Entry definition;
311 		definition.action = QLatin1String("TabBarWidget");
312 
313 		m_definitions[TabBar].entries.prepend(definition);
314 	}
315 
316 	m_isLoading = false;
317 }
318 
addToolBar(ToolBarsManager::ToolBarType type)319 void ToolBarsManager::addToolBar(ToolBarsManager::ToolBarType type)
320 {
321 	ToolBarDefinition definition;
322 	definition.type = type;
323 
324 	switch (type)
325 	{
326 		case BookmarksBarType:
327 			definition.bookmarksPath = QLatin1Char('/');
328 
329 			break;
330 		case SideBarType:
331 			definition.panels = QStringList({QLatin1String("bookmarks"), QLatin1String("history"), QLatin1String("feeds"), QLatin1String("notes"), QLatin1String("passwords"), QLatin1String("transfers")});
332 			definition.location = Qt::LeftToolBarArea;
333 
334 			break;
335 		default:
336 			break;
337 	}
338 
339 	ToolBarDialog dialog(definition);
340 
341 	if (dialog.exec() == QDialog::Accepted)
342 	{
343 		setToolBar(dialog.getDefinition());
344 	}
345 }
346 
configureToolBar(int identifier)347 void ToolBarsManager::configureToolBar(int identifier)
348 {
349 	if (identifier >= 0 && identifier < m_definitions.count())
350 	{
351 		ToolBarDialog dialog(getToolBarDefinition(identifier));
352 
353 		if (dialog.exec() == QDialog::Accepted)
354 		{
355 			setToolBar(dialog.getDefinition());
356 		}
357 	}
358 }
359 
resetToolBar(int identifier)360 void ToolBarsManager::resetToolBar(int identifier)
361 {
362 	if (identifier >= 0 && identifier < OtherToolBar && QMessageBox::question(nullptr, tr("Reset Toolbar"), tr("Do you really want to reset this toolbar to default configuration?"), QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
363 	{
364 		setToolBar(loadToolBars(SessionsManager::getReadableDataPath(QLatin1String("toolBars.json"), true), true).value(getToolBarName(identifier)));
365 	}
366 }
367 
removeToolBar(int identifier)368 void ToolBarsManager::removeToolBar(int identifier)
369 {
370 	if (identifier >= 0 && identifier < m_definitions.count() && identifier >= OtherToolBar && QMessageBox::question(nullptr, tr("Remove Toolbar"), tr("Do you really want to remove this toolbar?"), QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
371 	{
372 		m_definitions[identifier].wasRemoved = true;
373 		m_definitions[identifier].title.clear();
374 		m_definitions[identifier].entries.clear();
375 
376 		m_instance->scheduleSave();
377 
378 		emit m_instance->toolBarRemoved(identifier);
379 	}
380 }
381 
resetToolBars()382 void ToolBarsManager::resetToolBars()
383 {
384 	if (QMessageBox::question(nullptr, tr("Reset Toolbars"), tr("Do you really want to reset all toolbars to default configuration?"), QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
385 	{
386 		return;
387 	}
388 
389 	ensureInitialized();
390 
391 	const QList<int> customToolBars(m_identifiers.keys());
392 
393 	for (int i = 0; i < customToolBars.count(); ++i)
394 	{
395 		emit m_instance->toolBarRemoved(customToolBars.at(i));
396 	}
397 
398 	const QHash<QString, ToolBarDefinition> definitions(loadToolBars(SessionsManager::getReadableDataPath(QLatin1String("toolBars.json"), true), true));
399 
400 	m_identifiers.clear();
401 	m_definitions.clear();
402 	m_definitions.reserve(definitions.count());
403 
404 	for (int i = 0; i < OtherToolBar; ++i)
405 	{
406 		m_definitions.append(definitions.value(getToolBarName(i)));
407 
408 		emit m_instance->toolBarModified(i);
409 	}
410 
411 	emit m_instance->toolBarMoved(TabBar);
412 
413 	m_instance->scheduleSave();
414 }
415 
handleOptionChanged(int identifier,const QVariant & value)416 void ToolBarsManager::handleOptionChanged(int identifier, const QVariant &value)
417 {
418 	if (identifier == SettingsManager::Interface_LockToolBarsOption)
419 	{
420 		m_areToolBarsLocked = value.toBool();
421 
422 		emit toolBarsLockedChanged(m_areToolBarsLocked);
423 	}
424 }
425 
setToolBar(ToolBarsManager::ToolBarDefinition definition)426 void ToolBarsManager::setToolBar(ToolBarsManager::ToolBarDefinition definition)
427 {
428 	ensureInitialized();
429 
430 	int identifier(definition.identifier);
431 
432 	if (definition.isValid() && identifier < OtherToolBar)
433 	{
434 		const ToolBarsManager::ToolBarDefinition defaultDefinition(loadToolBars(SessionsManager::getReadableDataPath(QLatin1String("toolBars.json"), true), true).value(getToolBarName(identifier)));
435 
436 		definition.isDefault = (defaultDefinition.isValid() && definition == defaultDefinition);
437 	}
438 
439 	if (identifier < 0 || identifier >= m_definitions.count())
440 	{
441 		QStringList toolBars;
442 		toolBars.reserve(m_definitions.count());
443 
444 		for (int i = 0; i < OtherToolBar; ++i)
445 		{
446 			toolBars.append(getToolBarName(i));
447 		}
448 
449 		toolBars.append(m_identifiers.values());
450 
451 		identifier = m_definitions.count();
452 
453 		m_identifiers[identifier] = Utils::createIdentifier(QLatin1String("CustomBar"), toolBars, false);
454 
455 		definition.identifier = identifier;
456 
457 		m_definitions.append(definition);
458 
459 		if (m_definitions[identifier].location == Qt::NoToolBarArea)
460 		{
461 			m_definitions[identifier].location = Qt::TopToolBarArea;
462 		}
463 
464 		emit m_instance->toolBarAdded(identifier);
465 	}
466 	else
467 	{
468 		const bool wasMoved(definition.location != m_definitions[identifier].location || definition.row != m_definitions[identifier].row);
469 
470 		m_definitions[identifier] = definition;
471 
472 		if (wasMoved)
473 		{
474 			emit m_instance->toolBarMoved(identifier);
475 		}
476 
477 		emit m_instance->toolBarModified(identifier);
478 	}
479 
480 	m_instance->scheduleSave();
481 }
482 
scheduleSave()483 void ToolBarsManager::scheduleSave()
484 {
485 	if (!SessionsManager::isReadOnly() && m_saveTimer == 0)
486 	{
487 		m_saveTimer = startTimer(1000);
488 	}
489 }
490 
getInstance()491 ToolBarsManager* ToolBarsManager::getInstance()
492 {
493 	return m_instance;
494 }
495 
getToolBarName(int identifier)496 QString ToolBarsManager::getToolBarName(int identifier)
497 {
498 	ensureInitialized();
499 
500 	if (identifier < OtherToolBar)
501 	{
502 		return ToolBarsManager::staticMetaObject.enumerator(m_toolBarIdentifierEnumerator).valueToKey(identifier);
503 	}
504 
505 	return m_identifiers.value(identifier);
506 }
507 
encodeEntry(const ToolBarDefinition::Entry & definition)508 QJsonValue ToolBarsManager::encodeEntry(const ToolBarDefinition::Entry &definition)
509 {
510 	if (definition.entries.isEmpty() && definition.options.isEmpty() && definition.parameters.isEmpty())
511 	{
512 		return QJsonValue(definition.action);
513 	}
514 
515 	QJsonObject actionObject({{QLatin1String("identifier"), QJsonValue(definition.action)}});
516 
517 	if (!definition.entries.isEmpty())
518 	{
519 		QJsonArray actionsArray;
520 
521 		for (int i = 0; i < definition.entries.count(); ++i)
522 		{
523 			actionsArray.append(encodeEntry(definition.entries.at(i)));
524 		}
525 
526 		actionObject.insert(QLatin1String("actions"), actionsArray);
527 	}
528 
529 	if (!definition.options.isEmpty())
530 	{
531 		actionObject.insert(QLatin1String("options"), QJsonValue::fromVariant(definition.options));
532 	}
533 
534 	if (!definition.parameters.isEmpty())
535 	{
536 		actionObject.insert(QLatin1String("parameters"), QJsonValue::fromVariant(definition.parameters));
537 	}
538 
539 	return QJsonValue(actionObject);
540 }
541 
decodeEntry(const QJsonValue & value)542 ToolBarsManager::ToolBarDefinition::Entry ToolBarsManager::decodeEntry(const QJsonValue &value)
543 {
544 	ToolBarDefinition::Entry definition;
545 
546 	if (value.isString())
547 	{
548 		definition.action = value.toString();
549 
550 		return definition;
551 	}
552 
553 	const QJsonObject actionObject(value.toObject());
554 
555 	definition.action = actionObject.value(QLatin1String("identifier")).toString();
556 	definition.options = actionObject.value(QLatin1String("options")).toObject().toVariantMap();
557 	definition.parameters = actionObject.value(QLatin1String("parameters")).toObject().toVariantMap();
558 
559 	if (actionObject.contains(QLatin1String("actions")))
560 	{
561 		const QJsonArray actionsArray(actionObject.value(QLatin1String("actions")).toArray());
562 
563 		definition.entries.reserve(actionsArray.count());
564 
565 		for (int i = 0; i < actionsArray.count(); ++i)
566 		{
567 			definition.entries.append(decodeEntry(actionsArray.at(i)));
568 		}
569 	}
570 
571 	return definition;
572 }
573 
getToolBarDefinition(int identifier)574 ToolBarsManager::ToolBarDefinition ToolBarsManager::getToolBarDefinition(int identifier)
575 {
576 	ensureInitialized();
577 
578 	if (identifier >= 0 && identifier < m_definitions.count())
579 	{
580 		ToolBarDefinition definition(m_definitions[identifier]);
581 		definition.identifier = identifier;
582 
583 		return definition;
584 	}
585 
586 	return {};
587 }
588 
loadToolBars(const QString & path,bool isDefault)589 QHash<QString, ToolBarsManager::ToolBarDefinition> ToolBarsManager::loadToolBars(const QString &path, bool isDefault)
590 {
591 	QHash<QString, ToolBarsManager::ToolBarDefinition> definitions;
592 	QFile file(path);
593 
594 	if (!file.open(QIODevice::ReadOnly))
595 	{
596 		return definitions;
597 	}
598 
599 	const QJsonArray toolBarsArray(QJsonDocument::fromJson(file.readAll()).array());
600 	const QMap<QString, ToolBarVisibility> visibilityModes({{QLatin1String("visible"), AlwaysVisibleToolBar}, {QLatin1String("hover"), OnHoverVisibleToolBar}, {QLatin1String("auto"), AutoVisibilityToolBar}, {QLatin1String("hidden"), AlwaysHiddenToolBar}});
601 
602 	file.close();
603 
604 	for (int i = 0; i < toolBarsArray.count(); ++i)
605 	{
606 		const QJsonObject toolBarObject(toolBarsArray.at(i).toObject());
607 		const QJsonArray actionsArray(toolBarObject.value(QLatin1String("actions")).toArray());
608 		const QString identifier(toolBarObject.value(QLatin1String("identifier")).toString());
609 		const QString location(toolBarObject.value(QLatin1String("location")).toString());
610 		const QString buttonStyle(toolBarObject.value(QLatin1String("buttonStyle")).toString());
611 		ToolBarDefinition definition;
612 		definition.title = toolBarObject.value(QLatin1String("title")).toString();
613 		definition.bookmarksPath = toolBarObject.value(QLatin1String("bookmarksPath")).toString();
614 		definition.currentPanel = toolBarObject.value(QLatin1String("currentPanel")).toString();
615 		definition.panels = toolBarObject.value(QLatin1String("panels")).toVariant().toStringList();
616 		definition.type = (toolBarObject.contains(QLatin1String("bookmarksPath")) ? BookmarksBarType : (toolBarObject.contains(QLatin1String("currentPanel")) ? SideBarType : ActionsBarType));
617 		definition.normalVisibility = visibilityModes.value(toolBarObject.value(QLatin1String("normalVisibility")).toString(), AlwaysVisibleToolBar);
618 		definition.fullScreenVisibility = visibilityModes.value(toolBarObject.value(QLatin1String("fullScreenVisibility")).toString(), AlwaysHiddenToolBar);
619 		definition.iconSize = toolBarObject.value(QLatin1String("iconSize")).toInt();
620 		definition.maximumButtonSize = toolBarObject.value(QLatin1String("maximumButtonSize")).toInt();
621 		definition.panelSize = toolBarObject.value(QLatin1String("panelSize")).toInt();
622 		definition.row = toolBarObject.value(QLatin1String("row")).toInt();
623 		definition.hasToggle = toolBarObject.value(QLatin1String("hasToggle")).toBool();
624 		definition.isDefault = isDefault;
625 
626 		if (isDefault)
627 		{
628 			definition.identifier = getToolBarIdentifier(identifier);
629 		}
630 
631 		if (definition.normalVisibility == OnHoverVisibleToolBar)
632 		{
633 			definition.normalVisibility = AlwaysVisibleToolBar;
634 		}
635 
636 		if (location == QLatin1String("top"))
637 		{
638 			definition.location = Qt::TopToolBarArea;
639 		}
640 		else if (location == QLatin1String("bottom"))
641 		{
642 			definition.location = Qt::BottomToolBarArea;
643 		}
644 		else if (location == QLatin1String("left"))
645 		{
646 			definition.location = Qt::LeftToolBarArea;
647 		}
648 		else if (location == QLatin1String("right"))
649 		{
650 			definition.location = Qt::RightToolBarArea;
651 		}
652 
653 		if (buttonStyle == QLatin1String("auto"))
654 		{
655 			definition.buttonStyle = Qt::ToolButtonFollowStyle;
656 		}
657 		else if (buttonStyle == QLatin1String("textOnly"))
658 		{
659 			definition.buttonStyle = Qt::ToolButtonTextOnly;
660 		}
661 		else if (buttonStyle == QLatin1String("textBesideIcon"))
662 		{
663 			definition.buttonStyle = Qt::ToolButtonTextBesideIcon;
664 		}
665 		else if (buttonStyle == QLatin1String("textUnderIcon"))
666 		{
667 			definition.buttonStyle = Qt::ToolButtonTextUnderIcon;
668 		}
669 
670 		definition.entries.reserve(actionsArray.count());
671 
672 		for (int j = 0; j < actionsArray.count(); ++j)
673 		{
674 			definition.entries.append(decodeEntry(actionsArray.at(j)));
675 		}
676 
677 		definitions[identifier] = definition;
678 	}
679 
680 	return definitions;
681 }
682 
getToolBarDefinitions(Qt::ToolBarAreas areas)683 QVector<ToolBarsManager::ToolBarDefinition> ToolBarsManager::getToolBarDefinitions(Qt::ToolBarAreas areas)
684 {
685 	ensureInitialized();
686 
687 	QVector<ToolBarsManager::ToolBarDefinition> definitions;
688 	definitions.reserve(m_definitions.count());
689 
690 	for (int i = 0; i < m_definitions.count(); ++i)
691 	{
692 		if (!m_definitions.at(i).wasRemoved && (areas == Qt::AllToolBarAreas || areas.testFlag(m_definitions.at(i).location)))
693 		{
694 			definitions.append(m_definitions.at(i));
695 		}
696 	}
697 
698 	definitions.squeeze();
699 
700 	return definitions;
701 }
702 
getToolBarIdentifier(const QString & name)703 int ToolBarsManager::getToolBarIdentifier(const QString &name)
704 {
705 	ensureInitialized();
706 
707 	const int identifier(m_identifiers.key(name, -1));
708 
709 	if (identifier >= 0)
710 	{
711 		return identifier;
712 	}
713 
714 	return ToolBarsManager::staticMetaObject.enumerator(m_toolBarIdentifierEnumerator).keyToValue(name.toLatin1());
715 }
716 
areToolBarsLocked()717 bool ToolBarsManager::areToolBarsLocked()
718 {
719 	return m_areToolBarsLocked;
720 }
721 
722 }
723