[prev in list] [next in list] [prev in thread] [next in thread]
List: kmail-devel
Subject: [MIC MERGE] remove duplicates feature
From: Marc Mutz <mutz () kde ! org>
Date: 2002-12-26 16:12:00
[Download RAW message or body]
[Attachment #2 (multipart/mixed)]
Hi!
Attached is the patch set and the resulting diff for the remove
duplicates feature.
remove_dups.diff is the result of applying - in - order
004_remove_duplicates_feature
Initial commit. Lacks menu item.
031_add_remove_duplicate_feature_to_menubar
Adds this action to the Folder menu.
216_styleguide_fix
Capitalization fixes.
231_rename_remove_dups_menu_item
Truncate the too verbose name of the menu item
306_remove_C-ism
s/\(void\)/\(\)/
307_statusbar_notification_for_remove_duplicates
Present the result of the operation in the status bar.
ADD_01_MM_move_guard_clause
move the !mFolder guard clause to before the mHeaders->setFolder(0).
In the best case, this is just a speed up, in the worst case it fixes
the missing setFolder(oFolder) call later in normal processing.
Marc
--
"Similia similibus curentur"
-- Bush's new motto in fighting terrorism.
["remove_dups.diff" (text/x-diff)]
Index: kmmainwin.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmmainwin.cpp,v
retrieving revision 1.541.2.3
diff -u -3 -p -r1.541.2.3 kmmainwin.cpp
--- kmmainwin.cpp 9 Dec 2002 23:02:02 -0000 1.541.2.3
+++ kmmainwin.cpp 26 Dec 2002 16:11:00 -0000
@@ -585,6 +585,10 @@ void KMMainWin::createWidgets(void)
//Commands not worthy of menu items, but that deserve configurable keybindings
new KAction(
+ i18n("Remove Duplicate Messages"), CTRL+Key_Asterisk, this,
+ SLOT(removeDuplicates()), actionCollection(), "remove_duplicate_messages");
+
+ new KAction(
i18n("Focus on Next Folder"), CTRL+Key_Right, mFolderTree,
SLOT(incCurrentFolder()), actionCollection(), "inc_current_folder");
@@ -3126,3 +3130,51 @@ void KMMainWin::slotChangeCaption(QListV
setCaption( names.join("/") );
}
+//-----------------------------------------------------------------------------
+void KMMainWin::removeDuplicates()
+{
+ if (!mFolder)
+ return;
+ KMFolder *oFolder = mFolder;
+ mHeaders->setFolder(0);
+ QMap< QString, QValueList<int> > idMD5s;
+ QValueList<int> redundantIds;
+ QValueList<int>::Iterator kt;
+ mFolder->open();
+ for (int i = mFolder->count() - 1; i >= 0; --i) {
+ QString id = (*mFolder)[i]->msgIdMD5();
+ idMD5s[id].append( i );
+ }
+ QMap< QString, QValueList<int> >::Iterator it;
+ for ( it = idMD5s.begin(); it != idMD5s.end() ; ++it ) {
+ QValueList<int>::Iterator jt;
+ bool finished = false;
+ for ( jt = (*it).begin(); jt != (*it).end() && !finished; ++jt )
+ if (!((*mFolder)[*jt]->isUnread())) {
+ (*it).remove( jt );
+ (*it).prepend( *jt );
+ finished = true;
+ }
+ for ( jt = (*it).begin(), ++jt; jt != (*it).end(); ++jt )
+ redundantIds.append( *jt );
+ }
+ qHeapSort( redundantIds );
+ kt = redundantIds.end();
+ int numDuplicates = 0;
+ if (kt != redundantIds.begin()) do {
+ mFolder->removeMsg( *(--kt) );
+ ++numDuplicates;
+ }
+ while (kt != redundantIds.begin());
+
+ mFolder->close();
+ mHeaders->setFolder(oFolder);
+ QString msg;
+ if ( numDuplicates )
+ msg = i18n("Removed %n duplicate message.",
+ "Removed %n duplicate messages.", numDuplicates );
+ else
+ msg = i18n("No duplicate messages found.");
+ KMBroadcastStatus::instance()->setStatusMsg( msg );
+}
+
Index: kmmainwin.h
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmmainwin.h,v
retrieving revision 1.148
diff -u -3 -p -r1.148 kmmainwin.h
--- kmmainwin.h 29 Oct 2002 08:35:06 -0000 1.148
+++ kmmainwin.h 26 Dec 2002 16:11:00 -0000
@@ -322,6 +322,7 @@ protected slots:
/** changes the caption and displays the foldername */
void slotChangeCaption(QListViewItem*);
+ void removeDuplicates();
protected:
KRadioAction * actionForHeaderStyle(int);
Index: kmmainwin.rc
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmmainwin.rc,v
retrieving revision 1.45
diff -u -3 -p -r1.45 kmmainwin.rc
--- kmmainwin.rc 12 Oct 2002 10:12:44 -0000 1.45
+++ kmmainwin.rc 26 Dec 2002 16:11:00 -0000
@@ -67,6 +67,7 @@
<Action name="mark_all_as_read" />
<Action name="compact" />
<Action name="expire" />
+ <Action name="remove_duplicate_messages" />
<Separator/>
<Action name="empty" />
<Action name="delete_folder" />
["231_rename_remove_dups_menu_item" (text/x-diff)]
Index: kmmainwidget.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmmainwidget.cpp,v
retrieving revision 1.1.2.30
retrieving revision 1.1.2.31
diff -u -3 -p -r1.1.2.30 -r1.1.2.31
--- kmmainwidget.cpp 12 Nov 2002 15:27:25 -0000 1.1.2.30
+++ kmmainwidget.cpp 15 Nov 2002 09:48:58 -0000 1.1.2.31
@@ -603,6 +603,6 @@ void KMMainWidget::createWidgets(void)
//Commands not worthy of menu items, but that deserve configurable keybindings
new KAction(
- i18n("Remove Duplicate Messages in Current Folder"), CTRL+Key_Asterisk, this,
+ i18n("Remove Duplicate Messages"), CTRL+Key_Asterisk, this,
SLOT(removeDuplicates()), mActionCollection, "remove_duplicate_messages");
["ADD_01_MM_move_guard_clause" (text/x-diff)]
--- kmmainwin.cpp.orig Thu Dec 26 16:55:54 2002
+++ kmmainwin.cpp Thu Dec 26 16:56:25 2002
@@ -3133,13 +3133,13 @@
//-----------------------------------------------------------------------------
void KMMainWin::removeDuplicates()
{
+ if (!mFolder)
+ return;
KMFolder *oFolder = mFolder;
mHeaders->setFolder(0);
QMap< QString, QValueList<int> > idMD5s;
QValueList<int> redundantIds;
QValueList<int>::Iterator kt;
- if (!mFolder)
- return;
mFolder->open();
for (int i = mFolder->count() - 1; i >= 0; --i) {
QString id = (*mFolder)[i]->msgIdMD5();
["216_styleguide_fix" (text/x-diff)]
Index: kmmainwidget.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmmainwidget.cpp,v
retrieving revision 1.1.2.27
retrieving revision 1.1.2.28
diff -u -3 -p -r1.1.2.27 -r1.1.2.28
--- kmmainwidget.cpp 7 Nov 2002 08:55:41 -0000 1.1.2.27
+++ kmmainwidget.cpp 7 Nov 2002 10:38:20 -0000 1.1.2.28
@@ -620,7 +620,7 @@ void KMMainWidget::createWidgets(void)
//Commands not worthy of menu items, but that deserve configurable keybindings
new KAction(
- i18n("Remove duplicate messages in current folder"), CTRL+Key_Asterisk, this,
+ i18n("Remove Duplicate Messages in Current Folder"), CTRL+Key_Asterisk, this,
SLOT(removeDuplicates()), mActionCollection, "remove_duplicate_messages");
new KAction(
["307_statusbar_notification_for_remove_duplicates" (text/x-diff)]
Index: kmmainwidget.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmmainwidget.cpp,v
retrieving revision 1.1.2.52
retrieving revision 1.1.2.53
diff -u -3 -p -r1.1.2.52 -r1.1.2.53
--- kmmainwidget.cpp 30 Nov 2002 11:11:45 -0000 1.1.2.52
+++ kmmainwidget.cpp 30 Nov 2002 12:17:45 -0000 1.1.2.53
@@ -2772,13 +2772,22 @@ void KMMainWidget::removeDuplicates()
}
qHeapSort( redundantIds );
kt = redundantIds.end();
+ int numDuplicates = 0;
if (kt != redundantIds.begin()) do {
mFolder->removeMsg( *(--kt) );
+ ++numDuplicates;
}
while (kt != redundantIds.begin());
mFolder->close();
mHeaders->setFolder(oFolder);
+ QString msg;
+ if ( numDuplicates )
+ msg = i18n("Removed %n duplicate message.",
+ "Removed %n duplicate messages.", numDuplicates );
+ else
+ msg = i18n("No duplicate messages found.");
+ KMBroadcastStatus::instance()->setStatusMsg( msg );
}
["306_remove_C-ism" (text/x-diff)]
Index: kmmainwidget.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmmainwidget.cpp,v
retrieving revision 1.1.2.51
retrieving revision 1.1.2.52
diff -u -3 -p -r1.1.2.51 -r1.1.2.52
--- kmmainwidget.cpp 29 Nov 2002 23:33:14 -0000 1.1.2.51
+++ kmmainwidget.cpp 30 Nov 2002 11:11:45 -0000 1.1.2.52
@@ -2744,7 +2743,7 @@ void KMMainWidget::slotChangeCaption(QLi
}
//-----------------------------------------------------------------------------
-void KMMainWidget::removeDuplicates(void)
+void KMMainWidget::removeDuplicates()
{
KMFolder *oFolder = mFolder;
mHeaders->setFolder(0);
["031_add_remove_duplicate_feature_to_menubar" (text/x-diff)]
Index: kmmainwin.rc
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmmainwin.rc,v
retrieving revision 1.42
retrieving revision 1.42.2.1
diff -u -3 -p -r1.42 -r1.42.2.1
--- kmmainwin.rc 1 Sep 2002 13:59:06 -0000 1.42
+++ kmmainwin.rc 16 Sep 2002 14:21:12 -0000 1.42.2.1
@@ -67,6 +67,7 @@
<Action name="mark_all_as_read" />
<Action name="compact" />
<Action name="expire" />
+ <Action name="remove_duplicate_messages" />
<Separator/>
<Action name="empty" />
<Action name="delete_folder" />
["004_remove_duplicates_feature" (text/x-diff)]
Index: kmmainwin.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmmainwin.cpp,v
retrieving revision 1.541.2.3
diff -u -3 -p -r1.541.2.3 kmmainwin.cpp
--- kmmainwin.cpp 9 Dec 2002 23:02:02 -0000 1.541.2.3
+++ kmmainwin.cpp 26 Dec 2002 15:53:30 -0000
@@ -585,6 +585,10 @@ void KMMainWin::createWidgets(void)
//Commands not worthy of menu items, but that deserve configurable keybindings
new KAction(
+ i18n("Remove duplicate messages in current folder"), CTRL+Key_Asterisk, this,
+ SLOT(removeDuplicates()), actionCollection(), "remove_duplicate_messages");
+
+ new KAction(
i18n("Focus on Next Folder"), CTRL+Key_Right, mFolderTree,
SLOT(incCurrentFolder()), actionCollection(), "inc_current_folder");
@@ -3126,3 +3130,42 @@ void KMMainWin::slotChangeCaption(QListV
setCaption( names.join("/") );
}
+//-----------------------------------------------------------------------------
+void KMMainWin::removeDuplicates(void)
+{
+ KMFolder *oFolder = mFolder;
+ mHeaders->setFolder(0);
+ QMap< QString, QValueList<int> > idMD5s;
+ QValueList<int> redundantIds;
+ QValueList<int>::Iterator kt;
+ if (!mFolder)
+ return;
+ mFolder->open();
+ for (int i = mFolder->count() - 1; i >= 0; --i) {
+ QString id = (*mFolder)[i]->msgIdMD5();
+ idMD5s[id].append( i );
+ }
+ QMap< QString, QValueList<int> >::Iterator it;
+ for ( it = idMD5s.begin(); it != idMD5s.end() ; ++it ) {
+ QValueList<int>::Iterator jt;
+ bool finished = false;
+ for ( jt = (*it).begin(); jt != (*it).end() && !finished; ++jt )
+ if (!((*mFolder)[*jt]->isUnread())) {
+ (*it).remove( jt );
+ (*it).prepend( *jt );
+ finished = true;
+ }
+ for ( jt = (*it).begin(), ++jt; jt != (*it).end(); ++jt )
+ redundantIds.append( *jt );
+ }
+ qHeapSort( redundantIds );
+ kt = redundantIds.end();
+ if (kt != redundantIds.begin()) do {
+ mFolder->removeMsg( *(--kt) );
+ }
+ while (kt != redundantIds.begin());
+
+ mFolder->close();
+ mHeaders->setFolder(oFolder);
+}
+
Index: kmmainwin.h
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmmainwin.h,v
retrieving revision 1.148
diff -u -3 -p -r1.148 kmmainwin.h
--- kmmainwin.h 29 Oct 2002 08:35:06 -0000 1.148
+++ kmmainwin.h 26 Dec 2002 15:53:31 -0000
@@ -322,6 +322,7 @@ protected slots:
/** changes the caption and displays the foldername */
void slotChangeCaption(QListViewItem*);
+ void removeDuplicates();
protected:
KRadioAction * actionForHeaderStyle(int);
[Attachment #13 (application/pgp-signature)]
_______________________________________________
KMail Developers mailing list
kmail@mail.kde.org
http://mail.kde.org/mailman/listinfo/kmail
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic