• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kget

  • sources
  • kde-4.12
  • kdenetwork
  • kget
  • transfer-plugins
  • bittorrent
  • advanceddetails
peerview.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2007 by Joris Guisson and Ivan Vasic *
3  * joris.guisson@gmail.com *
4  * ivasic@gmail.com *
5  * *
6  * This program 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, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20  ***************************************************************************/
21 #include "peerview.h"
22 
23 #include <QHeaderView>
24 #include <klocale.h>
25 #include <kicon.h>
26 #include <kmenu.h>
27 #include <kstandarddirs.h>
28 #include <kconfiggroup.h>
29 #include <interfaces/peerinterface.h>
30 #include <peer/accessmanager.h>
31 #include <util/functions.h>
32 #include "peerviewmodel.h"
33 
34 using namespace bt;
35 
36 namespace kt
37 {
38 
39 
40  PeerView::PeerView(QWidget* parent) : QTreeView(parent)
41  {
42  setContextMenuPolicy(Qt::CustomContextMenu);
43  setRootIsDecorated(false);
44  setSortingEnabled(true);
45  setAlternatingRowColors(true);
46  setUniformRowHeights(true);
47 
48  model = new PeerViewModel(this);
49  setModel(model);
50 
51  context_menu = new KMenu(this);
52  context_menu->addAction(KIcon("list-remove-user"),i18n("Kick Peer"),this,SLOT(kickPeer()));
53  context_menu->addAction(KIcon("view-filter"),i18n("Ban Peer"),this,SLOT(banPeer()));
54  connect(this,SIGNAL(customContextMenuRequested(QPoint)),
55  this,SLOT(showContextMenu(QPoint)));
56  }
57 
58  PeerView::~PeerView()
59  {
60  }
61 
62  void PeerView::showContextMenu(const QPoint& pos)
63  {
64  if (selectionModel()->selectedRows().count() == 0)
65  return;
66 
67  context_menu->popup(mapToGlobal(pos));
68  }
69 
70  void PeerView::banPeer()
71  {
72  AccessManager & aman = AccessManager::instance();
73 
74  QModelIndexList indices = selectionModel()->selectedRows();
75  foreach (const QModelIndex &idx,indices)
76  {
77  bt::PeerInterface* peer = model->indexToPeer(idx);
78  if (peer)
79  {
80  aman.banPeer(peer->getStats().ip_address);
81  peer->kill();
82  }
83  }
84  }
85 
86  void PeerView::kickPeer()
87  {
88  QModelIndexList indices = selectionModel()->selectedRows();
89  foreach (const QModelIndex &idx,indices)
90  {
91  bt::PeerInterface* peer = model->indexToPeer(idx);
92  if (peer)
93  peer->kill();
94  }
95  }
96 
97  void PeerView::peerAdded(PeerInterface* peer)
98  {
99  model->peerAdded(peer);
100  }
101 
102  void PeerView::peerRemoved(PeerInterface* peer)
103  {
104  model->peerRemoved(peer);
105  }
106 
107  void PeerView::update()
108  {
109  model->update();
110  }
111 
112  void PeerView::removeAll()
113  {
114  model->clear();
115  }
116 
117  void PeerView::saveState(KSharedConfigPtr cfg)
118  {
119  KConfigGroup g = cfg->group("PeerView");
120  QByteArray s = header()->saveState();
121  g.writeEntry("state",s.toBase64());
122  }
123 
124  void PeerView::loadState(KSharedConfigPtr cfg)
125  {
126  KConfigGroup g = cfg->group("PeerView");
127  QByteArray s = QByteArray::fromBase64(g.readEntry("state",QByteArray()));
128  if (!s.isNull())
129  {
130  QHeaderView* v = header();
131  v->restoreState(s);
132  sortByColumn(v->sortIndicatorSection(),v->sortIndicatorOrder());
133  model->sort(v->sortIndicatorSection(),v->sortIndicatorOrder());
134  }
135  }
136 }
137 
138 #include "peerview.moc"
kt::PeerViewModel::sort
void sort(int col, Qt::SortOrder order)
Definition: peerviewmodel.cpp:405
kt::PeerViewModel::clear
void clear()
Definition: peerviewmodel.cpp:248
QWidget
kt::PeerView::removeAll
void removeAll()
Remove all items.
Definition: peerview.cpp:112
kt::PeerViewModel::peerRemoved
void peerRemoved(bt::PeerInterface *peer)
A peer has been removed.
Definition: peerviewmodel.cpp:231
kt::PeerView::~PeerView
virtual ~PeerView()
Definition: peerview.cpp:58
kt::PeerView::saveState
void saveState(KSharedConfigPtr cfg)
Definition: peerview.cpp:117
QTreeView
kt::PeerView::peerRemoved
void peerRemoved(bt::PeerInterface *peer)
A peer has been removed.
Definition: peerview.cpp:102
kt::PeerViewModel
Definition: peerviewmodel.h:36
kt::PeerView::update
void update()
Check to see if the GUI needs to be updated.
Definition: peerview.cpp:107
kt::PeerViewModel::peerAdded
void peerAdded(bt::PeerInterface *peer)
A peer has been added.
Definition: peerviewmodel.cpp:224
peerviewmodel.h
kt::PeerViewModel::update
void update()
Update the model.
Definition: peerviewmodel.cpp:255
kt::PeerView::loadState
void loadState(KSharedConfigPtr cfg)
Definition: peerview.cpp:124
peerview.h
kt::PeerView::peerAdded
void peerAdded(bt::PeerInterface *peer)
A peer has been added.
Definition: peerview.cpp:97
kt::PeerViewModel::indexToPeer
bt::PeerInterface * indexToPeer(const QModelIndex &idx)
Definition: peerviewmodel.cpp:379
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:17 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kget

Skip menu "kget"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal