Bug 115109 - KHotKeys crashes after "ticking" it to manipulate a nonexistant target window
Summary: KHotKeys crashes after "ticking" it to manipulate a nonexistant target window
Status: RESOLVED FIXED
Alias: None
Product: khotkeys
Classification: Plasma
Component: general (show other bugs)
Version: unspecified
Platform: Ubuntu Linux
: NOR crash
Target Milestone: ---
Assignee: Lubos Lunak
URL:
Keywords:
: 101680 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-10-26 12:50 UTC by Marius
Modified: 2007-02-02 20:35 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marius 2005-10-26 12:50:19 UTC
Version:            (using KDE KDE 3.4.3)
Installed from:    Ubuntu Packages
OS:                Linux

Inside khotkeys in the "Keyboard input settings" there seems to be a missing QButton->disable(); on the Modify, Copy and Delete-buttons in the Window-area. when changing between actions.

How to recreate.
1. Make sure you have an action where you have chosen "Keyboard shortcut -> Keyboard input (simple)" have checked the "Specific window" radiobutton in the "Keyboard input settings"-tab and that you have added a window to the list.
2. Click on that action to open it in the left view.
3. Make a new Action, choose "Keyboard shortcut -> Keyboard input (simple)" and click "Specific window".
4. Notice how the "Modify", "Copy" and "Delete"-buttons are active even though there are no windows in the list.
5. Click on one of them and the program will crash as it has no window to modify/copy/delete

What needs to be done?
Update the buttons on a change in the left menu list.

Something like
void LeftListView_Selection_changed
if (WindowList.Count() == 0)
ModifyButton->disabled();
CopyButton->disabled();
DeleteButton->disabled();
else
ModifyButton->enabled();
CopyButton->enabled();
DeleteButton->enabled();
Comment 1 Marius 2005-10-26 12:53:07 UTC
The "ticking" in the title should be "tricking"
and 
the "left" in "2. Click on that action to open it in the left view." should be "right"

sry :)
Comment 2 Marius 2006-12-11 09:31:36 UTC
Still happends in kde 3.5.5

The crash happends because there is no checking when changing actions of whether these buttons should be enabled or not
Comment 3 Lubos Lunak 2007-02-02 20:31:09 UTC
*** Bug 101680 has been marked as a duplicate of this bug. ***
Comment 4 Lubos Lunak 2007-02-02 20:35:41 UTC
SVN commit 629444 by lunakl:

Avoid various braindamage when deleting condition objects.
BUG: 139962
BUG: 115109




 M  +11 -7     kcontrol/condition_list_widget.cpp  
 M  +10 -0     shared/conditions.cpp  
 M  +0 -6      shared/conditions.h  
 M  +1 -1      shared/khlistview.cpp  


--- branches/KDE/3.5/kdebase/khotkeys/kcontrol/condition_list_widget.cpp #629443:629444
@@ -84,8 +84,8 @@
 void Condition_list_widget::clear_data()
     {
     comment_lineedit->clear();
+    conditions.clear();
     conditions_listview->clear();
-    conditions.clear();
     }
 
 void Condition_list_widget::set_data( const Condition_list* data_P )
@@ -96,8 +96,8 @@
         return;
         }
     comment_lineedit->setText( data_P->comment());
+    conditions.clear();
     conditions_listview->clear();
-    conditions.clear();
     insert_listview_items( data_P, conditions_listview, NULL );
 #ifdef KHOTKEYS_DEBUG
     kdDebug( 1217 ) << "Condition_list_widget::set_data():" << endl;
@@ -278,12 +278,14 @@
         if( parent1_P == NULL )
             {
             parent2_P->setOpen( true );
-            conditions.append( new_cond ); // we own it, not the listview
+            if( new_cond->parent() == NULL ) // own only toplevels, they own the rest
+                conditions.append( new_cond ); // we own it, not the listview
             return new Condition_list_item( parent2_P, after_P, new_cond );
             }
         else
             {
-            conditions.append( new_cond ); // we own it, not the listview
+            if( new_cond->parent() == NULL )
+                conditions.append( new_cond ); // we own it, not the listview
             return new Condition_list_item( parent1_P, after_P, new_cond );
             }
         }
@@ -312,9 +314,11 @@
         Condition* old_cond = item_P->condition();
         item_P->set_condition( new_condition );
         int pos = conditions.find( old_cond );
-        assert( pos >= 0 );
-        conditions.remove( pos ); // we own it
-        conditions.insert( pos, new_condition );
+        if( pos >= 0 )
+            {
+            conditions.remove( pos ); // we own it
+            conditions.insert( pos, new_condition );
+            }
         item_P->widthChanged( 0 );
         conditions_listview->repaintItem( item_P );
         }
--- branches/KDE/3.5/kdebase/khotkeys/shared/conditions.cpp #629443:629444
@@ -133,6 +133,16 @@
     cfg_P.setGroup( save_cfg_group );
     }
 
+Condition_list_base::~Condition_list_base()
+    {
+    while( !isEmpty())
+        {
+        Condition* c = getFirst();
+        remove( c );
+        delete c;
+        }
+    }
+    
 void Condition_list_base::cfg_write( KConfig& cfg_P ) const
     {
     QString save_cfg_group = cfg_P.group();
--- branches/KDE/3.5/kdebase/khotkeys/shared/conditions.h #629443:629444
@@ -213,12 +213,6 @@
     {
     }
 
-inline
-Condition_list_base::~Condition_list_base()
-    {
-    setAutoDelete( true );
-    }
-    
 // Condition_list
 
 inline
--- branches/KDE/3.5/kdebase/khotkeys/shared/khlistview.cpp #629443:629444
@@ -96,8 +96,8 @@
 
 void KHListView::clearSelection()
     {
-    saved_current_item = NULL;
     KListView::clearSelection();
+    slot_current_changed( currentItem());
     }
 
 // items are often inserted using the QListViewItem constructor,