</method>
<signal name="alert">
- <arg type="(ssbuuuuuuut)" name="info" direction="out"/>
+ <arg type="(ssuuuuuuuut)" name="info" direction="out"/>
<annotation name="com.trolltech.QtDBus.QtTypeName.In0"
value="qtrapids::TorrentState"/>
<arg type="a{ss}" name="other_info" direction="out"/>
void DownloadView::updateItem(TorrentState const& info, ParamsMap_t other_info)
{
DownloadItems_t::iterator p = items_.find(info.hash);
- if (p != items_.end()) {
- if (info.is_new) {
- qWarning() << "item with similar info hash marked as new";
- }
- updateItem_(p.value(), info, other_info);
- } else {
- if (!info.is_new) {
- qDebug() << "torrent info arrived but there is no torrent for it";
- return;
- }
- addItem_(info, other_info);
+ switch (info.action) {
+ case TorrentState::action_add :
+ if (p == items_.end()) {
+ addItem_(info, other_info);
+ } else {
+ qWarning() << "item with similar info hash marked as added";
+ updateItem_(p.value(), info, other_info);
+ }
+ break;
+ case TorrentState::action_update :
+ if (p != items_.end()) {
+ updateItem_(p.value(), info, other_info);
+ } else {
+ qWarning() << "item does not exist in list but information update arrived";
+ }
+ break;
+ case TorrentState::action_remove :
+ if (p != items_.end()) {
+ removeItem_(p.value(), info);
+ } else {
+ qWarning() << "item removal request arrived but there is no such item";
+ }
+ break;
+ default:
+ qWarning() << "unknown action requested: " << info.action;
+ break;
+ }
+ }
+
+ void DownloadView::removeItem_(DownloadViewItem *item, TorrentState const& info)
+ {
+ QString hash = item->getHash();
+
+ int removed = items_.remove(hash);
+ if (!removed)
+ qDebug() << "Inconsistent download view state on item removal";
+
+ int index = indexOfTopLevelItem(item);
+ if (index >= 0) {
+ takeTopLevelItem(index);
}
}
}
- QString DownloadView::removeSelected()
+ QString DownloadView::prepareRemoveSelected()
{
qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ;
DownloadViewItem *item = dynamic_cast<DownloadViewItem*> (currentItem());
QString hash = item->getHash();
- int removed = items_.remove(hash);
- if (!removed)
- qDebug() << "Inconsistent download view state on item removal";
-
- int index = indexOfTopLevelItem(currentItem());
- if (index >= 0) {
- takeTopLevelItem(index);
- }
+ item->setDisabled(true);
qDebug() << "DownloadView::removeSelected() " << topLevelItemCount() ;
~DownloadView();
void updateItem(TorrentState const& info, ParamsMap_t other_info);
- QString removeSelected();
+ QString prepareRemoveSelected();
private slots:
void on_itemClicked(QTreeWidgetItem * item, int column);
void addItem_(TorrentState const& info, ParamsMap_t other_info);
void updateItem_(DownloadViewItem *item
, TorrentState const& info, ParamsMap_t other_info);
+ void removeItem_(DownloadViewItem *item, TorrentState const& info);
// Maps torrent to downloadview item.
// Key: SHA1 info hash of torrent. Data: View item corresponding to torrent.
void MainWindow::on_removeAction_clicked()
{
- QString hash = dlView_->removeSelected();
+ QString hash = dlView_->prepareRemoveSelected();
try {
server_.removeTorrent(hash);
} catch (...) {
struct TorrentState
{
+
+ enum torrent_action
+ {
+ action_add,
+ action_remove,
+ action_update
+ };
+
TorrentState()
: hash("")
, name("")
, leeches(0)
, ratio(0)
, total_size(0)
- { }
+ { }
QString hash;
QString name;
- bool is_new;
+ torrent_action action;
uint state;
uint progress;
uint down_rate;
{
std::cout << "serialize" << std::endl;
argument.beginStructure();
- argument << state.hash << state.name << state.is_new << state.state << state.progress
+ argument << state.hash << state.name << (uint)(state.action) << state.state << state.progress
<< state.down_rate << state.up_rate << state.seeds
<< state.leeches << state.ratio << state.total_size;
argument.endStructure();
{
std::cout << "deserialize" << std::endl;
argument.beginStructure();
- argument >> state.hash >> state.name >> state.is_new >> state.state >> state.progress
+ uint action;
+ argument >> state.hash >> state.name >> action >> state.state >> state.progress
>> state.down_rate >> state.up_rate >> state.seeds
>> state.leeches >> state.ratio >> state.total_size;
+ state.action = (TorrentState::torrent_action)action;
argument.endStructure();
return argument;
}
--- /dev/null
+#include <QSettings>
+#include <QString>
+#include <QVariant>
+
+namespace qtrapids
+{
+ static inline QVariant GetSettingsStoreDefault(QSettings &settings
+ , QString const& name
+ , QVariant const& default_value)
+ {
+ QVariant v(settings.value(name));
+ if (!v.isNull()) {
+ return v;
+ }
+
+ settings.setValue(name, default_value);
+ return default_value;
+ }
+
+}
TorrentState state;
state.hash = Hash2QStr(handle.hash());
- state.is_new = false;
+ state.action = TorrentState::action_update;
state.state = handle.state();
state.progress = handle.progress() * torrent_progress_max;
state.down_rate = handle.downloadRate();
state.hash = hash;
state.name = handle->name();
- state.is_new = true;
+ state.action = TorrentState::action_add;
state.state = handle->state();
state.progress = handle->progress() * torrent_progress_max;
state.down_rate = handle->downloadRate();
state.hash = hash;
state.name = handle->name();
- state.is_new = true;
+ state.action = TorrentState::action_add;
state.state = handle->state();
state.progress = handle->progress() * torrent_progress_max;
state.down_rate = handle->downloadRate();
void TorrentSession::removeTorrent(const QString &hash)
{
torrents_t::iterator p = torrents_.find(hash);
+
if (p == torrents_.end()) {
qDebug() << "Invalid request to remove torrent with hash " << hash;
return;
"exception catched"
;
}
+
+ TorrentState state;
+ state.hash = hash;
+ state.action = TorrentState::action_remove;
+ emit alert(state, ParamsMap_t());
+ torrents_.erase(p);
}