#include <QDesktopServices>
#include <QDir>
+#include <QDomDocument>
+#include <QDomElement>
#include <QHostInfo>
#include <QIcon>
#include <QInputDialog>
#include <QMenu>
#include <QMessageBox>
#include <QSettings>
+#include <QSignalMapper>
#include <QTranslator>
#include <QUrl>
#include <stdlib.h>
-void initDataDir()
+static void initDataDir()
{
#ifdef Q_OS_WIN32
dataDir=getenv("APPDATA");
dataDir+="/.magicSmoke2";
}
-QMenu* MApplication::helpMenu()
-{
- QMenu*m=new QMenu(tr("&Help"));
- m->addAction("&Help",qApp,SLOT(help()));
- m->addSeparator();
- m->addAction("About &MagicSmoke",qApp,SLOT(aboutMS()));
- m->addAction("About &Qt",qApp,SLOT(aboutQt()));
- return m;
-}
+#define HOMEPAGE_BASEURL "http://smoke.silmor.de"
void MApplication::aboutMS()
{
mb.setIconPixmap(QPixmap(":/icon.png"));
mb.setWindowTitle(tr("About MagicSmoke"));
mb.setText(tr( "<h3>MagicSmoke %3</h3>"
- "© Konrad Rosenbaum, 2007-2010<br>"
+ "© Konrad Rosenbaum, 2007-2011<br>"
"© Peter Keller, 2007-2008<br>"
"protected under the GNU GPL v.3 or at your option any newer<p>"
- "See also the <a href=\"http://smoke.silmor.de\">MagicSmoke Homepage</a>.<p>"
+ "See also the <a href=\"" HOMEPAGE_BASEURL "\">MagicSmoke Homepage</a>.<p>"
"This version was compiled from repository '%1' revision '%2'.").
arg(MSInterface::repoPart()). // %1
arg(MInterface::svnVersion()). //%2
mb.exec();
}
+static QList<QPair<QString,QString> > helpUrl;
+
+static void initHelpUrl()
+{
+ //check file exists, if not initialize it
+ QFile fd(dataDir+"/helpMenu.xml");
+ if(!fd.exists()){
+ fd.open(QIODevice::WriteOnly);
+ fd.write(QByteArray("<HelpMenu>\n\t<Item label=\"&Help\">default://</Item>\n</HelpMenu>"));
+ 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<nl.size();i++){
+ QDomElement el=nl.at(i).toElement();
+ helpUrl.append(QPair<QString,QString>(el.attribute("label").trimmed(), el.text().trimmed()));
+ }
+ }
+ //fallback
+ if(helpUrl.size()<1)
+ helpUrl<<QPair<QString,QString>("&Help","default://");
+}
+
+QMenu* MApplication::helpMenu()
+{
+ QMenu*m=new QMenu(tr("&Help"));
+ QSignalMapper *map=new QSignalMapper(m);
+ connect(map,SIGNAL(mapped(int)),qApp,SLOT(help(int)));
+ for(int i=0;i<helpUrl.size();i++){
+ QAction*a=m->addAction(helpUrl[i].first,map,SLOT(map()));
+ map->setMapping(a,i);
+ }
+ m->addSeparator();
+ m->addAction("About &MagicSmoke",qApp,SLOT(aboutMS()));
+ m->addAction("About &Qt",qApp,SLOT(aboutQt()));
+ return m;
+}
+
void MApplication::help()
{
QString d=QApplication::applicationDirPath()+"/doc/index.html";
if(!QFile(d).exists()){
- d="http://smoke.silmor.de/doc/"+MSInterface::repoPart()+"/index.html";
+ d=HOMEPAGE_BASEURL "/doc/"+MSInterface::repoPart()+"/index.html";
}else d="file:///"+d;
QDesktopServices::openUrl(QUrl(d));
}
+void MApplication::help(int idx)
+{
+ if(idx<0 || idx>=helpUrl.size()){
+ help();
+ return;
+ }
+ QString url=helpUrl[idx].second;
+ if(url=="default://" || url=="")
+ help();
+ else
+ QDesktopServices::openUrl(QUrl(url));
+}
+
MApplication::MApplication(int&ac,char**av)
:QApplication(ac,av)
-{}
+{
+}
void MApplication::setMyStyle()
{
//initialize log file
initDebug();
+ //init help menu layout
+ initHelpUrl();
+
//check/generate profile
if(!QSettings().childGroups().contains("profiles")){
QMessageBox::warning(0,app.translate("initprofile","Initial Profile Warning"), app.translate("initprofile","You need a profile to work with Magic Smoke. Please create one now."));