1 /* Copyright (C) 2007 One Laptop Per Child 2 * Author: Marc Maurer <uwog@uwog.net> 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 * 02110-1301 USA. 18 */ 19 20 #ifndef __SUGARACCOUNTHANDLER__ 21 #define __SUGARACCOUNTHANDLER__ 22 23 #include <set> 24 25 #include <account/xp/AccountHandler.h> 26 #include <dbus/dbus.h> 27 #include <dbus/dbus-glib.h> 28 #include <dbus/dbus-glib-lowlevel.h> 29 #include "SugarBuddy.h" 30 31 #define SUGAR_STATIC_STORAGE_TYPE "com.abisource.abiword.abicollab.backend.sugar" 32 33 extern AccountHandlerConstructor SugarAccountHandlerConstructor; 34 35 class Session; 36 class FV_View; 37 38 class SugarAccountHandler : public AccountHandler 39 { 40 public: 41 static SugarAccountHandler* getHandler(); 42 SugarAccountHandler(); // TODO: this constructor shouldn't be public 43 virtual ~SugarAccountHandler(); 44 45 // housekeeping 46 static UT_UTF8String getStaticStorageType(); getStorageType()47 virtual UT_UTF8String getStorageType() 48 { return getStaticStorageType(); } 49 virtual UT_UTF8String getDescription(); 50 virtual UT_UTF8String getDisplayType(); 51 52 // dialog management embedDialogWidgets(void *)53 virtual void embedDialogWidgets(void* /*pEmbeddingParent*/) 54 { UT_ASSERT_HARMLESS(UT_NOT_REACHED); } removeDialogWidgets(void *)55 virtual void removeDialogWidgets(void* /*pEmbeddingParent*/) 56 { UT_ASSERT_HARMLESS(UT_NOT_REACHED); } canDelete()57 virtual bool canDelete() 58 { return false; } canEditProperties()59 virtual bool canEditProperties() 60 { return false; } 61 virtual void loadProperties(); 62 virtual void storeProperties(); 63 64 // connection management 65 virtual ConnectResult connect(); 66 virtual bool disconnect(); 67 virtual bool isOnline(); 68 69 // user management 70 virtual BuddyPtr constructBuddy(const PropertyMap& props); 71 virtual BuddyPtr constructBuddy(const std::string& descriptor, BuddyPtr pBuddy); allowsManualBuddies()72 virtual bool allowsManualBuddies() 73 { return false; } 74 virtual void forceDisconnectBuddy(BuddyPtr pBuddy); 75 virtual bool hasAccess(const std::vector<std::string>& vAcl, BuddyPtr pBuddy); hasPersistentAccessControl()76 virtual bool hasPersistentAccessControl() 77 { return false; } 78 virtual bool recognizeBuddyIdentifier(const std::string& identifier); 79 80 // session management allowsSessionTakeover()81 virtual bool allowsSessionTakeover() 82 { return true; } canManuallyStartSession()83 virtual bool canManuallyStartSession() 84 { return false; } 85 86 // packet management 87 virtual bool send(const Packet* pPacket); 88 virtual bool send(const Packet* pPacket, BuddyPtr buddy); 89 Packet* createPacket(const std::string& packet, BuddyPtr pBuddy); 90 91 // event management 92 void handleEvent(Session& pSession); 93 94 // signal management 95 virtual void signal(const Event& event, BuddyPtr pSource); 96 97 // tube & buddy management 98 SugarBuddyPtr getBuddy(const UT_UTF8String& dbusAddress); 99 bool offerTube(FV_View* pView, const UT_UTF8String& tubeDBusAddress); 100 bool joinTube(FV_View* pView, const UT_UTF8String& tubeDBusAddress); 101 bool disconnectTube(FV_View* pView); 102 bool joinBuddy(FV_View* pView, const UT_UTF8String& buddyDBusAddress); 103 bool disjoinBuddy(FV_View* pView, const UT_UTF8String& buddyDBusAddress); 104 isIgnoredBuddy(const UT_UTF8String & buddyName)105 bool isIgnoredBuddy(const UT_UTF8String& buddyName) 106 { return m_ignoredBuddies.find(buddyName) != m_ignoredBuddies.end(); } 107 108 protected: 109 bool _send(const Packet* pPacket, const char* dbusAddress); 110 void _registerEditMethods(); 111 virtual void _handlePacket(Packet* packet, BuddyPtr buddy); 112 113 private: 114 static SugarAccountHandler* m_pHandler; 115 DBusConnection* m_pTube; 116 bool m_bIsInSession; 117 std::set<UT_UTF8String> m_ignoredBuddies; 118 UT_UTF8String m_sSessionId; 119 }; 120 121 #endif /* __SUGARACCOUNTHANDLER__ */ 122