File: StatsPlugin.cc

package info (click to toggle)
ktorrent 5.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 22,864 kB
  • sloc: cpp: 44,654; javascript: 1,668; ansic: 968; xml: 905; python: 560; ruby: 161; sh: 10; makefile: 7
file content (111 lines) | stat: -rw-r--r-- 3,978 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/***************************************************************************
 *   Copyright © 2007 by Krzysztof Kundzicz                                *
 *   athantor@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 <StatsPlugin.h>
#include <interfaces/torrentactivityinterface.h>
#include <KPluginFactory>

K_PLUGIN_FACTORY_WITH_JSON(ktorrent_stats, "ktorrent_stats.json", registerPlugin<kt::StatsPlugin>();)

namespace kt
{

    StatsPlugin::StatsPlugin(QObject* p, const QVariantList&) : Plugin(p), mUpdCtr(1)
    {
        pmUiSett = nullptr;
        pmDispSett = nullptr;
    }

    StatsPlugin::~StatsPlugin()
    {
    }

    void StatsPlugin::load()
    {
        pmUiSpd = new SpdTabPage(nullptr);
        pmUiConns = new ConnsTabPage(nullptr);
        pmUiSett = new SettingsPage(nullptr);
        pmDispSett = new DisplaySettingsPage(nullptr);

        TorrentActivityInterface* ta = getGUI()->getTorrentActivity();
        ta->addToolWidget(pmUiSpd, i18n("Speed charts"), QStringLiteral("view-statistics"), i18n("Displays charts about download and upload speed"));
        ta->addToolWidget(pmUiConns, i18n("Connections charts"), QStringLiteral("view-statistics"), i18n("Displays charts about connections"));

        getGUI()->addPrefPage(pmUiSett);
        getGUI()->addPrefPage(pmDispSett);

        connect(&pmTmr, SIGNAL(timeout()), dynamic_cast<StatsPlugin*>(this), SLOT(gatherData()));
        connect(getCore(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged()));

        pmTmr.start(StatsPluginSettings::dataGatherIval());

    }

    void StatsPlugin::unload()
    {
        TorrentActivityInterface* ta = getGUI()->getTorrentActivity();
        ta->removeToolWidget(pmUiSpd);
        ta->removeToolWidget(pmUiConns);

        getGUI()->removePrefPage(pmUiSett);
        getGUI()->removePrefPage(pmDispSett);

        pmTmr.stop();

        disconnect(&pmTmr);
        disconnect(getCore());
    }

    bool StatsPlugin::versionCheck(const QString& version) const
    {
        return version == QStringLiteral(KT_VERSION_MACRO);
    }

    void StatsPlugin::guiUpdate()
    {
        if (mUpdCtr >= StatsPluginSettings::updateEveryGuiUpdates())
        {
            pmUiSpd->updateAllCharts();
            pmUiConns->updateAllCharts();

            mUpdCtr = 1;
        }
        else
        {
            mUpdCtr++;
        }
    }

    void StatsPlugin::gatherData()
    {
        pmUiSpd->gatherData(this);
        pmUiConns->gatherData(this);
    }

    void StatsPlugin::settingsChanged()
    {
        pmTmr.setInterval(StatsPluginSettings::dataGatherIval());
        pmUiSpd->applySettings();
        pmUiConns->applySettings();
    }

} //Ns end

#include "StatsPlugin.moc"