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

tdecore

  • tdecore
tdeshortcutlist.cpp
1 #include <tqstring.h>
2 #include <tqvariant.h>
3 
4 #include <tdeaccel.h>
5 #include "tdeaccelaction.h"
6 #include <tdeconfig.h>
7 #include <kdebug.h>
8 #include <tdeglobal.h>
9 #include <kglobalaccel.h>
10 #include <kinstance.h>
11 #include <tdeshortcut.h>
12 #include "tdeshortcutlist.h"
13 
14 //---------------------------------------------------------------------
15 // TDEShortcutList
16 //---------------------------------------------------------------------
17 
18 TDEShortcutList::TDEShortcutList()
19 {
20 }
21 
22 TDEShortcutList::~TDEShortcutList()
23 {
24 }
25 
26 bool TDEShortcutList::isGlobal( uint ) const
27 {
28  return false;
29 }
30 
31 int TDEShortcutList::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 TDEShortcutList::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 TDEInstance* TDEShortcutList::instance() const
57 {
58  return 0;
59 }
60 
61 TQVariant TDEShortcutList::getOther( Other, uint ) const
62 {
63  return TQVariant();
64 }
65 
66 bool TDEShortcutList::setOther( Other, uint, TQVariant )
67 {
68  return false;
69 }
70 
71 bool TDEShortcutList::readSettings( const TQString& sConfigGroup, TDEConfigBase* pConfig )
72 {
73  kdDebug(125) << "TDEShortcutList::readSettings( \"" << sConfigGroup << "\", " << pConfig << " ) start" << endl;
74  if( !pConfig )
75  pConfig = TDEGlobal::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  TDEConfigGroupSaver 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, TDEShortcut() );
96  else
97  setShortcut( i, TDEShortcut(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) << "TDEShortcutList::readSettings done" << endl;
106  return true;
107 }
108 
109 bool TDEShortcutList::writeSettings( const TQString &sConfigGroup, TDEConfigBase* pConfig, bool bWriteAll, bool bGlobal ) const
110 {
111  kdDebug(125) << "TDEShortcutList::writeSettings( " << sConfigGroup << ", " << pConfig << ", " << bWriteAll << ", " << bGlobal << " )" << endl;
112  if( !pConfig )
113  pConfig = TDEGlobal::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  TDEConfigGroupSaver 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 // TDEAccelShortcutList
153 //---------------------------------------------------------------------
154 
155 class TDEAccelShortcutListPrivate
156 {
157  public:
158  TQString m_configGroup;
159 };
160 
161 TDEAccelShortcutList::TDEAccelShortcutList( TDEAccel* pAccel )
162 : m_actions( pAccel->actions() )
163 {
164  d=new TDEAccelShortcutListPrivate;
165  m_bGlobal = false;
166  d->m_configGroup=pAccel->configGroup();
167 }
168 
169 TDEAccelShortcutList::TDEAccelShortcutList( TDEGlobalAccel* pAccel )
170 : m_actions( pAccel->actions() )
171 {
172  d=new TDEAccelShortcutListPrivate;
173  m_bGlobal = true;
174  d->m_configGroup=pAccel->configGroup();
175 }
176 
177 TDEAccelShortcutList::TDEAccelShortcutList( TDEAccelActions& actions, bool bGlobal )
178 : m_actions( actions )
179 {
180  d=new TDEAccelShortcutListPrivate;
181  m_bGlobal = bGlobal;
182 }
183 
184 
185 TDEAccelShortcutList::~TDEAccelShortcutList()
186  { delete d;}
187 uint TDEAccelShortcutList::count() const
188  { return m_actions.count(); }
189 TQString TDEAccelShortcutList::name( uint i ) const
190  { return m_actions.actionPtr(i)->name(); }
191 TQString TDEAccelShortcutList::label( uint i ) const
192  { return m_actions.actionPtr(i)->label(); }
193 TQString TDEAccelShortcutList::whatsThis( uint i ) const
194  { return m_actions.actionPtr(i)->whatsThis(); }
195 const TDEShortcut& TDEAccelShortcutList::shortcut( uint i ) const
196  { return m_actions.actionPtr(i)->shortcut(); }
197 const TDEShortcut& TDEAccelShortcutList::shortcutDefault( uint i ) const
198  { return m_actions.actionPtr(i)->shortcutDefault(); }
199 bool TDEAccelShortcutList::isConfigurable( uint i ) const
200  { return m_actions.actionPtr(i)->isConfigurable(); }
201 bool TDEAccelShortcutList::setShortcut( uint i, const TDEShortcut& cut )
202  { return m_actions.actionPtr(i)->setShortcut( cut ); }
203 TQVariant TDEAccelShortcutList::getOther( Other, uint ) const
204  { return TQVariant(); }
205 bool TDEAccelShortcutList::isGlobal( uint ) const
206  { return m_bGlobal; }
207 bool TDEAccelShortcutList::setOther( Other, uint, TQVariant )
208  { return false; }
209 bool TDEAccelShortcutList::save() const
210  { return writeSettings( d->m_configGroup ); }
211 
212 void TDEShortcutList::virtual_hook( int, void* )
213 { /*BASE::virtual_hook( id, data );*/ }
214 
215 void TDEAccelShortcutList::virtual_hook( int id, void* data )
216 { TDEShortcutList::virtual_hook( id, data ); }
217 
218 void TDEStdAccel::ShortcutList::virtual_hook( int id, void* data )
219 { TDEShortcutList::virtual_hook( id, data ); }
220 
TDEAccelShortcutList::virtual_hook
virtual void virtual_hook(int id, void *data)
used to extend the interface with virtuals without breaking binary compatibility
Definition: tdeshortcutlist.cpp:215
TDEShortcutList::instance
virtual const TDEInstance * instance() const
The TDEInstance.
Definition: tdeshortcutlist.cpp:56
TDEAccelShortcutList::m_actions
TDEAccelActions & m_actions
Actions (collection) for this shortcut list.
Definition: tdeshortcutlist.h:244
TDEAccelShortcutList::shortcut
virtual const TDEShortcut & shortcut(uint index) const
Returns the shortcut with the given index.
Definition: tdeshortcutlist.cpp:195
TDEAccelShortcutList::m_bGlobal
bool m_bGlobal
Is this shortcut list global? Access through isGlobal()
Definition: tdeshortcutlist.h:246
TDEConfigGroupSaver
Helper class to facilitate working with TDEConfig / KSimpleConfig groups.
Definition: tdeconfigbase.h:2082
TDEAccelShortcutList::setShortcut
virtual bool setShortcut(uint index, const TDEShortcut &shortcut)
Sets the shortcut of the given entry.
Definition: tdeshortcutlist.cpp:201
TDEShortcutList::TDEShortcutList
TDEShortcutList()
Default constructor.
Definition: tdeshortcutlist.cpp:18
TDEShortcutList::name
virtual TQString name(uint index) const =0
Returns the name of the shortcut with the given index.
TDEShortcutList::readSettings
virtual bool readSettings(const TQString &sConfigGroup=TQString::null, TDEConfigBase *pConfig=0)
Loads the shortcuts from the given configuration file.
Definition: tdeshortcutlist.cpp:71
KKeySequence
A KKeySequence object holds a sequence of up to 4 keys.
Definition: tdeshortcut.h:288
TDEAccel
Handle shortcuts.
Definition: tdeaccel.h:93
TDEConfigBase
KDE Configuration Management abstract base class.
Definition: tdeconfigbase.h:70
TDEAccelShortcutList::save
virtual bool save() const
Save the shortcut list.
Definition: tdeshortcutlist.cpp:209
TDEAccelShortcutList::label
virtual TQString label(uint index) const
Returns the (i18n'd) label of the shortcut with the given index.
Definition: tdeshortcutlist.cpp:191
TDEAccelShortcutList::isConfigurable
virtual bool isConfigurable(uint index) const
Checks whether the shortcut with the given index is configurable.
Definition: tdeshortcutlist.cpp:199
TDEConfigBase::writeEntry
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
Writes a key/value pair.
Definition: tdeconfigbase.cpp:1068
TDEConfigBase::deleteGroup
bool deleteGroup(const TQString &group, bool bDeep=true, bool bGlobal=false)
Deletes a configuration entry group.
Definition: tdeconfigbase.cpp:1261
TDEShortcutList::virtual_hook
virtual void virtual_hook(int id, void *data)
used to extend the interface with virtuals without breaking binary compatibility
Definition: tdeshortcutlist.cpp:212
TDEStdAccel::ShortcutList::virtual_hook
virtual void virtual_hook(int id, void *data)
used to extend the interface with virtuals without breaking binary compatibility
Definition: tdeshortcutlist.cpp:218
TDEShortcutList::shortcut
virtual const TDEShortcut & shortcut(uint index) const =0
Returns the shortcut with the given index.
TDEShortcutList::isGlobal
virtual bool isGlobal(uint index) const
Checks whether the shortcut with the given index is saved in the global configuration.
Definition: tdeshortcutlist.cpp:26
TDEAccelShortcutList::name
virtual TQString name(uint index) const
Returns the name of the shortcut with the given index.
Definition: tdeshortcutlist.cpp:189
TDEGlobalAccel
TDEGlobalAccel allows you to have global accelerators that are independent of the focused window...
Definition: kglobalaccel.h:45
TDEAccelShortcutList::whatsThis
virtual TQString whatsThis(uint index) const
Returns the (i18n'd) What's This text of the shortcut with the given index.
Definition: tdeshortcutlist.cpp:193
TDEShortcut
The TDEShortcut class is used to represent a keyboard shortcut to an action.
Definition: tdeshortcut.h:543
TDEShortcutList::setShortcut
virtual bool setShortcut(uint index, const TDEShortcut &shortcut)=0
Sets the shortcut of the given entry.
TDEShortcutList::count
virtual uint count() const =0
Returns the number of entries.
TDEShortcutList::index
virtual int index(const TQString &sName) const
Returns the index of the shortcut with he given name.
Definition: tdeshortcutlist.cpp:31
TDEAccel::configGroup
const TQString & configGroup() const
Returns the configuration group of the settings.
Definition: tdeaccel.cpp:524
TDEConfigBase::hasGroup
bool hasGroup(const TQString &group) const
Returns true if the specified group is known about.
Definition: tdeconfigbase.cpp:152
TDEGlobalAccel::configGroup
const TQString & configGroup() const
Returns the configuration group that is used to save the accelerators.
Definition: kglobalaccel.cpp:116
TDEConfigBase::deleteEntry
void deleteEntry(const TQString &pKey, bool bNLS=false, bool bGlobal=false)
Deletes the entry specified by pKey in the current group.
Definition: tdeconfigbase.cpp:1228
TDEAccelShortcutList::TDEAccelShortcutList
TDEAccelShortcutList(TDEAccel *accel)
Creates a new TDEShortcutList that accesses the given TDEAccel.
Definition: tdeshortcutlist.cpp:161
TDEShortcutList::isConfigurable
virtual bool isConfigurable(uint index) const =0
Checks whether the shortcut with the given index is configurable.
TDEGlobal::config
static TDEConfig * config()
Returns the general config object.
Definition: tdeglobal.cpp:65
endl
kndbgstream & endl(kndbgstream &s)
Does nothing.
Definition: kdebug.h:583
TDEAccelShortcutList::shortcutDefault
virtual const TDEShortcut & shortcutDefault(uint index) const
Returns default shortcut with the given index.
Definition: tdeshortcutlist.cpp:197
TDEConfigBase::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: tdeconfigbase.cpp:221
TDEShortcutList::shortcutDefault
virtual const TDEShortcut & shortcutDefault(uint index) const =0
Returns default shortcut with the given index.
KKeySequence::isNull
bool isNull() const
Returns true if the key sequence is null (after clear() or empty constructor).
Definition: tdeshortcut.cpp:316
TDEShortcutList::writeSettings
virtual bool writeSettings(const TQString &sConfigGroup=TQString::null, TDEConfigBase *pConfig=0, bool bWriteAll=false, bool bGlobal=false) const
Writes the shortcuts to the given configuration file.
Definition: tdeshortcutlist.cpp:109
TDEInstance
Access to KDE global objects for use in shared libraries.
Definition: kinstance.h:47
TDEConfigBase::sync
virtual void sync()
Flushes all changes that currently reside only in memory back to disk / permanent storage...
Definition: tdeconfigbase.cpp:1786
TDEAccelShortcutList::count
virtual uint count() const
Returns the number of entries.
Definition: tdeshortcutlist.cpp:187
TDEAccelShortcutList::isGlobal
virtual bool isGlobal(uint index) const
Checks whether the shortcut with the given index is saved in the global configuration.
Definition: tdeshortcutlist.cpp:205

tdecore

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

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.8.8
This website is maintained by Timothy Pearson.