kdecore Library API Documentation

kshortcutlist.cpp

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 // KShortcutList 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 // If the config file still has the old group name: 00079 // FIXME: need to rename instead? -- and don't do this if hasGroup( "Shortcuts" ). 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 // default shortcut 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 // If it has the deprecated group [Keys], remove it 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 // If we're using a global config or this setting 00130 // differs from the default, then we want to write. 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 // Otherwise, this key is the same as default 00139 // but exists in config file. Remove it. 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 // KAccelShortcutList 00153 //--------------------------------------------------------------------- 00154 00155 KAccelShortcutList::KAccelShortcutList( KAccel* pAccel ) 00156 : m_actions( pAccel->actions() ) 00157 { 00158 m_bGlobal = false; 00159 } 00160 00161 KAccelShortcutList::KAccelShortcutList( KGlobalAccel* pAccel ) 00162 : m_actions( pAccel->actions() ) 00163 { 00164 m_bGlobal = true; 00165 } 00166 00167 KAccelShortcutList::KAccelShortcutList( KAccelActions& actions, bool bGlobal ) 00168 : m_actions( actions ) 00169 { 00170 m_bGlobal = bGlobal; 00171 } 00172 00173 00174 KAccelShortcutList::~KAccelShortcutList() 00175 { } 00176 uint KAccelShortcutList::count() const 00177 { return m_actions.count(); } 00178 QString KAccelShortcutList::name( uint i ) const 00179 { return m_actions.actionPtr(i)->name(); } 00180 QString KAccelShortcutList::label( uint i ) const 00181 { return m_actions.actionPtr(i)->label(); } 00182 QString KAccelShortcutList::whatsThis( uint i ) const 00183 { return m_actions.actionPtr(i)->whatsThis(); } 00184 const KShortcut& KAccelShortcutList::shortcut( uint i ) const 00185 { return m_actions.actionPtr(i)->shortcut(); } 00186 const KShortcut& KAccelShortcutList::shortcutDefault( uint i ) const 00187 { return m_actions.actionPtr(i)->shortcutDefault(); } 00188 bool KAccelShortcutList::isConfigurable( uint i ) const 00189 { return m_actions.actionPtr(i)->isConfigurable(); } 00190 bool KAccelShortcutList::setShortcut( uint i, const KShortcut& cut ) 00191 { return m_actions.actionPtr(i)->setShortcut( cut ); } 00192 QVariant KAccelShortcutList::getOther( Other, uint ) const 00193 { return QVariant(); } 00194 bool KAccelShortcutList::isGlobal( uint ) const 00195 { return m_bGlobal; } 00196 bool KAccelShortcutList::setOther( Other, uint, QVariant ) 00197 { return false; } 00198 bool KAccelShortcutList::save() const 00199 { return writeSettings(); } 00200 00201 void KShortcutList::virtual_hook( int, void* ) 00202 { /*BASE::virtual_hook( id, data );*/ } 00203 00204 void KAccelShortcutList::virtual_hook( int id, void* data ) 00205 { KShortcutList::virtual_hook( id, data ); } 00206 00207 void KStdAccel::ShortcutList::virtual_hook( int id, void* data ) 00208 { KShortcutList::virtual_hook( id, data ); } 00209
KDE Logo
This file is part of the documentation for kdecore Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 12 15:07:59 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003