File indexing completed on 2024-05-19 16:34:36

0001 /*
0002     SPDX-FileCopyrightText: 2022 MBition GmbH
0003     SPDX-FileContributor: Kai Uwe Broulik <kai_uwe.broulik@mbition.io>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "sharedqmlengine.h"
0009 
0010 #include <QQmlContext>
0011 #include <QQmlEngine>
0012 
0013 #include <KLocalizedContext>
0014 
0015 namespace KWin
0016 {
0017 
0018 std::weak_ptr<QQmlEngine> SharedQmlEngine::s_engine;
0019 
0020 SharedQmlEngine::Ptr SharedQmlEngine::engine()
0021 {
0022     auto ret = s_engine.lock();
0023     if (!ret) {
0024         ret = std::make_shared<QQmlEngine>();
0025 
0026         auto *i18nContext = new KLocalizedContext(ret.get());
0027         ret->rootContext()->setContextObject(i18nContext);
0028 
0029         s_engine = ret;
0030     }
0031     return ret;
0032 }
0033 
0034 } // namespace KWin