diff options
author | deva <deva> | 2008-08-19 07:50:47 +0000 |
---|---|---|
committer | deva <deva> | 2008-08-19 07:50:47 +0000 |
commit | 26a6b739a38e928d005ac689e693a4d4dd7dc3ea (patch) | |
tree | c9f60b66fc795cf67baaac95ebb9eac03494f677 /client | |
parent | 6a2cc91b62f227ca71d759654ed34c138d236800 (diff) |
Made the netcom object global, for socket reuse.
Diffstat (limited to 'client')
-rw-r--r-- | client/macro.cc | 3 | ||||
-rw-r--r-- | client/macrowindow.cc | 45 | ||||
-rw-r--r-- | client/netcom.cc | 2 | ||||
-rw-r--r-- | client/netcom.h | 4 | ||||
-rw-r--r-- | client/pracro.cc | 6 |
5 files changed, 14 insertions, 46 deletions
diff --git a/client/macro.cc b/client/macro.cc index b0943d0..7f3286c 100644 --- a/client/macro.cc +++ b/client/macro.cc @@ -76,8 +76,7 @@ static MacroEventFilter *macro_event_filter = NULL; */ static void create_macro(QString course, QString macro) { - NetCom netcom(host, port, user, cpr); - QDomDocument xml_doc = netcom.send(course, macro); + QDomDocument xml_doc = Global::netcom->send(course, macro); cleanup_macros(); diff --git a/client/macrowindow.cc b/client/macrowindow.cc index 6837e1d..e3d4846 100644 --- a/client/macrowindow.cc +++ b/client/macrowindow.cc @@ -130,50 +130,7 @@ bool MacroWindow::doCommit() if(faulty == 0) { printf("MacroWindow -> committing...\n"); -#if 0 - // Build the XML commit - QString xml_string; - xml_string.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); - xml_string.append("<pracro version=\"1.0\" cpr=\"" + cpr + "\" user=\"" + user + "\">\n"); - xml_string.append(" <commit macro=\"" + macro + "\" version=\"" + - version + "\">\n"); - - // Iterate the different entries, and append their results to the commit string - QVector< Widget* >::iterator i = widgets.begin(); - while (i != widgets.end()) { - Widget* w = *i; - - xml_string.append(" <field name=\"" + w->getName() - + "\" value=\"" + w->getValue() + "\"/>\n"); - i++; - } - - xml_string.append(" </commit>\n"); - xml_string.append("</pracro>\n"); - - // Print commit to stdout for debug purposes - printf("%s\n", xml_string.toStdString().c_str()); - - // Convert the commit to Utf-8 charset - QByteArray xml_array = xml_string.toUtf8(); - QDomDocument xml_result; - - // Use setContent of QDomDocument to validate the xml commit - if (!xml_result.setContent(xml_array)) { - printf("Parse error: Invalid XML\n"); - } - - // Commit the xml data to the server - SendRecieve macro_commit(host, port); - macro_commit.makeConnection(&xml_result); - // Recieve answer from server whether successful or not - //QByteArray ba = macro_commit.getResult(); - QString ba = macro_commit.getResult(); - printf("Server returned result: %s", ba.toStdString().c_str()); -#endif/*0*/ - - NetCom netcom(host, port, user, cpr); - netcom.send(widgets, macro, version); + Global::netcom->send(widgets, macro, version); return true; } else { diff --git a/client/netcom.cc b/client/netcom.cc index cbe44d1..0f73e60 100644 --- a/client/netcom.cc +++ b/client/netcom.cc @@ -28,6 +28,8 @@ #include <QApplication> +NetCom *Global::netcom = NULL; + NetCom::NetCom(QString host, quint16 port, QString user, QString cpr) { this->user = user; diff --git a/client/netcom.h b/client/netcom.h index 18d6dbe..33a57f4 100644 --- a/client/netcom.h +++ b/client/netcom.h @@ -56,4 +56,8 @@ private: QString cpr; }; +namespace Global { + extern NetCom *netcom; +}; + #endif/*__PRACRO_NETCOM_H__*/ diff --git a/client/pracro.cc b/client/pracro.cc index 051fe2b..fdb0d7d 100644 --- a/client/pracro.cc +++ b/client/pracro.cc @@ -30,7 +30,9 @@ #include <QEvent> #include <QStringList> #include <QSettings> + #include "macro.h" +#include "netcom.h" #define VERSION "1.0" @@ -136,6 +138,8 @@ int main(int argc, char *argv[]) port = settings.value("port").toInt(); settings.endGroup(); + Global::netcom = new NetCom(host, port, user, cpr); + new_macro(course, macro); //app.setQuitOnLastWindowClosed(false); @@ -143,5 +147,7 @@ int main(int argc, char *argv[]) cleanup_macros(); + delete Global::netcom; + return ret; } |