From 12f4c7bd19306aa4edaaba4e86c8020c3ef05a5c Mon Sep 17 00:00:00 2001
From: Akira Ohgaki <akiraohgaki@gmail.com>
Date: Sat, 10 Dec 2016 07:20:38 +0900
Subject: [PATCH] Update qtlib

---
 src/lib/qtlib/README.md                     |  7 ++++
 src/lib/qtlib/README.txt                    |  1 -
 src/lib/qtlib/qtlib-test.pro                |  2 +-
 src/lib/qtlib/src/qtlib_config.cpp          | 11 ++----
 src/lib/qtlib/src/qtlib_config.h            |  6 ++--
 src/lib/qtlib/src/qtlib_dir.cpp             | 26 ++++++--------
 src/lib/qtlib/src/qtlib_dir.h               |  6 ++--
 src/lib/qtlib/src/qtlib_file.cpp            | 18 ++++------
 src/lib/qtlib/src/qtlib_file.h              |  6 ++--
 src/lib/qtlib/src/qtlib_json.cpp            | 27 +++++---------
 src/lib/qtlib/src/qtlib_json.h              |  6 ++--
 src/lib/qtlib/src/qtlib_networkresource.cpp |  6 ++--
 src/lib/qtlib/src/qtlib_networkresource.h   |  6 ++--
 src/lib/qtlib/src/qtlib_ocsapi.cpp          |  6 ++--
 src/lib/qtlib/src/qtlib_ocsapi.h            |  6 ++--
 src/lib/qtlib/src/qtlib_package.cpp         | 40 ++++++++++-----------
 src/lib/qtlib/src/qtlib_package.h           |  6 ++--
 17 files changed, 75 insertions(+), 111 deletions(-)
 create mode 100644 src/lib/qtlib/README.md
 delete mode 100644 src/lib/qtlib/README.txt

diff --git a/src/lib/qtlib/README.md b/src/lib/qtlib/README.md
new file mode 100644
index 0000000..5bc3150
--- /dev/null
+++ b/src/lib/qtlib/README.md
@@ -0,0 +1,7 @@
+# qtlib
+
+A library for Qt app
+
+Copyright: Akira Ohgaki
+
+License: LGPL-3+
diff --git a/src/lib/qtlib/README.txt b/src/lib/qtlib/README.txt
deleted file mode 100644
index 3dc2fdf..0000000
--- a/src/lib/qtlib/README.txt
+++ /dev/null
@@ -1 +0,0 @@
-A library for Qt app
diff --git a/src/lib/qtlib/qtlib-test.pro b/src/lib/qtlib/qtlib-test.pro
index 6d61b4c..7769787 100644
--- a/src/lib/qtlib/qtlib-test.pro
+++ b/src/lib/qtlib/qtlib-test.pro
@@ -10,4 +10,4 @@ QT += core
 
 SOURCES += test/main.cpp
 
-DISTFILES += README.txt
+DISTFILES += README.md
diff --git a/src/lib/qtlib/src/qtlib_config.cpp b/src/lib/qtlib/src/qtlib_config.cpp
index 6a06a5d..0c7b396 100644
--- a/src/lib/qtlib/src/qtlib_config.cpp
+++ b/src/lib/qtlib/src/qtlib_config.cpp
@@ -1,11 +1,9 @@
 /**
- * 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
diff --git a/src/lib/qtlib/src/qtlib_config.h b/src/lib/qtlib/src/qtlib_config.h
index 87b9d5f..456a9b6 100644
--- a/src/lib/qtlib/src/qtlib_config.h
+++ b/src/lib/qtlib/src/qtlib_config.h
@@ -1,11 +1,9 @@
 /**
- * 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
  */
 
diff --git a/src/lib/qtlib/src/qtlib_dir.cpp b/src/lib/qtlib/src/qtlib_dir.cpp
index 57e3768..94512f2 100644
--- a/src/lib/qtlib/src/qtlib_dir.cpp
+++ b/src/lib/qtlib/src/qtlib_dir.cpp
@@ -1,11 +1,9 @@
 /**
- * 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);
diff --git a/src/lib/qtlib/src/qtlib_dir.h b/src/lib/qtlib/src/qtlib_dir.h
index 000c0e6..a8b5a5e 100644
--- a/src/lib/qtlib/src/qtlib_dir.h
+++ b/src/lib/qtlib/src/qtlib_dir.h
@@ -1,11 +1,9 @@
 /**
- * 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
  */
 
diff --git a/src/lib/qtlib/src/qtlib_file.cpp b/src/lib/qtlib/src/qtlib_file.cpp
index ad074fb..ac4f740 100644
--- a/src/lib/qtlib/src/qtlib_file.cpp
+++ b/src/lib/qtlib/src/qtlib_file.cpp
@@ -1,11 +1,9 @@
 /**
- * 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
diff --git a/src/lib/qtlib/src/qtlib_file.h b/src/lib/qtlib/src/qtlib_file.h
index 23a83fc..5804b19 100644
--- a/src/lib/qtlib/src/qtlib_file.h
+++ b/src/lib/qtlib/src/qtlib_file.h
@@ -1,11 +1,9 @@
 /**
- * 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
  */
 
diff --git a/src/lib/qtlib/src/qtlib_json.cpp b/src/lib/qtlib/src/qtlib_json.cpp
index 8a3c771..49faa10 100644
--- a/src/lib/qtlib/src/qtlib_json.cpp
+++ b/src/lib/qtlib/src/qtlib_json.cpp
@@ -1,11 +1,9 @@
 /**
- * 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
diff --git a/src/lib/qtlib/src/qtlib_json.h b/src/lib/qtlib/src/qtlib_json.h
index 7072bd2..5cb9a60 100644
--- a/src/lib/qtlib/src/qtlib_json.h
+++ b/src/lib/qtlib/src/qtlib_json.h
@@ -1,11 +1,9 @@
 /**
- * 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
  */
 
diff --git a/src/lib/qtlib/src/qtlib_networkresource.cpp b/src/lib/qtlib/src/qtlib_networkresource.cpp
index e2ac963..9b26e29 100644
--- a/src/lib/qtlib/src/qtlib_networkresource.cpp
+++ b/src/lib/qtlib/src/qtlib_networkresource.cpp
@@ -1,11 +1,9 @@
 /**
- * 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
  */
 
diff --git a/src/lib/qtlib/src/qtlib_networkresource.h b/src/lib/qtlib/src/qtlib_networkresource.h
index 1e5c019..038f96e 100644
--- a/src/lib/qtlib/src/qtlib_networkresource.h
+++ b/src/lib/qtlib/src/qtlib_networkresource.h
@@ -1,11 +1,9 @@
 /**
- * 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
  */
 
diff --git a/src/lib/qtlib/src/qtlib_ocsapi.cpp b/src/lib/qtlib/src/qtlib_ocsapi.cpp
index 77c217a..f9f345d 100644
--- a/src/lib/qtlib/src/qtlib_ocsapi.cpp
+++ b/src/lib/qtlib/src/qtlib_ocsapi.cpp
@@ -1,11 +1,9 @@
 /**
- * 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
  */
 
diff --git a/src/lib/qtlib/src/qtlib_ocsapi.h b/src/lib/qtlib/src/qtlib_ocsapi.h
index 0ab08eb..93346d8 100644
--- a/src/lib/qtlib/src/qtlib_ocsapi.h
+++ b/src/lib/qtlib/src/qtlib_ocsapi.h
@@ -1,11 +1,9 @@
 /**
- * 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
  */
 
diff --git a/src/lib/qtlib/src/qtlib_package.cpp b/src/lib/qtlib/src/qtlib_package.cpp
index 570d69f..fde7612 100644
--- a/src/lib/qtlib/src/qtlib_package.cpp
+++ b/src/lib/qtlib/src/qtlib_package.cpp
@@ -1,11 +1,9 @@
 /**
- * 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;
diff --git a/src/lib/qtlib/src/qtlib_package.h b/src/lib/qtlib/src/qtlib_package.h
index 3210823..e5bd112 100644
--- a/src/lib/qtlib/src/qtlib_package.h
+++ b/src/lib/qtlib/src/qtlib_package.h
@@ -1,11 +1,9 @@
 /**
- * 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
  */
 
-- 
GitLab