More contact groups shit. Pain in my ass.

This commit is contained in:
CharleyLevenque
2010-09-27 00:45:04 -04:00
parent 2614a96731
commit 3fa7780d51
5 changed files with 66 additions and 145 deletions

View File

@@ -13,6 +13,19 @@
<string />
</array>
</map>
<key>AscentContactGroups</key>
<map>
<key>Comment</key>
<string>List for contact groups</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>LLSD</string>
<key>Value</key>
<array>
<string />
</array>
</map>
<key>Responder.Settings</key>
<map>
<key>Comment</key>

View File

@@ -32,6 +32,7 @@
ASFloaterContactGroups* ASFloaterContactGroups::sInstance = NULL;
LLDynamicArray<LLUUID> ASFloaterContactGroups::mSelectedUUIDs;
LLSD ASFloaterContactGroups::mContactGroupData;
ASFloaterContactGroups::ASFloaterContactGroups()
: LLFloater(std::string("floater_contact_groups"), std::string("FloaterContactRect"), LLStringUtil::null)
@@ -140,129 +141,37 @@ void ASFloaterContactGroups::populateFriendList()
}
}
std::string ASFloaterContactGroups::cleanFileName(std::string filename)
{
std::string invalidChars = "\"\'\\/?*:<>| ";
S32 position = filename.find_first_of(invalidChars);
while (position != filename.npos)
{
filename[position] = '_';
position = filename.find_first_of(invalidChars, position);
}
return filename;
}
void ASFloaterContactGroups::addContactMember(std::string contact_grp, LLUUID to_add)
{
std::string clean_contact_grp = cleanFileName(contact_grp);
std::string member_string = "Ascent." + clean_contact_grp + ".Members";
if (!gSavedSettings.controlExists(member_string))
gSavedSettings.declareString(member_string, to_add.asString(), "Stores UUIDs of members for " + clean_contact_grp, TRUE);
else
gSavedSettings.setString(member_string, gSavedSettings.getString(member_string) + " " + to_add.asString());
ASFloaterContactGroups::mContactGroupData[contact_grp].append(to_add.asString());
gSavedPerAccountSettings.setLLSD("AscentContactGroups", ASFloaterContactGroups::mContactGroupData);
}
void ASFloaterContactGroups::deleteContactGroup(std::string contact_grp)
{
std::string clean_contact_grp = cleanFileName(contact_grp);
std::string display_string = "Ascent." + clean_contact_grp + ".Display";
gSavedSettings.setString(display_string, "##DELETED##");
std::string group_list(gSavedSettings.getString("AscentContactGroups"));
if (group_list.find(clean_contact_grp) != group_list.npos)
{
gSavedSettings.setString(
"AscentContactGroups",
group_list.erase(
group_list.find_first_of(clean_contact_grp),
clean_contact_grp.length()
)
);
}
}
void ASFloaterContactGroups::createContactGroup(std::string contact_grp)
{
std::string clean_contact_grp = cleanFileName(contact_grp);
std::string display_string = "Ascent." + clean_contact_grp + ".Display";
std::string member_string = "Ascent." + clean_contact_grp + ".Members";
if (gSavedSettings.controlExists(display_string))
{
std::string s_display = gSavedSettings.getString(display_string);
if (s_display != "##DELETED##")
{
LLChat msg("Can't create duplicate group names.");
LLFloaterChat::addChat(msg);
return;
}
}
gSavedSettings.declareString(member_string, "NULL_KEY", "Stores UUIDs of members for " + clean_contact_grp, TRUE);
gSavedSettings.declareString(display_string, contact_grp, "Stores the real name of " + clean_contact_grp, TRUE);
gSavedSettings.setString(display_string, contact_grp);
gSavedSettings.saveToFile(gSavedSettings.getString("ClientSettingsFile"), TRUE);
gSavedSettings.setString(member_string, "NULL_KEY");
gSavedSettings.saveToFile(gSavedSettings.getString("ClientSettingsFile"), TRUE);
if (!gSavedSettings.controlExists("AscentContactGroups"))
{
gSavedSettings.declareString("AscentContactGroups", clean_contact_grp, "Stores titles of all Contact Groups", TRUE);
gSavedSettings.setString("AscentContactGroups", clean_contact_grp);
}
else
{
std::string group_list(gSavedSettings.getString("AscentContactGroups"));
group_list += " " + clean_contact_grp;
gSavedSettings.setString("AscentContactGroups", group_list);
}
gSavedSettings.saveToFile(gSavedSettings.getString("ClientSettingsFile"), TRUE);
}
void StringSplit(std::string str, std::string delim, std::vector<std::string> results)
{
int cutAt;
while((cutAt = str.find_first_of(delim)) != str.npos)
{
if(cutAt > 0)
{
results.push_back(str.substr(0,cutAt));
}
str = str.substr(cutAt+1);
}
if(str.length() > 0)
{
results.push_back(str);
}
ASFloaterContactGroups::mContactGroupData["ASC_MASTER_GROUP_LIST"].append(contact_grp);
gSavedPerAccountSettings.setLLSD("AscentContactGroups", ASFloaterContactGroups::mContactGroupData);
populateGroupList();
}
void ASFloaterContactGroups::populateGroupList()
{
ASFloaterContactGroups::mContactGroupData = gSavedPerAccountSettings.getLLSD("AscentContactGroups");
LLScrollListCtrl* scroller = getChild<LLScrollListCtrl>("group_scroll_list");
if(scroller != NULL)
{
scroller->deleteAllItems();
if (gSavedSettings.controlExists("AscentContactGroups"))
S32 count = ASFloaterContactGroups::mContactGroupData["ASC_MASTER_GROUP_LIST"].size();
S32 index;
for (index = 0; index < count; index++)
{
scroller->addSimpleElement(gSavedSettings.getString("AscentContactGroups"), ADD_BOTTOM);
/**
std::vector<std::string> group_list;
StringSplit(gSavedSettings.getString("AscentContactGroups"), " ", group_list);
for (S32 i=0; i < group_list.size(); i++)
{
scroller->addSimpleElement(group_list[i], ADD_BOTTOM);
LLChat msg("Add " + group_list[i]);
LLFloaterChat::addChat(msg);
}
**/
scroller->addSimpleElement(ASFloaterContactGroups::mContactGroupData["ASC_MASTER_GROUP_LIST"][index].asString(), ADD_BOTTOM);
}
}
else

View File

@@ -17,6 +17,7 @@
#include "llfloater.h"
#include "lldarray.h"
#include "llsdserialize.h"
class LLScrollListCtrl;
@@ -29,7 +30,6 @@ public:
// by convention, this shows the floater and does instance management
static void show(LLDynamicArray<LLUUID> ids);
static std::string cleanFileName(std::string filename);
void populateGroupList();
void populateFriendList();
@@ -47,6 +47,7 @@ private:
//assuming we just need one, which is typical
static ASFloaterContactGroups* sInstance;
static LLDynamicArray<LLUUID> mSelectedUUIDs;
static LLSD mContactGroupData;
};
#endif // ASCENT_CONTACT_GROUPS

View File

@@ -105,6 +105,7 @@ public:
}
virtual BOOL tick()
{
mFloater->populateContactGroupSelect();
mFloater->updateFriends(mMask);
mEventTimer.stop();
@@ -222,27 +223,13 @@ void LLPanelFriends::populateContactGroupSelect()
combo->removeall();
combo->add("All", ADD_BOTTOM);
std::string name;
gDirUtilp->getNextFileInDir(gDirUtilp->getPerAccountChatLogsDir(),"*",name,false);//stupid hack to clear last file search
LLSD groups = gSavedPerAccountSettings.getLLSD("AscentContactGroups");
std::string path_name(gDirUtilp->getPerAccountChatLogsDir() + gDirUtilp->getDirDelimiter());
bool found = true;
while(found = gDirUtilp->getNextFileInDir(path_name, "*.grp", name, false))
S32 count = groups["ASC_MASTER_GROUP_LIST"].size();
S32 index;
for (index = 0; index < count; index++)
{
if ((name == ".") || (name == "..")) continue;
//llinfos << "path name " << path_name << " and name " << name << " and found " << found << llendl;
if(found)
{
S32 periodIndex = name.find_last_of(".");
name = name.substr(0, periodIndex);
if ((name == ".") || (name == "..")) continue;
combo->add(name, ADD_BOTTOM);
//LLChat msg("Combo Add " + name);
//LLFloaterChat::addChat(msg);
}
combo->addSimpleElement(groups["ASC_MASTER_GROUP_LIST"][index].asString(), ADD_BOTTOM);
}
}
else
@@ -254,41 +241,50 @@ void LLPanelFriends::populateContactGroupSelect()
void LLPanelFriends::setContactGroup(std::string contact_grp)
{
std::string group_path = gDirUtilp->getPerAccountChatLogsDir() + gDirUtilp->getDirDelimiter();
std::string filename = group_path + cleanFileName(contact_grp + ".grp");
FILE* fp = LLFile::fopen(filename, "w");
if (fp)
if (contact_grp != "All")
{
char buffer[10000]; /*Flawfinder: ignore*/
char *bptr;
S32 len = 0;
filterContacts();
categorizeContacts();
}
else refreshNames(LLFriendObserver::ADD);
}
while ( fgets(buffer, 10000, fp) && !feof(fp) )
void LLPanelFriends::categorizeContacts()
{
LLSD contact_groups = gSavedPerAccountSettings.getLLSD("AscentContactGroups");
std::string group_name = "All";
LLComboBox* combo = getChild<LLComboBox>("buddy_group_combobox");
if (combo)
{
group_name = combo->getValue().asString();
if (group_name != "All")
{
len = strlen(buffer) - 1; /*Flawfinder: ignore*/
for ( bptr = (buffer + len); (*bptr == '\n' || *bptr == '\r') && bptr>buffer; bptr--) *bptr='\0';
std::vector<LLScrollListItem*> vFriends = mFriendsList->getAllData(); // all of it.
for (std::vector<LLScrollListItem*>::iterator itr = vFriends.begin(); itr != vFriends.end(); ++itr)
{
BOOL show_entry = (contact_groups[group_name][(*itr)->getUUID().asString()].size() != 0);
if (!show_entry)
{
mFriendsList->deleteItems((*itr)->getValue());
}
}
}
std::string file_contents(buffer);
mContactFilter = file_contents;
LLChat msg(mContactFilter);
LLFloaterChat::addChat(msg);
refreshUI();
}
}
void LLPanelFriends::filterContacts()
{
//LLComboBox* combo = getChild<LLComboBox>("buddy_group_combobox");
//if (combo->getValue().asString() != "All")
std::string friend_name;
std::string search_name;
search_name = LLPanelFriends::getChild<LLLineEditor>("buddy_search_lineedit")->getValue().asString();
if (search_name != "" && search_name != mLastContactSearch)
if ((search_name != "" /*&& search_name != mLastContactSearch*/))
{
mLastContactSearch = search_name;
refreshNames(LLFriendObserver::ADD);
@@ -298,6 +294,7 @@ void LLPanelFriends::filterContacts()
{
friend_name = utf8str_tolower((*itr)->getColumn(LIST_FRIEND_NAME)->getValue().asString());
BOOL show_entry = (friend_name.find(utf8str_tolower(search_name)) != std::string::npos);
if (!show_entry)
{
mFriendsList->deleteItems((*itr)->getValue());
@@ -698,7 +695,6 @@ BOOL LLPanelFriends::refreshNamesPresence(const LLAvatarTracker::buddy_map_t & a
// meal disk
void LLPanelFriends::refreshUI()
{
populateContactGroupSelect();
BOOL single_selected = FALSE;
BOOL multiple_selected = FALSE;
int num_selected = mFriendsList->getAllSelected().size();

View File

@@ -83,6 +83,8 @@ public:
static void requestFriendship(const LLUUID& target_id,
const std::string& target_name, const std::string& message);
void populateContactGroupSelect();
private:
enum FRIENDS_COLUMN_ORDER
@@ -103,8 +105,8 @@ private:
void refreshNames(U32 changed_mask);
// <dogmode> Contacts search and group system
void filterContacts();
void categorizeContacts();
void setContactGroup(std::string contact_grp);
void populateContactGroupSelect();
std::string cleanFileName(std::string filename);
// --
BOOL refreshNamesSync(const LLAvatarTracker::buddy_map_t & all_buddies);