Skip to content
Snippets Groups Projects
Commit 12f4c7bd authored by akiraohgaki's avatar akiraohgaki
Browse files

Update qtlib

parent e04fbdcc
No related branches found
No related tags found
No related merge requests found
Showing
with 75 additions and 111 deletions
# qtlib
A library for Qt app
Copyright: Akira Ohgaki
License: LGPL-3+
A library for Qt app
......@@ -10,4 +10,4 @@ QT += core
SOURCES += test/main.cpp
DISTFILES += README.txt
DISTFILES += README.md
/**
* A library for Qt app
*
* LICENSE: The GNU Lesser General Public License, version 3.0
* qtlib
*
* @author Akira Ohgaki <akiraohgaki@gmail.com>
* @copyright Akira Ohgaki
* @license https://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0
* @license https://opensource.org/licenses/LGPL-3.0
* @link https://github.com/akiraohgaki/qtlib
*/
......@@ -58,10 +56,7 @@ bool Config::set(const QString &name, const QJsonObject &object)
QString configFilePath = configDirPath() + "/" + name + ".json";
QByteArray json = qtlib::Json(object).toJson();
qtlib::Dir(configDirPath()).make();
if (qtlib::File(configFilePath).writeData(json)) {
return true;
}
return false;
return qtlib::File(configFilePath).writeData(json);
}
} // namespace qtlib
/**
* A library for Qt app
*
* LICENSE: The GNU Lesser General Public License, version 3.0
* qtlib
*
* @author Akira Ohgaki <akiraohgaki@gmail.com>
* @copyright Akira Ohgaki
* @license https://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0
* @license https://opensource.org/licenses/LGPL-3.0
* @link https://github.com/akiraohgaki/qtlib
*/
......
/**
* A library for Qt app
*
* LICENSE: The GNU Lesser General Public License, version 3.0
* qtlib
*
* @author Akira Ohgaki <akiraohgaki@gmail.com>
* @copyright Akira Ohgaki
* @license https://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0
* @license https://opensource.org/licenses/LGPL-3.0
* @link https://github.com/akiraohgaki/qtlib
*/
......@@ -46,8 +44,7 @@ void Dir::setPath(const QString &path)
bool Dir::exists()
{
QDir dir(path());
return dir.exists();
return QDir(path()).exists();
}
QFileInfoList Dir::list()
......@@ -76,15 +73,13 @@ bool Dir::copy(const QString &newPath)
bool Dir::move(const QString &newPath)
{
QDir dir(path());
return dir.rename(path(), newPath);
return QDir(path()).rename(path(), newPath);
}
bool Dir::remove()
{
// This function will remove files recursively
QDir dir(path());
return dir.removeRecursively();
return QDir(path()).removeRecursively();
}
QString Dir::rootPath()
......@@ -133,11 +128,12 @@ QString Dir::kdehomePath()
bool Dir::copyRecursively(const QString &srcPath, const QString &newPath)
{
QFileInfo fileInfo(srcPath);
if (fileInfo.isFile()) {
QFile file(srcPath);
if (file.copy(newPath)) {
return true;
}
if (fileInfo.isSymLink() && !fileInfo.exists()) {
// Ignore broken symlink
return true;
}
else if (fileInfo.isFile()) {
return QFile(srcPath).copy(newPath);
}
else if (fileInfo.isDir()) {
QDir newDir(newPath);
......
/**
* A library for Qt app
*
* LICENSE: The GNU Lesser General Public License, version 3.0
* qtlib
*
* @author Akira Ohgaki <akiraohgaki@gmail.com>
* @copyright Akira Ohgaki
* @license https://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0
* @license https://opensource.org/licenses/LGPL-3.0
* @link https://github.com/akiraohgaki/qtlib
*/
......
/**
* A library for Qt app
*
* LICENSE: The GNU Lesser General Public License, version 3.0
* qtlib
*
* @author Akira Ohgaki <akiraohgaki@gmail.com>
* @copyright Akira Ohgaki
* @license https://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0
* @license https://opensource.org/licenses/LGPL-3.0
* @link https://github.com/akiraohgaki/qtlib
*/
......@@ -45,8 +43,7 @@ void File::setPath(const QString &path)
bool File::exists()
{
QFile file(path());
return file.exists();
return QFile(path()).exists();
}
QByteArray File::readData()
......@@ -99,20 +96,17 @@ bool File::writeText(const QString &data)
bool File::copy(const QString &newPath)
{
QFile file(path());
return file.copy(newPath);
return QFile(path()).copy(newPath);
}
bool File::move(const QString &newPath)
{
QFile file(path());
return file.rename(newPath);
return QFile(path()).rename(newPath);
}
bool File::remove()
{
QFile file(path());
return file.remove();
return QFile(path()).remove();
}
} // namespace qtlib
/**
* A library for Qt app
*
* LICENSE: The GNU Lesser General Public License, version 3.0
* qtlib
*
* @author Akira Ohgaki <akiraohgaki@gmail.com>
* @copyright Akira Ohgaki
* @license https://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0
* @license https://opensource.org/licenses/LGPL-3.0
* @link https://github.com/akiraohgaki/qtlib
*/
......
/**
* A library for Qt app
*
* LICENSE: The GNU Lesser General Public License, version 3.0
* qtlib
*
* @author Akira Ohgaki <akiraohgaki@gmail.com>
* @copyright Akira Ohgaki
* @license https://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0
* @license https://opensource.org/licenses/LGPL-3.0
* @link https://github.com/akiraohgaki/qtlib
*/
......@@ -56,32 +54,27 @@ void Json::setJson(const QByteArray &json)
void Json::fromObject(const QJsonObject &object)
{
QJsonDocument doc(object);
setJson(doc.toJson());
setJson(QJsonDocument(object).toJson());
}
void Json::fromArray(const QJsonArray &array)
{
QJsonDocument doc(array);
setJson(doc.toJson());
setJson(QJsonDocument(array).toJson());
}
QByteArray Json::toJson()
{
QJsonDocument doc = QJsonDocument::fromJson(json());
return doc.toJson();
return QJsonDocument::fromJson(json()).toJson();
}
QJsonObject Json::toObject()
{
QJsonDocument doc = QJsonDocument::fromJson(json());
return doc.object();
return QJsonDocument::fromJson(json()).object();
}
QJsonArray Json::toArray()
{
QJsonDocument doc = QJsonDocument::fromJson(json());
return doc.array();
return QJsonDocument::fromJson(json()).array();
}
bool Json::isValid()
......@@ -96,14 +89,12 @@ bool Json::isValid()
bool Json::isObject()
{
QJsonDocument doc = QJsonDocument::fromJson(json());
return doc.isObject();
return QJsonDocument::fromJson(json()).isObject();
}
bool Json::isArray()
{
QJsonDocument doc = QJsonDocument::fromJson(json());
return doc.isArray();
return QJsonDocument::fromJson(json()).isArray();
}
} // namespace qtlib
/**
* A library for Qt app
*
* LICENSE: The GNU Lesser General Public License, version 3.0
* qtlib
*
* @author Akira Ohgaki <akiraohgaki@gmail.com>
* @copyright Akira Ohgaki
* @license https://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0
* @license https://opensource.org/licenses/LGPL-3.0
* @link https://github.com/akiraohgaki/qtlib
*/
......
/**
* A library for Qt app
*
* LICENSE: The GNU Lesser General Public License, version 3.0
* qtlib
*
* @author Akira Ohgaki <akiraohgaki@gmail.com>
* @copyright Akira Ohgaki
* @license https://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0
* @license https://opensource.org/licenses/LGPL-3.0
* @link https://github.com/akiraohgaki/qtlib
*/
......
/**
* A library for Qt app
*
* LICENSE: The GNU Lesser General Public License, version 3.0
* qtlib
*
* @author Akira Ohgaki <akiraohgaki@gmail.com>
* @copyright Akira Ohgaki
* @license https://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0
* @license https://opensource.org/licenses/LGPL-3.0
* @link https://github.com/akiraohgaki/qtlib
*/
......
/**
* A library for Qt app
*
* LICENSE: The GNU Lesser General Public License, version 3.0
* qtlib
*
* @author Akira Ohgaki <akiraohgaki@gmail.com>
* @copyright Akira Ohgaki
* @license https://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0
* @license https://opensource.org/licenses/LGPL-3.0
* @link https://github.com/akiraohgaki/qtlib
*/
......
/**
* A library for Qt app
*
* LICENSE: The GNU Lesser General Public License, version 3.0
* qtlib
*
* @author Akira Ohgaki <akiraohgaki@gmail.com>
* @copyright Akira Ohgaki
* @license https://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0
* @license https://opensource.org/licenses/LGPL-3.0
* @link https://github.com/akiraohgaki/qtlib
*/
......
/**
* A library for Qt app
*
* LICENSE: The GNU Lesser General Public License, version 3.0
* qtlib
*
* @author Akira Ohgaki <akiraohgaki@gmail.com>
* @copyright Akira Ohgaki
* @license https://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0
* @license https://opensource.org/licenses/LGPL-3.0
* @link https://github.com/akiraohgaki/qtlib
*/
......@@ -86,8 +84,7 @@ bool Package::installAsArchive(const QString &destinationDirPath)
archiveTypes["application/x-rar"] = QString("rar");
archiveTypes["application/x-rar-compressed"] = QString("rar");
QMimeDatabase mimeDb;
QString mimeType = mimeDb.mimeTypeForFile(path()).name();
QString mimeType = QMimeDatabase().mimeTypeForFile(path()).name();
if (archiveTypes.contains(mimeType)) {
QString archiveType = archiveTypes[mimeType].toString();
......@@ -132,23 +129,26 @@ bool Package::uninstallAsPlasmapkg(const QString &type)
#ifdef Q_OS_ANDROID
bool Package::installAsApk()
{
/*
String apkFile = "/path/to/package.apk";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(apkFile)), "application/vnd.android.package-archive");
startActivity(intent);
*/
QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");
if (activity.isValid()) {
QAndroidJniObject fileUri = QAndroidJniObject::fromString(path());
QAndroidJniObject parsedUri = QAndroidJniObject::callStaticObjectMethod("android/net/Uri", "parse", "(Ljava/lang/String;)Landroid/net/Uri;", fileUri.object());
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 activityKind = QAndroidJniObject::fromString("android.intent.action.VIEW");
QAndroidJniObject intent("android/content/Intent", "(Ljava/lang/String;)V", activityKind.object());
intent = intent.callObjectMethod("setDataAndType", "(Landroid/net/Uri;Ljava/lang/String;)Landroid/content/Intent;", parsedUri.object(), mimeType.object());
intent = intent.callObjectMethod("setFlags", "(I)Landroid/content/Intent;", 0x10000000); // 0x10000000 = FLAG_ACTIVITY_NEW_TASK
activity.callObjectMethod("startActivity", "(Landroid/content/Intent;)V", intent.object());
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;
......
/**
* A library for Qt app
*
* LICENSE: The GNU Lesser General Public License, version 3.0
* qtlib
*
* @author Akira Ohgaki <akiraohgaki@gmail.com>
* @copyright Akira Ohgaki
* @license https://opensource.org/licenses/LGPL-3.0 The GNU Lesser General Public License, version 3.0
* @license https://opensource.org/licenses/LGPL-3.0
* @link https://github.com/akiraohgaki/qtlib
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment