Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • akiraohgaki/ocs-url
  • ab3875o/ocs-url
  • dembego3/ocs-url
  • arakun/ocs-url
  • longviauroy/ocs-url
  • rolfen/ocs-url
  • hemm/ocs-url
  • simonsvw0000/ocs-url
  • dfn2/ocs-url
  • rws77/ocs-url
  • bitwalk/ocs-url
  • visdom/ocs-url
  • ricatfarker/ocs-url
  • mussah/ocs-url
  • tigefa/ocs-url
  • cobalt2727/ocs-url
  • ammark226/ocs-url
  • violethaze74/ocs-url
  • armedssault/ocs-url
  • billflick/ocs-url
  • kimblejeremy/ocs-url
  • yuvrajsm/ocs-url
  • wawmart/ocs-url
  • jhefry/ocs-url
  • robcdntruckin/ocs-url
  • bigmake2266/ocs-url
  • kamil-chbeir/ocs-url
  • jocker73/ocs-url
  • laboties/ocs-url
  • smekke61279-522014/ocs-url
  • coolduck/ocs-url
  • zulfikar-lahiya/ocs-url
  • faz-83/ocs-url
  • dado105/ocs-url
34 results
Show changes
/**
* qtlib
*
* @author Akira Ohgaki <akiraohgaki@gmail.com>
* @copyright Akira Ohgaki
* @license https://opensource.org/licenses/LGPL-3.0
* @link https://github.com/akiraohgaki/qtlib
*/
#pragma once
#include <QObject>
#include <QUrl>
#include <QUrlQuery>
#include <QJsonObject>
#include <QJsonArray>
namespace qtlib {
class OcsApi : public QObject
{
Q_OBJECT
public:
explicit OcsApi(const QString &id = "", const QUrl &baseUrl = QUrl(), const QString &userName = "", const QString &password = "", QObject *parent = 0);
OcsApi(const OcsApi &other, QObject *parent = 0);
OcsApi &operator =(const OcsApi &other);
QString id() const;
void setId(const QString &id);
QUrl baseUrl() const;
void setBaseUrl(const QUrl &baseUrl);
QString userName() const;
void setUserName(const QString &userName);
QString password() const;
void setPassword(const QString &password);
QJsonObject getConfig();
QJsonObject checkPerson();
QJsonObject getPersonDataSet(const QUrlQuery &query = QUrlQuery());
QJsonObject getPersonData(const QString &personId);
QJsonObject getPersonSelf();
QJsonObject getContentCategories();
QJsonObject getContentDataSet(const QUrlQuery &query = QUrlQuery());
QJsonObject getContentData(const QString &contentId);
QJsonObject getContentDownload(const QString &contentId, const QString &itemId);
static QJsonArray getProviderFile(const QUrl &url);
private:
QString id_;
QUrl baseUrl_;
QString userName_;
QString password_;
};
} // namespace qtlib
/**
* qtlib
*
* @author Akira Ohgaki <akiraohgaki@gmail.com>
* @copyright Akira Ohgaki
* @license https://opensource.org/licenses/LGPL-3.0
* @link https://github.com/akiraohgaki/qtlib
*/
#include "qtlib_package.h"
#ifdef QTLIB_UNIX
#include <QJsonObject>
#include <QMimeDatabase>
#include <QProcess>
#endif
#ifdef Q_OS_ANDROID
#include <QAndroidJniObject>
#endif
namespace qtlib {
Package::Package(const QString &path, QObject *parent)
: QObject(parent), path_(path)
{}
Package::Package(const Package &other, QObject *parent)
: QObject(parent)
{
setPath(other.path());
}
Package &Package::operator =(const Package &other)
{
setPath(other.path());
return *this;
}
QString Package::path() const
{
return path_;
}
void Package::setPath(const QString &path)
{
path_ = path;
}
#ifdef QTLIB_UNIX
bool Package::installAsProgram(const QString &newPath)
{
QStringList arguments;
arguments << "-m" << "755" << "-p" << path() << newPath;
return execute("install", arguments);
}
bool Package::installAsFile(const QString &newPath)
{
QStringList arguments;
arguments << "-m" << "644" << "-p" << path() << newPath;
return execute("install", arguments);
}
bool Package::installAsArchive(const QString &destinationDirPath)
{
QJsonObject archiveTypes;
archiveTypes["application/x-tar"] = QString("tar");
archiveTypes["application/x-gzip"] = QString("tar");
archiveTypes["application/gzip"] = QString("tar");
archiveTypes["application/x-bzip"] = QString("tar");
archiveTypes["application/x-bzip2"] = QString("tar");
archiveTypes["application/x-xz"] = QString("tar");
archiveTypes["application/x-lzma"] = QString("tar");
archiveTypes["application/x-lzip"] = QString("tar");
archiveTypes["application/x-compressed-tar"] = QString("tar");
archiveTypes["application/x-bzip-compressed-tar"] = QString("tar");
archiveTypes["application/x-bzip2-compressed-tar"] = QString("tar");
archiveTypes["application/x-xz-compressed-tar"] = QString("tar");
archiveTypes["application/x-lzma-compressed-tar"] = QString("tar");
archiveTypes["application/x-lzip-compressed-tar"] = QString("tar");
archiveTypes["application/zip"] = QString("zip");
archiveTypes["application/x-7z-compressed"] = QString("7z");
archiveTypes["application/x-rar"] = QString("rar");
archiveTypes["application/x-rar-compressed"] = QString("rar");
QString mimeType = QMimeDatabase().mimeTypeForFile(path()).name();
if (archiveTypes.contains(mimeType)) {
QString archiveType = archiveTypes[mimeType].toString();
QString program;
QStringList arguments;
if (archiveType == "tar") {
program = "tar";
arguments << "-xf" << path() << "-C" << destinationDirPath;
}
else if (archiveType == "zip") {
program = "unzip";
arguments << "-o" << path() << "-d" << destinationDirPath;
}
else if (archiveType == "7z") {
program = "7z";
arguments << "x" << path() << "-o" + destinationDirPath; // No space between -o and directory
}
else if (archiveType == "rar") {
program = "unrar";
arguments << "e" << path() << destinationDirPath;
}
return execute(program, arguments);
}
return false;
}
bool Package::installAsPlasmapkg(const QString &type)
{
QStringList arguments;
arguments << "-t" << type << "-i" << path();
return execute("plasmapkg2", arguments);
}
bool Package::uninstallAsPlasmapkg(const QString &type)
{
QStringList arguments;
arguments << "-t" << type << "-r" << path();
return execute("plasmapkg2", arguments);
}
#endif
#ifdef Q_OS_ANDROID
bool Package::installAsApk()
{
QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");
if (activity.isValid()) {
QString filePath = path();
if (filePath.startsWith("file://", Qt::CaseInsensitive)) {
filePath.replace("file://localhost", "", Qt::CaseInsensitive);
filePath.replace("file://", "", Qt::CaseInsensitive);
}
QAndroidJniObject fileUri = QAndroidJniObject::fromString("file://" + filePath);
QAndroidJniObject uri = QAndroidJniObject::callStaticObjectMethod("android/net/Uri", "parse", "(Ljava/lang/String;)Landroid/net/Uri;", fileUri.object());
QAndroidJniObject mimeType = QAndroidJniObject::fromString("application/vnd.android.package-archive");
QAndroidJniObject ACTION_VIEW = QAndroidJniObject::getStaticObjectField("android/content/Intent", "ACTION_VIEW", "Ljava/lang/String");
QAndroidJniObject FLAG_ACTIVITY_NEW_TASK = QAndroidJniObject::getStaticObjectField("android/content/Intent", "FLAG_ACTIVITY_NEW_TASK", "Ljava/lang/Integer");
QAndroidJniObject intent("android/content/Intent", "(Ljava/lang/String;)V", ACTION_VIEW.object());
intent = intent.callObjectMethod("setDataAndType", "(Landroid/net/Uri;Ljava/lang/String;)Landroid/content/Intent;", uri.object(), mimeType.object());
intent = intent.callObjectMethod("setFlags", "(I)Landroid/content/Intent;", FLAG_ACTIVITY_NEW_TASK.object());
activity.callMethod<void>("startActivity", "(Landroid/content/Intent;)V", intent.object());
return true;
}
return false;
}
#endif
#ifdef QTLIB_UNIX
bool Package::execute(const QString &program, const QStringList &arguments)
{
QProcess process;
process.start(program, arguments);
if (process.waitForFinished()) {
process.waitForReadyRead();
return true;
}
return false;
}
#endif
} // namespace qtlib
/**
* qtlib
*
* @author Akira Ohgaki <akiraohgaki@gmail.com>
* @copyright Akira Ohgaki
* @license https://opensource.org/licenses/LGPL-3.0
* @link https://github.com/akiraohgaki/qtlib
*/
#pragma once
#include <QObject>
namespace qtlib {
class Package : public QObject
{
Q_OBJECT
public:
explicit Package(const QString &path = "", QObject *parent = 0);
Package(const Package &other, QObject *parent = 0);
Package &operator =(const Package &other);
QString path() const;
void setPath(const QString &path);
#ifdef QTLIB_UNIX
bool installAsProgram(const QString &newPath);
bool installAsFile(const QString &newPath);
bool installAsArchive(const QString &destinationDirPath);
bool installAsPlasmapkg(const QString &type = "plasmoid");
bool uninstallAsPlasmapkg(const QString &type = "plasmoid");
#endif
#ifdef Q_OS_ANDROID
bool installAsApk();
#endif
private:
#ifdef QTLIB_UNIX
bool execute(const QString &program, const QStringList &arguments);
#endif
QString path_;
};
} // namespace qtlib
#include <QObject>
#include <QCoreApplication>
#include <QDebug>
#include "qtlib_file.h"
#include "qtlib_dir.h"
#include "qtlib_json.h"
#include "qtlib_config.h"
#include "qtlib_networkresource.h"
#include "qtlib_ocsapi.h"
#include "qtlib_package.h"
class Test : public QObject
{
public:
Test() {}
virtual ~Test() {}
void start()
{
qDebug() << "Start";
qtlib::NetworkResource *resource = new qtlib::NetworkResource(
"LGPL-3.0",
QUrl("https://api.opensource.org/license/LGPL-3.0"),
false,
this);
connect(resource, &qtlib::NetworkResource::downloadProgress, this, &Test::downloadProgress);
QJsonObject result = qtlib::Json(resource->get()->readData()).toObject();
qDebug() << resource->id() << ":" << result["name"].toString();
connect(resource, &qtlib::NetworkResource::finished, this, &Test::finished);
resource->setId(result["name"].toString());
resource->setUrl(QUrl(result["text"].toArray()[0].toObject()["url"].toString()));
resource->setAsync(true);
resource->get();
}
public slots:
void finished(qtlib::NetworkResource *resource)
{
QString path = qtlib::Dir::tempPath() + "/" + resource->url().fileName();
resource->saveData(path);
qDebug() << "Downloaded" << resource->id() << ":" << path;
qDebug() << "Finished";
resource->deleteLater();
QCoreApplication::exit();
}
void downloadProgress(QString id, qint64 bytesReceived, qint64 bytesTotal)
{
qDebug() << "Progress" << id << ":" << bytesReceived << "/" << bytesTotal;
}
};
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
Test test;
test.start();
return app.exec();
}