diff --git a/src/lib/qtlib/README.md b/src/lib/qtlib/README.md new file mode 100644 index 0000000000000000000000000000000000000000..5bc3150bf26123efc35b3d2d486c12b0f694e1fa --- /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 3dc2fdfac1edac3d1aabefdcfbe1a3c857a5411a..0000000000000000000000000000000000000000 --- 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 6d61b4c4df5ba30cd28d593ae9949fb6a0cd5b1d..7769787444482c0c01b5367587f20104631aa8bf 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 6a06a5dc9c7f4848aec005c4b8cbfe5630cb3a4f..0c7b3961c1c5bd1b3ab30ae39831f16b4509fef9 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 87b9d5f9f9af77d397f61e186c7d7000730724b4..456a9b66b006d2f36ad00b3525472490f804725d 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 57e3768cf2d36e2ff35d5817b54b85376844706a..94512f234c894f92b502a7ab5814cb504a18fe7c 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 000c0e687915a8f44b6b5181058e4f56f92bdf5e..a8b5a5e4b1c9b0af56b80b7f43dfe88d04cdd30a 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 ad074fbbd90191fbd893fc36f8ed32d3b3f17d01..ac4f740f01ae1a302b9ea7b1cfc017b2cfa41db2 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 23a83fcec7644e3252ef6f3ac57c9e26aeb95635..5804b19b36e85caa5a66ef2f257ef54ee633957d 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 8a3c771eafb3c356c9bf54bdec878156c616fbf4..49faa10d6c8a6ad352a1b3ae79982763c9ecd060 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 7072bd231693cc7f50537dfea197afc70b119df6..5cb9a60a43939a6880492b7c6fa13a3106562036 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 e2ac963fb2f740c4a2816e0b7e4dbaa2ccb2a38c..9b26e293f220433255d49a86fc4a5448e7ebf742 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 1e5c01955dddcf14729d3cee68cc77df1086795b..038f96ebc7d1814b62fe97163f921c75cbcfd5c4 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 77c217aec7b845863a84519ba2f72da4f749b4b2..f9f345d962a101c3e76bf6199d4a3687d5ba1bdc 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 0ab08eb2d3a65a4770f4f3f31184705d89c5f15d..93346d8efa77d0785cc277f3d741646901608cfb 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 570d69f93aee8d3bfd6725f06112b652b5dd20c1..fde761253b9023598af258feb3d1d8da3241458f 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 321082331106cc15cff233f79f884d9e693c0713..e5bd1125023ff12a6dd3b9c61b4c2dae621c4c6f 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 */