Debian Codegraph @

src/network/friendslistdialog.cpp

raw symbols SCIP
1 /***************************************************************************
2 * Copyright (C) 2009 by The qGo Project *
3 * *
4 * This file is part of qGo. *
5 * *
6 * qGo is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, see <http://www.gnu.org/licenses/> *
18 * or write to the Free Software Foundation, Inc., *
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 ***************************************************************************/
21
22
23 #include "friendslistdialog.h"
24 #include "network/networkconnection.h"
25 #include "network/playergamelistings.h"
26 #include "listviews.h"
27 #include "talk.h"
28 #include "room.h"
29
30 FriendsListDialog::FriendsListDialog(NetworkConnection * c, Room * r) : QDialog(), Ui::FriendsListDialog()
31 {
32 connection = c;
33 room = r;
34 ui.setupUi(this);
35
36 friendsView = ui.friendsView;
37 watchesView = ui.watchesView;
38 blockedView = ui.blockedView;
39
40 //friendsSortProxy = new PlayerSortProxy();
41 friendsListModel = new SimplePlayerListModel(true);
42 //friendsSortProxy->setSourceModel(friendsListModel);
43 //friendsView->setModel(friendsSortProxy);
44 friendsView->setModel(friendsListModel);
45 //friendsSortProxy->setDynamicSortFilter(true);
46 //probably don't need to be able to change sort order or sort on notify FIXME
47 watchesListModel = new SimplePlayerListModel(true);
48 watchesView->setModel(watchesListModel);
49 blockedListModel = new SimplePlayerListModel(true);
50 blockedView->setModel(blockedListModel);
51
52 connect(friendsView, &QTableView::customContextMenuRequested, this, &FriendsListDialog::slot_showPopupFriends);
53 connect(watchesView, &QTableView::customContextMenuRequested, this, &FriendsListDialog::slot_showPopupWatches);
54 connect(blockedView, &QTableView::customContextMenuRequested, this, &FriendsListDialog::slot_showPopupBlocked);
55
56 connect(friendsView, &QTableView::doubleClicked, this, &FriendsListDialog::slot_playersDoubleClickedFriends);
57 connect(watchesView, &QTableView::doubleClicked, this, &FriendsListDialog::slot_playersDoubleClickedWatches);
58
59
60 /* We need basically the same popup options as from room.cpp */
61 populateLists();
62
63 }
64
65 FriendsListDialog::~FriendsListDialog()
66 {
67 delete friendsListModel;
68 delete watchesListModel;
69 delete blockedListModel;
70 }
71
72 void FriendsListDialog::populateLists(void)
73 {
74 /* Either we get the local lists from the network connection
75 * or we get server side lists... the issue is that
76 * different servers may have different stored info on
77 * the listings, which means we can't necessarily assume
78 * they come in the same form as the local lists or are
79 * loaded as such. We might need to override that or have
80 * some kind of special list iterator or maybe have the
81 * other protocols subclass the FriendWatchListing and do
82 * some dynamic_cast ing here.
83 * In any event, I think we need to checkup on ORO and tygem
84 * friend lists before we go any further here */
85 /* So far it looks like if there's a notification option,
86 * its global, which means ours would either be stuck on
87 * or we'd have to store them privately.
88 * Tygem doesn't seem to have watches, but it does have
89 * friends and blocks, IGS nothing.
90 *
91 * I think though I've decided that the time checks and
92 * the friends lists are a lower priority than getting
93 * games playing on all three services */
94
95 std::vector<FriendWatchListing *> & friends = connection->getFriendsList();
96 std::vector<FriendWatchListing *> & watches = connection->getWatchesList();
97 std::vector<FriendWatchListing *> & blocked = connection->getBlockedList();
98
99 std::vector<FriendWatchListing *>::iterator i;
100 PlayerListing * p;
101 for(i = friends.begin(); i != friends.end(); i++)
102 {
103 p = connection->getPlayerListingFromFriendWatchListing(**i);
104 if(p)
105 friendsListModel->insertListing(p);
106 }
107 for(i = watches.begin(); i != watches.end(); i++)
108 {
109 p = connection->getPlayerListingFromFriendWatchListing(**i);
110 if(p)
111 watchesListModel->insertListing(p);
112 }
113 for(i = blocked.begin(); i != blocked.end(); i++)
114 {
115 p = connection->getPlayerListingFromFriendWatchListing(**i);
116 if(p)
117 blockedListModel->insertListing(p);
118 }
119 }
120
121 /* FIXME this is getting the wrong entry, like if I click on 0th, it takes
122 * the 1st off */
123 void FriendsListDialog::slot_showPopupFriends(const QPoint & iPoint)
124 {
125 popup_item = friendsView->indexAt(iPoint);
126 if (popup_item != QModelIndex())
127 {
128 popup_playerlisting = friendsListModel->playerListingFromIndex(popup_item);
129 if(popup_playerlisting->name == connection->getUsername())
130 return;
131
132 QMenu menu(friendsView);
133 menu.addAction(tr("Match"), this, &FriendsListDialog::slot_popupMatch);
134 menu.addAction(tr("Talk"), this, &FriendsListDialog::slot_popupTalk);
135 menu.addSeparator();
136 menu.addAction(tr("Remove from Friends"), this, &FriendsListDialog::slot_removeFriend);
137 menu.addAction(tr("Add to Watches"), this, &FriendsListDialog::slot_addWatch);
138 menu.addAction(tr("Block"), this, &FriendsListDialog::slot_addBlock);
139 menu.exec(friendsView->mapToGlobal(iPoint));
140 }
141 }
142
143 void FriendsListDialog::slot_showPopupWatches(const QPoint & iPoint)
144 {
145 popup_item = watchesView->indexAt(iPoint);
146 if (popup_item != QModelIndex())
147 {
148 popup_playerlisting = watchesListModel->playerListingFromIndex(popup_item);
149 if(popup_playerlisting->name == connection->getUsername())
150 return;
151
152 QMenu menu(watchesView);
153 menu.addAction(tr("Match"), this, &FriendsListDialog::slot_popupMatch);
154 menu.addAction(tr("Talk"), this, &FriendsListDialog::slot_popupTalk);
155 menu.addSeparator();
156 menu.addAction(tr("Add to Friends"), this, &FriendsListDialog::slot_addFriend);
157 //Maybe we don't want to have match and talk as fan options?
158 menu.addAction(tr("Remove from Watches"), this, &FriendsListDialog::slot_removeWatch);
159 menu.addAction(tr("Block"), this, &FriendsListDialog::slot_addBlock);
160 menu.exec(watchesView->mapToGlobal(iPoint));
161 }
162 }
163
164 void FriendsListDialog::slot_showPopupBlocked(const QPoint & iPoint)
165 {
166 popup_item = blockedView->indexAt(iPoint);
167 if (popup_item != QModelIndex())
168 {
169 popup_playerlisting = blockedListModel->playerListingFromIndex(popup_item);
170 if(popup_playerlisting->name == connection->getUsername())
171 return;
172
173 QMenu menu(blockedView);
174 menu.addAction(tr("Remove from Blocked"), this, &FriendsListDialog::slot_removeBlock);
175 menu.exec(blockedView->mapToGlobal(iPoint));
176 }
177 }
178
179 void FriendsListDialog::slot_addFriend(void)
180 {
181 if(popup_playerlisting->friendWatchType == PlayerListing::watched)
182 watchesListModel->removeListing(popup_playerlisting);
183 else if(popup_playerlisting->friendWatchType == PlayerListing::blocked)
184 blockedListModel->removeListing(popup_playerlisting);
185 friendsListModel->insertListing(popup_playerlisting);
186 connection->addFriend(popup_playerlisting);
187 }
188
189 /* This needs to call a resort or something on the list
190 * if we have "friends" checked, same thing with blocked
191 * if we don't, just to update that one entry FIXME */
192 void FriendsListDialog::slot_removeFriend(void)
193 {
194 friendsListModel->removeListing(popup_playerlisting);
195 connection->removeFriend(popup_playerlisting);
196 }
197
198 void FriendsListDialog::slot_addWatch(void)
199 {
200 if(popup_playerlisting->friendWatchType == PlayerListing::friended)
201 friendsListModel->removeListing(popup_playerlisting);
202 else if(popup_playerlisting->friendWatchType == PlayerListing::blocked)
203 blockedListModel->removeListing(popup_playerlisting);
204 watchesListModel->insertListing(popup_playerlisting);
205 connection->addWatch(popup_playerlisting);
206 }
207
208 void FriendsListDialog::slot_removeWatch(void)
209 {
210 watchesListModel->removeListing(popup_playerlisting);
211 connection->removeWatch(popup_playerlisting);
212 }
213
214 void FriendsListDialog::slot_addBlock(void)
215 {
216 if(popup_playerlisting->friendWatchType == PlayerListing::friended)
217 friendsListModel->removeListing(popup_playerlisting);
218 else if(popup_playerlisting->friendWatchType == PlayerListing::watched)
219 watchesListModel->removeListing(popup_playerlisting);
220 blockedListModel->insertListing(popup_playerlisting);
221 connection->addBlock(popup_playerlisting);
222 }
223
224 void FriendsListDialog::slot_removeBlock(void)
225 {
226 blockedListModel->removeListing(popup_playerlisting);
227 connection->removeBlock(popup_playerlisting);
228 }
229
230 void FriendsListDialog::slot_popupMatch(void)
231 {
232 connection->sendMatchInvite(popup_playerlisting);
233 }
234
235 void FriendsListDialog::slot_popupTalk(void)
236 {
237 Talk * talk = room->getTalk(popup_playerlisting);
238 if(talk)
239 talk->updatePlayerListing();
240 }
241
242 /* See the room code this was copied from. Its weird how we do all this... */
243 void FriendsListDialog::slot_playersDoubleClickedFriends(const QModelIndex & index)
244 {
245 PlayerListing * opponent = friendsListModel->playerListingFromIndex(index);
246 Talk * talk = room->getTalk(opponent);
247 if(talk)
248 talk->updatePlayerListing();
249 }
250
251 void FriendsListDialog::slot_playersDoubleClickedWatches(const QModelIndex & index)
252 {
253 PlayerListing * opponent = watchesListModel->playerListingFromIndex(index);
254 Talk * talk = room->getTalk(opponent);
255 if(talk)
256 talk->updatePlayerListing();
257 }