[PATCH] fix khotkey crashes

Andreas Pakulat apaku at gmx.de
Tue Dec 4 15:40:12 GMT 2007


On 04.12.07 16:14:19, Andreas Pakulat wrote:
> Hi,
> 
> Is this the right place for getting approval for khotkey patches? If not
> I'd appreciate directions.
> 
> The attached patch fixes the crashes when trying to create a new action
> or group or trying to store those settings.
> 
> May I commit this now or shall I wait until after the tagging was done
> (i.e. tagging freeze is lifted)

Forget about that patch, while I tried to fixup behind kate (which
introduced various whitespace changes for no reason) I missed a small
part.

Updated patch which actually does compile.

Andreas

-- 
You love your home and want it to be beautiful.
-------------- next part --------------
Index: shared/settings.cpp
===================================================================
--- shared/settings.cpp	(Revision 743820)
+++ shared/settings.cpp	(Arbeitskopie)
@@ -153,18 +153,21 @@
     int enabled_cnt = 0;
     QString save_cfg_group = cfg_P.name();
     int cnt = 0;
-    for( Action_data_group::Iterator it = parent_P->first_child();
-         it;
-         ++it )
+    if( parent_P )
         {
-        ++cnt;
-        if( enabled_P && (*it)->enabled( true ))
-            ++enabled_cnt;
-        KConfigGroup itConfig( cfg_P.config(), save_cfg_group + '_' + QString::number( cnt ));
-        ( *it )->cfg_write( itConfig );
-        Action_data_group* grp = dynamic_cast< Action_data_group* >( *it );
-        if( grp != NULL )
-            enabled_cnt += write_actions_recursively_v2( cfg_P, grp, enabled_P && (*it)->enabled( true ));
+        for( Action_data_group::ConstIterator it = parent_P->first_child();
+            it != parent_P->after_last_child();
+             ++it )
+            {
+            ++cnt;
+            if( enabled_P && (*it)->enabled( true ))
+                ++enabled_cnt;
+            KConfigGroup itConfig( cfg_P.config(), save_cfg_group + '_' + QString::number( cnt ));
+            ( *it )->cfg_write( itConfig );
+            Action_data_group* grp = dynamic_cast< Action_data_group* >( *it );
+            if( grp != NULL )
+                enabled_cnt += write_actions_recursively_v2( cfg_P, grp, enabled_P && (*it)->enabled( true ));
+            }
         }
     cfg_P.writeEntry( "DataCount", cnt );
     return enabled_cnt;
@@ -202,8 +205,8 @@
     KConfigGroup mainGroup( &cfg_P, "Main" );
     int sections = mainGroup.readEntry( "Num_Sections", 0 );
     Action_data_group* menuentries = NULL;
-    for( Action_data_group::Iterator it( actions->first_child());
-         *it;
+    for( Action_data_group::ConstIterator it = actions->first_child();
+         it != actions->after_last_child();
          ++it )
         {
         Action_data_group* tmp = dynamic_cast< Action_data_group* >( *it );
Index: shared/action_data.cpp
===================================================================
--- shared/action_data.cpp	(Revision 743820)
+++ shared/action_data.cpp	(Arbeitskopie)
@@ -72,8 +72,8 @@
         {
         if( cfg_P.readEntry( "AllowMerge", false ))
             {
-            for( Action_data_group::Iterator it = parent_P->first_child();
-                 it;
+            for( Action_data_group::ConstIterator it = parent_P->first_child();
+                 it != parent_P->after_last_child();
                  ++it )
                 {
                 if( Action_data_group* existing = dynamic_cast< Action_data_group* >( *it ))
@@ -151,8 +151,8 @@
     
 void Action_data_group::update_triggers()
     {
-    for( Action_data_group::Iterator it = first_child();
-         it;
+    for( Action_data_group::ConstIterator it = first_child();
+         it != after_last_child();
          ++it )
         ( *it )->update_triggers();
     }
Index: shared/action_data.h
===================================================================
--- shared/action_data.h	(Revision 743820)
+++ shared/action_data.h	(Arbeitskopie)
@@ -13,7 +13,8 @@
 
 #include <assert.h>
 
-#include <Qt3Support/Q3PtrList>
+#include <QtCore/QList>
+#include <QtCore/QListIterator>
 
 #include <kdebug.h>
 
@@ -74,13 +75,15 @@
         virtual ~Action_data_group();
         virtual void update_triggers();
         virtual void cfg_write( KConfigGroup& cfg_P ) const;
-        typedef Q3PtrListIterator< Action_data_base > Iterator; // CHECKME neni const :(
-        Iterator first_child() const;
+        typedef QList< Action_data_base* >::iterator Iterator; // CHECKME neni const :(
+        typedef QList< Action_data_base* >::const_iterator ConstIterator; // CHECKME neni const :(
+        ConstIterator first_child() const;
+        ConstIterator after_last_child() const;
         bool is_system_group() const;
         system_group_t system_group() const;
         using Action_data_base::set_conditions; // make public
     protected:
-        Q3PtrList< Action_data_base > list;
+        QList< Action_data_base* > list;
         system_group_t _system_group; // e.g. menuedit entries, can't be deleted or renamed
         friend class Action_data_base; // CHECKME
         void add_child( Action_data_base* child_P );
@@ -265,17 +268,26 @@
 Action_data_group::~Action_data_group()
     {
 //    kDebug( 1217 ) << "~Action_data_group() :" << list.count();
-    while( list.first())
-        delete list.first();
+    if( !list.isEmpty() )
+        {
+            while( list.first())
+            delete list.first();
+        }
     }
     
 inline
-Action_data_group::Iterator Action_data_group::first_child() const
+Action_data_group::ConstIterator Action_data_group::first_child() const
     {
-    return Iterator( list );
+    return list.begin();
     }
 
 inline
+Action_data_group::ConstIterator Action_data_group::after_last_child() const
+    {
+    return list.end();
+    }
+
+inline
 bool Action_data_group::is_system_group() const
     {
     return _system_group != SYSTEM_NONE;
@@ -296,7 +308,7 @@
 inline
 void Action_data_group::remove_child( Action_data_base* child_P )
     {
-    list.removeRef( child_P ); // is not auto-delete
+    list.remove( child_P ); // is not auto-delete
     }
     
 // Action_data
Index: kcontrol/general_tab.cpp
===================================================================
--- kcontrol/general_tab.cpp	(Revision 743820)
+++ kcontrol/general_tab.cpp	(Arbeitskopie)
@@ -104,7 +104,7 @@
         }
     action_name_lineedit->setText( data_P->name());
     disable_checkbox->setChecked( !data_P->enabled( true ));
-    if( !data_P->parent()->enabled( false ))
+    if( data_P->parent() && !data_P->parent()->enabled( false ))
         disable_checkbox->setText( i18n( "&Disable (group is disabled)" ));
     else
         disable_checkbox->setText( i18n( "&Disable" ));
Index: kcontrol/action_group_tab.cpp
===================================================================
--- kcontrol/action_group_tab.cpp	(Revision 743820)
+++ kcontrol/action_group_tab.cpp	(Arbeitskopie)
@@ -64,7 +64,8 @@
     action_name_lineedit->setText( data_P->name());
     action_name_lineedit->setReadOnly( data_P->is_system_group());
     disable_checkbox->setChecked( !data_P->enabled( true ));
-    if( !data_P->parent()->enabled( false ))
+
+    if( data_P->parent() && !data_P->parent()->enabled( false ))
         disable_checkbox->setText( i18n( "&Disable (group is disabled)" ));
     else
         disable_checkbox->setText( i18n( "&Disable" ));
Index: kcontrol/actions_listview_widget.cpp
===================================================================
--- kcontrol/actions_listview_widget.cpp	(Revision 743820)
+++ kcontrol/actions_listview_widget.cpp	(Arbeitskopie)
@@ -140,8 +140,8 @@
     Action_listview_item* item_parent_P )
     {
     Action_listview_item* prev = NULL;
-    for( Action_data_group::Iterator it = parent_P->first_child();
-         it;
+    for( Action_data_group::ConstIterator it = parent_P->first_child();
+         it != parent_P->after_last_child();
          ++it )
         {
         prev = create_item( item_parent_P, prev, ( *it )); 
Index: kcontrol/menuedit.cpp
===================================================================
--- kcontrol/menuedit.cpp	(Revision 743820)
+++ kcontrol/menuedit.cpp	(Arbeitskopie)
@@ -55,8 +55,8 @@
     {
     if( !data_P->enabled( false ))
         return NULL;
-    for( Action_data_group::Iterator it = data_P->first_child();
-         it;
+    for( Action_data_group::ConstIterator it = data_P->first_child();
+         it != data_P->after_last_child();
          ++it )
         {
         if( !(*it)->enabled( true ))
@@ -81,8 +81,8 @@
     
 Action_data_group* khotkeys_get_menu_root( Action_data_group* data_P )
     {
-    for( Action_data_group::Iterator it = data_P->first_child();
-         it;
+    for( Action_data_group::ConstIterator it = data_P->first_child();
+         it != data_P->after_last_child();
          ++it )
         if( Action_data_group* group = dynamic_cast< Action_data_group* >( *it ))
             {
@@ -111,8 +111,8 @@
     {
     if( !data_P->enabled( false ))
         return;
-    for( Action_data_group::Iterator it = data_P->first_child();
-         it;
+    for( Action_data_group::ConstIterator it = data_P->first_child();
+         it != data_P->after_last_child();
          ++it )
         {
         if( !(*it)->enabled( true ))
@@ -147,8 +147,8 @@
     {
     if( !data_P->enabled( false ))
         return KService::Ptr();
-    for( Action_data_group::Iterator it = data_P->first_child();
-         it;
+    for( Action_data_group::ConstIterator it = data_P->first_child();
+         it != data_P->after_last_child();
          ++it )
         {
         if( !(*it)->enabled( true ))
Index: kcontrol/tab_widget.cpp
===================================================================
--- kcontrol/tab_widget.cpp	(Revision 743820)
+++ kcontrol/tab_widget.cpp	(Arbeitskopie)
@@ -115,8 +115,8 @@
             module->current_action_data()->parent(), NULL );
         item->set_conditions( static_cast< Condition_list_tab* >( pages[ TAB_CONDITIONS ] )
             ->get_data( item ));
-        for( Action_data_group::Iterator it = old->first_child();
-             it;
+        for( Action_data_group::ConstIterator it = old->first_child();
+             it != old->after_last_child();
             )
             {
             Action_data_base* tmp = ( *it );


More information about the kde-core-devel mailing list