From bc21b49a464ae153341ee8d836993ca89b1a6919 Mon Sep 17 00:00:00 2001 From: Matúš Kukan Date: Mon, 30 Jul 2012 11:49:10 +0200 Subject: tubes: move sc/source/ui/collab/contacts.* to tubes - sc no longer directly links against telepathy - there is new class ScCollaboration derived from abstract Collaboration describing collaboration functionality for apps used in tubes/ - also added resource manager into tubes/ Change-Id: Ic89ae955f5b47490f4f4b8781bcee5dea5336bae --- tubes/AllLangResTarget_tubes.mk | 19 +++ tubes/CppunitTest_tubes_test.mk | 4 + tubes/Library_tubes.mk | 8 +- tubes/Module_tubes.mk | 1 + tubes/Package_inc.mk | 2 + tubes/inc/tubes/collaboration.hxx | 34 +++++ tubes/inc/tubes/contacts.hxx | 38 ++++++ tubes/source/contacts.cxx | 280 ++++++++++++++++++++++++++++++++++++++ tubes/source/contacts.hrc | 11 ++ tubes/source/contacts.src | 60 ++++++++ 10 files changed, 456 insertions(+), 1 deletion(-) create mode 100644 tubes/AllLangResTarget_tubes.mk create mode 100644 tubes/inc/tubes/collaboration.hxx create mode 100644 tubes/inc/tubes/contacts.hxx create mode 100644 tubes/source/contacts.cxx create mode 100644 tubes/source/contacts.hrc create mode 100644 tubes/source/contacts.src (limited to 'tubes') diff --git a/tubes/AllLangResTarget_tubes.mk b/tubes/AllLangResTarget_tubes.mk new file mode 100644 index 000000000000..9cd4e1fea948 --- /dev/null +++ b/tubes/AllLangResTarget_tubes.mk @@ -0,0 +1,19 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +$(eval $(call gb_AllLangResTarget_AllLangResTarget,tubes)) + +$(eval $(call gb_AllLangResTarget_add_srs,tubes,tubes/res)) + +$(eval $(call gb_SrsTarget_SrsTarget,tubes/res)) + +$(eval $(call gb_SrsTarget_add_files,tubes/res,\ + tubes/source/contacts.src \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/tubes/CppunitTest_tubes_test.mk b/tubes/CppunitTest_tubes_test.mk index c229b2acb214..597102cb6bdb 100644 --- a/tubes/CppunitTest_tubes_test.mk +++ b/tubes/CppunitTest_tubes_test.mk @@ -38,7 +38,11 @@ $(eval $(call gb_CppunitTest_use_libraries,tubes_test, \ comphelper \ cppu \ sal \ + svt \ + svxcore \ + tl \ utl \ + vcl \ $(gb_STDLIBS) \ )) diff --git a/tubes/Library_tubes.mk b/tubes/Library_tubes.mk index 0acd0a9872d8..2ff9ab2407dd 100644 --- a/tubes/Library_tubes.mk +++ b/tubes/Library_tubes.mk @@ -43,6 +43,11 @@ $(eval $(call gb_Library_use_libraries,tubes,\ comphelper \ cppu \ sal \ + svt \ + svxcore \ + tl \ + utl \ + vcl \ )) $(eval $(call gb_Library_use_externals,tubes,\ @@ -51,8 +56,9 @@ $(eval $(call gb_Library_use_externals,tubes,\ $(eval $(call gb_Library_add_exception_objects,tubes,\ tubes/source/conference \ - tubes/source/manager \ tubes/source/contact-list \ + tubes/source/contacts \ + tubes/source/manager \ )) $(eval $(call gb_Library_add_cobjects,tubes,\ diff --git a/tubes/Module_tubes.mk b/tubes/Module_tubes.mk index bc54f18b3299..7eec7984e60f 100644 --- a/tubes/Module_tubes.mk +++ b/tubes/Module_tubes.mk @@ -30,6 +30,7 @@ $(eval $(call gb_Module_Module,tubes)) ifeq ($(ENABLE_TELEPATHY),TRUE) $(eval $(call gb_Module_add_targets,tubes,\ + AllLangResTarget_tubes \ Library_tubes \ Package_inc \ Executable_liboapprover \ diff --git a/tubes/Package_inc.mk b/tubes/Package_inc.mk index ff63f1870b4b..1502b90db147 100644 --- a/tubes/Package_inc.mk +++ b/tubes/Package_inc.mk @@ -26,8 +26,10 @@ $(eval $(call gb_Package_Package,tubes_inc,$(SRCDIR)/tubes/inc)) +$(eval $(call gb_Package_add_file,tubes_inc,inc/tubes/collaboration.hxx,tubes/collaboration.hxx)) $(eval $(call gb_Package_add_file,tubes_inc,inc/tubes/conference.hxx,tubes/conference.hxx)) $(eval $(call gb_Package_add_file,tubes_inc,inc/tubes/contact-list.hxx,tubes/contact-list.hxx)) +$(eval $(call gb_Package_add_file,tubes_inc,inc/tubes/contacts.hxx,tubes/contacts.hxx)) $(eval $(call gb_Package_add_file,tubes_inc,inc/tubes/manager.hxx,tubes/manager.hxx)) $(eval $(call gb_Package_add_file,tubes_inc,inc/tubes/tubesdllapi.h,tubes/tubesdllapi.h)) $(eval $(call gb_Package_add_file,tubes_inc,inc/tubes/warnings_guard_boost_signals2.hpp,tubes/warnings_guard_boost_signals2.hpp)) diff --git a/tubes/inc/tubes/collaboration.hxx b/tubes/inc/tubes/collaboration.hxx new file mode 100644 index 000000000000..5a3dddc89987 --- /dev/null +++ b/tubes/inc/tubes/collaboration.hxx @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_TUBES_COLLABORATION_HXX +#define INCLUDED_TUBES_COLLABORATION_HXX + +#include + +#include + +class TeleConference; +typedef struct _TpContact TpContact; + +class Collaboration +{ +public: + Collaboration() {} + virtual ~Collaboration() {} + + virtual TeleConference* GetConference() const = 0; + virtual void SetCollaboration( TeleConference* pConference ) = 0; + // TODO: I think this could be moved to TeleManager later. + virtual void SendFile( TpContact* pContact, const OUString& rURL ) = 0; +}; + +#endif // INCLUDED_TUBES_COLLABORATION_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tubes/inc/tubes/contacts.hxx b/tubes/inc/tubes/contacts.hxx new file mode 100644 index 000000000000..a2b1f7fb42b6 --- /dev/null +++ b/tubes/inc/tubes/contacts.hxx @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Major Contributor(s): + * Copyright (C) 2012 Michael Meeks (initial developer) + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ + +#include "sal/config.h" +#include + +class Collaboration; + +namespace tubes { + void TUBES_DLLPUBLIC createContacts( Collaboration* pCollaboration ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tubes/source/contacts.cxx b/tubes/source/contacts.cxx new file mode 100644 index 000000000000..046be9763286 --- /dev/null +++ b/tubes/source/contacts.cxx @@ -0,0 +1,280 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Major Contributor(s): + * Copyright (C) 2012 Michael Meeks (initial developer) + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ + +#include + +#include "contacts.hrc" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +ResId TubesResId( sal_uInt32 nId ) +{ + static ResMgr* pResMgr = NULL; + if (!pResMgr) + { + pResMgr = ResMgr::CreateResMgr( "tubes" ); + } + return ResId( nId, *pResMgr ); +} + +#define CONTACTS_DLG + +#ifdef CONTACTS_DLG +namespace { +class TubeContacts : public ModelessDialog +{ + FixedLine maLabel; + PushButton maBtnConnect; + PushButton maBtnGroup; + PushButton maBtnInvite; + PushButton maBtnListen; + SvxSimpleTableContainer maListContainer; + SvxSimpleTable maList; + TeleManager* mpManager; + Collaboration* mpCollaboration; + + DECL_LINK( BtnConnectHdl, void * ); + DECL_LINK( BtnGroupHdl, void * ); + DECL_LINK( BtnInviteHdl, void * ); + DECL_LINK( BtnListenHdl, void * ); + + struct AccountContact + { + TpAccount* mpAccount; + TpContact* mpContact; + AccountContact( TpAccount* pAccount, TpContact* pContact ): + mpAccount(pAccount), mpContact(pContact) {} + }; + boost::ptr_vector maACs; + + void Invite() + { + AccountContact *pAC = NULL; + if (maList.FirstSelected()) + pAC = static_cast (maList.FirstSelected()->GetUserData()); + if (pAC) + { + if (mpCollaboration->GetConference()) + { + TpContact* pContact = pAC->mpContact; + mpCollaboration->GetConference()->invite( pContact ); + mpCollaboration->SendFile( pContact, OStringToOUString( + mpCollaboration->GetConference()->getUuid(), RTL_TEXTENCODING_UTF8 ) ); + } + } + } + + void Listen() + { + if (!mpManager->registerClients()) + SAL_INFO( "sc.tubes", "Could not register client handlers." ); + } + + void StartBuddySession() + { + AccountContact *pAC = NULL; + if (maList.FirstSelected()) + pAC = static_cast (maList.FirstSelected()->GetUserData()); + if (pAC) + { + TpAccount* pAccount = pAC->mpAccount; + TpContact* pContact = pAC->mpContact; + fprintf( stderr, "picked %s\n", tp_contact_get_identifier( pContact ) ); + TeleConference* pConference = mpManager->startBuddySession( pAccount, pContact ); + if (!pConference) + fprintf( stderr, "could not start session with %s\n", + tp_contact_get_identifier( pContact ) ); + else + { + mpCollaboration->SetCollaboration( pConference ); + mpCollaboration->SendFile( pContact, OStringToOUString( + pConference->getUuid(), RTL_TEXTENCODING_UTF8 ) ); + } + } + } + + void StartGroupSession() + { + AccountContact *pAC = NULL; + if (maList.FirstSelected()) + pAC = static_cast (maList.FirstSelected()->GetUserData()); + if (pAC) + { + TpAccount* pAccount = pAC->mpAccount; + fprintf( stderr, "picked %s\n", tp_account_get_display_name( pAccount ) ); + TeleConference* pConference = mpManager->startGroupSession( pAccount, + rtl::OUString("liboroom"), rtl::OUString("conference.jabber.org") ); + if (!pConference) + fprintf( stderr, "could not start group session\n" ); + else + { + mpCollaboration->SetCollaboration( pConference ); + } + } + } + +public: + TubeContacts( Collaboration* pCollaboration ) : + ModelessDialog( NULL, TubesResId( RID_TUBES_DLG_CONTACTS ) ), + maLabel( this, TubesResId( FL_LABEL ) ), + maBtnConnect( this, TubesResId( BTN_CONNECT ) ), + maBtnGroup( this, TubesResId( BTN_GROUP ) ), + maBtnInvite( this, TubesResId( BTN_INVITE ) ), + maBtnListen( this, TubesResId( BTN_LISTEN ) ), + maListContainer( this, TubesResId( CTL_LIST ) ), + maList( maListContainer ), + mpManager( new TeleManager() ), + mpCollaboration( pCollaboration ) + { + Hide(); + maBtnConnect.SetClickHdl( LINK( this, TubeContacts, BtnConnectHdl ) ); + maBtnGroup.SetClickHdl( LINK( this, TubeContacts, BtnGroupHdl ) ); + maBtnInvite.SetClickHdl( LINK( this, TubeContacts, BtnInviteHdl ) ); + maBtnListen.SetClickHdl( LINK( this, TubeContacts, BtnListenHdl ) ); + + static long aStaticTabs[]= + { + 3 /* count */, 0, 20, 100, 150, 200 + }; + + maList.SvxSimpleTable::SetTabs( aStaticTabs ); + String sHeader( '\t' ); + sHeader += String( TubesResId( STR_HEADER_ALIAS ) ); + sHeader += '\t'; + sHeader += String( TubesResId( STR_HEADER_NAME ) ); + sHeader += '\t'; + maList.InsertHeaderEntry( sHeader, HEADERBAR_APPEND, HIB_LEFT ); + + mpManager->getContactList()->sigContactListChanged.connect( + boost::bind( &TubeContacts::Populate, this ) ); + } + virtual ~TubeContacts() + { + delete mpCollaboration; + delete mpManager; + } + + static rtl::OUString fromUTF8( const char *pStr ) + { + return rtl::OStringToOUString( rtl::OString( pStr, strlen( pStr ) ), + RTL_TEXTENCODING_UTF8 ); + } + + void Populate() + { + SAL_INFO( "sc.tubes", "Populating contact list dialog" ); + maList.Clear(); + ContactList *pContacts = mpManager->getContactList(); + if ( pContacts ) + { + AccountContactPairV aPairs = pContacts->getContacts(); + AccountContactPairV::iterator it; + for( it = aPairs.begin(); it != aPairs.end(); ++it ) + { + Image aImage; + GFile *pAvatarFile = tp_contact_get_avatar_file( it->second ); + if( pAvatarFile ) + { + const rtl::OUString sAvatarFileUrl = fromUTF8( g_file_get_path ( pAvatarFile ) ); + Graphic aGraphic; + if( GRFILTER_OK == GraphicFilter::LoadGraphic( sAvatarFileUrl, rtl::OUString(""), aGraphic ) ) + { + BitmapEx aBitmap = aGraphic.GetBitmapEx(); + double fScale = 30.0 / aBitmap.GetSizePixel().Height(); + aBitmap.Scale( fScale, fScale ); + aImage = Image( aBitmap ); + } + } + rtl::OUStringBuffer aEntry( 128 ); + aEntry.append( sal_Unicode( '\t' ) ); + aEntry.append( fromUTF8 ( tp_contact_get_alias( it->second ) ) ); + aEntry.append( sal_Unicode( '\t' ) ); + aEntry.append( fromUTF8 ( tp_contact_get_identifier( it->second ) ) ); + aEntry.append( sal_Unicode( '\t' ) ); + SvLBoxEntry* pEntry = maList.InsertEntry( aEntry.makeStringAndClear(), aImage, aImage ); + // FIXME: ref the TpAccount, TpContact ... + maACs.push_back( new AccountContact( it->first, it->second ) ); + pEntry->SetUserData( &maACs.back() ); + } + } + Show(); + } +}; + +IMPL_LINK_NOARG( TubeContacts, BtnConnectHdl ) +{ + StartBuddySession(); + return 0; +} + +IMPL_LINK_NOARG( TubeContacts, BtnGroupHdl ) +{ + StartGroupSession(); + return 0; +} + +IMPL_LINK_NOARG( TubeContacts, BtnInviteHdl ) +{ + Invite(); + return 0; +} + +IMPL_LINK_NOARG( TubeContacts, BtnListenHdl ) +{ + Listen(); + return 0; +} + +} // anonymous namespace +#endif + +namespace tubes { +void createContacts( Collaboration* pCollaboration ) +{ +#ifdef CONTACTS_DLG + static TubeContacts *pContacts = new TubeContacts( pCollaboration ); + pContacts->Populate(); +#endif +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tubes/source/contacts.hrc b/tubes/source/contacts.hrc new file mode 100644 index 000000000000..84c5c3381c6a --- /dev/null +++ b/tubes/source/contacts.hrc @@ -0,0 +1,11 @@ +#define RID_TUBES_DLG_CONTACTS 1000 + +#define FL_LABEL 1 +#define CTL_LIST 2 +#define BTN_CONNECT 3 +#define BTN_INVITE 4 +#define BTN_LISTEN 5 +#define BTN_GROUP 6 + +#define STR_HEADER_ALIAS 20 +#define STR_HEADER_NAME 21 diff --git a/tubes/source/contacts.src b/tubes/source/contacts.src new file mode 100644 index 000000000000..0cd386af2bfc --- /dev/null +++ b/tubes/source/contacts.src @@ -0,0 +1,60 @@ +#include "contacts.hrc" + +ModelessDialog RID_TUBES_DLG_CONTACTS +{ + HelpId = "TUBES_HID"; // has to be something ... + OutputSize = TRUE ; + SVLook = TRUE ; + Hide = FALSE ; + Moveable = TRUE ; + Closeable = TRUE ; + Size = MAP_APPFONT ( 220 , 225 ) ; + OutputSize = TRUE ; + Text [ en-US ] = "Contacts" ; + + FixedLine FL_LABEL + { + Pos = MAP_APPFONT ( 8 , 2 ) ; + Size = MAP_APPFONT ( 198 , 8 ) ; + Text [ en-US ] = "Select a contact to collaborate with" ; + }; + PushButton BTN_CONNECT + { + Pos = MAP_APPFONT( 70 , 200 ); + Size = MAP_APPFONT( 50 , 10 ); + Text [ en-US ] = "startBuddySession"; + }; + PushButton BTN_GROUP + { + Pos = MAP_APPFONT( 70 , 212 ); + Size = MAP_APPFONT( 50 , 10 ); + Text [ en-US ] = "startGroupSession"; + }; + PushButton BTN_INVITE + { + Pos = MAP_APPFONT( 130 , 200 ); + Size = MAP_APPFONT( 50 , 10 ); + Text [ en-US ] = "Invite"; + }; + PushButton BTN_LISTEN + { + Pos = MAP_APPFONT( 8 , 200 ); + Size = MAP_APPFONT( 50 , 10 ); + Text [ en-US ] = "Listen"; + }; + Control CTL_LIST + { + Pos = MAP_APPFONT ( 8 , 10 ) ; + Size = MAP_APPFONT ( 200 , 190 ) ; + Border = TRUE ; + TabStop = TRUE ; + }; + String STR_HEADER_ALIAS + { + Text [ en-US ] = "Alias" ; + }; + String STR_HEADER_NAME + { + Text [ en-US ] = "Name" ; + }; +}; -- cgit