From 9ad5c7b5e23b4940e7a3ea3ca3a6fb77e6a8fab0 Mon Sep 17 00:00:00 2001 From: tpearson Date: Wed, 20 Jan 2010 02:37:40 +0000 Subject: Updated to final KDE3 ktorrent release (2.2.6) git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/ktorrent@1077377 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- plugins/scheduler/Makefile.am | 36 + plugins/scheduler/bwscheduler.cpp | 282 ++++++++ plugins/scheduler/bwscheduler.h | 173 +++++ plugins/scheduler/bwspage.ui | 877 ++++++++++++++++++++++++ plugins/scheduler/bwsprefpage.cpp | 0 plugins/scheduler/bwsprefpage.h | 0 plugins/scheduler/bwsprefpagewidget.cpp | 291 ++++++++ plugins/scheduler/bwsprefpagewidget.h | 84 +++ plugins/scheduler/bwswidget.cpp | 334 +++++++++ plugins/scheduler/bwswidget.h | 107 +++ plugins/scheduler/cell-a-0000.png | Bin 0 -> 700 bytes plugins/scheduler/cell-a-0001.png | Bin 0 -> 1003 bytes plugins/scheduler/cell-a-0002.png | Bin 0 -> 1102 bytes plugins/scheduler/cell-a-0003.png | Bin 0 -> 1174 bytes plugins/scheduler/cell-a-0004.png | Bin 0 -> 744 bytes plugins/scheduler/cell-b-0000.png | Bin 0 -> 672 bytes plugins/scheduler/cell-b-0001.png | Bin 0 -> 979 bytes plugins/scheduler/cell-b-0002.png | Bin 0 -> 1063 bytes plugins/scheduler/cell-b-0003.png | Bin 0 -> 1119 bytes plugins/scheduler/cell-b-0004.png | Bin 0 -> 728 bytes plugins/scheduler/ktschedulerplugin.desktop | 26 + plugins/scheduler/ktschedulerplugin.kcfg | 18 + plugins/scheduler/ktschedulerpluginui.rc | 12 + plugins/scheduler/schedulerpage.ui | 146 ++++ plugins/scheduler/schedulerplugin.cpp | 152 ++++ plugins/scheduler/schedulerplugin.h | 70 ++ plugins/scheduler/schedulerpluginsettings.kcfgc | 7 + plugins/scheduler/schedulerprefpage.cpp | 64 ++ plugins/scheduler/schedulerprefpage.h | 53 ++ plugins/scheduler/schedulerprefpagewidget.cpp | 83 +++ plugins/scheduler/schedulerprefpagewidget.h | 50 ++ 31 files changed, 2865 insertions(+) create mode 100644 plugins/scheduler/Makefile.am create mode 100644 plugins/scheduler/bwscheduler.cpp create mode 100644 plugins/scheduler/bwscheduler.h create mode 100644 plugins/scheduler/bwspage.ui create mode 100644 plugins/scheduler/bwsprefpage.cpp create mode 100644 plugins/scheduler/bwsprefpage.h create mode 100644 plugins/scheduler/bwsprefpagewidget.cpp create mode 100644 plugins/scheduler/bwsprefpagewidget.h create mode 100644 plugins/scheduler/bwswidget.cpp create mode 100644 plugins/scheduler/bwswidget.h create mode 100644 plugins/scheduler/cell-a-0000.png create mode 100644 plugins/scheduler/cell-a-0001.png create mode 100644 plugins/scheduler/cell-a-0002.png create mode 100644 plugins/scheduler/cell-a-0003.png create mode 100644 plugins/scheduler/cell-a-0004.png create mode 100644 plugins/scheduler/cell-b-0000.png create mode 100644 plugins/scheduler/cell-b-0001.png create mode 100644 plugins/scheduler/cell-b-0002.png create mode 100644 plugins/scheduler/cell-b-0003.png create mode 100644 plugins/scheduler/cell-b-0004.png create mode 100644 plugins/scheduler/ktschedulerplugin.desktop create mode 100644 plugins/scheduler/ktschedulerplugin.kcfg create mode 100644 plugins/scheduler/ktschedulerpluginui.rc create mode 100644 plugins/scheduler/schedulerpage.ui create mode 100644 plugins/scheduler/schedulerplugin.cpp create mode 100644 plugins/scheduler/schedulerplugin.h create mode 100644 plugins/scheduler/schedulerpluginsettings.kcfgc create mode 100644 plugins/scheduler/schedulerprefpage.cpp create mode 100644 plugins/scheduler/schedulerprefpage.h create mode 100644 plugins/scheduler/schedulerprefpagewidget.cpp create mode 100644 plugins/scheduler/schedulerprefpagewidget.h (limited to 'plugins/scheduler') diff --git a/plugins/scheduler/Makefile.am b/plugins/scheduler/Makefile.am new file mode 100644 index 0000000..b2c9760 --- /dev/null +++ b/plugins/scheduler/Makefile.am @@ -0,0 +1,36 @@ +INCLUDES = -I$(srcdir)/../../libktorrent $(all_includes) +METASOURCES = AUTO +kde_module_LTLIBRARIES = ktschedulerplugin.la +noinst_HEADERS = schedulerplugin.h bwscheduler.h schedulerprefpagewidget.h \ + bwsprefpagewidget.h bwswidget.h schedulerprefpage.h +ktschedulerplugin_la_SOURCES = schedulerplugin.cpp \ + schedulerpluginsettings.kcfgc bwscheduler.cpp schedulerprefpagewidget.cpp schedulerpage.ui bwspage.ui \ + bwsprefpagewidget.cpp bwswidget.cpp schedulerprefpage.cpp + +# Libs needed by the plugin +ktschedulerplugin_la_LIBADD = $(LIB_KHTML) $(LIB_KPARTS) \ + ../../libktorrent/libktorrent.la \ + $(LIB_QT) $(LIB_KDECORE) $(LIB_KDEUI) $(LIB_KFILE) + +# LD flags for the plugin +# -module says: this is a module, i.e. something you're going to dlopen +# so e.g. it has no version number like a normal shared lib would have. +ktschedulerplugin_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) + +# rc file containing the GUI for the plugin +# pluginsdir = $(kde_datadir)/ktschedulerplugin +# plugins_DATA = ktschedulerpluginui.rc + +# Install the desktop file needed to detect the plugin +kde_services_DATA = ktschedulerplugin.desktop + +kde_kcfg_DATA = ktschedulerplugin.kcfg + +kticonsdir = $(kde_datadir)/ktorrent/icons + +kticons_DATA = cell-a-0000.png cell-a-0001.png cell-a-0002.png cell-a-0003.png\ + cell-a-0004.png cell-b-0000.png cell-b-0001.png cell-b-0002.png\ + cell-b-0003.png cell-b-0004.png +rcdir = $(kde_datadir)/ktorrent +rc_DATA = ktschedulerpluginui.rc +KDE_CXXFLAGS = $(USE_EXCEPTIONS) $(USE_RTTI) diff --git a/plugins/scheduler/bwscheduler.cpp b/plugins/scheduler/bwscheduler.cpp new file mode 100644 index 0000000..56375b5 --- /dev/null +++ b/plugins/scheduler/bwscheduler.cpp @@ -0,0 +1,282 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include "bwscheduler.h" +#include "schedulerpluginsettings.h" + +#include +#include + +#include +#include + +#include + +#include +#include + +#include +#include +#include + +#include +#include + +using namespace bt; + +namespace kt +{ + // ****** BWS *---------------------------------------------------------------------- + BWS::BWS() + { + m_schedule = new ScheduleCategory*[7]; + for(int i=0; i<7; ++i) + m_schedule[i] = new ScheduleCategory[24]; + + reset(); + } + + BWS& kt::BWS::operator=(const BWS& b) + { + for(int i=0; i<7; ++i) + for(int j=0; j<24; ++j) + m_schedule[i][j] = b.m_schedule[i][j]; + + for(int i=0; i<3; ++i) + { + download[i] = b.download[i]; + upload[i] = b.upload[i]; + } + + return *this; + } + + int BWS::getDownload(int cat) + { + return download[cat]; + } + + int BWS::getUpload(int cat) + { + return upload[cat]; + } + + void BWS::setDownload(int cat, int val) + { + download[cat] = val; + } + + void BWS::setUpload(int cat, int val) + { + upload[cat] = val; + } + + void BWS::setCategory(int day, int hour, ScheduleCategory val) + { + m_schedule[day][hour] = val; + } + + ScheduleCategory BWS::getCategory(int day, int hour) + { + return m_schedule[day][hour]; + } + + void BWS::reset() + { + for(int i=0; i<7; ++i) + for(int j=0; j<24; ++j) + m_schedule[i][j] = CAT_NORMAL; + + for(int i=0; i<3; ++i) + { + download[i] = 0; + upload[i] = 0; + } + } + + BWS::~BWS() + { + for(int i=0; i<7; ++i) + delete [] m_schedule[i]; + + delete [] m_schedule; + } + + void BWS::debug() + { + for(int i=0; i<7; ++i) + { + Log & lg = Out(); + for(int j=0; j<24; ++j) + lg << m_schedule[i][j]; + lg << endl; + } + } + + // ---- BWScheduler -------------------------------------------------------------------- + + BWScheduler::BWScheduler() + : m_core(0) + { + m_enabled = SchedulerPluginSettings::enableBWS(); + loadSchedule(); + } + + BWScheduler::~BWScheduler() + { + } + + void BWScheduler::setSchedule(const BWS& sch) + { + Out(SYS_SCD|LOG_NOTICE) << "BWS: Setting new schedule..." << endl; + m_schedule = sch; + saveSchedule(); + trigger(); + } + + void BWScheduler::setCoreInterface(CoreInterface* core) + { + m_core = core; + } + + void BWScheduler::trigger() + { + if(!m_enabled) + return; + + QDateTime now = QDateTime::currentDateTime(); + + QString prefix = QString("BWS: %1 :: ").arg(now.toString()); + + int t1 = now.date().dayOfWeek(); + int t2 = now.time().hour(); + ScheduleCategory sch = m_schedule.getCategory(t1-1, t2); + + switch(sch) + { + case CAT_NORMAL: + Out(SYS_SCD|LOG_NOTICE) << prefix << "Switching to NORMAL category" << endl; + Out(SYS_SCD|LOG_NOTICE) << prefix << QString("%1 Up, %2 Down") + .arg(m_core->getMaxUploadSpeed()).arg(m_core->getMaxDownloadSpeed()) << endl; + if(!m_core) + break; + m_core->setPausedState(false); + net::SocketMonitor::setDownloadCap(1024 * m_core->getMaxDownloadSpeed()); + net::SocketMonitor::setUploadCap(1024 * m_core->getMaxUploadSpeed()); + break; + case CAT_FIRST: + Out(SYS_SCD|LOG_NOTICE) << prefix << "Switching to FIRST category" << endl; + Out(SYS_SCD|LOG_NOTICE) << prefix << QString("%1 Up, %2 Down") + .arg(m_schedule.getUpload(0)).arg(m_schedule.getDownload(0)) << endl; + if(!m_core) + break; + m_core->setPausedState(false); + net::SocketMonitor::setDownloadCap(1024 * m_schedule.getDownload(0)); + net::SocketMonitor::setUploadCap(1024 * m_schedule.getUpload(0)); + break; + case CAT_SECOND: + Out(SYS_SCD|LOG_NOTICE) << prefix << "Switching to SECOND category" << endl; + Out(SYS_SCD|LOG_NOTICE) << prefix << QString("%1 Up, %2 Down") + .arg(m_schedule.getUpload(1)).arg(m_schedule.getDownload(1)) << endl; + if(!m_core) + break; + m_core->setPausedState(false); + net::SocketMonitor::setDownloadCap(1024 * m_schedule.getDownload(1)); + net::SocketMonitor::setUploadCap(1024 * m_schedule.getUpload(1)); + break; + case CAT_THIRD: + Out(SYS_SCD|LOG_NOTICE) << prefix << "Switching to THIRD category" << endl; + Out(SYS_SCD|LOG_NOTICE) << prefix << QString("%1 Up, %2 Down") + .arg(m_schedule.getUpload(2)).arg(m_schedule.getDownload(2)) << endl; + if(!m_core) + break; + m_core->setPausedState(false); + net::SocketMonitor::setDownloadCap(1024 * m_schedule.getDownload(2)); + net::SocketMonitor::setUploadCap(1024 * m_schedule.getUpload(2)); + break; + case CAT_OFF: + Out(SYS_SCD|LOG_NOTICE) << prefix << "Switching to OFF" << endl; + + if(!m_core) + break; + m_core->setPausedState(true); + break; + } + } + + void BWScheduler::loadSchedule() + { + QFile file(KGlobal::dirs()->saveLocation("data","ktorrent") + "bwschedule"); + + if(!file.exists()) + return; + + file.open(IO_ReadOnly); + QDataStream stream(&file); + + int tmp; + + //extract category values + for(int i=0; i<3; ++i) + { + stream >> tmp; + m_schedule.setDownload(i, tmp); + stream >> tmp; + m_schedule.setUpload(i, tmp); + } + + //extract schedule + for(int i=0; i<7; ++i) + { + for(int j=0; j<24; ++j) + { + stream >> tmp; + m_schedule.setCategory(i, j, (ScheduleCategory) tmp); + } + } + + file.close(); + } + + void BWScheduler::saveSchedule() + { + QFile file(KGlobal::dirs()->saveLocation("data","ktorrent") + "bwschedule"); + + file.open(IO_WriteOnly); + QDataStream stream(&file); + + for(int i=0; i<3; ++i) + { + stream << m_schedule.getDownload(i); + stream << m_schedule.getUpload(i); + } + + //Now schedule + for(int i=0; i<7; ++i) + for(int j=0; j<24; ++j) + stream << (int) m_schedule.getCategory(i, j); + + file.close(); + } + + void BWScheduler::setEnabled(bool theValue) + { + m_enabled = theValue; + } +} diff --git a/plugins/scheduler/bwscheduler.h b/plugins/scheduler/bwscheduler.h new file mode 100644 index 0000000..e752b1d --- /dev/null +++ b/plugins/scheduler/bwscheduler.h @@ -0,0 +1,173 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef KTBWSCHEDULER_H +#define KTBWSCHEDULER_H + +#include + +namespace kt +{ + + typedef enum bws_category + { + CAT_NORMAL, + CAT_FIRST, + CAT_SECOND, + CAT_THIRD, + CAT_OFF + }ScheduleCategory; + + /** + * @author Ivan Vasic + * @brief This class represents bandwidth schedule for the week. + * It simplifies usage of 2 dimensional schedule (array) and its transfer between classes. + */ + class BWS + { + ///Schedule + ScheduleCategory** m_schedule; + + ///Download categories + int download[3]; + ///Upload categories + int upload[3]; + + public: + BWS(); + BWS& operator=(const BWS& b); + ~BWS(); + + /** + * @brief Resets this schedule. + */ + void reset(); + + + /** + * Gets download rate for category cat. + * @param cat download category index + * @return Download rate in KB/s + */ + int getDownload(int cat); + + /** + * Gets upload rate for category cat. + * @param cat upload category index + * @return upload rate in KB/s + */ + int getUpload(int cat); + + + /** + * @brief Gets category for specified day and hour. + * @param day Number of day in a week. + * @param hour Hour of the day. + * @return ScheduleCategory - category associated with that day/hour. + */ + ScheduleCategory getCategory(int day, int hour); + + + /** + * @brief Sets download rate for a category. + * @param cat Category to set rate to. + * @param val Download rate to set to category in KB/s + */ + void setDownload(int cat, int val); + + /** + * @brief Sets upload rate for a category. + * @param cat Category to set rate to. + * @param val Upload rate to set to category in KB/s + */ + void setUpload(int cat, int val); + + + /** + * @brief Sets category for specified day/hour combination. + * @param day Day of the week. + * @param hour Hour of the day. + * @param val Category value. + */ + void setCategory(int day, int hour, ScheduleCategory val); + + ///Prints schedule to LogViewer. Used only for debugging. + void debug(); + }; + + + /** + * @brief Bandwidth scheduler class. + * @author Ivan Vasic + * Singleton class. Used to keep bandwidth schedule and change download/upload rate as necessary. + */ + class BWScheduler + { + public: + inline static BWScheduler& instance() + { + static BWScheduler self; + return self; + } + ~BWScheduler(); + + /** + * Triggers bandwidth limit changes (if needed). + */ + void trigger(); + + /** + * Sets a new schedule. + * @param sch - new BWS schedule. + * @note Call trigger() after setting new schedule for changes to take effect. + */ + void setSchedule(const BWS& sch); + + /** + * Sets a pointer to CoreInterface. + * Needed for getting global bandwidth limits. + * @param core Pointer to CoreInterface + */ + void setCoreInterface(CoreInterface* core); + + ///Pauses all torrents (TURN OFF category) + void pauseAll(); + + ///Loads schedule from HD + void loadSchedule(); + ///Saves schedule to HD + void saveSchedule(); + + void setEnabled(bool theValue); + + + protected: + BWScheduler(); + BWScheduler(const BWScheduler&); + BWScheduler& operator=(const BWScheduler&); + + BWS m_schedule; + CoreInterface* m_core; + + bool m_enabled; + }; +} + +#endif + diff --git a/plugins/scheduler/bwspage.ui b/plugins/scheduler/bwspage.ui new file mode 100644 index 0000000..af0e771 --- /dev/null +++ b/plugins/scheduler/bwspage.ui @@ -0,0 +1,877 @@ + +BWSPage + + + BWSPage + + + + 0 + 0 + 718 + 530 + + + + + 0 + 0 + + + + + 750 + 540 + + + + Bandwidth scheduler + + + + unnamed + + + Fixed + + + + layout21 + + + + unnamed + + + + buttonGroup1 + + + Left click category + + + + unnamed + + + + radio2 + + + Categor&y 1 + + + + + pix1 + + + + 0 + 0 + 0 + 0 + + + + + 30 + 15 + + + + true + + + + + pix2 + + + + 0 + 0 + 0 + 0 + + + + + 30 + 15 + + + + true + + + + + pix3 + + + + 0 + 0 + 0 + 0 + + + + + 30 + 15 + + + + true + + + + + pix5 + + + + 0 + 0 + 0 + 0 + + + + + 30 + 15 + + + + true + + + + + radio5 + + + T&urn off + + + + + radio1 + + + &Normal + + + + + pix4 + + + + 0 + 0 + 0 + 0 + + + + + 30 + 15 + + + + true + + + + + radio4 + + + Category &3 + + + Alt+3 + + + + + radio3 + + + Category &2 + + + Alt+2 + + + + + + + buttonGroup1_2 + + + Right click category + + + + unnamed + + + + radio22 + + + Category &1 + + + Alt+1 + + + + + pix12 + + + + 0 + 0 + 0 + 0 + + + + + 30 + 15 + + + + true + + + + + pix22 + + + + 0 + 0 + 0 + 0 + + + + + 30 + 15 + + + + true + + + + + pix32 + + + + 0 + 0 + 0 + 0 + + + + + 30 + 15 + + + + true + + + + + pix52 + + + + 0 + 0 + 0 + 0 + + + + + 30 + 15 + + + + true + + + + + radio52 + + + T&urn off + + + + + radio12 + + + &Normal + + + + + pix42 + + + + 0 + 0 + 0 + 0 + + + + + 30 + 15 + + + + true + + + + + radio42 + + + &Category 3 + + + + + radio32 + + + Category &2 + + + Alt+2 + + + + + + + + + groupCategories_2 + + + Categories + + + + unnamed + + + + textLabel8_4 + + + <b>1. Category</b> + + + + + textLabel8_3_2 + + + <b>3. Category</b> + + + + + layout8 + + + + unnamed + + + + textLabel6_5 + + + download: + + + + + dlCat1 + + + 30000 + + + + + textLabel6_4_4 + + + upload: + + + + + ulCat1 + + + 30000 + + + + + textLabel9_4 + + + KB/s * + + + + + + + layout9 + + + + unnamed + + + + textLabel6_2_2 + + + download: + + + + + dlCat2 + + + 30000 + + + + + textLabel6_4_2_2 + + + upload: + + + + + ulCat2 + + + 30000 + + + + + textLabel9_2_2 + + + KB/s * + + + + + + + layout10 + + + + unnamed + + + + textLabel6_3_2 + + + download: + + + + + dlCat3 + + + 30000 + + + + + textLabel6_4_3_2 + + + upload: + + + + + ulCat3 + + + 30000 + + + + + textLabel9_3_2 + + + KB/s * + + + + + + + textLabel8_2_2 + + + <b>2. Category</b> + + + + + + + m_bwsWidget + + + + 0 + 0 + 0 + 0 + + + + + 379 + 510 + + + + + 379 + 508 + + + + + + layout34 + + + + unnamed + + + + lblStatus + + + + + + + + textLabel10 + + + + 5 + 0 + 0 + 0 + + + + * zero means no limit + + + AlignVCenter|AlignRight + + + + + + + spacer16 + + + Vertical + + + Expanding + + + + 20 + 16 + + + + + + layout32 + + + + unnamed + + + + layout31 + + + + unnamed + + + + btnSave + + + Save to file + + + + + btnLoad + + + &Load from file + + + + + btnReset + + + Reset schedule + + + + + + + spacer15 + + + Horizontal + + + Expanding + + + + 36 + 20 + + + + + + pix_icon + + + image0 + + + false + + + + + spacer14 + + + Horizontal + + + Expanding + + + + 35 + 20 + + + + + + layout29 + + + + unnamed + + + + btnOk + + + O&k + + + + + btnApply + + + &Apply + + + + + btnCancel + + + Cancel + + + + + + + + + + + kt::BWSWidget +
bwswidget.h
+ + -1 + -1 + + 0 + + 5 + 5 + 0 + 0 + + image1 +
+
+ + + 789c8597596f23470e80dfe75718c3b7c182e9eabb11ec834fc9873cbeaf601fc86ec9966df994cfc5fef794483633934d10c836fcb9582cde55fee5dbd2d9de68e9db2f5f9ee7349fb64bed153d2d7deb5e66b38fdffef3efff7ef99aa64b8baf2c5b4abffeebcb57dc5c6a9720499290640b8613e110ff22eb941b07657e7256f90be742e4a7c6a9ed076791c7a1732efbd784d3f817615a71167db0e55c0a17ce95c88f8ced3c7e74d6f306cea29fd159f583b3e8a75367d18f5bce8df0b63389be67e3ccfcd97716fd78e22cfaf1d459edefedcbedbc63e75af4cf85b33edeb8616cfef1b5b39eb7e72cf6c28b7166fb53678df7b5b3fadf388b3d503a8b3d40c6b9eaa35767d9cf37c6a5e53f73d6f3769d55bedf5f2789ac6bfcf2de1fda33ce4cdfbb716eeb6fce1acf1de3c2f2bbe7acf573605cdafe2b67f5efd359f20bb97165febe38b3c453fd2bfa7cd0a67165fea97c9db416ff1de3b1e9d77a6d12567bf8c159ed9d1ab7969fc2b8d378e2ba304579c93769bd719457fd524f2184cae221f51bd250a8fd3c35ae4cfec1b8b6fa06e3c6eaffc859d651f215b2d0c7efdab8327b969d459e9e8d7bfd57c68df587c43be4c1e20b685c1b9f0b17c1e283cfce927f96f911ca40d63fcbce7afebd31eb3a91b3fa37376ead9e64dea5759606a94f546eb23499883d9bc69932bef4acf22cf594725c1f8bfca9b3c8d3aa711e82c82bb73de3817111a4fe2171d67e1a1b97ba8e87ce5a8f12bfb48b2cfae8ceb85206894f9666135bff2e5c45d6fae894a3393a3f5be13aaeb7729eca4ff2d6ce3f5b701ef2b1c95f0aa7715dfb4de657519675d0fc8d8c9ba0f527f12faab234fd8fc695f1ab716dfa3f84ebb2089dec5f779678d381711d74beae398b7f540b3751bfd6e39ab1c9033b6bbd07e326687dcb3c2da8ecf47cfa301e9bbe37e389c94b3c0a2edba0f5f361dc194b3c8b36eed77acf9c453fab7f6d95587e6e8d83c957c25dc9668fdc5fc538b2c6e3a6e754e7adcc836252b6a9d69bccffb2ad535d67e98fb2ab538befaab3e8439947e5b84e82f6ffa17165f1bd7096fcc1ccb8b67a981b375a0f20f92d2775b078493dd54c75aaef0de9dfba75167fea2eb2f683dc5771388d753fbe396b7fca7c6b52ea2c5e57ce621fcbfdd26464f1812767ed8f63e3ced665de34c464fe9e1bb3d5b3f45bc3dca67a7fc9fba7697b46a9bf66cc13cb8fcc8b66c2960f3832b6f3988dad1e2828b799c53371d6f9766b9c5b7f4afe286983f5c3aeb3be177ace6c1ecc9cb51f6a678def8a7169f351fca710f5a93d9db3d64febacf9981aa76a2f5e3b6b7d5d1af7f6df3aebfb67e4acf93f72d6f972675cd83c7d77d67cac3bebfdfce9acf7eb87b3c66b665cdabc5feed9f44bfd51caade59395dbc4fc3f33cecc9f9b9e35bf786fdccfffc459e7ffc059eb7fe2acefcfd459df13dbceda5f4367bddffed8affdf0665c243a6f769c351f6367f51f7ad6fcefcf9dd57e72567fd959e3dd3a6bbc3b677daf34ce6affadb3dadbdb57263a5f46ce7adf8e9dd5dededfbe5e2f9cb5de5b678df7bb71a5fa59f767dccf77cd57d6f7136c185b7e79d359f3159cf53df7e8acf19e19f7f57ee5acef9b0d67f5b733b6fa844b63f38f07ceea9fcc3fca5b9bef58199b3dbce5acefa53567bd6fee8c73d54f95b3fa3b34b6fcc3b3b3f6dba1b3f6afe6a788fb6bad9f1f3f08f19b90b18ddff0f3dafefc2fe4bb284948f1b7f1e2e73fca4ff012af708ad77883b77f2f8f33bc8b9aeff1011ff1099f718e2ff88a6ff88e1ff8196da33fc92fe30aaee21aaee3060e70889bb885dbb88323dc8d7a407df941be8dd2dfa3ec5e94dac7033cc4233cc6133cc5333cc78bffb327c18029669863812556d1ef1a9ba8168080a1850ec608daaf30814bb882296ec035dc486426700b33b8837b78c0213cc2133ce367af3f7a93c01c5e700b5ee10d6fe11d093ee01396610556f104d6601d36a2d77abf0da2f41036610bb6b1841d18c12e7c873dd887033884233886133885b318297d3fc558e114cee1021208d1e01432c8a180122aa8e3c5190f2322c63bb507995aea62bc37698c9f34a14bba822d9ad235ddd02dcde80e87744f0f7fc823d1233de1363d634d737aa1577aa3ebf8047ba70ffaa4655aa1555aa375b37f0c298e6923ca0fb0a1212cd3266dd136edd08876e93bedd13e1dd0211d997e88f6031dd3099d624e67744e17f15f8b40296594cb273ef61632aa5ff34515d5d43032707c19449fd6e993db283b8217ee62fc0630fa31bf1cdf037c493bb1724ef98a162d30e56bcae185467cc3b731dfa0f935f919dff13daef1033ff2133fc77d039e73d41da55ff90d268b8afba17ea27d30a18edff9833f7999577895d7a88421aff31b6fc0e04ff5c6314acc031ef2266cc4c7ce036ff12ca66a10ff75d95eacfd2ccf3b0bfd38e651ac93f7d83b77f84e47d1e6f1222e0bf9c5ef3ff7a3f690766f4ffd0490aa85affffbf5cbef985d44a8 + + + 89504e470d0a1a0a0000000d4948445200000016000000160806000000c4b46c3b0000042949444154388db5954d6c545514c77ff7de37eff1a6a550da994e5ba798868f948fc847a2a2911816c436b0a02ed0083161a1981877ee10d90aa94656063491882c5cd4c4b8103f20cd806909a98604da8482341de80cb69de9bcd799799d79efba980f1da3a80b4f727273939bdff99f9b93f3175a6b6a21849080020c4002a29a8f0a5dcd002803bed63a1035f0d0d0504b6f6fef51d7758fa4d3e98d8ee3fc03af128ee3303939399548242eb8aefb09300f78464de9f0f0f0d148cc7caf3d5424de97a7ec17104220242805520a44557bbd4b21f083801d33e63a6d1bc7bf19c6064e0319a35a58b9ae7ba43d54e4d7c54b64dc097c7f09d30ef04b36736983cc7c11b4456b9b492c5e20dc54a6540e00896a8268a7017010f8bcae1830d2e9f4c69ebe3c197782b2ce60d94ddc9b30f9feeb45ae5d7181c5ead35636ef08d3ffe26a76ee3208b4031a56d80aa00768fda362e9380e25bf80ef3b587613d7afc099533380a4b5dda46fcb5aa42998b9eb7173dce5e6788e434763ec7fc942532008ea436003660d2caa7f8d69c3bd8910674e4d033e83877ad8d36fb0aa4d6058658ac5358c5df6383bf480f31fdda5a3632bbbfb6da4ccd5c00a10b2012cc12fd97cfb5516f0187c25cee0619396480ec3ca909d0f3372d1e5f9fe66de3ad605587c712ec55256a2540d5519d19ae24a29057329839f7ecc138944d833102290f3184ae1e6d6f0e98739c61229e6d21eafbed1c9c8c5558c8f3ee4ceed76946a1c43d97091828585223e2eebfbc295f60d45de89707628cb58224577bc85a79e5d4d786581cddb9b0148259711b20145836221400416e0232d1f6595c9ce4538773ac7b54406f0b15784e8e80aa1ac2594190220d021e49f2437960156b70ba095e95f96f18acd8c263cc6122962b1167a7ba34cdd7ec8c977a699bed546722a8fc2a02b6e2185fff78ab586ce78894ddb9ab9f5738ed14b1e030756929d8ff2e4ae5544632b38f96e89a99b298ebd6950cc2d12ed0eb3618b26f520788462ad09877df60db600f0f1fb49c646f21c7ebd836dcf94e9d9b4c0db27d6d3bd36c6426a96bce731703046d7da129a4670836284a054869d4f1b1c7e2dca67676ef3c1898091ef5ad8bc358c3205c93bf7c9a40ad4c660f4728edd7bbb3142ea2fc1da711cfc200011e08b45f6bd1c261adbce9717928c5f9d63fc6a19f0014567773303073790f8214bd6f5282dfbb8b9fa1f6b40d7c1939393533b92e63ad9240990484aec7e41b27d579cbb531e0f67023492d86316ebb768ba1e0f786e6f37e56550c62237aee7011e54abd7c1412291b8a06de378b4d3c0b215da9708e5a3a442192085404a83d4accfecac067c0c43e13a70e3fa12e96409e0325000966bbb354465339d04a6f9dd15fe6dde07ce030780278088d05ad72cc9a6b2f2daaaa74d75a1f0e8d0d5f60b40868a8364ead6248430000b0857a126ffcdf396abf03ce089ffcb4c7f033046c6b4a995e7a00000000049454e44ae426082 + + + + + btnOk + clicked() + BWSPage + btnOk_clicked() + + + btnApply + clicked() + BWSPage + btnApply_clicked() + + + btnSave + clicked() + BWSPage + btnSave_clicked() + + + btnLoad + clicked() + BWSPage + btnLoad_clicked() + + + btnReset + clicked() + BWSPage + btnReset_clicked() + + + btnCancel + clicked() + BWSPage + reject() + + + + radio1 + radio2 + radio3 + radio4 + radio5 + dlCat1 + ulCat1 + dlCat2 + ulCat2 + dlCat3 + ulCat3 + + + btnOk_clicked() + btnApply_clicked() + btnCancel_clicked() + btnSave_clicked() + btnLoad_clicked() + btnReset_clicked() + + + + knuminput.h + knuminput.h + knuminput.h + knuminput.h + knuminput.h + knuminput.h + bwswidget.h + kpushbutton.h + kpushbutton.h + kpushbutton.h + kpushbutton.h + kpushbutton.h + kpushbutton.h + +
diff --git a/plugins/scheduler/bwsprefpage.cpp b/plugins/scheduler/bwsprefpage.cpp new file mode 100644 index 0000000..e69de29 diff --git a/plugins/scheduler/bwsprefpage.h b/plugins/scheduler/bwsprefpage.h new file mode 100644 index 0000000..e69de29 diff --git a/plugins/scheduler/bwsprefpagewidget.cpp b/plugins/scheduler/bwsprefpagewidget.cpp new file mode 100644 index 0000000..0c44a43 --- /dev/null +++ b/plugins/scheduler/bwsprefpagewidget.cpp @@ -0,0 +1,291 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include "bwspage.h" +#include "bwsprefpagewidget.h" +#include "bwscheduler.h" +#include "bwswidget.h" +#include "schedulerpluginsettings.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace kt +{ + + /* PREF PAGE WIDGET --------------------------------------------------------*/ + + BWSPrefPageWidget::BWSPrefPageWidget(QWidget* parent, const char* name, WFlags fl) + : BWSPage(parent,name,fl) + { + + loadDefault(); + + lblStatus->clear(); + + pix_icon->setPixmap(KGlobal::iconLoader()->loadIcon("clock",KIcon::NoGroup)); + + btnOk->setGuiItem(KStdGuiItem::ok()); + btnCancel->setGuiItem(KStdGuiItem::cancel()); + btnApply->setGuiItem(KStdGuiItem::apply()); + btnSave->setGuiItem(KStdGuiItem::saveAs()); + btnLoad->setGuiItem(KStdGuiItem::open()); + btnReset->setGuiItem(KStdGuiItem::reset()); + + + bool use_colors = SchedulerPluginSettings::useColors(); + + if(use_colors) //set up colors + { + pix1->setPaletteBackgroundColor(QColor(30,165,105)); + pix2->setPaletteBackgroundColor(QColor(195,195,70)); + pix3->setPaletteBackgroundColor(QColor(195,195,70)); + pix4->setPaletteBackgroundColor(QColor(195,195,70)); + pix5->setPaletteBackgroundColor(QColor(190,30,30)); + + pix12->setPaletteBackgroundColor(QColor(30,165,105)); + pix22->setPaletteBackgroundColor(QColor(195,195,70)); + pix32->setPaletteBackgroundColor(QColor(195,195,70)); + pix42->setPaletteBackgroundColor(QColor(195,195,70)); + pix52->setPaletteBackgroundColor(QColor(190,30,30)); + } else //set up pixmaps + { + pix1->setPixmap(QPixmap(locate("data", QString("ktorrent/icons/cell-a-0000.png")))); + pix2->setPixmap(QPixmap(locate("data", QString("ktorrent/icons/cell-a-0001.png")))); + pix3->setPixmap(QPixmap(locate("data", QString("ktorrent/icons/cell-a-0002.png")))); + pix4->setPixmap(QPixmap(locate("data", QString("ktorrent/icons/cell-a-0003.png")))); + pix5->setPixmap(QPixmap(locate("data", QString("ktorrent/icons/cell-a-0004.png")))); + + pix12->setPixmap(QPixmap(locate("data", QString("ktorrent/icons/cell-a-0000.png")))); + pix22->setPixmap(QPixmap(locate("data", QString("ktorrent/icons/cell-a-0001.png")))); + pix32->setPixmap(QPixmap(locate("data", QString("ktorrent/icons/cell-a-0002.png")))); + pix42->setPixmap(QPixmap(locate("data", QString("ktorrent/icons/cell-a-0003.png")))); + pix52->setPixmap(QPixmap(locate("data", QString("ktorrent/icons/cell-a-0004.png")))); + } + + connect(radio1, SIGNAL(stateChanged(int)), this, SLOT(categoryChanged(int))); + connect(radio2, SIGNAL(stateChanged(int)), this, SLOT(categoryChanged(int))); + connect(radio3, SIGNAL(stateChanged(int)), this, SLOT(categoryChanged(int))); + connect(radio4, SIGNAL(stateChanged(int)), this, SLOT(categoryChanged(int))); + connect(radio5, SIGNAL(stateChanged(int)), this, SLOT(categoryChanged(int))); + connect(radio12, SIGNAL(stateChanged(int)), this, SLOT(categoryChanged(int))); + connect(radio22, SIGNAL(stateChanged(int)), this, SLOT(categoryChanged(int))); + connect(radio32, SIGNAL(stateChanged(int)), this, SLOT(categoryChanged(int))); + connect(radio42, SIGNAL(stateChanged(int)), this, SLOT(categoryChanged(int))); + connect(radio52, SIGNAL(stateChanged(int)), this, SLOT(categoryChanged(int))); + + //pre-check default categories (say 1 for left and 0 for right) + radio2->setChecked(true); + radio12->setChecked(true); + + m_bwsWidget->setSchedule(schedule); + } + + BWSPrefPageWidget::~BWSPrefPageWidget() + {} + + void BWSPrefPageWidget::btnSave_clicked() + { + QString sf = KFileDialog::getSaveFileName("/home","*",this,i18n("Choose a filename to save under")); + + if(sf.isEmpty()) + return; + + saveSchedule(sf); + } + + void BWSPrefPageWidget::btnLoad_clicked() + { + QString lf = KFileDialog::getOpenFileName("/home", "*",this,i18n("Choose a file")); + + if(lf.isEmpty()) + return; + + btnReset_clicked(); + loadSchedule(lf); + } + + void BWSPrefPageWidget::saveSchedule(QString& fn) + { + schedule = m_bwsWidget->schedule(); + + QFile file(fn); + + file.open(IO_WriteOnly); + QDataStream stream(&file); + + //First category + stream << dlCat1->value(); + stream << ulCat1->value(); + + //Second category + stream << dlCat2->value(); + stream << ulCat2->value(); + + //Third category + stream << dlCat3->value(); + stream << ulCat3->value(); + + //Now schedule + for(int i=0; i<7; ++i) + for(int j=0; j<24; ++j) + stream << (int) schedule.getCategory(i, j); + + file.close(); + lblStatus->setText(i18n("Schedule saved.")); + } + + void BWSPrefPageWidget::loadSchedule(QString& fn, bool showmsg) + { + QFile file(fn); + + if(!file.exists()) { + if(showmsg) + KMessageBox::error(this, i18n("File not found."), i18n("Error")); + return; + } + + file.open(IO_ReadOnly); + QDataStream stream(&file); + + int tmp; + + stream >> tmp; + dlCat1->setValue(tmp); + stream >> tmp; + ulCat1->setValue(tmp); + + stream >> tmp; + dlCat2->setValue(tmp); + stream >> tmp; + ulCat2->setValue(tmp); + + stream >> tmp; + dlCat3->setValue(tmp); + stream >> tmp; + ulCat3->setValue(tmp); + + for(int i=0; i<7; ++i) { + for(int j=0; j<24; ++j) { + stream >> tmp; + schedule.setCategory(i, j, (ScheduleCategory) tmp); + } + } + + file.close(); + + m_bwsWidget->setSchedule(schedule); + lblStatus->setText(i18n("Schedule loaded.")); + } + + void BWSPrefPageWidget::loadDefault() + { + //read schedule from HD + QString fn = KGlobal::dirs()->saveLocation("data","ktorrent") + "bwschedule"; + loadSchedule(fn, false); + } + + void BWSPrefPageWidget::btnReset_clicked() + { + schedule.reset(); + m_bwsWidget->resetSchedule(); + + dlCat1->setValue(0); + dlCat2->setValue(0); + dlCat3->setValue(0); + + ulCat1->setValue(0); + ulCat2->setValue(0); + ulCat3->setValue(0); + + lblStatus->clear(); + } + + void BWSPrefPageWidget::apply() + { + schedule = m_bwsWidget->schedule(); + + SchedulerPluginSettings::writeConfig(); + + //update category values... + schedule.setDownload(0, dlCat1->value()); + schedule.setUpload(0, ulCat1->value()); + schedule.setDownload(1, dlCat2->value()); + schedule.setUpload(1, ulCat2->value()); + schedule.setDownload(2, dlCat3->value()); + schedule.setUpload(2, ulCat3->value()); + + //set new schedule + BWScheduler::instance().setSchedule(schedule); + } + + void BWSPrefPageWidget::btnOk_clicked() + { + apply(); + accept(); + } + + void BWSPrefPageWidget::btnApply_clicked() + { + apply(); + } +} + +void kt::BWSPrefPageWidget::categoryChanged(int) +{ + if(radio1->isChecked()) + m_bwsWidget->setLeftCategory(0); + else if(radio2->isChecked()) + m_bwsWidget->setLeftCategory(1); + else if(radio3->isChecked()) + m_bwsWidget->setLeftCategory(2); + else if(radio4->isChecked()) + m_bwsWidget->setLeftCategory(3); + else if(radio5->isChecked()) + m_bwsWidget->setLeftCategory(4); + + if(radio12->isChecked()) + m_bwsWidget->setRightCategory(0); + else if(radio22->isChecked()) + m_bwsWidget->setRightCategory(1); + else if(radio32->isChecked()) + m_bwsWidget->setRightCategory(2); + else if(radio42->isChecked()) + m_bwsWidget->setRightCategory(3); + else if(radio52->isChecked()) + m_bwsWidget->setRightCategory(4); +} + + + +#include "bwsprefpagewidget.moc" diff --git a/plugins/scheduler/bwsprefpagewidget.h b/plugins/scheduler/bwsprefpagewidget.h new file mode 100644 index 0000000..ca0e80b --- /dev/null +++ b/plugins/scheduler/bwsprefpagewidget.h @@ -0,0 +1,84 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef KTBWSPREFPAGEWIDGET_H +#define KTBWSPREFPAGEWIDGET_H + +#include + +#include "bwspage.h" +#include "bwscheduler.h" + +namespace kt +{ + /** + * @brief Bandwidth Scheduler page + * @author Ivan Vasic + */ + class BWSPrefPageWidget : public BWSPage + { + Q_OBJECT + public: + BWSPrefPageWidget(QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + ~BWSPrefPageWidget(); + /*$PUBLIC_FUNCTIONS$*/ + + /** + * @brief Loads default schedule. + * Default schedule is currently active (if enabled) and it's in ~/.kde/share/apps/ktorrent/bwschedule + */ + void loadDefault(); + + /** + * Loads a schedule from HD. + * @param fn Schedule filename + * @param showmsg Should I show msgBox if file doesn't exist. + * @ref BWSPrefPageWidget::btnLoad_clicked() + * @ref BWSPrefPageWidget::loadDefault() + */ + void loadSchedule(QString& fn, bool showmsg = true); + + /** + * Saves current schedule to HD. + * @param fn Schedule filename. + */ + void saveSchedule(QString& fn); + + + public slots: + /*$PUBLIC_SLOTS$*/ + virtual void btnReset_clicked(); + virtual void btnLoad_clicked(); + virtual void btnSave_clicked(); + virtual void btnApply_clicked(); + virtual void btnOk_clicked(); + + private slots: + void categoryChanged(int); + + ///Applies settings + void apply(); + + private: + BWS schedule; + }; + +} + +#endif diff --git a/plugins/scheduler/bwswidget.cpp b/plugins/scheduler/bwswidget.cpp new file mode 100644 index 0000000..b430de3 --- /dev/null +++ b/plugins/scheduler/bwswidget.cpp @@ -0,0 +1,334 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include "bwswidget.h" +#include "schedulerpluginsettings.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace kt +{ + BWSWidget::BWSWidget(QWidget* parent, const char* name, bool useColors) + : QTable(parent,name), m_leftCategory(1), m_rightCategory(0), draw_focus(true), right_click(false), use_colors(useColors) + { + use_colors = SchedulerPluginSettings::useColors(); + + QStringList days; + QStringList hours; + + days << i18n("MON") << i18n("TUE") << i18n("WED") << i18n("THU") << i18n("FRI") << i18n("SAT") << i18n("SUN"); + hours << + "00:00-00:59h" << "01:00-01:59h" << + "02:00-02:59h" << "03:00-03:59h" << + "04:00-04:59h" << "05:00-05:59h" << + "06:00-06:59h" << "07:00-07:59h" << + "08:00-08:59h" << "09:00-09:59h" << + "10:00-10:59h" << "11:00-11:59h" << + "12:00-12:59h" << "13:00-13:59h" << + "14:00-14:59h" << "15:00-15:59h" << + "16:00-16:59h" << "17:00-17:59h" << + "18:00-18:59h" << "19:00-19:59h" << + "20:00-20:59h" << "21:00-21:59h" << + "22:00-22:59h" << "23:00-23:59h"; + + insertRows(0,24); + insertColumns(0,7); + + setColumnLabels(days); + setRowLabels(hours); + + setFocusPolicy(QWidget::StrongFocus); + + QFont f; + f.setPointSize(8); + setFont(f); + + for(int i=0; i<7; ++i) { + setColumnWidth(i,40); + setColumnStretchable(i, true); + } + for(int i=0; i<24; ++i) { + setColumnWidth(i,40); + setRowStretchable(i, true); + } + + setColumnMovingEnabled(false); + setRowMovingEnabled(false); + + setSorting(false); + + adjustSize(); + + for(int i=0; i<5; ++i) { + m_pix[i] = 0; + m_pixf[i] = 0; + m_color[i] = 0; + m_colorf[i] = 0; + } + + setType(use_colors); + + resetSchedule(); + + setSelectionMode(QTable::NoSelection); + + setHScrollBarMode(QTable::AlwaysOff); + setVScrollBarMode(QTable::AlwaysOff); + + connect(this, SIGNAL(currentChanged( int, int )), this, SLOT(cellSelectionChanged( int, int ))); + connect(this, SIGNAL(pressed(int, int, int, const QPoint&)), this, SLOT(cellMouseDown(int, int, int, const QPoint& ))); + } + + BWSWidget::~BWSWidget() + { + for(int i=0; i<5; ++i) { + if(m_pix[i]) + delete m_pix[i]; + if(m_pixf[i]) + delete m_pixf[i]; + } + } + + void BWSWidget::paintFocus(QPainter* p, const QRect& cr) + { + int x = rowAt(cr.y()); + int y = columnAt(cr.x()); + + if(x == 1 && y == 1) { + int trt = 0; + ++trt; + } + + if(lastFocused.x != x || lastFocused.y != y) + updateCell(lastFocused.x, lastFocused.y); + + if(draw_focus) { + + if(right_click) + drawCell(p, m_rightCategory, true); + else + drawCell(p, m_leftCategory, true); + + lastFocused.x = x; + lastFocused.y = y; + } else { + lastFocused.x = -1; + lastFocused.y = -1; + } + } + + void BWSWidget::cellSelectionChanged(int row, int col) + { + if(right_click) + setText(row, col, QString::number(m_rightCategory)); + else + setText(row, col, QString::number(m_leftCategory)); + } + + void BWSWidget::paintCell(QPainter* p, int row, int col, const QRect& cr, bool selected) + { + if(selected) + return; + + bool ok; + int cat = text(row,col).toInt(&ok); + if((ok || cat == 0) && cat >= 0 && cat <= 4) + drawCell(p, cat); + else + setText(row,col,QString::number(0)); + // QTable::paintCell(p,row,col,cr,selected); + } + + void BWSWidget::resetSchedule() + { + for(int i=0; i<7; ++i) + for(int j=0; j<24; ++j) + setText(j,i, "0"); + draw_focus = false; + clearSelection(); + updateHeaderStates(); + } + + void BWSWidget::repaintWidget() + { + for(int i=0; i<7; ++i) + for(int j=0; j<24; ++j) + updateCell(j,i); + } + + void BWSWidget::cellMouseDown(int row, int col, int button, const QPoint& mousePos) + { + right_click = button == 2; + draw_focus = true; + cellSelectionChanged(row,col); + } + + void BWSWidget::clearSelect() + { + draw_focus = false; + clearSelection(); + updateHeaderStates(); + repaintWidget(); + } + + void BWSWidget::setLeftCategory(const int& theValue) + { + m_leftCategory = theValue; + } + + void BWSWidget::setRightCategory(const int& theValue) + { + m_rightCategory = theValue; + } + + + void BWSWidget::setUseColors(bool theValue) + { + use_colors = theValue; + } + + void BWSWidget::drawCell(QPainter* p, int category, bool focus) + { + if(use_colors) { + if(focus) { + p->fillRect(0,0,40,20,*m_colorf[category]); + } else { + p->fillRect(0,0,40,20,*m_color[category]); + } + + switch(category) { + case 0: + // p->drawText(QRect(0,0,40,20), Qt::AlignCenter | Qt::SingleLine, "normalllll"); + break; + case 1: + case 2: + case 3: + p->drawText(QRect(0,0,40,20), Qt::AlignCenter | Qt::SingleLine, QString::number(category)); + break; + case 4: + p->drawText(QRect(0,0,40,20), Qt::AlignCenter | Qt::SingleLine, "off"); + break; + } + + p->drawRect(0,0,40,20); + } else { + if(focus) + p->drawPixmap(0,0,*m_pixf[category]); + else + p->drawPixmap(0,0, *m_pix[category]); + } + } + + void BWSWidget::setType(bool color) + { + if(color) { + for(int i=0; i<5; ++i) { + if(m_pix[i]) + delete m_pix[i]; + if(m_pixf[i]) + delete m_pixf[i]; + + m_pix[i] = 0; + m_pixf[i] = 0; + } + + m_color[0] = new QColor(30,165,105); + m_color[1] = new QColor(195,195,70); + m_color[2] = new QColor(195,195,70); + m_color[3] = new QColor(195,195,70); + m_color[4] = new QColor(190,30,30); + + m_colorf[0] = new QColor(40,200,130); + m_colorf[1] = new QColor(210,220,130); + m_colorf[2] = new QColor(210,220,130); + m_colorf[3] = new QColor(210,220,130); + m_colorf[4] = new QColor(230,40,40); + + } else { + for(int i=0; i<5; ++i) { + if(m_color[i]) + delete m_color[i]; + if(m_colorf[i]) + delete m_colorf[i]; + + m_color[i] = 0; + m_colorf[i] = 0; + } + + m_pix[0] = new QPixmap(locate("data", QString("ktorrent/icons/cell-a-0000.png"))); + m_pix[1] = new QPixmap(locate("data", QString("ktorrent/icons/cell-a-0001.png"))); + m_pix[2] = new QPixmap(locate("data", QString("ktorrent/icons/cell-a-0002.png"))); + m_pix[3] = new QPixmap(locate("data", QString("ktorrent/icons/cell-a-0003.png"))); + m_pix[4] = new QPixmap(locate("data", QString("ktorrent/icons/cell-a-0004.png"))); + + m_pixf[0] = new QPixmap(locate("data", QString("ktorrent/icons/cell-b-0000.png"))); + m_pixf[1] = new QPixmap(locate("data", QString("ktorrent/icons/cell-b-0001.png"))); + m_pixf[2] = new QPixmap(locate("data", QString("ktorrent/icons/cell-b-0002.png"))); + m_pixf[3] = new QPixmap(locate("data", QString("ktorrent/icons/cell-b-0003.png"))); + m_pixf[4] = new QPixmap(locate("data", QString("ktorrent/icons/cell-b-0004.png"))); + } + + use_colors = color; + + repaintWidget(); + } + + void BWSWidget::setSchedule(const BWS& theValue) + { + m_schedule = theValue; + for(int i=0; i<7; ++i) + for(int j=0; j<24; ++j) + setText(j,i, QString::number((int) m_schedule.getCategory(i,j))); + } + + const BWS& BWSWidget::schedule() + { + for(int i=0; i<7; ++i) + { + for(int j=0; j<24; ++j) + { + bool ok; + ScheduleCategory cat = (ScheduleCategory) text(j,i).toInt(&ok); + + if((ok || cat == 0) && cat >= 0 && cat <= 4) //precaution + m_schedule.setCategory(i,j, cat); + else + m_schedule.setCategory(i,j,(ScheduleCategory) 0); + } + } + + return m_schedule; + } + + void BWSWidget::focusOutEvent(QFocusEvent* e) + { + if(e->lostFocus()) + clearSelect(); + } +} diff --git a/plugins/scheduler/bwswidget.h b/plugins/scheduler/bwswidget.h new file mode 100644 index 0000000..c035edb --- /dev/null +++ b/plugins/scheduler/bwswidget.h @@ -0,0 +1,107 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef KTBWSWIDGET_H +#define KTBWSWIDGET_H + +#include +#include +#include +#include + +#include "bwscheduler.h" + +namespace kt +{ + typedef struct _focusedCell + { + int x; + int y; + } + FocusedCell; + + /** + * @brief Bandwidth scheduler widget. + * @author Ivan Vasić + * This class is a QTable with customized cells. It's used for bandwidth scheduling by painting each cell with mouse moves or keyboard. + */ + class BWSWidget : public QTable + { + Q_OBJECT + public: + BWSWidget(QWidget* parent = 0, const char* name = 0, bool useColors = true); + ~BWSWidget(); + + ///Repaints the whole widget + void repaintWidget(); + + ///Clears selection (removes focus) + void clearSelect(); + + ///Sets category for left mouse click. + void setLeftCategory(const int& theValue); + ///Sets category for right mouse click. + void setRightCategory(const int& theValue); + + + /** + * Sets cell paint type. + * @param color TRUE - paints colors. FALSE - paints pixmaps. + */ + void setType(bool color); + + ///Returns current schedule. + const BWS& schedule(); + ///Sets schedule. + void setSchedule(const BWS& theValue); + + public slots: + void resetSchedule(); + void setUseColors(bool theValue); + + private slots: + void cellSelectionChanged(int row, int col); + void cellMouseDown(int row, int col, int button, const QPoint& mousePos); + + private: + void paintFocus(QPainter* p, const QRect& cr); + void paintCell(QPainter* p, int row, int col, const QRect& cr, bool selected); + void drawCell(QPainter* p, int category, bool focus = false); + void focusOutEvent(QFocusEvent*); + + QPixmap* m_pix[5]; + QPixmap* m_pixf[5]; + + QColor* m_color[5]; + QColor* m_colorf[5]; + + int m_leftCategory; + int m_rightCategory; + + FocusedCell lastFocused; + + bool draw_focus; + bool right_click; + + bool use_colors; + + BWS m_schedule; + }; +} +#endif diff --git a/plugins/scheduler/cell-a-0000.png b/plugins/scheduler/cell-a-0000.png new file mode 100644 index 0000000..c3a7afd Binary files /dev/null and b/plugins/scheduler/cell-a-0000.png differ diff --git a/plugins/scheduler/cell-a-0001.png b/plugins/scheduler/cell-a-0001.png new file mode 100644 index 0000000..7f93d4e Binary files /dev/null and b/plugins/scheduler/cell-a-0001.png differ diff --git a/plugins/scheduler/cell-a-0002.png b/plugins/scheduler/cell-a-0002.png new file mode 100644 index 0000000..635377e Binary files /dev/null and b/plugins/scheduler/cell-a-0002.png differ diff --git a/plugins/scheduler/cell-a-0003.png b/plugins/scheduler/cell-a-0003.png new file mode 100644 index 0000000..16f5080 Binary files /dev/null and b/plugins/scheduler/cell-a-0003.png differ diff --git a/plugins/scheduler/cell-a-0004.png b/plugins/scheduler/cell-a-0004.png new file mode 100644 index 0000000..db91d39 Binary files /dev/null and b/plugins/scheduler/cell-a-0004.png differ diff --git a/plugins/scheduler/cell-b-0000.png b/plugins/scheduler/cell-b-0000.png new file mode 100644 index 0000000..1c765f0 Binary files /dev/null and b/plugins/scheduler/cell-b-0000.png differ diff --git a/plugins/scheduler/cell-b-0001.png b/plugins/scheduler/cell-b-0001.png new file mode 100644 index 0000000..2fdfcc2 Binary files /dev/null and b/plugins/scheduler/cell-b-0001.png differ diff --git a/plugins/scheduler/cell-b-0002.png b/plugins/scheduler/cell-b-0002.png new file mode 100644 index 0000000..6ed81c0 Binary files /dev/null and b/plugins/scheduler/cell-b-0002.png differ diff --git a/plugins/scheduler/cell-b-0003.png b/plugins/scheduler/cell-b-0003.png new file mode 100644 index 0000000..847b3a4 Binary files /dev/null and b/plugins/scheduler/cell-b-0003.png differ diff --git a/plugins/scheduler/cell-b-0004.png b/plugins/scheduler/cell-b-0004.png new file mode 100644 index 0000000..458aae4 Binary files /dev/null and b/plugins/scheduler/cell-b-0004.png differ diff --git a/plugins/scheduler/ktschedulerplugin.desktop b/plugins/scheduler/ktschedulerplugin.desktop new file mode 100644 index 0000000..c208cb3 --- /dev/null +++ b/plugins/scheduler/ktschedulerplugin.desktop @@ -0,0 +1,26 @@ +[Desktop Entry] +Name=SchedulerPlugin +Name[bg]=Приставка за график +Name[cs]=Modul plánování +Name[da]=Skemalægger-Plugin +Name[de]=Planer-Modul +Name[el]=Πρόσθετο προγραμματισμού +Name[et]=Ajastamisplugin +Name[it]=Plugin pianificatore +Name[nb]=Planleggermodul +Name[nds]=Planer-Moduul +Name[nl]=Plannerplugin +Name[pl]=Wtyczka planowanie transferu +Name[pt_BR]=Plugin de agendamento +Name[sk]=Scheduler Plugin +Name[sr]=Прикључак распоређивања +Name[sr@Latn]=Priključak raspoređivanja +Name[sv]=Insticksprogram för schemaläggning +Name[tr]=Zamanlayıcı Eklentisi +Name[uk]=Втулок розкладу +Name[xx]=xxSchedulerPluginxx +Name[zh_CN]=带宽规划器插件 +Name[zh_TW]=排程器外掛程式 +ServiceTypes=KTorrent/Plugin +Type=Service +X-KDE-Library=ktschedulerplugin diff --git a/plugins/scheduler/ktschedulerplugin.kcfg b/plugins/scheduler/ktschedulerplugin.kcfg new file mode 100644 index 0000000..7f752b3 --- /dev/null +++ b/plugins/scheduler/ktschedulerplugin.kcfg @@ -0,0 +1,18 @@ + + + + + + + + FALSE + + + + FALSE + + + diff --git a/plugins/scheduler/ktschedulerpluginui.rc b/plugins/scheduler/ktschedulerpluginui.rc new file mode 100644 index 0000000..217e103 --- /dev/null +++ b/plugins/scheduler/ktschedulerpluginui.rc @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/scheduler/schedulerpage.ui b/plugins/scheduler/schedulerpage.ui new file mode 100644 index 0000000..01a4f47 --- /dev/null +++ b/plugins/scheduler/schedulerpage.ui @@ -0,0 +1,146 @@ + +SchedulerPage + + + SchedulerPage + + + + 0 + 0 + 570 + 401 + + + + Scheduler Plugin Pref Page + + + + unnamed + + + + useBS + + + Use &bandwidth scheduler? + + + + + groupBWS + + + Bandwidth Scheduler + + + + unnamed + + + + useColors + + + Use colors instead of pi&xmaps? + + + + + textLabel1_2 + + + (Recommended for slower systems) + + + + + btnEditBWS + + + Edit s&chedule + + + + + spacer22 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + spacer18 + + + Vertical + + + Expanding + + + + 20 + 80 + + + + + + + + spacer8 + + + Vertical + + + Expanding + + + + 20 + 40 + + + + + + + + useBS + toggled(bool) + groupBWS + setEnabled(bool) + + + btnEditBWS + clicked() + SchedulerPage + btnEditBWS_clicked() + + + useColors + toggled(bool) + SchedulerPage + useColors_toggled(bool) + + + + btnEditBWS_toggled(bool) + btnEditBWS_clicked() + useColors_toggled(bool) + + + diff --git a/plugins/scheduler/schedulerplugin.cpp b/plugins/scheduler/schedulerplugin.cpp new file mode 100644 index 0000000..7639293 --- /dev/null +++ b/plugins/scheduler/schedulerplugin.cpp @@ -0,0 +1,152 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "schedulerplugin.h" +#include "schedulerpluginsettings.h" +#include "bwscheduler.h" +#include "schedulerprefpage.h" +#include "bwsprefpagewidget.h" + +#include +#include +#include + +using namespace bt; + +K_EXPORT_COMPONENT_FACTORY(ktschedulerplugin,KGenericFactory("schedulerplugin")) + +namespace kt +{ + const QString NAME = "Bandwith Scheduler"; + const QString AUTHOR = "Ivan Vasic"; + const QString EMAIL = "ivasic@gmail.com"; + const QString DESCRIPTION = i18n("Bandwidth scheduling plugin"); + + SchedulerPlugin::SchedulerPlugin(QObject* parent, const char* name, const QStringList& args) + : Plugin(parent, name, args,NAME,i18n("Bandwidth Scheduler"),AUTHOR,EMAIL,DESCRIPTION, "clock") + { + setXMLFile("ktschedulerpluginui.rc"); + bws_action = 0; + connect(&m_timer, SIGNAL(timeout()), this, SLOT(timer_triggered())); + } + + + SchedulerPlugin::~SchedulerPlugin() + { + } + + void SchedulerPlugin::load() + { + Pref = new SchedulerPrefPage(this); + getGUI()->addPrefPage(Pref); + BWScheduler::instance().setCoreInterface(getCore()); + + QDateTime now = QDateTime::currentDateTime(); + + //each hour + QDateTime hour = now.addSecs(3600); + QTime t(hour.time().hour(), 0); + + //each minute +// QDateTime hour = now.addSecs(60); +// QTime t(hour.time().hour(), hour.time().minute()); + + QDateTime round(hour.date(), t); + + // add a 5 second safety margin (BUG: 131246) + int secs_to = now.secsTo(round) + 5; + + m_timer.start(secs_to*1000); + + BWScheduler::instance().trigger(); + +// updateEnabledBWS(); + bws_action = new KAction(i18n("Open Bandwidth Scheduler" ), "clock", 0, this, + SLOT(openBWS()), actionCollection(), "bwscheduler" ); + } + + void SchedulerPlugin::unload() + { + getGUI()->removePrefPage(Pref); + if(Pref) + delete Pref; + Pref = 0; + + if(bws_action) + delete bws_action; + bws_action = 0; + + m_timer.stop(); + } + + void SchedulerPlugin::timer_triggered() + { + m_timer.changeInterval(3600*1000); + QDateTime now = QDateTime::currentDateTime(); + BWScheduler::instance().trigger(); + } + + void SchedulerPlugin::openBWS() + { + if(SchedulerPluginSettings::enableBWS()) + { + BWSPrefPageWidget dlg; + dlg.exec(); + } + else + KMessageBox::sorry(0, i18n("Bandwidth scheduler is disabled. Go to Preferences->Scheduler to enable it.")); + } + + void SchedulerPlugin::updateEnabledBWS() + { + if(SchedulerPluginSettings::enableBWS()) + { + bws_action = new KAction(i18n("Open Bandwidth Scheduler" ), "clock", 0, this, + SLOT(openBWS()), actionCollection(), "bwscheduler" ); + } + else + { + if(bws_action) + delete bws_action; + bws_action = 0; + } + } + + bool SchedulerPlugin::versionCheck(const QString & version) const + { + return version == KT_VERSION_MACRO; + } +} diff --git a/plugins/scheduler/schedulerplugin.h b/plugins/scheduler/schedulerplugin.h new file mode 100644 index 0000000..6828d0d --- /dev/null +++ b/plugins/scheduler/schedulerplugin.h @@ -0,0 +1,70 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef KTschedulerPLUGIN_H +#define KTschedulerPLUGIN_H + +#include + +#include "schedulerprefpage.h" + +#include + +#include + +class QString; + + +namespace kt +{ + class BWSPrefPage; + + /** + * @author Ivan Vasic + * @brief KTorrent scheduler plugin. + * + */ + class SchedulerPlugin : public Plugin + { + Q_OBJECT + public: + SchedulerPlugin(QObject* parent, const char* name, const QStringList& args); + virtual ~SchedulerPlugin(); + + virtual void load(); + virtual void unload(); + virtual bool versionCheck(const QString& version) const; + + void updateEnabledBWS(); + + public slots: + void timer_triggered(); + void openBWS(); + + private: + QTimer m_timer; + + /* BANDWIDTH SCHEDULE PLUGIN */ + SchedulerPrefPage* Pref; + KAction* bws_action; + }; + +} + +#endif diff --git a/plugins/scheduler/schedulerpluginsettings.kcfgc b/plugins/scheduler/schedulerpluginsettings.kcfgc new file mode 100644 index 0000000..f38f816 --- /dev/null +++ b/plugins/scheduler/schedulerpluginsettings.kcfgc @@ -0,0 +1,7 @@ +# Code generation options for kconfig_compiler +File=ktschedulerplugin.kcfg +ClassName=SchedulerPluginSettings +Namespace=kt +Singleton=true +Mutators=true +# will create the necessary code for setting those variables \ No newline at end of file diff --git a/plugins/scheduler/schedulerprefpage.cpp b/plugins/scheduler/schedulerprefpage.cpp new file mode 100644 index 0000000..fe82f34 --- /dev/null +++ b/plugins/scheduler/schedulerprefpage.cpp @@ -0,0 +1,64 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include "schedulerprefpage.h" +#include "bwsprefpagewidget.h" +#include "schedulerplugin.h" +#include "schedulerpluginsettings.h" + +#include +#include +#include + + +namespace kt +{ + + SchedulerPrefPage::SchedulerPrefPage(SchedulerPlugin* plugin) + : PrefPageInterface(i18n("Scheduler"), i18n("Scheduler plugin options"), KGlobal::iconLoader()->loadIcon("clock",KIcon::NoGroup)), m_plugin(plugin) + { + widget = 0; + } + + + SchedulerPrefPage::~SchedulerPrefPage() + {} + + bool SchedulerPrefPage::apply() + { + widget->apply(); +// m_plugin->updateEnabledBWS(); + return true; + } + + void SchedulerPrefPage::createWidget( QWidget * parent ) + { + widget = new SchedulerPrefPageWidget(parent); + } + + void SchedulerPrefPage::updateData() + {} + + void SchedulerPrefPage::deleteWidget() + { + delete widget; + widget = 0; + } +} diff --git a/plugins/scheduler/schedulerprefpage.h b/plugins/scheduler/schedulerprefpage.h new file mode 100644 index 0000000..a10a98a --- /dev/null +++ b/plugins/scheduler/schedulerprefpage.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef KTSchedulerPREFPAGE_H +#define KTSchedulerPREFPAGE_H + +#include + +#include "schedulerprefpagewidget.h" + +namespace kt +{ + class SchedulerPlugin; + + /** + * @brief Scheduler Preferences Page. + * @author Ivan Vasic + */ + class SchedulerPrefPage : public PrefPageInterface + { + public: + SchedulerPrefPage(SchedulerPlugin* plugin); + virtual ~SchedulerPrefPage(); + + virtual bool apply(); + virtual void createWidget(QWidget* parent); + virtual void updateData(); + virtual void deleteWidget(); + + private: + SchedulerPlugin* m_plugin; + SchedulerPrefPageWidget* widget; + }; +} + +#endif diff --git a/plugins/scheduler/schedulerprefpagewidget.cpp b/plugins/scheduler/schedulerprefpagewidget.cpp new file mode 100644 index 0000000..d6e73dd --- /dev/null +++ b/plugins/scheduler/schedulerprefpagewidget.cpp @@ -0,0 +1,83 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include "schedulerprefpagewidget.h" +#include "bwsprefpagewidget.h" +#include "bwscheduler.h" +#include "schedulerpluginsettings.h" + +#include +#include +#include +#include + +namespace kt +{ + + SchedulerPrefPageWidget::SchedulerPrefPageWidget(QWidget* parent, const char* name, WFlags fl) + : SchedulerPage(parent,name,fl) + { + groupBWS->setEnabled(false); + bool useit = SchedulerPluginSettings::enableBWS(); + bool use_colors = SchedulerPluginSettings::useColors(); + useBS->setChecked(useit); + useColors->setChecked(use_colors); + } + + + SchedulerPrefPageWidget::~SchedulerPrefPageWidget() + {} + + void SchedulerPrefPageWidget::btnEditBWS_clicked() + { + BWSPrefPageWidget w(this); + w.exec(); + } + + void SchedulerPrefPageWidget::apply() + { + bool use_bws = useBS->isChecked(); + + SchedulerPluginSettings::setEnableBWS(use_bws); + SchedulerPluginSettings::setUseColors(useColors->isChecked()); + SchedulerPluginSettings::writeConfig(); + + /* force trigger since the schedule has changed but after KTorrent::apply() + * Used QTimer with fixed interval - not very nice solution... */ + if(useBS->isChecked()) + QTimer::singleShot(1000, this, SLOT(scheduler_trigger())); + + BWScheduler::instance().setEnabled(use_bws); + } + + void SchedulerPrefPageWidget::scheduler_trigger() + { + BWScheduler::instance().trigger(); + } + + void SchedulerPrefPageWidget::useColors_toggled(bool) + { + SchedulerPluginSettings::setUseColors(useColors->isChecked()); + SchedulerPluginSettings::writeConfig(); + } + +} + + + diff --git a/plugins/scheduler/schedulerprefpagewidget.h b/plugins/scheduler/schedulerprefpagewidget.h new file mode 100644 index 0000000..9f62c20 --- /dev/null +++ b/plugins/scheduler/schedulerprefpagewidget.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef KTSCHEDULERPREFPAGEWIDGET_H +#define KTSCHEDULERPREFPAGEWIDGET_H + +#include +#include "schedulerpage.h" + +namespace kt +{ + /** + * @brief Scheduler Preferences Page. + * @author Ivan Vasic + */ + class SchedulerPrefPageWidget : public SchedulerPage + { + Q_OBJECT + public: + SchedulerPrefPageWidget(QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + + ~SchedulerPrefPageWidget(); + + void apply(); + + public slots: + virtual void btnEditBWS_clicked(); + void scheduler_trigger(); + virtual void useColors_toggled(bool); + }; + +} + +#endif -- cgit v1.2.1