1 /*
2  * This file is part of Licq, an instant messaging client for UNIX.
3  * Copyright (C) 2007-2010 Licq developers
4  *
5  * Licq is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * Licq is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Licq; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19 
20 #ifndef MULTICONTACTPROXY_H
21 #define MULTICONTACTPROXY_H
22 
23 #include <set>
24 
25 #include <licq/userid.h>
26 
27 #include "contactlist.h"
28 #include "sortedcontactlistproxy.h"
29 
30 
31 namespace LicqQtGui
32 {
33 class ContactListModel;
34 
35 /**
36  * Proxy for ContactListModel that presents a sorted list of custom contats
37  *
38  * This proxy presents only those contacts specified by the user. Used for
39  * listing multiple recipients in the send dialog.
40  * Sorting is inherited from SortedContactList.
41  */
42 class MultiContactProxy : public SortedContactListProxy
43 {
44   Q_OBJECT
45 
46 public:
47   /**
48    * Constructor
49    *
50    * @param contactList The contact list to use contacts from
51    * @param parent Parent object
52    */
53   MultiContactProxy(ContactListModel* contactList, QObject* parent = NULL);
54 
55   /**
56    * Destructor
57    */
~MultiContactProxy()58   virtual ~MultiContactProxy() {}
59 
60   /**
61    * Clear the list
62    */
63   void clear();
64 
65   /**
66    * Add a contact to the list
67    *
68    * @param userId User id
69    */
70   void add(const Licq::UserId& userId);
71 
72   /**
73    * Remove a contact from the list
74    *
75    * @param userId User id
76    */
77   void remove(const Licq::UserId& userId);
78 
79   /**
80    * Remove a list of contacts from the list
81    *
82    * @param indexes Indexes of the contacts to remove
83    */
84   void remove(const QModelIndexList& indexes);
85 
86   /**
87    * Crop the list to containt only the specified list
88    *
89    * @param indexes Indexes of the contacts to keep
90    */
91   void crop(const QModelIndexList& indexes);
92 
93   /**
94    * Add all contacts from a group
95    *
96    * @param groupId Group id
97    */
98   void addGroup(int groupId);
99 
100   /**
101    * Return the current list of contacts
102    *
103    * @return A set containing the contacts
104    */
contacts()105   const std::set<Licq::UserId>& contacts() const
106   { return myContacts; }
107 
108   /**
109    * Get root index the view should use
110    *
111    * @return Root index
112    */
113   QModelIndex rootIndex() const;
114 
115 private:
116   /**
117    * Check if an item should be present in the list or if it should be hidden
118    * from the view
119    *
120    * @param source_row A row in the source model to test
121    * @param source_parent Parent item for the row to test
122    * @return True if the item should be visible in the view
123    */
124   bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const;
125 
126   std::set<Licq::UserId> myContacts;
127 };
128 
129 } // namespace LicqQtGui
130 
131 #endif
132