• 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
webseedstab.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2008 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 "webseedstab.h"
22 #include <QHeaderView>
23 #include <kmessagebox.h>
24 #include <interfaces/torrentinterface.h>
25 #include <interfaces/webseedinterface.h>
26 #include "webseedsmodel.h"
27 
28 using namespace bt;
29 
30 namespace kt
31 {
32 
33  WebSeedsTab::WebSeedsTab(QWidget* parent)
34  : QWidget(parent),curr_tc(0)
35  {
36  setupUi(this);
37  connect(m_add,SIGNAL(clicked()),this,SLOT(addWebSeed()));
38  connect(m_remove,SIGNAL(clicked()),this,SLOT(removeWebSeed()));
39  m_add->setIcon(KIcon("list-add"));
40  m_remove->setIcon(KIcon("list-remove"));
41  m_add->setEnabled(false);
42  m_remove->setEnabled(false);
43  m_webseed_list->setEnabled(false);
44  model = new WebSeedsModel(this);
45  proxy_model = new QSortFilterProxyModel(this);
46  proxy_model->setSourceModel(model);
47  proxy_model->setSortRole(Qt::UserRole);
48  m_webseed_list->setModel(proxy_model);
49  m_webseed_list->setSortingEnabled(true);
50 
51  connect(m_webseed_list->selectionModel(),SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
52  this,SLOT(selectionChanged(QItemSelection,QItemSelection)));
53 
54  connect(m_webseed,SIGNAL(textChanged(QString)),this,SLOT(onWebSeedTextChanged(QString)));
55  }
56 
57 
58  WebSeedsTab::~WebSeedsTab()
59  {
60  }
61 
62  void WebSeedsTab::changeTC(bt::TorrentInterface* tc)
63  {
64  curr_tc = tc;
65  model->changeTC(tc);
66  m_add->setEnabled(curr_tc != 0);
67  m_remove->setEnabled(curr_tc != 0);
68  m_webseed_list->setEnabled(curr_tc != 0);
69  m_webseed->setEnabled(curr_tc != 0);
70  onWebSeedTextChanged(m_webseed->text());
71 
72  // see if we need to enable or disable the remove button
73  if (curr_tc)
74  selectionChanged(m_webseed_list->selectionModel()->selectedRows());
75  }
76 
77  void WebSeedsTab::addWebSeed()
78  {
79  if (!curr_tc)
80  return;
81 
82  KUrl url(m_webseed->text());
83  if (curr_tc != 0 && url.isValid() && url.protocol() == "http")
84  {
85  if (curr_tc->addWebSeed(url))
86  {
87  model->changeTC(curr_tc);
88  m_webseed->clear();
89  }
90  else
91  {
92  KMessageBox::error(this,i18n("Cannot add the webseed %1, it is already part of the list of webseeds.", url.prettyUrl()));
93  }
94  }
95  }
96 
97  void WebSeedsTab::removeWebSeed()
98  {
99  if (!curr_tc)
100  return;
101 
102  QModelIndexList idx_list = m_webseed_list->selectionModel()->selectedRows();
103  foreach (const QModelIndex &idx, idx_list)
104  {
105  const WebSeedInterface* ws = curr_tc->getWebSeed(proxy_model->mapToSource(idx).row());
106  if (ws && ws->isUserCreated())
107  {
108  if (!curr_tc->removeWebSeed(ws->getUrl()))
109  KMessageBox::error(this,i18n("Cannot remove webseed %1, it is part of the torrent.", ws->getUrl().prettyUrl()));
110  }
111  }
112 
113  model->changeTC(curr_tc);
114  }
115 
116  void WebSeedsTab::selectionChanged(const QModelIndexList & indexes)
117  {
118  foreach (const QModelIndex &idx, indexes)
119  {
120  const WebSeedInterface* ws = curr_tc->getWebSeed(proxy_model->mapToSource(idx).row());
121  if (ws && ws->isUserCreated())
122  {
123  m_remove->setEnabled(true);
124  return;
125  }
126  }
127 
128  m_remove->setEnabled(false);
129  }
130 
131  void WebSeedsTab::selectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
132  {
133  Q_UNUSED(deselected)
134  if (!curr_tc)
135  return;
136 
137  selectionChanged(selected.indexes());
138  }
139 
140  void WebSeedsTab::onWebSeedTextChanged(const QString & ws)
141  {
142  KUrl url(ws);
143  m_add->setEnabled(curr_tc != 0 && url.isValid() && url.protocol() == "http");
144  }
145 
146  void WebSeedsTab::update()
147  {
148  if (model->update())
149  proxy_model->invalidate();
150  }
151 
152  void WebSeedsTab::saveState(KSharedConfigPtr cfg)
153  {
154  KConfigGroup g = cfg->group("WebSeedsTab");
155  QByteArray s = m_webseed_list->header()->saveState();
156  g.writeEntry("state",s.toBase64());
157  }
158 
159  void WebSeedsTab::loadState(KSharedConfigPtr cfg)
160  {
161  KConfigGroup g = cfg->group("WebSeedsTab");
162  QByteArray s = QByteArray::fromBase64(g.readEntry("state",QByteArray()));
163  if (!s.isNull())
164  m_webseed_list->header()->restoreState(s);
165  }
166 }
kt::WebSeedsTab::~WebSeedsTab
virtual ~WebSeedsTab()
Definition: webseedstab.cpp:58
kt::WebSeedsTab::changeTC
void changeTC(bt::TorrentInterface *tc)
Switch to a different torrent.
Definition: webseedstab.cpp:62
QWidget
kt::WebSeedsModel
Definition: webseedsmodel.h:38
kt::WebSeedsTab::WebSeedsTab
WebSeedsTab(QWidget *parent)
Definition: webseedstab.cpp:33
kt::WebSeedsModel::update
bool update()
See if we need to update the model.
Definition: webseedsmodel.cpp:61
kt::WebSeedsTab::saveState
void saveState(KSharedConfigPtr cfg)
Definition: webseedstab.cpp:152
webseedsmodel.h
webseedstab.h
kt::WebSeedsModel::changeTC
void changeTC(bt::TorrentInterface *tc)
Change the current torrent.
Definition: webseedsmodel.cpp:42
QSortFilterProxyModel
kt::WebSeedsTab::loadState
void loadState(KSharedConfigPtr cfg)
Definition: webseedstab.cpp:159
kt::WebSeedsTab::update
void update()
Check to see if the GUI needs to be updated.
Definition: webseedstab.cpp:146
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:18 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