1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <sal/config.h>
12 #include <vcl/graphicfilter.hxx>
13 #include <tubes/conference.hxx>
14 #include <tubes/collaboration.hxx>
15 #include <tubes/manager.hxx>
16 #include <vcl/button.hxx>
17 #include <vcl/dialog.hxx>
18 #include <vcl/lstbox.hxx>
20 #include <telepathy-glib/telepathy-glib.h>
24 class TubeContacts
: public ModelessDialog
26 PushButton
* mpBtnDemo
;
27 PushButton
* mpBtnBuddy
;
28 PushButton
* mpBtnGroup
;
29 PushButton
* mpBtnInvite
;
30 PushButton
* mpBtnListen
;
32 Collaboration
* mpCollaboration
;
34 DECL_LINK( BtnDemoHdl
, void * );
35 DECL_LINK( BtnConnectHdl
, void * );
36 DECL_LINK( BtnGroupHdl
, void * );
37 DECL_LINK( BtnInviteHdl
, void * );
38 DECL_LINK( BtnListenHdl
, void * );
40 AccountContactPairV maACs
;
44 if (mpList
->GetSelectEntryCount())
46 sal_uInt16 i
= mpList
->GetSelectEntryPos();
47 TpContact
* pContact
= maACs
[i
].second
;
48 mpCollaboration
->Invite( pContact
);
54 if (!TeleManager::registerClients())
55 SAL_INFO( "tubes", "Could not register client handlers." );
58 void StartDemoSession()
60 TeleConference
* pConference
= TeleManager::startDemoSession();
62 SAL_WARN( "tubes", "Could not start demo session!" );
65 mpCollaboration
->StartCollaboration( pConference
);
66 mpCollaboration
->SaveAndSendFile( NULL
);
70 void StartBuddySession()
72 if (mpList
->GetSelectEntryCount())
74 sal_uInt16 i
= mpList
->GetSelectEntryPos();
75 TpAccount
* pAccount
= maACs
[i
].first
;
76 TpContact
* pContact
= maACs
[i
].second
;
77 SAL_INFO( "tubes", "picked " << tp_contact_get_identifier( pContact
) );
78 TeleConference
* pConference
= TeleManager::startBuddySession( pAccount
, pContact
);
80 SAL_WARN( "tubes", "Could not start session with " <<
81 tp_contact_get_identifier( pContact
) );
84 mpCollaboration
->StartCollaboration( pConference
);
85 mpCollaboration
->SaveAndSendFile( pContact
);
90 void StartGroupSession()
92 if (mpList
->GetSelectEntryCount())
94 sal_uInt16 i
= mpList
->GetSelectEntryPos();
95 TpAccount
* pAccount
= maACs
[i
].first
;
96 SAL_INFO( "tubes", "picked " << tp_account_get_display_name( pAccount
) );
97 TeleConference
* pConference
= TeleManager::startGroupSession( pAccount
,
98 OUString("liboroom"), OUString("conference.jabber.org") );
100 SAL_WARN( "tubes", "Could not start group session." );
103 mpCollaboration
->StartCollaboration( pConference
);
109 TubeContacts( Collaboration
* pCollaboration
) :
110 ModelessDialog( NULL
, "ContactsDialog", "tubes/ui/contacts.ui" ),
111 mpCollaboration( pCollaboration
)
113 get( mpBtnListen
, "listen");
114 get( mpBtnInvite
, "invite");
115 get( mpBtnDemo
, "demo");
116 get( mpBtnBuddy
, "buddy");
117 get( mpBtnGroup
, "group");
118 get( mpList
, "contacts");
119 mpBtnListen
->SetClickHdl( LINK( this, TubeContacts
, BtnListenHdl
) );
120 mpBtnInvite
->SetClickHdl( LINK( this, TubeContacts
, BtnInviteHdl
) );
121 mpBtnDemo
->SetClickHdl( LINK( this, TubeContacts
, BtnDemoHdl
) );
122 mpBtnBuddy
->SetClickHdl( LINK( this, TubeContacts
, BtnConnectHdl
) );
123 mpBtnGroup
->SetClickHdl( LINK( this, TubeContacts
, BtnGroupHdl
) );
125 virtual ~TubeContacts()
129 static OUString
fromUTF8( const char *pStr
)
131 return OStringToOUString( OString( pStr
, strlen( pStr
) ),
132 RTL_TEXTENCODING_UTF8
);
137 SAL_INFO( "tubes", "Populating contact list dialog" );
141 AccountContactPairV aPairs
= TeleManager::getContacts();
142 AccountContactPairV::iterator it
;
143 // make sure we have enough memory to not need re-allocation
144 // which would invalidate pointers stored in mpList entries
145 maACs
.reserve( aPairs
.size() );
146 for( it
= aPairs
.begin(); it
!= aPairs
.end(); ++it
)
149 GFile
*pAvatarFile
= tp_contact_get_avatar_file( it
->second
);
152 const OUString sAvatarFileUrl
= fromUTF8( g_file_get_path ( pAvatarFile
) );
154 if( GRFILTER_OK
== GraphicFilter::LoadGraphic( sAvatarFileUrl
, OUString(""), aGraphic
) )
156 BitmapEx aBitmap
= aGraphic
.GetBitmapEx();
157 double fScale
= 30.0 / aBitmap
.GetSizePixel().Height();
158 aBitmap
.Scale( fScale
, fScale
);
159 aImage
= Image( aBitmap
);
162 OUStringBuffer
aEntry( 128 );
163 aEntry
.append( " " );
164 aEntry
.append( fromUTF8 ( tp_contact_get_alias( it
->second
) ) );
165 aEntry
.append( " - " );
166 aEntry
.append( fromUTF8 ( tp_contact_get_identifier( it
->second
) ) );
167 mpList
->InsertEntry( aEntry
.makeStringAndClear(), aImage
);
168 // FIXME: ref the TpAccount, TpContact ...
169 maACs
.push_back( AccountContactPair( it
->first
, it
->second
) );
171 g_object_unref (it
->first
);
172 g_object_unref (it
->second
);
178 IMPL_LINK_NOARG( TubeContacts
, BtnDemoHdl
)
184 IMPL_LINK_NOARG( TubeContacts
, BtnConnectHdl
)
190 IMPL_LINK_NOARG( TubeContacts
, BtnGroupHdl
)
196 IMPL_LINK_NOARG( TubeContacts
, BtnInviteHdl
)
202 IMPL_LINK_NOARG( TubeContacts
, BtnListenHdl
)
208 } // anonymous namespace
210 void Collaboration::DisplayContacts()
213 mpContacts
= new TubeContacts( this );
214 reinterpret_cast<TubeContacts
*> (mpContacts
)->Populate();
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */