File: logviewerplugin.cpp

package info (click to toggle)
ktorrent 25.04.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 25,104 kB
  • sloc: cpp: 40,482; xml: 1,163; python: 182; sh: 10; makefile: 5
file content (129 lines) | stat: -rw-r--r-- 3,233 bytes parent folder | download
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
    SPDX-FileCopyrightText: 2005-2007 Joris Guisson <joris.guisson@gmail.com>
    SPDX-License-Identifier: GPL-2.0-or-later
*/

#include <QDockWidget>

#include <KLocalizedString>
#include <KMainWindow>
#include <KPluginFactory>

#include "logflags.h"
#include "logprefpage.h"
#include "logviewer.h"
#include "logviewerplugin.h"
#include "logviewerpluginsettings.h"
#include <interfaces/coreinterface.h>
#include <interfaces/guiinterface.h>
#include <interfaces/torrentactivityinterface.h>
#include <torrent/globals.h>
#include <util/log.h>

using namespace bt;

K_PLUGIN_CLASS_WITH_JSON(kt::LogViewerPlugin, "ktorrent_logviewer.json")

namespace kt
{
LogViewerPlugin::LogViewerPlugin(QObject *parent, const KPluginMetaData &data, const QVariantList &args)
    : Plugin(parent, data, args)
{
}

LogViewerPlugin::~LogViewerPlugin()
{
}

void LogViewerPlugin::load()
{
    connect(getCore(), &CoreInterface::settingsChanged, this, &LogViewerPlugin::applySettings);
    flags = new LogFlags();
    lv = new LogViewer(flags);
    pref = new LogPrefPage(flags, nullptr);

    pos = (LogViewerPosition)LogViewerPluginSettings::logWidgetPosition();
    addLogViewerToGUI();
    getGUI()->addPrefPage(pref);
    AddLogMonitor(lv);
    applySettings();
}

void LogViewerPlugin::unload()
{
    pref->saveState();
    disconnect(getCore(), &CoreInterface::settingsChanged, this, &LogViewerPlugin::applySettings);
    getGUI()->removePrefPage(pref);
    removeLogViewerFromGUI();
    RemoveLogMonitor(lv);
    delete lv;
    lv = nullptr;
    delete pref;
    pref = nullptr;
    delete flags;
    flags = nullptr;
}

void LogViewerPlugin::applySettings()
{
    lv->setRichText(LogViewerPluginSettings::useRichText());
    lv->setMaxBlockCount(LogViewerPluginSettings::maxBlockCount());
    LogViewerPosition p = (LogViewerPosition)LogViewerPluginSettings::logWidgetPosition();
    if (pos != p) {
        removeLogViewerFromGUI();
        pos = p;
        addLogViewerToGUI();
    }
}

void LogViewerPlugin::addLogViewerToGUI()
{
    switch (pos) {
    case SEPARATE_ACTIVITY:
        getGUI()->addActivity(lv);
        break;
    case DOCKABLE_WIDGET: {
        KMainWindow *mwnd = getGUI()->getMainWindow();
        dock = new QDockWidget(mwnd);
        dock->setWidget(lv);
        dock->setObjectName(QStringLiteral("LogViewerDockWidget"));
        mwnd->addDockWidget(Qt::BottomDockWidgetArea, dock);
        break;
    }
    case TORRENT_ACTIVITY:
        getGUI()->getTorrentActivity()->addToolWidget(lv, lv->name(), lv->icon(), lv->toolTip());
        break;
    }
}

void LogViewerPlugin::removeLogViewerFromGUI()
{
    switch (pos) {
    case SEPARATE_ACTIVITY:
        getGUI()->removeActivity(lv);
        break;
    case TORRENT_ACTIVITY:
        getGUI()->getTorrentActivity()->removeToolWidget(lv);
        break;
    case DOCKABLE_WIDGET: {
        KMainWindow *mwnd = getGUI()->getMainWindow();
        mwnd->removeDockWidget(dock);
        dock->setWidget(nullptr);
        lv->setParent(nullptr);
        delete dock;
        dock = nullptr;
        break;
    }
    }
}

void LogViewerPlugin::guiUpdate()
{
    if (lv)
        lv->processPending();
}

}
#include "logviewerplugin.moc"

#include "moc_logviewerplugin.cpp"