From 4739f509d9d5ebaef71a51cece8f75b6a7e4b3dc Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Fri, 7 Sep 2018 13:11:58 +0200 Subject: Move ProfileManager to libweb --- src/profilemanager.cpp | 102 ------------------------------------------------- 1 file changed, 102 deletions(-) delete mode 100644 src/profilemanager.cpp (limited to 'src/profilemanager.cpp') diff --git a/src/profilemanager.cpp b/src/profilemanager.cpp deleted file mode 100644 index 5b0f76e..0000000 --- a/src/profilemanager.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* - * This file is part of smolbote. It's copyrighted by the contributors recorded - * in the version control history of the file, available from its original - * location: https://neueland.iserlohn-fortress.net/smolbote.hg - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#include "profilemanager.h" -#include -#include -#include -#include - -ProfileManager *ProfileManager::s_instance = nullptr; - -ProfileManager::ProfileManager(const QHash &profileSection, QObject *parent) : QObject(parent) - , defaults(profileSection) -{ -} - -void ProfileManager::setInstance(ProfileManager *instance) -{ - Q_CHECK_PTR(instance); - s_instance = instance; -} - -ProfileManager *ProfileManager::instance() -{ - Q_CHECK_PTR(s_instance); - return s_instance; -} - -WebProfile *ProfileManager::loadProfile(const QString &path) -{ - WebProfile *profile = nullptr; -#ifdef QT_DEBUG - qDebug("==> Reading profile config : %s", qUtf8Printable(path)); -#endif - - const QString id = QFileInfo(path).baseName(); - QSettings config(path, QSettings::IniFormat); - - if(config.value("otr", true).toBool()) { - profile = new WebProfile(config.value("name", id).toString(), path, nullptr); - } else { - profile = new WebProfile(id, config.value("name", id).toString(), path, nullptr); - } - - Q_CHECK_PTR(profile); - profiles.insert(id, profile); - - profile->setSearch(config.value("search", defaults.value("profile.search")).toString()); - profile->setHomepage(config.value("homepage", defaults.value("profile.homepage")).toUrl()); - profile->setNewtab(config.value("newtab", defaults.value("profile.newtab")).toUrl()); - - config.beginGroup("properties"); - { - const auto keys = config.childKeys(); - for(const QString &key : keys) { -#ifdef QT_DEBUG - qDebug("- set property %s to %s", qUtf8Printable(key), qUtf8Printable(config.value(key).toString())); -#endif - profile->setProperty(qUtf8Printable(key), config.value(key)); - } - } - config.endGroup(); // properties - - config.beginGroup("attributes"); - { - const auto keys = config.childKeys(); - auto *settings = profile->settings(); - for(const QString &key : keys) { -#ifdef QT_DEBUG - qDebug("- set attribute %s to %s", qUtf8Printable(key), qUtf8Printable(config.value(key).toString())); -#endif - auto attribute = static_cast(key.toInt()); - settings->setAttribute(attribute, config.value(key).toBool()); - } - } - config.endGroup(); - - return profile; -} - -const QString ProfileManager::id(WebProfile *profile) -{ - return profiles.key(profile); -} - -WebProfile *ProfileManager::profile(const QString &id) -{ - if(profiles.contains(id)) - return profiles.value(id); - else - return nullptr; -} - -const QMap &ProfileManager::profileList() -{ - return profiles; -} -- cgit v1.2.1