Skip to content
Permalink
Browse files

SkTorrent: Create WBackendCache

  • Loading branch information...
3unjee committed Sep 13, 2019
1 parent cdfc362 commit 4835b064f5a0f03a5178a8bd63d642ad7845913c
@@ -69,6 +69,11 @@
- WBackendTorrent: Fix the 'isEmpty' implementation.


## SkTorrent

- Create WBackendCache.


## SkyComponents

- Create TextSubtitle.
@@ -1,5 +1,6 @@
#ifndef SKBACKEND_H
#define SKBACKEND_H
#include "WBackendCache.h"
#include "WBackendBing.h"
#include "WBackendDailymotion.h"
#include "WBackendDuckDuckGo.h"
@@ -1,5 +1,6 @@
#ifndef SKBACKEND_H
#define SKBACKEND_H
#include "WBackendCache.h"
#include "WBackendBing.h"
#include "WBackendDailymotion.h"
#include "WBackendDuckDuckGo.h"
@@ -0,0 +1 @@
#include "../../src/SkBackend/src/io/WBackendCache.h"
@@ -0,0 +1 @@
#include "../../src/SkBackend/src/io/WBackendCache.h"
@@ -38,21 +38,26 @@ QMAKE_CXXFLAGS += -std=c++11
unix:QMAKE_LFLAGS += "-Wl,-rpath,'\$$ORIGIN'"

include(src/media/media.pri)
include(src/io/io.pri)

INCLUDEPATH += $$SK/include/SkCore \
$$SK/include/SkCore/private \
$$SK/include/SkGui \
$$SK/include/SkGui/private \
$$SK/include/SkTorrent \
$$SK/include/SkTorrent/private \
$$SK/include/SkBackend \
$$SK/include/SkBackend/private \

CONFIG(debug, debug|release) {

LIBS += -L$$SK/lib -lSkCoreD \
-L$$SK/lib -lSkGuiD
-L$$SK/lib -lSkGuiD \
-L$$SK/lib -lSkTorrentD
} else {
LIBS += -L$$SK/lib -lSkCore \
-L$$SK/lib -lSkGui
-L$$SK/lib -lSkGui \
-L$$SK/lib -lSkTorrent
}

macx {
@@ -0,0 +1,158 @@
//=================================================================================================
/*
Copyright (C) 2015-2017 Sky kit authors united with omega. <http://omega.gg/about>
Author: Benjamin Arnaud. <http://bunjee.me> <bunjee@omega.gg>
This file is part of the SkBackend module of Sky kit.
- GNU General Public License Usage:
This file may be used under the terms of the GNU General Public License version 3 as published
by the Free Software Foundation and appearing in the LICENSE.md file included in the packaging
of this file. Please review the following information to ensure the GNU General Public License
requirements will be met: https://www.gnu.org/licenses/gpl.html.
*/
//=================================================================================================

#include "WBackendCache.h"

#ifndef SK_NO_BACKENDCACHE

// Sk includes
#include <WBackendUniversal>

//-------------------------------------------------------------------------------------------------
// Static variables

static const int BACKENDCACHE_MAX = 20;

//-------------------------------------------------------------------------------------------------
// Private
//-------------------------------------------------------------------------------------------------

class SK_BACKEND_EXPORT WBackendCachePrivate : public WPrivate
{
public:
WBackendCachePrivate(WBackendCache * p);

void init();

public: // Functions
void updateScripts();

public: // Variables
QHash<QString, WBackendUniversalScript> scripts;

QStringList names;

int maxCount;

protected:
W_DECLARE_PUBLIC(WBackendCache)
};

//-------------------------------------------------------------------------------------------------

WBackendCachePrivate::WBackendCachePrivate(WBackendCache * p) : WPrivate(p) {}

void WBackendCachePrivate::init()
{
maxCount = BACKENDCACHE_MAX;
}

//-------------------------------------------------------------------------------------------------
// Private functions
//-------------------------------------------------------------------------------------------------

void WBackendCachePrivate::updateScripts()
{
while (names.count() > BACKENDCACHE_MAX)
{
scripts.remove(names.takeFirst());
}
}

//-------------------------------------------------------------------------------------------------
// Ctor / dtor
//-------------------------------------------------------------------------------------------------

WBackendCache::WBackendCache(QObject * parent)
: QObject(parent), WPrivatable(new WBackendCachePrivate(this))
{
Q_D(WBackendCache); d->init();
}

//-------------------------------------------------------------------------------------------------
// Interface
//-------------------------------------------------------------------------------------------------

/* Q_INVOKABLE */ WBackendUniversalScript * WBackendCache::getScript(const QString & name,
const QString & data)
{
Q_D(WBackendCache);

QHash<QString, WBackendUniversalScript>::iterator i = d->scripts.find(name);

if (i != d->scripts.end())
{
qDebug("SCRIPT CACHED");

d->names.removeOne(name);
d->names.append (name);

return &(i.value());
}

WBackendUniversalScript script(data);

i = d->scripts.insert(name, script);

d->names.append(name);

d->updateScripts();

return &(i.value());
}

/* Q_INVOKABLE */ void WBackendCache::removeScripts(const QString & pattern)
{
Q_D(WBackendCache);

QMutableHashIterator<QString, WBackendUniversalScript> i(d->scripts);

while (i.hasNext())
{
i.next();

QString name = i.key();

if (name.startsWith(pattern))
{
d->names.removeOne(name);

i.remove();
}
}
}

//-------------------------------------------------------------------------------------------------
// Properties
//-------------------------------------------------------------------------------------------------

int WBackendCache::maxCount() const
{
Q_D(const WBackendCache); return d->maxCount;
}

void WBackendCache::setMaxCount(int max)
{
Q_D(WBackendCache);

if (d->maxCount == max) return;

d->maxCount = max;

emit maxCountChanged();
}

#endif // SK_NO_BACKENDCACHE
@@ -0,0 +1,58 @@
//=================================================================================================
/*
Copyright (C) 2015-2017 Sky kit authors united with omega. <http://omega.gg/about>
Author: Benjamin Arnaud. <http://bunjee.me> <bunjee@omega.gg>
This file is part of the SkBackend module of Sky kit.
- GNU General Public License Usage:
This file may be used under the terms of the GNU General Public License version 3 as published
by the Free Software Foundation and appearing in the LICENSE.md file included in the packaging
of this file. Please review the following information to ensure the GNU General Public License
requirements will be met: https://www.gnu.org/licenses/gpl.html.
*/
//=================================================================================================

#ifndef WBACKENDCACHE_H
#define WBACKENDCACHE_H

// Qt includes
#include <QObject>

// Sk includes
#include <Sk>

#ifndef SK_NO_BACKENDCACHE

// Forward declarations
class WBackendCachePrivate;
class WBackendUniversalScript;

class SK_BACKEND_EXPORT WBackendCache : public QObject, public WPrivatable
{
Q_OBJECT

Q_PROPERTY(int maxCount READ maxCount WRITE setMaxCount NOTIFY maxCountChanged)

public:
explicit WBackendCache(QObject * parent = NULL);

public: // Interface
Q_INVOKABLE WBackendUniversalScript * getScript(const QString & name, const QString & data);

Q_INVOKABLE void removeScripts(const QString & pattern);

signals:
void maxCountChanged();

public: // Properties
int maxCount() const;
void setMaxCount(int max);

private:
W_DECLARE_PRIVATE(WBackendCache)
};

#endif // SK_NO_BACKENDCACHE
#endif // WBACKENDCACHE_H

0 comments on commit 4835b06

Please sign in to comment.
You can’t perform that action at this time.