23 #include "dockBuddiesList.h" 24 #include "ui_addBuddyDlg.h" 25 #include "ui_dockBuddiesList.h" 26 #include "configuration/doomseekerconfig.h" 27 #include "serverapi/mastermanager.h" 28 #include "serverapi/playerslist.h" 29 #include "serverapi/server.h" 30 #include "patternlist.h" 31 #include "strings.hpp" 33 #include <QMessageBox> 35 #include <QStandardItemModel> 37 class BuddyLocationInfo
40 BuddyLocationInfo(
const Player &buddy, ServerPtr location);
43 const Player &buddy()
const;
44 ServerPtr location()
const;
46 bool operator==(
const BuddyLocationInfo &other)
const;
54 DClass<BuddyLocationInfo>
61 DPointered(BuddyLocationInfo)
66 QList<BuddyLocationInfo> buddies;
67 QStandardItemModel *buddiesTableModel;
74 : QDockWidget(parent), masterClient(NULL), save(false)
77 this->toggleViewAction()->setIcon(QIcon(
":/icons/buddies.png"));
80 d->buddiesTableModel =
new QStandardItemModel();
84 columns << DockBuddiesList::tr(
"ID");
85 columns << DockBuddiesList::tr(
"Buddy");
86 columns << DockBuddiesList::tr(
"Location");
87 d->buddiesTableModel->setHorizontalHeaderLabels(columns);
89 d->buddiesTable->setModel(d->buddiesTableModel);
90 d->buddiesTable->setColumnHidden(0,
true);
93 d->patterns = gConfig.doomseeker.buddies;
95 foreach (
const QRegExp& pattern, d->patterns)
97 d->patternsList->addItem(pattern.pattern());
100 connect(d->addButton, SIGNAL( clicked() ),
this, SLOT( addBuddy() ));
101 connect(d->buddiesTable, SIGNAL( doubleClicked(
const QModelIndex &) ),
this, SLOT( followBuddy(
const QModelIndex &) ));
102 connect(d->deleteButton, SIGNAL( clicked() ),
this, SLOT( deleteBuddy() ));
103 connect(d->patternsList, SIGNAL( customContextMenuRequested(
const QPoint &) ),
this, SLOT( patternsListContextMenu(
const QPoint &) ));
106 DockBuddiesList::~DockBuddiesList()
111 gConfig.doomseeker.buddies = d->patterns;
114 void DockBuddiesList::addBuddy()
117 int result = dlg.exec();
118 if(result != QDialog::Accepted)
121 QRegExp pattern = dlg.pattern();
122 d->patterns << pattern;
123 d->patternsList->addItem(pattern.pattern());
130 void DockBuddiesList::deleteBuddy()
133 if(d->patternsList->selectionModel()->selectedIndexes().size() <= 0)
136 if(QMessageBox::warning(
this, tr(
"Delete Buddy"), tr(
"Are you sure you want to delete this pattern?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes)
140 QModelIndexList selection = d->patternsList->selectionModel()->selectedIndexes();
142 while(selection.size() > 0)
144 int largestIndex = 0;
145 for(
int i = 1;i < selection.size();i++)
147 if(selection[i].row() > selection[largestIndex].row())
151 d->patterns.removeAt(selection[largestIndex].row());
152 delete d->patternsList->item(selection[largestIndex].row());
153 selection.removeAt(largestIndex);
161 void DockBuddiesList::followBuddy(
const QModelIndex &index)
166 ServerPtr server = d->buddies[d->buddiesTableModel->item(index.row(), BLCID_ID)->data().toInt()].location();
167 emit joinServer(server);
170 bool DockBuddiesList::hasBuddy(
const ServerPtr &server)
172 foreach (
const BuddyLocationInfo &location, d->buddies)
174 if (location.location() == server)
182 void DockBuddiesList::patternsListContextMenu(
const QPoint &pos)
const 185 QModelIndexList selection = d->patternsList->selectionModel()->selectedIndexes();
190 QAction *addAction = context.addAction(tr(
"Add"));
191 connect(addAction, SIGNAL( triggered() ),
this, SLOT( addBuddy() ));
194 if(selection.size() > 0)
196 QAction *deleteAction = context.addAction(tr(
"Delete"));
197 connect(deleteAction, SIGNAL( triggered() ),
this, SLOT( deleteBuddy() ));
201 context.exec(d->patternsList->mapToGlobal(pos));
206 if(master == NULL && masterClient == NULL)
208 else if(master != masterClient && master != NULL)
210 masterClient = master;
214 foreach(ServerPtr server, masterClient->allServers())
216 if (!server->isKnown())
220 for(
int i = 0; i < server->players().numClients(); ++i)
222 const Player player = server->player(i);
225 BuddyLocationInfo candidate(player, server);
226 if (!d->buddies.contains(candidate))
228 d->buddies << BuddyLocationInfo(player, server);
235 d->buddiesTableModel->removeRows(0, d->buddiesTableModel->rowCount());
236 for(
int i = 0;i < d->buddies.size();i++)
238 const BuddyLocationInfo &info = d->buddies[i];
239 QList<QStandardItem *> columns;
241 for(
int j = 0;j < HOW_MANY_BUDDIESLIST_COLUMNS;j++)
247 QStandardItem *item =
new QStandardItem();
253 columns <<
new QStandardItem(info.buddy().nameColorTagsStripped());
256 columns <<
new QStandardItem(info.location()->name());
259 columns <<
new QStandardItem();
264 d->buddiesTableModel->appendRow(columns);
268 d->buddiesTable->resizeRowsToContents();
269 emit scanCompleted();
274 DClass<AddBuddyDlg> :
public Ui::AddBuddyDlg
284 connect(d->buttonBox, SIGNAL( clicked(QAbstractButton *) ),
this, SLOT( buttonBoxClicked(QAbstractButton *) ));
287 AddBuddyDlg::~AddBuddyDlg()
291 void AddBuddyDlg::buttonBoxClicked(QAbstractButton *button)
293 if(d->buttonBox->standardButton(button) == QDialogButtonBox::Ok)
295 if (!pattern().isValid())
297 QMessageBox::information(
this, tr(
"Invalid Pattern"), tr(
"The pattern you have specified is invalid."));
306 QRegExp AddBuddyDlg::pattern()
const 308 QRegExp::PatternSyntax syntax = d->basicPattern->isChecked() ? QRegExp::Wildcard : QRegExp::RegExp;
309 return QRegExp(d->patternBox->text(), Qt::CaseInsensitive, syntax);
314 BuddyLocationInfo::BuddyLocationInfo(
const Player &buddy, ServerPtr location)
317 d->server = location;
320 BuddyLocationInfo::~BuddyLocationInfo()
324 const Player &BuddyLocationInfo::buddy()
const 329 ServerPtr BuddyLocationInfo::location()
const 334 bool BuddyLocationInfo::operator==(
const BuddyLocationInfo &other)
const 336 return d->buddy == other.d->buddy
337 && d->server->address() == other.d->server->address()
338 && d->server->port() == other.d->server->port()
339 && d->server->plugin() == other.d->server->plugin();
QString nameColorTagsStripped() const
Data structure that holds information about players in a server.
Manager class for a number of MasterClient instances.