23#include "tdeaccelaction.h"
24#include "tdeaccelbase.h"
32#include <kkeynative.h>
34#include <tdeshortcutlist.h>
40class TDEAccelActionPrivate
46TDEAccelAction::TDEAccelAction()
49 d =
new TDEAccelActionPrivate;
52 m_bConfigurable =
true;
55 d->m_nConnections = 0;
58TDEAccelAction::TDEAccelAction(
const TDEAccelAction& action )
61 d =
new TDEAccelActionPrivate;
65TDEAccelAction::TDEAccelAction(
const TQString& sName,
const TQString& sLabel,
const TQString& sWhatsThis,
67 const TQObject* pObjSlot,
const char* psMethodSlot,
68 bool bConfigurable,
bool bEnabled )
71 d =
new TDEAccelActionPrivate;
72 init( sName, sLabel, sWhatsThis,
74 pObjSlot, psMethodSlot,
75 bConfigurable, bEnabled );
78TDEAccelAction::~TDEAccelAction()
84void TDEAccelAction::clear()
89 m_bConfigurable =
true;
92 d->m_nConnections = 0;
95bool TDEAccelAction::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) <<
"TDEAccelAction::init( \"" << sName <<
"\" ): created with enabled = false" <<
endl;
117TDEAccelAction& TDEAccelAction::operator =(
const TDEAccelAction& action )
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;
130 d->m_nConnections =
action.d->m_nConnections;
135void TDEAccelAction::setName(
const TQString& s )
137void TDEAccelAction::setLabel(
const TQString& s )
139void TDEAccelAction::setWhatsThis(
const TQString& s )
140 { m_sWhatsThis = s; }
142bool TDEAccelAction::setShortcut(
const TDEShortcut& cut )
148void TDEAccelAction::setSlot(
const TQObject* pObjSlot,
const char* psMethodSlot )
150 m_pObjSlot = pObjSlot;
151 m_psMethodSlot = psMethodSlot;
154void TDEAccelAction::setConfigurable(
bool b )
155 { m_bConfigurable = b; }
156void TDEAccelAction::setEnabled(
bool b )
159TQString TDEAccelAction::toString()
const
160 {
return m_cut.toString(); }
162TQString TDEAccelAction::toStringInternal()
const
165bool TDEAccelAction::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 );
175void TDEAccelAction::clearShortcut()
182 return m_cut.contains( seq );
183 for( uint i = 0; i < m_cut.count(); i++ ) {
184 if( m_cut.seq(i) == seq )
190const TDEShortcut& TDEAccelAction::shortcutDefault()
const
191 {
return (useFourModifierKeys()) ? m_cutDefault4 : m_cutDefault3; }
192bool TDEAccelAction::isConnected()
const
193 {
return d->m_nConnections; }
194void TDEAccelAction::incConnections()
195 { d->m_nConnections++; }
196void TDEAccelAction::decConnections()
197 {
if( d->m_nConnections > 0 ) d->m_nConnections--; }
200int TDEAccelAction::g_bUseFourModifierKeys = -1;
202bool TDEAccelAction::useFourModifierKeys()
204 if( TDEAccelAction::g_bUseFourModifierKeys == -1 ) {
210 return TDEAccelAction::g_bUseFourModifierKeys == 1;
213void TDEAccelAction::useFourModifierKeys(
bool b )
215 if( TDEAccelAction::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 = " << TDEAccelAction::g_bUseFourModifierKeys <<
endl;
232class TDEAccelActionsPrivate
237TDEAccelActions::TDEAccelActions()
239 kdDebug(125) <<
"TDEAccelActions(): this = " <<
this <<
endl;
243TDEAccelActions::TDEAccelActions(
const TDEAccelActions& actions )
245 kdDebug(125) <<
"TDEAccelActions( actions = " << &actions <<
" ): this = " <<
this <<
endl;
250TDEAccelActions::TDEAccelActions( TDEAccelBase* pTDEAccelBase )
252 kdDebug(125) <<
"TDEAccelActions( TDEAccelBase = " << pTDEAccelBase <<
" ): this = " <<
this <<
endl;
253 initPrivate( pTDEAccelBase );
256TDEAccelActions::~TDEAccelActions()
263void TDEAccelActions::initPrivate( TDEAccelBase* pTDEAccelBase )
265 m_pTDEAccelBase = pTDEAccelBase;
266 m_nSizeAllocated = m_nSize = 0;
271void TDEAccelActions::clear()
273 kdDebug(125) <<
"\tTDEAccelActions::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;
282bool TDEAccelActions::init(
const TDEAccelActions& actions )
285 resize( actions.count() );
286 for( uint i = 0; i < m_nSize; i++ ) {
287 TDEAccelAction* pAction = actions.m_prgActions[i];
289 m_prgActions[i] =
new TDEAccelAction( *pAction );
297bool TDEAccelActions::init(
TDEConfigBase& config,
const TQString& sGroup )
299 kdDebug(125) <<
"TDEAccelActions::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 TDEAccelAction( it.key(), it.key(), it.key(),
321void TDEAccelActions::resize( uint nSize )
323 if( nSize > m_nSizeAllocated ) {
324 uint nSizeAllocated = ((nSize/10) + 1) * 10;
325 TDEAccelAction** prgActions =
new TDEAccelAction* [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;
343void TDEAccelActions::insertPtr( TDEAccelAction* pAction )
345 resize( m_nSize + 1 );
346 m_prgActions[m_nSize-1] = pAction;
349void TDEAccelActions::updateShortcuts( TDEAccelActions& actions2 )
351 kdDebug(125) <<
"TDEAccelActions::updateShortcuts()" <<
endl;
352 bool bChanged =
false;
354 for( uint i = 0; i < m_nSize; i++ ) {
355 TDEAccelAction* pAction = m_prgActions[i];
356 if( pAction && pAction->m_bConfigurable ) {
357 TDEAccelAction* 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();
374int TDEAccelActions::actionIndex(
const TQString& sAction )
const
376 for( uint i = 0; i < m_nSize; i++ ) {
377 if( m_prgActions[i] == 0 )
378 kdWarning(125) <<
"TDEAccelActions::actionPtr( " << sAction <<
" ): encountered null pointer at m_prgActions[" << i <<
"]" <<
endl;
379 else if( m_prgActions[i]->m_sName == sAction )
385TDEAccelAction* TDEAccelActions::actionPtr( uint i )
387 return m_prgActions[i];
390const TDEAccelAction* TDEAccelActions::actionPtr( uint i )
const
392 return m_prgActions[i];
395TDEAccelAction* TDEAccelActions::actionPtr(
const TQString& sAction )
397 int i = actionIndex( sAction );
398 return (i >= 0) ? m_prgActions[i] : 0;
401const TDEAccelAction* TDEAccelActions::actionPtr(
const TQString& sAction )
const
403 int i = actionIndex( sAction );
404 return (i >= 0) ? m_prgActions[i] : 0;
407TDEAccelAction* TDEAccelActions::actionPtr(
KKeySequence cut )
409 for( uint i = 0; i < m_nSize; i++ ) {
410 if( m_prgActions[i] == 0 )
411 kdWarning(125) <<
"TDEAccelActions::actionPtr( " <<
cut.toStringInternal() <<
" ): encountered null pointer at m_prgActions[" << i <<
"]" <<
endl;
412 else if( m_prgActions[i]->contains( cut ) )
413 return m_prgActions[i];
418TDEAccelAction& TDEAccelActions::operator []( uint i )
420 return *actionPtr( i );
423const TDEAccelAction& TDEAccelActions::operator []( uint i )
const
425 return *actionPtr( i );
428TDEAccelAction* TDEAccelActions::insert(
const TQString& sName,
const TQString& sLabel )
430 if( actionPtr( sName ) ) {
431 kdWarning(125) <<
"TDEAccelActions::insertLabel( " << sName <<
", " << sLabel <<
" ): action with same name already present." <<
endl;
435 TDEAccelAction* pAction =
new TDEAccelAction;
436 pAction->m_sName = sName;
437 pAction->m_sLabel = sLabel;
438 pAction->m_bConfigurable =
false;
439 pAction->m_bEnabled =
false;
441 insertPtr( pAction );
445TDEAccelAction* TDEAccelActions::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) <<
"TDEAccelActions::insert( " << sAction <<
" ): action with same name already present." <<
endl;
456 TDEAccelAction* pAction =
new TDEAccelAction(
457 sAction, sLabel, sWhatsThis,
458 rgCutDefaults3, rgCutDefaults4,
459 pObjSlot, psMethodSlot,
460 bConfigurable, bEnabled );
461 insertPtr( pAction );
467bool TDEAccelActions::remove(
const TQString& sAction )
469 kdDebug(125) <<
"TDEAccelActions::remove( \"" << sAction <<
"\" ): this = " <<
this <<
" m_pTDEAccelBase = " << m_pTDEAccelBase <<
endl;
471 int iAction = actionIndex( sAction );
475 if( m_pTDEAccelBase )
476 m_pTDEAccelBase->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];
486bool TDEAccelActions::readActions(
const TQString& sConfigGroup,
TDEConfigBase* pConfig )
489 return accelList.readSettings( sConfigGroup, pConfig );
505bool TDEAccelActions::writeActions(
const TQString &sGroup,
TDEConfigBase* pConfig,
506 bool bWriteAll,
bool bGlobal )
const
508 kdDebug(125) <<
"TDEAccelActions::writeActions( " << sGroup <<
", " << pConfig <<
", " << bWriteAll <<
", " << bGlobal <<
" )" <<
endl;
513 for( uint i = 0; i < m_nSize; i++ ) {
514 if( m_prgActions[i] == 0 ) {
515 kdWarning(125) <<
"TDEAccelActions::writeActions(): encountered null pointer at m_prgActions[" << i <<
"]" <<
endl;
518 const TDEAccelAction&
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();
535 if( bWriteAll || !bSameAsDefault )
546 else if( bConfigHasAction ) {
547 kdDebug(125) <<
"\tremoving " <<
action.m_sName <<
" because == default" <<
endl;
558void TDEAccelActions::emitKeycodeChanged()
560 if( m_pTDEAccelBase )
561 m_pTDEAccelBase->emitSignal( TDEAccelBase::KEYCODE_CHANGED );
564uint TDEAccelActions::count()
const
static bool keyboardHasWinKey()
Checks whether the keyboard has a Win key.
A KKeySequence object holds a sequence of up to 4 keys.
TDEShortcutList implementation to access TDEAccel and TDEGlobalAccel lists.
virtual const TDEShortcut & shortcutDefault() const
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.
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
Reads a boolean entry.
void deleteEntry(const TQString &pKey, bool bNLS=false, bool bGlobal=false)
Deletes the entry specified by pKey in the current group.
virtual void sync()
Flushes all changes that currently reside only in memory back to disk / permanent storage.
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
Writes a key/value pair.
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 TDEConfig / KSimpleConfig groups.
static TDEConfig * config()
Returns the general config object.
The TDEShortcut class is used to represent a keyboard shortcut to an action.
bool init(int keyQt)
Initializes the shortcut with the given Qt key code as the only key sequence.
kdbgstream kdWarning(int area=0)
Returns a warning stream.
kdbgstream kdDebug(int area=0)
Returns a debug stream.
kdbgstream & endl(kdbgstream &s)
Prints an "\n".
TDEAction * action(StdAction act_enum, const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0L)
TDEAction * cut(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * clear(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEShortcut shortcutDefault(StdAccel id)
Returns the hardcoded default shortcut for id.