22 #include <QHeaderView>
23 #include <kmessagebox.h>
24 #include <interfaces/torrentinterface.h>
25 #include <interfaces/webseedinterface.h>
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);
46 proxy_model->setSourceModel(model);
47 proxy_model->setSortRole(Qt::UserRole);
48 m_webseed_list->setModel(proxy_model);
49 m_webseed_list->setSortingEnabled(
true);
51 connect(m_webseed_list->selectionModel(),SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
52 this,SLOT(selectionChanged(QItemSelection,QItemSelection)));
54 connect(m_webseed,SIGNAL(textChanged(QString)),
this,SLOT(onWebSeedTextChanged(QString)));
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());
74 selectionChanged(m_webseed_list->selectionModel()->selectedRows());
77 void WebSeedsTab::addWebSeed()
82 KUrl url(m_webseed->text());
83 if (curr_tc != 0 && url.isValid() && url.protocol() ==
"http")
85 if (curr_tc->addWebSeed(url))
92 KMessageBox::error(
this,i18n(
"Cannot add the webseed %1, it is already part of the list of webseeds.", url.prettyUrl()));
97 void WebSeedsTab::removeWebSeed()
102 QModelIndexList idx_list = m_webseed_list->selectionModel()->selectedRows();
103 foreach (
const QModelIndex &idx, idx_list)
105 const WebSeedInterface* ws = curr_tc->getWebSeed(proxy_model->mapToSource(idx).row());
106 if (ws && ws->isUserCreated())
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()));
116 void WebSeedsTab::selectionChanged(
const QModelIndexList & indexes)
118 foreach (
const QModelIndex &idx, indexes)
120 const WebSeedInterface* ws = curr_tc->getWebSeed(proxy_model->mapToSource(idx).row());
121 if (ws && ws->isUserCreated())
123 m_remove->setEnabled(
true);
128 m_remove->setEnabled(
false);
131 void WebSeedsTab::selectionChanged(
const QItemSelection & selected,
const QItemSelection & deselected)
137 selectionChanged(selected.indexes());
140 void WebSeedsTab::onWebSeedTextChanged(const QString & ws)
143 m_add->setEnabled(curr_tc != 0 && url.isValid() && url.protocol() ==
"http");
149 proxy_model->invalidate();
154 KConfigGroup g = cfg->group(
"WebSeedsTab");
155 QByteArray s = m_webseed_list->header()->saveState();
156 g.writeEntry(
"state",s.toBase64());
161 KConfigGroup g = cfg->group(
"WebSeedsTab");
162 QByteArray s = QByteArray::fromBase64(g.readEntry(
"state",QByteArray()));
164 m_webseed_list->header()->restoreState(s);
void changeTC(bt::TorrentInterface *tc)
Switch to a different torrent.
WebSeedsTab(QWidget *parent)
bool update()
See if we need to update the model.
void saveState(KSharedConfigPtr cfg)
void changeTC(bt::TorrentInterface *tc)
Change the current torrent.
void loadState(KSharedConfigPtr cfg)
void update()
Check to see if the GUI needs to be updated.