Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: New Quick Start and Video Guide modules added #449

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .tx/config
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ host = https://www.transifex.com
minimum_perc = 80
mode = developer

[deepin-manual.deepin-manual]
[o:linuxdeepin:p:deepin-manual:r:deepin-manual]
file_filter = translations/deepin-manual_<lang>.ts
source_file = translations/deepin-manual.ts
source_lang = en_US
type = QT

[deepin-manual.desktopts]
[o:linuxdeepin:p:deepin-manual:r:desktopts]
file_filter = translations/desktop/desktop_<lang>.ts
source_file = translations/desktop/desktop.ts
source_lang = en
Expand Down
2 changes: 2 additions & 0 deletions src/base/consts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ const char kConfigWindowWidth[] = "window_width";
const char kConfigWindowHeight[] = "window_height";
const char kConfigWindowInfo[] = "window_info";
const char kConfigAppList[] = "AppList";

const char kVideoConfigPath[] = DMAN_MANUAL_DIR"/system/video-guide/videos/config.json";
5 changes: 5 additions & 0 deletions src/base/consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@ extern const char kConfigWindowHeight[];
extern const char kConfigWindowInfo[];
extern const char kConfigAppList[];

extern const char kVideoConfigPath[];

const char kLearnBasicOperations[] = "learn-basic-operations";
const char kCommonApplicationLibraries[] = "common-application-libraries";


#endif // DEEPIN_MANUAL_BASE_CONSTS_H
13 changes: 13 additions & 0 deletions src/base/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ DCORE_USE_NAMESPACE
#include <QFontDatabase>
#include <QImageReader>

#include "base/consts.h"

QHash<QString, QPixmap> Utils::m_imgCacheHash;
QHash<QString, QString> Utils::m_fontNameCache;
QString Utils::cpuModeName;
Expand Down Expand Up @@ -305,6 +307,17 @@ QStringList Utils::getSystemManualList()
app_list_.append("dde");
}
}

// 非应用文档,直接添加
if (systemList.contains(kLearnBasicOperations) || oldAppList.contains(kLearnBasicOperations)) {
if (app_list_.indexOf(kLearnBasicOperations) == -1)
app_list_.append(kLearnBasicOperations);
}
if (systemList.contains(kCommonApplicationLibraries) || oldAppList.contains(kCommonApplicationLibraries)) {
if (app_list_.indexOf(kCommonApplicationLibraries) == -1)
app_list_.append(kCommonApplicationLibraries);
}
qDebug() << "exist app list: " << app_list_ << ", count:" << app_list_.size();
}
qDebug() << "exist app list: " << app_list_ << ", count:" << app_list_.size();
return app_list_;
Expand Down
7 changes: 7 additions & 0 deletions src/controller/filewatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "filewatcher.h"
#include "base/utils.h"
#include "base/consts.h"

#include <QDir>
#include <QDebug>
Expand Down Expand Up @@ -244,6 +245,12 @@ void fileWatcher::onTimerOut()
}
#endif
}
QFileInfo fileInfo(kVideoConfigPath);
if (fileInfo.exists()) {
QString modifyTime = fileInfo.lastModified().toString("yyyy-MM-dd hh:mm:ss.zzz");
mapNow.insert(kVideoConfigPath, modifyTime);
}

QStringList deleteList;
QStringList addList;
QStringList addTime;
Expand Down
88 changes: 81 additions & 7 deletions src/controller/helpermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ void helperManager::getModuleInfo()
}
#endif
}

QFileInfo fileInfo(kVideoConfigPath); //配置文件也需要监控
if (fileInfo.exists()) {
QString modifyTime = fileInfo.lastModified().toString("yyyy-MM-dd hh:mm:ss.zzz");
mapNow.insert(kVideoConfigPath, modifyTime);
}

QStringList deleteList;
QStringList addList;
QStringList addTime;
Expand Down Expand Up @@ -154,18 +161,85 @@ void helperManager::handleDb(const QStringList &deleteList, const QStringList &a
QStringList appList;
QStringList langList;
for (const QString &path : deleteList) {
QStringList list = path.split("/");
if (list.count() >= 4) {
langList.append(list.at(list.count() - 2));
appList.append(list.at(list.count() - 4));
if (path.contains("video-guide")) {
appList << "video-guide" << "video-guide";
langList << "en_US" << "zh_CN";
} else {
QStringList list = path.split("/");
if (list.count() >= 4) {
langList.append(list.at(list.count() - 2));
appList.append(list.at(list.count() - 4));
}
}
}

dbObj->deleteSearchInfo(appList, langList);
}

QStringList list = handlePriority(addList);
QStringList tmpAddList = addList;
int videoIndex = tmpAddList.indexOf(kVideoConfigPath);
if (videoIndex >= 0) { //视频配置文件单独拿出来处理
tmpAddList.removeAt(videoIndex);
QFile file(kVideoConfigPath);
if (!file.open(QIODevice::ReadOnly)) {
qDebug() << "Failed to open video config file.";
} else {
QByteArray jsonData = file.readAll();
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
if (jsonDoc.isNull()) {
qDebug() << "Failed to parse JSON of video config file.";
} else {
QJsonObject jsonObj = jsonDoc.object();

QMap<QString, QStringList> anchors;
QStringList anchorIdList;
QMap<QString, QStringList> anchorInitialList;
QMap<QString, QStringList> anchorSpellList;
QStringList contents;

for (QString key : jsonObj.keys()) {
QJsonValue jsValue = jsonObj.value(key);
if (jsValue.isArray() && key == "videos") {
QJsonArray jsArray = jsValue.toArray();
QJsonArray resultArray;
for (int i = 0; i < jsArray.count(); i++) {
if (jsArray[i].isObject()) {
QJsonObject obj = jsArray[i].toObject();
if (obj["name[en_US]"].isString() && obj["name[zh_CN]"].isString()) {
anchors["en_US"].append(obj["name[en_US]"].toString());
anchors["zh_CN"].append(obj["name[zh_CN]"].toString());
//anchors["zh_HK"].append(obj["name[zh_HK]"].toString());
//anchors["zh_TW"].append(obj["name[zh_TW]"].toString());

anchorInitialList["en_US"].append("");
anchorInitialList["zh_CN"].append("");
//anchorInitialList["zh_HK"].append("");
//anchorInitialList["zh_TW"].append("");

anchorSpellList["en_US"].append(obj["name[en_US]"].toString().remove(" "));
anchorSpellList["zh_CN"].append(Dtk::Core::Chinese2Pinyin(obj["name[zh_CN]"].toString()).remove(QRegExp("[1-9]")));
//anchorSpellList["zh_HK"].append("");
//anchorSpellList["zh_TW"].append("");

anchorIdList.append(QString("h%0").arg(i));
contents.append(obj["url"].toString());
}
}
}
}
for(QString lang_key : anchors.keys()) {
if (anchorInitialList.keys().contains(lang_key) && anchorSpellList.keys().contains(lang_key))
dbObj->addSearchEntry("video-guide", lang_key, anchors[lang_key], anchorInitialList[lang_key], anchorSpellList[lang_key], anchorIdList, contents);
}
}
}
}
}

QStringList list = handlePriority(tmpAddList);

if (!list.isEmpty() && !addTime.isEmpty()) {
dbObj->insertFilesTimeEntry(addList, addTime);
dbObj->insertFilesTimeEntry(tmpAddList, addTime);
//通过JS层函数来完成md转html, 然后解析html内所有文本内容
if (jsObj && m_webView) {
QString strChange = list.join(",");
Expand Down Expand Up @@ -230,7 +304,7 @@ QStringList helperManager::handlePriority(const QStringList &list)
QStringList splitList = mdPath.split("/");

//新文案结构 /usr/share/deepin-manual/manual-assets/[application | system]/appName/appNameT/land/*_appNameT.md
if (splitList.contains("application") || splitList.contains("application")) {
if (splitList.contains("application") || splitList.contains("system")) {
QString moduleLang = splitList.at(splitList.count() - 4) + splitList.at(splitList.count() - 2);
QString mdFile = splitList.at(splitList.count() - 1);
QStringList listTemp = mdFile.split("_");
Expand Down
7 changes: 3 additions & 4 deletions src/controller/search_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void SearchDb::handleSearchAnchor(const QString &keyword)
while (query.next() && (result.size() < kResultLimitation)) {
qDebug() << "handleSearchAnchor===> " << query.value(0).toString() << strlistApp;
//只将当前预装应用中的内容输出。
if (strlistApp.contains(query.value(0).toString())) {
if (strlistApp.contains(query.value(0).toString())/* || query.value(0).toString().contains("video-guide")*/) {
//搜索结果优先显示应用名称
if (query.value(3) == "h0") {
result.prepend(SearchAnchorResult {
Expand Down Expand Up @@ -623,8 +623,7 @@ void SearchDb::handleSearchContent(const QString &keyword)
}
}
}
const QString sql =
QString(kSearchSelectContent).replace(":lang", lang).replace(":content", keyword);
const QString sql = QString(kSearchSelectContent).replace(":lang", lang).replace(":content", keyword);

listStruct.clear();
nH0OfList = 0;
Expand All @@ -643,7 +642,7 @@ void SearchDb::handleSearchContent(const QString &keyword)
const QString anchor = query.value(1).toString();
const QString anchorId = query.value(2).toString();
const QString content = query.value(3).toString();
if (!strlistApp.contains(app_name)) {
if (!strlistApp.contains(app_name) && !app_name.contains("video-guide")) {
continue;
}

Expand Down
14 changes: 8 additions & 6 deletions src/view/i18n_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ I18nProxy::~I18nProxy()
QVariantHash I18nProxy::getSentences() const
{
QVariantHash result {
{"QuickStart", QObject::tr("Quick Start")},
{"VideoGuide", QObject::tr("Video Guide")},
{"System", QObject::tr("System")},
{"Applications", QObject::tr("Applications")},
// { "NoResult",QObject::tr(
// "Sorry, there are no search results for \"%1\"") },
{"NoResult", QObject::tr("No search results")},
// { "WikiSearch", QObject::tr(
// "Change your keywords and try again, or search for it in Deepin Wiki") },
{"ToIndexPage", QObject::tr("Home")},
// { "SearchInWiki", QObject::tr("Deepin Wiki") },
{"ResultNumSuffix", QObject::tr(" result")}, //单数结果后缀
{"ResultNumSuffixs", QObject::tr(" results")}};
{"ResultNumSuffixs", QObject::tr(" results")},
{"ClicktoView", QObject::tr("Click to view ")},
{"ViewAll", QObject::tr("View all")},
{"Support", QObject::tr("Service and Support")}
};

return result;
}

Expand Down
81 changes: 79 additions & 2 deletions src/view/manual_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ QString ManualProxy::appToPath(const QString &appName)
QStringList assetsPathList = Utils::getSystemManualDir();
foreach (auto assetPath, assetsPathList) {
QString appPath;
if (appName == "dde") {
if (appName == "dde" || appName == kLearnBasicOperations || appName == kCommonApplicationLibraries || appName == "video-guide") {
appPath = assetPath + "/system/" + appName;
} else {
appPath = assetPath + "/application/" + appName;
Expand Down Expand Up @@ -307,7 +307,11 @@ QString ManualProxy::getAppIconPath(const QString &desktopname)
QString ManualProxy::getLocalAppName(const QString &desktopname)
{
QString strdisplayname = desktopname;
if (0 == desktopname.compare("dde", Qt::CaseInsensitive)) {
if (0 == desktopname.compare(kLearnBasicOperations, Qt::CaseInsensitive)) {
strdisplayname = tr("Learn Basic Operations");
} else if (0 == desktopname.compare(kCommonApplicationLibraries, Qt::CaseInsensitive)) {
strdisplayname = tr("Common Application Libraries");
} else if (0 == desktopname.compare("dde", Qt::CaseInsensitive)) {
strdisplayname = tr("Desktop Environment");
} else {
QStringList pathList = Utils::getEnvsourcePath();
Expand All @@ -325,6 +329,79 @@ QString ManualProxy::getLocalAppName(const QString &desktopname)
return strdisplayname;
}

QVariant ManualProxy::getVideoGuideInfo()
{
QFile file(kVideoConfigPath);
if (!file.open(QIODevice::ReadOnly)) {
qDebug() << "Failed to open file";
return QVariantList();
}

QString locale = QLocale().name();
//藏语维语使用简体中文
if (locale == "ug_CN" || locale == "bo_CN") {
locale = "zh_CN";
} else if (locale == "en_US" || locale == "en_GB") {
locale = "en_US";
}

QByteArray jsonData = file.readAll();
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
if (jsonDoc.isNull()) {
qDebug() << "Failed to parse JSON";
return QVariantList();
}

// locale = "en_US"; //test
QJsonObject jsonObj = jsonDoc.object();

for (QString key : jsonObj.keys()) {
QJsonValue jsValue = jsonObj.value(key);

if (jsValue.isString() && key == "url") {
videoUrl = jsValue.toString();
} else if (jsValue.isArray() && key == "videos") {
QJsonArray jsArray = jsValue.toArray();
QJsonArray resultArray;

for (int i = 0; i < jsArray.count(); i++) {
if (jsArray[i].isObject()) {
QJsonObject obj = jsArray[i].toObject();
QJsonObject tmpObj {
{"cover", QString(DMAN_MANUAL_DIR"/system/video-guide/videos/" + obj["cover"].toString())},
{"url", obj["url"]}
};

if (locale == "zh_CN") {
tmpObj.insert("name", obj["name[zh_CN]"]);
} else if(locale == "zh_HK") {
tmpObj.insert("name", obj["name[zh_HK]"]);
} else if(locale == "zh_TW") {
tmpObj.insert("name", obj["name[zh_TW]"]);
} else {
tmpObj.insert("name", obj["name[en_US]"]);
}

resultArray.append(tmpObj);
}
}

return resultArray.toVariantList();
}
}

return QVariantList();
}

void ManualProxy::openVideo(QString url)
{
if(url.isEmpty()) {
url = videoUrl;
}
QProcess process;
process.startDetached("browser", QStringList(url));
process.waitForFinished();
}

/**
* @brief ManualProxy::saveAppList
Expand Down
4 changes: 4 additions & 0 deletions src/view/manual_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public slots:

QString translateTitle(const QString &titleUS);

QVariant getVideoGuideInfo();
void openVideo(QString url = "");

private:
void saveAppList(const QStringList &list);
QString getAppLocalDir(const QString &appPath);
Expand All @@ -50,6 +53,7 @@ public slots:
QStringList app_list_;
QString strIconTheme;
QIconLoader *piconload;
QString videoUrl;
};

#endif // DEEPIN_MANUAL_VIEW_MANUAL_PROXY_H
Loading