|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 #include "qmessagefoldersortorder.h" |
|
42 #include "qmessagefoldersortorder_p.h" |
|
43 |
|
44 QTM_BEGIN_NAMESPACE |
|
45 |
|
46 bool QMessageFolderSortOrderPrivate::lessthan(const QMessageFolderSortOrder &sortOrder, const QMessageFolder &l, const QMessageFolder &r) |
|
47 { |
|
48 QMessageFolderSortOrderPrivate *d(sortOrder.d_ptr); |
|
49 |
|
50 QList<QPair<Field, Qt::SortOrder> >::iterator it(d->_fieldOrderList.begin()); |
|
51 while (it != d->_fieldOrderList.end()) { |
|
52 Field field((*it).first); |
|
53 Qt::SortOrder order((*it).second); |
|
54 ++it; |
|
55 |
|
56 const QMessageFolder *left; |
|
57 const QMessageFolder *right; |
|
58 if (order == Qt::AscendingOrder) { |
|
59 left = &l; |
|
60 right = &r; |
|
61 } else { |
|
62 left = &r; |
|
63 right = &l; |
|
64 } |
|
65 |
|
66 switch (field) |
|
67 { |
|
68 case Name: { |
|
69 if (left->name() < right->name()) { |
|
70 return true; |
|
71 } else if (right->name() < left->name()) { |
|
72 return false; |
|
73 } else { |
|
74 continue; |
|
75 } |
|
76 } |
|
77 case Path: { |
|
78 if (left->path() < right->path()) { |
|
79 return true; |
|
80 } else if (right->path() < left->path()) { |
|
81 return false; |
|
82 } else { |
|
83 continue; |
|
84 } |
|
85 } |
|
86 } // switch |
|
87 } |
|
88 return false; // equality |
|
89 } |
|
90 |
|
91 QMessageFolderSortOrder::QMessageFolderSortOrder() |
|
92 : d_ptr(new QMessageFolderSortOrderPrivate(this)) |
|
93 { |
|
94 } |
|
95 |
|
96 QMessageFolderSortOrder::QMessageFolderSortOrder(const QMessageFolderSortOrder &other) |
|
97 : d_ptr(new QMessageFolderSortOrderPrivate(this)) |
|
98 { |
|
99 this->operator=(other); |
|
100 } |
|
101 |
|
102 QMessageFolderSortOrder::~QMessageFolderSortOrder() |
|
103 { |
|
104 delete d_ptr; |
|
105 d_ptr = 0; |
|
106 } |
|
107 |
|
108 QMessageFolderSortOrder& QMessageFolderSortOrder::operator=(const QMessageFolderSortOrder& other) |
|
109 { |
|
110 if (&other != this) { |
|
111 d_ptr->_fieldOrderList = other.d_ptr->_fieldOrderList; |
|
112 } |
|
113 |
|
114 return *this; |
|
115 } |
|
116 |
|
117 bool QMessageFolderSortOrder::isEmpty() const |
|
118 { |
|
119 return d_ptr->_fieldOrderList.isEmpty(); |
|
120 } |
|
121 |
|
122 bool QMessageFolderSortOrder::isSupported() const |
|
123 { |
|
124 return true; |
|
125 } |
|
126 |
|
127 QMessageFolderSortOrder QMessageFolderSortOrder::operator+(const QMessageFolderSortOrder& other) const |
|
128 { |
|
129 QMessageFolderSortOrder sum; |
|
130 sum.d_ptr->_fieldOrderList = d_ptr->_fieldOrderList + other.d_ptr->_fieldOrderList; |
|
131 return sum; |
|
132 } |
|
133 |
|
134 QMessageFolderSortOrder& QMessageFolderSortOrder::operator+=(const QMessageFolderSortOrder& other) |
|
135 { |
|
136 if (&other == this) |
|
137 return *this; |
|
138 d_ptr->_fieldOrderList += other.d_ptr->_fieldOrderList; |
|
139 return *this; |
|
140 } |
|
141 |
|
142 bool QMessageFolderSortOrder::operator==(const QMessageFolderSortOrder& other) const |
|
143 { |
|
144 return (d_ptr->_fieldOrderList == other.d_ptr->_fieldOrderList); |
|
145 } |
|
146 |
|
147 QMessageFolderSortOrder QMessageFolderSortOrder::byName(Qt::SortOrder order) |
|
148 { |
|
149 QMessageFolderSortOrder result; |
|
150 QPair<QMessageFolderSortOrderPrivate::Field, Qt::SortOrder> fieldOrder(QMessageFolderSortOrderPrivate::Name, order); |
|
151 result.d_ptr->_fieldOrderList.append(fieldOrder); |
|
152 return result; |
|
153 } |
|
154 |
|
155 QMessageFolderSortOrder QMessageFolderSortOrder::byPath(Qt::SortOrder order) |
|
156 { |
|
157 QMessageFolderSortOrder result; |
|
158 QPair<QMessageFolderSortOrderPrivate::Field, Qt::SortOrder> fieldOrder(QMessageFolderSortOrderPrivate::Path, order); |
|
159 result.d_ptr->_fieldOrderList.append(fieldOrder); |
|
160 return result; |
|
161 } |
|
162 |
|
163 QTM_END_NAMESPACE |