23 #include "kaccelaction.h" 24 #include "kaccelbase.h" 26 #include <tqkeycode.h> 32 #include <kkeynative.h> 34 #include <kshortcutlist.h> 40 class KAccelActionPrivate
46 KAccelAction::KAccelAction()
49 d =
new KAccelActionPrivate;
52 m_bConfigurable =
true;
55 d->m_nConnections = 0;
58 KAccelAction::KAccelAction(
const KAccelAction& action )
61 d =
new KAccelActionPrivate;
65 KAccelAction::KAccelAction(
const TQString& sName,
const TQString& sLabel,
const TQString& sWhatsThis,
67 const TQObject* pObjSlot,
const char* psMethodSlot,
68 bool bConfigurable,
bool bEnabled )
71 d =
new KAccelActionPrivate;
72 init( sName, sLabel, sWhatsThis,
74 pObjSlot, psMethodSlot,
75 bConfigurable, bEnabled );
78 KAccelAction::~KAccelAction()
84 void KAccelAction::clear()
89 m_bConfigurable =
true;
92 d->m_nConnections = 0;
95 bool KAccelAction::init(
const TQString& sName,
const TQString& sLabel,
const TQString& sWhatsThis,
97 const TQObject* pObjSlot,
const char* psMethodSlot,
98 bool bConfigurable,
bool bEnabled )
102 m_sWhatsThis = sWhatsThis;
103 m_cutDefault3 = rgCutDefaults3;
104 m_cutDefault4 = rgCutDefaults4;
105 m_pObjSlot = pObjSlot;
106 m_psMethodSlot = psMethodSlot;
107 m_bConfigurable = bConfigurable;
108 m_bEnabled = bEnabled;
111 d->m_nConnections = 0;
113 kdDebug(125) <<
"KAccelAction::init( \"" << sName <<
"\" ): created with enabled = false" <<
endl;
117 KAccelAction& KAccelAction::operator =(
const KAccelAction& action )
119 m_sName = action.m_sName;
120 m_sLabel = action.m_sLabel;
121 m_sWhatsThis = action.m_sWhatsThis;
122 m_cutDefault3 = action.m_cutDefault3;
123 m_cutDefault4 = action.m_cutDefault4;
124 m_pObjSlot = action.m_pObjSlot;
125 m_psMethodSlot = action.m_psMethodSlot;
126 m_bConfigurable = action.m_bConfigurable;
127 m_bEnabled = action.m_bEnabled;
128 m_nIDAccel = action.m_nIDAccel;
129 m_cut = action.m_cut;
130 d->m_nConnections = action.d->m_nConnections;
135 void KAccelAction::setName(
const TQString& s )
137 void KAccelAction::setLabel(
const TQString& s )
139 void KAccelAction::setWhatsThis(
const TQString& s )
140 { m_sWhatsThis = s; }
142 bool KAccelAction::setShortcut(
const KShortcut& cut )
148 void KAccelAction::setSlot(
const TQObject* pObjSlot,
const char* psMethodSlot )
150 m_pObjSlot = pObjSlot;
151 m_psMethodSlot = psMethodSlot;
154 void KAccelAction::setConfigurable(
bool b )
155 { m_bConfigurable = b; }
156 void KAccelAction::setEnabled(
bool b )
159 TQString KAccelAction::toString()
const 162 TQString KAccelAction::toStringInternal()
const 165 bool KAccelAction::setKeySequence( uint i,
const KKeySequence& seq )
167 if( i < m_cut.count() ) {
168 m_cut.setSeq( i, seq );
170 }
else if( i == m_cut.count() )
171 return m_cut.append( seq );
175 void KAccelAction::clearShortcut()
182 return m_cut.contains( seq );
183 for( uint i = 0; i < m_cut.count(); i++ ) {
184 if( m_cut.seq(i) == seq )
190 const KShortcut& KAccelAction::shortcutDefault()
const 191 {
return (useFourModifierKeys()) ? m_cutDefault4 : m_cutDefault3; }
192 bool KAccelAction::isConnected()
const 193 {
return d->m_nConnections; }
194 void KAccelAction::incConnections()
195 { d->m_nConnections++; }
196 void KAccelAction::decConnections()
197 {
if( d->m_nConnections > 0 ) d->m_nConnections--; }
200 int KAccelAction::g_bUseFourModifierKeys = -1;
202 bool KAccelAction::useFourModifierKeys()
204 if( KAccelAction::g_bUseFourModifierKeys == -1 ) {
210 return KAccelAction::g_bUseFourModifierKeys == 1;
213 void KAccelAction::useFourModifierKeys(
bool b )
215 if( KAccelAction::g_bUseFourModifierKeys != (
int)b ) {
220 kdDebug(125) <<
"Tried to use four modifier keys on a keyboard layout without a Meta key.\n";
225 kdDebug(125) <<
"bUseFourModifierKeys = " << KAccelAction::g_bUseFourModifierKeys <<
endl;
232 class KAccelActionsPrivate
237 KAccelActions::KAccelActions()
239 kdDebug(125) <<
"KAccelActions(): this = " <<
this <<
endl;
243 KAccelActions::KAccelActions(
const KAccelActions& actions )
245 kdDebug(125) <<
"KAccelActions( actions = " << &actions <<
" ): this = " <<
this <<
endl;
250 KAccelActions::KAccelActions( KAccelBase* pKAccelBase )
252 kdDebug(125) <<
"KAccelActions( KAccelBase = " << pKAccelBase <<
" ): this = " <<
this <<
endl;
253 initPrivate( pKAccelBase );
256 KAccelActions::~KAccelActions()
263 void KAccelActions::initPrivate( KAccelBase* pKAccelBase )
265 m_pKAccelBase = pKAccelBase;
266 m_nSizeAllocated = m_nSize = 0;
271 void KAccelActions::clear()
273 kdDebug(125) <<
"\tKAccelActions::clear()" <<
endl;
274 for( uint i = 0; i < m_nSize; i++ )
275 delete m_prgActions[i];
276 delete[] m_prgActions;
278 m_nSizeAllocated = m_nSize = 0;
282 bool KAccelActions::init(
const KAccelActions& actions )
285 resize( actions.count() );
286 for( uint i = 0; i < m_nSize; i++ ) {
287 KAccelAction* pAction = actions.m_prgActions[i];
289 m_prgActions[i] =
new KAccelAction( *pAction );
297 bool KAccelActions::init(
KConfigBase& config,
const TQString& sGroup )
299 kdDebug(125) <<
"KAccelActions::init( " << sGroup <<
" )" <<
endl;
300 TQMap<TQString, TQString> mapEntry = config.
entryMap( sGroup );
301 resize( mapEntry.count() );
303 TQMap<TQString, TQString>::Iterator it( mapEntry.begin() );
304 for( uint i = 0; it != mapEntry.end(); ++it, i++ ) {
305 TQString sShortcuts = *it;
308 kdDebug(125) << it.key() <<
" = " << sShortcuts <<
endl;
309 if( !sShortcuts.isEmpty() && sShortcuts !=
"none" )
310 cuts.
init( sShortcuts );
312 m_prgActions[i] =
new KAccelAction( it.key(), it.key(), it.key(),
321 void KAccelActions::resize( uint nSize )
323 if( nSize > m_nSizeAllocated ) {
324 uint nSizeAllocated = ((nSize/10) + 1) * 10;
325 KAccelAction** prgActions =
new KAccelAction* [nSizeAllocated];
328 for( uint i = 0; i < m_nSizeAllocated; i++ )
329 prgActions[i] = m_prgActions[i];
332 for( uint i = m_nSizeAllocated; i < nSizeAllocated; i++ )
335 delete[] m_prgActions;
336 m_prgActions = prgActions;
337 m_nSizeAllocated = nSizeAllocated;
343 void KAccelActions::insertPtr( KAccelAction* pAction )
345 resize( m_nSize + 1 );
346 m_prgActions[m_nSize-1] = pAction;
349 void KAccelActions::updateShortcuts( KAccelActions& actions2 )
351 kdDebug(125) <<
"KAccelActions::updateShortcuts()" <<
endl;
352 bool bChanged =
false;
354 for( uint i = 0; i < m_nSize; i++ ) {
355 KAccelAction* pAction = m_prgActions[i];
356 if( pAction && pAction->m_bConfigurable ) {
357 KAccelAction* pAction2 = actions2.actionPtr( pAction->m_sName );
359 TQString sOld = pAction->m_cut.toStringInternal();
360 pAction->m_cut = pAction2->m_cut;
361 kdDebug(125) <<
"\t" << pAction->m_sName
362 <<
" found: " << sOld
363 <<
" => " << pAction2->m_cut.toStringInternal()
364 <<
" = " << pAction->m_cut.toStringInternal() <<
endl;
371 emitKeycodeChanged();
374 int KAccelActions::actionIndex(
const TQString& sAction )
const 376 for( uint i = 0; i < m_nSize; i++ ) {
377 if( m_prgActions[i] == 0 )
378 kdWarning(125) <<
"KAccelActions::actionPtr( " << sAction <<
" ): encountered null pointer at m_prgActions[" << i <<
"]" <<
endl;
379 else if( m_prgActions[i]->m_sName == sAction )
385 KAccelAction* KAccelActions::actionPtr( uint i )
387 return m_prgActions[i];
390 const KAccelAction* KAccelActions::actionPtr( uint i )
const 392 return m_prgActions[i];
395 KAccelAction* KAccelActions::actionPtr(
const TQString& sAction )
397 int i = actionIndex( sAction );
398 return (i >= 0) ? m_prgActions[i] : 0;
401 const KAccelAction* KAccelActions::actionPtr(
const TQString& sAction )
const 403 int i = actionIndex( sAction );
404 return (i >= 0) ? m_prgActions[i] : 0;
407 KAccelAction* KAccelActions::actionPtr(
KKeySequence cut )
409 for( uint i = 0; i < m_nSize; i++ ) {
410 if( m_prgActions[i] == 0 )
411 kdWarning(125) <<
"KAccelActions::actionPtr( " << cut.toStringInternal() <<
" ): encountered null pointer at m_prgActions[" << i <<
"]" <<
endl;
412 else if( m_prgActions[i]->contains( cut ) )
413 return m_prgActions[i];
418 KAccelAction& KAccelActions::operator []( uint i )
420 return *actionPtr( i );
423 const KAccelAction& KAccelActions::operator []( uint i )
const 425 return *actionPtr( i );
428 KAccelAction* KAccelActions::insert(
const TQString& sName,
const TQString& sLabel )
430 if( actionPtr( sName ) ) {
431 kdWarning(125) <<
"KAccelActions::insertLabel( " << sName <<
", " << sLabel <<
" ): action with same name already present." <<
endl;
435 KAccelAction* pAction =
new KAccelAction;
436 pAction->m_sName = sName;
437 pAction->m_sLabel = sLabel;
438 pAction->m_bConfigurable =
false;
439 pAction->m_bEnabled =
false;
441 insertPtr( pAction );
445 KAccelAction* KAccelActions::insert(
const TQString& sAction,
const TQString& sLabel,
const TQString& sWhatsThis,
447 const TQObject* pObjSlot,
const char* psMethodSlot,
448 bool bConfigurable,
bool bEnabled )
451 if( actionPtr( sAction ) ) {
452 kdWarning(125) <<
"KAccelActions::insert( " << sAction <<
" ): action with same name already present." <<
endl;
456 KAccelAction* pAction =
new KAccelAction(
457 sAction, sLabel, sWhatsThis,
458 rgCutDefaults3, rgCutDefaults4,
459 pObjSlot, psMethodSlot,
460 bConfigurable, bEnabled );
461 insertPtr( pAction );
467 bool KAccelActions::remove(
const TQString& sAction )
469 kdDebug(125) <<
"KAccelActions::remove( \"" << sAction <<
"\" ): this = " <<
this <<
" m_pKAccelBase = " << m_pKAccelBase <<
endl;
471 int iAction = actionIndex( sAction );
476 m_pKAccelBase->slotRemoveAction( m_prgActions[iAction] );
477 delete m_prgActions[iAction];
479 for( uint i = iAction; i < m_nSize - 1; i++ )
480 m_prgActions[i] = m_prgActions[i+1];
486 bool KAccelActions::readActions(
const TQString& sConfigGroup,
KConfigBase* pConfig )
489 return accelList.readSettings( sConfigGroup, pConfig );
505 bool KAccelActions::writeActions(
const TQString &sGroup,
KConfigBase* pConfig,
506 bool bWriteAll,
bool bGlobal )
const 508 kdDebug(125) <<
"KAccelActions::writeActions( " << sGroup <<
", " << pConfig <<
", " << bWriteAll <<
", " << bGlobal <<
" )" <<
endl;
513 for( uint i = 0; i < m_nSize; i++ ) {
514 if( m_prgActions[i] == 0 ) {
515 kdWarning(125) <<
"KAccelActions::writeActions(): encountered null pointer at m_prgActions[" << i <<
"]" <<
endl;
518 const KAccelAction&
action = *m_prgActions[i];
521 bool bConfigHasAction = !pConfig->
readEntry( action.m_sName ).isEmpty();
522 bool bSameAsDefault =
true;
523 bool bWriteAction =
false;
525 if( action.m_bConfigurable ) {
526 s = action.toStringInternal();
527 bSameAsDefault = (action.m_cut == action.shortcutDefault());
535 if( bWriteAll || !bSameAsDefault )
539 kdDebug(125) <<
"\twriting " << action.m_sName <<
" = " << s <<
endl;
542 pConfig->
writeEntry( action.m_sName, s,
true, bGlobal );
546 else if( bConfigHasAction ) {
547 kdDebug(125) <<
"\tremoving " << action.m_sName <<
" because == default" <<
endl;
558 void KAccelActions::emitKeycodeChanged()
561 m_pKAccelBase->emitSignal( KAccelBase::KEYCODE_CHANGED );
564 uint KAccelActions::count()
const void deleteEntry(const TQString &pKey, bool bNLS=false, bool bGlobal=false)
Deletes the entry specified by pKey in the current group.
KShortcut shortcutDefault(StdAccel id)
Returns the hardcoded default shortcut for id.
KAction * clear(const TQObject *recvr, const char *slot, KActionCollection *parent, const char *name=0)
bool init(int keyQt)
Initializes the shortcut with the given Qt key code as the only key sequence.
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
Reads a boolean entry.
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
Writes a key/value pair.
virtual void sync()
Flushes all changes that currently reside only in memory back to disk / permanent storage...
The KShortcut class is used to represent a keyboard shortcut to an action.
A KKeySequence object holds a sequence of up to 4 keys.
KShortcutList implementation to access KAccel and KGlobalAccel lists.
virtual TQMap< TQString, TQString > entryMap(const TQString &group) const =0
Returns a map (tree) of entries for all entries in a particular group.
Helper class to facilitate working with KConfig / KSimpleConfig groups.
KDE Configuration Management abstract base class.
TQString readEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
Reads the value of an entry specified by pKey in the current group.
KAction * action(StdAction act_enum, const TQObject *recvr, const char *slot, KActionCollection *parent, const char *name=0L)
TQString toString() const
Returns a description of the shortcut as semicolon-separated ket sequences, as returned by KKeySequen...
static bool keyboardHasWinKey()
Checks whether the keyboard has a Win key.
kndbgstream & endl(kndbgstream &s)
Does nothing.
static KConfig * config()
Returns the general config object.