Changeset 846 for trunk/tools/qdbus


Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tools/qdbus/qdbus.pro

    r2 r846  
    11TEMPLATE = subdirs
    2 SUBDIRS = qdbus qdbusxml2cpp qdbuscpp2xml qdbusviewer
     2SUBDIRS = qdbus qdbusxml2cpp qdbuscpp2xml
     3!contains(QT_CONFIG, no-gui): SUBDIRS += qdbusviewer
  • trunk/tools/qdbus/qdbus/qdbus.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    249249}
    250250
    251 static void placeCall(const QString &service, const QString &path, const QString &interface,
    252                const QString &member, QStringList args)
     251static placeCall(const QString &service, const QString &path, const QString &interface,
     252               const QString &member, )
    253253{
    254254    QDBusInterface iface(service, path, interface, connection);
     
    257257    // activate the service if possible.
    258258
     259
     260
     261
    259262    QVariantList params;
    260263    if (!args.isEmpty()) {
     
    263266        match += '(';
    264267
    265         int midx = -1;
    266268        for (int i = mo->methodOffset(); i < mo->methodCount(); ++i) {
    267269            QMetaMethod mm = mo->method(i);
    268270            QByteArray signature = mm.signature();
    269             if (signature.startsWith(match)) {
    270                 midx = i;
    271                 break;
     271            if (signature.startsWith(match))
     272                knownIds += i;
     273         }
     274
     275
     276        while (!matchFound) {
     277            args = arguments; // reset
     278            params.clear();
     279            if (knownIds.isEmpty()) {
     280                // Failed to set property after falling back?
     281                // Bail out without displaying an error
     282                if (!try_prop)
     283                    return 1;
     284                if (try_prop && args.size() == 1) {
     285                    QStringList proparg;
     286                    proparg += interface;
     287                    proparg += member;
     288                    proparg += args.first();
     289                    if (!placeCall(service, path, "org.freedesktop.DBus.Properties", "Set", proparg, false))
     290                        return 0;
     291                }
     292                fprintf(stderr, "Cannot find '%s.%s' in object %s at %s\n",
     293                        qPrintable(interface), qPrintable(member), qPrintable(path),
     294                        qPrintable(service));
     295                return 1;
    272296            }
    273          }
    274 
    275         if (midx == -1) {
    276             fprintf(stderr, "Cannot find '%s.%s' in object %s at %s\n",
    277                     qPrintable(interface), qPrintable(member), qPrintable(path),
    278                     qPrintable(service));
    279             exit(1);
    280         }
    281 
    282         QMetaMethod mm = mo->method(midx);
    283         QList<QByteArray> types = mm.parameterTypes();
    284         for (int i = 0; i < types.count(); ++i) {
    285             if (types.at(i).endsWith('&')) {
    286                 // reference (and not a reference to const): output argument
    287                 // we're done with the inputs
    288                 while (types.count() > i)
    289                     types.removeLast();
    290                 break;
     297
     298            QMetaMethod mm = mo->method(knownIds.takeFirst());
     299            QList<QByteArray> types = mm.parameterTypes();
     300            for (int i = 0; i < types.count(); ++i) {
     301                if (types.at(i).endsWith('&')) {
     302                    // reference (and not a reference to const): output argument
     303                    // we're done with the inputs
     304                    while (types.count() > i)
     305                        types.removeLast();
     306                    break;
     307                }
    291308            }
    292         }
    293 
    294         for (int i = 0; !args.isEmpty() && i < types.count(); ++i) {
    295             int id = QVariant::nameToType(types.at(i));
    296             if (id == QVariant::UserType)
    297                 id = QMetaType::type(types.at(i));
    298             Q_ASSERT(id);
    299 
    300             QVariant p;
    301             QString argument;
    302             if ((id == QVariant::List || id == QVariant::StringList)
    303                  && args.at(0) == QLatin1String("("))
    304                 p = readList(args);
    305             else
    306                 p = argument = args.takeFirst();
    307 
    308             if (id == int(QMetaType::UChar)) {
    309                 // special case: QVariant::convert doesn't convert to/from
    310                 // UChar because it can't decide if it's a character or a number
    311                 p = qVariantFromValue<uchar>(p.toUInt());
    312             } else if (id < int(QMetaType::User) && id != int(QVariant::Map)) {
    313                 p.convert(QVariant::Type(id));
    314                 if (p.type() == QVariant::Invalid) {
    315                     fprintf(stderr, "Could not convert '%s' to type '%s'.\n",
    316                             qPrintable(argument), types.at(i).constData());
    317                     exit(1);
     309
     310            for (int i = 0; !args.isEmpty() && i < types.count(); ++i) {
     311                int id = QVariant::nameToType(types.at(i));
     312                if (id == QVariant::UserType)
     313                    id = QMetaType::type(types.at(i));
     314                Q_ASSERT(id);
     315
     316                QVariant p;
     317                QString argument;
     318                if ((id == QVariant::List || id == QVariant::StringList)
     319                     && args.at(0) == QLatin1String("("))
     320                    p = readList(args);
     321                else
     322                    p = argument = args.takeFirst();
     323
     324                if (id == int(QMetaType::UChar)) {
     325                    // special case: QVariant::convert doesn't convert to/from
     326                    // UChar because it can't decide if it's a character or a number
     327                    p = qVariantFromValue<uchar>(p.toUInt());
     328                } else if (id < int(QMetaType::User) && id != int(QVariant::Map)) {
     329                    p.convert(QVariant::Type(id));
     330                    if (p.type() == QVariant::Invalid) {
     331                        fprintf(stderr, "Could not convert '%s' to type '%s'.\n",
     332                                qPrintable(argument), types.at(i).constData());
     333                        return 1 ;
     334                    }
     335                } else if (id == qMetaTypeId<QDBusVariant>()) {
     336                    QDBusVariant tmp(p);
     337                    p = qVariantFromValue(tmp);
     338                } else if (id == qMetaTypeId<QDBusObjectPath>()) {
     339                    QDBusObjectPath path(argument);
     340                    if (path.path().isNull()) {
     341                        fprintf(stderr, "Cannot pass argument '%s' because it is not a valid object path.\n",
     342                                qPrintable(argument));
     343                        return 1;
     344                    }
     345                    p = qVariantFromValue(path);
     346                } else if (id == qMetaTypeId<QDBusSignature>()) {
     347                    QDBusSignature sig(argument);
     348                    if (sig.signature().isNull()) {
     349                        fprintf(stderr, "Cannot pass argument '%s' because it is not a valid signature.\n",
     350                                qPrintable(argument));
     351                        return 1;
     352                    }
     353                    p = qVariantFromValue(sig);
     354                } else {
     355                    fprintf(stderr, "Sorry, can't pass arg of type '%s'.\n",
     356                            types.at(i).constData());
     357                    return 1;
    318358                }
    319             } else if (id == qMetaTypeId<QDBusVariant>()) {
    320                 QDBusVariant tmp(p);
    321                 p = qVariantFromValue(tmp);
    322             } else if (id == qMetaTypeId<QDBusObjectPath>()) {
    323                 QDBusObjectPath path(argument);
    324                 if (path.path().isNull()) {
    325                     fprintf(stderr, "Cannot pass argument '%s' because it is not a valid object path.\n",
    326                             qPrintable(argument));
    327                     exit(1);
    328                 }
    329                 p = qVariantFromValue(path);
    330             } else if (id == qMetaTypeId<QDBusSignature>()) {
    331                 QDBusSignature sig(argument);
    332                 if (sig.signature().isNull()) {
    333                     fprintf(stderr, "Cannot pass argument '%s' because it is not a valid signature.\n",
    334                             qPrintable(argument));
    335                     exit(1);
    336                 }
    337                 p = qVariantFromValue(sig);
    338             } else {
    339                 fprintf(stderr, "Sorry, can't pass arg of type '%s'.\n",
    340                         types.at(i).constData());
    341                 exit(1);
     359                params += p;
    342360            }
    343             params += p;
    344         }
    345         if (params.count() != types.count() || !args.isEmpty()) {
    346             fprintf(stderr, "Invalid number of parameters\n");
    347             exit(1);
    348         }
    349     }
     361            if (params.count() == types.count() && args.isEmpty())
     362                matchFound = true;
     363            else if (knownIds.isEmpty()) {
     364                fprintf(stderr, "Invalid number of parameters\n");
     365                return 1;
     366            }
     367        } // while (!matchFound)
     368    } // if (!args.isEmpty()
    350369
    351370    QDBusMessage reply = iface.callWithArgumentList(QDBus::Block, member, params);
    352371    if (reply.type() == QDBusMessage::ErrorMessage) {
    353372        QDBusError err = reply;
     373
     374
     375
     376
     377
     378
     379
     380
     381
     382
     383
    354384        if (err.type() == QDBusError::ServiceUnknown)
    355385            fprintf(stderr, "Service '%s' does not exist.\n", qPrintable(service));
    356386        else
    357387            printf("Error: %s\n%s\n", qPrintable(err.name()), qPrintable(err.message()));
    358         exit(2);
     388        ;
    359389    } else if (reply.type() != QDBusMessage::ReplyMessage) {
    360390        fprintf(stderr, "Invalid reply type %d\n", int(reply.type()));
    361         exit(1);
     391        ;
    362392    }
    363393
     
    365395        printArg(v);
    366396
    367     exit(0);
     397    ;
    368398}
    369399
     
    484514    }
    485515
    486     placeCall(service, path, interface, member, args);
    487 }
    488 
     516    int ret = placeCall(service, path, interface, member, args);
     517    exit(ret);
     518}
     519
  • trunk/tools/qdbus/qdbuscpp2xml/qdbuscpp2xml.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    6565// in qdbusxmlgenerator.cpp
    6666QT_BEGIN_NAMESPACE
    67 extern QDBUS_EXPORT QString qDBusGenerateMetaObjectXml(QString interface, const QMetaObject *mo,
     67extern QDBUS_EXPORT QString qDBusGenerateMetaObjectXml(QString interface, const QMetaObject *mo,
    6868                                                       const QMetaObject *base, int flags);
    6969QT_END_NAMESPACE
     
    7171#define PROGRAMNAME     "qdbuscpp2xml"
    7272#define PROGRAMVERSION  "0.1"
    73 #define PROGRAMCOPYRIGHT "Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)."
     73#define PROGRAMCOPYRIGHT "Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies)."
    7474
    7575static QString outputFile;
  • trunk/tools/qdbus/qdbusviewer/main.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/qdbus/qdbusviewer/propertydialog.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/qdbus/qdbusviewer/propertydialog.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/qdbus/qdbusviewer/qdbusmodel.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    7676    QString name;
    7777    QString caption;
     78
    7879};
    7980
     
    119120                    child.attribute(QLatin1String("name")), parent);
    120121            item->caption = QLatin1String("Method: ") + item->name;
     122
     123
     124
     125
     126
     127
     128
    121129        } else if (child.tagName() == QLatin1String("signal")) {
    122130            item = new QDBusItem(QDBusModel::SignalItem,
     
    299307}
    300308
     309
     310
     311
     312
     313
     314
    301315QModelIndex QDBusModel::findObject(const QDBusObjectPath &objectPath)
    302316{
  • trunk/tools/qdbus/qdbusviewer/qdbusmodel.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    7373    QString dBusInterface(const QModelIndex &index) const;
    7474    QString dBusMethodName(const QModelIndex &index) const;
     75
    7576
    7677    void refresh(const QModelIndex &index = QModelIndex());
  • trunk/tools/qdbus/qdbusviewer/qdbusviewer.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    7070    objectPathRegExp(QLatin1String("\\[ObjectPath: (.*)\\]"))
    7171{
    72     services = new QTreeWidget;
    73     services->setRootIsDecorated(false);
    74     services->setHeaderLabels(QStringList(QLatin1String("Services")));
     72    servicesModel = new QStringListModel(this);
     73    servicesFilterModel = new QSortFilterProxyModel(this);
     74    servicesFilterModel->setSourceModel(servicesModel);
     75    servicesFilterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
     76    serviceFilterLine = new QLineEdit(this);
     77    serviceFilterLine->setPlaceholderText(tr("Search..."));
     78    servicesView = new QListView(this);
     79    servicesView->setModel(servicesFilterModel);
     80
     81    connect(serviceFilterLine, SIGNAL(textChanged(QString)), servicesFilterModel, SLOT(setFilterFixedString(QString)));
    7582
    7683    tree = new QTreeView;
     
    8794    connect(refreshShortcut, SIGNAL(activated()), this, SLOT(refreshChildren()));
    8895
    89     QVBoxLayout *topLayout = new QVBoxLayout(this);
     96    QVBoxLayout *layout = new QVBoxLayout(this);
     97    QSplitter *topSplitter = new QSplitter(Qt::Vertical, this);
     98    layout->addWidget(topSplitter);
     99
    90100    log = new QTextBrowser;
    91101    connect(log, SIGNAL(anchorClicked(QUrl)), this, SLOT(anchorClicked(QUrl)));
    92102
    93     QHBoxLayout *layout = new QHBoxLayout;
    94     layout->addWidget(services, 1);
    95     layout->addWidget(tree, 2);
    96 
    97     topLayout->addLayout(layout);
    98     topLayout->addWidget(log);
    99 
    100     connect(services, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
    101             this, SLOT(serviceChanged(QTreeWidgetItem*)));
     103    QSplitter *splitter = new QSplitter(topSplitter);
     104    splitter->addWidget(servicesView);
     105
     106    QWidget *servicesWidget = new QWidget;
     107    QVBoxLayout *servicesLayout = new QVBoxLayout(servicesWidget);
     108    servicesLayout->addWidget(serviceFilterLine);
     109    servicesLayout->addWidget(servicesView);
     110    splitter->addWidget(servicesWidget);
     111    splitter->addWidget(tree);
     112
     113    topSplitter->addWidget(splitter);
     114    topSplitter->addWidget(log);
     115
     116    connect(servicesView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
     117            this, SLOT(serviceChanged(QModelIndex)));
    102118    connect(tree, SIGNAL(customContextMenuRequested(QPoint)),
    103119            this, SLOT(showContextMenu(QPoint)));
     
    134150void QDBusViewer::refresh()
    135151{
    136     services->clear();
     152    services);
    137153
    138154    if (c.isConnected()) {
    139155        const QStringList serviceNames = c.interface()->registeredServiceNames();
    140         foreach (QString service, serviceNames)
    141             new QTreeWidgetItem(services, QStringList(service));
     156        servicesModel->setStringList(serviceNames);
    142157    }
    143158}
     
    155170    sig.mInterface = model->dBusInterface(item);
    156171    sig.mName = model->dBusMethodName(item);
     172
    157173
    158174    switch (model->itemType(item)) {
     
    208224}
    209225
     226
     227
     228
     229
     230
     231
     232
     233
     234
     235
     236
    210237void QDBusViewer::callMethod(const BusSignature &sig)
    211238{
     
    218245        const QString signature = QString::fromLatin1(mo->method(i).signature());
    219246        if (signature.startsWith(sig.mName) && signature.at(sig.mName.length()) == QLatin1Char('('))
    220             method = mo->method(i);
     247            if (getDbusSignature(mo->method(i)) == sig.mTypeSig)
     248                method = mo->method(i);
    221249    }
    222250    if (!method.signature()) {
     
    278306    sig.mInterface = model->dBusInterface(item);
    279307    sig.mName = model->dBusMethodName(item);
     308
    280309
    281310    QMenu menu;
     
    380409}
    381410
    382 void QDBusViewer::serviceChanged(QTreeWidgetItem *item)
     411void QDBusViewer::serviceChanged()
    383412{
    384413    delete tree->model();
    385414
    386415    currentService.clear();
    387     if (!item)
    388         return;
    389     currentService = item->text(0);
     416    if (!i)
     417        return;
     418    currentService = i);
    390419
    391420    tree->setModel(new QDBusViewModel(currentService, c));
     
    398427        return;
    399428
    400     new QTreeWidgetItem(services, QStringList(service));
    401 }
    402 
    403 static QTreeWidgetItem *findItem(const QTreeWidget *services, const QString &name)
    404 {
    405     for (int i = 0; i < services->topLevelItemCount(); ++i) {
    406         if (services->topLevelItem(i)->text(0) == name)
    407             return services->topLevelItem(i);
    408     }
    409     return 0;
     429    servicesModel->insertRows(0, 1);
     430    servicesModel->setData(servicesModel->index(0, 0), service);
     431}
     432
     433static QModelIndex findItem(QStringListModel *servicesModel, const QString &name)
     434{
     435    QModelIndexList hits = servicesModel->match(servicesModel->index(0, 0), Qt::DisplayRole, name);
     436    if (hits.isEmpty())
     437        return QModelIndex();
     438
     439    return hits.first();
    410440}
    411441
    412442void QDBusViewer::serviceUnregistered(const QString &name)
    413443{
    414     delete findItem(services, name);
     444    QModelIndex hit = findItem(servicesModel, name);
     445    if (!hit.isValid())
     446        return;
     447    servicesModel->removeRows(hit.row(), 1);
    415448}
    416449
     
    418451                                      const QString &newOwner)
    419452{
    420     QTreeWidgetItem *item = findItem(services, name);
    421 
    422     if (!item && oldOwner.isEmpty() && !newOwner.isEmpty())
     453    Q, name);
     454
     455    if (! && oldOwner.isEmpty() && !newOwner.isEmpty())
    423456        serviceRegistered(name);
    424     else if (item && !oldOwner.isEmpty() && newOwner.isEmpty())
    425         delete item;
    426     else if (item && !oldOwner.isEmpty() && !newOwner.isEmpty()) {
    427         delete item;
     457    else if ( && !oldOwner.isEmpty() && newOwner.isEmpty())
     458        ;
     459    else if ( && !oldOwner.isEmpty() && !newOwner.isEmpty()) {
     460        ;
    428461        serviceRegistered(name);
    429462    }
     
    445478                "<h3>%1</h3>"
    446479                "<p>Version %2</p></center>"
    447                 "<p>Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).</p>")
     480                "<p>Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).</p>")
    448481            .arg(tr("D-Bus Viewer")).arg(QLatin1String(QT_VERSION_STR)));
    449482    box.setWindowTitle(tr("D-Bus Viewer"));
  • trunk/tools/qdbus/qdbusviewer/qdbusviewer.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    5353{
    5454    QString mService, mPath, mInterface, mName;
     55
    5556};
    5657
     
    6667
    6768private slots:
    68     void serviceChanged(QTreeWidgetItem *item);
     69    void serviceChanged();
    6970    void showContextMenu(const QPoint &);
    7071    void connectionRequested(const BusSignature &sig);
     
    9293    QAction *refreshAction;
    9394    QTreeWidget *services;
     95
     96
     97
     98
    9499    QTextBrowser *log;
    95100    QRegExp objectPathRegExp;
  • trunk/tools/qdbus/qdbusxml2cpp/qdbusxml2cpp.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    5454#include "private/qdbusintrospection_p.h"
    5555
    56 #include <sys/types.h>
    5756#include <stdio.h>
    5857#include <stdlib.h>
    5958
    60 #ifdef Q_WS_WIN
    61 #include <process.h>
    62 #endif
    63 
    6459#define PROGRAMNAME     "qdbusxml2cpp"
    6560#define PROGRAMVERSION  "0.7"
    66 #define PROGRAMCOPYRIGHT "Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)."
     61#define PROGRAMCOPYRIGHT "Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies)."
    6762
    6863#define ANNOTATION_NO_WAIT      "org.freedesktop.DBus.Method.NoReply"
     
    11361131    objects or implement said interfaces.
    11371132
    1138     \c qdbusxml2dcpp has two modes of operation, that correspond to the two possible outputs it can
     1133    \c qdbusxml2cpp has two modes of operation, that correspond to the two possible outputs it can
    11391134    produce: the interface (proxy) class or the adaptor class. The latter consists of both a C++
    11401135    header and a source file, which are meant to be edited and adapted to your needs.
    11411136
    1142     The \c qdbusxml2dcpp tool is not meant to be run every time you compile your
     1137    The \c qdbusxml2cpp tool is not meant to be run every time you compile your
    11431138    application. Instead, it's meant to be used when developing the code or when the interface
    11441139    changes.
Note: See TracChangeset for help on using the changeset viewer.