00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef ROSTER_HH
00034 #define ROSTER_HH
00035
00036 #include <string>
00037 #include <set>
00038 #include <map>
00039 #include <sigc++/object.h>
00040 #include <sigc++/signal.h>
00041 #include <XCP.hh>
00042 #include <jabberoofwd.h>
00043 #include <presence.hh>
00044 #include <jutil.hh>
00045
00046 namespace jabberoo
00047 {
00052 class Roster
00053 : public SigC::Object
00054 {
00055 public:
00060 enum Subscription {
00061 rsNone,
00062 rsTo,
00063 rsFrom,
00064 rsBoth,
00065 rsRemove
00066 };
00067
00068
00069 class XCP_InvalidJID : public XCP{};
00070
00074 class Item {
00075 public:
00076
00082 Item(const judo::Element& t);
00090 Item(Roster& r, const judo::Element& t);
00096 Item(const std::string& jid, const std::string& nickname);
00100 ~Item();
00101 public:
00102
00108 void addToGroup(const std::string& group);
00114 void delFromGroup(const std::string& group);
00118 void clearGroups();
00123 void setNickname(const std::string& nickname);
00131 void setJID(const std::string& jid);
00132
00133
00137 bool isAvailable() const;
00141 std::string getNickname() const;
00145 std::string getJID() const;
00150 Subscription getSubsType() const;
00154 bool isPending() const;
00155
00156
00157 typedef std::set<std::string>::const_iterator iterator;
00162 iterator begin() const { return _groups.begin(); }
00167 iterator end() const { return _groups.end(); }
00172 bool empty() const { return _groups.empty(); }
00173
00174 protected:
00175
00176 void update(Roster& r, const std::string& jid, const Presence& p, Presence::Type prev_type);
00177 bool update(const judo::Element& t);
00178 bool update(Roster& r, const judo::Element& t);
00179 private:
00180 friend class Roster;
00181 int _rescnt;
00182 std::set<std::string> _groups;
00183 Subscription _type;
00184 bool _pending;
00185 std::string _nickname;
00186 std::string _jid;
00187 };
00188
00189 typedef std::map<std::string, Item, jutil::CaseInsensitiveCmp> ItemMap;
00190
00191
00192 typedef jutil::ValueIterator<ItemMap::iterator, Item > iterator;
00197 iterator begin() { return _items.begin(); }
00202 iterator end() { return _items.end(); }
00203
00204
00205 typedef jutil::ValueIterator<ItemMap::const_iterator, const Item> const_iterator;
00210 const_iterator begin() const { return _items.begin(); }
00215 const_iterator end() const { return _items.end(); }
00216
00217
00223 Roster(Session& s);
00224
00225
00230 Session& getSession() { return _owner; }
00231
00232
00236 const Roster::Item& operator[](const std::string& jid) const;
00237 Roster::Item& operator[](const std::string& jid);
00241 Roster& operator<<(const Item& i) { update(i); return *this; }
00242 public:
00243 void reset();
00244
00245
00250 bool containsJID(const std::string& jid) const;
00251
00252
00258 void update(const judo::Element& t);
00264 void update(const Presence& p, Presence::Type prev_type);
00273 void update(const Item& i);
00274
00275
00280 void deleteUser(const std::string& jid);
00284 void fetch() const;
00288 int size() const
00289 { return _items.size(); }
00290
00291
00292 static std::string translateS10N(Subscription stype);
00293 static Subscription translateS10N(const std::string& stype);
00294 static std::string filterJID(const std::string& jid);
00295
00296
00297 const std::map<std::string, std::set<std::string> >& getGroups() const { return _groups;}
00298 public:
00302 SigC::Signal0<void, SigC::Marshal<void> > evtRefresh;
00309 SigC::Signal3<void, const std::string&, bool, Presence::Type, SigC::Marshal<void> > evtPresence;
00310 private:
00311 friend class Item;
00312 void mergeItemGroups(const std::string& itemjid, const std::set<std::string>& oldgrp, const std::set<std::string>& newgrp);
00313 void removeItemFromGroup(const std::string& group, const std::string& jid);
00314 void removeItemFromAllGroups(const Item& item);
00315 void deleteAgent(const judo::Element& iq);
00316 ItemMap _items;
00317 std::map<std::string, std::set<std::string> > _groups;
00318 Session& _owner;
00319 };
00320
00321 }
00322 #endif // #ifndef ROSTER_HH