fxbuddy.cpp

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

CPP
860
字号
		return;	Account_Info * ac_info = new Account_Info;	ac_info->accountName = name;	ac_info->accountID = account->id;	ac_info->onlinestate = online_state;	QTreeWidgetItem *accountItem = new QTreeWidgetItem;	if (!m_isMainView)		accountItem->setCheckState(0, Qt::Unchecked);	accountItem->setText(0, name);#if MS_VC6	QVariant Var((uint)ac_info);#else	QVariant Var;	Var.setValue (ac_info); //vc7 up#endif	accountItem->setData(0, Qt::UserRole, Var);	accountItem->setIcon(0, getOnlineStatusIcon(ac_info->onlinestate));	setTipsOfAccount(accountItem, account);	groupItem->addChild(accountItem);#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(fx_is_on_line_by_account (account))	{		groupItem->removeChild(accountItem);		groupItem->insertChild(group_info->online_no, accountItem);		group_info->online_no ++;	}#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);}QString BuddyOpt::createAccountTipsInfo(const Fetion_Account *account){	QString tips;	QString tmp;	bool hP = false;	if(account->personal)		hP = true;	QString info;	info += tr("mobile_no:");	if(hP)	{		tmp = QString::fromUtf8(account->personal->mobile_no);		if (!tmp.isEmpty())		{			info += "<b style=\"color:red; \">" + tmp +"</b>";			tips += info +"<br>";		}	}	else 	{		if (!fx_is_pc_user_by_account(account)){			long head, body;			int prefix = 0;			head = account->id / (100000000); // 8 -> 10 				body = account->id % (100000000);			switch(head)			{				case 11:					prefix = 157;					break;				case 12:					prefix = 158;					break;				case 13:					prefix = 159;					break;				default:					//14-19					prefix = 130+ head%10;					break;			}			char mobile_no[12];			sprintf(mobile_no, "%d%08ld", prefix, body);			mobile_no[11] = '\0';			info += "<b style=\"color:red; \">"+QString(mobile_no) + "</b>"; 		}		info += "<b style=\"color:red; \"> </b>"; 	tips += info +"<br>";	}	if (fx_is_pc_user_by_account(account)){		info = tr("fetion_no:");		info += "<b style=\"color:red; \">"+QString("%1").arg(account->id)+"</b>";		tips += info +"<br>";	}	if(hP)	{		tmp = QString::fromUtf8(account->personal->nickname);		if (!tmp.isEmpty())		{			info = tr("nickname:");			info += "<b style=\"color:red; \">" + tmp +"</b>";			tips += info +"<br>";		}		tmp = QString::fromUtf8(account->personal->name);		if (!tmp.isEmpty())		{			info = tr("name:");			info += "<b style=\"color:red; \">" + tmp +"</b>";			tips += info +"<br>";		}		info = tr("gender:");		switch(account->personal->gender)		{			case 2:				info += "<b style=\"color:red; \">" + tr("girl") +"</b>";				tips += info +"<br>";				break;			case 1:				info += "<b style=\"color:red; \">" + tr("boy") +"</b>";				tips += info +"<br>";				break;			case 0:				info += "<b style=\"color:red; \">" + tr("unknow") +"</b>";				break;		}		tmp = QString::fromUtf8(account->personal->impresa);		if (!tmp.isEmpty())		{			info = tr("impresa:");			info += "<b style=\"color:red; \">" + tmp +"</b>";			tips += info +"<br>";		}	}	//remove the last "<br>"	tips = tips.remove( tips.size() - strlen("<br>"), strlen("<br>"));	return tips;}//fix: need to....void BuddyOpt::setTipsOfAccount(QTreeWidgetItem *accountItem, const Fetion_Account *account){	if (!accountItem || !account)		return;	QString tips = createAccountTipsInfo(account);	accountItem->setToolTip(0, tips); }QTreeWidgetItem* BuddyOpt::findGroupItemByID(int group_id){	QTreeWidgetItem *RootItem = this->treeWidget->invisibleRootItem();	if(!RootItem)		return NULL;	int GroupCount = RootItem-> childCount ();	QTreeWidgetItem *groupItem = NULL;	for(int i =0;  i< GroupCount; i++)	{		groupItem = RootItem->child(i);		if(!groupItem && isQunItem(groupItem) )			continue;#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)			continue;		if (group_id == group_info->groupID)			return groupItem;	}	return NULL;}QTreeWidgetItem* BuddyOpt::findAccountItemFromGroup(QTreeWidgetItem *groupItem, const Fetion_Account *account){	if(!groupItem || !account)		return NULL;	QTreeWidgetItem *tmpItem = NULL;	qlonglong account_id = (qlonglong)account->id;	int itemCounts = groupItem-> childCount ();	for(int i =0;  i< itemCounts; i++)	{		tmpItem = groupItem->child(i);		if(!tmpItem)			continue;#if MS_VC6		Account_Info *ac_info =(Account_Info*)(tmpItem->data(0, Qt::UserRole).toUInt());#else		Account_Info *ac_info =tmpItem->data(0, Qt::UserRole).value<Account_Info*>() ;#endif		if(ac_info && account_id == ac_info->accountID)			return tmpItem;	}	return NULL;}QTreeWidgetItem* BuddyOpt::findAccountItem(const Fetion_Account *account){	if(!account)		return NULL;	int	group_no = fx_get_account_group_id(account) ;	if(group_no <= 0)		group_no = 0;	QTreeWidgetItem* groupItem = findGroupItemByID(group_no);	QTreeWidgetItem *accountItem = findAccountItemFromGroup(groupItem, account);	if(accountItem)		return accountItem;	return NULL;}static bool isonline(int state){	if (state != FX_STATUS_OFFLINE && 			state != 0 &&			state != FX_STATUS_WAITING_AUTH &&			state != FX_STATUS_REFUSE &&			state != FX_STATUS_BLACK &&			state != FX_STATUS_MOBILE ) 		return true;	else		return false;}//this function will add to libfetion impl...// return false should not changed// true should changed// state is 0 sub the online number//       is 1 add the online numberbool BuddyOpt::isOnlineStateChanged(int old_state, int new_state, int* state){	if(old_state == new_state)		return false;	if( isonline(old_state))  //old_state is online state	{		if( !isonline(new_state)) { //new state is offline state			*state = 0;			return true;		}	} else { //old_state is offline state		if( isonline(new_state)) { //new state is online state			*state = 1;			return true;		}	}	return false;}void BuddyOpt::updateAccountInfo(qlonglong account_id){	const Fetion_Account * account = fx_get_account_by_id (account_id);	if(!account)		return;	QTreeWidgetItem* accountItem = findAccountItem(account);	//not find this account, so add it to Group...	if(!accountItem) {		printf("not find the item , i will add to the group\n");		addAccountToGroup (account);		return;	}	//update the account info	setTipsOfAccount(accountItem, account);	char * showname = fx_get_account_show_name(account, TRUE);	QString show_name = QString::fromUtf8(showname);	if(showname)		free(showname);#if MS_VC6	Account_Info *ac_info =(Account_Info*)(accountItem->data(0, Qt::UserRole).toUInt());#else	Account_Info *ac_info = accountItem->data(0, Qt::UserRole).value<Account_Info*>() ;#endif	if(!ac_info)		return;	ac_info->accountName = show_name;	int old_online_state = ac_info->onlinestate;	int new_online_state = fx_get_online_status_by_account(account);	ac_info->onlinestate = new_online_state;	accountItem->setText(0, show_name);	accountItem->setIcon(0, getOnlineStatusIcon(ac_info->onlinestate));	int state = 0;	if (isOnlineStateChanged(old_online_state , new_online_state , &state))	{		//group name ++1		int	group_no = fx_get_account_group_id(account) ;		if(group_no <= 0)			group_no = 0;		QTreeWidgetItem* groupItem = findGroupItemByID(group_no);		if(groupItem)		{#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)		return ;	groupItem->removeChild(accountItem);	//if (groupItem->childCount() == 0)	if (group_info->online_no - 1 > 0)		groupItem->insertChild(group_info->online_no - 1, accountItem);	else		groupItem->insertChild(0, accountItem);	if (state)					group_info->online_no ++;	else 		group_info->online_no --;			#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);		}	}	printf("Updata new buddy.... \n");}void BuddyOpt::updateStyles(QTreeWidgetItem *item, int column){    if (!item || column != 0)        return;    Qt::CheckState state = item->checkState(0);    QTreeWidgetItem *parent = item->parent();    if (parent) {        // Only count style items.        if (state == Qt::Checked)            ++markedCount;        else            --markedCount;		/*		//bad code...		if (markedCount > 32)		return;		*/        if (state == Qt::Checked &&            parent->checkState(0) == Qt::Unchecked) {            // Mark parent items when child items are checked.            parent->setCheckState(0, Qt::Checked);        } else if (state == Qt::Unchecked &&                   parent->checkState(0) == Qt::Checked) {            bool marked = false;            for (int row = 0; row < parent->childCount(); ++row) {                if (parent->child(row)->checkState(0) == Qt::Checked) {                    marked = true;                    break;                }            }            // Unmark parent items when all child items are unchecked.            if (!marked)                parent->setCheckState(0, Qt::Unchecked);        }    } else {        int row;        int number = 0;        for (row = 0; row < item->childCount(); ++row) {            if (item->child(row)->checkState(0) == Qt::Checked)                ++number;        }        // Mark/unmark all child items when marking/unmarking top-level        // items.        if (state == Qt::Checked && number == 0) {            for (row = 0; row < item->childCount(); ++row) {                if (item->child(row)->checkState(0) == Qt::Unchecked)                    item->child(row)->setCheckState(0, Qt::Checked);            }        } else if (state == Qt::Unchecked && number > 0) {            for (row = 0; row < item->childCount(); ++row) {                if (item->child(row)->checkState(0) == Qt::Checked)                    item->child(row)->setCheckState(0, Qt::Unchecked);            }        }    }	emit m_itemChanged();}

⌨️ 快捷键说明

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