Commit 754b4a50 authored by Joris Guisson's avatar Joris Guisson
Browse files

Backport rev 1014515 (bandwidth scheduler fixes)

svn path=/branches/stable/extragear-kde4/network/ktorrent/; revision=1026884
parent f7b08dd6
......@@ -2,6 +2,7 @@ Changes in 3.2.4 :
- Improve flexibility of IP blocklist parsing to support more formats
- Fix bug in TorrentFileListModel causing wrong checkstate to be shown
- Fix very rare crash caused by 0 pointer (206689)
- Fix bug causing scheduler to not restart the schedule timer
Changes in 3.2.3 :
- Make sure View gets focus back when you are finished editing the name of a torrent
......
......@@ -79,13 +79,14 @@ namespace kt
ScheduleItem* item = new ScheduleItem();
item->day = day;
item->start = m_from->time();
item->end = m_to->time().addSecs(59 - m_to->time().second());
item->end = m_to->time();
item->upload_limit = m_upload_limit->value();
item->download_limit = m_download_limit->value();
item->paused = m_paused->isChecked();
item->global_conn_limit = m_max_conn_global->value();
item->torrent_conn_limit = m_max_conn_per_torrent->value();
item->set_conn_limits = m_set_connection_limits->isChecked();
item->checkTimes();
if (!schedule->addItem(item))
{
failures++;
......
......@@ -212,8 +212,15 @@ namespace kt
}
}
restartTimer();
}
void BWSchedulerPlugin::restartTimer()
{
QDateTime now = QDateTime::currentDateTime();
// now calculate the new interval
int wait_time = m_schedule->getTimeToNextScheduleEvent(now) * 1000;
Out(SYS_SCD|LOG_NOTICE) << "Timer will fire in " << wait_time << " ms" << endl;
if (wait_time < 1000)
wait_time = 1000;
m_timer.stop();
......
......@@ -59,6 +59,9 @@ namespace kt
void onToggled(bool on);
void colorsChanged();
private:
void restartTimer();
private:
QTimer m_timer;
KAction* m_bws_action;
......
......@@ -76,9 +76,7 @@ namespace kt
if (exec() == QDialog::Accepted)
{
item->start = m_from->time();
item->start = item->start.addSecs(-item->start.second()); // seconds must be 0
item->end = m_to->time();
item->end = item->end.addSecs(59 - item->end.second()); // seconds must be 59
item->day = m_day->currentIndex() + 1;
item->upload_limit = m_upload_limit->value();
item->download_limit = m_download_limit->value();
......@@ -86,6 +84,7 @@ namespace kt
item->global_conn_limit = m_max_conn_global->value();
item->torrent_conn_limit = m_max_conn_per_torrent->value();
item->set_conn_limits = m_set_connection_limits->isChecked();
item->checkTimes();
return true;
}
return false;
......
......@@ -90,6 +90,12 @@ namespace kt
torrent_conn_limit == item.torrent_conn_limit;
}
void ScheduleItem::checkTimes()
{
start.setHMS(start.hour(),start.minute(),0);
end.setHMS(end.hour(),end.minute(),59);
}
/////////////////////////////////////////
......@@ -184,6 +190,7 @@ namespace kt
item->set_conn_limits = true;
}
}
item->checkTimes();
return true;
}
......@@ -256,7 +263,7 @@ namespace kt
ScheduleItem* item = getCurrentItem(now);
// when we are in the middle of a ScheduleItem, we need to trigger again at the end of it
if (item)
return now.time().secsTo(item->end) + 1; // change the schedule one second after it expires
return now.time().secsTo(item->end) + 5; // change the schedule 5 seconds after it expires
// lets look at all schedule items on the same day
// and find the next one
......@@ -271,10 +278,10 @@ namespace kt
}
if (item)
return now.time().secsTo(item->start);
return now.time().secsTo(item->start) + 5;
QTime end_of_day(23,59,59);
return now.time().secsTo(end_of_day) + 1;
return now.time().secsTo(end_of_day) + 5;
}
bool Schedule::modify(ScheduleItem* item,const QTime & start,const QTime & end,int day)
......@@ -286,6 +293,7 @@ namespace kt
item->start = start;
item->end = end;
item->day = day;
item->checkTimes();
if (conflicts(item))
{
// restore old start and end time
......
......@@ -72,6 +72,9 @@ namespace kt
/// Whether or not a QDateTime is falls within this item
bool contains(const QDateTime & dt) const;
/// Check if start and end time are OK
void checkTimes();
};
/**
......
......@@ -220,8 +220,6 @@ namespace kt
QTime start = yToTime(np.y());
int d = item->start.secsTo(item->end); // duration in seconds
QTime end = start.addSecs(d);
end = end.addSecs(59 - end.second()); // make sure end seconds is 59
itemMoved(item,start,end,1 + floor((np.x() + day_width * 0.5 - xoff) / day_width));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment