?? fxbuddy.cpp
字號(hào):
/*************************************************************************** * 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 <assert.h>#include "appconfig.h"#include "fxbuddy.h"#include "fxsendGroupSMS.h"BuddyOpt::BuddyOpt(QTreeWidget * widget, bool isMainView){ m_isMainView = isMainView; QunItem = NULL; have_zero_group = false; markedCount = 0; assert(widget); treeWidget = widget; addGroupToTree(); addAccountToTree(); if (m_isMainView) addQunToTree(); else { connect(treeWidget, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(updateStyles(QTreeWidgetItem *, int))); } //expandTree();}BuddyOpt::~BuddyOpt(){ freeAllGroupdata(); }void BuddyOpt::expandTree(){ QTreeWidgetItem *RootItem = this->treeWidget->invisibleRootItem(); if(!RootItem) return ; for(int i =0; i< RootItem-> childCount (); i++) this->treeWidget->expandItem (RootItem->child(i));}void BuddyOpt::freeAllGroupdata(){ QTreeWidgetItem *RootItem = this->treeWidget->invisibleRootItem(); if(!RootItem) return ; int GroupCount = RootItem-> childCount (); QTreeWidgetItem *groupItem = NULL; for(int i =0; i< GroupCount; i++) { groupItem = RootItem->child(i); if(!groupItem && isQunItem(groupItem) ) continue; //free all account data of this group freeAllAccountdata(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) delete group_info; }}void BuddyOpt::freeAllAccountdata(QTreeWidgetItem *groupItem) { if (!groupItem) return; int itemCounts = groupItem-> childCount(); QTreeWidgetItem *tmpItem = NULL; 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 ) delete ac_info; }}void BuddyOpt::addQunToTree(){ Fetion_Qun *qun = NULL; Qun_Info *qun_info = NULL; DList *tmp_qun = (DList *)fx_get_qun(); while(tmp_qun) { qun = (Fetion_Qun *) tmp_qun->data; if(qun) { if(!QunItem) { QunItem = new QTreeWidgetItem(treeWidget); QunItem->setText(0, tr("fetion qun")); } qun_info = new Qun_Info; char * qun_name = fx_get_qun_show_name(qun); qun_info->qunName = QString::fromUtf8(qun_name); if(qun_name) free(qun_name); qun_info->qunID = qun->id; #if MS_VC6 QVariant Var((uint)qun_info);#else QVariant Var; Var.setValue (qun_info); #endif QTreeWidgetItem *item; item = new QTreeWidgetItem(QunItem); item->setText(0, qun_info->qunName); item->setIcon(0, getQunIcon()); item->setData(0, Qt::UserRole, Var); } tmp_qun = d_list_next(tmp_qun); }}bool BuddyOpt::isQunItem(QTreeWidgetItem *item) { if(QunItem) return item == QunItem; else return false;}//add Group info to tree widgetvoid BuddyOpt::addGroupToTree(){ 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) { QTreeWidgetItem *item; item = new QTreeWidgetItem(treeWidget); if (!m_isMainView) item->setCheckState(0, Qt::Unchecked); QString str = QString::fromUtf8(group->name); groupinfo = new Group_Info; groupinfo->groupName = str; groupinfo->groupID = group->id; groupinfo->online_no = 0; item->setText(0, str+"(0/0)"); #if MS_VC6 QVariant Var((uint)groupinfo);#else QVariant Var; Var.setValue (groupinfo); #endif item->setData(0, Qt::UserRole, Var); } tmp_group = d_list_next(tmp_group); }}void BuddyOpt::delAccount_direct(qlonglong uid){ QTreeWidgetItem *RootItem = this->treeWidget->invisibleRootItem(); if(!RootItem) return ; int GroupCount = RootItem-> childCount (); QTreeWidgetItem *groupItem = NULL; for(int i =0; i< GroupCount; i++) { groupItem = RootItem->child(i); if(!groupItem && isQunItem(groupItem) ) continue; int itemCounts = groupItem-> childCount(); QTreeWidgetItem *tmpItem = NULL; 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) continue; if(ac_info->accountID == uid) { delAccount(tmpItem); return; } } }}void BuddyOpt::delAccount(QTreeWidgetItem* accountItem) { if(!accountItem) return;#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; const Fetion_Account * account = fx_get_account_by_id (ac_info->accountID); if(ac_info ) delete ac_info; QTreeWidgetItem* groupItem = accountItem->parent(); if(!groupItem) return; groupItem->removeChild(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 (!group_info) return ; if (fx_is_on_line_by_account(account)) 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); }}void BuddyOpt::delAccount(qlonglong uid) { const Fetion_Account * account = fx_get_account_by_id (uid); if(!account) return; delAccount(findAccountItem(account)); }void BuddyOpt::addGroup(const char* groupname, qlonglong id){ Group_Info *groupinfo = new Group_Info; groupinfo->groupName = QString::fromUtf8((char*)groupname); groupinfo->groupID = id; groupinfo->online_no = 0; QTreeWidgetItem *item; item = new QTreeWidgetItem(treeWidget); if (!m_isMainView) item->setCheckState(0, Qt::Unchecked); item->setText(0, groupinfo->groupName+"(0/0)"); #if MS_VC6 QVariant Var((uint)groupinfo);#elseQVariant Var; Var.setValue (groupinfo); #endif item->setData(0, Qt::UserRole, Var);}void BuddyOpt::delGroup(qlonglong id) { QTreeWidgetItem *RootItem = this->treeWidget->invisibleRootItem(); if(!RootItem) return ; QTreeWidgetItem *groupItem = NULL; int GroupCount = RootItem-> childCount (); 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 && group_info->groupID == id) { //free all account data of this group freeAllAccountdata(groupItem); delete group_info; RootItem->removeChild(groupItem); } }}//add account info to tree widgetvoid BuddyOpt::addAccountToTree(){ Fetion_Account *account = NULL; DList *tmp_account = (DList *)fx_get_account(); while(tmp_account) { account = (Fetion_Account *)tmp_account->data; if(account) addAccountToGroup(account); tmp_account = d_list_next(tmp_account); }}//add account to it's group item void BuddyOpt::addAccountToGroup(const Fetion_Account *account) { //remove the user's id on account from list... if (!account || account->id == (qlonglong)strtol(fx_get_usr_uid(), NULL, 10)) return; int group_no = fx_get_account_group_id(account) ; if(group_no <= 0) { group_no = 0; if( !have_zero_group) { QTreeWidgetItem *item; item = new QTreeWidgetItem(treeWidget); if (!m_isMainView) item->setCheckState(0, Qt::Unchecked); QString str = tr("un set group"); Group_Info *groupinfo = new Group_Info; groupinfo->groupName = str; groupinfo->groupID = group_no; groupinfo->online_no = 0; item->setText(0, str);#if MS_VC6 QVariant Var((uint)groupinfo);#else QVariant Var; Var.setValue (groupinfo); #endif item->setData(0, Qt::UserRole, Var); have_zero_group = true; } } char * showname = fx_get_account_show_name(account, TRUE); QString show_name = QString::fromUtf8(showname); int online_state = fx_get_online_status_by_account(account); addAccountToGroup(account, show_name, online_state, group_no); if(showname) free(showname);}void BuddyOpt::addAccountToGroup(const Fetion_Account *account, QString & name, int online_state, int group_id ){ //remove the user's id on account from list... fixed: it maybe have redundance if (!account || account->id == (qlonglong)strtol(fx_get_usr_uid(), NULL, 10)) return; QTreeWidgetItem * groupItem = findGroupItemByID(group_id); if(!groupItem)
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -