00001 #include <tqstring.h>
00002 #include <tqvariant.h>
00003
00004 #include <tdeaccel.h>
00005 #include "tdeaccelaction.h"
00006 #include <tdeconfig.h>
00007 #include <kdebug.h>
00008 #include <tdeglobal.h>
00009 #include <kglobalaccel.h>
00010 #include <kinstance.h>
00011 #include <tdeshortcut.h>
00012 #include "tdeshortcutlist.h"
00013
00014
00015
00016
00017
00018 TDEShortcutList::TDEShortcutList()
00019 {
00020 }
00021
00022 TDEShortcutList::~TDEShortcutList()
00023 {
00024 }
00025
00026 bool TDEShortcutList::isGlobal( uint ) const
00027 {
00028 return false;
00029 }
00030
00031 int TDEShortcutList::index( const TQString& 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 TDEShortcutList::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 TDEInstance* TDEShortcutList::instance() const
00057 {
00058 return 0;
00059 }
00060
00061 TQVariant TDEShortcutList::getOther( Other, uint ) const
00062 {
00063 return TQVariant();
00064 }
00065
00066 bool TDEShortcutList::setOther( Other, uint, TQVariant )
00067 {
00068 return false;
00069 }
00070
00071 bool TDEShortcutList::readSettings( const TQString& sConfigGroup, TDEConfigBase* pConfig )
00072 {
00073 kdDebug(125) << "TDEShortcutList::readSettings( \"" << sConfigGroup << "\", " << pConfig << " ) start" << endl;
00074 if( !pConfig )
00075 pConfig = TDEGlobal::config();
00076 TQString sGroup = (!sConfigGroup.isEmpty()) ? sConfigGroup : TQString("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 TDEConfigGroupSaver cgs( pConfig, sGroup );
00088
00089 uint nSize = count();
00090 for( uint i = 0; i < nSize; i++ ) {
00091 if( isConfigurable(i) ) {
00092 TQString sEntry = pConfig->readEntry( name(i) );
00093 if( !sEntry.isEmpty() ) {
00094 if( sEntry == "none" )
00095 setShortcut( i, TDEShortcut() );
00096 else
00097 setShortcut( i, TDEShortcut(sEntry) );
00098 }
00099 else
00100 setShortcut( i, shortcutDefault(i) );
00101 kdDebug(125) << "\t" << name(i) << " = '" << sEntry << "'" << endl;
00102 }
00103 }
00104
00105 kdDebug(125) << "TDEShortcutList::readSettings done" << endl;
00106 return true;
00107 }
00108
00109 bool TDEShortcutList::writeSettings( const TQString &sConfigGroup, TDEConfigBase* pConfig, bool bWriteAll, bool bGlobal ) const
00110 {
00111 kdDebug(125) << "TDEShortcutList::writeSettings( " << sConfigGroup << ", " << pConfig << ", " << bWriteAll << ", " << bGlobal << " )" << endl;
00112 if( !pConfig )
00113 pConfig = TDEGlobal::config();
00114
00115 TQString sGroup = (!sConfigGroup.isEmpty()) ? sConfigGroup : TQString("Shortcuts");
00116
00117
00118 if( pConfig->hasGroup( "Keys" ) )
00119 pConfig->deleteGroup( "Keys", true );
00120
00121 TDEConfigGroupSaver cs( pConfig, sGroup );
00122
00123 uint nSize = count();
00124 for( uint i = 0; i < nSize; i++ ) {
00125 if( isConfigurable(i) ) {
00126 const TQString& sName = name(i);
00127 bool bConfigHasAction = !pConfig->readEntry( sName ).isEmpty();
00128 bool bSameAsDefault = (shortcut(i) == shortcutDefault(i));
00129
00130
00131 if( bWriteAll || !bSameAsDefault ) {
00132 TQString 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 TDEAccelShortcutListPrivate
00156 {
00157 public:
00158 TQString m_configGroup;
00159 };
00160
00161 TDEAccelShortcutList::TDEAccelShortcutList( TDEAccel* pAccel )
00162 : m_actions( pAccel->actions() )
00163 {
00164 d=new TDEAccelShortcutListPrivate;
00165 m_bGlobal = false;
00166 d->m_configGroup=pAccel->configGroup();
00167 }
00168
00169 TDEAccelShortcutList::TDEAccelShortcutList( TDEGlobalAccel* pAccel )
00170 : m_actions( pAccel->actions() )
00171 {
00172 d=new TDEAccelShortcutListPrivate;
00173 m_bGlobal = true;
00174 d->m_configGroup=pAccel->configGroup();
00175 }
00176
00177 TDEAccelShortcutList::TDEAccelShortcutList( TDEAccelActions& actions, bool bGlobal )
00178 : m_actions( actions )
00179 {
00180 d=new TDEAccelShortcutListPrivate;
00181 m_bGlobal = bGlobal;
00182 }
00183
00184
00185 TDEAccelShortcutList::~TDEAccelShortcutList()
00186 { delete d;}
00187 uint TDEAccelShortcutList::count() const
00188 { return m_actions.count(); }
00189 TQString TDEAccelShortcutList::name( uint i ) const
00190 { return m_actions.actionPtr(i)->name(); }
00191 TQString TDEAccelShortcutList::label( uint i ) const
00192 { return m_actions.actionPtr(i)->label(); }
00193 TQString TDEAccelShortcutList::whatsThis( uint i ) const
00194 { return m_actions.actionPtr(i)->whatsThis(); }
00195 const TDEShortcut& TDEAccelShortcutList::shortcut( uint i ) const
00196 { return m_actions.actionPtr(i)->shortcut(); }
00197 const TDEShortcut& TDEAccelShortcutList::shortcutDefault( uint i ) const
00198 { return m_actions.actionPtr(i)->shortcutDefault(); }
00199 bool TDEAccelShortcutList::isConfigurable( uint i ) const
00200 { return m_actions.actionPtr(i)->isConfigurable(); }
00201 bool TDEAccelShortcutList::setShortcut( uint i, const TDEShortcut& cut )
00202 { return m_actions.actionPtr(i)->setShortcut( cut ); }
00203 TQVariant TDEAccelShortcutList::getOther( Other, uint ) const
00204 { return TQVariant(); }
00205 bool TDEAccelShortcutList::isGlobal( uint ) const
00206 { return m_bGlobal; }
00207 bool TDEAccelShortcutList::setOther( Other, uint, TQVariant )
00208 { return false; }
00209 bool TDEAccelShortcutList::save() const
00210 { return writeSettings( d->m_configGroup ); }
00211
00212 void TDEShortcutList::virtual_hook( int, void* )
00213 { }
00214
00215 void TDEAccelShortcutList::virtual_hook( int id, void* data )
00216 { TDEShortcutList::virtual_hook( id, data ); }
00217
00218 void TDEStdAccel::ShortcutList::virtual_hook( int id, void* data )
00219 { TDEShortcutList::virtual_hook( id, data ); }
00220