kshortcutlist.cpp
#include <qstring.h>
#include <qvariant.h>
#include <kaccel.h>
#include "kaccelaction.h"
#include <kconfig.h>
#include <kdebug.h>
#include <kglobal.h>
#include <kglobalaccel.h>
#include <kinstance.h>
#include <kshortcut.h>
#include "kshortcutlist.h"
//---------------------------------------------------------------------
// KShortcutList
//---------------------------------------------------------------------
KShortcutList::KShortcutList()
{
}
KShortcutList::~KShortcutList()
{
}
bool KShortcutList::isGlobal( uint ) const
{
return false;
}
int KShortcutList::index( const QString& sName ) const
{
uint nSize = count();
for( uint i = 0;
i < nSize;
++i )
if( name( i ) == sName )
return i;
return -1;
}
int KShortcutList::index( const KKeySequence& seq ) const
{
if( seq.isNull() )
return -1;
uint nSize = count();
for( uint i = 0; i < nSize; i++ ) {
if( shortcut(i).contains( seq ) )
return i;
}
return -1;
}
const KInstance* KShortcutList::instance() const
{
return 0;
}
QVariant KShortcutList::getOther( Other, uint ) const
{
return QVariant();
}
bool KShortcutList::setOther( Other, uint, QVariant )
{
return false;
}
bool KShortcutList::readSettings( const QString& sConfigGroup, KConfigBase* pConfig )
{
kdDebug(125) << "KShortcutList::readSettings( \"" << sConfigGroup << "\", " << pConfig << " ) start" << endl;
if( !pConfig )
pConfig = KGlobal::config();
QString sGroup = (!sConfigGroup.isEmpty()) ? sConfigGroup : QString("Shortcuts");
// If the config file still has the old group name:
// FIXME: need to rename instead? -- and don't do this if hasGroup( "Shortcuts" ).
if( sGroup == "Shortcuts" && pConfig->hasGroup( "Keys" ) ) {
readSettings( "Keys", pConfig );
}
kdDebug(125) << "\treadSettings( \"" << sGroup << "\", " << pConfig << " )" << endl;
if( !pConfig->hasGroup( sGroup ) )
return true;
KConfigGroupSaver cgs( pConfig, sGroup );
uint nSize = count();
for( uint i = 0; i < nSize; i++ ) {
if( isConfigurable(i) ) {
QString sEntry = pConfig->readEntry( name(i) );
if( !sEntry.isEmpty() ) {
if( sEntry == "none" )
setShortcut( i, KShortcut() );
else
setShortcut( i, KShortcut(sEntry) );
}
else // default shortcut
setShortcut( i, shortcutDefault(i) );
kdDebug(125) << "\t" << name(i) << " = '" << sEntry << "'" << endl;
}
}
kdDebug(125) << "KShortcutList::readSettings done" << endl;
return true;
}
bool KShortcutList::writeSettings( const QString &sConfigGroup, KConfigBase* pConfig, bool bWriteAll, bool bGlobal ) const
{
kdDebug(125) << "KShortcutList::writeSettings( " << sConfigGroup << ", " << pConfig << ", " << bWriteAll << ", " << bGlobal << " )" << endl;
if( !pConfig )
pConfig = KGlobal::config();
QString sGroup = (!sConfigGroup.isEmpty()) ? sConfigGroup : QString("Shortcuts");
// If it has the deprecated group [Keys], remove it
if( pConfig->hasGroup( "Keys" ) )
pConfig->deleteGroup( "Keys", true );
KConfigGroupSaver cs( pConfig, sGroup );
uint nSize = count();
for( uint i = 0; i < nSize; i++ ) {
if( isConfigurable(i) ) {
const QString& sName = name(i);
bool bConfigHasAction = !pConfig->readEntry( sName ).isEmpty();
bool bSameAsDefault = (shortcut(i) == shortcutDefault(i));
// If we're using a global config or this setting
// differs from the default, then we want to write.
if( bWriteAll || !bSameAsDefault ) {
QString s = shortcut(i).toStringInternal();
if( s.isEmpty() )
s = "none";
kdDebug(125) << "\twriting " << sName << " = " << s << endl;
pConfig->writeEntry( sName, s, true, bGlobal );
}
// Otherwise, this key is the same as default
// but exists in config file. Remove it.
else if( bConfigHasAction ) {
kdDebug(125) << "\tremoving " << sName << " because == default" << endl;
pConfig->deleteEntry( sName, false, bGlobal );
}
}
}
pConfig->sync();
return true;
}
//---------------------------------------------------------------------
// KAccelShortcutList
//---------------------------------------------------------------------
class KAccelShortcutListPrivate
{
public:
QString m_configGroup;
};
KAccelShortcutList::KAccelShortcutList( KAccel* pAccel )
: m_actions( pAccel->actions() )
{
d=new KAccelShortcutListPrivate;
m_bGlobal = false;
d->m_configGroup=pAccel->configGroup();
}
KAccelShortcutList::KAccelShortcutList( KGlobalAccel* pAccel )
: m_actions( pAccel->actions() )
{
d=new KAccelShortcutListPrivate;
m_bGlobal = true;
d->m_configGroup=pAccel->configGroup();
}
KAccelShortcutList::KAccelShortcutList( KAccelActions& actions, bool bGlobal )
: m_actions( actions )
{
d=new KAccelShortcutListPrivate;
m_bGlobal = bGlobal;
}
KAccelShortcutList::~KAccelShortcutList()
{ delete d;}
uint KAccelShortcutList::count() const
{ return m_actions.count(); }
QString KAccelShortcutList::name( uint i ) const
{ return m_actions.actionPtr(i)->name(); }
QString KAccelShortcutList::label( uint i ) const
{ return m_actions.actionPtr(i)->label(); }
QString KAccelShortcutList::whatsThis( uint i ) const
{ return m_actions.actionPtr(i)->whatsThis(); }
const KShortcut& KAccelShortcutList::shortcut( uint i ) const
{ return m_actions.actionPtr(i)->shortcut(); }
const KShortcut& KAccelShortcutList::shortcutDefault( uint i ) const
{ return m_actions.actionPtr(i)->shortcutDefault(); }
bool KAccelShortcutList::isConfigurable( uint i ) const
{ return m_actions.actionPtr(i)->isConfigurable(); }
bool KAccelShortcutList::setShortcut( uint i, const KShortcut& cut )
{ return m_actions.actionPtr(i)->setShortcut( cut ); }
QVariant KAccelShortcutList::getOther( Other, uint ) const
{ return QVariant(); }
bool KAccelShortcutList::isGlobal( uint ) const
{ return m_bGlobal; }
bool KAccelShortcutList::setOther( Other, uint, QVariant )
{ return false; }
bool KAccelShortcutList::save() const
{ return writeSettings( d->m_configGroup ); }
void KShortcutList::virtual_hook( int, void* )
{ /*BASE::virtual_hook( id, data );*/ }
void KAccelShortcutList::virtual_hook( int id, void* data )
{ KShortcutList::virtual_hook( id, data ); }
void KStdAccel::ShortcutList::virtual_hook( int id, void* data )
{ KShortcutList::virtual_hook( id, data ); }
KShortcutList::name
virtual QString name(uint index) const =0
Returns the name of the shortcut with the given index.
KAccelShortcutList::label
virtual QString label(uint index) const
Returns the (i18n'd) label of the shortcut with the given index.
Definition: kshortcutlist.cpp:191
KAccel
Handle shortcuts.
Definition: kaccel.h:93
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
KAccelShortcutList::whatsThis
virtual QString whatsThis(uint index) const
Returns the (i18n'd) What's This text of the shortcut with the given index.
Definition: kshortcutlist.cpp:193
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::hasGroup
bool hasGroup(const QString &group) const
Returns true if the specified group is known about.
Definition: kconfigbase.cpp:134
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.
KConfigBase::sync
virtual void sync()
Flushes all changes that currently reside only in memory back to disk / permanent storage...
Definition: kconfigbase.cpp:1695
KShortcutList::KShortcutList
KShortcutList()
Default constructor.
Definition: kshortcutlist.cpp:18
KShortcutList::index
virtual int index(const QString &sName) const
Returns the index of the shortcut with he given name.
Definition: kshortcutlist.cpp:31
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
KShortcutList::readSettings
virtual bool readSettings(const QString &sConfigGroup=QString::null, KConfigBase *pConfig=0)
Loads the shortcuts from the given configuration file.
Definition: kshortcutlist.cpp:71
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 QString & configGroup() const
Returns the configuration group of the settings.
Definition: kaccel.cpp:521
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::name
virtual QString name(uint index) const
Returns the name of the shortcut with the given index.
Definition: kshortcutlist.cpp:189
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:2057
KConfigBase
KDE Configuration Management abstract base class.
Definition: kconfigbase.h:70
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
KConfigBase::deleteEntry
void deleteEntry(const QString &pKey, bool bNLS=false, bool bGlobal=false)
Deletes the entry specified by pKey in the current group.
Definition: kconfigbase.cpp:1163
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
KConfigBase::readEntry
QString readEntry(const QString &pKey, const QString &aDefault=QString::null) const
Reads the value of an entry specified by pKey in the current group.
Definition: kconfigbase.cpp:203
KShortcutList::isConfigurable
virtual bool isConfigurable(uint index) const =0
Checks whether the shortcut with the given index is configurable.
KConfigBase::deleteGroup
bool deleteGroup(const QString &group, bool bDeep=true, bool bGlobal=false)
Deletes a configuration entry group.
Definition: kconfigbase.cpp:1196
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.
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
KConfigBase::writeEntry
void writeEntry(const QString &pKey, const QString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
Writes a key/value pair.
Definition: kconfigbase.cpp:1012
KShortcutList::writeSettings
virtual bool writeSettings(const QString &sConfigGroup=QString::null, KConfigBase *pConfig=0, bool bWriteAll=false, bool bGlobal=false) const
Writes the shortcuts to the given configuration file.
Definition: kshortcutlist.cpp:109
KKeySequence::isNull
bool isNull() const
Returns true if the key sequence is null (after clear() or empty constructor).
Definition: kshortcut.cpp:315
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
KGlobalAccel::configGroup
const QString & configGroup() const
Returns the configuration group that is used to save the accelerators.
Definition: kglobalaccel.cpp:116

KDE Home | KDE Accessibility Home | Description of Access Keys