00001
#include <qstring.h>
00002
#include <qvariant.h>
00003
00004
#include <kaccel.h>
00005
#include "kaccelaction.h"
00006
#include <kconfig.h>
00007
#include <kdebug.h>
00008
#include <kglobal.h>
00009
#include <kglobalaccel.h>
00010
#include <kinstance.h>
00011
#include <kshortcut.h>
00012
#include "kshortcutlist.h"
00013
00014
00015
00016
00017
00018 KShortcutList::KShortcutList()
00019 {
00020 }
00021
00022 KShortcutList::~KShortcutList()
00023 {
00024 }
00025
00026 bool KShortcutList::isGlobal( uint )
const
00027
{
00028
return false;
00029 }
00030
00031 int KShortcutList::index(
const QString& sName )
const
00032
{
00033 uint nSize =
count();
00034
for( uint i = 0;
00035 i < nSize;
00036 ++i )
00037
if(
name( i ) == sName )
00038
return i;
00039
return -1;
00040 }
00041
00042 int KShortcutList::index(
const KKeySequence& seq )
const
00043
{
00044
if( seq.
isNull() )
00045
return -1;
00046
00047 uint nSize =
count();
00048
for( uint i = 0; i < nSize; i++ ) {
00049
if(
shortcut(i).
contains( seq ) )
00050
return i;
00051 }
00052
00053
return -1;
00054 }
00055
00056 const KInstance*
KShortcutList::instance()
const
00057
{
00058
return 0;
00059 }
00060
00061
QVariant KShortcutList::getOther( Other, uint )
const
00062
{
00063
return QVariant();
00064 }
00065
00066
bool KShortcutList::setOther( Other, uint,
QVariant )
00067 {
00068
return false;
00069 }
00070
00071 bool KShortcutList::readSettings(
const QString& sConfigGroup,
KConfigBase* pConfig )
00072 {
00073 kdDebug(125) <<
"KShortcutList::readSettings( \"" << sConfigGroup <<
"\", " << pConfig <<
" ) start" <<
endl;
00074
if( !pConfig )
00075 pConfig =
KGlobal::config();
00076
QString sGroup = (!sConfigGroup.isEmpty()) ? sConfigGroup :
QString(
"Shortcuts");
00077
00078
00079
00080
if( sGroup ==
"Shortcuts" && pConfig->
hasGroup(
"Keys" ) ) {
00081
readSettings(
"Keys", pConfig );
00082 }
00083
00084 kdDebug(125) <<
"\treadSettings( \"" << sGroup <<
"\", " << pConfig <<
" )" <<
endl;
00085
if( !pConfig->
hasGroup( sGroup ) )
00086
return true;
00087
KConfigGroupSaver cgs( pConfig, sGroup );
00088
00089 uint nSize =
count();
00090
for( uint i = 0; i < nSize; i++ ) {
00091
if(
isConfigurable(i) ) {
00092
QString sEntry = pConfig->
readEntry(
name(i) );
00093
if( !sEntry.isEmpty() ) {
00094
if( sEntry ==
"none" )
00095
setShortcut( i,
KShortcut() );
00096
else
00097
setShortcut( i,
KShortcut(sEntry) );
00098 }
00099
else
00100
setShortcut( i,
shortcutDefault(i) );
00101 kdDebug(125) <<
"\t" <<
name(i) <<
" = '" << sEntry <<
"'" <<
endl;
00102 }
00103 }
00104
00105 kdDebug(125) <<
"KShortcutList::readSettings done" <<
endl;
00106
return true;
00107 }
00108
00109 bool KShortcutList::writeSettings(
const QString &sConfigGroup,
KConfigBase* pConfig,
bool bWriteAll,
bool bGlobal )
const
00110
{
00111 kdDebug(125) <<
"KShortcutList::writeSettings( " << sConfigGroup <<
", " << pConfig <<
", " << bWriteAll <<
", " << bGlobal <<
" )" <<
endl;
00112
if( !pConfig )
00113 pConfig =
KGlobal::config();
00114
00115
QString sGroup = (!sConfigGroup.isEmpty()) ? sConfigGroup :
QString(
"Shortcuts");
00116
00117
00118
if( pConfig->
hasGroup(
"Keys" ) )
00119 pConfig->
deleteGroup(
"Keys",
true );
00120
00121
KConfigGroupSaver cs( pConfig, sGroup );
00122
00123 uint nSize =
count();
00124
for( uint i = 0; i < nSize; i++ ) {
00125
if(
isConfigurable(i) ) {
00126
const QString& sName =
name(i);
00127
bool bConfigHasAction = !pConfig->
readEntry( sName ).isEmpty();
00128
bool bSameAsDefault = (
shortcut(i) ==
shortcutDefault(i));
00129
00130
00131
if( bWriteAll || !bSameAsDefault ) {
00132
QString s =
shortcut(i).
toStringInternal();
00133
if( s.isEmpty() )
00134 s =
"none";
00135 kdDebug(125) <<
"\twriting " << sName <<
" = " << s <<
endl;
00136 pConfig->
writeEntry( sName, s,
true, bGlobal );
00137 }
00138
00139
00140
else if( bConfigHasAction ) {
00141 kdDebug(125) <<
"\tremoving " << sName <<
" because == default" <<
endl;
00142 pConfig->
deleteEntry( sName,
false, bGlobal );
00143 }
00144 }
00145 }
00146
00147 pConfig->
sync();
00148
return true;
00149 }
00150
00151
00152
00153
00154
00155
class KAccelShortcutListPrivate
00156 {
00157
public:
00158
QString m_configGroup;
00159 };
00160
00161 KAccelShortcutList::KAccelShortcutList(
KAccel* pAccel )
00162 : m_actions( pAccel->actions() )
00163 {
00164 d=
new KAccelShortcutListPrivate;
00165 m_bGlobal =
false;
00166 d->m_configGroup=pAccel->
configGroup();
00167 }
00168
00169 KAccelShortcutList::KAccelShortcutList(
KGlobalAccel* pAccel )
00170 : m_actions( pAccel->actions() )
00171 {
00172 d=
new KAccelShortcutListPrivate;
00173 m_bGlobal =
true;
00174 d->m_configGroup=pAccel->
configGroup();
00175 }
00176
00177
KAccelShortcutList::KAccelShortcutList( KAccelActions& actions,
bool bGlobal )
00178 : m_actions( actions )
00179 {
00180 d=
new KAccelShortcutListPrivate;
00181 m_bGlobal = bGlobal;
00182 }
00183
00184
00185 KAccelShortcutList::~KAccelShortcutList()
00186 {
delete d;}
00187 uint
KAccelShortcutList::count()
const
00188
{
return m_actions.count(); }
00189 QString KAccelShortcutList::name( uint i )
const
00190
{
return m_actions.actionPtr(i)->name(); }
00191 QString KAccelShortcutList::label( uint i )
const
00192
{
return m_actions.actionPtr(i)->label(); }
00193 QString KAccelShortcutList::whatsThis( uint i )
const
00194
{
return m_actions.actionPtr(i)->whatsThis(); }
00195 const KShortcut&
KAccelShortcutList::shortcut( uint i )
const
00196
{
return m_actions.actionPtr(i)->shortcut(); }
00197 const KShortcut&
KAccelShortcutList::shortcutDefault( uint i )
const
00198
{
return m_actions.actionPtr(i)->shortcutDefault(); }
00199 bool KAccelShortcutList::isConfigurable( uint i )
const
00200
{
return m_actions.actionPtr(i)->isConfigurable(); }
00201 bool KAccelShortcutList::setShortcut( uint i,
const KShortcut& cut )
00202 {
return m_actions.actionPtr(i)->setShortcut( cut ); }
00203
QVariant KAccelShortcutList::getOther( Other, uint )
const
00204
{
return QVariant(); }
00205 bool KAccelShortcutList::isGlobal( uint )
const
00206
{
return m_bGlobal; }
00207
bool KAccelShortcutList::setOther( Other, uint,
QVariant )
00208 {
return false; }
00209 bool KAccelShortcutList::save()
const
00210
{
return writeSettings( d->m_configGroup ); }
00211
00212 void KShortcutList::virtual_hook(
int,
void* )
00213 { }
00214
00215 void KAccelShortcutList::virtual_hook(
int id,
void* data )
00216 {
KShortcutList::virtual_hook(
id, data ); }
00217
00218 void KStdAccel::ShortcutList::virtual_hook(
int id,
void* data )
00219 {
KShortcutList::virtual_hook(
id, data ); }
00220