Added a simple WIP ContactInfoWindow that will be improved while we add new informations available in the ContactLiker, actually it's useful to get the contact id/email.

This commit is contained in:
barrett 2012-03-11 15:11:29 +00:00
parent b80c9b2b11
commit 730e9d3d49
7 changed files with 181 additions and 6 deletions

View File

@ -52,6 +52,7 @@ Application Caya :
NicknameTextControl.cpp
RosterItem.cpp
RosterListView.cpp
ContactInfoWindow.cpp
StatusMenuItem.cpp
StatusView.cpp
CayaRenderView.cpp

View File

@ -289,6 +289,7 @@ MainWindow::ImMessage(BMessage* msg)
// Sort list view again
fListView->Sort();
// Check if the user want the notification
if (!CayaPreferences::Item()->NotifyContactStatus)
break;

View File

@ -305,7 +305,8 @@ Server::ImMessage(BMessage* msg)
linker->SetNotifyAvatarBitmap(NULL);
break;
}
case IM_SEND_MESSAGE: {
case IM_SEND_MESSAGE:
{
// Route this message through the appropriate ProtocolLooper
ContactLinker* linker = _EnsureContactLinker(msg);
if (linker->GetProtocolLooper())

View File

@ -0,0 +1,104 @@
/*
* Copyright 2012, Casalinuovo Dario. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Casalinuovo Dario
*/
#include <Alert.h>
#include <Application.h>
#include <Box.h>
#include <GridLayout.h>
#include <GridLayoutBuilder.h>
#include <GroupLayout.h>
#include <GroupLayoutBuilder.h>
#include <Layout.h>
#include <Message.h>
#include <SpaceLayoutItem.h>
#include <String.h>
#include "BitmapView.h"
#include "CayaMessages.h"
#include "CayaProtocolMessages.h"
#include "ContactLinker.h"
#include "CayaConstants.h"
#include "CayaRenderView.h"
#include "NotifyMessage.h"
#include "ContactInfoWindow.h"
ContactInfoWindow::ContactInfoWindow(ContactLinker* linker)
:
BWindow(BRect(200, 200, 500, 400),
"Contact Informations", B_FLOATING_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE),
fContactLinker(linker)
{
fPersonalMessage = new BTextView("personalMessage", B_WILL_DRAW);
fPersonalMessage->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE));
fPersonalMessage->SetText(fContactLinker->GetNotifyPersonalStatus());
fPersonalMessage->SetExplicitMaxSize(BSize(200, 200));
fPersonalMessage->MakeEditable(false);
fPersonalMessage->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
BString status(fContactLinker->GetName());
switch (fContactLinker->GetNotifyStatus()) {
case CAYA_ONLINE:
status << " is available";
break;
case CAYA_EXTENDED_AWAY:
case CAYA_AWAY:
status << " is away";
break;
case CAYA_DO_NOT_DISTURB:
status << " is busy, please do not disturb!";
break;
case CAYA_OFFLINE:
status << " is offline";
break;
default:
break;
}
status << "\n\n ID : ";
status << fContactLinker->GetId();
fStatus = new BTextView("status", B_WILL_DRAW);
fStatus->SetText(status);
fStatus->MakeEditable(false);
fStatus->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
SetLayout(new BGroupLayout(B_HORIZONTAL));
fAvatar = new BitmapView("ContactIcon");
fAvatar->SetExplicitMaxSize(BSize(70, 70));
fAvatar->SetExplicitMinSize(BSize(50, 50));
fAvatar->SetExplicitPreferredSize(BSize(50, 50));
fAvatar->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT, B_ALIGN_MIDDLE));
fAvatar->SetBitmap(fContactLinker->AvatarBitmap());
AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
.AddGroup(B_HORIZONTAL)
.Add(fStatus)
.Add(fAvatar)
.End()
.AddGroup(B_HORIZONTAL)
.Add(fPersonalMessage)
.End()
.SetInsets(5, 5, 5, 5)
);
MoveTo(BAlert::AlertPosition(Bounds().Width(), Bounds().Height() / 2));
}
void
ContactInfoWindow::MessageReceived(BMessage* message)
{
switch (message->what) {
default:
BWindow::MessageReceived(message);
break;
}
}

View File

@ -0,0 +1,34 @@
/*
* Copyright 2012, Casalinuovo Dario. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Casalinuovo Dario
*/
#ifndef _CONTACT_INFO_WINDOW_H
#define _CONTACT_INFO_WINDOW_H
#include <Window.h>
#include <TextView.h>
#include <StringView.h>
#include "Observer.h"
#include "CayaConstants.h"
class BitmapView;
class ContactLinker;
class ContactInfoWindow: public BWindow, public Observer {
public:
ContactInfoWindow(ContactLinker* linker);
virtual void MessageReceived(BMessage* message);
private:
BTextView* fStatus;
ContactLinker* fContactLinker;
BTextView* fPersonalMessage;
BitmapView* fAvatar;
};
#endif

View File

@ -14,6 +14,7 @@
#include <PopUpMenu.h>
#include <SeparatorItem.h>
#include "ContactInfoWindow.h"
#include "ContactLinker.h"
#include "RosterItem.h"
#include "RosterListView.h"
@ -54,8 +55,8 @@ RosterListView::RosterListView(const char* name)
fPrevItem(NULL)
{
// Context menu
fPopUp = new BPopUpMenu("contextMenu", false);
fPopUp->AddItem(new BMenuItem("Get Information", new BMessage(kGetInfo)));
fPopUp = new BPopUpMenu("contextMenu", false, false);
fPopUp->AddItem(new BMenuItem("Get Informations", new BMessage(kGetInfo)));
fPopUp->AddItem(new BMenuItem("Show Logs", new BMessage(kShowLogs)));
fPopUp->AddItem(new BSeparatorItem());
fPopUp->AddItem(new BMenuItem("Add to Address Book",
@ -67,12 +68,32 @@ RosterListView::RosterListView(const char* name)
// #pragama mark -
void
RosterListView::AttachedToWindow()
{
fPopUp->SetTargetForItems(this);
SetTarget(this);
}
void
RosterListView::MessageReceived(BMessage* msg)
{
switch (msg->what) {
case kGetInfo:
{
BPoint where;
uint32 buttons;
GetMouse(&where, &buttons);
BListItem* item = ItemAt(IndexOf(where));
RosterItem* ritem = reinterpret_cast<RosterItem*>(item);
if (ritem == NULL)
return;
_InfoWindow(ritem->GetContactLinker());
break;
}
default:
BListView::MessageReceived(msg);
}
@ -131,12 +152,13 @@ RosterListView::MouseDown(BPoint where)
Select(index);
// Show context menu if right button is clicked
(void)fPopUp->Go(ConvertToScreen(where), false, true, false);
(void)fPopUp->Go(ConvertToScreen(where), true, true, false);
}
} else
} else {
// Call original MouseDown()
BListView::MouseDown(where);
}
}
void
@ -169,3 +191,11 @@ RosterListView::Sort()
{
SortItems(compare_by_name);
}
void
RosterListView::_InfoWindow(ContactLinker* linker)
{
ContactInfoWindow* win = new ContactInfoWindow(linker);
win->Show();
}

View File

@ -9,6 +9,7 @@
class BPopUpMenu;
class ContactLinker;
class RosterItem;
class RosterListView : public BListView
@ -20,10 +21,13 @@ public:
virtual void MouseMoved(BPoint where, uint32 code, const BMessage*);
virtual void MouseDown(BPoint where);
virtual void Draw(BRect updateRect);
virtual void AttachedToWindow();
void Sort();
private:
void _InfoWindow(ContactLinker* linker);
BPopUpMenu* fPopUp;
RosterItem* fPrevItem;
};