/*
Copyright (C) 2008 John Hobbs - john@velvetcache.org
This file is part of The Mana World Buddy.
The Mana World Buddy 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 3 of the License, or
(at your option) any later version.
The Mana World Buddy 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 The Mana World Buddy. If not, see .
*/
#include "addDialog.h"
namespace tmwb {
addDialog::addDialog(std::set _users) :
addEntry("Add From Entry"), addSelected("Add Selected"), done("Done") {
users = _users;
set_title("Add Buddies");
set_border_width(5);
set_default_size(250,400);
get_action_area()->add(addEntry);
get_action_area()->add(addSelected);
get_action_area()->add(done);
addEntry.signal_clicked().connect(sigc::mem_fun(*this,&addDialog::onAddEntryClick));
addSelected.signal_clicked().connect(sigc::mem_fun(*this,&addDialog::onAddSelectedClick));
done.signal_clicked().connect(sigc::mem_fun(*this,&addDialog::hide));
potentialBuddiesList = new Gtk::ListViewText(1);
potentialBuddiesList->set_column_title(0,"Online Users");
refreshList();
potentialBuddiesScrolledWindow.add(*potentialBuddiesList);
potentialBuddiesScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC,Gtk::POLICY_AUTOMATIC);
get_vbox()->pack_start(potentialBuddiesScrolledWindow,true,true,5);
get_vbox()->pack_start(entry,false,false,5);
show_all();
}
addDialog::~addDialog() {
if(NULL != potentialBuddiesList) {
delete potentialBuddiesList;
}
}
void addDialog::onAddEntryClick() {
sig_addThem.emit(entry.get_text());
users.erase(entry.get_text());
refreshList();
}
void addDialog::onAddSelectedClick() {
std::vector addThese = potentialBuddiesList->get_selected();
for(std::vector::iterator it = addThese.begin(); it < addThese.end(); it++) {
sig_addThem.emit(potentialBuddiesList->get_text(*it));
users.erase(potentialBuddiesList->get_text(*it));
}
refreshList();
}
void addDialog::refreshList() {
potentialBuddiesList->clear_items();
for(std::set::iterator it = users.begin(); it != users.end(); it++) {
potentialBuddiesList->append_text(*it);
}
}
}