You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
221 lines
6.1 KiB
221 lines
6.1 KiB
15 years ago
|
#include <tqstring.h>
|
||
|
#include <tqvariant.h>
|
||
15 years ago
|
|
||
|
#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;
|
||
|
}
|
||
|
|
||
15 years ago
|
int KShortcutList::index( const TQString& sName ) const
|
||
15 years ago
|
{
|
||
|
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++ ) {
|
||
14 years ago
|
if( shortcut(i).contains( seq ) )
|
||
15 years ago
|
return i;
|
||
|
}
|
||
|
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
const KInstance* KShortcutList::instance() const
|
||
|
{
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQVariant KShortcutList::getOther( Other, uint ) const
|
||
15 years ago
|
{
|
||
15 years ago
|
return TQVariant();
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
bool KShortcutList::setOther( Other, uint, TQVariant )
|
||
15 years ago
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KShortcutList::readSettings( const TQString& sConfigGroup, KConfigBase* pConfig )
|
||
15 years ago
|
{
|
||
|
kdDebug(125) << "KShortcutList::readSettings( \"" << sConfigGroup << "\", " << pConfig << " ) start" << endl;
|
||
|
if( !pConfig )
|
||
|
pConfig = KGlobal::config();
|
||
15 years ago
|
TQString sGroup = (!sConfigGroup.isEmpty()) ? sConfigGroup : TQString("Shortcuts");
|
||
15 years ago
|
|
||
|
// 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) ) {
|
||
15 years ago
|
TQString sEntry = pConfig->readEntry( name(i) );
|
||
15 years ago
|
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;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KShortcutList::writeSettings( const TQString &sConfigGroup, KConfigBase* pConfig, bool bWriteAll, bool bGlobal ) const
|
||
15 years ago
|
{
|
||
|
kdDebug(125) << "KShortcutList::writeSettings( " << sConfigGroup << ", " << pConfig << ", " << bWriteAll << ", " << bGlobal << " )" << endl;
|
||
|
if( !pConfig )
|
||
|
pConfig = KGlobal::config();
|
||
|
|
||
15 years ago
|
TQString sGroup = (!sConfigGroup.isEmpty()) ? sConfigGroup : TQString("Shortcuts");
|
||
15 years ago
|
|
||
|
// 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) ) {
|
||
15 years ago
|
const TQString& sName = name(i);
|
||
15 years ago
|
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 ) {
|
||
15 years ago
|
TQString s = shortcut(i).toStringInternal();
|
||
15 years ago
|
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:
|
||
15 years ago
|
TQString m_configGroup;
|
||
15 years ago
|
};
|
||
|
|
||
|
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(); }
|
||
15 years ago
|
TQString KAccelShortcutList::name( uint i ) const
|
||
15 years ago
|
{ return m_actions.actionPtr(i)->name(); }
|
||
15 years ago
|
TQString KAccelShortcutList::label( uint i ) const
|
||
15 years ago
|
{ return m_actions.actionPtr(i)->label(); }
|
||
15 years ago
|
TQString KAccelShortcutList::whatsThis( uint i ) const
|
||
15 years ago
|
{ 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 ); }
|
||
15 years ago
|
TQVariant KAccelShortcutList::getOther( Other, uint ) const
|
||
|
{ return TQVariant(); }
|
||
15 years ago
|
bool KAccelShortcutList::isGlobal( uint ) const
|
||
|
{ return m_bGlobal; }
|
||
15 years ago
|
bool KAccelShortcutList::setOther( Other, uint, TQVariant )
|
||
15 years ago
|
{ 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 ); }
|
||
|
|