[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: [PATCH] kmail leaking KPopupMenus
From:       Rolf Magnus <ramagnus () kde ! org>
Date:       2003-12-30 10:53:01
Message-ID: 200312301153.01800.ramagnus () kde ! org
[Download RAW message or body]

On Tuesday 30 December 2003 11:48, Rolf Magnus wrote:
> Attached is a patch for a small leak in KMail. Whenever you drag/drop a
> mail into a mail folder, a new KPopupMenu for selection between copy and
> move is created, but not destroyed. This patch creates the menu once and
> reuses it.

Hmpf, forgot the header... complete patch attached.

["kmfoldertree.diff" (text/x-diff)]

Index: kmfoldertree.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmfoldertree.cpp,v
retrieving revision 1.273
diff -u -3 -p -B -w -r1.273 kmfoldertree.cpp
--- kmfoldertree.cpp	3 Dec 2003 11:53:01 -0000	1.273
+++ kmfoldertree.cpp	30 Dec 2003 10:56:12 -0000
@@ -31,6 +31,15 @@ using namespace KPIM;
 #include <X11/Xlib.h>
 #include <fixx11h.h>
 
+//-----------------------------------------------------------------------------
+// Drag and Drop handling -- based on the Troll Tech dirview example
+
+enum {
+  DRAG_COPY = 0,
+  DRAG_MOVE = 1,
+  DRAG_CANCEL = 2
+};
+
 //=============================================================================
 
 KMFolderTreeItem::KMFolderTreeItem( KFolderTree *parent, const QString & name,
@@ -231,13 +240,19 @@ void KMFolderTreeItem::properties()
 
 KMFolderTree::KMFolderTree( KMMainWidget *mainWidget, QWidget *parent,
                             const char *name )
-  : KFolderTree( parent, name )
+  : KFolderTree( parent, name ),
+    mDnDPopup( new KPopupMenu( this ) )
 {
   oldSelected = 0;
   oldCurrent = 0;
   mLastItem = 0;
   mMainWidget = mainWidget;
 
+  // drag and drop popup menu
+  mDnDPopup->insertItem( i18n("&Move Here"), DRAG_MOVE, 0 );
+  mDnDPopup->insertItem( SmallIcon("editcopy"), i18n("&Copy Here"), DRAG_COPY, 1 );
+  mDnDPopup->insertSeparator();
+  mDnDPopup->insertItem( SmallIcon("cancel"), i18n("C&ancel"), DRAG_CANCEL, 3 );
   addAcceptableDropMimetype(MailListDrag::format(), false);
 
   int namecol = addColumn( i18n("Folder"), 250 );
@@ -1208,15 +1223,6 @@ void KMFolderTree::cleanupConfigFile()
 
 
 //-----------------------------------------------------------------------------
-// Drag and Drop handling -- based on the Troll Tech dirview example
-
-enum {
-  DRAG_COPY = 0,
-  DRAG_MOVE = 1,
-  DRAG_CANCEL = 2
-};
-
-//-----------------------------------------------------------------------------
 void KMFolderTree::openFolder()
 {
     autoopen_timer.stop();
@@ -1392,12 +1398,7 @@ void KMFolderTree::contentsDropEvent( QD
         emit folderDrop(fti->folder());
       } else {
         if ( mShowPopupAfterDnD ) {
-          KPopupMenu *menu = new KPopupMenu( this );
-          menu->insertItem( i18n("&Move Here"), DRAG_MOVE, 0 );
-          menu->insertItem( SmallIcon("editcopy"), i18n("&Copy Here"), DRAG_COPY, 1 );
-          menu->insertSeparator();
-          menu->insertItem( SmallIcon("cancel"), i18n("C&ancel"), DRAG_CANCEL, 3 );
-          int id = menu->exec( QCursor::pos(), 0 );
+          int id = mDnDPopup->exec( QCursor::pos(), 0 );
           switch(id) {
             case DRAG_COPY:
               emit folderDropCopy(fti->folder());
Index: kmfoldertree.h
===================================================================
RCS file: /home/kde/kdepim/kmail/kmfoldertree.h,v
retrieving revision 1.76
diff -u -3 -p -B -w -r1.76 kmfoldertree.h
--- kmfoldertree.h	29 Nov 2003 15:16:03 -0000	1.76
+++ kmfoldertree.h	30 Dec 2003 10:56:12 -0000
@@ -288,6 +288,8 @@ private:
   int mUnreadPop;
   int mTotalPop;
 
+  KPopupMenu* mDnDPopup;
+
   /** show popup after D'n'D? */
   bool mShowPopupAfterDnD;
   KMMainWidget *mMainWidget;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic