Warning, file /frameworks/kactivities/src/imports/resourceinstance.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2011-2015 Marco Martin <mart@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "resourceinstance.h" 0008 0009 #include <QQuickWindow> 0010 #include <QTimer> 0011 0012 #include <KActivities/ResourceInstance> 0013 #include <QDebug> 0014 0015 namespace KActivities 0016 { 0017 namespace Imports 0018 { 0019 ResourceInstance::ResourceInstance(QQuickItem *parent) 0020 : QQuickItem(parent) 0021 { 0022 m_syncTimer = new QTimer(this); 0023 m_syncTimer->setSingleShot(true); 0024 connect(m_syncTimer, &QTimer::timeout, this, &ResourceInstance::syncWid); 0025 } 0026 0027 ResourceInstance::~ResourceInstance() 0028 { 0029 } 0030 0031 void ResourceInstance::syncWid() 0032 { 0033 QWindow *w = window(); 0034 if (!w) { 0035 return; 0036 } 0037 0038 WId wid = w->winId(); 0039 if (!m_resourceInstance || m_resourceInstance->winId() != wid) { 0040 // qDebug() << "Creating a new instance of the resource" << m_uri << "window id" << wid; 0041 m_resourceInstance.reset(new KActivities::ResourceInstance(wid, m_uri, m_mimetype, m_title)); 0042 } else { 0043 m_resourceInstance->setUri(m_uri); 0044 m_resourceInstance->setMimetype(m_mimetype); 0045 m_resourceInstance->setTitle(m_title); 0046 } 0047 } 0048 0049 QUrl ResourceInstance::uri() const 0050 { 0051 return m_uri; 0052 } 0053 0054 void ResourceInstance::setUri(const QUrl &uri) 0055 { 0056 if (m_uri == uri) { 0057 return; 0058 } 0059 0060 m_uri = uri.adjusted(QUrl::StripTrailingSlash); 0061 m_syncTimer->start(100); 0062 } 0063 0064 QString ResourceInstance::mimetype() const 0065 { 0066 return m_mimetype; 0067 } 0068 0069 void ResourceInstance::setMimetype(const QString &mimetype) 0070 { 0071 if (m_mimetype == mimetype) { 0072 return; 0073 } 0074 m_mimetype = mimetype; 0075 m_syncTimer->start(100); 0076 } 0077 0078 QString ResourceInstance::title() const 0079 { 0080 return m_title; 0081 } 0082 0083 void ResourceInstance::setTitle(const QString &title) 0084 { 0085 if (m_title == title) { 0086 return; 0087 } 0088 m_title = title; 0089 m_syncTimer->start(100); 0090 } 0091 0092 void ResourceInstance::notifyModified() 0093 { 0094 // ensure the resource instance exists 0095 syncWid(); 0096 m_resourceInstance->notifyModified(); 0097 } 0098 0099 void ResourceInstance::notifyFocusedIn() 0100 { 0101 // ensure the resource instance exists 0102 syncWid(); 0103 m_resourceInstance->notifyFocusedIn(); 0104 } 0105 0106 void ResourceInstance::notifyFocusedOut() 0107 { 0108 // ensure the resource instance exists 0109 syncWid(); 0110 m_resourceInstance->notifyFocusedOut(); 0111 } 0112 0113 } 0114 }