This forum has been archived. All content is frozen. Please use KDE Discuss instead.

[PATCH] add fast max quick selection in systray

Tags: None
(comma "," separated)
khrothgar
Registered Member
Posts
4
Karma
0
hi!
i have made a patch to set quickly max upload/download rate through ksystray.
i'd like to see this feature in a next relase.

work with 550926 svn

db

Code: Select all
diff -u -r ktorrent/apps/ktorrent/ktorrent.cpp my_ktorrent/apps/ktorrent/ktorrent.cpp
--- ktorrent/apps/ktorrent/ktorrent.cpp   2006-06-13 08:57:21.000000000 +0000
+++ my_ktorrent/apps/ktorrent/ktorrent.cpp   2006-06-13 09:16:20.000000000 +0000
@@ -283,6 +283,8 @@
    if (Settings::showSystemTrayIcon())
    {
       m_systray_icon->show();
+      m_set_max_upload_rate->update();
+      m_set_max_download_rate->update();
    }
    else
    {
@@ -434,6 +436,13 @@
    m_systray_icon->contextMenu()->insertSeparator();
    m_pasteurl->plug(m_systray_icon->contextMenu());
    m_systray_icon->contextMenu()->insertSeparator();
+
+   m_set_max_upload_rate = new SetMaxRate(m_core, 0, this);
+   m_systray_icon->contextMenu()->insertItem(i18n("Set max upload rate"),m_set_max_upload_rate);
+
+   m_set_max_download_rate = new SetMaxRate(m_core, 1, this);
+   m_systray_icon->contextMenu()->insertItem(i18n("Set max download rate"),m_set_max_download_rate);
+
    pref->plug(m_systray_icon->contextMenu());
    
    createGUI();
diff -u -r ktorrent/apps/ktorrent/ktorrent.h my_ktorrent/apps/ktorrent/ktorrent.h
--- ktorrent/apps/ktorrent/ktorrent.h   2006-06-13 08:57:21.000000000 +0000
+++ my_ktorrent/apps/ktorrent/ktorrent.h   2006-06-13 09:14:22.000000000 +0000
@@ -40,6 +40,7 @@
 class KTorrentCore;
 class KTorrentView;
 class TrayIcon;
+class SetMaxRate;
 class KTabWidget;
 class KTorrentDCOP;
 class QLabel;
@@ -174,6 +175,8 @@
    
    KTorrentCore* m_core;
    TrayIcon* m_systray_icon;
+   SetMaxRate* m_set_max_upload_rate;
+   SetMaxRate* m_set_max_download_rate;
    KTabWidget* m_tabs;
    KTorrentDCOP* m_dcop;
    QTimer m_gui_update_timer;
diff -u -r ktorrent/apps/ktorrent/ktorrentcore.cpp my_ktorrent/apps/ktorrent/ktorrentcore.cpp
--- ktorrent/apps/ktorrent/ktorrentcore.cpp   2006-06-13 08:57:21.000000000 +0000
+++ my_ktorrent/apps/ktorrent/ktorrentcore.cpp   2006-06-13 09:12:04.000000000 +0000
@@ -616,6 +616,16 @@
    return Settings::maxDownloadRate();
 }
 
+void KTorrentCore::setMaxUploadSpeed(int v)
+{
+   return Settings::setMaxUploadRate(v);
+}
+
+void KTorrentCore::setMaxDownloadSpeed(int v)
+{
+   return Settings::setMaxDownloadRate(v);
+}
+
 void KTorrentCore::setPausedState(bool pause)
 {
    qman->setPausedState(pause);
diff -u -r ktorrent/apps/ktorrent/ktorrentcore.h my_ktorrent/apps/ktorrent/ktorrentcore.h
--- ktorrent/apps/ktorrent/ktorrentcore.h   2006-06-13 08:57:21.000000000 +0000
+++ my_ktorrent/apps/ktorrent/ktorrentcore.h   2006-06-13 09:10:58.000000000 +0000
@@ -191,7 +191,9 @@
    
    int getMaxDownloadSpeed();
    int getMaxUploadSpeed();
-   
+   void setMaxDownloadSpeed(int v);
+   void setMaxUploadSpeed(int v);
+
    void setPausedState(bool pause);
    
    kt::TorrentInterface* getTorFromNumber(int tornumber);
diff -u -r ktorrent/apps/ktorrent/trayicon.cpp my_ktorrent/apps/ktorrent/trayicon.cpp
--- ktorrent/apps/ktorrent/trayicon.cpp   2006-06-13 08:57:21.000000000 +0000
+++ my_ktorrent/apps/ktorrent/trayicon.cpp   2006-06-13 09:30:56.000000000 +0000
@@ -85,4 +85,54 @@
    KPassivePopup::message(i18n("Torrent moved to download panel"), i18n("<b>%1</b> torrent has been moved to download panel.").arg(s.torrent_name),loadIcon("ktorrent"), this);
 }
 
+SetMaxRate::SetMaxRate( KTorrentCore* tc, int t, QWidget *parent, const char *name):KPopupMenu(parent, name)
+{
+   m_core = tc;
+   type=t;
+   makeMenu();
+   connect(this,SIGNAL(activated (int)),this,SLOT(rateSelected(int )));
+}
+void SetMaxRate::makeMenu(){
+   int rate=(type==0) ? m_core->getMaxUploadSpeed() : m_core->getMaxDownloadSpeed();
+   insertTitle("max rate in kb/s");
+   int maxBandwidth=(rate <= 0) ? 500 : rate;
+   insertItem(i18n("Unlimited"));
+   int delta = 0;
+        for (int i = 0; i < 10; i++) {
+            QValueList<int> valuePair;
+              if (delta == 0)
+                valuePair.append(maxBandwidth);
+              else{
+                valuePair.append(maxBandwidth - delta);
+      valuePair.append(maxBandwidth + delta);
+      }
+
+              for (int j = 0; j < (int)valuePair.count(); j++) {
+                if (valuePair[j] >= 5) {
+       insertItem(QString("%1").arg(valuePair[j]),-1, (j == 0) ? 2 : count());
+                }
+              }
+
+              delta += (delta >= 30) ? 50 : (delta >= 10) ? 10 : (delta >= 5) ? 5 : (delta >= 2) ? 3 : 1;
+        }
+}
+void SetMaxRate::update(){
+   clear();
+   makeMenu();
+}
+
+void SetMaxRate::rateSelected(int id){
+   int rate;
+   if(text(id).contains("Unlimited"))
+      rate=0;
+   else
+      rate=text(id).toInt();
+
+   if(type==0)
+      m_core->setMaxUploadSpeed(rate);
+   else
+      m_core->setMaxDownloadSpeed(rate);
+   
+   update();
+}
 #include "trayicon.moc"
diff -u -r ktorrent/apps/ktorrent/trayicon.h my_ktorrent/apps/ktorrent/trayicon.h
--- ktorrent/apps/ktorrent/trayicon.h   2006-06-13 08:57:21.000000000 +0000
+++ my_ktorrent/apps/ktorrent/trayicon.h   2006-06-13 09:18:18.000000000 +0000
@@ -22,6 +22,7 @@
 #define TRAYICON_H
 
 #include <ksystemtray.h>
+#include <kpopupmenu.h>
 
 #include "ktorrentcore.h"
 #include "interfaces/torrentinterface.h"
@@ -62,4 +63,20 @@
    KTorrentCore* m_core;
 };
 
+class SetMaxRate : public KPopupMenu
+{
+   Q_OBJECT
+public:
+   SetMaxRate(KTorrentCore* tc, int t, QWidget *parent=0, const char *name=0); // type: 0 Upload; 1 Download
+   ~SetMaxRate(){};
+
+   void update();   
+private:
+   KTorrentCore* m_core;
+   int type;
+   void makeMenu();
+private slots:
+   void rateSelected(int id);
+};
+
 #endif
Sho
Registered Member
Posts
7
Karma
0

Tue Jun 13, 2006 8:31 pm
Discussion of the patch on BKO: http://bugs.kde.org/show_bug.cgi?id=129076


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]