Esempio n. 1
0
void
MainWindow::ImMessage(BMessage* msg)
{
	int32 im_what = msg->FindInt32("im_what");
	switch (im_what) {
		case IM_OWN_CONTACT_INFO:
			fStatusView->SetName(msg->FindString("name"));
			break;
		case IM_OWN_AVATAR_SET:
		{
			entry_ref ref;

			if (msg->FindRef("ref", &ref) == B_OK) {
				BBitmap* bitmap = BTranslationUtils::GetBitmap(&ref);
				fStatusView->SetAvatarIcon(bitmap);
			}
			break;
		}
		case IM_STATUS_SET:
		{
			int32 status;

			if (msg->FindInt32("status", &status) != B_OK)
				return;

			RosterItem*	rosterItem = fServer->RosterItemForId(msg->FindString("id"));

			if (rosterItem) {
				UpdateListItem(rosterItem);

				// Add or remove item
				switch (status) {
					/*case CAYA_OFFLINE:
						// By default offline contacts are hidden
						if (!CayaPreferences::Item()->HideOffline)
							break;
						if (HasItem(rosterItem))
							RemoveItem(rosterItem);
						return;*/
					default:
						// Add item because it has a non-offline status
						if (!HasItem(rosterItem))
							AddItem(rosterItem);
						break;
				}

				UpdateListItem(rosterItem);

				// Sort list view again
				fListView->Sort();

				// Check if the user want the notification
				if (!CayaPreferences::Item()->NotifyContactStatus)
					break;

				switch (status) {
					case CAYA_ONLINE:
					case CAYA_OFFLINE:
						// Notify when contact is online or offline
						if (status == CAYA_ONLINE) {
							BString message;
							message << rosterItem->GetContactLinker()->GetName();

							if (status == CAYA_ONLINE)
								message << " is available!";
							else
								message << " is offline!";

							BNotification notification(B_INFORMATION_NOTIFICATION);
							notification.SetGroup(BString("Caya"));
							notification.SetTitle(BString("Presence"));
							notification.SetIcon(rosterItem->Bitmap());
							notification.SetContent(message);
							notification.Send();
						}
						break;
					default:
						break;
				}
			}
			break;
		}
		case IM_AVATAR_SET:
		case IM_CONTACT_INFO:
		case IM_EXTENDED_CONTACT_INFO:
		{
			RosterItem*	rosterItem
				= fServer->RosterItemForId(msg->FindString("id"));
			if (rosterItem)
				UpdateListItem(rosterItem);
			break;
		}
	}
}
Esempio n. 2
0
void
MainWindow::MessageReceived(BMessage* message)
{
	switch (message->what) {
		case kSearchContact:
		{
			void* control = NULL;
			if (message->FindPointer("source", &control) != B_OK)
				return;

			SearchBarTextControl* searchBox 
				= static_cast<SearchBarTextControl*>(control);
			if (searchBox == NULL)
				return;

			RosterMap map = fServer->RosterItems();
			for (uint32 i = 0; i < map.CountItems(); i++) {
				ContactLinker* linker = map.ValueAt(i);
				RosterItem* item = linker->GetRosterItem();

				// If the search filter has been deleted show all the items,
				// otherwise remove the item in order to show only items
				// that matches the search criteria
				if (strcmp(searchBox->Text(), "") == 0)
					AddItem(item);
				else if (linker->GetName().IFindFirst(searchBox->Text()) == B_ERROR)
					RemoveItem(item);
				else
					AddItem(item);
				UpdateListItem(item);
			}
			break;
		}
		case CAYA_SHOW_SETTINGS:
		{
			PreferencesDialog* dialog = new PreferencesDialog();
			dialog->Show();
			break;
		}
		case CAYA_OPEN_CHAT_WINDOW:
		{
			int index = message->FindInt32("index");
			RosterItem* ritem = ItemAt(index);
			if (ritem != NULL)
				ritem->GetContactLinker()->ShowWindow(false, true);
			break;
		}

		case CAYA_REPLICANT_STATUS_SET:
		{
			int32 status;
			message->FindInt32("status", &status);
			AccountManager* accountManager = AccountManager::Get();
			accountManager->SetStatus((CayaStatus)status);
			break;
		}

		case CAYA_REPLICANT_SHOW_WINDOW:
		{
			if (LockLooper()) {
				SetWorkspaces(B_CURRENT_WORKSPACE);
				
				if ((IsMinimized() || IsHidden()) 
					|| fWorkspaceChanged) {
					Minimize(false);
					Show();
					fWorkspaceChanged = false;
				} else if ((!IsMinimized() || !IsHidden())
					|| (!fWorkspaceChanged)) {
					Minimize(true);
				}
				UnlockLooper();
			}
			break;
		}

		case IM_MESSAGE:
			ImMessage(message);
			break;
		case IM_ERROR:
			ImError(message);
			break;
		case B_ABOUT_REQUESTED:
			be_app->PostMessage(message);
			break;

		default:
			BWindow::MessageReceived(message);
	}
}