Skip to contentSkip to conversation

Modernize phonesim codebase

PATCH Applied Jonah Brüchert 2 participants 21 messages Nov 12, 2019 – Nov 18, 2019

lore
Share & tools
lore
#0 lore raw

Dear maintainers,
as mentioned earlier I'm now sending the remaining patches to ofono phonesim.

I tried to split them up logically and to explain them in their descriptions. If anything is still unclear, please ask. Overall the patchset fixes all compiler warnings that appear with the recommedations of Qt, as found in QtCreator.

The changes that have been made automatically using clang tooling are marked as such in their descriptions, and should be reproducible when running clang-tidy again.

Some of the patches are independent of the others and can be left out if not wanted.

I'd still require some help testing the scripting functionality after my changes. If someone has a working scripting setup, I'd be glad if they could test this. The changes related to scripting are basically a switch of the java script engine from the deprecated QtScript to QtQml.

Kind regards,
Jonah

#1 lore raw

PATCH 1/13 Use nullptrs

Done using the modernize-use-nullptr check of clang-tidy

---
 src/aidapplication.h              |  2 +-
 src/callmanager.h                 |  2 +-
 src/conformancesimapplication.cpp |  2 +-
 src/control.cpp                   |  2 +-
 src/control.h                     |  2 +-
 src/gsmspec.cpp                   | 20 ++++++------
 src/hardwaremanipulator.h         |  2 +-
 src/main.cpp                      |  6 ++--
 src/phonesim.cpp                  | 54 +++++++++++++++----------------
 src/phonesim.h                    |  2 +-
 src/qatresult.cpp                 |  2 +-
 src/qatresultparser.cpp           |  8 ++---
 src/qatutils.cpp                  | 12 +++----
 src/qcbsmessage.cpp               |  2 +-
 src/qsmsmessage.cpp               |  8 ++---
 src/qsmsmessage_p.h               |  4 +--
 src/qwsppdu.cpp                   |  4 +--
 src/server.cpp                    |  4 +--
 src/simapplication.cpp            | 22 ++++++-------
 src/simapplication.h              |  6 ++--
 20 files changed, 83 insertions(+), 83 deletions(-)
src/aidapplication.h +1 -1
index 6a2f4d9..d8b1b93 100644
@@ -66,7 +66,7 @@ class AidAppWrapper : public QObject
 {
     Q_OBJECT
 public:
-    AidAppWrapper( SimRules *r, QList<AidApplication *> apps, SimAuth *auth = NULL );
+    AidAppWrapper( SimRules *r, QList<AidApplication *> apps, SimAuth *auth = nullptr );
     ~AidAppWrapper();
 
     bool command( const QString& cmd );
src/callmanager.h +1 -1
index c34e7fd..9b1eef0 100644
@@ -51,7 +51,7 @@ class CallManager : public QObject
 {
     Q_OBJECT
 public:
-    CallManager( QObject *parent = 0 );
+    CallManager( QObject *parent = nullptr );
     ~CallManager();
 
     // Process an AT command.  Returns false if not a call-related command.
src/conformancesimapplication.cpp +1 -1
index 108b060..2817b0c 100644
@@ -147,7 +147,7 @@ void ConformanceSimApplication::mainMenu()
 
     cmd.setMenuItems( items );
 
-    command( cmd, 0, 0 );
+    command( cmd, nullptr, nullptr );
 }
 
 void ConformanceSimApplication::mainMenuSelection( int id )
src/control.cpp +1 -1
index 5eb82f1..1ea5294 100644
@@ -503,7 +503,7 @@ void ControlWidget::resetTranslator()
 {
     QString fileName = QFileDialog::getOpenFileName(this,
      tr("Open Specification File"), QDir::homePath(), tr("Specification files (*.xml)"));
-    if(fileName != 0)
+    if(fileName != nullptr)
         translator->resetSpecification(fileName);
 }
 
src/control.h +1 -1
index fd1a4e6..6514bf4 100644
@@ -149,7 +149,7 @@ class Control: public HardwareManipulator
 Q_OBJECT
 
 public:
-    Control(const QString& ruleFile, SimRules *sr, QObject *parent=0);
+    Control(const QString& ruleFile, SimRules *sr, QObject *parent=nullptr);
     virtual ~Control();
 
 public slots:
src/gsmspec.cpp +10 -10
index 013ef62..fbb7e2a 100644
@@ -137,11 +137,11 @@ void GSMSpec::setupDictionary(const QString& filePath)
     GsmXmlNode *specNode = handler->documentElement()->children;
     QString command, profile, format, response, description;
 
-    while ( specNode != 0 ) {
+    while ( specNode != nullptr ) {
         if ( specNode->tag == "spec" ) {
 
             GsmXmlNode *specData = specNode->children;
-            while ( specData != 0 ) {
+            while ( specData != nullptr ) {
 
                 if( specData->tag == "command" ) {
                     command = specData->contents;
@@ -171,10 +171,10 @@ void GSMSpec::setupDictionary(const QString& filePath)
 
 GsmXmlNode::GsmXmlNode( const QString& _tag )
 {
-    parent = 0;
-    next = 0;
-    children = 0;
-    attributes = 0;
+    parent = nullptr;
+    next = nullptr;
+    children = nullptr;
+    attributes = nullptr;
     tag = _tag;
 }
 
@@ -200,7 +200,7 @@ GsmXmlNode::~GsmXmlNode()
 void GsmXmlNode::addChild( GsmXmlNode *child )
 {
     GsmXmlNode *current = children;
-    GsmXmlNode *prev = 0;
+    GsmXmlNode *prev = nullptr;
     while ( current ) {
         prev = current;
         current = current->next;
@@ -210,7 +210,7 @@ void GsmXmlNode::addChild( GsmXmlNode *child )
     } else {
         children = child;
     }
-    child->next = 0;
+    child->next = nullptr;
     child->parent = this;
 }
 
@@ -218,7 +218,7 @@ void GsmXmlNode::addChild( GsmXmlNode *child )
 void GsmXmlNode::addAttribute( GsmXmlNode *child )
 {
     GsmXmlNode *current = attributes;
-    GsmXmlNode *prev = 0;
+    GsmXmlNode *prev = nullptr;
     while ( current ) {
         prev = current;
         current = current->next;
@@ -228,7 +228,7 @@ void GsmXmlNode::addAttribute( GsmXmlNode *child )
     } else {
         attributes = child;
     }
-    child->next = 0;
+    child->next = nullptr;
     child->parent = this;
 }
 
src/hardwaremanipulator.h +1 -1
index 87a8c6e..ae071e5 100644
@@ -34,7 +34,7 @@ class HardwareManipulator : public QObject
 Q_OBJECT
 
 public:
-    HardwareManipulator(SimRules *sr, QObject *parent=0);
+    HardwareManipulator(SimRules *sr, QObject *parent=nullptr);
     QSMSMessageList & getSMSList();
     bool getSimPresent();
     QStringList getSimAppsNameList();
src/main.cpp +3 -3
index 684a9b7..b320140 100644
@@ -34,7 +34,7 @@ static void usage()
 
 int main(int argc, char **argv)
 {
-    QString filename = NULL;
+    QString filename = nullptr;
     QCoreApplication *app;
     int port = 12345;
     int index;
@@ -72,7 +72,7 @@ int main(int argc, char **argv)
 
     }
 
-    if (filename == NULL) {
+    if (filename == nullptr) {
         qWarning() << "ERROR: filename must be the last argument";
         usage();
     }
@@ -85,7 +85,7 @@ int main(int argc, char **argv)
     } else
         app = new QCoreApplication(argc, argv);
 
-    PhoneSimServer *pss = new PhoneSimServer(filename, port, 0);
+    PhoneSimServer *pss = new PhoneSimServer(filename, port, nullptr);
 
     if (with_gui)
         pss->setHardwareManipulator(new ControlFactory);
src/phonesim.cpp +27 -27

157 lines not on this page · raw message

src/phonesim.h +1 -1
index 466f88d..fef97d4 100644
@@ -386,7 +386,7 @@ class QVariantTimer : public QTimer
 {
     Q_OBJECT
 public:
-    QVariantTimer( QObject *parent = 0 ) : QTimer(parent) { }
+    QVariantTimer( QObject *parent = nullptr ) : QTimer(parent) { }
     QVariant param;
 };
 
src/qatresult.cpp +1 -1
index d4b8cab..9a29503 100644
@@ -45,7 +45,7 @@ public:
         result = "OK";
         resultCode = QAtResult::OK;
         verbose = true;
-        userData = 0;
+        userData = nullptr;
     }
     ~QAtResultPrivate()
     {
src/qatresultparser.cpp +4 -4
index 0cc0b24..cba41ad 100644
@@ -328,7 +328,7 @@ QAtResultParser::Node::Node( uint number )
 {
     _kind = Number;
     _number = number;
-    _list = 0;
+    _list = nullptr;
 }
 
 QAtResultParser::Node::Node( uint first, uint last )
@@ -336,14 +336,14 @@ QAtResultParser::Node::Node( uint first, uint last )
     _kind = Range;
     _number = first;
     _last = last;
-    _list = 0;
+    _list = nullptr;
 }
 
 QAtResultParser::Node::Node( const QString& str )
 {
     _kind = String;
     _str = str;
-    _list = 0;
+    _list = nullptr;
 }
 
 QAtResultParser::Node::Node( QList<Node> *list )
@@ -361,7 +361,7 @@ QAtResultParser::Node::Node( const Node& other )
     _number = other._number;
     _last = other._last;
     _str = other._str;
-    _list = ( other._list ? new QList<Node>( *other._list ) : 0 );
+    _list = ( other._list ? new QList<Node>( *other._list ) : nullptr );
 }
 
 /*!
src/qatutils.cpp +6 -6
index 6fa191f..51161bb 100644
@@ -923,18 +923,18 @@ QByteArray QCodePage850Codec::convertFromUnicode(const QChar *in, int length, Co
 QTextCodec *QAtUtils::codec( const QString& gsmCharset )
 {
     QString cs = gsmCharset.toLower();
-    QTextCodec *codec = 0;
+    QTextCodec *codec = nullptr;
 
     // Convert the name into an appropriate codec.
     if ( cs == "gsm" ) {
         // 7-bit GSM character set.
-        static QTextCodec *gsm = 0;
+        static QTextCodec *gsm = nullptr;
         if ( !gsm )
             gsm = new QGsmCodec();
         codec = gsm;
     } else if ( cs == "gsm-noloss" ) {
         // 7-bit GSM character set, with no loss of quality.
-        static QTextCodec *gsmNoLoss = 0;
+        static QTextCodec *gsmNoLoss = nullptr;
         if ( !gsmNoLoss )
             gsmNoLoss = new QGsmCodec( true );
         codec = gsmNoLoss;
@@ -943,13 +943,13 @@ QTextCodec *QAtUtils::codec( const QString& gsmCharset )
         // be anything according to the specification, but we need to pick
         // something.  We assume that it is 7-bit GSM, as that is the most
         // likely value.
-        static QTextCodec *hex = 0;
+        static QTextCodec *hex = nullptr;
         if ( !hex )
             hex = new QGsmHexCodec();
         codec = hex;
     } else if ( cs == "ucs2" ) {
         // Hex-encoded UCS2 character set.
-        static QTextCodec *ucs2 = 0;
+        static QTextCodec *ucs2 = nullptr;
         if ( !ucs2 )
             ucs2 = new QUcs2HexCodec();
         codec = ucs2;
@@ -964,7 +964,7 @@ QTextCodec *QAtUtils::codec( const QString& gsmCharset )
         // to handle embedded UCS-2 character strings.  A hex UCS-2 string
         // will start with "80" and end with "FFFF".  If the string does
         // not have this format, it is interpreted as code page 437.
-        static QTextCodec *cp437 = 0;
+        static QTextCodec *cp437 = nullptr;
         if ( !cp437 )
             cp437 = new QCodePage437Codec();
         codec = cp437;
src/qcbsmessage.cpp +1 -1
index a1c0913..b56a761 100644
@@ -135,7 +135,7 @@ QCBSMessage::QCBSMessage()
 */
 QCBSMessage::QCBSMessage(const QCBSMessage &msg)
 {
-    d = 0;
+    d = nullptr;
     *this = msg;
 }
 
src/qsmsmessage.cpp +4 -4
index 63d6952..ec158ef 100644
@@ -85,7 +85,7 @@ public:
         mReplyRequest = false;
         mStatusReportRequested = false;
         mMessageType = QSMSMessage::Normal;
-        mCodec = 0;
+        mCodec = nullptr;
         mForceGsm = false;
         mBestScheme = (QSMSDataCodingScheme)(-1);
         mDataCodingScheme = -1;
@@ -2030,7 +2030,7 @@ QString QPDUMessage::userData(QSMSDataCodingScheme scheme, QTextCodec *codec, QB
     uint ch;
 
     // Reset the header return.
-    headers = 0;
+    headers = nullptr;
 
     // Get the length of the user data payload.
     if ( implicitLength ) {
@@ -2437,7 +2437,7 @@ QSMSMessage QSMSDeliverMessage::unpack(QTextCodec *codec)
     }
 
     // Read the user data field.
-    QByteArray *headers = 0;
+    QByteArray *headers = nullptr;
     QString text;
     text = userData( (QSMSDataCodingScheme)scheme, codec,
                      headers, userDataHeader, false );
@@ -2590,7 +2590,7 @@ QCBSMessage QCBSDeliverMessage::unpack(QTextCodec *codec)
     mPosn += 6;
 
     // Read the user data field and strip CR's, LF's, and NUL's from the end.
-    QByteArray *headers = 0;
+    QByteArray *headers = nullptr;
     QString text = userData
         ( (QSMSDataCodingScheme)scheme, codec, headers, false, true );
     len = text.length();
src/qsmsmessage_p.h +2 -2
index f26d066..49060c7 100644
@@ -169,7 +169,7 @@ class QSMSDeliverMessage: public QPDUMessage
 public:
     explicit QSMSDeliverMessage(const QByteArray &pdu);
 
-    QSMSMessage unpack(QTextCodec *codec=0);
+    QSMSMessage unpack(QTextCodec *codec=nullptr);
 };
 
 class QCBSDeliverMessage: public QPDUMessage
@@ -178,7 +178,7 @@ public:
     QCBSDeliverMessage();
     explicit QCBSDeliverMessage(const QByteArray &pdu);
 
-    QCBSMessage unpack(QTextCodec *codec=0);
+    QCBSMessage unpack(QTextCodec *codec=nullptr);
     void pack(const QCBSMessage &m, QSMSDataCodingScheme scheme);
 };
 
src/qwsppdu.cpp +2 -2
index 49b9405..f487a35 100644
@@ -108,7 +108,7 @@ static const char * const contentTypeAssignments[] = {
     "application/vnd.oma.drm.content",
     "application/vnd.oma.drm.rights+xml",
     "application/vnd.oma.drm.rights+wbxml",
-    0
+    nullptr
 };
 #define numContentTypes (int)((sizeof(contentTypeAssignments) / \
                                sizeof(char *)) - 1)
@@ -1731,7 +1731,7 @@ const QWspField *QWspPart::header(const QString &name) const
             return &(*it);
     }
 
-    return 0;
+    return nullptr;
 }
 
 /*!
src/server.cpp +2 -2
index 62487ee..3ff7def 100644
@@ -25,7 +25,7 @@
 static int phonenumber = 555000;
 
 PhoneSimServer::PhoneSimServer(const QString &f, quint16 port, QObject *parent)
-    : QTcpServer(parent), fact(0), currentRules(0)
+    : QTcpServer(parent), fact(nullptr), currentRules(nullptr)
 {
     listen( QHostAddress::Any, port );
     filename = f;
@@ -33,7 +33,7 @@ PhoneSimServer::PhoneSimServer(const QString &f, quint16 port, QObject *parent)
 
 PhoneSimServer::~PhoneSimServer()
 {
-    setHardwareManipulator(0);
+    setHardwareManipulator(nullptr);
 }
 
 void PhoneSimServer::setHardwareManipulator(HardwareManipulatorFactory *f)
src/simapplication.cpp +11 -11
index c491674..f9169f2 100644
@@ -30,8 +30,8 @@ public:
     {
         expectedType = QSimCommand::NoCommand;
         modemHandled = false;
-        target = 0;
-        slot = 0;
+        target = nullptr;
+        slot = nullptr;
         inResponse = false;
     }
 
@@ -136,8 +136,8 @@ void SimApplication::abort()
     d->expectedType = QSimCommand::NoCommand;
     d->modemHandled = false;
     d->currentCommand = QByteArray();
-    d->target = 0;
-    d->slot = 0;
+    d->target = nullptr;
+    d->slot = nullptr;
     endSession();
 }
 
@@ -196,8 +196,8 @@ bool SimApplication::envelope( const QSimEnvelope& env )
 
     d->expectedType = QSimCommand::NoCommand;
     d->currentCommand = QByteArray();
-    d->target = 0;
-    d->slot = 0;
+    d->target = nullptr;
+    d->slot = nullptr;
     if ( env.requestHelp() )
         mainMenuHelpRequest( env.menuItem() );
     else
@@ -235,8 +235,8 @@ bool SimApplication::response( const QSimTerminalResponse& resp )
         d->modemHandled = false;
         d->currentCommand = QByteArray();
     }
-    d->target = 0;
-    d->slot = 0;
+    d->target = nullptr;
+    d->slot = nullptr;
 
     // Process the response.
     d->inResponse = true;
@@ -247,7 +247,7 @@ bool SimApplication::response( const QSimTerminalResponse& resp )
         int index = target->metaObject()->indexOfMethod( name.constData() );
         if ( index != -1 ) {
             void *args[2];
-            args[0] = 0;
+            args[0] = nullptr;
             args[1] = (void *)&resp;
             target->qt_metacall
                 ( QMetaObject::InvokeMetaMethod, index, args );
@@ -500,7 +500,7 @@ void DemoSimApplication::mainMenu()
 
     cmd.setMenuItems( items );
 
-    command( cmd, 0, 0 );
+    command( cmd, nullptr, nullptr );
 }
 
 void DemoSimApplication::sendDisplayText()
@@ -2186,7 +2186,7 @@ void DemoSimApplication::timersMenuResp( const QSimTerminalResponse& resp )
         cmd.setTimerId( 2 );
         cmd.setDuration( 10000 );
         cmd.setDestinationDevice( QSimCommand::ME );
-        command( cmd, NULL, NULL );
+        command( cmd, nullptr, nullptr );
         break;
 
     case Timers_Query:
src/simapplication.h +3 -3
index d80d0e6..c5c6501 100644
@@ -32,7 +32,7 @@ class SimApplication : public QObject
 {
     Q_OBJECT
 public:
-    SimApplication( SimRules *rules, QObject *parent = 0 );
+    SimApplication( SimRules *rules, QObject *parent = nullptr );
     ~SimApplication();
 
     virtual bool envelope( const QSimEnvelope& env );
@@ -67,7 +67,7 @@ class DemoSimApplication : public SimApplication
 {
     Q_OBJECT
 public:
-    DemoSimApplication( SimRules *rules, QObject *parent = 0 );
+    DemoSimApplication( SimRules *rules, QObject *parent = nullptr );
     ~DemoSimApplication();
 
     const QString getName();
@@ -148,7 +148,7 @@ class ConformanceSimApplication : public SimApplication
 {
     Q_OBJECT
 public:
-    ConformanceSimApplication( SimRules *rules, QObject *parent = 0 );
+    ConformanceSimApplication( SimRules *rules, QObject *parent = nullptr );
     ~ConformanceSimApplication();
 
     const QString getName();

--
2.24.0

#2 lore raw

Re: [PATCH phonesim 01/13] Use nullptrs

Hi Jonah,

Quoted 15 lines · Jonah Brüchert

Done using the modernize-use-nullptr check of clang-tidy

---
  src/aidapplication.h              |  2 +-
  src/callmanager.h                 |  2 +-
  src/conformancesimapplication.cpp |  2 +-
  src/control.cpp                   |  2 +-
  src/control.h                     |  2 +-
  src/gsmspec.cpp                   | 20 ++++++------
  src/hardwaremanipulator.h         |  2 +-
  src/main.cpp                      |  6 ++--
  src/phonesim.cpp                  | 54 +++++++++++++++----------------
  src/phonesim.h                    |  2 +-
  src/qatresult.cpp                 |  2 +-
  src/qatresultparser.cpp           |  8 ++---
  src/qatutils.cpp                  | 12 +++----
Quoted 9 lines
  src/qcbsmessage.cpp               |  2 +-
  src/qsmsmessage.cpp               |  8 ++---
  src/qsmsmessage_p.h               |  4 +--
  src/qwsppdu.cpp                   |  4 +--
  src/server.cpp                    |  4 +--
  src/simapplication.cpp            | 22 ++++++-------
  src/simapplication.h              |  6 ++--
  20 files changed, 83 insertions(+), 83 deletions(-)

Patches 1 & 2 applied, thanks.

Regards,
-Denis

#3 lore raw

PATCH 2/13 Replace deprecated headers

In reply to Jonah Brüchert

Done using the modernize-deprecated-headers check of clang-tidy

---
 src/main.cpp        | 2 +-
 src/phonesim.h      | 6 +++---
 src/qsmsmessage.cpp | 2 +-
 src/qwsppdu.cpp     | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)
src/main.cpp +1 -1
index b320140..712e767 100644
@@ -22,7 +22,7 @@
 #include <qapplication.h>
 #include <qstring.h>
 #include <qdebug.h>
-#include <stdlib.h>
+#include <cstdlib>
 
 static void usage()
 {
src/phonesim.h +3 -3
index fef97d4..65ea794 100644
@@ -33,11 +33,11 @@
 #include <qpointer.h>
 #include <qsimcontrolevent.h>
 
-#include <string.h>
-#include <stdlib.h>
+#include <cstring>
+#include <cstdlib>
 #include <sys/types.h>
 #include <unistd.h>
-#include <signal.h>
+#include <csignal>
 #include <sys/time.h>
 #include <sys/wait.h>
 #include <sys/select.h>
src/qsmsmessage.cpp +1 -1
index ec158ef..518e542 100644
@@ -17,7 +17,7 @@
 **
 ****************************************************************************/
 
-#include <stdlib.h>
+#include <cstdlib>
 
 #include <qsmsmessage.h>
 #include <qcbsmessage.h>
src/qwsppdu.cpp +1 -1
index f487a35..def5675 100644
@@ -24,7 +24,7 @@
 #include <qiodevice.h>
 #include <qbuffer.h>
 #include <netinet/in.h>
-#include <stdlib.h>
+#include <cstdlib>
 
 // Reference: WAP-230-WSP
 //            Wireless Application Protocol

--
2.24.0

#4 lore raw

PATCH 3/13 Port old-style connects

In reply to Jonah Brüchert

* Update CXX Standard to 14 to be able to use qOverload()

---
 configure.ac        |  4 +--
 src/callmanager.cpp | 22 ++++++-------
 src/control.cpp     | 77 +++++++++++++++++++++------------------------
 src/phonesim.cpp    | 56 +++++++++++++++++----------------
 src/phonesim.h      |  3 +-
 5 files changed, 80 insertions(+), 82 deletions(-)
configure.ac +2 -2
index e339691..5cc4545 100644
@@ -25,8 +25,8 @@ AC_ARG_ENABLE(optimization, AC_HELP_STRING([--disable-optimization],
 PKG_CHECK_MODULES(QT, Qt5Core Qt5Gui Qt5Xml Qt5Network Qt5Script Qt5DBus Qt5Widgets, dummy=yes,
 						AC_MSG_ERROR(Qt is required))
 
-# Needed for Qt 5.7
-CXXFLAGS="$CXXFLAGS --std=gnu++11"
+# Needed for qOverload
+CXXFLAGS="$CXXFLAGS --std=gnu++14"
 
 AC_SUBST(QT_CFLAGS)
 AC_SUBST(QT_LIBS)
src/callmanager.cpp +11 -11
index 1995c6d..fbdb179 100644
@@ -33,11 +33,11 @@ CallManager::CallManager( QObject *parent )
 
     hangupTimer = new QTimer(this);
     hangupTimer->setSingleShot(true);
-    connect( hangupTimer, SIGNAL(timeout()), this, SLOT(hangupTimeout()) );
+    connect( hangupTimer, &QTimer::timeout, this, &CallManager::hangupTimeout );
 
     ringTimer = new QTimer(this);
     ringTimer->setSingleShot(true);
-    connect( ringTimer, SIGNAL(timeout()), this, SLOT(sendNextRing()) );
+    connect( ringTimer, &QTimer::timeout, this, &CallManager::sendNextRing );
 }
 
 CallManager::~CallManager()
@@ -92,19 +92,19 @@ bool CallManager::command( const QString& cmd )
         // Check for special dial-back numbers.
         if ( number == "199" ) {
             send( "NO CARRIER" );
-            QTimer::singleShot( 5000, this, SLOT(dialBack()) );
+            QTimer::singleShot( 5000, this, &CallManager::dialBack );
             return true;
         } else if ( number == "1993" ) {
             send( "NO CARRIER" );
-            QTimer::singleShot( 30000, this, SLOT(dialBack()) );
+            QTimer::singleShot( 30000, this, &CallManager::dialBack );
             return true;
         } else if ( number == "177" ) {
             send( "NO CARRIER" );
-            QTimer::singleShot( 2000, this, SLOT(dialBackWithHangup5()) );
+            QTimer::singleShot( 2000, this, &CallManager::dialBackWithHangup5 );
             return true;
         } else if ( number == "166" ) {
             send( "NO CARRIER" );
-            QTimer::singleShot( 1000, this, SLOT(dialBackWithHangup4()) );
+            QTimer::singleShot( 1000, this, &CallManager::dialBackWithHangup4 );
             return true;
         } else if ( number == "155" ) {
             send( "BUSY" );
@@ -156,11 +156,11 @@ bool CallManager::command( const QString& cmd )
 
         // Automatic accept of calls
         if ( number == "6789" ) {
-            QTimer::singleShot( 1000, this, SLOT(dialingToConnected()) );
+            QTimer::singleShot( 1000, this, &CallManager::dialingToConnected );
         } else if ( number.startsWith( "05123" ) ) {
-            QTimer::singleShot( 1000, this, SLOT(dialingToConnected()) );
+            QTimer::singleShot( 1000, this, &CallManager::dialingToConnected );
         } else if ( number.startsWith( "06123" ) ) {
-            QTimer::singleShot( 1000, this, SLOT(dialingToAlerting()) );
+            QTimer::singleShot( 1000, this, &CallManager::dialingToAlerting );
         }
 
     // Data call - phone number 696969
@@ -726,7 +726,7 @@ void CallManager::dialingToConnected()
         temp = temp.replace( "05123" , "" );
         int timeout = temp.toInt( &ok, 10 );
         timeout = ok ? timeout * 1000 : 10000;
-        QTimer::singleShot( timeout, this, SLOT(hangup()) );
+        QTimer::singleShot( timeout, this, &CallManager::hangup );
     }
 }
 
@@ -750,7 +750,7 @@ void CallManager::dialingToAlerting()
         temp = temp.replace( "06123" , "" );
         int timeout = temp.toInt( &ok, 10 );
         timeout = ok ? timeout * 1000 : 10000;
-        QTimer::singleShot( timeout, this, SLOT(dialingToConnected()) );
+        QTimer::singleShot( timeout, this, &CallManager::dialingToConnected );
     }
 }
 
src/control.cpp +36 -41

89 lines not on this page · raw message

src/phonesim.cpp +29 -27

85 lines not on this page · raw message

src/phonesim.h +2 -1
index 65ea794..ac5084d 100644
@@ -300,6 +300,8 @@ public slots:
     // Set a variable to a new value.
     void setVariable( const QString& name, const QString& value );
 
+    void delaySetVariable();
+
     // Switch to a new simulator state.
     void switchTo(const QString& name);
 
@@ -320,7 +322,6 @@ private slots:
     void tryReadCommand();
     void destruct();
     void delayTimeout();
-    void delaySetVariable();
     void dialCheck( const QString& number, bool& ok );
 
 private:

--
2.24.0

#5 lore raw

Re: [PATCH phonesim 03/13] Port old-style connects

Hi Jonah,

Quoted 9 lines · Jonah Brüchert

* Update CXX Standard to 14 to be able to use qOverload()

---
  configure.ac        |  4 +--
  src/callmanager.cpp | 22 ++++++-------
  src/control.cpp     | 77 +++++++++++++++++++++------------------------
  src/phonesim.cpp    | 56 +++++++++++++++++----------------
  src/phonesim.h      |  3 +-
  5 files changed, 80 insertions(+), 82 deletions(-)

<snip>

Quoted 13 lines
src/phonesim.cpp +1 -8
@@ -527,35 +528,36 @@ SimRules::SimRules(qintptr fd, QObject *p,  const QString& filename, HardwareMan
          machine = hmf->create(this, nullptr);
 
      if (machine) {
-        connect(machine, SIGNAL(unsolicitedCommand(QString)),
-                this, SLOT(unsolicited(QString)));
-        connect(machine, SIGNAL(command(QString)),
-                this, SLOT(command(QString)));
-        connect(machine, SIGNAL(variableChanged(QString,QString)),
-                this, SLOT(setVariable(QString,QString)));
-        connect(machine, SIGNAL(switchTo(QString)),
-                this, SLOT(switchTo(QString)));
+        connect(machine, &HardwareManipulator::unsolicitedCommand,

src/phonesim.cpp SimRules::SimRules(qintptr fd, QObject *p, const QString& filename, HardwareMan · line 541

Quoted 10 lines
src/phonesim.cpp +8 -0
+                this, &SimRules::unsolicited);
+        connect(machine, &HardwareManipulator::command,
+                this, &SimRules::command);
+        connect(machine, &HardwareManipulator::variableChanged,
+                this, &SimRules::setVariable);
+        connect(machine, &HardwareManipulator::switchTo,
+                this, &SimRules::switchTo);
      }
 
+

I squashed this stray whitespace...

Quoted 28 lines
src/phonesim.cpp +9 -16
      _callManager = new CallManager(this);
-    connect( _callManager, SIGNAL(send(QString)),
-             this, SLOT(respond(QString)) );
-    connect( _callManager, SIGNAL(unsolicited(QString)),
-             this, SLOT(unsolicited(QString)) );
-    connect( _callManager, SIGNAL(dialCheck(QString,bool&)),
-             this, SLOT(dialCheck(QString,bool&)) );
+    connect( _callManager, &CallManager::send,
+             this, qOverload<const QString &>( &SimRules::respond ) );
+    connect( _callManager, &CallManager::unsolicited,
+             this, &SimRules::unsolicited );
+    connect( _callManager, &CallManager::dialCheck,
+             this, &SimRules::dialCheck );
 
      if ( machine ) {
-        connect( machine, SIGNAL(startIncomingCall(QString,QString,QString)),
-                 _callManager, SLOT(startIncomingCall(QString,QString,QString)) );
-        connect ( _callManager, SIGNAL( callStatesChanged( QList<CallInfo> * ) ),
-                  machine, SLOT( callManagement( QList<CallInfo> * ) ) );
-        connect ( machine, SIGNAL( stateChangedToAlerting() ), _callManager,
-                SLOT( dialingToAlerting() ) );
-        connect ( machine, SIGNAL( stateChangedToConnected() ), _callManager,
-                SLOT( dialingToConnected() ) );
-        connect ( machine, SIGNAL( stateChangedToHangup( int ) ), _callManager,
-                SLOT( hangupRemote( int ) ) );
+        connect( machine, &HardwareManipulator::startIncomingCall, _callManager,
+                 qOverload<const QString &, const QString &, const QString &>( &CallManager::startIncomingCall ) );
+        connect ( _callManager, &CallManager::callStatesChanged,

src/phonesim.cpp SimRules::SimRules(qintptr fd, QObject *p, const QString& filename, HardwareMan · line 563

Quoted 10 lines
src/phonesim.cpp +7 -0
+                  machine, &HardwareManipulator::callManagement);
+        connect ( machine, &HardwareManipulator::stateChangedToAlerting, _callManager,
+                &CallManager::dialingToAlerting );
+        connect ( machine, &HardwareManipulator::stateChangedToConnected, _callManager,
+                &CallManager::dialingToConnected );
+        connect ( machine, &HardwareManipulator::stateChangedToHangup, _callManager,
+                &CallManager::hangupRemote );
      }
 
      connect(this,SIGNAL(readyRead()),

... and applied this patch.

Regards,
-Denis

#6 lore raw

PATCH 4/13 Replace QtScript with QtQml

In reply to Jonah Brüchert
---
 configure.ac    |  2 +-
 src/control.cpp | 18 +++++++++---------
 src/control.h   |  4 ++--
 3 files changed, 12 insertions(+), 12 deletions(-)
configure.ac +1 -1
index 5cc4545..0587f9f 100644
@@ -22,7 +22,7 @@ AC_ARG_ENABLE(optimization, AC_HELP_STRING([--disable-optimization],
 	fi
 ])
 
-PKG_CHECK_MODULES(QT, Qt5Core Qt5Gui Qt5Xml Qt5Network Qt5Script Qt5DBus Qt5Widgets, dummy=yes,
+PKG_CHECK_MODULES(QT, Qt5Core Qt5Gui Qt5Xml Qt5Network Qt5Qml Qt5DBus Qt5Widgets, dummy=yes,
 						AC_MSG_ERROR(Qt is required))
 
 # Needed for qOverload
src/control.cpp +9 -9
index d4732b7..8c1e412 100644
@@ -641,28 +641,28 @@ void ControlWidget::modemSilentReset()
 Script::Script(QObject *obj, Ui_ControlBase *ui) : QDBusAbstractAdaptor(obj)
 {
     /* Export tabs to be accessed by script */
-    QScriptValue qsTab = engine.newQObject(ui->tab);
+    QJSValue qsTab = engine.newQObject(ui->tab);
     engine.globalObject().setProperty("tabRegistration", qsTab);
 
-    QScriptValue qsTab2 = engine.newQObject(ui->tab_2);
+    QJSValue qsTab2 = engine.newQObject(ui->tab_2);
     engine.globalObject().setProperty("tabCBM", qsTab2);
 
-    QScriptValue qsTab3 = engine.newQObject(ui->tab_3);
+    QJSValue qsTab3 = engine.newQObject(ui->tab_3);
     engine.globalObject().setProperty("tabSMS", qsTab3);
 
-    QScriptValue qsTab4 = engine.newQObject(ui->tab_4);
+    QJSValue qsTab4 = engine.newQObject(ui->tab_4);
     engine.globalObject().setProperty("tabVoiceMail", qsTab4);
 
-    QScriptValue qsTab5 = engine.newQObject(ui->tab_5);
+    QJSValue qsTab5 = engine.newQObject(ui->tab_5);
     engine.globalObject().setProperty("tabUSSD", qsTab5);
 
-    QScriptValue qsTab6 = engine.newQObject(ui->tab_6);
+    QJSValue qsTab6 = engine.newQObject(ui->tab_6);
     engine.globalObject().setProperty("tabSIM", qsTab6);
 
-    QScriptValue qsTab8 = engine.newQObject(ui->tab_8);
+    QJSValue qsTab8 = engine.newQObject(ui->tab_8);
     engine.globalObject().setProperty("tabPosition", qsTab8);
 
-    QScriptValue qsTab9 = engine.newQObject(ui->tab_9);
+    QJSValue qsTab9 = engine.newQObject(ui->tab_9);
     engine.globalObject().setProperty("tabCall", qsTab9);
 }
 
@@ -705,7 +705,7 @@ QString Script::Run(const QString &name, const QDBusMessage &msg)
     QString contents = stream.readAll();
     scriptFile.close();
 
-    QScriptValue qsScript = engine.evaluate(contents);
+    QJSValue qsScript = engine.evaluate(contents);
     if (qsScript.isError()) {
         QString info = fileName + ", line " + qsScript.property("lineNumber").toString() + ", " + qsScript.toString();
         QDBusMessage reply = msg.createErrorReply(SERVICE ".Error.ScriptExecError", info);
src/control.h +2 -2
index 6514bf4..a7c0ff3 100644
@@ -22,7 +22,7 @@
 
 #include <hardwaremanipulator.h>
 #include <QtDBus/QtDBus>
-#include <QtScript>
+#include <QJSEngine>
 #include "ui_controlbase.h"
 #include "attranslator.h"
 #include "callmanager.h"
@@ -58,7 +58,7 @@ public slots:
 
 private:
     QString dirPath;
-    QScriptEngine engine;
+    QJSEngine engine;
 };
 
 class ControlWidget : public QWidget

--
2.24.0

#7 lore raw

Re: [PATCH phonesim 04/13] Replace QtScript with QtQml

Hi Jonah,

Quoted 6 lines · Jonah Brüchert
---
  configure.ac    |  2 +-
  src/control.cpp | 18 +++++++++---------
  src/control.h   |  4 ++--
  3 files changed, 12 insertions(+), 12 deletions(-)

Patches 4-9 applied, thanks.

Regards,
-Denis

#8 lore raw

PATCH 5/13 Port away from some deprecated Qt apis

In reply to Jonah Brüchert
---
 src/qsimcommand.cpp    | 4 ++++
 src/qsmsmessage.cpp    | 4 ++++
 src/qwsppdu.cpp        | 4 ++--
 src/simapplication.cpp | 2 +-
 4 files changed, 11 insertions(+), 3 deletions(-)
src/qsimcommand.cpp +4 -0
index 672ffb9..6642035 100644
@@ -3764,7 +3764,11 @@ void QSimCommand::addExtensionField( int tag, const QByteArray& value )
 QSimCommandPrivate *QSimCommand::dwrite()
 {
     // If we are the only user of the private object, return it as-is.
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
+    if ( d->ref.loadRelaxed() == 1 )
+#else
     if ( d->ref.load() == 1 )
+#endif
         return d;
 
     // Create a new private object and copy the current contents into it.
src/qsmsmessage.cpp +4 -0
index 518e542..e4e41b9 100644
@@ -365,7 +365,11 @@ QSMSMessage::~QSMSMessage()
 QSMSMessagePrivate *QSMSMessage::dwrite()
 {
     // If we are the only user of the private object, return it as-is.
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
+    if ( d->ref.loadRelaxed() == 1 )
+#else
     if ( d->ref.load() == 1 )
+#endif
         return d;
 
     // Create a new private object and copy the current contents into it.
src/qwsppdu.cpp +2 -2
index def5675..26f450d 100644
@@ -292,7 +292,7 @@ static QString secsToUTC(int seconds)
 
     int h = seconds / 3600;
     int m = ( abs(seconds) - abs(h * 3600) ) / 60;
-    str.sprintf("%+.2d%.2d", h, m );
+    str.asprintf("%+.2d%.2d", h, m );
 
     return str;
 }
@@ -413,7 +413,7 @@ QString QWspDateTime::dateString(QDateTime d)
     QByteArray dayName = date.shortDayName(date.dayOfWeek()).toUtf8();
     QByteArray monthName = date.shortMonthName(date.month()).toUtf8();
     QByteArray utcOffs = secsToUTC(timeZoneDiff()).toUtf8();
-    str.sprintf("%s, %.2d %s %d %.2d:%.2d:%.2d %s",
+    str.asprintf("%s, %.2d %s %d %.2d:%.2d:%.2d %s",
             dayName.constData(),
             date.day(),
             monthName.constData(),
src/simapplication.cpp +1 -1
index f9169f2..84058af 100644
@@ -2227,7 +2227,7 @@ void DemoSimApplication::timersCmdResp( const QSimTerminalResponse& resp )
     if ( resp.command().qualifier() == 2 ) {
         if ( resp.result() == QSimTerminalResponse::Success ) {
             QString status;
-            status.sprintf( "Timer %i expires in %i:%02i:%02i.\n",
+            status.asprintf( "Timer %i expires in %i:%02i:%02i.\n",
                     resp.timerId(), resp.duration() / 3600000,
                     (resp.duration() / 60000) % 60,
                     (resp.duration() / 1000) % 60 );

--
2.24.0

#9 lore raw

PATCH 6/13 qwsppdu: Port to QLocale

In reply to Jonah Brüchert
---
 src/qwsppdu.cpp | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
src/qwsppdu.cpp +11 -8
index 26f450d..f3a1661 100644
@@ -18,13 +18,15 @@
 ****************************************************************************/
 
 #include <qwsppdu.h>
-#include <qstringlist.h>
-#include <qtextcodec.h>
+
+#include <cstdlib>
+#include <netinet/in.h>
+#include <qbuffer.h>
 #include <qdatetime.h>
+#include <qlocale.h>
 #include <qiodevice.h>
-#include <qbuffer.h>
-#include <netinet/in.h>
-#include <cstdlib>
+#include <qstringlist.h>
+#include <qtextcodec.h>
 
 // Reference: WAP-230-WSP
 //            Wireless Application Protocol
@@ -409,9 +411,10 @@ QString QWspDateTime::dateString(QDateTime d)
 {
     QDate date = d.date();
     QTime time = d.time();
+    QLocale locale;
     QString str;
-    QByteArray dayName = date.shortDayName(date.dayOfWeek()).toUtf8();
-    QByteArray monthName = date.shortMonthName(date.month()).toUtf8();
+    QByteArray dayName = locale.dayName(date.dayOfWeek(), QLocale::ShortFormat).toUtf8();
+    QByteArray monthName = locale.monthName(date.month(), QLocale::ShortFormat).toUtf8();
     QByteArray utcOffs = secsToUTC(timeZoneDiff()).toUtf8();
     str.asprintf("%s, %.2d %s %d %.2d:%.2d:%.2d %s",
             dayName.constData(),
@@ -434,7 +437,7 @@ QString QWspDateTime::dateString(QDateTime d)
 QDateTime QWspDateTime::fromGmtTime_t(quint32 t)
 {
     QDateTime dt;
-    dt.setTime_t(t + timeZoneDiff());
+    dt.setSecsSinceEpoch(t + timeZoneDiff());
     return dt;
 }
 

--
2.24.0

#10 lore raw

PATCH 7/13 Port away from Q_FOREACH

In reply to Jonah Brüchert
---
 src/aidapplication.cpp      |  4 ++--
 src/callmanager.cpp         |  6 +++---
 src/control.cpp             | 19 +++++++++----------
 src/hardwaremanipulator.cpp |  4 ++--
 src/phonesim.cpp            |  4 ++--
 src/qsimcommand.cpp         | 10 +++++-----
 src/simfilesystem.cpp       |  8 ++++----
 7 files changed, 27 insertions(+), 28 deletions(-)
src/aidapplication.cpp +2 -2
index e255145..16fef0c 100644
@@ -47,7 +47,7 @@ bool AidAppWrapper::command( const QString& cmd )
             return true;
         }
 
-        foreach ( AidApplication* app, applications )
+        for ( AidApplication* app : qAsConst(applications) )
         response += app->getAid();
 
         response.append( "\n\nOK" );
@@ -72,7 +72,7 @@ bool AidAppWrapper::command( const QString& cmd )
         aid = cmd.split('=')[1];
         aid = aid.replace("\"", "");
 
-        foreach ( AidApplication* app, applications ) {
+        for ( AidApplication* app : qAsConst(applications) ) {
             if ( app->getAid().contains( aid ) ) {
                 if ( sessions.size() >= MAX_LOGICAL_CHANNELS )
                     break;
src/callmanager.cpp +3 -3
index fbdb179..1fa13cf 100644
@@ -195,7 +195,7 @@ bool CallManager::command( const QString& cmd )
     } else if ( cmd == "AT+CLCC" ) {
 
         // List all calls that are presently active.
-        foreach ( CallInfo info, callList ) {
+        for ( const CallInfo &info : qAsConst(callList) ) {
             int multiparty;
             if ( countForState(info.state) >= 2 )
                 multiparty = 1;
@@ -821,7 +821,7 @@ int CallManager::newId()
     bool seen;
     for ( id = 1; id <= 32; ++id ) {
         seen = false;
-        foreach ( CallInfo info, callList ) {
+        for ( const CallInfo &info : qAsConst(callList) ) {
             if ( info.id == id ) {
                 seen = true;
                 break;
@@ -879,7 +879,7 @@ int CallManager::indexForId( int id )
 
 bool CallManager::hasCall( CallState state )
 {
-    foreach ( CallInfo info, callList ) {
+    for ( const CallInfo &info : qAsConst(callList) ) {
         if ( info.state == state )
             return true;
     }
src/control.cpp +9 -10
index 8c1e412..817a0b2 100644
@@ -147,7 +147,7 @@ void Control::callManagement( QList<CallInfo> *list )
 
     widget->clearCallView();
 
-    foreach( CallInfo i, *list ) {
+    for ( const CallInfo &i : qAsConst(*list) ) {
         QString param[5];
 
         if ( i.incoming && !enableCSSU )
@@ -181,15 +181,15 @@ void ControlWidget::setStateAlerting()
 
 void ControlWidget::setStateHangup()
 {
-    QList <QTableWidgetItem *> items = ui->twCallMgt->selectedItems();
+    const QList <QTableWidgetItem *> items = ui->twCallMgt->selectedItems();
 
-    foreach ( QTableWidgetItem *item, items )
+    for ( QTableWidgetItem *item : items )
     {
         int row = item->row();
         if ( row >= 0 )
         {
             QTableWidgetItem *itemCallId = ui->twCallMgt->item( row, 0 );
-            if ( itemCallId != 0 )
+            if ( itemCallId != nullptr )
             {
                 QString strid = itemCallId->text();
                 int id = strid.toInt();
@@ -360,9 +360,9 @@ void ControlWidget::setDefaultGNSSData()
 
 void ControlWidget::sendGNSSData()
 {
-    QStringList xml = ui->teGNSStext->toPlainText().split("\n");
+    const QStringList xml = ui->teGNSStext->toPlainText().split("\n");
 
-    foreach ( QString line, xml )
+    for ( const QString &line : xml )
     {
         if (!line.isEmpty()) {
             QString cposr =  "+CPOSR: " + line;
@@ -468,9 +468,8 @@ void Control::handleFromData( const QString& cmd )
 
 void ControlWidget::handleToData( const QString& cmd )
 {
-    QStringList dataList = cmd.split("\n");
-    QString dataItem;
-    foreach( dataItem, dataList ){
+    const QStringList dataList = cmd.split("\n");
+    for ( auto &dataItem : dataList ){
         if( dataItem != "" ){
             ui->atViewer->append( dataItem + " : " + translator->translateCommand(dataItem) );
         }
@@ -564,7 +563,7 @@ void ControlWidget::addVoicemail()
 
 void ControlWidget::delVoicemail()
 {
-    foreach ( QTableWidgetSelectionRange range,
+    for ( QTableWidgetSelectionRange &range :
             ui->twMessageList->selectedRanges() ) {
         for ( int i = range.topRow(); i <= range.bottomRow(); i ++ ) {
             VoicemailItem &item = mailbox[i];
src/hardwaremanipulator.cpp +2 -2
index 6c83c8e..7a61c0e 100644
@@ -239,7 +239,7 @@ void HardwareManipulator::sendVMNotify( int type, int count, const QList<QVMMess
             mwiUdh.append( count );    // Number of Voice Messages
             mwiUdh.append( received.size() ); // Number of VM Notifications
 
-            foreach ( QVMMessage msg, received ) {
+            for ( const QVMMessage &msg : received ) {
                 mwiUdh.append( msg.id & 0xff );
                 mwiUdh.append( msg.id >> 8 ); // Endianness doesn't matter here
                 mwiUdh.append( qMin( msg.lengthSecs, 255 ) );
@@ -261,7 +261,7 @@ void HardwareManipulator::sendVMNotify( int type, int count, const QList<QVMMess
             mwiUdh.append( count ); // Number of Voice Messages
             mwiUdh.append( deleted.size() ); // Number of VM Notifications
 
-            foreach ( QVMMessage msg, deleted ) {
+            for ( const QVMMessage &msg : deleted ) {
                 mwiUdh.append( msg.id & 0xff );
                 mwiUdh.append( msg.id >> 8 ); // Endianness doesn't matter here
                 mwiUdh.append( qMin( msg.lengthSecs, 255 ) );
src/phonesim.cpp +2 -2
index 1fd3c15..0f72a09 100644
@@ -1380,9 +1380,9 @@ void SimRules::phoneBook( const QString& cmd )
     }
 
     if ( cmd.startsWith( "AT+CPBS=?" ) ) {
-        QStringList names = phoneBooks.keys();
+        const QStringList names = phoneBooks.keys();
         QString response = "+CPBS: (";
-        foreach ( QString name, names ) {
+        for ( const QString &name : names ) {
             if ( response.length() > 8 )
                 response += QChar(',');
             response += "\"" + name + "\"";
src/qsimcommand.cpp +5 -5
index 6642035..fb200ed 100644
@@ -3119,7 +3119,7 @@ static void writeSubAddress( QByteArray& data, const QString& value )
     writeBerLength( data, value.length() + 2 );
     data += (char)0x80;     // NSAP address type
     data += (char)0x50;     // NSAP address is BCD-encoded IA5 characters
-    foreach ( QChar ch, value ) {
+    for ( const QChar &ch : value ) {
         int val = ch.unicode() - 32;
         if ( val > 127 )
             val = 0;
@@ -3368,7 +3368,7 @@ QByteArray QSimCommand::toPdu( QSimCommand::ToPduOptions options ) const
                 data += (char)0x8F;
                 data += (char)0x00;
             }
-            foreach ( QSimMenuItem item, menuItems() ) {
+            for ( QSimMenuItem &item : menuItems() ) {
                 QByteArray contents;
                 contents += (char)item.identifier();
                 writeEFADN( contents, item.label(), options, -1 );
@@ -3386,7 +3386,7 @@ QByteArray QSimCommand::toPdu( QSimCommand::ToPduOptions options ) const
             if ( hasNextActions ) {
                 data += (char)0x18;
                 data += (char)menuItems().size();
-                foreach ( QSimMenuItem item, menuItems() )
+                for ( const QSimMenuItem &item : menuItems() )
                     data += (char)item.nextAction();
             }
             if ( type() == SelectItem && defaultItem() != 0 ) {
@@ -3399,14 +3399,14 @@ QByteArray QSimCommand::toPdu( QSimCommand::ToPduOptions options ) const
                 data += (char)0x9F;
                 data += (char)(menuItems().size() + 1);
                 data += (char)(selfExplanatory ? 0x00 : 0x01);
-                foreach ( QSimMenuItem item, menuItems() )
+                for ( const QSimMenuItem &item : menuItems() )
                     data += (char)item.iconId();
             }
             writeTextAttribute( data, titleAttribute() );
             if ( attrLen != 0 ) {
                 data += (char)0xD1;
                 writeBerLength( data, attrLen );
-                foreach ( QSimMenuItem item, menuItems() ) {
+                for ( QSimMenuItem &item : menuItems() ) {
                     data += item.labelAttribute();
                 }
             }
src/simfilesystem.cpp +4 -4
index 0e5c2a9..b3ea8a4 100644
@@ -514,9 +514,9 @@ SimFileItem *SimFileSystem::findItemRelative( const QString& fileid )
         item = currentItem->parentDir();
     } else {
         // Search the current item's immediate children.
-        QList<SimFileItem *> children = currentItem->children();
-        item = 0;
-        foreach( SimFileItem *temp, children ) {
+        const QList<SimFileItem *> children = currentItem->children();
+        item = nullptr;
+        for ( SimFileItem *temp : children ) {
             if ( temp->fileid() == fileid ) {
                 item = temp;
                 break;
@@ -635,7 +635,7 @@ SimFileItem *SimFileItem::findItem( const QString& fileid )
 {
     if ( fileid == _fileid )
         return this;
-    foreach ( SimFileItem *item, _children ) {
+    for ( SimFileItem *item : qAsConst(_children) ) {
         SimFileItem *temp = item->findItem( fileid );
         if ( temp )
             return temp;

--
2.24.0

#11 lore raw

PATCH 8/13 Port deprecations in controlbase.ui

In reply to Jonah Brüchert
---
 src/controlbase.ui | 158 ++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 142 insertions(+), 16 deletions(-)
src/controlbase.ui +142 -16
index 4eb1355..c2acbf6 100644
@@ -17,7 +17,16 @@
    <property name="spacing">
     <number>6</number>
    </property>
-   <property name="margin">
+   <property name="leftMargin">
+    <number>9</number>
+   </property>
+   <property name="topMargin">
+    <number>9</number>
+   </property>
+   <property name="rightMargin">
+    <number>9</number>
+   </property>
+   <property name="bottomMargin">
     <number>9</number>
    </property>
    <item>
@@ -162,7 +171,16 @@
           <property name="spacing">
            <number>6</number>
           </property>
-          <property name="margin">
+          <property name="leftMargin">
+           <number>9</number>
+          </property>
+          <property name="topMargin">
+           <number>9</number>
+          </property>
+          <property name="rightMargin">
+           <number>9</number>
+          </property>
+          <property name="bottomMargin">
            <number>9</number>
           </property>
           <item>
@@ -180,7 +198,16 @@
             <property name="spacing">
              <number>6</number>
             </property>
-            <property name="margin">
+            <property name="leftMargin">
+             <number>0</number>
+            </property>
+            <property name="topMargin">
+             <number>0</number>
+            </property>
+            <property name="rightMargin">
+             <number>0</number>
+            </property>
+            <property name="bottomMargin">
              <number>0</number>
             </property>
             <item>
@@ -197,7 +224,16 @@
           </item>
           <item>
            <layout class="QGridLayout">
-            <property name="margin">
+            <property name="leftMargin">
+             <number>0</number>
+            </property>
+            <property name="topMargin">
+             <number>0</number>
+            </property>
+            <property name="rightMargin">
+             <number>0</number>
+            </property>
+            <property name="bottomMargin">
              <number>0</number>
             </property>
             <property name="spacing">
@@ -319,7 +355,16 @@
        <property name="spacing">
         <number>6</number>
        </property>
-       <property name="margin">
+       <property name="leftMargin">
+        <number>9</number>
+       </property>
+       <property name="topMargin">
+        <number>9</number>
+       </property>
+       <property name="rightMargin">
+        <number>9</number>
+       </property>
+       <property name="bottomMargin">
         <number>9</number>
        </property>
        <item>
@@ -337,8 +382,8 @@
          <property name="tabChangesFocus">
           <bool>true</bool>
          </property>
-         <property name="tabStopWidth">
-          <number>40</number>
+         <property name="tabStopDistance">
+          <double>40.000000000000000</double>
          </property>
          <property name="acceptRichText">
           <bool>false</bool>
@@ -350,7 +395,16 @@
          <property name="spacing">
           <number>6</number>
          </property>
-         <property name="margin">
+         <property name="leftMargin">
+          <number>0</number>
+         </property>
+         <property name="topMargin">
+          <number>0</number>
+         </property>
+         <property name="rightMargin">
+          <number>0</number>
+         </property>
+         <property name="bottomMargin">
           <number>0</number>
          </property>
          <item>
@@ -387,7 +441,16 @@
           <bool>false</bool>
          </property>
          <layout class="QGridLayout">
-          <property name="margin">
+          <property name="leftMargin">
+           <number>9</number>
+          </property>
+          <property name="topMargin">
+           <number>9</number>
+          </property>
+          <property name="rightMargin">
+           <number>9</number>
+          </property>
+          <property name="bottomMargin">
            <number>9</number>
           </property>
           <property name="spacing">
@@ -601,7 +664,16 @@
        <property name="spacing">
         <number>6</number>
        </property>
-       <property name="margin">
+       <property name="leftMargin">
+        <number>9</number>
+       </property>
+       <property name="topMargin">
+        <number>9</number>
+       </property>
+       <property name="rightMargin">
+        <number>9</number>
+       </property>
+       <property name="bottomMargin">
         <number>9</number>
        </property>
        <item>
@@ -867,7 +939,16 @@
             <property name="spacing">
              <number>6</number>
             </property>
-            <property name="margin">
+            <property name="leftMargin">
+             <number>0</number>
+            </property>
+            <property name="topMargin">
+             <number>0</number>
+            </property>
+            <property name="rightMargin">
+             <number>0</number>
+            </property>
+            <property name="bottomMargin">
              <number>0</number>
             </property>
             <item>
@@ -905,7 +986,16 @@
        <property name="spacing">
         <number>6</number>
        </property>
-       <property name="margin">
+       <property name="leftMargin">
+        <number>9</number>
+       </property>
+       <property name="topMargin">
+        <number>9</number>
+       </property>
+       <property name="rightMargin">
+        <number>9</number>
+       </property>
+       <property name="bottomMargin">
         <number>9</number>
        </property>
        <item>
@@ -1077,7 +1167,16 @@
        <property name="spacing">
         <number>6</number>
        </property>
-       <property name="margin">
+       <property name="leftMargin">
+        <number>9</number>
+       </property>
+       <property name="topMargin">
+        <number>9</number>
+       </property>
+       <property name="rightMargin">
+        <number>9</number>
+       </property>
+       <property name="bottomMargin">
         <number>9</number>
        </property>
        <item>
@@ -1138,7 +1237,16 @@
        <property name="spacing">
         <number>6</number>
        </property>
-       <property name="margin">
+       <property name="leftMargin">
+        <number>9</number>
+       </property>
+       <property name="topMargin">
+        <number>9</number>
+       </property>
+       <property name="rightMargin">
+        <number>9</number>
+       </property>
+       <property name="bottomMargin">
         <number>9</number>
        </property>
        <item>
@@ -1413,7 +1521,16 @@
               <property name="spacing">
                <number>6</number>
               </property>
-              <property name="margin">
+              <property name="leftMargin">
+               <number>0</number>
+              </property>
+              <property name="topMargin">
+               <number>0</number>
+              </property>
+              <property name="rightMargin">
+               <number>0</number>
+              </property>
+              <property name="bottomMargin">
                <number>0</number>
               </property>
               <item>
@@ -1492,7 +1609,16 @@
       <property name="spacing">
        <number>6</number>
       </property>
-      <property name="margin">
+      <property name="leftMargin">
+       <number>9</number>
+      </property>
+      <property name="topMargin">
+       <number>9</number>
+      </property>
+      <property name="rightMargin">
+       <number>9</number>
+      </property>
+      <property name="bottomMargin">
        <number>9</number>
       </property>
       <item>

--
2.24.0

#12 lore raw

PATCH 9/13 Require Qt5Widgets >= 5.10

In reply to Jonah Brüchert

I don't think it's possible to use preprocessor directives with Qt's ui files, so this is neccessary.

---
 configure.ac | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
configure.ac +1 -1
index 0587f9f..da87afe 100644
@@ -22,7 +22,7 @@ AC_ARG_ENABLE(optimization, AC_HELP_STRING([--disable-optimization],
 	fi
 ])
 
-PKG_CHECK_MODULES(QT, Qt5Core Qt5Gui Qt5Xml Qt5Network Qt5Qml Qt5DBus Qt5Widgets, dummy=yes,
+PKG_CHECK_MODULES(QT, Qt5Core Qt5Gui Qt5Xml Qt5Network Qt5Qml Qt5DBus [Qt5Widgets >= 5.10], dummy=yes,
 						AC_MSG_ERROR(Qt is required))
 
 # Needed for qOverload

--
2.24.0

#13 lore raw

PATCH 10/13 Port from c-style casts to static_cast<>()

In reply to Jonah Brüchert

Done using the google-readability-casting check of clang-tidy

---
 src/callmanager.cpp          |   6 +-
 src/hardwaremanipulator.cpp  |  12 +-
 src/phonesim.cpp             |  62 +++---
 src/qatresult.cpp            |  10 +-
 src/qatresultparser.cpp      |   6 +-
 src/qatutils.cpp             | 116 +++++------
 src/qcbsmessage.cpp          |   6 +-
 src/qgsmcodec.cpp            |  54 ++---
 src/qsimcommand.cpp          | 370 +++++++++++++++++------------------
 src/qsimcontrolevent.cpp     |  16 +-
 src/qsimenvelope.cpp         |  48 ++---
 src/qsimterminalresponse.cpp |  98 +++++-----
 src/qsmsmessage.cpp          | 208 ++++++++++----------
 src/qsmsmessage_p.h          |   4 +-
 src/qwsppdu.cpp              |  94 ++++-----
 src/simapplication.cpp       |  68 +++----
 src/simauth.cpp              |  12 +-
 src/simfilesystem.cpp        |  24 +--
 18 files changed, 605 insertions(+), 609 deletions(-)
src/callmanager.cpp +3 -3
index 1fa13cf..5436e08 100644
@@ -203,8 +203,8 @@ bool CallManager::command( const QString& cmd )
                 multiparty = 0;
             QString line =
                 "+CLCC: " + QString::number(info.id) + "," +
-                QString::number((int)(info.incoming)) + "," +
-                QString::number((int)(info.state)) + ",0," +
+                QString::number(static_cast<int>(info.incoming)) + "," +
+                QString::number(static_cast<int>(info.state)) + ",0," +
                 QString::number(multiparty);
             if ( !info.number.isEmpty() ) {
                 line += ",";
@@ -904,7 +904,7 @@ void CallManager::sendState( const CallInfo& info )
         return;     // In the middle of a state swap: don't send this.
     QString line =
         "*ECAV: " + QString::number(info.id) + "," +
-        QString::number(stateMap[(int)(info.state)]) + ",0";
+        QString::number(stateMap[static_cast<int>(info.state)]) + ",0";
     if ( !info.number.isEmpty() ) {
         line += ",,," + QAtUtils::encodeNumber(info.number);
     }
src/hardwaremanipulator.cpp +6 -6
index 7a61c0e..ea895e7 100644
@@ -74,7 +74,7 @@ void HardwareManipulator::constructCBMessage(const QString &messageCode, int geo
         return;
     }
 
-    QCBSMessage::GeographicalScope gs = (QCBSMessage::GeographicalScope)geographicalScope;
+    QCBSMessage::GeographicalScope gs = static_cast<QCBSMessage::GeographicalScope>(geographicalScope);
 
     uint un = convertString(updateNumber,NIBBLE_MAX,ONE_CHAR,HEX_BASE,&ok);
     if ( !ok ) {
@@ -93,7 +93,7 @@ void HardwareManipulator::constructCBMessage(const QString &messageCode, int geo
         return;
     }
 
-    QCBSMessage::Language lang = (QCBSMessage::Language)language;
+    QCBSMessage::Language lang = static_cast<QCBSMessage::Language>(language);
 
     QCBSMessage m;
     m.setMessageCode(mc);
@@ -226,7 +226,7 @@ void HardwareManipulator::sendVMNotify( int type, int count, const QList<QVMMess
     if ( type == 0 ) {
         mwiUdh.append( 0x01 );     // Special SMS message indication
         mwiUdh.append( 0x02 );     // IE length
-        mwiUdh.append( (char) 0 ); // Message type: Voice
+        mwiUdh.append( static_cast<char>(0) ); // Message type: Voice
         mwiUdh.append( count );    // Message count
     } else if ( type == 1 ) {
         if ( received.size() ) {
@@ -234,7 +234,7 @@ void HardwareManipulator::sendVMNotify( int type, int count, const QList<QVMMess
 
             mwiUdh.append( 0x23 );     // Enhanced Voice Mail Notification
             mwiUdh.append( 0x02 );     // IE length (Filled in later)
-            mwiUdh.append( (char) 0 ); // Parameters
+            mwiUdh.append( static_cast<char>(0) ); // Parameters
             QSMSMessage::appendAddress( mwiUdh, mailbox, false );
             mwiUdh.append( count );    // Number of Voice Messages
             mwiUdh.append( received.size() ); // Number of VM Notifications
@@ -308,8 +308,8 @@ void HardwareManipulator::sendUSSD( bool cancel, bool response,
             uint len = content.length();
 
             for ( u = 0; u < len; u++ ) {
-                binary += (unsigned char)(content[u].unicode() >> 8);
-                binary += (unsigned char)(content[u].unicode() & 0xFF);
+                binary += static_cast<unsigned char>(content[u].unicode() >> 8);
+                binary += static_cast<unsigned char>(content[u].unicode() & 0xFF);
             }
             request = PS_toHex( binary );
         }
src/phonesim.cpp +31 -31

185 lines not on this page · raw message

src/qatresult.cpp +5 -5
index 9a29503..1c7e785 100644
@@ -483,7 +483,7 @@ static int numeric( const QString& value )
         return -1;
     int number = 0;
     while ( posn < value.length() && value[posn] >= '0' && value[posn] <= '9' )
-        number = number * 10 + (int)(value[posn++].unicode() - '0');
+        number = number * 10 + (value[posn++].unicode() - '0');
     return number;
 }
 
@@ -519,7 +519,7 @@ void QAtResult::resultToCode( const QString& value )
         val = value.mid( 11 ).trimmed();
         index = numeric( val );
         if ( index >= 0 ) {
-            d->resultCode = (QAtResult::ResultCode)index;
+            d->resultCode = static_cast<QAtResult::ResultCode>(index);
             d->verbose = false;
             return;
         }
@@ -531,7 +531,7 @@ void QAtResult::resultToCode( const QString& value )
         val = value.mid( 11 ).trimmed();
         index = numeric( val );
         if ( index >= 0 ) {
-            d->resultCode = (QAtResult::ResultCode)index;
+            d->resultCode = static_cast<QAtResult::ResultCode>(index);
             d->verbose = false;
             return;
         }
@@ -591,8 +591,8 @@ QString QAtResult::codeToResult( const QString& defaultValue ) const
         }
     }
     if ( defaultValue.isEmpty() ) {
-        if ( ((int)d->resultCode) >= 300 &&
-             ((int)d->resultCode) <= 500 ) {
+        if ( (static_cast<int>(d->resultCode)) >= 300 &&
+             (static_cast<int>(d->resultCode)) <= 500 ) {
             return "+CMS ERROR: " + QString::number( d->resultCode );
         } else {
             return "+CME ERROR: " + QString::number( d->resultCode );
src/qatresultparser.cpp +3 -3
index cba41ad..7e694e2 100644
@@ -174,7 +174,7 @@ uint QAtResultParser::readNumeric()
     uint value = 0;
     while ( d->linePosn < d->line.length() &&
             d->line[d->linePosn] >= '0' && d->line[d->linePosn] <= '9' ) {
-        value = value * 10 + (uint)(d->line[d->linePosn].unicode() - '0');
+        value = value * 10 + static_cast<uint>(d->line[d->linePosn].unicode() - '0');
         ++(d->linePosn);
     }
     if ( d->linePosn < d->line.length() && d->line[d->linePosn] == ',' ) {
@@ -188,9 +188,9 @@ uint QAtResultParser::readNumeric()
 
 static QString nextString( const QString& buf, int& posn )
 {
-    uint posn2 = (uint)posn;
+    uint posn2 = static_cast<uint>(posn);
     QString result = QAtUtils::nextString( buf, posn2 );
-    posn = (int)posn2;
+    posn = static_cast<int>(posn2);
     return result;
 }
 
src/qatutils.cpp +58 -58

310 lines not on this page · raw message

src/qcbsmessage.cpp +3 -3
index b56a761..17a2cd5 100644
@@ -387,8 +387,8 @@ bool QCBSMessage::operator!=( const QCBSMessage& other ) const
 void QCBSMessage::print()
 {
     qLog(Modem) << "channel=" << channel()
-                  << ", scope=" << (int)scope()
-                  << ", messageCode=" << (int)messageCode()
+                  << ", scope=" << static_cast<int>(scope())
+                  << ", messageCode=" << static_cast<int>(messageCode())
                   << ", updateNumber=" << updateNumber()
                   << ", language=" << language()
                   << ", page=" << page()
@@ -434,7 +434,7 @@ QByteArray QCBSMessage::toPdu() const
 {
     QCBSDeliverMessage deliver;
 
-    deliver.pack( *this, (QSMSDataCodingScheme)bestScheme() );
+    deliver.pack( *this, static_cast<QSMSDataCodingScheme>(bestScheme()) );
     return deliver.toByteArray();
 }
 
src/qgsmcodec.cpp +27 -27

118 lines not on this page · raw message

src/qsimcommand.cpp +185 -185

867 lines not on this page · raw message

src/qsimcontrolevent.cpp +8 -8
index 4502d78..8b41890 100644
@@ -226,9 +226,9 @@ QByteArray QSimControlEvent::extensionField( int tag ) const
 {
     uint posn = 0;
     uint currentTag, length;
-    while ( posn < (uint)( d->extensionData.length() ) ) {
+    while ( posn < static_cast<uint>( d->extensionData.length() ) ) {
         readBer( d->extensionData, posn, currentTag, length );
-        if ( ( currentTag & 0x7F ) == (uint)( tag & 0x7F ) )
+        if ( ( currentTag & 0x7F ) == static_cast<uint>( tag & 0x7F ) )
             return d->extensionData.mid( posn, length );
         posn += length;
     }
@@ -243,7 +243,7 @@ QByteArray QSimControlEvent::extensionField( int tag ) const
 */
 void QSimControlEvent::addExtensionField( int tag, const QByteArray& value )
 {
-    d->extensionData += (char)tag;
+    d->extensionData += static_cast<char>(tag);
     writeBerLength( d->extensionData, value.size() );
     d->extensionData += value;
 }
@@ -269,14 +269,14 @@ QSimControlEvent QSimControlEvent::fromPdu
         return ev;
     }
     readBer( pdu, posn, tag, length );
-    ev.setResult( (QSimControlEvent::Result)tag );
+    ev.setResult( static_cast<QSimControlEvent::Result>(tag) );
     content = pdu.mid( posn, length );
     posn = 0;
-    if ( posn >= (uint)content.size() )
+    if ( posn >= static_cast<uint>(content.size()) )
         return ev;
     readBer( content, posn, tag, length );
     for (;;) {
-        if ( ( posn + length ) > (uint)content.size() )
+        if ( ( posn + length ) > static_cast<uint>(content.size()) )
             break;
         newPosn = posn + length;
         switch ( tag & 0x7F ) {
@@ -296,7 +296,7 @@ QSimControlEvent QSimControlEvent::fromPdu
             break;
         }
         posn = newPosn;
-        if ( posn >= (uint)content.size() )
+        if ( posn >= static_cast<uint>(content.size()) )
             break;
         readBer( content, posn, tag, length );
     }
@@ -335,7 +335,7 @@ QByteArray QSimControlEvent::toPdu() const
 
     // Add the outermost tag layer and return.
     QByteArray outer;
-    outer += (char)result();
+    outer += static_cast<char>(result());
     writeBerLength( outer, data.size() );
     outer += data;
     return outer;
src/qsimenvelope.cpp +24 -24

122 lines not on this page · raw message

src/qsimterminalresponse.cpp +48 -50

210 lines not on this page · raw message

src/qsmsmessage.cpp +103 -105

566 lines not on this page · raw message

src/qsmsmessage_p.h +2 -2
index 49060c7..b25056f 100644
@@ -120,7 +120,7 @@ public:
     static void setBits(int offset, int len, int val);
     void commitBits();
     static void commitBits(QByteArray& buffer);
-    void appendOctet(uchar c) { mBuffer += (char)c; }
+    void appendOctet(uchar c) { mBuffer += static_cast<char>(c); }
 
     bool bit(int b);
     unsigned char bits(int offset, int len);
@@ -147,7 +147,7 @@ public:
     void reset() { mPosn = 0; }
 
     bool needOctets( uint num ) const
-        { return ((uint)(mBuffer.size() - mPosn) >= num); }
+        { return (static_cast<uint>(mBuffer.size() - mPosn) >= num); }
 
     static void appendAddress( QByteArray &buffer, const QString &strin, bool SCAddress );
 
src/qwsppdu.cpp +47 -47

279 lines not on this page · raw message

src/simapplication.cpp +34 -34

128 lines not on this page · raw message

src/simauth.cpp +6 -6
index 93b8826..b5fc7b1 100644
@@ -52,8 +52,8 @@ void SimAuth::gsmAuthenticate( QString rand, QString &sres,
 
     comp128( ki, _rand, _sres, _kc );
 
-    sres = QByteArray( (const char *)_sres, 4 ).toHex();
-    kc = QByteArray( (const char *)_kc, 8 ).toHex();
+    sres = QByteArray( reinterpret_cast<const char *>(_sres), 4 ).toHex();
+    kc = QByteArray( reinterpret_cast<const char *>(_kc), 8 ).toHex();
 }
 
 /*
@@ -167,7 +167,7 @@ enum UmtsStatus SimAuth::umtsAuthenticate( QString rand, QString autn,
 
         memcpy(_auts + 6, out1 + 8, 8);
 
-        auts = QByteArray( (const char *)_auts, 14 ).toHex();
+        auts = QByteArray( reinterpret_cast<const char *>(_auts), 14 ).toHex();
 
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

src/simfilesystem.cpp +12 -12
index b3ea8a4..7293a2f 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

--
2.24.0

Part of the diff is not shown here. View the raw message.

#14 lore raw

Re: [PATCH phonesim 10/13] Port from c-style casts to static_cast<>()

Hi Jonah,

Quoted 13 lines · Jonah Brüchert

Done using the google-readability-casting check of clang-tidy

---
  src/callmanager.cpp          |   6 +-
  src/hardwaremanipulator.cpp  |  12 +-
  src/phonesim.cpp             |  62 +++---
  src/qatresult.cpp            |  10 +-
  src/qatresultparser.cpp      |   6 +-
  src/qatutils.cpp             | 116 +++++------
  src/qcbsmessage.cpp          |   6 +-
  src/qgsmcodec.cpp            |  54 ++---
  src/qsimcommand.cpp          | 370 +++++++++++++++++------------------
  src/qsimcontrolevent.cpp     |  16 +-
  src/qsimenvelope.cpp         |  48 ++---
Quoted 9 lines
  src/qsimterminalresponse.cpp |  98 +++++-----
  src/qsmsmessage.cpp          | 208 ++++++++++----------
  src/qsmsmessage_p.h          |   4 +-
  src/qwsppdu.cpp              |  94 ++++-----
  src/simapplication.cpp       |  68 +++----
  src/simauth.cpp              |  12 +-
  src/simfilesystem.cpp        |  24 +--
  18 files changed, 605 insertions(+), 609 deletions(-)

This patch is really way too long, and since it was seemingly done by machine, you probably need to check whether all the changes make sense first. Just a few examples, picking at random:

src/callmanager.cpp bool CallManager::command( const QString& cmd ) · line 207

Quoted 12 lines
src/callmanager.cpp +2 -2
index 1fa13cf..5436e08 100644
@@ -203,8 +203,8 @@ bool CallManager::command( const QString& cmd )
                  multiparty = 0;
              QString line =
                  "+CLCC: " + QString::number(info.id) + "," +
-                QString::number((int)(info.incoming)) + "," +
-                QString::number((int)(info.state)) + ",0," +
+                QString::number(static_cast<int>(info.incoming)) + "," +
+                QString::number(static_cast<int>(info.state)) + ",0," +

These casts are not needed at all due to implicit conversions

Quoted 3 lines
src/callmanager.cpp +0 -0
                  QString::number(multiparty);
              if ( !info.number.isEmpty() ) {
                  line += ",";

<snip>

src/callmanager.cpp void DemoSimApplication::BIPMenu( const QSimTerminalResponse& resp ) · line 2505

Quoted 8 lines
src/callmanager.cpp +2 -2
@@ -2501,8 +2501,8 @@ void DemoSimApplication::BIPMenu( const QSimTerminalResponse& resp )
 
                  destAddress += 0x21;
                  destAddress += 0x7F; /* local host 127.0.0.1 */
-                destAddress += (char) 0x00;
-                destAddress += (char) 0x00;
+                destAddress += static_cast<char>(0x00);
+                destAddress += static_cast<char>(0x00);

Why use a cast here but not lines above or below..

Quoted 8 lines
src/callmanager.cpp +0 -0
                  destAddress += 0x01;
 
                  apn += 0x06;
src/simauth.cpp +0 -0
index 93b8826..b5fc7b1 100644

src/simauth.cpp void SimAuth::gsmAuthenticate( QString rand, QString &sres, · line 56

Quoted 7 lines
src/simauth.cpp +2 -2
@@ -52,8 +52,8 @@ void SimAuth::gsmAuthenticate( QString rand, QString &sres,
 
      comp128( ki, _rand, _sres, _kc );
 
-    sres = QByteArray( (const char *)_sres, 4 ).toHex();
-    kc = QByteArray( (const char *)_kc, 8 ).toHex();
+    sres = QByteArray( reinterpret_cast<const char *>(_sres), 4 ).toHex();
+    kc = QByteArray( reinterpret_cast<const char *>(_kc), 8 ).toHex();

This likely needs a toUtf8 or something instead of messing with casts.

src/simauth.cpp void SimAuth::gsmAuthenticate( QString rand, QString &sres, · line 58

Quoted 2 lines
src/simauth.cpp +0 -0
  }
 

Perhaps you want to split it up a bit more so the parts that make sense can get merged, and the rest we can address piecemeal by removing the unnecessary casts.

Regards,
-Denis

#15 lore raw

PATCH 11/13 Use dynamic_cast where appropriate

In reply to Jonah Brüchert

Done using the cppcoreguidelines-pro-type-cstyle-cast check of clang-tidy

---
 src/aidapplication.cpp | 2 +-
 src/phonesim.cpp       | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
src/aidapplication.cpp +1 -1
index 16fef0c..807d7f9 100644
@@ -15,7 +15,7 @@ AidApplication::AidApplication( QObject *parent, SimXmlNode& n )
 
     while (child) {
         if ( child->tag == "filesystem" )
-            fs = new SimFileSystem( (SimRules *)parent, *child, FILE_SYSTEM_TYPE_ISIM );
+            fs = new SimFileSystem( dynamic_cast<SimRules *>(parent), *child, FILE_SYSTEM_TYPE_ISIM );
 
         child = child->next;
     }
src/phonesim.cpp +2 -2
index f9dab52..9acd39e 100644
@@ -1665,7 +1665,7 @@ void SimRules::callControlEventNotify( const QSimControlEvent& evt )
 
 void SimRules::delayTimeout()
 {
-    SimDelayTimer *timer = (SimDelayTimer *)sender();
+    SimDelayTimer *timer = dynamic_cast<SimDelayTimer *>(sender());
     int save = currentChannel;
     currentChannel = timer->channel;
     writeChatData(timer->response.toLatin1().data(), timer->response.length());
@@ -1676,7 +1676,7 @@ void SimRules::delayTimeout()
 
 void SimRules::delaySetVariable()
 {
-    QVariantTimer *timer = (QVariantTimer *)sender();
+    QVariantTimer *timer = dynamic_cast<QVariantTimer *>(sender());
     QPairKV kv = timer->param.value<QPairKV>();
 
     setVariable( kv.first, kv.second );

--
2.24.0

#16 lore raw

Re: [PATCH phonesim 11/13] Use dynamic_cast where appropriate

Hi Jonah,

Quoted 6 lines · Jonah Brüchert

Done using the cppcoreguidelines-pro-type-cstyle-cast check of clang-tidy

---
  src/aidapplication.cpp | 2 +-
  src/phonesim.cpp       | 4 ++--
  2 files changed, 3 insertions(+), 3 deletions(-)

Applied, thanks.

Regards,
-Denis

#17 lore raw

PATCH 12/13 Annotate overriding functions with override

In reply to Jonah Brüchert

* Allows us to notice when a function becomes source incompatible in a Qt major release, and our implementation stops overriding.

---
 src/aidapplication.cpp      |  3 ++-
 src/aidapplication.h        |  4 ++--
 src/callmanager.h           |  2 +-
 src/control.h               | 18 +++++++--------
 src/hardwaremanipulator.cpp |  1 +
 src/phonesim.h              | 16 +++++++-------
 src/qatutils.cpp            | 44 ++++++++++++++++++-------------------
 src/qgsmcodec.h             | 10 ++++-----
 src/qwsppdu.cpp             |  6 ++---
 src/qwsppdu.h               |  4 ++--
 src/simapplication.h        | 20 ++++++++---------
 src/simauth.h               |  2 +-
 src/simfilesystem.h         |  4 ++--
 13 files changed, 68 insertions(+), 66 deletions(-)
src/aidapplication.cpp +2 -1
index 807d7f9..395fe99 100644
@@ -190,7 +190,8 @@ bool AidAppWrapper::command( const QString& cmd )
 
             return true;
         }
-        break;
+        // if CMD_TYPE_GSM_AUTH is the case, we already returned
+        // and can't fallthrough, so no break here
         case CMD_TYPE_UMTS_AUTH:
         {
             enum UmtsStatus status;
src/aidapplication.h +2 -2
index d8b1b93..9126412 100644
@@ -44,7 +44,7 @@ class AidApplication : public QObject
     Q_OBJECT
 public:
     AidApplication( QObject *parent, SimXmlNode& n );
-    ~AidApplication();
+    ~AidApplication() override;
 
     QString getAid() { return aid; };
     QString getType() { return type; };
@@ -67,7 +67,7 @@ class AidAppWrapper : public QObject
     Q_OBJECT
 public:
     AidAppWrapper( SimRules *r, QList<AidApplication *> apps, SimAuth *auth = nullptr );
-    ~AidAppWrapper();
+    ~AidAppWrapper() override;
 
     bool command( const QString& cmd );
 
src/callmanager.h +1 -1
index 9b1eef0..a39f484 100644
@@ -52,7 +52,7 @@ class CallManager : public QObject
     Q_OBJECT
 public:
     CallManager( QObject *parent = nullptr );
-    ~CallManager();
+    ~CallManager() override;
 
     // Process an AT command.  Returns false if not a call-related command.
     bool command( const QString& cmd );
src/control.h +9 -9
index a7c0ff3..79cd417 100644
@@ -119,7 +119,7 @@ signals:
     void stateChangedToHangup( int callId );
 
 protected:
-    void closeEvent(QCloseEvent *event);
+    void closeEvent(QCloseEvent *event) override;
 
 private:
     Ui_ControlBase *ui;
@@ -150,17 +150,17 @@ Q_OBJECT
 
 public:
     Control(const QString& ruleFile, SimRules *sr, QObject *parent=nullptr);
-    virtual ~Control();
+    ~Control() override;
 
 public slots:
-    void handleFromData( const QString& );
-    void handleToData( const QString& );
-    void setPhoneNumber( const QString& );
-    void handleNewApp();
-    void callManagement( QList<CallInfo> *info );
+    void handleFromData( const QString& ) override;
+    void handleToData( const QString& ) override;
+    void setPhoneNumber( const QString& ) override;
+    void handleNewApp() override;
+    void callManagement( QList<CallInfo> *info ) override;
 
 protected:
-    virtual void warning( const QString&, const QString& );
+    void warning( const QString&, const QString& ) override;
 
 private:
     ControlWidget *widget;
@@ -170,7 +170,7 @@ private:
 class ControlFactory : public HardwareManipulatorFactory
 {
 public:
-    inline virtual HardwareManipulator *create(SimRules *sr, QObject *parent)
+    inline HardwareManipulator *create(SimRules *sr, QObject *parent) override
         { return new Control(ruleFile(), sr, parent); }
 };
 
src/hardwaremanipulator.cpp +1 -0
index ea895e7..63c498a 100644
@@ -363,4 +363,5 @@ void HardwareManipulator::simAppAbort()
 
 void HardwareManipulator::callManagement( QList<CallInfo> *info )
 {
+    Q_UNUSED(info)
 }
src/phonesim.h +8 -8
index ac5084d..362a6a8 100644
@@ -128,7 +128,7 @@ class SimItem : public QObject
     Q_OBJECT
 public:
     SimItem( SimState *state ) { _state = state; }
-    virtual ~SimItem() {}
+    ~SimItem() override {}
 
     // Get the state that contains this item.
     SimState *state() { return _state; }
@@ -153,9 +153,9 @@ class SimChat : public SimItem
     Q_OBJECT
 public:
     SimChat( SimState *state, SimXmlNode& e );
-    ~SimChat() {}
+    ~SimChat() override {}
 
-    virtual bool command( const QString& cmd );
+    bool command( const QString& cmd ) override;
 
 private:
     QString _command;
@@ -180,10 +180,10 @@ class SimUnsolicited : public SimItem
     Q_OBJECT
 public:
     SimUnsolicited( SimState *state, SimXmlNode& e );
-    ~SimUnsolicited() {}
+    ~SimUnsolicited() override {}
 
-    virtual void enter();
-    virtual void leave();
+    void enter() override;
+    void leave() override;
 
 private:
     QString response;
@@ -204,7 +204,7 @@ class SimPhoneBook : public QObject
     Q_OBJECT
 public:
     SimPhoneBook( int size, QObject *parent );
-    ~SimPhoneBook();
+    ~SimPhoneBook() override;
 
     int size() const { return numbers.size(); }
     int used() const;
@@ -248,7 +248,7 @@ class SimRules : public QTcpSocket
     Q_OBJECT
 public:
     SimRules(qintptr fd, QObject *parent, const QString& filename, HardwareManipulatorFactory *hmf );
-    ~SimRules() {}
+    ~SimRules() override {}
 
     // get the variable value for.
     QString variable(const QString &name);
src/qatutils.cpp +22 -22

80 lines not on this page · raw message

src/qgsmcodec.h +5 -5
index 8ecb6f9..b2347d5 100644
@@ -27,10 +27,10 @@ class QGsmCodec : public QTextCodec
 {
 public:
     explicit QGsmCodec( bool noLoss=false );
-    ~QGsmCodec();
+    ~QGsmCodec() override;
 
-    QByteArray name() const;
-    int mibEnum() const;
+    QByteArray name() const override;
+    int mibEnum() const override;
 
     static char singleFromUnicode(QChar ch);
     static QChar singleToUnicode(char ch);
@@ -39,8 +39,8 @@ public:
     static QChar twoByteToUnicode(unsigned short ch);
 
 protected:
-    QString convertToUnicode(const char *in, int length, ConverterState *state) const;
-    QByteArray convertFromUnicode(const QChar *in, int length, ConverterState *state) const;
+    QString convertToUnicode(const char *in, int length, ConverterState *state) const override;
+    QByteArray convertFromUnicode(const QChar *in, int length, ConverterState *state) const override;
 
 private:
     bool noLoss;
src/qwsppdu.cpp +3 -3
index ccb6869..f830a94 100644
@@ -164,9 +164,9 @@ public:
                 EncodingVersion
     };
 
-    virtual QWspField decode(QWspPduDecoder &);
-    virtual bool encode(QWspPduEncoder&, const QWspField&);
-    virtual quint8 codePage() const { return 1; }
+    QWspField decode(QWspPduDecoder &) override;
+    bool encode(QWspPduEncoder&, const QWspField&) override;
+    quint8 codePage() const override { return 1; }
 
 private:
     int fieldFromNumber(quint8 id);
src/qwsppdu.h +2 -2
index 91b3880..fac0176 100644
@@ -129,7 +129,7 @@ class QWspPduDecoder : public QObject
     Q_OBJECT
 public:
     explicit QWspPduDecoder(QIODevice *);
-    ~QWspPduDecoder();
+    ~QWspPduDecoder() override;
 
     quint8 peekOctet();
     quint8 decodeOctet();
@@ -184,7 +184,7 @@ class QWspPduEncoder : public QObject
     Q_OBJECT
 public:
     explicit QWspPduEncoder(QIODevice *);
-    ~QWspPduEncoder();
+    ~QWspPduEncoder() override;
 
     void encodeOctet(quint8);
     void encodeUInt8(quint8);
src/simapplication.h +10 -10
index c5c6501..5f427ed 100644
@@ -33,7 +33,7 @@ class SimApplication : public QObject
     Q_OBJECT
 public:
     SimApplication( SimRules *rules, QObject *parent = nullptr );
-    ~SimApplication();
+    ~SimApplication() override;
 
     virtual bool envelope( const QSimEnvelope& env );
     virtual bool response( const QSimTerminalResponse& resp );
@@ -68,15 +68,15 @@ class DemoSimApplication : public SimApplication
     Q_OBJECT
 public:
     DemoSimApplication( SimRules *rules, QObject *parent = nullptr );
-    ~DemoSimApplication();
+    ~DemoSimApplication() override;
 
-    const QString getName();
+    const QString getName() override;
 
-    bool envelope( const QSimEnvelope& env );
+    bool envelope( const QSimEnvelope& env ) override;
 
 protected slots:
-    void mainMenu();
-    void mainMenuSelection( int id );
+    void mainMenu() override;
+    void mainMenuSelection( int id ) override;
     void sendSportsMenu();
     void sportsMenu( const QSimTerminalResponse& resp );
     void sendCallsMenu();
@@ -149,13 +149,13 @@ class ConformanceSimApplication : public SimApplication
     Q_OBJECT
 public:
     ConformanceSimApplication( SimRules *rules, QObject *parent = nullptr );
-    ~ConformanceSimApplication();
+    ~ConformanceSimApplication() override;
 
-    const QString getName();
+    const QString getName() override;
 
 protected slots:
-    void mainMenu();
-    void mainMenuSelection( int id );
+    void mainMenu() override;
+    void mainMenuSelection( int id ) override;
     void sendDisplayTextMenu();
     void DisplayTextMenu( const QSimTerminalResponse& resp );
     void DisplayTextNormalMenu( const QSimTerminalResponse& resp );
src/simauth.h +1 -1
index fb66593..5a4996d 100644
@@ -34,7 +34,7 @@ class SimAuth : public QObject
     Q_OBJECT
 public:
     SimAuth( QObject *parent, SimXmlNode& n );
-    ~SimAuth();
+    ~SimAuth() override;
 
     void gsmAuthenticate( QString rand, QString &sres, QString &kc );
     enum UmtsStatus umtsAuthenticate( QString rand, QString autn,
src/simfilesystem.h +2 -2
index 477c6c7..9988c82 100644
@@ -58,7 +58,7 @@ class SimFileSystem : public QObject
     Q_OBJECT
 public:
     SimFileSystem( SimRules *rules, SimXmlNode& e, enum file_system_type type = FILE_SYSTEM_TYPE_DEFAULT );
-    ~SimFileSystem();
+    ~SimFileSystem() override;
 
     // Execute an AT+CRSM command against the filesystem.
     void crsm( const QString& args );
@@ -98,7 +98,7 @@ class SimFileItem : public QObject
 public:
     SimFileItem( const QString& fileid, SimFileItem *parentDir,
                  int access = 0, enum file_type type = FILE_TYPE_INVALID);
-    ~SimFileItem();
+    ~SimFileItem() override;
 
     QString fileid() const { return _fileid; }
     SimFileItem *parentDir() const { return _parentDir; }

--
2.24.0

#18 lore raw

Re: [PATCH phonesim 12/13] Annotate overriding functions with override

Hi Jonah,

Quoted 23 lines · Jonah Brüchert

* Allows us to notice when a function becomes source incompatible in a Qt major release, and our implementation stops overriding.

---
  src/aidapplication.cpp      |  3 ++-
  src/aidapplication.h        |  4 ++--
  src/callmanager.h           |  2 +-
  src/control.h               | 18 +++++++--------
  src/hardwaremanipulator.cpp |  1 +
  src/phonesim.h              | 16 +++++++-------
  src/qatutils.cpp            | 44 ++++++++++++++++++-------------------
  src/qgsmcodec.h             | 10 ++++-----
  src/qwsppdu.cpp             |  6 ++---
  src/qwsppdu.h               |  4 ++--
  src/simapplication.h        | 20 ++++++++---------
  src/simauth.h               |  2 +-
  src/simfilesystem.h         |  4 ++--
  13 files changed, 68 insertions(+), 66 deletions(-)
src/aidapplication.cpp +0 -0
index 807d7f9..395fe99 100644

src/aidapplication.cpp bool AidAppWrapper::command( const QString& cmd ) · line 194

Quoted 6 lines
src/aidapplication.cpp +2 -1
@@ -190,7 +190,8 @@ bool AidAppWrapper::command( const QString& cmd )
 
              return true;
          }
-        break;
+        // if CMD_TYPE_GSM_AUTH is the case, we already returned
+        // and can't fallthrough, so no break here

This doesn't seem to belong in this patch, so I left it out.

Quoted 3 lines
src/aidapplication.cpp +0 -0
          case CMD_TYPE_UMTS_AUTH:
          {
              enum UmtsStatus status;

<snip>

src/hardwaremanipulator.cpp void HardwareManipulator::simAppAbort() · line 367

Quoted 10 lines
src/hardwaremanipulator.cpp +1 -0
index ea895e7..63c498a 100644
@@ -363,4 +363,5 @@ void HardwareManipulator::simAppAbort()
 
  void HardwareManipulator::callManagement( QList<CallInfo> *info )
  {
+    Q_UNUSED(info)
  }

Same here

Rest applied, thanks.

Regards,
-Denis

#19 lore raw

PATCH 13/13 Use bool literals

In reply to Jonah Brüchert

Done using the modernize-use-bool-literals of clang-tidy

---
 src/qsmsmessage.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/qsmsmessage.cpp +1 -1
index 1d0f733..06845bf 100644
@@ -1565,7 +1565,7 @@ bool QPDUMessage::bit(int b)
     if ( needOctets(1) )
         return (mBuffer[mPosn] & (Unit << b));
     else
-        return 0;
+        return false;
 }
 
 unsigned char QPDUMessage::bits(int offset, int len)

--
2.24.0

#20 lore raw

Re: [PATCH phonesim 13/13] Use bool literals

Hi Jonah,

Quoted 5 lines · Jonah Brüchert

Done using the modernize-use-bool-literals of clang-tidy

---
  src/qsmsmessage.cpp | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks.

Regards,
-Denis