• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kdecore
 

kdecore

  • kdecore
kshortcutlist.cpp
1 #include <tqstring.h>
2 #include <tqvariant.h>
3 
4 #include <kaccel.h>
5 #include "kaccelaction.h"
6 #include <kconfig.h>
7 #include <kdebug.h>
8 #include <kglobal.h>
9 #include <kglobalaccel.h>
10 #include <kinstance.h>
11 #include <kshortcut.h>
12 #include "kshortcutlist.h"
13 
14 //---------------------------------------------------------------------
15 // KShortcutList
16 //---------------------------------------------------------------------
17 
18 KShortcutList::KShortcutList()
19 {
20 }
21 
22 KShortcutList::~KShortcutList()
23 {
24 }
25 
26 bool KShortcutList::isGlobal( uint ) const
27 {
28  return false;
29 }
30 
31 int KShortcutList::index( const TQString& sName ) const
32 {
33  uint nSize = count();
34  for( uint i = 0;
35  i < nSize;
36  ++i )
37  if( name( i ) == sName )
38  return i;
39  return -1;
40 }
41 
42 int KShortcutList::index( const KKeySequence& seq ) const
43 {
44  if( seq.isNull() )
45  return -1;
46 
47  uint nSize = count();
48  for( uint i = 0; i < nSize; i++ ) {
49  if( shortcut(i).contains( seq ) )
50  return i;
51  }
52 
53  return -1;
54 }
55 
56 const KInstance* KShortcutList::instance() const
57 {
58  return 0;
59 }
60 
61 TQVariant KShortcutList::getOther( Other, uint ) const
62 {
63  return TQVariant();
64 }
65 
66 bool KShortcutList::setOther( Other, uint, TQVariant )
67 {
68  return false;
69 }
70 
71 bool KShortcutList::readSettings( const TQString& sConfigGroup, KConfigBase* pConfig )
72 {
73  kdDebug(125) << "KShortcutList::readSettings( \"" << sConfigGroup << "\", " << pConfig << " ) start" << endl;
74  if( !pConfig )
75  pConfig = KGlobal::config();
76  TQString sGroup = (!sConfigGroup.isEmpty()) ? sConfigGroup : TQString("Shortcuts");
77 
78  // If the config file still has the old group name:
79  // FIXME: need to rename instead? -- and don't do this if hasGroup( "Shortcuts" ).
80  if( sGroup == "Shortcuts" && pConfig->hasGroup( "Keys" ) ) {
81  readSettings( "Keys", pConfig );
82  }
83 
84  kdDebug(125) << "\treadSettings( \"" << sGroup << "\", " << pConfig << " )" << endl;
85  if( !pConfig->hasGroup( sGroup ) )
86  return true;
87  KConfigGroupSaver cgs( pConfig, sGroup );
88 
89  uint nSize = count();
90  for( uint i = 0; i < nSize; i++ ) {
91  if( isConfigurable(i) ) {
92  TQString sEntry = pConfig->readEntry( name(i) );
93  if( !sEntry.isEmpty() ) {
94  if( sEntry == "none" )
95  setShortcut( i, KShortcut() );
96  else
97  setShortcut( i, KShortcut(sEntry) );
98  }
99  else // default shortcut
100  setShortcut( i, shortcutDefault(i) );
101  kdDebug(125) << "\t" << name(i) << " = '" << sEntry << "'" << endl;
102  }
103  }
104 
105  kdDebug(125) << "KShortcutList::readSettings done" << endl;
106  return true;
107 }
108 
109 bool KShortcutList::writeSettings( const TQString &sConfigGroup, KConfigBase* pConfig, bool bWriteAll, bool bGlobal ) const
110 {
111  kdDebug(125) << "KShortcutList::writeSettings( " << sConfigGroup << ", " << pConfig << ", " << bWriteAll << ", " << bGlobal << " )" << endl;
112  if( !pConfig )
113  pConfig = KGlobal::config();
114 
115  TQString sGroup = (!sConfigGroup.isEmpty()) ? sConfigGroup : TQString("Shortcuts");
116 
117  // If it has the deprecated group [Keys], remove it
118  if( pConfig->hasGroup( "Keys" ) )
119  pConfig->deleteGroup( "Keys", true );
120 
121  KConfigGroupSaver cs( pConfig, sGroup );
122 
123  uint nSize = count();
124  for( uint i = 0; i < nSize; i++ ) {
125  if( isConfigurable(i) ) {
126  const TQString& sName = name(i);
127  bool bConfigHasAction = !pConfig->readEntry( sName ).isEmpty();
128  bool bSameAsDefault = (shortcut(i) == shortcutDefault(i));
129  // If we're using a global config or this setting
130  // differs from the default, then we want to write.
131  if( bWriteAll || !bSameAsDefault ) {
132  TQString s = shortcut(i).toStringInternal();
133  if( s.isEmpty() )
134  s = "none";
135  kdDebug(125) << "\twriting " << sName << " = " << s << endl;
136  pConfig->writeEntry( sName, s, true, bGlobal );
137  }
138  // Otherwise, this key is the same as default
139  // but exists in config file. Remove it.
140  else if( bConfigHasAction ) {
141  kdDebug(125) << "\tremoving " << sName << " because == default" << endl;
142  pConfig->deleteEntry( sName, false, bGlobal );
143  }
144  }
145  }
146 
147  pConfig->sync();
148  return true;
149 }
150 
151 //---------------------------------------------------------------------
152 // KAccelShortcutList
153 //---------------------------------------------------------------------
154 
155 class KAccelShortcutListPrivate
156 {
157  public:
158  TQString m_configGroup;
159 };
160 
161 KAccelShortcutList::KAccelShortcutList( KAccel* pAccel )
162 : m_actions( pAccel->actions() )
163 {
164  d=new KAccelShortcutListPrivate;
165  m_bGlobal = false;
166  d->m_configGroup=pAccel->configGroup();
167 }
168 
169 KAccelShortcutList::KAccelShortcutList( KGlobalAccel* pAccel )
170 : m_actions( pAccel->actions() )
171 {
172  d=new KAccelShortcutListPrivate;
173  m_bGlobal = true;
174  d->m_configGroup=pAccel->configGroup();
175 }
176 
177 KAccelShortcutList::KAccelShortcutList( KAccelActions& actions, bool bGlobal )
178 : m_actions( actions )
179 {
180  d=new KAccelShortcutListPrivate;
181  m_bGlobal = bGlobal;
182 }
183 
184 
185 KAccelShortcutList::~KAccelShortcutList()
186  { delete d;}
187 uint KAccelShortcutList::count() const
188  { return m_actions.count(); }
189 TQString KAccelShortcutList::name( uint i ) const
190  { return m_actions.actionPtr(i)->name(); }
191 TQString KAccelShortcutList::label( uint i ) const
192  { return m_actions.actionPtr(i)->label(); }
193 TQString KAccelShortcutList::whatsThis( uint i ) const
194  { return m_actions.actionPtr(i)->whatsThis(); }
195 const KShortcut& KAccelShortcutList::shortcut( uint i ) const
196  { return m_actions.actionPtr(i)->shortcut(); }
197 const KShortcut& KAccelShortcutList::shortcutDefault( uint i ) const
198  { return m_actions.actionPtr(i)->shortcutDefault(); }
199 bool KAccelShortcutList::isConfigurable( uint i ) const
200  { return m_actions.actionPtr(i)->isConfigurable(); }
201 bool KAccelShortcutList::setShortcut( uint i, const KShortcut& cut )
202  { return m_actions.actionPtr(i)->setShortcut( cut ); }
203 TQVariant KAccelShortcutList::getOther( Other, uint ) const
204  { return TQVariant(); }
205 bool KAccelShortcutList::isGlobal( uint ) const
206  { return m_bGlobal; }
207 bool KAccelShortcutList::setOther( Other, uint, TQVariant )
208  { return false; }
209 bool KAccelShortcutList::save() const
210  { return writeSettings( d->m_configGroup ); }
211 
212 void KShortcutList::virtual_hook( int, void* )
213 { /*BASE::virtual_hook( id, data );*/ }
214 
215 void KAccelShortcutList::virtual_hook( int id, void* data )
216 { KShortcutList::virtual_hook( id, data ); }
217 
218 void KStdAccel::ShortcutList::virtual_hook( int id, void* data )
219 { KShortcutList::virtual_hook( id, data ); }
220 
KAccel
Handle shortcuts.
Definition: kaccel.h:93
KConfigBase::deleteEntry
void deleteEntry(const TQString &pKey, bool bNLS=false, bool bGlobal=false)
Deletes the entry specified by pKey in the current group.
Definition: kconfigbase.cpp:1220
KShortcutList::count
virtual uint count() const =0
Returns the number of entries.
KShortcutList::shortcutDefault
virtual const KShortcut & shortcutDefault(uint index) const =0
Returns default shortcut with the given index.
KAccelShortcutList::virtual_hook
virtual void virtual_hook(int id, void *data)
used to extend the interface with virtuals without breaking binary compatibility
Definition: kshortcutlist.cpp:215
KAccelShortcutList::isConfigurable
virtual bool isConfigurable(uint index) const
Checks whether the shortcut with the given index is configurable.
Definition: kshortcutlist.cpp:199
KShortcutList::writeSettings
virtual bool writeSettings(const TQString &sConfigGroup=TQString::null, KConfigBase *pConfig=0, bool bWriteAll=false, bool bGlobal=false) const
Writes the shortcuts to the given configuration file.
Definition: kshortcutlist.cpp:109
KShortcutList::virtual_hook
virtual void virtual_hook(int id, void *data)
used to extend the interface with virtuals without breaking binary compatibility
Definition: kshortcutlist.cpp:212
KConfigBase::writeEntry
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
Writes a key/value pair.
Definition: kconfigbase.cpp:1067
KAccelShortcutList::KAccelShortcutList
KAccelShortcutList(KAccel *accel)
Creates a new KShortcutList that accesses the given KAccel.
Definition: kshortcutlist.cpp:161
KShortcutList::shortcut
virtual const KShortcut & shortcut(uint index) const =0
Returns the shortcut with the given index.
KAccelShortcutList::label
virtual TQString label(uint index) const
Returns the (i18n'd) label of the shortcut with the given index.
Definition: kshortcutlist.cpp:191
KConfigBase::sync
virtual void sync()
Flushes all changes that currently reside only in memory back to disk / permanent storage...
Definition: kconfigbase.cpp:1776
KShortcutList::KShortcutList
KShortcutList()
Default constructor.
Definition: kshortcutlist.cpp:18
KConfigBase::readEntry
TQString readEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
Reads the value of an entry specified by pKey in the current group.
Definition: kconfigbase.cpp:222
KShortcut
The KShortcut class is used to represent a keyboard shortcut to an action.
Definition: kshortcut.h:543
KShortcutList::instance
virtual const KInstance * instance() const
The KInstance.
Definition: kshortcutlist.cpp:56
KAccelShortcutList::save
virtual bool save() const
Save the shortcut list.
Definition: kshortcutlist.cpp:209
KKeySequence
A KKeySequence object holds a sequence of up to 4 keys.
Definition: kshortcut.h:288
KAccel::configGroup
const TQString & configGroup() const
Returns the configuration group of the settings.
Definition: kaccel.cpp:524
KShortcutList::index
virtual int index(const TQString &sName) const
Returns the index of the shortcut with he given name.
Definition: kshortcutlist.cpp:31
KAccelShortcutList::m_actions
KAccelActions & m_actions
Actions (collection) for this shortcut list.
Definition: kshortcutlist.h:244
KInstance
Access to KDE global objects for use in shared libraries.
Definition: kinstance.h:43
KAccelShortcutList::count
virtual uint count() const
Returns the number of entries.
Definition: kshortcutlist.cpp:187
KConfigGroupSaver
Helper class to facilitate working with KConfig / KSimpleConfig groups.
Definition: kconfigbase.h:2059
KConfigBase::deleteGroup
bool deleteGroup(const TQString &group, bool bDeep=true, bool bGlobal=false)
Deletes a configuration entry group.
Definition: kconfigbase.cpp:1253
KConfigBase
KDE Configuration Management abstract base class.
Definition: kconfigbase.h:70
KShortcutList::readSettings
virtual bool readSettings(const TQString &sConfigGroup=TQString::null, KConfigBase *pConfig=0)
Loads the shortcuts from the given configuration file.
Definition: kshortcutlist.cpp:71
KAccelShortcutList::isGlobal
virtual bool isGlobal(uint index) const
Checks whether the shortcut with the given index is saved in the global configuration.
Definition: kshortcutlist.cpp:205
KAccelShortcutList::m_bGlobal
bool m_bGlobal
Is this shortcut list global? Access through isGlobal()
Definition: kshortcutlist.h:246
KStdAccel::ShortcutList::virtual_hook
virtual void virtual_hook(int id, void *data)
used to extend the interface with virtuals without breaking binary compatibility
Definition: kshortcutlist.cpp:218
KShortcutList::isConfigurable
virtual bool isConfigurable(uint index) const =0
Checks whether the shortcut with the given index is configurable.
KAccelShortcutList::shortcutDefault
virtual const KShortcut & shortcutDefault(uint index) const
Returns default shortcut with the given index.
Definition: kshortcutlist.cpp:197
KShortcutList::setShortcut
virtual bool setShortcut(uint index, const KShortcut &shortcut)=0
Sets the shortcut of the given entry.
KShortcutList::name
virtual TQString name(uint index) const =0
Returns the name of the shortcut with the given index.
KAccelShortcutList::whatsThis
virtual TQString whatsThis(uint index) const
Returns the (i18n'd) What's This text of the shortcut with the given index.
Definition: kshortcutlist.cpp:193
KAccelShortcutList::name
virtual TQString name(uint index) const
Returns the name of the shortcut with the given index.
Definition: kshortcutlist.cpp:189
endl
kndbgstream & endl(kndbgstream &s)
Does nothing.
Definition: kdebug.h:583
KAccelShortcutList::shortcut
virtual const KShortcut & shortcut(uint index) const
Returns the shortcut with the given index.
Definition: kshortcutlist.cpp:195
KGlobalAccel::configGroup
const TQString & configGroup() const
Returns the configuration group that is used to save the accelerators.
Definition: kglobalaccel.cpp:116
KConfigBase::hasGroup
bool hasGroup(const TQString &group) const
Returns true if the specified group is known about.
Definition: kconfigbase.cpp:153
KKeySequence::isNull
bool isNull() const
Returns true if the key sequence is null (after clear() or empty constructor).
Definition: kshortcut.cpp:316
KAccelShortcutList::setShortcut
virtual bool setShortcut(uint index, const KShortcut &shortcut)
Sets the shortcut of the given entry.
Definition: kshortcutlist.cpp:201
KGlobalAccel
KGlobalAccel allows you to have global accelerators that are independent of the focused window...
Definition: kglobalaccel.h:45
KGlobal::config
static KConfig * config()
Returns the general config object.
Definition: kglobal.cpp:61
KShortcutList::isGlobal
virtual bool isGlobal(uint index) const
Checks whether the shortcut with the given index is saved in the global configuration.
Definition: kshortcutlist.cpp:26

kdecore

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

kdecore

Skip menu "kdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdecore by doxygen 1.8.6
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |