File use-qt5.patch of Package gaia2

Index: gaia-2.4.5/src/wscript
===================================================================
--- gaia-2.4.5.orig/src/wscript
+++ gaia-2.4.5/src/wscript
@@ -2,6 +2,7 @@
 # encoding: utf-8
 
 import os, os.path
+from waflib import Utils
 
 def options(opt):
     opt.add_option('--with-stlfacade', action='store_true',
@@ -44,8 +45,9 @@ def build_library(bld):
     gaialib = bld.stlib(
         source   = sources,
         target   = 'gaia2',
+        uselib   = 'QT5CORE QT5NETWORK QT5CONCURRENT',
         use      = bld.env['USELIB'],
-        install_path = '${PREFIX}/lib',
+        install_path = '${PREFIX}/lib%s' % Utils.lib64(),
         includes = [ '.', 'metrics', '3rdparty' ]
     )
     
@@ -75,8 +77,8 @@ def build_library(bld):
         os.chdir('src')
         install_tree(bld, '${PREFIX}/include/gaia2/Eigen', '3rdparty/Eigen')
 
-    bld.install_files('${PREFIX}/lib/pkgconfig', '../build/gaia2.pc')
-    bld.install_files('${PREFIX}/lib', 'libgaia2.a')
+    bld.install_files('${PREFIX}/lib%s/pkgconfig' % Utils.lib64(), '../build/gaia2.pc')
+    bld.install_files('${PREFIX}/lib%s' % Utils.lib64(), 'libgaia2.a')
 
 
 def is_dev_version(bld):
@@ -84,18 +86,25 @@ def is_dev_version(bld):
 
 
 def build_tools(bld):
+    qtincludes = set()
+    qtincludes.update(bld.env['INCLUDES_QT5CORE'])
+    qtincludes.update(bld.env['INCLUDES_QT5CONCURRENT'])
+    qtincludes.update(bld.env['INCLUDES_QT5NETWORK'])
+    qtincludes = list(qtincludes)
     # merge utility
     bld.program(
         source = 'tools/gaiamerge.cpp',
         target = 'tools/gaiamerge',
-        includes = [ '.', 'metrics', '3rdparty' ],
+        includes = [ '.', 'metrics', '3rdparty' ] + qtincludes,
+        uselib   = 'QT5CORE QT5NETWORK QT5CONCURRENT',
         use = ['gaia2'] + bld.env['USELIB'])
 
     # info utility
     bld.program(
         source = 'tools/gaiainfo.cpp',
         target = 'tools/gaiainfo',
-        includes = [ '.', 'metrics', '3rdparty' ],
+        includes = [ '.', 'metrics', '3rdparty' ] + qtincludes,
+        uselib   = 'QT5CORE QT5NETWORK QT5CONCURRENT',
         use = ['gaia2'] + bld.env['USELIB'])
     
     # GaiaFusion
@@ -105,7 +114,8 @@ def build_tools(bld):
     bld.program(
         source = 'tools/gaiafreeze.cpp',
         target = 'tools/gaiafreeze',
-        includes = [ '.', 'metrics', '3rdparty' ],
+        includes = [ '.', 'metrics', '3rdparty' ] + qtincludes,
+        uselib   = 'QT5CORE QT5NETWORK QT5CONCURRENT',
         use = ['gaia2'] + bld.env['USELIB'])
         
     if is_dev_version(bld):
@@ -115,14 +125,14 @@ def build_tools(bld):
         bld.program(
             source = 'tools/gaiabench.cpp tools/frozensearch.cpp',
             target = 'tools/gaiabench',
-            includes = [ '.', 'metrics', '3rdparty' ],
+            includes = [ '.', 'metrics', '3rdparty' ] + qtincludes,
             use = ['gaia2'] + bld.env['USELIB'])
 
     # Cyclops server
     if bld.env['WITH_CYCLOPS']:
         # cyclops "normal" server
         bld(
-            features = 'qt4 cxx cxxprogram cyclops',
+            features = 'qt5 cxx cxxprogram cyclops',
             source = '''
             tools/cyclops_server/cyclopsserver.cpp
             tools/cyclops_server/cyclopsproxy.cpp
@@ -130,12 +140,13 @@ def build_tools(bld):
             tools/cyclops_server/yamlrpcserver.cpp
             ''',
             target = 'tools/cyclops',
-            includes = [ '.', 'metrics', '3rdparty' ],
-            use = ['gaia2'] + bld.env['USELIB'])
+            includes = [ '.', 'metrics', '3rdparty' ] + qtincludes,
+
+            use = ['gaia2'] + bld.env['USELIB'] + ['Qt5Core', 'Qt5Network', 'Qt5Concurrent'])
 
         # cyclops "master" server
         bld(
-            features = 'qt4 cxx cxxprogram cyclops',
+            features = 'qt5 cxx cxxprogram cyclops',
             source = '''
             tools/cyclops_server/cyclopsmasterserver.cpp
             tools/cyclops_server/cyclopsproxy.cpp
@@ -144,7 +155,7 @@ def build_tools(bld):
             tools/cyclops_server/yamlrpcserver.cpp
             ''',
             target = 'tools/cyclopsmaster',
-            includes = [ '.', 'metrics', '3rdparty', 'tools/cyclops_server/' ],
+            includes = [ '.', 'metrics', '3rdparty', 'tools/cyclops_server/' ] + qtincludes,
             use = ['gaia2'] + bld.env['USELIB'])
 
         # cyclops init scripts
Index: gaia-2.4.5/wscript
===================================================================
--- gaia-2.4.5.orig/wscript
+++ gaia-2.4.5/wscript
@@ -4,6 +4,7 @@
 import sys, glob
 ##import Options, Scripting
 from os.path import join, exists, normpath
+from waflib import Utils
 import os
 
 def get_git_version():
@@ -25,7 +26,7 @@ out = 'build'
 
 
 def options(opt):
-    opt.load('compiler_cxx compiler_c qt4')
+    opt.load('compiler_cxx compiler_c qt5')
     opt.recurse('src')
 
     # whether or not to have all the asserts working
@@ -91,7 +92,7 @@ def configure(conf):
     conf.env.APP_VERSION = VERSION
 
     # compiler flags
-    conf.env.CXXFLAGS += [ '-std=c++03', '-Wall', '-fno-strict-aliasing', '-fPIC', '-fvisibility=hidden' ]
+    conf.env.CXXFLAGS += [ '-std=c++11', '-Wall', '-fno-strict-aliasing', '-fPIC', '-fvisibility=hidden' ]
 
     # define this to be stricter, but sometimes some libraries can give problems...
     #conf.env.CXXFLAGS += [ '-Werror' ]
@@ -166,7 +167,7 @@ def configure(conf):
         conf.env.CXXFLAGS = ['-static-libgcc', '-static-libstdc++']
 
 
-    conf.load('compiler_cxx compiler_c qt4')
+    conf.load('compiler_cxx compiler_c qt5')
 
     #conf.env['LINKFLAGS'] += [ '--as-needed' ] # TODO do we need this flag?
 
@@ -190,17 +191,25 @@ def configure(conf):
     # write pkg-config file
     prefix = normpath(conf.options.prefix)
 
+    qtincludedirs = set()
+    qtincludedirs.update(conf.env['INCLUDES_QT5CORE'])
+    qtincludedirs.update(conf.env['INCLUDES_QT5CONCURRENT'])
+    qtincludedirs.update(conf.env['INCLUDES_QT5NETWORK'])
+
     if sys.platform == 'linux2':
 
+
+        print(conf.env)
         opts = { 'prefix': prefix,
              'qtlibdir': conf.env['LIB_QTCORE'] or '/usr/lib',
-             'qtincludedir': '-I' + ' -I'.join(conf.env['INCLUDES_QTCORE']),
+             'qtincludedir': '-I' + ' -I'.join(qtincludedirs),
              'version': VERSION,
              'tbblib': tbblib,
+             'lib64': Utils.lib64(),
              }
 
         pcfile = '''prefix=%(prefix)s
-        libdir=${prefix}/lib
+        libdir=${prefix}/lib%(lib64)s
         includedir=${prefix}/include
         qtlibdir=%(qtlibdir)s
         qtincludes=%(qtincludedir)s
@@ -208,7 +217,7 @@ def configure(conf):
         Name: libgaia2
         Description: A library for doing similarity in semimetric spaces
         Version: %(version)s
-        Libs: -L${libdir} -L${qtlibdir} -lgaia2 -lQtCore -lyaml %(tbblib)s
+        Libs: -L${libdir} -L${qtlibdir} -lgaia2 -lQt5Core -lQt5Network -lQt5Concurrent -lyaml %(tbblib)s
         Cflags: -I${includedir} ${qtincludes}
         ''' % opts
 
@@ -216,13 +225,14 @@ def configure(conf):
         opts = { 'prefix': prefix,
              'qtlibdir': '-F' + conf.env['FRAMEWORKPATH_QTCORE'][0] +
                          ' -framework ' + conf.env['FRAMEWORK_QTCORE'][0],
-             'qtincludedir': '-I' + ' -I'.join(conf.env['INCLUDES_QTCORE']),
+             'qtincludedir': '-I' + ' -I'.join(qtincludedirs),
              'version': VERSION,
              'tbblib': tbblib,
+             'lib64': Utils.lib64(),
              }
 
         pcfile = '''prefix=%(prefix)s
-        libdir=${prefix}/lib
+        libdir=${prefix}/lib%(lib64)s
         includedir=${prefix}/include
         qtlibdir=%(qtlibdir)s
         qtincludes=%(qtincludedir)s
Index: gaia-2.4.5/src/algorithms/svmtrain.cpp
===================================================================
--- gaia-2.4.5.orig/src/algorithms/svmtrain.cpp
+++ gaia-2.4.5/src/algorithms/svmtrain.cpp
@@ -183,7 +183,7 @@ Transformation SVMTrain::analyze(const D
   QString modelFilename = modelFile.fileName();
   modelFile.close();
 
-  if (svm_save_model(modelFilename.toAscii().constData(), model) == -1) {
+  if (svm_save_model(modelFilename.toLocal8Bit().constData(), model) == -1) {
     throw GaiaException("SVMTrain: error while saving SVM model to temp file");
   }
 
@@ -195,7 +195,7 @@ Transformation SVMTrain::analyze(const D
   // if we asked for the model to be output specifically, also do it
   if (_params.value("modelFilename", "").toString() != "") {
     QString filename = _params.value("modelFilename").toString();
-    svm_save_model(filename.toAscii().constData(), model);
+    svm_save_model(filename.toLocal8Bit().constData(), model);
   }
 
   // destroy the model allocated by libsvm
Index: gaia-2.4.5/src/gaia.cpp
===================================================================
--- gaia-2.4.5.orig/src/gaia.cpp
+++ gaia-2.4.5/src/gaia.cpp
@@ -42,8 +42,8 @@ const char* version_git_sha = GAIA_GIT_S
 // message handler that aborts execution, so that when run inside gdb we can
 // still get a stack trace. Very useful!
 // got the idea from http://der-dakon.net/blog/KDE/tracing-qassert.html
-static void qtMessageHandler(QtMsgType type, const char *msg) {
-  fprintf(stderr, "%s\n", msg);
+static void qtMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
+  fprintf(stderr, "%s\n", msg.toLocal8Bit().data());
   if (type == QtFatalMsg) {
     abort();
   }
@@ -56,7 +56,7 @@ void init() {
 
   QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf-8"));
 
-  qInstallMsgHandler(qtMessageHandler);
+  qInstallMessageHandler(qtMessageHandler);
 
   registerAnalyzers();
   registerAppliers();
Index: gaia-2.4.5/src/metrics/frozencosineangledistance.h
===================================================================
--- gaia-2.4.5.orig/src/metrics/frozencosineangledistance.h
+++ gaia-2.4.5/src/metrics/frozencosineangledistance.h
@@ -27,7 +27,7 @@ namespace gaia2 {
 
 class FrozenCosineAngleDistance : public FrozenDistance {
 public:
-  static const Real defaultUndefinedDistance = 0.0;
+  static constexpr Real defaultUndefinedDistance = 0.0;
 
   FrozenCosineAngleDistance(const FrozenDataSet& dataset, int offset, int size)
     : FrozenDistance(dataset), _offset(offset), _size(size),
Index: gaia-2.4.5/src/parser/filter.cpp
===================================================================
--- gaia-2.4.5.orig/src/parser/filter.cpp
+++ gaia-2.4.5/src/parser/filter.cpp
@@ -210,7 +210,7 @@ Filter* FilterParser::parseFilter(const
   str.replace('\r', ' ');
 
   int yv;
-  YY_BUFFER_STATE buf = yy_scan_string(str.toAscii().data());
+  YY_BUFFER_STATE buf = yy_scan_string(str.toLatin1().data());
 
   Filter* result;
 
Index: gaia-2.4.5/src/types.h
===================================================================
--- gaia-2.4.5.orig/src/types.h
+++ gaia-2.4.5/src/types.h
@@ -20,6 +20,7 @@
 #ifndef GAIA_TYPES_H
 #define GAIA_TYPES_H
 
+#include <QDataStream>
 #include <QMap>
 #include <QStringList>
 #include <QPointF>
Index: gaia-2.4.5/src/utils.cpp
===================================================================
--- gaia-2.4.5.orig/src/utils.cpp
+++ gaia-2.4.5/src/utils.cpp
@@ -694,7 +694,7 @@ int memoryUsage(QString mtype) {
 
   QString statfile = QString("/proc/%1/status").arg(getpid());
 
-  FILE* f = fopen(statfile.toAscii().data(), "r");
+  FILE* f = fopen(statfile.toLocal8Bit().data(), "r");
   char buf[4096];
   buf[fread(buf, 1, 4096, f)] = '\0';
   fclose(f);
Index: gaia-2.4.5/src/gvarlengtharray.h
===================================================================
--- gaia-2.4.5.orig/src/gvarlengtharray.h
+++ gaia-2.4.5/src/gvarlengtharray.h
@@ -199,7 +199,7 @@ Q_OUTOFLINE_TEMPLATE void GVarLengthArra
         while (i < j)
             new (i++) T(*abuf++);
     } else {
-        qMemCopy(&ptr[idx], abuf, asize * sizeof(T));
+        memcpy(&ptr[idx], abuf, asize * sizeof(T));
     }
 }
 
@@ -224,7 +224,7 @@ Q_OUTOFLINE_TEMPLATE void GVarLengthArra
                     j->~T();
                 }
             } else {
-                qMemCopy(ptr, oldPtr, osize * sizeof(T));
+                memcpy(ptr, oldPtr, osize * sizeof(T));
             }
         } else {
             ptr = oldPtr;
Index: gaia-2.4.5/src/metrics/keydistance.cpp
===================================================================
--- gaia-2.4.5.orig/src/metrics/keydistance.cpp
+++ gaia-2.4.5/src/metrics/keydistance.cpp
@@ -27,7 +27,7 @@ class Key {
 
  public:
   Key(QString key) {
-    switch (key[0].toUpper().toAscii()) {
+    switch (key[0].toUpper().toLatin1()) {
     case 'A': _note = 0; break;
     case 'B': _note = 2; break;
     case 'C': _note = 3; break;
@@ -40,7 +40,7 @@ class Key {
 
     // is there an alteration or not?
     if (key.size() == 2) {
-      switch (key[1].toAscii()) {
+      switch (key[1].toLatin1()) {
       case '#': _note++; break;
       case 'b': _note--; break;
       default: throw GaiaException("impossible to parse key: ", key);
Index: gaia-2.4.5/src/bindings/wscript
===================================================================
--- gaia-2.4.5.orig/src/bindings/wscript
+++ gaia-2.4.5/src/bindings/wscript
@@ -46,6 +46,11 @@ def build(bld):
     #major, minor, _, _, _ = sys.version_info
     #if major >= 2 and minor >= 6:
     #    bld.env['PYTHONDIR'] = bld.env['PYTHONDIR'].replace('site-packages', 'dist-packages')
+    qtincludes = set()
+    qtincludes.update(bld.env['INCLUDES_QT5CORE'])
+    qtincludes.update(bld.env['INCLUDES_QT5CONCURRENT'])
+    qtincludes.update(bld.env['INCLUDES_QT5NETWORK'])
+    qtincludes = list(qtincludes)
 
     bld(features = 'cxx cshlib pyext',
         source = 'gaia.swig',
@@ -53,7 +58,7 @@ def build(bld):
         # -w 451: ignore the warning "Setting a const char * variable may leak memory"
         swig_flags = '-c++ -python -w451',
         use = ['gaia2'] + bld.env['USELIB'], # + ['BINDINGS'],
-        includes = bld.env['CPPPATH_BINDINGS'],
+        includes = bld.env['CPPPATH_BINDINGS'] + qtincludes,
         install_path = '${PYTHONDIR}'
         )
 
Index: gaia-2.4.5/src/tools/cyclops_server/cyclops.cpp
===================================================================
--- gaia-2.4.5.orig/src/tools/cyclops_server/cyclops.cpp
+++ gaia-2.4.5/src/tools/cyclops_server/cyclops.cpp
@@ -316,7 +316,7 @@ ResultSet Cyclops::nnSearch(const QStrin
 
   QString point64 = args[0];
   Point query;
-  query.fromBase64(point64.toAscii());
+  query.fromBase64(point64.toLatin1());
 
   if (methodName == "nnSearchByExample") {
     checkArgs(args, 3, methodName);
Index: gaia-2.4.5/src/tools/cyclops_server/cyclopsmaster.cpp
===================================================================
--- gaia-2.4.5.orig/src/tools/cyclops_server/cyclopsmaster.cpp
+++ gaia-2.4.5/src/tools/cyclops_server/cyclopsmaster.cpp
@@ -245,7 +245,7 @@ DataSet* reducePointsToDataSet(const QLi
   for (int i=0; i<replies.size(); i++) {
     // all replies should contain a result, even if only an empty dataset
     DataSet ds;
-    ds.fromBase64(replies[i]["result"].scalar().toAscii());
+    ds.fromBase64(replies[i]["result"].scalar().toLatin1());
     resultds->appendDataSet(&ds);
   }
 
@@ -453,7 +453,7 @@ yaml::Mapping CyclopsMaster::split(const
       if (methodName.startsWith("nnSearchById")) {
         // TODO: we have unnecessary points copies here, maybe there's sth to optimize
         //Point q;
-        //q.fromBase64(args[0].scalar().toAscii());
+        //q.fromBase64(args[0].scalar().toLatin1());
         //qpoints.addPoint(q); // NB: this should be grouped in a single addPoints at the end
         pointIDs << args[0].scalar();
       }
@@ -536,7 +536,7 @@ yaml::Mapping reduceGetPoints(const QLis
   for (int i=0; i<replies.size(); i++) {
     // all replies should contain a result, even if only an empty dataset
     DataSet ds;
-    ds.fromBase64(replies[i]["result"].scalar().toAscii());
+    ds.fromBase64(replies[i]["result"].scalar().toLatin1());
     resultds.appendDataSet(&ds);
   }
   */
@@ -587,7 +587,7 @@ yaml::Mapping CyclopsMaster::reduce(cons
     for (int i=0; i<results.replies.size(); i++) {
       // all replies should contain result, even if only an empty dataset
       DataSet ds;
-      ds.fromBase64(results.replies[i]["result"].scalar().toAscii());
+      ds.fromBase64(results.replies[i]["result"].scalar().toLatin1());
       resultds.appendDataSet(&ds);
     }
     if (resultds.size() == results.request["params"][1].sequence().size()) {
Index: gaia-2.4.5/src/tools/cyclops_server/cyclopsproxy.cpp
===================================================================
--- gaia-2.4.5.orig/src/tools/cyclops_server/cyclopsproxy.cpp
+++ gaia-2.4.5/src/tools/cyclops_server/cyclopsproxy.cpp
@@ -410,7 +410,7 @@ yaml::Node CyclopsProxy::process(const y
 
     try {
       point64 = params[0];
-      query.fromBase64(point64.toAscii());
+      query.fromBase64(point64.toLatin1());
 
       datasetName = params[1];
       distanceName = params[2];
@@ -443,7 +443,7 @@ yaml::Node CyclopsProxy::process(const y
 
     try {
       point64 = params[0];
-      query.fromBase64(point64.toAscii());
+      query.fromBase64(point64.toLatin1());
 
       datasetName = params[1];
       distanceName = params[2];
Index: gaia-2.4.5/src/tools/cyclops_server/logging.h
===================================================================
--- gaia-2.4.5.orig/src/tools/cyclops_server/logging.h
+++ gaia-2.4.5/src/tools/cyclops_server/logging.h
@@ -25,7 +25,7 @@
 
 inline QDebug clog() {
   return qDebug() << QString("%1:").arg(QDateTime::currentDateTime().toString())
-    .toAscii().constData(); // toAscii.constData to avoid the "..." around QStrings
+    .toLatin1().constData(); // toLatin1.constData to avoid the "..." around QStrings
 }
 
 #endif // GAIA_CYCLOPSLOGGING_H
Index: gaia-2.4.5/src/tools/cyclops_server/yamlrpcserver.cpp
===================================================================
--- gaia-2.4.5.orig/src/tools/cyclops_server/yamlrpcserver.cpp
+++ gaia-2.4.5/src/tools/cyclops_server/yamlrpcserver.cpp
@@ -19,7 +19,7 @@
 
 #include <QTcpSocket>
 #include <QStringList>
-#include <QHttpRequestHeader>
+//#include <QHttpRequestHeader>
 #include <QUrl>
 #include <QDateTime>
 #include "yamlrpcserver.h"
@@ -72,16 +72,26 @@ QByteArray readHTTPRequest(QTcpSocket* s
   bool done = false;
 
   QStringList headers;
-  QHttpRequestHeader httpHeader;
+ // QHttpRequestHeader httpHeader;
 
   // if asked for a GET on /status, this should return the equivalent of a well-formed Yaml-RPC call
   bool wantStatus = false;
+  int contentLength = 0;
 
   while (!done && (socket->bytesAvailable() > 0 || socket->waitForReadyRead())) {
     QString line = socket->readLine();
+    if (line.startsWith("Content-Length:")) {
+        int index = sizeof("Content-Length:") - 1;
+        const auto end = std::find(line.cbegin() + index, line.cend(), '\r');
+        auto num = line.mid(index, std::distance(line.cbegin() + index, end));
+        bool ok;
+        int tmp = num.toInt(&ok);
+        if (ok)
+            contentLength = tmp;
+    }
 
     if (line.trimmed().isEmpty())  {
-      httpHeader = QHttpRequestHeader(headers.join(""));
+      //httpHeader = QHttpRequestHeader(headers.join(""));
       done = true;
     }
     else {
@@ -93,12 +103,12 @@ QByteArray readHTTPRequest(QTcpSocket* s
   }
 
   QByteArray msgbytes;
-  int messageLength = httpHeader.contentLength();
-  msgbytes.reserve(messageLength + 1); // +1 for final '\0' (necessary?)
+  //int messageLength = httpHeader.contentLength();
+  msgbytes.reserve(contentLength + 1); // +1 for final '\0' (necessary?)
 
-  while ((msgbytes.size() < messageLength) && (socket->bytesAvailable() > 0 || socket->waitForReadyRead())) {
+  while ((msgbytes.size() < contentLength) && (socket->bytesAvailable() > 0 || socket->waitForReadyRead())) {
     // TODO: need to make sure the socket is still valid, as the next call might return because of an error
-    msgbytes.append(socket->read(messageLength - msgbytes.size()));
+    msgbytes.append(socket->read(contentLength - msgbytes.size()));
   }
 
   if (wantStatus) {