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

KNotify

  • sources
  • kde-4.14
  • kde-runtime
  • knotify
knotifyconfig.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2005-2009 by Olivier Goffart <ogoffart at kde.org>
3 
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2, or (at your option)
8  any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 
19  */
20 
21 #include "knotifyconfig.h"
22 
23 #include <ksharedconfig.h>
24 #include <kconfiggroup.h>
25 #include <kdebug.h>
26 #include <kglobal.h>
27 #include <QCache>
28 #include <QDataStream>
29 
30 typedef QCache<QString, KSharedConfig::Ptr> ConfigCache;
31 K_GLOBAL_STATIC_WITH_ARGS(ConfigCache , static_cache, (15))
32 
33 static KSharedConfig::Ptr retrieve_from_cache(const QString& filename, const char *resourceType="config")
34 {
35  QCache<QString, KSharedConfig::Ptr> &cache = *static_cache;
36  if (cache.contains(filename))
37  return *cache[filename];
38  KSharedConfig::Ptr m = KSharedConfig::openConfig (filename , KConfig::NoGlobals, resourceType );
39  cache.insert(filename, new KSharedConfig::Ptr(m));
40  return m;
41 }
42 
43 void KNotifyConfig::reparseConfiguration()
44 {
45  QCache<QString, KSharedConfig::Ptr> &cache = *static_cache;
46  foreach (const QString& filename, cache.keys())
47  (*cache[filename])->reparseConfiguration();
48 }
49 
50 
51 KNotifyConfig::KNotifyConfig( const QString & _appname, const ContextList & _contexts, const QString & _eventid )
52  : appname (_appname),
53  eventsfile(retrieve_from_cache(_appname+'/'+_appname + ".notifyrc" , "data" )),
54  configfile(retrieve_from_cache(_appname+QString::fromAscii( ".notifyrc" ))),
55  contexts(_contexts) , eventid(_eventid)
56 {
57 // kDebug() << appname << " , " << eventid;
58 }
59 
60 KNotifyConfig::~KNotifyConfig()
61 {
62 }
63 
64 KNotifyConfig *KNotifyConfig::copy() const
65 {
66  KNotifyConfig *config = new KNotifyConfig( appname, contexts, eventid );
67  config->title = title;
68  config->text = text;
69  config->image = KNotifyImage( image.data() );
70  config->timeout = timeout;
71  config->winId = winId;
72  config->actions = actions;
73  config->eventsfile = eventsfile;
74  config->configfile = configfile;
75  // appname, contexts, eventid already done in constructor
76 
77  return config;
78 }
79 
80 QString KNotifyConfig::readEntry( const QString & entry, bool path )
81 {
82  QPair<QString , QString> context;
83  foreach( context , contexts )
84  {
85  const QString group="Event/" + eventid + '/' + context.first + '/' + context.second;
86  if( configfile->hasGroup( group ) )
87  {
88  KConfigGroup cg(configfile, group);
89  QString p=path ? cg.readPathEntry(entry, QString()) : cg.readEntry(entry,QString());
90  if(!p.isNull())
91  return p;
92  }
93 
94  if( eventsfile->hasGroup( group ) )
95  {
96  KConfigGroup cg(eventsfile, group);
97  QString p=path ? cg.readPathEntry(entry, QString()) : cg.readEntry(entry,QString());
98  if(!p.isNull())
99  return p;
100  }
101  }
102 // kDebug() << entry << " not found in contexts ";
103  const QString group="Event/" + eventid ;
104  if(configfile->hasGroup( group ) )
105  {
106  KConfigGroup cg(configfile, group);
107  QString p=path ? cg.readPathEntry(entry, QString()) : cg.readEntry(entry,QString());
108  if(!p.isNull())
109  return p;
110  }
111 // kDebug() << entry << " not found in config ";
112  if(eventsfile->hasGroup( group ) )
113  {
114  KConfigGroup cg( eventsfile, group);
115  QString p=path ? cg.readPathEntry(entry, QString()) : cg.readEntry(entry, QString());
116  if(!p.isNull())
117  return p;
118  }
119 // kDebug() << entry << " not found !!! ";
120 
121  return QString();
122 }
123 
124 QImage KNotifyImage::toImage()
125 {
126  if (dirty)
127  {
128  if (source.size() > 4) // no way an image can fit in less than 4 bytes
129  {
130  image.loadFromData(source);
131  }
132  dirty = false;
133  }
134  return image;
135 }
QImage::loadFromData
bool loadFromData(const uchar *data, int len, const char *format)
KNotifyConfig::KNotifyConfig
KNotifyConfig(const QString &appname, const ContextList &_contexts, const QString &_eventid)
Definition: knotifyconfig.cpp:51
KNotifyConfig::eventsfile
KSharedConfig::Ptr eventsfile
Definition: knotifyconfig.h:114
KNotifyConfig::readEntry
QString readEntry(const QString &entry, bool path=false)
Definition: knotifyconfig.cpp:80
QCache::contains
bool contains(const Key &key) const
KNotifyConfig::configfile
KSharedConfig::Ptr configfile
Definition: knotifyconfig.h:114
KNotifyConfig::contexts
ContextList contexts
Definition: knotifyconfig.h:115
KNotifyConfig::reparseConfiguration
static void reparseConfiguration()
reparse the cached configs.
Definition: knotifyconfig.cpp:43
KNotifyConfig::timeout
int timeout
How long the notification should be presented (in seconds).
Definition: knotifyconfig.h:95
knotifyconfig.h
KNotifyImage::data
QByteArray data() const
Definition: knotifyconfig.h:46
KNotifyConfig::text
QString text
the text of the notification
Definition: knotifyconfig.h:85
KNotifyConfig::copy
KNotifyConfig * copy() const
Definition: knotifyconfig.cpp:64
KNotifyConfig::title
QString title
the title of the notification
Definition: knotifyconfig.h:81
QString::isNull
bool isNull() const
KNotifyImage
An image with lazy loading from the byte array.
Definition: knotifyconfig.h:37
KNotifyConfig::eventid
QString eventid
the name of the notification
Definition: knotifyconfig.h:120
KNotifyImage::toImage
QImage toImage()
Definition: knotifyconfig.cpp:124
QCache::insert
bool insert(const Key &key, T *object, int cost)
QString
QList< QPair< QString, QString > >
KNotifyConfig::actions
QStringList actions
the user-readable list of action.
Definition: knotifyconfig.h:104
retrieve_from_cache
static KSharedConfig::Ptr retrieve_from_cache(const QString &filename, const char *resourceType="config")
Definition: knotifyconfig.cpp:33
QCache
QPair
QImage
QCache::keys
QList< Key > keys() const
KNotifyConfig::winId
WId winId
The windowsID of the window that initiated the notification (it is a window in the client) ...
Definition: knotifyconfig.h:100
KNotifyConfig::image
KNotifyImage image
the pixmap to put on the notification
Definition: knotifyconfig.h:89
QByteArray::size
int size() const
KNotifyConfig::appname
QString appname
the name of the application that triggered the notification
Definition: knotifyconfig.h:109
KNotifyConfig
Represent the configuration for an event.
Definition: knotifyconfig.h:60
KNotifyConfig::~KNotifyConfig
~KNotifyConfig()
Definition: knotifyconfig.cpp:60
ConfigCache
QCache< QString, KSharedConfig::Ptr > ConfigCache
Definition: knotifyconfig.cpp:30
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:08:23 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KNotify

Skip menu "KNotify"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

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