File: scanfolderplugin.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 (93 lines) | stat: -rw-r--r-- 2,586 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
/*
    SPDX-FileCopyrightText: 2006 Ivan Vasić <ivasic@gmail.com>
    SPDX-License-Identifier: GPL-2.0-or-later
*/

#include <interfaces/coreinterface.h>
#include <interfaces/guiinterface.h>
#include <interfaces/plugin.h>
#include <util/constants.h>
#include <util/functions.h>
#include <util/log.h>
#include <util/logsystemmanager.h>

#include <QDir>

#include <KLocalizedString>
#include <KPluginFactory>

#include "scanfolder.h"
#include "scanfolderplugin.h"
#include "scanfolderpluginsettings.h"
#include "scanfolderprefpage.h"
#include "scanthread.h"
#include "torrentloadqueue.h"

using namespace bt;

K_PLUGIN_CLASS_WITH_JSON(kt::ScanFolderPlugin, "ktorrent_scanfolder.json")

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

ScanFolderPlugin::~ScanFolderPlugin()
{
}

void ScanFolderPlugin::load()
{
    LogSystemManager::instance().registerSystem(i18nc("plugin name", "Scan Folder"), SYS_SNF);
    tlq = new TorrentLoadQueue(getCore(), this);
    scanner = new ScanThread();
    connect(scanner, &ScanThread::found, tlq, qOverload<const QList<QUrl> &>(&TorrentLoadQueue::add), Qt::QueuedConnection);
    pref = new ScanFolderPrefPage(this, nullptr);
    getGUI()->addPrefPage(pref);
    connect(getCore(), &CoreInterface::settingsChanged, this, &ScanFolderPlugin::updateScanFolders);
    scanner->start(QThread::IdlePriority);
    updateScanFolders();
}

void ScanFolderPlugin::unload()
{
    LogSystemManager::instance().unregisterSystem(i18nc("plugin name", "Scan Folder"));
    disconnect(getCore(), &CoreInterface::settingsChanged, this, &ScanFolderPlugin::updateScanFolders);
    getGUI()->removePrefPage(pref);
    scanner->stop();
    delete scanner;
    scanner = nullptr;
    delete pref;
    pref = nullptr;
    delete tlq;
    tlq = nullptr;
}

void ScanFolderPlugin::updateScanFolders()
{
    QStringList folders = ScanFolderPluginSettings::folders();

    // make sure folders end with /
    for (QString &s : folders) {
        if (s.endsWith(bt::DirSeparator()))
            s += bt::DirSeparator();
    }

    if (ScanFolderPluginSettings::actionDelete())
        tlq->setLoadedTorrentAction(DeleteAction);
    else if (ScanFolderPluginSettings::actionMove())
        tlq->setLoadedTorrentAction(MoveAction);
    else
        tlq->setLoadedTorrentAction(DefaultAction);

    scanner->setRecursive(ScanFolderPluginSettings::recursive());
    scanner->setFolderList(folders);
}

}

#include "scanfolderplugin.moc"

#include "moc_scanfolderplugin.cpp"