fxmainwindow.cpp

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

CPP
2,191
字号
/*************************************************************************** *   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 <QtGui>#include <QStandardItemModel>#include <QModelIndex>#include <QTreeView>#include <QListView>#include <QHeaderView>#include <QStandardItem>#include "appconfig.h"#include "fxmainwindow.h"#include "fxloginwindow.h"#include "fxshowAccountInfo.h"#include "fxqunwindow.h"#include "fxverifyAccount.h"#include "fxrefuseSMS.h"#include "fxsendGroupSMS.h"#include "fxconfigDlg.h"void  Sys_EventListener (int message, WPARAM wParam, LPARAM lParam, void* args){	if(!args)		return;	FxMainWindow * mainWind = (FxMainWindow *) args;	mainWind->handleFx_Sys_Event(message, wParam, lParam);}void FxMainWindow::handleFx_Sys_Event(int message, WPARAM wParam, LPARAM lParam){	switch(message)	{		case FX_CURRENT_VERSION:			emit signal_Current_Version((int)wParam);			break;		case FX_ADDACCOUNT_APP:			emit signal_AddAccountApp((char*)(lParam), (char*)wParam);			break;		case FX_MOVE_GROUP_OK:			emit signal_MoveGroup(qlonglong(lParam), (int)wParam);			break;		case FX_MOVE_GROUP_FAIL:			break;		case FX_SYS_MESSAGE:			emit signal_NewSysMsg(qlonglong(lParam));			break;		case FX_NEW_MESSAGE:			emit signal_NewMsg(qlonglong(lParam));			break;		case FX_NEW_QUN_MESSAGE:			emit signal_NewQunMsg(qlonglong(lParam));			break;		case FX_SET_STATE_OK:			emit signal_set_state((int)wParam);			break;		case FX_STATUS_OFFLINE: //²»ÔÚÏß		case FX_STATUS_ONLINE ://ÔÚÏß		case FX_STATUS_BUSY:    //æµ		case FX_STATUS_AWAY:  //ÂíÉÏ»ØÀ´		case FX_STATUS_MEETING:  //»áÒéÖÐ		case FX_STATUS_PHONE:   //µç»°ÖÐ		case FX_STATUS_DINNER:  //Íâ³öÓòÍ		case FX_STATUS_EXTENDED_AWAY:  //À뿪 		case FX_STATUS_NUM_PRIMITIVES: //×Ô¶¨Òå		case FX_ACCOUNT_UPDATA_OK:			emit signal_UpdateAcInfo(qlonglong(lParam));			break;		case FX_STATUS_SMSEXTENED:			//printf("have receive the FX_STATUS_SMSEXTENED message of %d %ld\n", wParam, lParam);			//emit signal_UpdateAcInfo(qlonglong(lParam));			break;		case FX_SET_REFUSE_SMS_DAY_OK:			emit signal_UpdateSmsDay((wParam));			break;		case FX_REMOVE_BLACKLIST_OK:		case FX_ADD_BLACKLIST_OK:			emit signal_UpdateAcInfo(qlonglong(lParam));			break;		case FX_SYS_ERR_NETWORK:			emit signal_SystemNetErr( wParam);			break;		case FX_SYS_DEREGISTERED:			emit signal_DeRegistered();			break;		case FX_DIA_SEND_OK: 		case FX_DIA_SEND_FAIL: 		case FX_DIA_SEND_TIMEOUT: 		case FX_SMS_OK: 		case FX_SMS_FAIL: 		case FX_SMS_FAIL_LIMIT: 		case FX_SMS_TIMEOUT: 		case FX_QUN_SEND_OK: 		case FX_QUN_SEND_FAIL: 		case FX_QUN_SEND_TIMEOUT: 		case FX_QUN_SMS_OK: 		case FX_QUN_SMS_FAIL: 		case FX_QUN_SMS_FAIL_LIMIT: 		case FX_QUN_SMS_TIMEOUT: 			emit signal_SysDialogMsg( message, wParam, (qlonglong)lParam);			break;		case FX_ADD_BUDDY_OK:			emit signal_add_buddy( message, wParam, (qlonglong)lParam);			break;		case FX_RENAME_GROUP_OK:			emit signal_reName_group( message, wParam, (qlonglong)lParam);			break;		case FX_SET_BUDDY_INFO_OK:			emit signal_reName_buddy( message, wParam, (qlonglong)lParam);			break;		case FX_ADD_GROUP_OK:			emit signal_add_group( message, wParam, (qlonglong)lParam);			break;		case FX_DEL_GROUP_OK:			emit signal_del_group( message, wParam, (qlonglong)lParam);			break;		case FX_DEL_BUDDY_OK:			emit signal_del_buddy( message, wParam, (qlonglong)lParam);			break;		case FX_ADD_GROUP_FAIL:		case FX_DEL_GROUP_FAIL:		case FX_SET_BUDDY_INFO_FAIL:		case FX_RENAME_GROUP_FAIL:  //ignored this message			if(wParam)				free((char*)(int)wParam);			break;					case FX_SET_NICKNAME_OK:			emit signal_set_nickname_ok();			break;		default:			break;#if 0 //follow message is ignored		case FX_REMOVE_BLACKLIST_FAIL:		case FX_ADD_BLACKLIST_FAIL:		case FX_REMOVE_BLACKLIST_TIMEOUT:		case FX_ADD_BLACKLIST_TIMEOUT:		case FX_RENAME_GROUP_TIMEOUT:		case FX_SET_BUDDY_INFO_TIMEOUT:		case FX_SET_REFUSE_SMS_DAY_FAIL:#endif	}}FxMainWindow::FxMainWindow(QWidget *parent):QMainWindow(parent){	setupUi(this);	newVersion = 0;	new_msg_count = 0;	new_qun_msg_count = 0;	tmp_addBuddy = NULL;	fx_status = NO_SET;	isQuit = false;	isBreakOut = false;	isHaveminimized = false;	isNeedRecordWinPos = false;    init_UI();	initAllActions();	createMenu();	initTrayIcon();	init_slot_signal();	//set the fetion system msg call back function	fx_set_system_msg_cb (Sys_EventListener, this);	//save the account info to db, 	//will a bug: when the account is changed, but the db info maybe not changed follow#if 1	saveAccountInfo();#else	QTreeWidgetItem * tm = new QTreeWidgetItem(view, 0);	tm->setText(0, "haha");#endif		minimizedTimer.start(100);}FxMainWindow::~FxMainWindow(){	if(buddyopt)		delete buddyopt;	if(msgwin)		delete msgwin;}void FxMainWindow::UI_enable_impresa(){	UI_Impresa->setDisabled (false);	UI_Impresa->setFocus ();}void FxMainWindow::UI_enable_search(){	UI_Search->setDisabled (false);	UI_Search->setFocus ();}void FxMainWindow::setUINiceName(){	QString impresa; 	if (fx_data_get_PersonalInfo())		impresa = QString::fromUtf8(fx_data_get_PersonalInfo()->impresa); 	if (impresa.isEmpty())	{		UI_Impresa->setToolTip (NULL);		impresa = tr("please input impresa...");	}		UI_Impresa->setText(impresa);	UI_Impresa->setToolTip(impresa);	UI_Impresa->setCursorPosition (0);	m_impresa = impresa;		QString state;	switch (fx_get_user_state())	{		case FX_STATUS_ONLINE:			state = tr("online");			break;		case FX_STATUS_OFFLINE:			state = tr("hide");			break;		case FX_STATUS_BUSY:			state = tr("busy");			break;		default:			state = tr("away");			break;	}	QString name = QString::fromUtf8(fx_get_usr_show_name());	//if (name.size >12)	QString showstr= name + "(" +state + ")";	UI_NiceName->setText (showstr);}void FxMainWindow::SearcheditingFinished (){	QString text = UI_Search->text();	if (text.isEmpty())	{		UI_Search->setText(tr("search friends..."));		UI_Search->setCursorPosition (0);		//show mian tree list	}//	UI_Search->setDisabled (true);}void FxMainWindow::SearchtextChanged (const QString &text){	QString content = UI_Search->text();	if (content.isEmpty() || content == tr("search friends..."))	{		search->hide();		view->show();		return;	}		view->hide(); //hide mian tree list 		search->clear();	QList<QTreeWidgetItem *>  *items = searchAccountInfo(content.toUtf8().data());	search->insertTopLevelItems(0, *items);	search->show();}void FxMainWindow::changeNiceName(){	UI_Edit_NiceName->hide();	QString text = UI_Edit_NiceName->text();	if (text != QString::fromUtf8(fx_get_usr_show_name()))		fx_set_user_nickname(text.toUtf8().data(), NULL, NULL); }void FxMainWindow::changeImpresa(){	QString text = UI_Impresa->text();	if (text == m_impresa)		return;	if (text.isEmpty())	{		UI_Impresa->setText(tr("please input impresa..."));		UI_Impresa->setCursorPosition (0);		text = tr("please input impresa...");				if (m_impresa != tr("please input impresa..."))			fx_set_user_impresa(NULL, NULL, NULL);	}	else		fx_set_user_impresa(text.toUtf8().data(), NULL, NULL); 	UI_Impresa->setToolTip (text);	m_impresa = text;}void FxMainWindow::SearchFocusIn (){	if (UI_Search->text() == tr("search friends...") )		UI_Search->setText("");}void FxMainWindow::ImpresaFocusIn (){	if (UI_Impresa->text() == tr("please input impresa...") )		UI_Impresa->setText("");}void FxMainWindow::addNewMsgCount(bool isQunMsg){	if (!isQunMsg)		new_msg_count++;	else		new_qun_msg_count++;	if (isHaveTray) 		startFlickerTray();}bool FxMainWindow::showNewMsgDlg(){	if (new_msg_count > 0)	{		subNewMsgCount();		msgwin->show();		msgwin->activateWindow();		msgwin->setWindowState(Qt::WindowNoState) ;		return true;	}	if (new_qun_msg_count > 0)	{		subNewMsgCount(true);		return true;	}	return false;}void FxMainWindow::subNewMsgCount(bool isQunMsg){	if (!isQunMsg)		new_msg_count--;	else		new_qun_msg_count--;	if ( !new_msg_count && !new_qun_msg_count && isHaveTray) 		endFlickerTray();	if(new_msg_count < 0)		new_msg_count = 0;	if (new_qun_msg_count < 0)		new_qun_msg_count = 0;}void FxMainWindow::startFlickerTray(){	if (trayFlickTimer.isActive())		return;	trayFlickTimer.start(300);}void FxMainWindow::endFlickerTray(){	if (trayFlickTimer.isActive())		trayFlickTimer.stop();	trayIcon->setIcon(getSysTrayIcon (fx_get_user_state()));}void  Relogin_EventListener (int message, WPARAM wParam, LPARAM lParam, void* args){	if(!args)		return;	FxMainWindow * mainwind = (FxMainWindow *) args;	mainwind->handleFx_relogin_Event(message, wParam, lParam);}void FxMainWindow::relogin_fetion(){		if (reloginTimer.isActive())		return;	if (isHaveTray) 		trayIcon->setContextMenu(reloginTrayMenu);	this->hide();	fx_relogin(Relogin_EventListener, this);	reloginTimer.start(1000*35);}void FxMainWindow::handleFx_relogin_Event(int message, WPARAM wParam, LPARAM lParam){	switch(message)	{		case FX_LOGIN_URI_ERROR:		case FX_LOGIN_FAIL:		case FX_LOGIN_NETWORK_ERROR:		case FX_LOGIN_UNKOWN_ERROR :   		case FX_LOGIN_UNKOWN_USR:		case FX_LOGIN_GP_FAIL:			relogin_fetion();			if (!isBreakOut && isHaveTray) //here just one warnning			{				isBreakOut = true;				QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon(3);				trayIcon->showMessage (tr("connect break off"), 						tr("disconnect from fetion server, will relogin fetion"), 						icon, 1*1000);			}			break;		case FX_LOGIN_OK :			fx_status = NO_SET;			isBreakOut = false;			if (isHaveTray) { 				trayIcon->setContextMenu(trayIconMenu);				trayIcon->setIcon(getSysTrayIcon (fx_get_user_state()));			}			if (reloginTimer.isActive())				reloginTimer.stop();			break;	}}void FxMainWindow::relogin_timer(){	fx_relogin(Relogin_EventListener, this);	/*	   if (reloginTimer.isActive())	   reloginTimer.stop();	   */}void FxMainWindow::flickerTray(){	static bool flick_flag = false;	trayIcon->setIcon(getFlickIcon(flick_flag));	flick_flag = !flick_flag;}void FxMainWindow::minimizedWind(){	if (!isHaveminimized)	{		isHaveminimized = true;		this->setWindowState(Qt::WindowMinimized);	} else {		minimizedTimer.stop();		this->setWindowState(Qt::WindowNoState);		//registed the hot key, when the mainwindow is created, and can get the winId		if (Settings::instance().isEnableGetMsgHotKey())			Settings::instance().setGetMsgHotKey(Settings::instance().GetMsgHotKey(), Settings::instance().GetMsgHotKeyMod());		if (Settings::instance().isStartHide())			this->hide();		else			this->show();		move(Settings::instance().MainWinPos());		isNeedRecordWinPos = true;	}}void FxMainWindow::haveCurrentVersionMessage(int version){	newVersion = version;	if (version > CURRENT_VERSION)	{		QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon(1);		trayIcon->showMessage(tr("LibFetion"),				tr("LibFetion Have New Version,"					"access http://www.libfetion.cn for more infomation"),				icon, 10*1000);	}}void FxMainWindow::haveAddAccountAppMessage(char* uri, char*desc){	FxVerifyAccount * verifyAccount = new FxVerifyAccount(this, uri, desc, this);	verifyAccount->show();}void FxMainWindow::haveMoveGroupMessage(qlonglong account_id, int group_id) {	buddyopt->delAccount_direct(account_id);  	buddyopt->addAccountToGroup(fx_get_account_by_id (account_id));}void FxMainWindow::haveNewSysMessage(qlonglong sys_id){#if 0 //not using system message	Fetion_MSG * fxMsg = fx_get_msg(sys_id);	if(!fxMsg)		return;	QString newmsg ;	char *msg = fx_simple_paser_msg(fxMsg->message); 	newmsg = newmsg.fromUtf8(msg);	QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon(1);	trayIcon->showMessage(tr("sys message"), newmsg, 			icon, 5*1000);	fx_destroy_msg (fxMsg);	if(msg)		free(msg);

⌨️ 快捷键说明

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