From adbeba1453bb51d7beaa95dfd8ca1624b52306c2 Mon Sep 17 00:00:00 2001 From: konrad Date: Sat, 8 Aug 2009 10:11:43 +0000 Subject: [PATCH] *moved version discovery for client to woc *MISSING: do the same for server *moved help menu into application class git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@321 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- src/main.cpp | 70 +++++++++++++++++++++++++++++++++++++------------- src/main.h | 16 +++++++++++ src/mainwindow.cpp | 40 +---------------------------- src/mainwindow.h | 4 --- src/msinterface.cpp | 43 +++++++++++++++++++++++++++++- src/msinterface.h | 16 +++++++---- src/overview.cpp | 3 +- src/smoke.pro | 11 +------- src/version.cpp | 68 ------------------------------------------------- src/version.h | 8 ------ wob/magicsmoke.wolf | 2 +- woc/processor.cpp | 15 ++++++++++- woc/processor.h | 7 ++++- woc/qtout.cpp | 10 ++++--- 14 files changed, 150 insertions(+), 163 deletions(-) delete mode 100644 src/version.cpp delete mode 100644 src/version.h diff --git a/src/main.cpp b/src/main.cpp index 3595d95..cf09217 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,23 +10,25 @@ // // -#include +#include #include #include #include #include #include +#include #include #include #include +#include #include "autoupdate.h" -#include "keygen.h" -#include "mainwindow.h" +#include "debug.h" #include "hmac.h" +#include "keygen.h" #include "main.h" -#include "debug.h" - +#include "mainwindow.h" +#include "msinterface.h" QString choseLanguage(bool warn) { @@ -62,30 +64,62 @@ QString dataDir; void initDataDir() { - QSettings set; - if(set.contains("datadir")) - dataDir=set.value("datadir").toString(); - else{ #ifdef Q_OS_WIN32 - dataDir=getenv("APPDATA"); + dataDir=getenv("APPDATA"); #else - dataDir=getenv("HOME"); + dataDir=getenv("HOME"); #endif - if(dataDir=="") - qFatal("Cannot determine application data directory."); - dataDir+="/.magicSmoke"; - set.setValue("datadir",dataDir); - } + if(dataDir=="") + qFatal("Cannot determine application data directory."); + 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; +} + +void MApplication::aboutMS() +{ + QMessageBox mb; + mb.setIconPixmap(QPixmap(":/icon.png")); + mb.setWindowTitle(tr("About MagicSmoke")); + mb.setText(tr( "

MagicSmoke %3

" + "© Konrad Rosenbaum, Peter Keller, 2007-9
" + "protected under the GNU GPL v.3 or at your option any newer

" + "See also the MagicSmoke Homepage.

" + "This version was compiled from repository '%1' revision '%2'."). + arg(MSInterface::repoPart()). // %1 + arg(MInterface::svnVersion()). //%2 + arg(MSInterface::version()) //%3 + ); + mb.setStandardButtons(QMessageBox::Ok); + mb.exec(); } +void MApplication::help() +{ + QString d=QApplication::applicationDirPath()+"/doc/index.html"; + if(!QFile(d).exists()){ + d="http://smoke.silmor.de/doc/"+MSInterface::repoPart()+"/index.html"; + }else d="file:///"+d; + QDesktopServices::openUrl(QUrl(d)); +} + + int main(int argc,char**argv) { //create global app - QApplication app(argc,argv); + MApplication app(argc,argv); //locate settings app.setOrganizationName("MagicSmoke"); - app.setApplicationName("MagicSmoke"); + app.setApplicationName("MagicSmoke2"); //set icon app.setWindowIcon(QIcon(":/icon.png")); diff --git a/src/main.h b/src/main.h index 7be4ad9..c5f3c0b 100644 --- a/src/main.h +++ b/src/main.h @@ -21,4 +21,20 @@ QString choseLanguage(bool warn=true); /**contains the directory that is used for external data storage*/ extern QString dataDir; + +#include +class QMenu; +class MApplication:public QApplication +{ + Q_OBJECT + public: + MApplication(int ac,char**av):QApplication(ac,av){} + + static QMenu*helpMenu(); + public slots: + //help menu + void aboutMS(); + void help(); +}; + #endif diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 54b7821..1ffa61c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -16,7 +16,6 @@ #include "msinterface.h" #include "office.h" #include "overview.h" -#include "version.h" #include #include @@ -40,11 +39,8 @@ #include #include -static MMainWindow *maininst=0; - MMainWindow::MMainWindow() { - maininst=this; setWindowTitle("Magic Smoke"); //create Menu Bar QMenuBar*mb=menuBar(); @@ -61,7 +57,7 @@ MMainWindow::MMainWindow() m->addAction(tr("&Generate Host Key..."),this,SLOT(generateKey())); m->addSeparator(); m->addAction(tr("&OpenOffice.org Settings..."),this,SLOT(openOfficeCfg())); - mb->addMenu(helpMenu()); + mb->addMenu(MApplication::helpMenu()); //create central widget QWidget *loginwidget; @@ -125,16 +121,6 @@ MMainWindow::MMainWindow() loadProfile(); } -QMenu* MMainWindow::helpMenu() -{ - QMenu*m=new QMenu(tr("&Help")); - m->addAction("&Help",maininst,SLOT(help())); - m->addSeparator(); - m->addAction("About &MagicSmoke",maininst,SLOT(about())); - m->addAction("About &Qt",qApp,SLOT(aboutQt())); - return m; -} - void MMainWindow::initProfiles() { QSettings set; @@ -356,27 +342,3 @@ void MMainWindow::openOfficeCfg() MOfficeConfig c(this); c.exec(); } - -void MMainWindow::about() -{ - QMessageBox mb(this); - mb.setIconPixmap(QPixmap(":/icon.png")); - mb.setWindowTitle(tr("About MagicSmoke")); - mb.setText(tr( "

MagicSmoke

" - "© Konrad Rosenbaum, Peter Keller, 2007-9
" - "protected under the GNU GPL v.3 or at your option any newer

" - "See also the MagicSmoke Homepage.

" - "This version was compiled from repository %1 revision %2."). - arg(repoPart()).arg(svnRevision())); - mb.setStandardButtons(QMessageBox::Ok); - mb.exec(); -} - -void MMainWindow::help() -{ - QString d=QApplication::applicationDirPath()+"/doc/index.html"; - if(!QFile(d).exists()){ - d="http://smoke.silmor.de/doc/"+repoPart()+"/index.html"; - }else d="file:///"+d; - QDesktopServices::openUrl(QUrl(d)); -} diff --git a/src/mainwindow.h b/src/mainwindow.h index 7b3515f..256d153 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -31,7 +31,6 @@ class MMainWindow:public QMainWindow public: MMainWindow(); - static QMenu*helpMenu(); private: QHttp*req; QString sessionid; @@ -56,9 +55,6 @@ class MMainWindow:public QMainWindow void importKey(); void generateKey(); void openOfficeCfg(); - //help menu - void about(); - void help(); }; #endif diff --git a/src/msinterface.cpp b/src/msinterface.cpp index 318515c..4643cb5 100644 --- a/src/msinterface.cpp +++ b/src/msinterface.cpp @@ -11,6 +11,9 @@ // #include "msinterface.h" +#include "main.h" + +#include #include MSInterface::MSInterface(QString pid) @@ -19,8 +22,14 @@ MSInterface::MSInterface(QString pid) profileid=pid; } +MSInterface::~MSInterface() +{ + logout(); +} + bool MSInterface::login(QString username,QString passwd,QString hostname,QString hostkey) { + m_uname=username;m_passwd=passwd;m_host=hostname;m_hostkey=hostkey; MTLogin lg=MTLogin::query(username,passwd,hostname,hostkey); if(lg.stage()==lg.Error) QMessageBox::warning(0,tr("Warning"),tr("Login failed: %1").arg(tr(lg.errorString().toAscii()))); @@ -29,8 +38,16 @@ bool MSInterface::login(QString username,QString passwd,QString hostname,QString return lg.stage()==lg.Success; } - void logout(){} - bool relogin(){return false;} +void MSInterface::logout() +{ + if(m_sessid!="")queryLogout(); + m_sessid=""; +} +bool MSInterface::relogin() +{ + logout(); + return login(m_uname,m_passwd,m_host,m_hostkey); +} QMap MSInterface::headers(QString s)const { @@ -38,3 +55,25 @@ QMap MSInterface::headers(QString s)const ret.insert("Wob-SessionId",m_sessid); return ret; } + +QString MSInterface::dataDir()const +{ + QString dd="profile."+profileid; + QDir dir(::dataDir); + if(!dir.exists(dd)) + if(!dir.mkpath(dd)) + qDebug("Warning: oh dir! Can't create my data directory!"); + return ::dataDir+"/"+dd; +} + +QString MSInterface::settingsGroup()const +{ + return "profsettings/"+profileid; +} + +QString MSInterface::repoPart() +{ + QStringList l=svnRepositoryUrl().split("/smoke/"); + if(l.size()>1)return l[1]; + else return svnRepositoryUrl(); +} diff --git a/src/msinterface.h b/src/msinterface.h index 32e723c..9bdd16d 100644 --- a/src/msinterface.h +++ b/src/msinterface.h @@ -20,27 +20,31 @@ class MSInterface:public MInterface Q_OBJECT public: MSInterface(QString); + ~MSInterface(); static MSInterface* instance(){return qobject_cast(MInterface::instance());} - QString currentUser()const{return "";} + QString currentUser()const{return m_uname;} bool hasRole(QString)const{return false;} - QString dataDir()const{return "/tmp/blah";} - QString settingsGroup()const{return "nosuchgroup";} + QString dataDir()const; + QString settingsGroup()const; /**returns the current session ID*/ QString sessionId()const{return m_sessid;} + /**returns the branch/trunk part of the repository*/ + static QString repoPart(); + virtual QMap headers(QString)const; public slots: bool login(QString username,QString passwd,QString hostname,QString hostkey); - void logout(){} - bool relogin(){return false;} + void logout(); + bool relogin(); /**sets the session id to be transmitted*/ void setSessionId(QString sid){m_sessid=sid;} private: - QString profileid,m_sessid; + QString profileid,m_sessid,m_uname,m_passwd,m_host,m_hostkey; }; diff --git a/src/overview.cpp b/src/overview.cpp index b7b61f0..f49be4d 100644 --- a/src/overview.cpp +++ b/src/overview.cpp @@ -14,6 +14,7 @@ #include "checkdlg.h" #include "eventedit.h" #include "eventsummary.h" +#include "main.h" #include "mainwindow.h" #include "misc.h" #include "moneylog.h" @@ -134,7 +135,7 @@ MOverview::MOverview(QString pk) m->addAction(tr("&Backup now..."),this,SLOT(doBackup())) ->setEnabled(req->hasRole("backup")); - mb->addMenu(MMainWindow::helpMenu()); + mb->addMenu(MApplication::helpMenu()); //tabs setCentralWidget(tab=new QTabWidget); diff --git a/src/smoke.pro b/src/smoke.pro index 5b63963..a882ae3 100644 --- a/src/smoke.pro +++ b/src/smoke.pro @@ -41,7 +41,6 @@ SOURCES = \ ticketrender.cpp \ orderwin.cpp \ labeldlg.cpp \ - version.cpp \ templates.cpp \ templatedlg.cpp \ office.cpp \ @@ -51,6 +50,7 @@ SOURCES = \ msinterface.cpp HEADERS = \ + main.h \ keygen.h \ debug.h \ mainwindow.h \ @@ -93,12 +93,3 @@ include(../zip/zip.pri) include(widgets/widgets.pri) include(wbase/wbase.pri) include(wob/wob.pri) - -#LIBS += -lgmp - -versiontarget.target = version.xml -versiontarget.commands = svn info -R --xml --non-interactive .. > version.xml -versiontarget.depends = FORCE - -PRE_TARGETDEPS += version.xml -QMAKE_EXTRA_TARGETS += versiontarget diff --git a/src/version.cpp b/src/version.cpp deleted file mode 100644 index 394eb31..0000000 --- a/src/version.cpp +++ /dev/null @@ -1,68 +0,0 @@ -// -// C++ Implementation: version information -// -// Description: processes version.inc to form some meaningful C++ code -// -// -// Author: Konrad Rosenbaum , (C) 2008 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#include "version.h" - -#define defversion(x,y) const char VERSION_##x[] = #y; -#include "../www/inc/machine/version.inc" -#undef defversion - -#include -#include -#include -#include - -static QString rpart,srev; - -static void initVer() -{ - QFile x(":/version.xml"); - x.open(QIODevice::ReadOnly); - QDomDocument doc; - doc.setContent(&x); - QDomNodeList nl=doc.documentElement().elementsByTagName("entry"); - int baserev=0,maxrev=0; - for(int i=0;i0)u=nl2.at(0).toElement().text(); - else continue; - nl2=el.elementsByTagName("root"); - if(nl2.size()>0){ - u="."+u.mid(nl2.at(0).toElement().text().size()); - } - QStringList sl=u.split("/smoke/"); - if(sl.size()>1)rpart=sl[1]; - else rpart=u; - } - if(r>maxrev)maxrev=r; - } - srev=QString::number(baserev); - if(maxrev>baserev)srev+="-"+QString::number(maxrev); -} - -QString repoPart() -{ - if(rpart=="")initVer(); - return rpart; -} - -QString svnRevision() -{ - if(rpart=="")initVer(); - return srev; -} diff --git a/src/version.h b/src/version.h deleted file mode 100644 index 8d73366..0000000 --- a/src/version.h +++ /dev/null @@ -1,8 +0,0 @@ -#include - -#define defversion(x,y) extern const char VERSION_##x[]; -#include "../www/inc/machine/version.inc" -#undef defversion - -QString repoPart(); -QString svnRevision(); diff --git a/wob/magicsmoke.wolf b/wob/magicsmoke.wolf index 6fa5bd5..f6ac072 100644 --- a/wob/magicsmoke.wolf +++ b/wob/magicsmoke.wolf @@ -9,7 +9,7 @@ - + diff --git a/woc/processor.cpp b/woc/processor.cpp index b3beb16..59d211f 100644 --- a/woc/processor.cpp +++ b/woc/processor.cpp @@ -171,7 +171,7 @@ void WocProcessor::callSvn() qDebug("Warning: unable to parse output of svn info."); return; } - //parse it. + //parse it:revisions QStringList rl=MDomQuery(doc,"/*/entry/@revision"); if(rl.size()==0){ m_svnRev="unknown"; @@ -188,6 +188,19 @@ void WocProcessor::callSvn() else m_svnRev=QString::number(minv)+"-"+QString::number(maxv); } + //parse for repository path + MDomNodeList nl=MDomQuery(doc,"/*/entry"); + for(int i=0;i0)m_svnUrl=rl[0]; + rl=MDomQuery(el,"repository/root"); + if(rl.size()>0)m_svnRoot=rl[0]; + break;//we can stop now + } + } } //svn status svn.start(m_svnExe,QStringList()<<"status"<<"--xml"<<"--non-interactive"<<"."); diff --git a/woc/processor.h b/woc/processor.h index 3b9c60d..17f18d6 100644 --- a/woc/processor.h +++ b/woc/processor.h @@ -319,6 +319,10 @@ class WocProcessor:public QObject QString verHR()const{return m_verHR;} /**returns the SVN revision of the project: it contains two tokens, the first one is the current revision or min-max if the working copy contains mixed revisions; the second token contains the word "vanilla" if there are no local modifications, or "modified" if there are local modifications*/ QString svnRevision()const{return m_svnRev;} + /**returns the SVN Repository Root*/ + QString svnRepositoryRoot()const{return m_svnRoot;} + /**returns the complete SVN Repository URL*/ + QString svnRepositoryUrl()const{return m_svnUrl;} /**returns the variable name that will contain the database driver instance*/ QString dbInst()const{return m_dbInst;} /**returns the variable name that will contain the database schema object*/ @@ -342,7 +346,8 @@ class WocProcessor:public QObject void errorFound(); private: QString m_baseDir,m_wobDir,m_verComm,m_verNeedComm,m_verHR,m_projname; - QString m_svnTarget,m_svnRev,m_svnExe,m_dbInst,m_dbSchema,m_dbVer; + QString m_svnTarget,m_svnRev,m_svnExe,m_svnRoot,m_svnUrl; + QString m_dbInst,m_dbSchema,m_dbVer; bool m_error; QList m_tables; diff --git a/woc/qtout.cpp b/woc/qtout.cpp index c7d00df..115e6b5 100644 --- a/woc/qtout.cpp +++ b/woc/qtout.cpp @@ -84,10 +84,12 @@ WocQtClientOut::WocQtClientOut(QDomElement&el) m_iface.write(QString("class "+m_prefix+"Interface:public WInterface\n{\n Q_OBJECT\n").toAscii()); m_iface.write(QString(" public:\n "+m_prefix+"Interface(QString name=\""+pn+"\"):WInterface(name){}\n").toAscii()); m_iface.write(QString(" static "+m_prefix+"Interface*instance(QString name=\""+pn+"\")\n\t{return qobject_cast<"+m_prefix+"Interface*>(WInterface::instance(name));}\n\n").toAscii()); - m_iface.write(QString(" QString commVersion()const{return \""+woc->verComm()+"\";}\n").toAscii()); - m_iface.write(QString(" QString needCommVersion()const{return \""+woc->verNeedComm()+"\";}\n").toAscii()); - m_iface.write(QString(" QString version()const{return \""+woc->verHR()+"\";}\n").toAscii()); - m_iface.write(QString(" QString svnVersion()const{return \""+woc->svnRevision()+"\";}\n\n").toAscii()); + m_iface.write(QString(" static QString commVersion(){return \""+woc->verComm()+"\";}\n").toAscii()); + m_iface.write(QString(" static QString needCommVersion(){return \""+woc->verNeedComm()+"\";}\n").toAscii()); + m_iface.write(QString(" static QString version(){return \""+woc->verHR()+"\";}\n").toAscii()); + m_iface.write(QString(" static QString svnVersion(){return \""+woc->svnRevision()+"\";}\n\n").toAscii()); + m_iface.write(QString(" static QString svnRepositoryRoot(){return \""+woc->svnRepositoryRoot()+"\";}\n\n").toAscii()); + m_iface.write(QString(" static QString svnRepositoryUrl(){return \""+woc->svnRepositoryUrl()+"\";}\n\n").toAscii()); //create all includer m_hdr.setFileName(m_basedir+"/"+m_subdir+"/"+m_prefix+"Include.h"); -- 1.7.2.5