⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fxmsgwindow.cpp

📁 linux-下的fetion-0.8.1。包括所有源代码
💻 CPP
字号:
/*************************************************************************** *   Copyright (C) 2008 by DDD                                          * *   dedodong@163.com                                                     * *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * *   This program is distributed in the hope that it will be useful,       * *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * *   GNU General Public License for more details.                          * *                                                                         * *   You should have received a copy of the GNU General Public License     * *   along with this program; if not, write to the                         * *   Free Software Foundation, Inc.,                                       * *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * ***************************************************************************/#include <QLabel>#include <QtGui>#include <QTextEdit>#include "fxmsgwindow.h"#include "fxuitl.h"//find is have the ac_idinline AccountTab *findFromMsgWindow(QTabWidget * tabWidget, qlonglong ac_id){	AccountTab *ac_tab = NULL;	int tabCount = tabWidget->count ();	for(int i = 0; i< tabCount; i++)	{		ac_tab = (AccountTab *) tabWidget->widget(i); 		if(ac_tab) {			if(ac_tab->account_id == ac_id)				return ac_tab;		}	}	return NULL;}FxMsgWindow::FxMsgWindow(QWidget *parent)    : QMainWindow(parent){	setupUi(this);	mainwindow = NULL;	isQuit = false;	inputFace = new FxInputFace(this);	QPalette pal;	pal.setBrush(QPalette::Window,QBrush(getInputFaceIcon()));	inputFace->setPalette(pal);	inputFace->setMsgWindow(this);	inputFace->setGeometry (QCursor::pos().x(), QCursor::pos().y(), 320, 261);	inputFace->setWindowFlags(Qt::Dialog| Qt::FramelessWindowHint);		//tabWidget = new FxMyTabWidget(this);	tabWidget->setParent(this);	tabWidget->clear();	pal = palette();	pal.setColor(QPalette::Active, QPalette::Button, pal.color(QPalette::Active, QPalette::Window));	pal.setColor(QPalette::Disabled, QPalette::Button, pal.color(QPalette::Disabled, QPalette::Window));	pal.setColor(QPalette::Inactive, QPalette::Button, pal.color(QPalette::Inactive, QPalette::Window));	QToolButton *closeTabButton = new QToolButton(tabWidget);	closeTabButton->setAutoRaise(true);	closeTabButton->setEnabled(true);	closeTabButton->setPalette(pal);	tabWidget->setCornerWidget(closeTabButton, Qt::TopRightCorner);	closeTabButton->setCursor(Qt::ArrowCursor);	closeTabButton->setIcon(getCloseTabImage());	connect(closeTabButton, SIGNAL(clicked()), this, SLOT(closeTab()));	closeTabButton->setToolTip(tr("close current Tab"));#if 0#if MAC_OS	tabWidget->setGeometry (0,0,342,405);#else	tabWidget->setGeometry (0,0,321,385);#endif#endif	connect(tabWidget, SIGNAL( currentChanged(int) ), this, SLOT( currentChangedName(int) ));	connect(tabWidget, SIGNAL( mouseDblClick(int) ), this, SLOT( closeTabWid(int) ));	move(Settings::instance().MsgWinPos());	resize(Settings::instance().MsgWinSize());}void FxMsgWindow::setMainWind(FxMainWindow *mainW){	this->mainwindow = mainW;}void FxMsgWindow::currentChangedName(int index){/*	if(tabWidget->currentIndex() == index)		return;	*/	AccountTab *accountTab = (AccountTab *) tabWidget->widget (index); 	if (accountTab)	{		accountTab->endFlickerTab();		QString title = tr("with") + accountTab->account_name + tr("chating... "); 		this->setWindowTitle(title);		int online_state ;		if(!fx_is_pc_user_by_account(accountTab->m_account))			online_state = -1;		else		online_state = fx_get_online_status_by_account(accountTab->m_account);		//	online_state = fx_is_on_line_by_account(accountTab->m_account);		this->setWindowIcon (getOnlineStatusIcon(online_state));	}}	void FxMsgWindow::closeTab(){	closeTabWid (tabWidget->currentIndex());}void FxMsgWindow::closeTabWid(int index){	AccountTab *accountTab = (AccountTab *) tabWidget->widget(index); 	tabWidget->removeTab (index);	//if the tabWidget have no tab, hide it..	if(tabWidget->count() <= 0)		this->hide();	if(accountTab)		delete accountTab;}FxQunWindow* FxMsgWindow::findQunWindow(qlonglong qun_id){	int size = qunWindow.size();	for(int i = 0; i< size; i++ )		if(qunWindow.at(i)->qun_id == qun_id)			return qunWindow.at(i);	return NULL;}bool FxMsgWindow::addQunMessage(QString msg, qlonglong qun_id, qlonglong sender, bool iscoming_msg){	FxQunWindow	*qunW = findQunWindow(qun_id);	if(!qunW)	{		qunW = new FxQunWindow(qun_id, this);		qunWindow.append(qunW);	}	qunW->show();	qunW->activateWindow();	qunW->setWindowState ( Qt::WindowNoState ) ;	qunW->MsgEdit->setFocus();	QString str; 	QString show_msg; 	if(iscoming_msg) {		str = "<b style=\"color:rgb(0,85,0);\">"+ 			qunW->getSenderName(sender) +"("+			QDateTime::currentDateTime().toString(tr("hh:mm:ss")) + "--" +			QDateTime::currentDateTime().toString(tr("yyyy-MM-dd")) +			"):</b><br>"+ msg;		show_msg= show_msg.fromUtf8(str.toUtf8().data()); 	} else {		show_msg= msg; 	}	QTextEdit * msgBrowser = qunW->MsgBrowser;	msgBrowser->append(show_msg);	msgBrowser->moveCursor(QTextCursor::End);	saveHistroyMsg(strtol(fx_get_usr_uid(), NULL, 10), qun_id, show_msg.toUtf8().data(), NULL);	this->setFocus();	return true;}bool FxMsgWindow::addMessage(QString msg, qlonglong account_id,  bool iscoming_msg){	if (fx_is_qun_by_id(account_id)) {		addQunMessage(msg, account_id, 0L, true);		return true;	}	AccountTab *accountTab = findFromMsgWindow(tabWidget, account_id);	if (!accountTab)	{		accountTab = new AccountTab(account_id, tabWidget);		accountTab->setMainWind( this->mainwindow );		tabWidget->addTab( accountTab, accountTab->account_name);	}	if (!this->isVisible())	{		tabWidget->setCurrentWidget(accountTab);		QString title = tr("with") + accountTab->account_name + tr("chating... "); 		this->setWindowTitle(title);		int online_state ;		if (!accountTab->m_account)			online_state = -1;		else			if (!fx_is_pc_user_by_account(accountTab->m_account))				online_state = -1;			else				online_state = fx_get_online_status_by_account(accountTab->m_account);		this->setWindowIcon (getOnlineStatusIcon(online_state));		if (Settings::instance().isAutoShowMsg())		{			this->show();			this->setWindowState(Qt::WindowNoState) ;			this->setFocus();			accountTab->msgSend->MsgEdit->setFocus();		}	}		//int indexOf();	QString str; 	QString show_msg; 	if(iscoming_msg) {		str ="<b style=\"color:rgb(0,85,0);\">"+ accountTab->account_name + "("+			QDateTime::currentDateTime().toString(tr("hh:mm:ss")) + "--" +			QDateTime::currentDateTime().toString(tr("yyyy-MM-dd")) +			"):</b><br>" + msg;		show_msg= show_msg.fromUtf8(str.toUtf8().data()); 	} else {		show_msg= show_msg.fromUtf8(msg.toUtf8().data()); 	}	if (account_id == SYSTEM_ID)	{		bool tmp = selectSystemMsg (strtol (fx_get_usr_uid(), NULL, 10),				SYSTEM_ID, show_msg.toUtf8().data());		if (tmp)		{			printf("this system message have ok \n");			return true;		}	}	QTextEdit * msgBrowser = accountTab->msgSend->MsgBrowser;	msgBrowser->append(show_msg);	msgBrowser->moveCursor(QTextCursor::End);	saveHistroyMsg(strtol(fx_get_usr_uid(), NULL, 10), account_id, show_msg.toUtf8().data(), NULL);	if (Settings::instance().isAutoReply())	{		exec_autoRelpy(msgBrowser, account_id, Settings::instance().getAutoReply());	}	accountTab->startFlickerTab();	if (!Settings::instance().isMute())		playSound(MSG_SOUND);	return true;}void FxMsgWindow::exec_autoRelpy(QTextEdit* msgBrowser, qlonglong account_id, QString msg){	bool sendFlag = false;	msg = QObject::tr("(LibFetion auto reply msg)") + msg;	if (!fx_is_pc_user_by_id(account_id))		sendFlag = fx_send_sms (account_id, msg.toUtf8().data(), NULL, NULL); 	else {		msg.replace(QString("<"), QString("&lt;"));		msg.replace(QString(">"), QString("&gt;"));		sendFlag = fx_dialog_send( account_id, msg.toUtf8().data(), NULL, NULL); 	}	QString show_msg;	QString head;	if(sendFlag) 		head = "<b style=\"color:rgb(0,0,255);\">"+tr("Me:(")+ 			QDateTime::currentDateTime().toString(tr("hh:mm:ss")) + "--" +			QDateTime::currentDateTime().toString(tr("yyyy-MM-dd")) +			")</b><br>";	else 		head = "<b style=\"color:red;\">"+tr("send fail:(")+ 			QDateTime::currentDateTime().toString(tr("hh:mm:ss")) + "--" +			QDateTime::currentDateTime().toString(tr("yyyy-MM-dd")) +			")</b><br>";	msg.replace(QString("<"), QString("&lt;"));	msg.replace(QString(">"), QString("&gt;"));	msg.replace(QString("\n"), QString("<br>"));	msg = fxgui_to_faces(msg);	QString str = head+ msg;	show_msg = show_msg.fromUtf8(str.toUtf8().data());	//show the send reslut to the browser...	msgBrowser->append(show_msg);	saveHistroyMsg(strtol(fx_get_usr_uid(), NULL, 10), account_id, show_msg.toUtf8().data(), NULL);}void FxMsgWindow::haveQunMessage(qlonglong qun_id){	if (!Settings::instance().isMute())		playSound(MSG_SOUND);	Fetion_MSG * fxMsg = fx_get_msg(qun_id);	if(!fxMsg)		return;	long sender = fxMsg->ext_id;	QString newmsg = fxgui_handle_newMsg(fxMsg);#if 0	QString newmsg ;	char *msg = fx_simple_paser_msg(fxMsg->message); 	newmsg = newmsg.fromUtf8(msg);	if(msg)		free(msg);#endif	addQunMessage(newmsg, qun_id, sender, true);	fx_destroy_msg (fxMsg);}void FxMsgWindow::haveNewMessage(qlonglong account_id){	Fetion_MSG * fxMsg = fx_get_msg(account_id);	if(!fxMsg)		return;#if 0	char *msg = fx_simple_paser_msg(fxMsg->message); 	QString newmsg = newmsg.fromUtf8(msg);	addMessage(newmsg, account_id, true);	if(msg)		free(msg);#else	QString newmsg = fxgui_handle_newMsg(fxMsg);	addMessage(newmsg, account_id, true);#endif	fx_destroy_msg (fxMsg);}void FxMsgWindow::resizeEvent (QResizeEvent * event) {	Settings::instance().setMsgWinSize(size());	tabWidget->resize(event->size());}void FxMsgWindow::closeEvent(QCloseEvent *event){	hide();	if(isQuit)		event->accept();	else		event->ignore();}void FxMsgWindow::moveEvent(QMoveEvent * event){	Settings::instance().setMsgWinPos(pos());}void FxMsgWindow::addQunWin(qlonglong qun_id, bool isSendSms){	FxQunWindow	*qun = findQunWindow(qun_id);	if(!qun) {		qun = new FxQunWindow(qun_id, this, isSendSms);		qunWindow.append(qun);	}	qun->show(); 	qun->activateWindow();}void FxMsgWindow::addAccount(qlonglong account_id, bool isSendSms){	if ( fx_is_InBlacklist_by_id(account_id) ) {		QMessageBox::information(this->parentWidget(), tr("can't send mseeage to he"), 				tr("it have be added in blacklist by you") );		return ;	}	int	authed = fx_is_authed_by_id(account_id);	if( authed == AUTH_WAIT ){		QMessageBox::information(this->parentWidget(), tr("can't send mseeage to he"), 				tr("wait auth to add friend") );		return ;	}	if( authed == AUTH_REFUS){		QMessageBox::information(this->parentWidget(), tr("can't send mseeage to he"), 				tr("was refused to add friend") );		return ;	}	//first find is have the instance of the account_id, if have show it, and return.	//then create a new instance of this account_id, and add to the tabwidget.	AccountTab *accountTab = findFromMsgWindow(tabWidget, account_id);	if(!accountTab)	{		accountTab = new AccountTab(account_id, tabWidget, isSendSms);		accountTab->setMainWind( this->mainwindow );		tabWidget->addTab( accountTab, accountTab->account_name);	}	tabWidget->setCurrentWidget(accountTab);	QString title = tr("with") + accountTab->account_name + tr("chating... "); 	//QString title = QString::fromUtf8("涓?) + accountTab->account_name + QString::fromUtf8("鑱婂ぉ涓?..");	this->setWindowTitle(title);	int online_state ;	if(!fx_is_pc_user_by_account(accountTab->m_account))		online_state = -1;	else		online_state = fx_get_online_status_by_account(accountTab->m_account);	this->setWindowIcon (getOnlineStatusIcon(online_state));	if (!this->isVisible ())		this->show();	this->activateWindow();	this->setWindowState(Qt::WindowNoState);	accountTab->setSendModle(isSendSms);	accountTab->msgSend->MsgEdit->setFocus();}FxMsgWindow::~FxMsgWindow(){	int size = qunWindow.size();	for(int i = 0; i< size; i++ )		qunWindow.at(i)->qun_exit();}void FxMsgWindow::msg_exit(){	isQuit = true;	close();}void FxMsgWindow::showFaces(){	inputFace->setGeometry (QCursor::pos().x() - 320,			QCursor::pos().y() - 261, 320, 261);	inputFace->show();	inputFace->setFocus();	//inputFace->setWindowState(Qt::WindowActive);	//inputFace->grabMouse() ;}

⌨️ 快捷键说明

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