• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kmail

  • sources
  • kde-4.12
  • kdepim
  • kmail
undostack.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KMail
3 
4  Copyright (C) 1999 Waldo Bastian (bastian@kde.org)
5  Copyright (c) 2003 Zack Rusin <zack@kde.org>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License
9  version 2 as published by the Free Software Foundation.
10 
11  This software is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this library; see the file COPYING. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "undostack.h"
23 
24 #include "kmmainwin.h"
25 #include "kmkernel.h"
26 #include <KJob>
27 #include <akonadi/itemmovejob.h>
28 
29 #include <kmessagebox.h>
30 #include <klocale.h>
31 #include <kdebug.h>
32 
33 #include <QList>
34 
35 namespace KMail {
36 
37 UndoStack::UndoStack(int size)
38  : QObject(0),
39  mSize(size),
40  mLastId(0),
41  mCachedInfo(0)
42 {
43 }
44 
45 UndoStack::~UndoStack()
46 {
47  clear();
48 }
49 
50 void UndoStack::clear()
51 {
52  qDeleteAll( mStack );
53  mStack.clear();
54 }
55 
56 int UndoStack::newUndoAction( const Akonadi::Collection &srcFolder, const Akonadi::Collection &destFolder )
57 {
58  UndoInfo *info = new UndoInfo;
59  info->id = ++mLastId;
60  info->srcFolder = srcFolder;
61  info->destFolder = destFolder;
62  if ((int) mStack.count() == mSize) {
63  delete mStack.last();
64  mStack.removeLast();
65  }
66  mStack.prepend( info );
67  emit undoStackChanged();
68  return info->id;
69 }
70 
71 void UndoStack::addMsgToAction( int undoId, const Akonadi::Item &item )
72 {
73  if ( !mCachedInfo || mCachedInfo->id != undoId ) {
74  QList<UndoInfo*>::const_iterator itr = mStack.constBegin();
75  while ( itr != mStack.constEnd() ) {
76  if ( (*itr)->id == undoId ) {
77  mCachedInfo = (*itr);
78  break;
79  }
80  ++itr;
81  }
82  }
83 
84  Q_ASSERT( mCachedInfo );
85  mCachedInfo->items.append( item );
86 }
87 
88 void UndoStack::undo()
89 {
90  if ( !mStack.isEmpty() )
91  {
92  UndoInfo *info = mStack.takeFirst();
93  emit undoStackChanged();
94  Akonadi::ItemMoveJob * job = new Akonadi::ItemMoveJob( info->items, info->srcFolder, this );
95  connect( job, SIGNAL(result(KJob*)), this, SLOT(slotMoveResult(KJob*)) );
96  delete info;
97  }
98  else
99  {
100  // Sorry.. stack is empty..
101  KMessageBox::sorry( kmkernel->mainWin(), i18n("There is nothing to undo."));
102  }
103 }
104 
105 void UndoStack::slotMoveResult( KJob *job )
106 {
107  if ( job->error() )
108  KMessageBox::sorry( kmkernel->mainWin(), i18n("Cannot move message. %1", job->errorString() ) );
109 }
110 
111 void UndoStack::pushSingleAction(const Akonadi::Item &item, const Akonadi::Collection &folder, const Akonadi::Collection &destFolder)
112 {
113  int id = newUndoAction( folder, destFolder );
114  addMsgToAction( id, item );
115 }
116 
117 void UndoStack::msgDestroyed( const Akonadi::Item & /*msg*/)
118 {
119  /*
120  for (UndoInfo *info = mStack.first(); info; )
121  {
122  if (info->msgIdMD5 == msg->msgIdMD5())
123  {
124  mStack.removeRef( info );
125  info = mStack.current();
126  }
127  else
128  info = mStack.next();
129  }
130  */
131 }
132 
133 void
134 UndoStack::folderDestroyed( const Akonadi::Collection &folder)
135 {
136  QList<UndoInfo*>::iterator it = mStack.begin();
137  while ( it != mStack.end() ) {
138  UndoInfo *info = *it;
139  if ( info &&
140  ( (info->srcFolder == folder) ||
141  (info->destFolder == folder) ) ) {
142  delete info;
143  it = mStack.erase( it );
144  }
145  else
146  ++it;
147  }
148  emit undoStackChanged();
149 }
150 
151 }
152 
153 #include "undostack.moc"
KMail::UndoStack::~UndoStack
~UndoStack()
Definition: undostack.cpp:45
KMail::UndoStack::clear
void clear()
Definition: undostack.cpp:50
KMail::UndoStack::slotMoveResult
void slotMoveResult(KJob *)
Definition: undostack.cpp:105
KMail::UndoInfo::id
int id
Definition: undostack.h:37
KMail::UndoStack::mCachedInfo
UndoInfo * mCachedInfo
Definition: undostack.h:70
KMail::UndoStack::newUndoAction
int newUndoAction(const Akonadi::Collection &srcFolder, const Akonadi::Collection &destFolder)
Definition: undostack.cpp:56
kmmainwin.h
undostack.h
QObject
KMail::UndoStack::undo
void undo()
Definition: undostack.cpp:88
KMail::UndoStack::mLastId
int mLastId
Definition: undostack.h:69
KMail::UndoInfo::destFolder
Akonadi::Collection destFolder
Definition: undostack.h:40
KMail::UndoInfo
A class for storing Undo information.
Definition: undostack.h:34
KMail::UndoStack::UndoStack
UndoStack(int size)
Definition: undostack.cpp:37
KMail::UndoStack::undoStackChanged
void undoStackChanged()
kmkernel
#define kmkernel
Definition: kmkernel.h:22
KMail::UndoInfo::srcFolder
Akonadi::Collection srcFolder
Definition: undostack.h:39
KMail::UndoStack::mStack
QList< UndoInfo * > mStack
Definition: undostack.h:67
kmkernel.h
KMail::UndoStack::folderDestroyed
void folderDestroyed(const Akonadi::Collection &folder)
Definition: undostack.cpp:134
KMail::UndoInfo::items
Akonadi::Item::List items
Definition: undostack.h:38
KJob
KMail::UndoStack::pushSingleAction
void pushSingleAction(const Akonadi::Item &item, const Akonadi::Collection &, const Akonadi::Collection &destFolder)
Definition: undostack.cpp:111
QList
KMail::UndoStack::mSize
int mSize
Definition: undostack.h:68
KMail::UndoStack::addMsgToAction
void addMsgToAction(int undoId, const Akonadi::Item &item)
Definition: undostack.cpp:71
KMail::UndoStack::msgDestroyed
void msgDestroyed(const Akonadi::Item &msg)
Definition: undostack.cpp:117
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:52 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal