• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ServiceBuddy.h

Go to the documentation of this file.
00001 /* Copyright (C) 2006,2007 Marc Maurer <uwog@uwog.net>
00002  * Copyright (C) 2008 AbiSource Corporation B.V.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301 USA.
00018  */
00019 
00020 #ifndef __SERVICEBUDDY__
00021 #define __SERVICEBUDDY__
00022 
00023 #include <string>
00024 #ifdef _MSC_VER
00025 #include "msc_stdint.h"
00026 #else
00027 #include <stdint.h>
00028 #endif
00029 #include <boost/lexical_cast.hpp>
00030 #include <boost/shared_ptr.hpp>
00031 #include "ut_string_class.h"
00032 #include <core/account/xp/Buddy.h>
00033 #include <core/account/xp/AccountHandler.h>
00034 
00035 enum ServiceBuddyType
00036 {
00037     SERVICE_USER = 0,
00038     SERVICE_FRIEND,
00039     SERVICE_GROUP
00040 };
00041 
00042 class ServiceBuddy : public Buddy
00043 {
00044 public:
00045     ServiceBuddy(AccountHandler* handler, ServiceBuddyType type_, uint64_t user_id, const std::string& name, const std::string& domain)
00046         : Buddy(handler),
00047         m_type(type_),
00048         m_user_id(user_id),
00049         m_name(name),
00050         m_domain(domain)
00051     {
00052         setVolatile(true);
00053     }
00054 
00055     virtual UT_UTF8String getDescriptor(bool include_session_info = false) const
00056     {
00057         if (include_session_info)
00058         {
00059             UT_ASSERT_HARMLESS(UT_NOT_REACHED);
00060         }
00061         std::string descr = std::string("acn://")+
00062                                 boost::lexical_cast<std::string>(m_user_id) + ":" +
00063                                 boost::lexical_cast<std::string>(m_type) + "@" +
00064                                 m_domain;
00065         return descr.c_str();
00066     }
00067 
00068     virtual UT_UTF8String getDescription() const
00069         { return m_name.c_str(); }
00070 
00071     ServiceBuddyType getType() const
00072         { return m_type; }
00073 
00074     uint64_t getUserId() const
00075         { return m_user_id; }
00076 
00077     const std::string& getName() const
00078         { return m_name; }
00079 
00080     virtual const DocTreeItem* getDocTreeItems() const
00081     {
00082         const std::vector<DocHandle*>& docHandles = getDocHandles();
00083         DocTreeItem* first = 0;
00084         DocTreeItem* prev = 0;
00085         for (std::vector<DocHandle*>::const_iterator pos = docHandles.begin(); pos != docHandles.end(); pos++)
00086         {
00087             DocTreeItem* item = new DocTreeItem();
00088             item->m_type = DOCTREEITEM_TYPE_DOCUMENT;
00089             item->m_docHandle = *pos;
00090             item->m_child = 0;
00091             item->m_next = 0;
00092 
00093             if (!first)
00094                 first = item;
00095             if (prev)
00096                 prev->m_next = item;
00097             prev = item;
00098         }
00099         return first;
00100     }
00101 
00102 private:
00103     ServiceBuddyType    m_type;
00104     uint64_t            m_user_id;
00105     std::string         m_name;
00106     std::string         m_domain;
00107 };
00108 
00109 typedef boost::shared_ptr<ServiceBuddy> ServiceBuddyPtr;
00110 
00111 #endif /* __SERVICEBUDDY__ */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1