fxmainwindow.cpp

来自「linux-下的fetion-0.8.1。包括所有源代码」· C++ 代码 · 共 2,191 行 · 第 1/4 页

CPP
2,191
字号
#endif}void FxMainWindow::haveNewMessage(qlonglong account_id){	msgwin->haveNewMessage(account_id);}void FxMainWindow::haveNewQunMessage(qlonglong qun_id){	msgwin->haveQunMessage(qun_id);}void FxMainWindow::updateAccountInfo(qlonglong account_id){	buddyopt->updateAccountInfo(account_id);}void FxMainWindow::slot_SystemNetErr(int err){	relogin_fetion();	if (fx_status == SYS_RELOGIN)		return ;	fx_status = SYS_RELOGIN;	if (isHaveTray)  		trayIcon->setIcon (getSysTrayIcon(0));}void FxMainWindow::slot_DeRegistered(){	if(isHaveTray) {		trayIcon->setIcon(getSysTrayIcon(0));		fx_status = SYS_DeRegist;		QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon(3);		trayIcon->showMessage(tr("relogin"), 				tr("you have login in other pc, libfetion will quit"), 				icon, 20*1000);	} else {		QMessageBox::critical(this, tr("relogin"), 				tr("you have login in other pc, libfetion will quit") ); 		isQuit = true;		close();	}}#define MSG_OK       1#define MSG_FAIL     2#define MSG_TIMEOUT  3#define MSG_FAIL_LIMIT  4void FxMainWindow::handle_sendmsg(int msgflag, int fx_msg, qlonglong account_id){	if(!fx_msg)		return;	int i = 0;	Fetion_MSG *fxMsg = (Fetion_MSG *) fx_msg;	char *msg = fx_simple_paser_msg(fxMsg->message); 	QString newmsg;	switch(msgflag)	{		case MSG_OK:			for (i = 0; i < timeOutMsgVector.size(); ++i) {				if (timeOutMsgVector.at(i) == fx_msg)				{					newmsg = "<b style=\"color:rgb(170,0,255);\">" +tr("auto resend ok:") + "</b>" + newmsg.fromUtf8(msg);					msgwin->addMessage(newmsg, account_id);					timeOutMsgVector.remove(i);					break;				}			}			break;		case MSG_FAIL:			for (i = 0; i < timeOutMsgVector.size(); ++i) {				if (timeOutMsgVector.at(i) == fx_msg)	{					timeOutMsgVector.remove(i);					break;				}			}			newmsg = "<b style=\"color:red;\">"+tr("send fail:") +"</b>"+ newmsg.fromUtf8(msg);			msgwin->addMessage(newmsg, account_id);			break;		case MSG_FAIL_LIMIT:			for (i = 0; i < timeOutMsgVector.size(); ++i) {				if (timeOutMsgVector.at(i) == fx_msg)	{					timeOutMsgVector.remove(i);					break;				}			}			newmsg = "<b style=\"color:red;\">"+tr("send sms fail by limit:") +"</b>"+ newmsg.fromUtf8(msg);			msgwin->addMessage(newmsg, account_id);			break;		case MSG_TIMEOUT:			timeOutMsgVector.append(fx_msg); // add the msg to vector			newmsg = "<b style=\"color:rgb(170,0,255);\">" +tr("send timeout:") +"</b>" + newmsg.fromUtf8(msg)+"<br><b style=\"color:rgb(170,0,255);\">" +tr("will auto resend")+"</b>";			msgwin->addMessage(newmsg, account_id);			break;	}	if(msg)		free(msg);}void FxMainWindow::slot_SysDialogMsg (int message, int fx_msg, qlonglong who){	switch(message)	{		case FX_SMS_OK: 		case FX_DIA_SEND_OK: 		case FX_QUN_SEND_OK: 		case FX_QUN_SMS_OK: 			handle_sendmsg( MSG_OK, fx_msg, who);			if(!fx_msg)				return;			fx_destroy_msg((Fetion_MSG *)fx_msg);			break;		case FX_SMS_FAIL: 		case FX_DIA_SEND_FAIL: 		case FX_QUN_SEND_FAIL: 		case FX_QUN_SMS_FAIL: 			handle_sendmsg( MSG_FAIL, fx_msg, who);			if(!fx_msg)				return;			fx_destroy_msg((Fetion_MSG *)fx_msg);			break;		case FX_SMS_TIMEOUT: 		case FX_DIA_SEND_TIMEOUT: 		case FX_QUN_SEND_TIMEOUT: 		case FX_QUN_SMS_TIMEOUT: 			handle_sendmsg( MSG_TIMEOUT, fx_msg, who);			//time out should not to destroy msg, beacuse the system will resend by itself..			break;		case FX_SMS_FAIL_LIMIT: 		case FX_QUN_SMS_FAIL_LIMIT: 			handle_sendmsg( MSG_FAIL_LIMIT , fx_msg, who);			fx_destroy_msg((Fetion_MSG *)fx_msg);			break;	}}void FxMainWindow::slot_reName_group (int, int newname, qlonglong id){	QTreeWidgetItem * groupItem = buddyopt->findGroupItemByID(id);	if(!groupItem) {		if(newname)			free((char*)newname);		return;	}	#if MS_VC6	Group_Info *group_info =(Group_Info *)( groupItem->data(0, Qt::UserRole).toUInt() );#else	Group_Info *group_info = groupItem->data(0, Qt::UserRole).value<Group_Info *>();#endif	if(!group_info)	{		if(newname)			free((char*)newname);		return;	}	group_info->groupName = QString::fromUtf8((char*)newname);#ifdef WIN32	char online[30];	_snprintf (online, sizeof(online)-1, "(%d/%d)", group_info->online_no, groupItem->childCount());	QString groupShowName = group_info->groupName+ online;#else	char *online= NULL;	asprintf(&online, "(%d/%d)", group_info->online_no, groupItem->childCount());	QString groupShowName = group_info->groupName+ online;	if(online)		free(online);#endif	groupItem->setText(0, groupShowName);	if(newname)		free((char*)newname);}void FxMainWindow::slot_add_buddy (int , int , qlonglong id){	buddyopt->delAccount(id);  	buddyopt->addAccountToGroup (fx_get_account_by_id(id) );}void FxMainWindow::slot_reName_buddy (int , int newname, qlonglong id){	if(newname)		free((char*)newname);	updateAccountInfo(id);}void FxMainWindow::slot_add_group (int, int newname, qlonglong id){	if(tmp_addBuddy) {		QVariant Var((int)id);		tmp_addBuddy->CB_group->addItem(QString::fromUtf8((char*)newname), Var);	}	buddyopt->addGroup((const char*) newname, id);	if(newname)		free((char*)newname);}void FxMainWindow::slot_del_buddy (int, int, qlonglong id){	buddyopt->delAccount(id);    }void FxMainWindow::slot_set_state(int state){	setUINiceName();	if (traySetStatusMenu)		traySetStatusMenu->setIcon (getOnlineStatusIcon(state));	if (buddySetStatusMenu)		buddySetStatusMenu->setIcon (getOnlineStatusIcon(state));	if(isHaveTray) 		trayIcon->setIcon(getSysTrayIcon (state));}void FxMainWindow::slot_del_group (int, int newname, qlonglong id){	buddyopt->delGroup(id);    	if(newname)		free((char*)newname);}void FxMainWindow::slot_updateSmsDay(int day){	if (day)	{		refuseSMSAct->setIcon(getMenuIcon(ApplyIcon));		acceptSMSAct->setIcon(QPixmap());	} else {		acceptSMSAct->setIcon(getMenuIcon(ApplyIcon));		refuseSMSAct->setIcon(QPixmap());	}}void FxMainWindow::showQunWindow(qlonglong qun_id){	msgwin->addQunWin(qun_id);}void FxMainWindow::showMsgWindow(qlonglong account_id){	msgwin->addAccount(account_id);}void FxMainWindow::accountPressed ( QTreeWidgetItem * item, int){	if(item == 0)		return;	if (qApp->mouseButtons() == Qt::RightButton )	{		if(item->parent()) //it is a account or qun		{			if(	buddyopt->isQunItem(item->parent()) ) //test if it is a qun				showQunMenu();			else				showBuddyMenu();		}		else			if(!buddyopt->isQunItem(item))				showGroupMenu();	}}void FxMainWindow::showQunMenu(){	QPoint pos;	QMenu menu(this);	menu.addAction(IMQunAct);	menu.addAction(SMSQunAct);	menu.addAction(GetInfoQunAct);	//menu.popup(QCursor::pos());	menu.exec(QCursor::pos());}void FxMainWindow::showGroupMenu(){	QPoint pos;	QMenu menu(this);	menu.addAction(AddGroupAct);	menu.addAction(DeleteGroupAct);	menu.addAction(ReNameGroupAct);	menu.exec(QCursor::pos());	//menu.popup(QCursor::pos());}void FxMainWindow::showBuddyMenu(){	Account_Info *ac_info =getAc_InfoOfCurrentItem();	if(!ac_info)		return;	QPoint pos;	QMenu menu(this);	//if in blacklist, show remove from the blacklist	if ( !fx_is_InBlacklist_by_id(ac_info->accountID) ) {		menu.addAction(IMBuddyAct);		menu.addAction(SMSBuddyAct);		menu.addSeparator();		menu.addAction(ReNameBuddyAct);		menu.addAction(GetInfoBuddyAct);		menu.addAction(RefreshInfoBuddyAct);		QMenu *groupMenu = menu.addMenu(tr("move group"));		{			groupMenu->setIcon(getMenuIcon(MoveIcon));			createGroupMenu(groupMenu);				}		menu.addSeparator();		menu.addAction(DeleteBuddyAct);		menu.addAction(AddBlackBuddyAct);	} else {		menu.addAction(ReNameBuddyAct);		menu.addAction(GetInfoBuddyAct);		menu.addAction(RefreshInfoBuddyAct);		QMenu *groupMenu = menu.addMenu(tr("move group"));		{			createGroupMenu(groupMenu);				}		menu.addSeparator();		menu.addAction(DeleteBuddyAct);		menu.addAction(RemoveBlackBuddyAct);	}	menu.exec(QCursor::pos());	//menu.popup(QCursor::pos());}void FxMainWindow::createGroupMenu(QMenu *groupMenu){	Group_Info *groupinfo = NULL; 	Fetion_Group *group = NULL;	DList *tmp_group = (DList *)fx_get_group();	while(tmp_group)	{		group = (Fetion_Group *) tmp_group->data;		if(group) {			QAction *action = new QAction(QString::fromUtf8(group->name), this);			action->setIcon(getQunIcon());			QVariant Var((int) group->id);			action->setData(Var);			groupMenu->addAction(action);		}		tmp_group = d_list_next(tmp_group);	}	connect(groupMenu, SIGNAL(triggered(QAction *)), this, SLOT(moveGroupMenutriggered(QAction *)));}void FxMainWindow::moveGroupMenutriggered(QAction *action){	int group_id = action->data().toInt();	Account_Info *ac_info =getAc_InfoOfCurrentItem();	if(!ac_info)		return;	fx_move_group_buddy_by_id(ac_info->accountID, group_id, NULL, NULL);}void FxMainWindow::searchaccountDoubleClicked (QTreeWidgetItem * item, int column ){	if(item == 0)		return;	if(	buddyopt->isQunItem(item->parent()) ) //test if it is a qun	{#if MS_VC6		Qun_Info *qun_info =(Qun_Info*)(item->data(0, Qt::UserRole).toUInt());#else		Qun_Info *qun_info =item->data(0, Qt::UserRole).value<Qun_Info*>();#endif		if(qun_info)			showQunWindow(qun_info->qunID);	}	else	{#if MS_VC6		Account_Info *ac_info =(Account_Info*)(item->data(0, Qt::UserRole).toUInt());#else		Account_Info *ac_info =item->data(0, Qt::UserRole).value<Account_Info*>();#endif		if(ac_info)			showMsgWindow(ac_info->accountID);	}}void FxMainWindow::accountDoubleClicked ( QTreeWidgetItem * item, int){	if(item == 0)		return;	if(item->parent()) //it is a account	{		if(	buddyopt->isQunItem(item->parent()) ) //test if it is a qun		{#if MS_VC6			Qun_Info *qun_info =(Qun_Info*)(item->data(0, Qt::UserRole).toUInt());#else			Qun_Info *qun_info =item->data(0, Qt::UserRole).value<Qun_Info*>();#endif			if(qun_info)				showQunWindow(qun_info->qunID);		}		else		{#if MS_VC6			Account_Info *ac_info =(Account_Info*)(item->data(0, Qt::UserRole).toUInt());#else			Account_Info *ac_info =item->data(0, Qt::UserRole).value<Account_Info*>();#endif			if(ac_info)				showMsgWindow(ac_info->accountID);		}	}}#if WIN32#elsebool FxMainWindow::event( QEvent * event ){	if( event->type() == QEvent::WindowStateChange) 	{		QWindowStateChangeEvent *mEvent = (QWindowStateChangeEvent *)event;		if( mEvent->oldState() == Qt::WindowNoState)		{			QMainWindow::event(event);			hide();			return true;		}	}	return QMainWindow::event(event);}#endif#if WIN32#include <windows.h>bool FxMainWindow::winEvent(MSG *msg, long *result){	if(WM_HOTKEY == msg->message)	{		if (showNewMsgDlg())			return true;		//here codes should be ajust after later..		if (fx_status == SYS_RELOGIN) //relogin state will not handle this message..			return true;		trayMessageClicked();		if (this->isVisible() && windowState() != Qt::WindowNoState)		{			this->activateWindow();						setWindowState ( Qt::WindowNoState);		}		if (!this->isVisible())		{			this->setVisible(true);			this->activateWindow();						setWindowState (Qt::WindowNoState);		}		return true;	}	return false;}#endifvoid FxMainWindow::closeEvent(QCloseEvent *event){	if(isQuit){		if(isHaveTray) 			trayIcon->hide();		msgwin->msg_exit();		event->accept();		return;	}	if(isHaveTray) { 		if (trayIcon->isVisible()) {			hide();			event->ignore();		}	} else {		msgwin->hide();		event->accept();	}}void FxMainWindow::moveEvent(QMoveEvent * event){	if (isNeedRecordWinPos)		Settings::instance().setMainWinPos(pos());}void FxMainWindow::trayMessageClicked(){	switch(fx_status)	{#if 0		case NET_ERR:			QMessageBox::critical (this, tr("connect break off"), 					tr("disconnect from fetion server, will relogin fetion"));			printf("the system network have some error, we will relogin fetion \n");			isQuit = true;			close();			break;#endif		case SYS_DeRegist:			QMessageBox::critical(this, tr("relogin"), 					tr("you have login in other pc, libfetion will quit") ); 			isQuit = true;			close();			break;		case NEW_MSG:			break;	}}void FxMainWindow::trayIconActivated(QSystemTrayIcon::ActivationReason reason){

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?