23 #include <QHeaderView>
27 #include <kmessagebox.h>
29 #include <kinputdialog.h>
30 #include <torrent/globals.h>
31 #include <interfaces/trackerinterface.h>
32 #include <interfaces/torrentinterface.h>
33 #include <interfaces/trackerslist.h>
50 proxy_model->setSortRole(Qt::UserRole);
51 proxy_model->setSourceModel(model);
52 m_tracker_list->setModel(proxy_model);
53 m_tracker_list->setAllColumnsShowFocus(
true);
54 m_tracker_list->setRootIsDecorated(
false);
55 m_tracker_list->setAlternatingRowColors(
true);
56 m_tracker_list->setSortingEnabled(
true);
57 connect(m_add_tracker,SIGNAL(clicked()),
this,SLOT(
addClicked()));
58 connect(m_remove_tracker,SIGNAL(clicked()),
this,SLOT(
removeClicked()));
59 connect(m_change_tracker,SIGNAL(clicked()),
this,SLOT(
changeClicked()));
60 connect(m_restore_defaults,SIGNAL(clicked()),
this,SLOT(
restoreClicked()));
61 connect(m_tracker_list->selectionModel(),SIGNAL(
currentChanged(QModelIndex,QModelIndex)),
63 connect(m_scrape,SIGNAL(clicked()),
this,SLOT(
scrapeClicked()));
65 m_add_tracker->setIcon(KIcon(
"list-add"));
66 m_remove_tracker->setIcon(KIcon(
"list-remove"));
67 m_restore_defaults->setIcon(KIcon(
"kt-restore-defaults"));
68 m_change_tracker->setIcon(KIcon(
"kt-change-tracker"));
84 QClipboard* clipboard = QApplication::clipboard();
85 QString text = KInputDialog::getText(
86 i18n(
"Add Tracker"),i18n(
"Enter the URL of the tracker:"),clipboard->text(),&ok,
this);
94 KMessageBox::error(0, i18n(
"Malformed URL."));
99 if (!tc->getTrackersList()->addTracker(url,
true))
101 KMessageBox::sorry(0,i18n(
"There already is a tracker named <b>%1</b>.",text));
105 model->insertRow(model->
rowCount(QModelIndex()));
111 QModelIndex current = proxy_model->mapToSource(m_tracker_list->selectionModel()->currentIndex());
112 if (!current.isValid())
115 model->removeRow(current.row());
120 QModelIndex current = m_tracker_list->selectionModel()->currentIndex();
121 if (!current.isValid())
124 bt::TrackersList* tlist = tc->getTrackersList();
125 bt::TrackerInterface* trk = model->
tracker(proxy_model->mapToSource(current));
126 if (trk && trk->isEnabled())
127 tlist->setCurrentTracker(trk);
132 tc->getTrackersList()->restoreDefault();
169 void TrackerView::torrentChanged(TorrentInterface* ti)
174 m_add_tracker->setEnabled(
false);
175 m_remove_tracker->setEnabled(
false);
176 m_restore_defaults->setEnabled(
false);
177 m_change_tracker->setEnabled(
false);
178 m_scrape->setEnabled(
false);
183 m_add_tracker->setEnabled(
true);
184 m_remove_tracker->setEnabled(
true);
185 m_restore_defaults->setEnabled(
true);
186 m_scrape->setEnabled(
true);
188 currentChanged(m_tracker_list->selectionModel()->currentIndex(),QModelIndex());
197 m_change_tracker->setEnabled(
false);
198 m_remove_tracker->setEnabled(
false);
202 const TorrentStats & s = tc->getStats();
204 bt::TrackerInterface* trk = model->
tracker(proxy_model->mapToSource(current));
205 bool enabled = trk ? trk->isEnabled() :
false;
206 m_change_tracker->setEnabled(s.running && model->
rowCount(QModelIndex()) > 1 && enabled);
207 m_remove_tracker->setEnabled(trk && tc->getTrackersList()->canRemoveTracker(trk));
212 KConfigGroup g = cfg->group(
"TrackerView");
213 QByteArray s = m_tracker_list->header()->saveState();
214 g.writeEntry(
"state",s.toBase64());
219 KConfigGroup g = cfg->group(
"TrackerView");
220 QByteArray s = QByteArray::fromBase64(g.readEntry(
"state",QByteArray()));
223 QHeaderView* v = m_tracker_list->header();
230 #include "trackerview.moc"
virtual void scrapeClicked()
virtual void updateClicked()
virtual void restoreClicked()
void loadState(KSharedConfigPtr cfg)
virtual void removeClicked()
virtual void addClicked()
virtual int rowCount(const QModelIndex &parent) const
bt::TrackerInterface * tracker(const QModelIndex &idx)
Get a tracker given a model index.
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
virtual void changeClicked()
void saveState(KSharedConfigPtr cfg)
void changeTC(bt::TorrentInterface *tc)
void changeTC(bt::TorrentInterface *ti)