diff options
author | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2014-05-01 13:52:48 +0000 |
---|---|---|
committer | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2014-05-01 13:52:48 +0000 |
commit | f480edbdb34462d893f4bef8a7010c6b749b785c (patch) | |
tree | 6067e13c2277b41084ff7fc2f1adca958a729ba9 | |
parent | udated TODO (diff) | |
download | gpg4usb-f480edbdb34462d893f4bef8a7010c6b749b785c.tar.gz gpg4usb-f480edbdb34462d893f4bef8a7010c6b749b785c.zip |
open localized help file if available
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@1089 34ebc366-c3a9-4b3c-9f84-69acf7962910
-rw-r--r-- | helppage.cpp | 40 | ||||
-rw-r--r-- | helppage.h | 5 |
2 files changed, 44 insertions, 1 deletions
diff --git a/helppage.cpp b/helppage.cpp index 40152cb..9fd3d34 100644 --- a/helppage.cpp +++ b/helppage.cpp @@ -33,11 +33,49 @@ HelpPage::HelpPage(const QString path, QWidget *parent) : setLayout(mainLayout); //setAttribute(Qt::WA_DeleteOnClose); //browser->setSource(QUrl::fromLocalFile(path)); - browser->setSource(QUrl(path)); + + connect(browser, SIGNAL(anchorClicked(QUrl)), this, SLOT(openUrl(QUrl))); + browser->setOpenLinks(false); + browser->setSource(localizedHelp(QUrl(path))); browser->setFocus(); } +void HelpPage::openUrl(QUrl url) { + browser->setSource(localizedHelp(url)); +}; + +/** + * @brief HelpPage::localizedHelp + * check if the requested file is also available with the locale, + * e.g. return index.de.html if index.html was requested but the + * locale is de and index.de.html is available + * @param url + * @return + */ +QUrl HelpPage::localizedHelp(QUrl url) { + QString path = url.toLocalFile(); + QString filename = path.mid(path.lastIndexOf("/") + 1 ); + QString filepath = path.left(path.lastIndexOf("/") + 1 ); + QStringList fileparts = filename.split("."); + + //QSettings settings; + QString lang = QSettings().value("int/lang", QLocale::system().name()).toString(); + if (lang.isEmpty()) { + lang = QLocale::system().name(); + } + + fileparts.insert(1,lang); + QString langfile = filepath + fileparts.join("."); + + if(QFile(QUrl(langfile).toLocalFile()).exists()) { + return langfile; + } else { + return path; + } + +} + QTextBrowser* HelpPage::getBrowser() { return browser; } @@ -25,6 +25,9 @@ #include <QWidget> #include <QTextBrowser> #include <QVBoxLayout> +#include <QSettings> +#include <QFile> +#include <QLocale> class HelpPage : public QWidget { @@ -36,9 +39,11 @@ public: signals: public slots: + void openUrl(QUrl url); private: QTextBrowser *browser; /** The textbrowser of the tab */ + QUrl localizedHelp(QUrl path); }; |