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

kmail

  • sources
  • kde-4.14
  • 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 using 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 QString UndoStack::undoInfo() const
57 {
58  if (!mStack.isEmpty()) {
59  UndoInfo *info = mStack.first();
60  return info->moveToTrash ? i18n("Move To Trash") : i18np("Move Message", "Move Messages", info->items.count());
61  } else {
62  return QString();
63  }
64 }
65 
66 int UndoStack::newUndoAction( const Akonadi::Collection &srcFolder, const Akonadi::Collection &destFolder )
67 {
68  UndoInfo *info = new UndoInfo;
69  info->id = ++mLastId;
70  info->srcFolder = srcFolder;
71  info->destFolder = destFolder;
72  info->moveToTrash = (destFolder == CommonKernel->trashCollectionFolder());
73  if ((int) mStack.count() == mSize) {
74  delete mStack.last();
75  mStack.removeLast();
76  }
77  mStack.prepend( info );
78  emit undoStackChanged();
79  return info->id;
80 }
81 
82 void UndoStack::addMsgToAction( int undoId, const Akonadi::Item &item )
83 {
84  if ( !mCachedInfo || mCachedInfo->id != undoId ) {
85  QList<UndoInfo*>::const_iterator itr = mStack.constBegin();
86  while ( itr != mStack.constEnd() ) {
87  if ( (*itr)->id == undoId ) {
88  mCachedInfo = (*itr);
89  break;
90  }
91  ++itr;
92  }
93  }
94 
95  Q_ASSERT( mCachedInfo );
96  mCachedInfo->items.append( item );
97 }
98 
99 void UndoStack::undo()
100 {
101  if ( !mStack.isEmpty() )
102  {
103  UndoInfo *info = mStack.takeFirst();
104  emit undoStackChanged();
105  Akonadi::ItemMoveJob * job = new Akonadi::ItemMoveJob( info->items, info->srcFolder, this );
106  connect( job, SIGNAL(result(KJob*)), this, SLOT(slotMoveResult(KJob*)) );
107  delete info;
108  }
109  else
110  {
111  // Sorry.. stack is empty..
112  KMessageBox::sorry( kmkernel->mainWin(), i18n("There is nothing to undo."));
113  }
114 }
115 
116 void UndoStack::slotMoveResult( KJob *job )
117 {
118  if ( job->error() )
119  KMessageBox::sorry( kmkernel->mainWin(), i18n("Cannot move message. %1", job->errorString() ) );
120 }
121 
122 void UndoStack::pushSingleAction(const Akonadi::Item &item, const Akonadi::Collection &folder, const Akonadi::Collection &destFolder)
123 {
124  const int id = newUndoAction( folder, destFolder );
125  addMsgToAction( id, item );
126 }
127 
128 void UndoStack::folderDestroyed( const Akonadi::Collection &folder)
129 {
130  QList<UndoInfo*>::iterator it = mStack.begin();
131  while ( it != mStack.end() ) {
132  UndoInfo *info = *it;
133  if ( info &&
134  ( (info->srcFolder == folder) ||
135  (info->destFolder == folder) ) ) {
136  delete info;
137  it = mStack.erase( it );
138  }
139  else
140  ++it;
141  }
142  emit undoStackChanged();
143 }
144 
KMail::UndoStack::undo
void undo()
Definition: undostack.cpp:99
KMail::UndoStack::pushSingleAction
void pushSingleAction(const Akonadi::Item &item, const Akonadi::Collection &, const Akonadi::Collection &destFolder)
Definition: undostack.cpp:122
KMail::UndoStack::slotMoveResult
void slotMoveResult(KJob *)
Definition: undostack.cpp:116
KMail::UndoStack::clear
void clear()
Definition: undostack.cpp:50
KMail::UndoInfo::id
int id
Definition: undostack.h:43
KMail::UndoInfo::moveToTrash
bool moveToTrash
Definition: undostack.h:47
KMail::UndoStack::mCachedInfo
UndoInfo * mCachedInfo
Definition: undostack.h:77
kmmainwin.h
undostack.h
KMail::UndoStack::addMsgToAction
void addMsgToAction(int undoId, const Akonadi::Item &item)
Definition: undostack.cpp:82
QList::const_iterator
KMail::UndoStack::mLastId
int mLastId
Definition: undostack.h:76
KMail::UndoInfo::destFolder
Akonadi::Collection destFolder
Definition: undostack.h:46
QObject
KMail::UndoInfo
A class for storing Undo information.
Definition: undostack.h:34
KMail::UndoStack::undoStackChanged
void undoStackChanged()
QString
QList::iterator
kmkernel
#define kmkernel
Definition: kmkernel.h:24
KMail::UndoInfo::srcFolder
Akonadi::Collection srcFolder
Definition: undostack.h:45
KMail::UndoStack::mStack
QList< UndoInfo * > mStack
Definition: undostack.h:74
KMail::UndoStack::UndoStack
UndoStack(int size)
Definition: undostack.cpp:37
kmkernel.h
KMail::UndoInfo::items
Akonadi::Item::List items
Definition: undostack.h:44
KMail::UndoStack::undoInfo
QString undoInfo() const
Definition: undostack.cpp:56
KMail::UndoStack::newUndoAction
int newUndoAction(const Akonadi::Collection &srcFolder, const Akonadi::Collection &destFolder)
Definition: undostack.cpp:66
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KMail::UndoStack::~UndoStack
~UndoStack()
Definition: undostack.cpp:45
KJob
KMail::UndoStack::folderDestroyed
void folderDestroyed(const Akonadi::Collection &folder)
Definition: undostack.cpp:128
KMail::UndoStack::mSize
int mSize
Definition: undostack.h:75
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:33 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
  • pimprint

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