Skip to content

Commit

Permalink
remove sgmlist
Browse files Browse the repository at this point in the history
  • Loading branch information
lidaobing committed Nov 11, 2021
1 parent 44f1f9e commit d3778c1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 49 deletions.
16 changes: 16 additions & 0 deletions src/iptux/GroupInfoManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ GroupInfo_S GroupInfoManager::addPal(PalInfo_S pal, PalInfo_SC me) {
return grpinf;
}

GroupInfo_S GroupInfoManager::getGroupInfo(const GroupInfo::KeyType& key) {
return groupInfos[key];
}

GroupInfo_S GroupInfoManager::addGroup(GroupBelongType type,
PalInfo_SC me,
std::string name) {
GroupInfo_S grpinf(new GroupInfo(type, vector<PPalInfo>(), me, logSystem));
grpinf->grpid = g_quark_from_static_string(name.c_str());
grpinf->name = name;
grpinf->buffer = gtk_text_buffer_new(programData->table);
grpinf->clearDialog();
addGroupInfo(grpinf);
return grpinf;
}

GroupInfo_S GroupInfoManager::getGroupInfo(const PalInfo* pal) {
return groupInfos[GroupInfo::genKey(pal)];
}
Expand Down
4 changes: 4 additions & 0 deletions src/iptux/GroupInfoManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ class GroupInfoManager {
GroupInfoManager(UiProgramData_S programData, LogSystem_S logSystem);

void addGroupInfo(GroupInfo_S groupInfo);

GroupInfo_S addPal(PalInfo_S pal, PalInfo_SC me);
GroupInfo_S addGroup(GroupBelongType type, PalInfo_SC me, std::string name);

GroupInfo_S getGroupInfo(const PalInfo* pal);
GroupInfo_S getGroupInfo(const GroupInfo::KeyType& key);

private:
UiProgramData_S programData;
Expand Down
64 changes: 16 additions & 48 deletions src/iptux/UiCoreThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ namespace iptux {
UiCoreThread::UiCoreThread(Application* app, shared_ptr<UiProgramData> data)
: CoreThread(data),
programData(data),
sgmlist(NULL),
grplist(NULL),
brdlist(NULL),
pbn(1),
Expand Down Expand Up @@ -63,28 +62,6 @@ void UiCoreThread::ClearAllPalFromList() {
GroupInfo* grpinf;
GSList* tlist;

// /* 清空常规模式下所有群组的成员 */
// tlist = groupInfos;
// while (tlist) {
// grpinf = (GroupInfo*)tlist->data;
// if (grpinf->getDialog()) {
// session = (SessionAbstract*)g_object_get_data(
// G_OBJECT(grpinf->getDialog()), "session-class");
// session->ClearAllPalData();
// }
// tlist = g_slist_next(tlist);
// }
/* 清空网段模式下所有群组的成员 */
tlist = sgmlist;
while (tlist) {
grpinf = (GroupInfo*)tlist->data;
if (grpinf->getDialog()) {
session = (SessionAbstract*)g_object_get_data(
G_OBJECT(grpinf->getDialog()), "session-class");
session->ClearAllPalData();
}
tlist = g_slist_next(tlist);
}
/* 清空分组模式下所有群组的成员 */
tlist = grplist;
while (tlist) {
Expand Down Expand Up @@ -235,21 +212,12 @@ GroupInfo* UiCoreThread::GetPalRegularItem(const PalInfo* pal) {
* @return 群组信息
*/
GroupInfo* UiCoreThread::GetPalSegmentItem(const PalInfo* pal) {
GSList* tlist;
GQuark grpid;

/* 获取局域网网段ID */
auto name = ipv4_get_lan_name(pal->ipv4);
grpid = g_quark_from_string(name.empty() ? _("Others") : name.c_str());

tlist = sgmlist;
while (tlist) {
if (((GroupInfo*)tlist->data)->grpid == grpid)
break;
tlist = g_slist_next(tlist);
}

return (GroupInfo*)(tlist ? tlist->data : NULL);
auto key = make_pair(GROUP_BELONG_TYPE_SEGMENT,
name.empty() ? _("Others") : name.c_str());
auto res = groupInfoManager->getGroupInfo(key);
return res ? res.get() : nullptr;
}

/**
Expand Down Expand Up @@ -298,9 +266,6 @@ void UiCoreThread::ClearSublayer() {

CoreThread::ClearSublayer();

for (tlist = sgmlist; tlist; tlist = g_slist_next(tlist))
delete (GroupInfo*)tlist->data;
g_slist_free(sgmlist);
for (tlist = grplist; tlist; tlist = g_slist_next(tlist))
delete (GroupInfo*)tlist->data;
g_slist_free(grplist);
Expand Down Expand Up @@ -357,15 +322,18 @@ GroupInfo* UiCoreThread::AttachPalSegmentItem(PPalInfo pal) {
name = _("Others");
}

grpinf = new GroupInfo(GROUP_BELONG_TYPE_SEGMENT, vector<PPalInfo>(), getMe(),
logSystem);
grpinf->grpid = g_quark_from_static_string(name.c_str());
grpinf->name = name;
grpinf->buffer = gtk_text_buffer_new(programData->table);
grpinf->clearDialog();
sgmlist = g_slist_append(sgmlist, grpinf);

return grpinf;
auto res =
groupInfoManager->addGroup(GROUP_BELONG_TYPE_SEGMENT, getMe(), name);
return res.get();

// grpinf = new GroupInfo(GROUP_BELONG_TYPE_SEGMENT, vector<PPalInfo>(),
// getMe(),
// logSystem);
// grpinf->grpid = g_quark_from_static_string(name.c_str());
// grpinf->name = name;
// grpinf->buffer = gtk_text_buffer_new(programData->table);
// grpinf->clearDialog();
// sgmlist = g_slist_append(sgmlist, grpinf);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/iptux/UiCoreThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ class UiCoreThread : public CoreThread {
std::queue<MsgPara> messages;

GroupInfoManager_U groupInfoManager;
GSList *sgmlist, *grplist, *brdlist; //群组链表(成员不能被删除)
// GSList *sgmlist;
GSList *grplist, *brdlist; //群组链表(成员不能被删除)

uint32_t pbn, prn; //当前已使用的文件编号(共享/私有)
GSList* ecsList; //文件链表(好友发过来)
Expand Down

0 comments on commit d3778c1

Please sign in to comment.