summaryrefslogtreecommitdiffstats
path: root/scribus/updatemanager.cpp
blob: 7190d4eca3d62ac30bb0c4e08d10a54e29a5c63b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56


#include "updatemanager.h"

UpdateMemento::~UpdateMemento() 
{}


//	int m_updatesDisabled;
//	QSet<QPair<UpdateManaged*, UpdateMemento*> > m_pending;
	
typedef QPair<UpdateManaged*, UpdateMemento*> PendingUpdate;


UpdateManager::~UpdateManager()
{
	foreach(PendingUpdate pair, m_pending) {
		delete pair.second;
	}
}
	
void UpdateManager::setUpdatesEnabled(bool val)
{
	if (val)
	{
		if (m_updatesDisabled > 0)
		{
			if (--m_updatesDisabled == 0)
			{
				foreach(PendingUpdate pair, m_pending) {
					pair.first->updateNow(pair.second);
				}
				m_pending.clear();
			}
		}
	}
	else
	{
		++m_updatesDisabled;
	}
}


bool UpdateManager::requestUpdate(UpdateManaged* observable, UpdateMemento* what)
{
	if (m_updatesDisabled == 0)
	{
		return true;	
	}
	else
	{
		m_pending.insert(PendingUpdate(observable, what));
		return false;
	}
}