From: Konrad Rosenbaum Date: Mon, 26 Aug 2013 20:22:06 +0000 (+0200) Subject: document and fix help menu X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=d95e57723bc75c4a58d849ea4a5f513de1a02fac;p=konrad%2Fsmoke.git document and fix help menu --- diff --git a/doc/client/helpmenu.html b/doc/client/helpmenu.html new file mode 100644 index 0000000..7afc930 --- /dev/null +++ b/doc/client/helpmenu.html @@ -0,0 +1,35 @@ + +Magic Smoke Client Help Menu + + +

Magic Smoke Client Help Menu

+ +Per default the Help menu of the client shows three "About" entries, which are fixed, and one help entry which points at a default location. The latter can be replaced by one or more custom entries.

+ +You can customize the help menu of the MagicSmoke client to point at the documentation you chose to show to your users.

+ +

Config Locations

+ +MagicSmoke checks two locations for configuration of the help menu: its data directory (Linux/Mac: $HOME/.magicSmoke2; Windows: %APPDATA%/.magicSmoke2) and the installation directory where the executable is located. In both locations it checks for a file named helpMenu.xml - if found each file is parsed and read into the help menu. If none is found the default entry is used.

+ +

Config Syntax

+ +The configuration files allow to define active menu items and separators (with optional labels). The syntax is quite simple:

+ +

+<HelpMenu>
+        <Item label="&Help Index">default:/</Item>
+        <Item label="Help &Client">default:/client/index.html</Item>
+        <Separator label="external"/>
+        <Item label="Heise">http://www.heise.de</Item>
+</HelpMenu>
+
+ +The Item tag defines an active menu item. The label attribute defines what is shown as menu entry - if it contains an ampersand the following letter is used as shortcut. The text of the item is the URL of the help file (usually HTML) to be displayed. MagicSmoke uses the default browser for this type of URL to display the help file - usually file: and http: type URLs in combination with HTML files will work regardless of operating system - other URL types or file types may or may not work. The default: URLs are a special case, if a doc directory is present in the installation directory then help files are sought there, otherwise they refer to a default URL that is compiled into MagicSmoke (defined in src/smoke.pro).

+ +The Separator tag defines a simple separator line in the menu. The optional label attribute defines a label shown on the separator. Whether the label is actually visible depends on GUI style (e.g. the default Linux style "cleanlooks" does show them, while the default Windows style does not).

+ +Items and Separators are shown in exactly the order they are listed, first the ones from data directory then those from the installation directory. + + + \ No newline at end of file diff --git a/doc/client/index.html b/doc/client/index.html index 6764aa5..2f66b03 100644 --- a/doc/client/index.html +++ b/doc/client/index.html @@ -12,6 +12,7 @@ This section of the documentation describes how to use the dedicated Magic Smoke

  • Configuration
  • Creating Events and Inventory
  • Selling and Shipping +
  • Configuring the Help menu
  • User Administration
  • Templates
  • Scripting diff --git a/doc/index.html b/doc/index.html index 3c936cc..11e1aa3 100644 --- a/doc/index.html +++ b/doc/index.html @@ -62,7 +62,7 @@ This software comes with no warranty at all. You use it at your own risk.
  • Web Template Design
  • ODT Template Design
  • Ticket and Voucher Template Design
  • - +

    Programmers Manual

    diff --git a/src/main.cpp b/src/main.cpp index 25e5e13..9a7d1a9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -106,7 +106,9 @@ static inline QString resolveDir(const QString &dirspec) return rdir; } +#ifndef HOMEPAGE_BASEURL #define HOMEPAGE_BASEURL "http://smoke.silmor.de" +#endif void MApplication::aboutMS() { @@ -178,31 +180,45 @@ void MApplication::versionDlg() } -static QList > helpUrl; +struct HelpUrl { + enum Type {None, Item, Separator} type=None; + QString label,url; + HelpUrl(Type t,QString l,QString u=QString()):type(t),label(l),url(u){} +}; +static QList helpUrl; + +static void loadHelpUrlFile(const QString&fname) +{ + QFile fd(fname); + QList urls; + //try to open + if(fd.open(QIODevice::ReadOnly)){ + //read config + QDomDocument doc; + doc.setContent(&fd); + QDomNodeList nl=doc.documentElement().childNodes(); + for(int i=0;i0 && urls.size()>0)helpUrl.append(HelpUrl(HelpUrl::Separator,"")); + helpUrl.append(urls); +} -static void initHelpUrl() +void MApplication::initHelpUrl() { //check file exists, if not initialize it - QFile fd(dataDir+"/helpMenu.xml"); - if(!fd.exists()){ - fd.open(QIODevice::WriteOnly); - fd.write(QByteArray("\n\tdefault://\n")); - fd.close(); - }; - //try to open - if(fd.open(QIODevice::ReadOnly)){ - //read config - QDomDocument doc; - doc.setContent(&fd); - QDomNodeList nl=doc.elementsByTagName("Item"); - for(int i=0;i(el.attribute("label").trimmed(), el.text().trimmed())); - } - } + loadHelpUrlFile(dataDir()+"/helpMenu.xml"); + loadHelpUrlFile(applicationDirPath()+"/helpMenu.xml"); //fallback if(helpUrl.size()<1) - helpUrl<("&Help","default://"); + helpUrl<addAction(helpUrl[i].first,map,SLOT(map())); - map->setMapping(a,i); + if(helpUrl[i].type==HelpUrl::Separator){ + m->addSeparator()->setText(helpUrl[i].label); + }else{ + QAction*a=m->addAction(helpUrl[i].label,map,SLOT(map())); + map->setMapping(a,i); + } } m->addSeparator(); m->addAction("About &MagicSmoke",qApp,SLOT(aboutMS())); @@ -221,14 +241,25 @@ QMenu* MApplication::helpMenu() return m; } +static inline QUrl convHelpUrl(QUrl s) +{ + if(s.scheme()=="default"){ + static const QString ad=QApplication::applicationDirPath()+"/doc/"; + if(QFile(ad+"index.html").exists()) + return QUrl::fromLocalFile(ad+s.path()); + else + //TODO: allow different versions? + return HOMEPAGE_BASEURL "/doc/" + s.path(); + } + else return s; +} + + + void MApplication::help() { - QString d=QApplication::applicationDirPath()+"/doc/index.html"; - //TODO: fix this to work with GIT and be more generic - if(!QFile(d).exists()){ - d=HOMEPAGE_BASEURL "/doc/"+MSInterface::staticVersionInfo(WOb::VersionPath)+"/index.html"; - }else d="file:///"+d; - QDesktopServices::openUrl(QUrl(d)); + qDebug()<<"Opening default help..."; + QDesktopServices::openUrl(convHelpUrl(QUrl("default:/index.html"))); } void MApplication::help(int idx) @@ -237,11 +268,9 @@ void MApplication::help(int idx) help(); return; } - QString url=helpUrl[idx].second; - if(url=="default://" || url=="") - help(); - else - QDesktopServices::openUrl(QUrl(url)); + QUrl u=convHelpUrl(helpUrl[idx].url); + qDebug()<<"Opening help:"<