• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kde-runtime API Reference
  • KDE Home
  • Contact Us
 

PlasmaExtraComponents

  • sources
  • kde-4.14
  • kde-runtime
  • plasma
  • declarativeimports
  • plasmaextracomponents
resourceinstance.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright 2011 Marco Martin <mart@kde.org> *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU Library General Public License as published by *
6  * the Free Software Foundation; either version 2 of the License, or *
7  * (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU Library General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU Library General Public License *
15  * along with this program; if not, write to the *
16  * Free Software Foundation, Inc., *
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18  ***************************************************************************/
19 
20 #include "resourceinstance.h"
21 
22 #include <QApplication>
23 #include <QGraphicsObject>
24 #include <QGraphicsView>
25 #include <QTimer>
26 
27 #include <KActivities/ResourceInstance>
28 #include <KDebug>
29 
30 
31 ResourceInstance::ResourceInstance(QDeclarativeItem *parent)
32  : QDeclarativeItem(parent)
33 {
34  m_syncTimer = new QTimer(this);
35  m_syncTimer->setSingleShot(true);
36  connect(m_syncTimer, SIGNAL(timeout()), this, SLOT(syncWid()));
37 }
38 
39 ResourceInstance::~ResourceInstance()
40 {
41 
42 }
43 
44 QGraphicsView *ResourceInstance::view() const
45 {
46  // It's assumed that we won't be visible on more than one view here.
47  // Anything that actually needs view() should only really care about
48  // one of them anyway though.
49  if (!scene()) {
50  return 0;
51  }
52 
53  QGraphicsView *found = 0;
54  QGraphicsView *possibleFind = 0;
55  //kDebug() << "looking through" << scene()->views().count() << "views";
56  foreach (QGraphicsView *view, scene()->views()) {
57  //kDebug() << " checking" << view << view->sceneRect()
58  // << "against" << sceneBoundingRect() << scenePos();
59  if (view->sceneRect().intersects(sceneBoundingRect()) ||
60  view->sceneRect().contains(scenePos())) {
61  //kDebug() << " found something!" << view->isActiveWindow();
62  if (view->isActiveWindow()) {
63  found = view;
64  } else {
65  possibleFind = view;
66  }
67  }
68  }
69 
70  return found ? found : possibleFind;
71 }
72 
73 void ResourceInstance::syncWid()
74 {
75  QGraphicsView *v = view();
76  if (!v) {
77  return;
78  }
79 
80  WId wid = v->topLevelWidget()->effectiveWinId();
81  if (!m_resourceInstance || m_resourceInstance->winId() != wid) {
82  delete m_resourceInstance;
83 
84  kDebug() << "Creating a new instance of the resource" << m_uri << "window id" << wid;
85  m_resourceInstance = new KActivities::ResourceInstance(wid, m_uri, m_mimetype, m_title);
86  } else {
87 
88  if (m_uri.scheme().startsWith(QLatin1String("http")) && !m_uri.hasQuery() && m_uri.path().endsWith('/')) {
89  const QString & oldPath = m_uri.path();
90  m_uri.setPath(oldPath.left(oldPath.length() - 1));
91 
92  kDebug() << "Old and new path" << oldPath << m_uri;
93 
94  } else {
95  m_resourceInstance->setUri(m_uri);
96  }
97 
98  kDebug() << "Setting" << m_uri << m_mimetype << "to window" << wid;
99 
100  m_resourceInstance->setMimetype(m_mimetype);
101  m_resourceInstance->setTitle(m_title);
102  }
103 }
104 
105 QUrl ResourceInstance::uri() const
106 {
107  return m_uri;
108 }
109 
110 void ResourceInstance::setUri(const QUrl &uri)
111 {
112  if (m_uri == uri) {
113  return;
114  }
115 
116  m_uri = uri;
117  m_syncTimer->start(100);
118 }
119 
120 QString ResourceInstance::mimetype() const
121 {
122  return m_mimetype;
123 }
124 
125 void ResourceInstance::setMimetype(const QString &mimetype)
126 {
127  if (m_mimetype == mimetype) {
128  return;
129  }
130  m_mimetype = mimetype;
131  m_syncTimer->start(100);
132 }
133 
134 QString ResourceInstance::title() const
135 {
136  return m_title;
137 }
138 
139 void ResourceInstance::setTitle(const QString &title)
140 {
141  if (m_title == title) {
142  return;
143  }
144  m_title = title;
145  m_syncTimer->start(100);
146 }
147 
148 void ResourceInstance::notifyModified()
149 {
150  //ensure the resource instance exists
151  syncWid();
152  m_resourceInstance->notifyModified();
153 }
154 
155 void ResourceInstance::notifyFocusedIn()
156 {
157  //ensure the resource instance exists
158  syncWid();
159  m_resourceInstance->notifyFocusedIn();
160 }
161 
162 
163 void ResourceInstance::notifyFocusedOut()
164 {
165  //ensure the resource instance exists
166  syncWid();
167  m_resourceInstance->notifyFocusedOut();
168 }
169 
170 #include "resourceinstance.moc"
171 
ResourceInstance::~ResourceInstance
~ResourceInstance()
Definition: resourceinstance.cpp:39
ResourceInstance::syncWid
void syncWid()
Definition: resourceinstance.cpp:73
QGraphicsItem::sceneBoundingRect
QRectF sceneBoundingRect() const
QGraphicsView::sceneRect
sceneRect
QGraphicsItem::scene
QGraphicsScene * scene() const
QUrl::setPath
void setPath(const QString &path)
ResourceInstance::view
QGraphicsView * view() const
Definition: resourceinstance.cpp:44
ResourceInstance::notifyFocusedIn
void notifyFocusedIn()
Call this method to notify the system that the resource has the focus in your application.
Definition: resourceinstance.cpp:155
QWidget::topLevelWidget
QWidget * topLevelWidget() const
QTimer
ResourceInstance::uri
QUrl uri() const
ResourceInstance::setMimetype
void setMimetype(const QString &mimetype)
Definition: resourceinstance.cpp:125
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
QUrl::path
QString path() const
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
ResourceInstance::ResourceInstance
ResourceInstance(QDeclarativeItem *parent=0)
Definition: resourceinstance.cpp:31
QString
QWidget::isActiveWindow
isActiveWindow
QUrl::scheme
QString scheme() const
ResourceInstance::notifyModified
void notifyModified()
Call this method to notify the system that you modified (the contents of) the resource.
Definition: resourceinstance.cpp:148
QUrl
ResourceInstance::setTitle
void setTitle(const QString &title)
Definition: resourceinstance.cpp:139
QLatin1String
ResourceInstance::mimetype
QString mimetype() const
QString::length
int length() const
ResourceInstance::notifyFocusedOut
void notifyFocusedOut()
Call this method to notify the system that the resource lost the focus in your application.
Definition: resourceinstance.cpp:163
QString::left
QString left(int n) const
QTimer::start
void start(int msec)
QDeclarativeItem
ResourceInstance::setUri
void setUri(const QUrl &uri)
Definition: resourceinstance.cpp:110
QWidget::effectiveWinId
WId effectiveWinId() const
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QUrl::hasQuery
bool hasQuery() const
QGraphicsView
QGraphicsItem::scenePos
QPointF scenePos() const
ResourceInstance::title
QString title() const
resourceinstance.h
QTimer::setSingleShot
void setSingleShot(bool singleShot)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:08:46 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

PlasmaExtraComponents

Skip menu "PlasmaExtraComponents"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kde-runtime API Reference

Skip menu "kde-runtime API Reference"
  • KCMShell
  • KNotify
  • Plasma Runtime
  •     PlasmaCore
  •     DragAndDrop
  •     PlasmaComponents
  •     PlasmaExtraComponents
  •     QtExtraComponents

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal