From 984b02fc0ea25d86cca5c1c837b8ac7648add20e Mon Sep 17 00:00:00 2001 From: zheng_wenlong Date: Fri, 14 Jun 2019 14:32:39 +0900 Subject: add app list --- launcher/qml/Launcher.qml | 18 ++--- launcher/src/applicationmodel.cpp | 146 +++++++++++++++++++++++++++++++++++-- launcher/src/applicationmodel.h | 7 ++ launcher/src/homescreenhandler.cpp | 61 ++++++++++++---- launcher/src/homescreenhandler.h | 3 +- package/etc/applist.json | 64 ++++++++++++++++ package/package.pro | 6 ++ 7 files changed, 272 insertions(+), 33 deletions(-) create mode 100644 package/etc/applist.json diff --git a/launcher/qml/Launcher.qml b/launcher/qml/Launcher.qml index 034e05a..4b1971a 100644 --- a/launcher/qml/Launcher.qml +++ b/launcher/qml/Launcher.qml @@ -138,24 +138,13 @@ ApplicationWindow { } onReleased: { if (currentId === '' && loc.index >= 0 ) { - // Not long press, exec application and tapshortcut -// pid = launcher.launch(applicationModel.id(loc.index)) -// if (1 < pid) { homescreenHandler.tapShortcut(applicationModel.appid(loc.index)) - -// } -// else { -// console.warn("app cannot be launched!") -// } } else if (loc.mouseY <= 0) { if (loc.mouseX >= 197 && loc.mouseX < 393) { -// shortcutAppModel.changeShortcut(currentId, currentName, "0"); homescreenHandler.registerShortcut(currentId, currentName, "0"); } else if (loc.mouseX >= 393 && loc.mouseX < 589) { -// shortcutAppModel.changeShortcut(currentId, currentName, "1"); homescreenHandler.registerShortcut(currentId, currentName, "1"); } else if (loc.mouseX >= 589 && loc.mouseX < 785) { -// shortcutAppModel.changeShortcut(currentId, currentName, "2"); homescreenHandler.registerShortcut(currentId, currentName, "2"); } if (oldIndex != newIndex){ @@ -175,6 +164,10 @@ ApplicationWindow { uninstallDialog.uninstallApp = currentId uninstallDialog.visible = true } + if (oldIndex != newIndex){ +// applicationModel.recordAppsPosition(newIndex, oldIndex, 0) + applicationModel.move(newIndex, newIndex = oldIndex) + } } currentName = '' @@ -185,7 +178,8 @@ ApplicationWindow { if (loc.currentId === '') return if (index < 0) return if (index === newIndex) return - applicationModel.move(newIndex, newIndex = index) + applicationModel.move(newIndex, newIndex = index) + applicationModel.recordAppsPosition() } } } diff --git a/launcher/src/applicationmodel.cpp b/launcher/src/applicationmodel.cpp index 261e43e..493bd41 100644 --- a/launcher/src/applicationmodel.cpp +++ b/launcher/src/applicationmodel.cpp @@ -23,9 +23,15 @@ #include #include +#include +#include +#include +#include +#include +#include #include "afm_user_daemon_proxy.h" - +#define APPLIST_PATH "/var/local/lib/afm/applications/launcher/0.1/etc/applist.json" extern org::AGL::afm::user *afm_user_daemon_proxy; class ApplicationModel::Private @@ -33,6 +39,7 @@ class ApplicationModel::Private public: Private(); + void appendApp(QString icon, QString name, QString id); void addApp(QString icon, QString name, QString id); void removeApp(QString id); @@ -80,6 +87,25 @@ void ApplicationModel::Private::addApp(QString icon, QString name, QString id) this->data.insert(pos, AppInfo(_icon, name, id)); } + +void ApplicationModel::Private::appendApp(QString icon, QString name, QString id) +{ + HMI_DEBUG("addApp","name: %s icon: %s id: %s.", name.toStdString().c_str(), icon.toStdString().c_str(), id.toStdString().c_str()); + for(int i = 0; i < this->data.size(); ++i) { + if(this->data[i].id() == id) + return; + } + + QString _icon = name.toLower(); + if ( !QFile::exists(QString(":/images/%1_active.svg").arg(_icon)) || + !QFile::exists(QString(":/images/%1_inactive.svg").arg(_icon)) ) + { + _icon = "blank"; + } + + this->data.append(AppInfo(_icon, name, id)); +} + void ApplicationModel::Private::removeApp(QString id) { HMI_DEBUG("removeApp","id: %s.",id.toStdString().c_str()); @@ -202,14 +228,120 @@ void ApplicationModel::initAppList(QString data) { HMI_DEBUG("launcher","init application list."); beginResetModel(); + QFile file(APPLIST_PATH); QJsonDocument japps = QJsonDocument::fromJson(data.toUtf8()); - for (auto const &app : japps.array()) { - QJsonObject const &jso = app.toObject(); - auto const name = jso["name"].toString(); - auto const id = jso["id"].toString(); - auto const icon = get_icon_name(jso); + if(file.open(QIODevice::ReadOnly | QIODevice::Text)) { + QByteArray allData = file.readAll(); + QString str(allData); + if(str == "") { + file.close(); - d->addApp(icon, name, id); + } + QJsonParseError json_error; + QJsonDocument jsonDoc(QJsonDocument::fromJson(allData, &json_error)); + + if(json_error.error != QJsonParseError::NoError) + { + HMI_ERROR("Launcher", "connection.json error"); + return; + } + HMI_DEBUG("initAppList1","initAppList 1"); + + QJsonObject rootObj = jsonDoc.object(); + QJsonArray arrayObj = rootObj.value("applist").toArray(); + QJsonArray newAreaObj; + HMI_DEBUG("initAppList1","initAppList 2"); + HMI_DEBUG("initAppList1","initAppList size %d",arrayObj.size()); + QJsonObject subObj1; + subObj1 = arrayObj.at(2).toObject(); + HMI_DEBUG("initAppList1","initAppList iiid=%s",subObj1["id"].toString().toStdString().c_str()); + //check list + for (auto const &app : japps.array()) { + QJsonObject const &jso = app.toObject(); + auto const name = jso["name"].toString(); + auto const id = jso["id"].toString(); + bool haveNewApp = false; + + for (int i = 0; i < arrayObj.size(); ++i) { + QJsonObject subObj = arrayObj.at(i).toObject(); + HMI_DEBUG("initAppList1","initAppList %s",subObj["id"].toString().toStdString().c_str()); + if((id == subObj["id"].toString()) && (name == subObj["name"].toString())) { + HMI_DEBUG("initAppList1","initAppList flag--%s",subObj["flag"].toString().toStdString().c_str()); + subObj.remove("flag"); + subObj.insert("flag", "1"); + arrayObj.replace(i, subObj); + HMI_DEBUG("initAppList1","initAppList flag---%s",subObj["flag"].toString().toStdString().c_str()); + haveNewApp = false; + break; + } else { + haveNewApp = true; + } + } + if(haveNewApp) { + QJsonObject newObj; + newObj.insert("id", id); + newObj.insert("name", name); + newObj.insert("flag", "1"); + newAreaObj.append(newObj); + } + } + HMI_DEBUG("initAppList1","initAppList 3"); + + //updatelist + for (int i = 0; i < arrayObj.size(); ++i) { + QJsonObject subObj = arrayObj.at(i).toObject(); + HMI_DEBUG("initAppList1", "flag==%s", subObj["flag"].toString().toStdString().c_str()); + if(subObj["flag"].toString() == "1") { + d->appendApp(get_icon_name(subObj), subObj["name"].toString(), subObj["id"].toString()); + } + } + HMI_DEBUG("initAppList1","initAppList 4"); + + if(newAreaObj.size() > 0) { + for(int i = 0; i < newAreaObj.size(); ++i) { + QJsonObject subObj = newAreaObj.at(i).toObject(); + d->appendApp(get_icon_name(subObj), subObj["name"].toString(), subObj["id"].toString()); + } + } + } else { + HMI_ERROR("Launcher", "read applist.json file failed"); + for (auto const &app : japps.array()) { + QJsonObject const &jso = app.toObject(); + auto const name = jso["name"].toString(); + auto const id = jso["id"].toString(); + auto const icon = get_icon_name(jso); + + d->addApp(icon, name, id); + } } + HMI_DEBUG("initAppList1","initAppList 5"); + file.close(); endResetModel(); + recordAppsPosition(); +} +void ApplicationModel::recordAppsPosition() +{ + QFile file(APPLIST_PATH); + if(file.open(QIODevice::WriteOnly | QIODevice::Text)) { + + QJsonObject rootObj; + QJsonArray arrayObj; + for(int i = 0; i < d->data.size(); ++i) { + QJsonObject subObj; + subObj.insert("id", d->data.at(i).id()); + subObj.insert("name", d->data.at(i).name()); + subObj.insert("flag", "0"); + arrayObj.append(subObj); + } + rootObj.insert("applist", arrayObj); + QJsonDocument jsonDoc; + jsonDoc.setObject(rootObj); + file.write(jsonDoc.toJson()); + + } else { + HMI_ERROR("Launcher", "write to applist.json file failed"); + } + file.flush(); + fsync(file.handle()); + file.close(); } diff --git a/launcher/src/applicationmodel.h b/launcher/src/applicationmodel.h index 780e575..4238baf 100644 --- a/launcher/src/applicationmodel.h +++ b/launcher/src/applicationmodel.h @@ -19,6 +19,11 @@ #define APPLICATIONMODEL_H #include +enum { + CHANGE, + ADD, + REMOVE +}; class ApplicationModel : public QAbstractListModel { @@ -37,8 +42,10 @@ public: Q_INVOKABLE void move(int from, int to); Q_INVOKABLE void initAppList(QString data); Q_INVOKABLE void updateApplist(QStringList info); + Q_INVOKABLE void recordAppsPosition(); private: + class Private; Private *d; }; diff --git a/launcher/src/homescreenhandler.cpp b/launcher/src/homescreenhandler.cpp index 2450ccb..010d0e9 100644 --- a/launcher/src/homescreenhandler.cpp +++ b/launcher/src/homescreenhandler.cpp @@ -27,12 +27,16 @@ extern org::AGL::afm::user *afm_user_daemon_proxy; #define BUF_SIZE 1024 +#define AREA_FILE_PATH "/etc/hmi-config/connection.json" void* HomescreenHandler::myThis = 0; HomescreenHandler::HomescreenHandler(QObject *parent) : QObject(parent), - mp_qhs(NULL) + mp_qhs(NULL), + meter_area(""), + hud_tbt_area("") { + getLauncherArea(); } HomescreenHandler::~HomescreenHandler() @@ -128,7 +132,6 @@ void HomescreenHandler::init(int port, const char *token, QLibWindowmanager *qwm shortcut_list << QString(QLatin1String(json_object_get_string(json_object_object_get(json_object_array_get_idx(obj_array, i), "shortcut_id")))); shortcut_list << QString(QLatin1String(json_object_get_string(json_object_object_get(json_object_array_get_idx(obj_array, i), "shortcut_name")))); } - HMI_DEBUG("Launcher","SEvent_UpdateShortcut id1 = %s", shortcut_list.at(2).toStdString().c_str()); emit updateShortcutList(shortcut_list); }); } @@ -160,6 +163,7 @@ void HomescreenHandler::onRep(struct json_object* reply_contents) if(json_object_object_get_ex(obj_res, "data", &obj_data)) { HMI_DEBUG("launcher","HomescreenHandler emit initAppList"); QString data = json_object_to_json_string(obj_data); + HMI_DEBUG("applist", "applist------%s", data.toStdString().c_str()); emit initAppList(data); } } @@ -172,14 +176,6 @@ void HomescreenHandler::hideWindow(QString application_id) void HomescreenHandler::registerShortcut(QString shortcut_id, QString shortcut_name, QString position) { -// struct json_object* j_obj = json_object_new_object(); -// struct json_object* val_id = json_object_new_string(shortcut_id.toStdString().c_str()); -// struct json_object* val_name = json_object_new_string(shortcut_name.toStdString().c_str()); -// struct json_object* val_position = json_object_new_string(position.toStdString().c_str()); -// json_object_object_add(j_obj, "shortcut_id", val_id); -// json_object_object_add(j_obj, "shortcut_name", val_name); -// json_object_object_add(j_obj, "position", val_position); - mp_qhs->registerShortcut(shortcut_id, shortcut_name, position); } @@ -204,7 +200,7 @@ void HomescreenHandler::sendAppToMeter(QString application_id) HMI_DEBUG("Launcher","sendAppToMeter %s", application_id.toStdString().c_str()); struct json_object* j_json = json_object_new_object(); struct json_object* value; - value = json_object_new_string("master.split.sub"); + value = json_object_new_string(meter_area.toStdString().c_str()); json_object_object_add(j_json, "area", value); mp_qhs->showWindow(application_id.section('@', 0, 0).toStdString().c_str(), j_json); @@ -215,10 +211,11 @@ void HomescreenHandler::sendAppToHud(QString application_id) HMI_DEBUG("Launcher","sendAppToHud %s", application_id.toStdString().c_str()); struct json_object* j_json = json_object_new_object(); struct json_object* value; - value = json_object_new_string("hud.normal.full"); + QString id = application_id.section('@', 0, 0); + value = json_object_new_string(hud_tbt_area.toStdString().c_str()); json_object_object_add(j_json, "area", value); - mp_qhs->showWindow(application_id.section('@', 0, 0).toStdString().c_str(), j_json); + mp_qhs->showWindow(id.toStdString().c_str(), j_json); } @@ -231,3 +228,41 @@ void HomescreenHandler::setQuickWindow(QQuickWindow *qw) { mp_qhs->setQuickWindow(qw); } + +void HomescreenHandler::getLauncherArea() +{ + QFile file(AREA_FILE_PATH); + if(file.open(QIODevice::ReadOnly | QIODevice::Text)) { + QByteArray allData = file.readAll(); + QString str(allData); + if(str == "") { + file.close(); + + } + QJsonParseError json_error; + QJsonDocument jsonDoc(QJsonDocument::fromJson(allData, &json_error)); + + if(json_error.error != QJsonParseError::NoError) + { + HMI_ERROR("Launcher", "connection.json error"); + return; + } + + QJsonObject rootObj = jsonDoc.object(); + QJsonArray connectionsObj = rootObj.value("connections").toArray(); + + QJsonObject firstObj = connectionsObj.first().toObject(); + QString meter = firstObj["screen_name"].toString(); + QJsonArray meterAreaArray = firstObj.value("areas").toArray(); + meter_area = meterAreaArray.first().toObject()["area_name"].toString(); + meter_area = meter + "." + meter_area; + + QJsonObject secondObj = connectionsObj.last().toObject(); + QString hud = secondObj["screen_name"].toString(); + QJsonArray hudAreaArray = secondObj.value("areas").toArray(); + hud_tbt_area = hudAreaArray.first().toObject()["area_name"].toString(); + hud_tbt_area = hud + "." + hud_tbt_area; + + } + file.close(); +} diff --git a/launcher/src/homescreenhandler.h b/launcher/src/homescreenhandler.h index a34a2a9..8e5c71d 100644 --- a/launcher/src/homescreenhandler.h +++ b/launcher/src/homescreenhandler.h @@ -55,9 +55,10 @@ signals: void updateShortcutList(QStringList shortcut_list); private: + void getLauncherArea(); QLibHomeScreen *mp_qhs; QLibWindowmanager *mp_qwm; - QString m_myname; + QString m_myname, meter_area, hud_tbt_area; }; #endif // HOMESCREENHANDLER_H diff --git a/package/etc/applist.json b/package/etc/applist.json new file mode 100644 index 0000000..d67310f --- /dev/null +++ b/package/etc/applist.json @@ -0,0 +1,64 @@ +{ + "applist": [ + { + "flag": "0", + "id": "radio@0.1", + "name": "Radio" + }, + { + "flag": "0", + "id": "poi@0.1", + "name": "POI" + }, + { + "flag": "0", + "id": "dashboard@0.1", + "name": "Dashboard" + }, + { + "flag": "0", + "id": "hvac@0.1", + "name": "HVAC" + }, + { + "flag": "0", + "id": "mixer@7.0", + "name": "mixer" + }, + { + "flag": "0", + "id": "navigation@0.1", + "name": "navigation" + }, + { + "flag": "0", + "id": "phone@0.1", + "name": "Phone" + }, + { + "flag": "0", + "id": "mediaplayer@0.1", + "name": "MediaPlayer" + }, + { + "flag": "0", + "id": "settings@0.1", + "name": "Settings" + }, + { + "flag": "0", + "id": "hudspeed@0.1", + "name": "Hudspeed" + }, + { + "flag": "0", + "id": "tbtnavi@0.1", + "name": "tbtnavi" + }, + { + "flag": "0", + "id": "hudtbt@0.1", + "name": "Hudtbt" + } + ] +} diff --git a/package/package.pro b/package/package.pro index 0045478..23b34a2 100644 --- a/package/package.pro +++ b/package/package.pro @@ -12,6 +12,12 @@ copy_config.commands = $(COPY_FILE) \"$$replace(copy_config.depends, /, $$QMAKE_ QMAKE_EXTRA_TARGETS += copy_config PRE_TARGETDEPS += $$copy_config.target +copy_json.target = $$OUT_PWD/root/etc +copy_json.depends = $$_PRO_FILE_PWD_/etc +copy_json.commands = $(COPY_DIR) \"$$replace(copy_json.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_json.target, /, $$QMAKE_DIR_SEP)\" +QMAKE_EXTRA_TARGETS += copy_json +PRE_TARGETDEPS += $$copy_json.target + wgt.target = package wgt.commands = wgtpkg-pack -f -o launcher.wgt root -- cgit 1.2.3-korg