Beispiel #1
0
void NickListModel::setMode(const QString &mode, const QString &nick)
{
  if (mode.isEmpty() || nick.isEmpty())
    return;

  int i = indexOfNick(nick);
  if (i < 0) {
    return;
  }

  QPair<QString, int> pair = m_list[i];
  int newFlags = pair.second;

  bool add;
  const QChar op = mode.at(0);
  if (op == '-') {
    add = false;
  }
  else if (op == '+') {
    add = true;
  }
  else {
    /* Bogus mode */
    return;
  }

  if (add) {
    for (int j = 1; j < mode.count(); j++) {
      const QChar c = mode.at(j);
      if (c == 'v') {
        newFlags |= VoicePrivileges;
      }
      else if (c == 'o') {
        newFlags |= OpPrivileges;
      }
    }
  }
  else {
    for (int j = 1; j < mode.count(); j++) {
      const QChar c = mode.at(j);
      if (c == 'v') {
        newFlags &= ~VoicePrivileges;
      }
      else if (c == 'o') {
        newFlags &= ~OpPrivileges;
      }
    }
  }

  if (newFlags != pair.second) {
    /* I'm lazy */
    pair.second = newFlags;
    QString newNick = nickWithSymbols(pair);
    removeNick(pair.first);
    addNick(newNick);
  }
}
Beispiel #2
0
//Part Start
void lolIRC::Client::lolIRC_Client::lolIRC_Response_Part::doIt(lolIRC_Message& m)
{
	std::list<std::string>::iterator it = m.parameters.begin();

	for(std::list<lolIRC_Channel>::iterator i = client.channels.begin(); i != client.channels.end(); i++)
	{
		if(!((*i).getChannelName().compare(*it)))//If the channel is in the list...
		{
			removeNick(*i, m.prefix.start);
			it++; //Part message

			if(m.parameters.size() == 2)
				(*client.ch)(client, (*i).getChannelName(), USERPART, m.prefix.start.c_str(), (*it).c_str());
			else
				(*client.ch)(client, (*i).getChannelName(), USERPART, m.prefix.start.c_str(), "");
		}
	}
}
LRESULT CALLBACK ParentMessageProcessingHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {	
	case WM_CREATE:
		{
			mainDialogHandle = hwnd;

			if(!TalkInitWinSock())
			{
				ShowError("An error ocured!\nThe program will now exit.", hwnd);
				DestroyWindow(hwnd);
			}

			if(!CreateConnectDialog(hwnd))
			{
				ShowError("The Application has encountered an internal error!", hwnd);
				DestroyWindow(hwnd);
			}
			else
			{
				talkPic = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_TALK));
				if(talkPic == NULL)
				{
					ShowError("The Application has encountered an internal error!", hwnd);
					DestroyWindow(hwnd);
				}
			}
		}
		break;

	case WM_SIZE:
			SizeConnectDialog(hwnd);
		break;

	case WM_SOCKET_MESSAGE:	//aici sunt mesajele winsock
		switch(WSAGETSELECTEVENT(lParam))
		{
		case FD_CONNECT: //server Connect
			break;
		case FD_READ:
			switch(connectionState)
			{
			case TRYING_TO_CONNECT:
				{
					vector<char *> *msgList;

					if((msgList = TalkReceiveMessage(wParam)) != NULL)
					{
						if(!msgList->empty())
						{
							if(TALK_MSG_BOOL_IS_MSG((*msgList)[0], TALK_MSG_TYPE_BEGIN_NICK_LIST))
							{
								size_t size = msgList->size();

								for(size_t i = 1; i < size; i++)
								{
									if(i == size - 1 && TALK_MSG_BOOL_IS_MSG((*msgList)[i], TALK_MSG_TYPE_END_NICK_LIST))
									{
										connectionState = CONNECTED;
										//TalkSendMessage(serverSocket, "Connected", 10);
										DistroyConnectDialog();
										SetClassLong(hwnd, GCL_HBRBACKGROUND, LONG(GetStockObject(WHITE_BRUSH)));
										InvalidateRect(hwnd, NULL, TRUE);
									}
									else
										addNick((*msgList)[i]);
								}

								if(connectionState != CONNECTED)
									connectionState = CONNECTION_ACCEPTED_GETTING_LIST;
							}

							else
							{
								ShowError("Nick name already in use!", hwnd);
								connectionState = UNCONNECTED;
							}
						}
					}
					else
					{
						ShowError("TRYING_TO_CONNECT error!", hwnd);
						connectionState = UNCONNECTED;
					}
				}
				break;
			case CONNECTION_ACCEPTED_GETTING_LIST:
				{
					vector<char *> *msgList;

					if((msgList = TalkReceiveMessage(wParam)) != NULL)
					{
						size_t size = msgList->size();

						for(size_t i = 0; i < size; i++)
							if(i == size - 1 && TALK_MSG_BOOL_IS_MSG((*msgList)[i], TALK_MSG_TYPE_END_NICK_LIST))
							{
								connectionState = CONNECTED;
								//TalkSendMessage(serverSocket, "Connected", 10);
								DistroyConnectDialog();
								SetClassLong(hwnd, GCL_HBRBACKGROUND, LONG(GetStockObject(WHITE_BRUSH)));
								InvalidateRect(hwnd, NULL, TRUE);
							}
							else
								addNick((*msgList)[i]);
					}
					else
					{
						ShowError("CONNECTION_ACCEPTED_GETTING_LIST error!", hwnd);
						connectionState = UNCONNECTED;
					}
				}
				break;
			case CONNECTED:
				{
					vector<char *> *msgList;

					if((msgList = TalkReceiveMessage(wParam)) != NULL)
					{
						size_t size = msgList->size();

						for(size_t i = 0; i < size; i++)
						{
							switch(TALK_MSG_VAL_MSG_TYPE((*msgList)[i]))
							{
							case TALK_MSG_TYPE_NORMAL_MSG:
								{
									char *src;
									char *msg;
									map<char *, HWND, ltstr>::iterator itr;

									TALK_GET_MSG_NORMAL_MSG_DEST_MSG((*msgList)[i], src, msg);

									itr = nickList.find(src);

									if(itr->second == NULL)
									{
										itr->second = CrateDialogFromTemplate(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG_CHAT),
											NULL, DLGPROC(InstantTalkProcessingHandler));
										
										if(itr->second == NULL)
										{
											ShowError("The Application has encountered an internal error!", hwnd);
											break;
										}
										else
										{
											char instDlgCapt[256];
											strcpy(instDlgCapt, itr->first);
											strcat(instDlgCapt, " - Instant Talk");

											SetWindowText(itr->second, instDlgCapt);

											openConversationList[itr->second] = itr->first;
										}
									}

									SendMessage(itr->second, GOT_MSG, (WPARAM)(msg), 0);
								}
								break;
							case TALK_MSG_TYPE_CLIENT_CONN_NOTIF:
								addNick(TALK_GET_MSG_CLIENT_CONN_NOTIF((*msgList)[i]));
								InvalidateRect(hwnd, NULL, TRUE);
								break;
							case TALK_MSG_TYPE_CLIENT_DISC_NOTIF:
								removeNick(TALK_GET_MSG_CLIENT_CONN_NOTIF((*msgList)[i]));
								InvalidateRect(hwnd, NULL, TRUE);
								break;
							}
						}
					}
				}
				break;
			}
			break;
		case FD_CLOSE:
			{
				if(serverSocket == wParam)
				{
					resetNickName();
					TalkShutDownConnection(wParam);

					if(connectionState == CONNECTED)
					{
						connectionState = UNCONNECTED;
						if(!CreateConnectDialog(hwnd))
						{
							ShowError("The Application has encountered an internal error!", hwnd);
							DestroyWindow(hwnd);
						}

						SetClassLong(hwnd, GCL_HBRBACKGROUND, LONG(COLOR_3DSHADOW));
						InvalidateRect(hwnd, NULL, TRUE);

						ShowError("Connection with server lost!", hwnd);
					}
				}
			}
			break;
		}
		break;

	case WM_SYSKEYDOWN:
	case WM_KEYDOWN:
		if(connectionState == CONNECTED)
		{
			switch (wParam) 
			{
			case VK_UP:
				if(selectedEntry > 0)
				{
					selectedEntry --;
					InvalidateRect(hwnd, NULL, TRUE);
				}
				break;
			case VK_DOWN:
				if(selectedEntry < nickList.size() - 1)
				{
					selectedEntry ++;
					InvalidateRect(hwnd, NULL, TRUE);
				}
				break;
			case VK_RETURN:
				if(connectionState == CONNECTED)
				{
					map<char *, HWND, ltstr>::iterator itr = nickList.begin();
					for(unsigned int i = 0; i < selectedEntry; i++, itr++);
					
					if(itr->second == NULL)
					{
						itr->second = CrateDialogFromTemplate(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG_CHAT),
							NULL, DLGPROC(InstantTalkProcessingHandler));
						
						if(itr->second == NULL)
						{
							ShowError("The Application has encountered an internal error!", hwnd);
						}
						else
						{
							char instDlgCapt[256];
							strcpy(instDlgCapt, itr->first);
							strcat(instDlgCapt, " - Instant Talk");

							SetWindowText(itr->second, instDlgCapt);
						}
					}
					else
						SetFocus(itr->second);
				}
				break;
			}
		}
		break;

	case WM_LBUTTONDOWN:
			if(connectionState == CONNECTED)
			{
				BITMAP bitmap;
				GetObject(talkPic, sizeof(bitmap), &bitmap);

				int i = (HIWORD(lParam) - 5) / (bitmap.bmHeight + 5);
				if(i < nickList.size())
				{
					selectedEntry = i;
					InvalidateRect(hwnd, NULL, TRUE);
				}
			}
		break;
	
	case WM_LBUTTONDBLCLK:
		if(connectionState == CONNECTED)
		{
			map<char *, HWND, ltstr>::iterator itr = nickList.begin();
			for(unsigned int i = 0; i < selectedEntry; i++, itr++);
			
			if(itr->second == NULL)
			{
				itr->second = CrateDialogFromTemplate(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG_CHAT),
					NULL, DLGPROC(InstantTalkProcessingHandler));
				
				if(itr->second == NULL)
				{
					ShowError("The Application has encountered an internal error!", hwnd);
				}
				else
				{
					char instDlgCapt[256];
					strcpy(instDlgCapt, itr->first);
					strcat(instDlgCapt, " - Instant Talk");

					SetWindowText(itr->second, instDlgCapt);

					openConversationList[itr->second] = itr->first;
				}
			}
			else
				SetFocus(itr->second);
		}
		break;

	case WM_PAINT://aici e paintu
		{
			PAINTSTRUCT paintStr;

			HDC hdc = BeginPaint(hwnd, &paintStr);

			if(connectionState == CONNECTED)
			{
				BITMAP bitmap;

				HDC hdcMem = CreateCompatibleDC(hdc);
				HBITMAP oldBitmap = (HBITMAP)SelectObject(hdcMem, talkPic);

				GetObject(talkPic, sizeof(bitmap), &bitmap);
				
				//size_t listSize = nickList.size();
				map<char *, HWND, ltstr>::iterator itr, itrend;
				itrend = nickList.end();
				unsigned int i = 0;
				for(itr = nickList.begin(); itr != itrend; itr++, i++)
				{
					BitBlt(hdc, 15, 5 + (bitmap.bmHeight + 5) * i, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY);
					if(i == selectedEntry)
					{
						SetTextColor(hdc, RGB(255, 255, 255));
						SetBkColor(hdc, RGB(100, 20, 180));
					}
					TextOut(hdc, 20 + bitmap.bmWidth, 5 + (bitmap.bmHeight + 5) * i, (*itr).first, strlen((*itr).first));
					if(i == selectedEntry)
					{
						SetBkColor(hdc, RGB(255, 255, 255));
						SetTextColor(hdc, RGB(0, 0, 0));
					}
				}

				SelectObject(hdcMem, oldBitmap);
				DeleteDC(hdcMem);
			}

			EndPaint(hwnd, &paintStr);
		}
		break;
    case WM_CLOSE:
        DestroyWindow(hwnd);
    break;
    case WM_DESTROY:
		{
			//daca se inchide aplicatia inchide toate conversatiile si elibereaza memoria 
			//ocupata de lista de nickuri
			resetNickName();
			clearNickList();

			if(talkPic != NULL)
			{
				DeleteObject(talkPic);
			}

			TalkShutDownWinSock();

			PostQuitMessage(0);
		}
    break;
    default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
    }

    return FALSE;
}