File indexing completed on 2025-02-23 04:35:14

0001 // SPDX-FileCopyrightText: 2019 Linus Jahn <lnj@kaidan.im>
0002 // SPDX-License-Identifier: GPL-3.0-or-later
0003 
0004 #include "plasmatube.h"
0005 
0006 #include "config.h"
0007 
0008 #include <KLocalizedString>
0009 
0010 #include <QGuiApplication>
0011 #include <QNetworkProxy>
0012 #include <QSettings>
0013 #include <QStringBuilder>
0014 
0015 PlasmaTube::PlasmaTube(QObject *parent)
0016     : QObject(parent)
0017     , m_controller(new VideoController(this))
0018     , m_sourceManager(new SourceManager(this))
0019 {
0020     setApplicationProxy();
0021     m_sourceManager->load();
0022     connect(m_sourceManager, &SourceManager::sourceSelected, this, &PlasmaTube::sourceSelected);
0023 }
0024 
0025 PlasmaTube &PlasmaTube::instance()
0026 {
0027     static PlasmaTube instance;
0028     return instance;
0029 }
0030 
0031 VideoController *PlasmaTube::videoController() const
0032 {
0033     return m_controller;
0034 }
0035 
0036 SourceManager *PlasmaTube::sourceManager() const
0037 {
0038     return m_sourceManager;
0039 }
0040 
0041 VideoSource *PlasmaTube::selectedSource()
0042 {
0043     return m_sourceManager->selectedSource();
0044 }
0045 
0046 void PlasmaTube::setApplicationProxy()
0047 {
0048     PlasmaTubeSettings settings(KSharedConfig::openConfig(QStringLiteral("plasmatuberc"), KConfig::SimpleConfig, QStandardPaths::AppConfigLocation));
0049     QNetworkProxy proxy;
0050 
0051     // type match to ProxyType from config.kcfg
0052     switch (settings.proxyType()) {
0053     case 1: // HTTP
0054         proxy.setType(QNetworkProxy::HttpProxy);
0055         proxy.setHostName(settings.proxyHost());
0056         proxy.setPort(settings.proxyPort());
0057         proxy.setUser(settings.proxyUser());
0058         proxy.setPassword(settings.proxyPassword());
0059         break;
0060         break;
0061     case 0: // System Default
0062     default:
0063         // do nothing
0064         break;
0065     }
0066 
0067     QNetworkProxy::setApplicationProxy(proxy);
0068 }
0069 
0070 #include "moc_plasmatube.cpp"