2
* This file is part of buteo-syncfw package
4
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6
* Contact: Sateesh Kavuri <sateesh.kavuri@nokia.com>
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public License
10
* version 2.1 as published by the Free Software Foundation.
12
* This library is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25
#include "SyncQueue.h"
26
#include "SyncSession.h"
27
#include "SyncProfile.h"
28
#include "LogMacros.h"
30
using namespace Buteo;
32
void SyncQueue::enqueue(SyncSession *aSession)
36
iItems.enqueue(aSession);
40
SyncSession *SyncQueue::dequeue()
44
SyncSession *p = NULL;
46
if (!iItems.isEmpty())
54
SyncSession *SyncQueue::head()
58
SyncSession *p = NULL;
59
if (!iItems.isEmpty())
67
bool SyncQueue::isEmpty() const
71
return iItems.isEmpty();
74
bool SyncQueue::contains(const QString &aProfileName) const
78
QQueue<SyncSession*>::const_iterator i;
79
for (i = iItems.begin(); i != iItems.end(); ++i)
81
if ((*i)->profileName() == aProfileName)
88
bool syncSessionPointerLessThan(SyncSession *&aLhs, SyncSession *&aRhs)
91
// Manual sync has higher priority than scheduled sync.
92
if (aLhs->isScheduled() != aRhs->isScheduled())
93
return !aLhs->isScheduled();
95
SyncProfile *lhsProfile = aLhs->profile();
96
SyncProfile *rhsProfile = aRhs->profile();
97
if (lhsProfile == 0 || rhsProfile == 0)
100
// Device sync has higher priority than online sync.
101
SyncProfile::DestinationType lhsDestType = lhsProfile->destinationType();
102
SyncProfile::DestinationType rhsDestType = rhsProfile->destinationType();
103
if (lhsDestType != rhsDestType)
104
return (lhsDestType == SyncProfile::DESTINATION_TYPE_DEVICE);
110
void SyncQueue::sort()
114
// @todo: Sort queued profiles using some criteria.