00001 /* Copyright (C) 2006 by Marc Maurer <uwog@uwog.net> 00002 * 00003 * This program is free software; you can redistribute it and/or 00004 * modify it under the terms of the GNU General Public License 00005 * as published by the Free Software Foundation; either version 2 00006 * of the License, or (at your option) any later version. 00007 * 00008 * This program is distributed in the hope that it will be useful, 00009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 * GNU General Public License for more details. 00012 * 00013 * You should have received a copy of the GNU General Public License 00014 * along with this program; if not, write to the Free Software 00015 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00016 * 02110-1301 USA. 00017 */ 00018 00019 #ifndef __TCPBUDDY_H__ 00020 #define __TCPBUDDY_H__ 00021 00022 #include <map> 00023 #include <string> 00024 #include <boost/shared_ptr.hpp> 00025 #include "ut_string_class.h" 00026 #include <core/account/xp/Buddy.h> 00027 #include <core/account/xp/DocTreeItem.h> 00028 #include <core/account/xp/AccountHandler.h> 00029 00030 class DocHandle; 00031 00032 class TCPBuddy : public Buddy 00033 { 00034 public: 00035 TCPBuddy(AccountHandler* handler, const std::string& address, const std::string& port) 00036 : Buddy(handler), 00037 m_address(address), 00038 m_port(port) 00039 { 00040 setVolatile(true); 00041 } 00042 00043 virtual UT_UTF8String getDescriptor(bool /*include_session_info = false*/) const 00044 { 00045 return UT_UTF8String("tcp://") + m_address.c_str() + UT_UTF8String(":") + m_port.c_str(); 00046 } 00047 00048 virtual UT_UTF8String getDescription() const 00049 { 00050 return UT_UTF8String(m_address.c_str()) + UT_UTF8String(":") + m_port.c_str(); 00051 } 00052 00053 const std::string& getAddress() const 00054 { return m_address; } 00055 00056 const std::string& getPort() const 00057 { return m_port; } 00058 00059 virtual const DocTreeItem* getDocTreeItems() const 00060 { 00061 const std::vector<DocHandle*>& docHandles = getDocHandles(); 00062 DocTreeItem* first = 0; 00063 DocTreeItem* prev = 0; 00064 for (std::vector<DocHandle*>::const_iterator pos = docHandles.begin(); pos != docHandles.end(); pos++) 00065 { 00066 DocTreeItem* item = new DocTreeItem(); 00067 item->m_type = DOCTREEITEM_TYPE_DOCUMENT; 00068 item->m_docHandle = *pos; 00069 item->m_child = 0; 00070 item->m_next = 0; 00071 00072 if (!first) 00073 first = item; 00074 if (prev) 00075 prev->m_next = item; 00076 prev = item; 00077 } 00078 return first; 00079 } 00080 00081 private: 00082 std::string m_address; 00083 std::string m_port; 00084 }; 00085 00086 typedef boost::shared_ptr<TCPBuddy> TCPBuddyPtr; 00087 00088 #endif /* TCPBUDDY_H */