Esempio n. 1
0
bool SingleApplication::attachToOtherInstance() {
    QDBusInterface iface(SERVICE_NAME, "/", "", QDBusConnection::sessionBus());
    if (!iface.isValid())
        return false;

    QDBusReply<void> reply = iface.call("receive", QDir::currentPath(), QApplication::arguments());
    if (reply.isValid())
        return true;

    qDebug() <<  "Call to SingleApplication::receive() failed: " << reply.error().message();
    return false;
}
Esempio n. 2
0
void tst_QDBusContext::sendErrorReply()
{
    QDBusInterface iface(QDBusConnection::sessionBus().baseService(), "/TestObject");
    QVERIFY(iface.isValid());

    QDBusReply<void> reply = iface.call("generateError");
    QVERIFY(!reply.isValid());

    const QDBusError &error = reply.error();
    QCOMPARE(error.name(), QString::fromLatin1(errorName));
    QCOMPARE(error.message(), QString::fromLatin1(errorMsg));
}
	int KTorrentDbusInterface::detect()
	{
		QDBusReply<QStringList> reply = QDBusConnection::sessionBus().interface()->registeredServiceNames();
		if (!reply.isValid())		/* something fishy with dbus, it won't work */
			return 0;

		foreach (QString name, reply.value())
			if (name == "org.ktorrent.ktorrent")	/* ktorrent is running */
				return 100;

		return 1;	/* dbus works, ktorrent may be closed */
	}
Esempio n. 4
0
bool tst_Events::dismissEvent(const uint cookie)
{
    Maemo::Timed::Interface timedIface;
    QDBusReply<bool> dialogResponseReply = timedIface.dialog_response_sync(cookie, -2);
    if (!dialogResponseReply.isValid()) {
        qWarning() << "Dismissing event" << cookie << "failed, DBus error"
                   << dialogResponseReply.error().message();
        return false;
    }
    bool retval = dialogResponseReply;
    return retval;
}
QGeoPositionInfo& DBusComm::requestLastKnownPosition(bool satelliteMethodOnly)
{
    QDBusReply<QByteArray> reply; 
    reply = positioningdProxy->call("latestPosition", satelliteMethodOnly);
    static QGeoPositionInfo update;

    if (reply.isValid()) {
        // cout << "requestLastKnownPosition(): received update\n";
        QByteArray message = reply.value();
        QDataStream stream(message);
        stream >> update;
    } else {
Esempio n. 6
0
void Transaction::cancel()
{
    Q_D(Transaction);
    if (d->destroyed) {
        return;
    }

    QDBusReply<void> r = d->p->Cancel();
    if (!r.isValid()) {
        d->error = Util::errorFromString(r.error().message());
    }
}
Esempio n. 7
0
int pid()
{
  Maemo::Timed::Interface ifc ;
  QDBusReply<int> reply = ifc.pid_sync() ;
  if(!reply.isValid())
  {
    qDebug() << "pid call failed" << ifc.lastError() ;
    return 1 ;
  }
  cout << "server pid=" << reply.value() << endl ;
  return 0 ;
}
Esempio n. 8
0
// Figure out which devices we should allow a user to write to.
void
PlatformUdisks::findDevices()
{
    int i = 0;
    if (!udiskEnabled())
    {
        QMessageBox msgBox;
        msgBox.setText(QObject::tr("You don't have UDisks support."));
        msgBox.exec();
        return;
    }

    // First get the list of disks
    QDBusConnection connection = QDBusConnection::systemBus();
    QDBusMessage message;
    message = QDBusMessage::createMethodCall("org.freedesktop.UDisks", "/org/freedesktop/UDisks", "org.freedesktop.UDisks", "EnumerateDevices");

    QDBusReply<QList<QDBusObjectPath> > reply = connection.call(message);
    if (!reply.isValid())
    {
        qDebug() << "Failure: " <<  reply.error();
        return;
    }

    QList<QDBusObjectPath> list = reply.value();
    QStringList devList;
    QRegExp reg("[0-9]+$");

    // Ignore partition slices
    for (i = 0; i < list.size(); ++i)
        if (!list.at(i).path().contains(reg))
            devList << list.at(i).path();

    QStringList diskList;
    // Safe mode (the default) only handles USB devices
    if (!mUnsafe)
    {
        for (i = 0; i < devList.size(); ++i)
            if (isUSB(devList.at(i)))
                diskList << devList.at(i);
    }
    else
    {
        diskList = devList;
    }

    for (i = 0; i < diskList.size(); ++i)
    {
        getNewDevice(diskList.at(i));
    }

    return;
}
Esempio n. 9
0
void method1()
{
    qDebug() << "Method 1:";

    QDBusReply<QStringList> reply = QDBusConnection::sessionBus().interface()->registeredServiceNames();
    if (!reply.isValid()) {
        qDebug() << "Error:" << reply.error().message();
        exit(1);
    }
    foreach (QString name, reply.value())
        qDebug() << name;
}
Esempio n. 10
0
QString BluetoothDevice::connectSerial()
{
    if(isProfileSupported(BluetoothProfiles::spp))
    {
        QDBusInterface interface("org.bluez",m_device->path(),"org.bluez.Serial",QDBusConnection::systemBus());
        QDBusReply<QString> reply = interface.call(QDBus::AutoDetect, "Connect","spp");

        if(reply.isValid()) return reply;
        else qDebug()<<"Error connecting spp profile: "<<reply.error().message();
    }

    return "";
}
void PeopleApplication::smsNumberToActiveService(const QString& number){
   // hard-coded details of the MeeGo SMS application
    QDBusInterface sms("com.meego.sms", "/", "com.meego.sms");
    if (!sms.isValid()) {
        qWarning() << "Composing SMS to" << number << "- could not find SMS app";
        return;
    }

    QDBusReply<void> reply = sms.call(QDBus::BlockWithGui, "showdialogpage", number);
    if (!reply.isValid())
        qWarning() << "Composing SMS to" << number << "failed:" <<
                reply.error().message();
}
Esempio n. 12
0
void KSaveIOConfig::updateProxyScout(QWidget * parent)
{
  // Inform the proxyscout kded module about changes if we cannot update,
  // ioslaves inform the end user...
  QDBusInterface kded(QStringLiteral("org.kde.kded5"), QStringLiteral("/modules/proxyscout"), QStringLiteral("org.kde.KPAC.ProxyScout"));
  QDBusReply<void> reply = kded.call(QStringLiteral("reset"));
  if (!reply.isValid())
  {
    KMessageBox::information (parent,
                              i18n("You have to restart KDE for these changes to take effect."),
                              i18nc("@title:window", "Update Failed"));
  }
}
Esempio n. 13
0
int ping_pong()
{
  Maemo::Timed::Interface ifc ;
  QDBusReply<QString> reply = ifc.ping_sync() ;
  if(!reply.isValid())
  {
    qDebug() << "ping call failed" << ifc.lastError() ;
    return 1 ;
  }
  QString pong = reply.value() ;
  cout << "---" << endl << pong.toStdString() << "---" << endl ;
  return 0 ;
}
Esempio n. 14
0
int parse_data(const char *text)
{
  Maemo::Timed::Interface ifc ;
  QDBusReply<QString> reply = ifc.parse_sync(QString(text)) ;
  if(!reply.isValid())
  {
    qDebug() << "parse call failed" << ifc.lastError() ;
    return 1 ;
  }
  QString plain = reply.value() ;
  cout << "---" << endl << plain.toStdString() << "---" << endl ;
  return 0 ;
}
Esempio n. 15
0
void ResourceView::editResource()
{
  bool ok = false;
  ResourceItem *item = currentItem();
  if ( !item ) {
    return;
  }
  ResourceCalendar *resource = item->resource();

  if ( item->isSubresource() ) {
    if ( resource->type() == "imap" ) {
      QString identifier = item->resourceIdentifier();
      const QString newResourceName =
        KInputDialog::getText( i18n( "Rename Calendar Folder" ),
                               i18n( "Please enter a new name for the calendar folder" ),
                               item->text(0),
                               &ok, this );
      if ( !ok ) {
        return;
      }

      QDBusConnection bus = QDBusConnection::sessionBus();
      QDBusInterface *interface =
        new QDBusInterface( "org.kde.kmail",
                            "/Groupware",
                            "org.kde.kmail.groupware",
                            bus,
                            this );

      QDBusReply<int> reply =
        interface->call( "changeResourceUIName", identifier, newResourceName );
      if ( !reply.isValid() ) {
        kDebug() << "DBUS Call changeResourceUIName() failed ";
      }
    } else {
      const QString subResourceName = resource->labelForSubresource( item->resourceIdentifier() );
      KMessageBox::sorry( this,
                          i18n ( "<qt>Cannot edit the calendar folder <b>%1</b>.</qt>",
                                 subResourceName ) );
    }
  } else {
    QPointer<KRES::ConfigDialog> dlg =
      new KRES::ConfigDialog( this, QString( "calendar" ), resource );
    if ( dlg->exec() ) {
      item->setText( 0, resource->resourceName() );
      mCalendar->resourceManager()->change( resource );
    }
    delete dlg;
  }
  emitResourcesChanged();
}
Esempio n. 16
0
bool X11ScreenModeChecker::isScreensaverActive()
{
    // org.freedesktop.ScreenSaver
    {
        QDBusInterface dbus(
            "org.freedesktop.ScreenSaver", "/ScreenSaver", "org.freedesktop.ScreenSaver",
            QDBusConnection::sessionBus());
        if (dbus.isValid())
        {
            QDBusReply<bool> reply = dbus.call("GetActive");
            if (reply.isValid() && reply.value())
                return true;
        }
    }
    // org.kde.screensaver
    {
        QDBusInterface dbus(
            "org.kde.screensaver", "/ScreenSaver", "org.freedesktop.ScreenSaver", QDBusConnection::sessionBus());
        if (dbus.isValid())
        {
            QDBusReply<bool> reply = dbus.call("GetActive");
            if (reply.isValid() && reply.value())
                return true;
        }
    }
    // org.gnome.ScreenSaver
    {
        QDBusInterface dbus("org.gnome.ScreenSaver", "/", "org.gnome.ScreenSaver", QDBusConnection::sessionBus());
        if (dbus.isValid())
        {
            QDBusReply<bool> reply = dbus.call("GetActive");
            if (reply.isValid() && reply.value())
                return true;
        }
    }

    return false;
}
Esempio n. 17
0
unsigned int QmSystemState::getPowerOnTimeInSeconds() {
    unsigned int result = 0;
    QDBusReply<int> powerontimerReply = QDBusConnection::systemBus().call(
                                            QDBusMessage::createMethodCall(SYS_POWERONTIMER_SERVICE,
                                                                           SYS_POWERONTIMER_PATH,
                                                                           SYS_POWERONTIMER_INTERFACE,
                                                                           SYS_POWERONTIMER_TIME_GET));
    if (!powerontimerReply.isValid()) {
        return result;
    }

    result = powerontimerReply.value();
    return result;
}
Esempio n. 18
0
void Client::test()
{
	interface = new QDBusInterface("com.Skype.API","/com/Skype");
	QDBusReply<QString> reply = interface->call("Invoke","NAME test");
	if(reply.isValid())
	{
		std::cout << reply.value().toStdString() << std::endl;
		if(reply.value().toStdString() == "OK")
		{
			reply = interface->call("Invoke","PROTOCOL 8");
			cout << reply.value().toStdString() << endl;
		}
	}
}
Esempio n. 19
0
// A special hack for WebHistory and Bookmark. We check the nfo:bookmarks and
// nfo:uri properties, and if the uri has either of them defined, we check the
// object of that property, and dispatch it by its scheme.
static bool hactionSchemeFromTracker(const QStringList& uris, QStringList &urls)
{
    QString query("SELECT ");
    Q_FOREACH (const QString& uri, uris)
        query += QString("tracker:coalesce(nfo:bookmarks(<%1>), nfo:uri(<%1>)) ").arg(uri);
    query += " {}";
    QDBusReply<QVector<QStringList> > reply = tracker()->call(SparqlQuery, query);
    if (!reply.isValid())
        return false;
    urls = reply.value()[0];
    Q_FOREACH (const QString& x, urls)
        if (x.isEmpty()) return false;
    return true;
}
Esempio n. 20
0
void SailfishPlatform::setProfile(const QString &profile) const
{
    QDBusReply<bool> res = QDBusConnection::sessionBus().call(
                QDBusMessage::createMethodCall("com.nokia.profiled", "/com/nokia/profiled", "com.nokia.profiled", "set_profile")
                << profile);
    if (res.isValid()) {
        if (!res.value()) {
            qWarning() << "Unable to set profile" << profile;
        }
    }
    else {
        qWarning() << res.error().message();
    }
}
Esempio n. 21
0
void ContactsKopete::load(bool forceReload)
{
    if (forceReload) {
        d->delayTimer.stop();
        d->contactsToUpdate.clear();
    }

    setEmitInhibited(true);

    if (!d->interface) {

        clear();

        if (addService("kopete")) {
            // Item * item = const_cast < Item * > (& itemAt(0));
            // item->title = i18n("Messaging client");
            // item->description = i18n("Messaging client is not running");
        } else {
            add(i18n("Unable to find Kopete"), "",
                    KIcon("application-x-executable"), QVariant("http://kopete.kde.org"));
        }
    } else {
        if (forceReload) {
            // kDebug() << "full";
            clear();
            d->noOnlineContacts = false;

            QDBusReply < QStringList > contacts = d->interface->contactsByFilter("online");
            if (!contacts.isValid()) {
                return;
            }

            foreach (const QString& contact, contacts.value()) {
                 updateContactData(contact);
            }

            if (size() == 0) {
                add(i18n("No online contacts"), "", KIcon("user-offline"), QVariant());
                d->noOnlineContacts = true;
                setSelfTitle(i18n("Contacts"));
            } else {
                setSelfTitle(i18nc("Contacts (number of online contacts)", "Contacts (%1)", QString::number(size())));
            }

        }
    }

    setEmitInhibited(false);
    emit updated();
}
Esempio n. 22
0
int MPRISMediaPlayer::getInt(QString obj, QString func)
{
	if (!isActive())
		return 0;

	QDBusInterface amarokApp(service, obj, "org.freedesktop.MediaPlayer");
	QDBusReply<int> reply = amarokApp.call(func);
                               
	if (reply.isValid())
	{
		return reply.value();
	}
	return -1;
}
Esempio n. 23
0
QString MPRISMediaPlayer::getString(QString obj, QString func)
{
	if (!isActive())
		return "";

	QDBusInterface amarokApp(service, obj, "org.freedesktop.MediaPlayer");
	QDBusReply<QString> reply = amarokApp.call(func);
                               
	if (reply.isValid())
	{
		return reply.value().simplified();
	}
	return "";
}
quint32 QBluetoothAbstractServicePrivate::registerRecord(const QString &record)
{
    QDBusConnection dbc = QDBusConnection::systemBus();
    QDBusInterface iface("org.bluez", "/org/bluez",
                        "org.bluez.Database", dbc);
    if (!iface.isValid())
        return 0;

    QDBusReply<quint32> reply = iface.call("AddServiceRecordFromXML", record);
    if (!reply.isValid()) 
        return 0;

    return reply.value();
}
Esempio n. 25
0
int main(int argc, char *argv[])
{
	KAboutData aboutData("kwalletnoautoclose", 0, ki18n("kwalletnoautoclose"), "version");
	KCmdLineArgs::init(argc, argv, &aboutData);
	KApplication app;

	QDBusInterface service("org.kde.kwalletd", "/modules/kwalletd");
	if (!service.isValid()) {
		_out << "Constructed service is invalid!" << endl;
		return 1;
	}
	
	QDBusReply<bool> r = service.call(QDBus::Block, "isEnabled");
	if (!r.isValid() || !r) {
		_out << "kwalletd is disabled or not running!" << endl;
		return 1;
	}
	
	QDBusReply<QString> kdewallet = service.call(QDBus::Block, "localWallet");
	_kdewallet = kdewallet;
	_out << "local wallet is " << _kdewallet << endl;
	
	QDBusReply<bool> open = service.call(QDBus::Block, "isOpen", _kdewallet);
	if (open) {
		_out << "wallet is already open. Please close to run this test." << endl;
		return 1;
	}
	
	int rc;
	
	_out << "Opening and closing the wallet properly." << endl;
	rc = openAndClose();
	if (rc != 0) {
		_out << "FAILED!" << endl;
		return rc;
	}
	
	_out << "Opening and exiting." << endl;
	QDBusReply<int> h = service.call(QDBus::Block, "open", _kdewallet, (qlonglong)0, "kwalletnoautoclose");
	if (h < 0) {
		_out << "Opening the wallet failed!" << endl;
		return 1;
	} else {
		_out << "Wallet opened." << endl;
	}
	
	_out << "Exiting. Wallet should stay open." << endl;
	
	return 0;
}
Esempio n. 26
0
bool DatabaseServerStarter::isServerRegistered()
{
    QDBusConnectionInterface* const interface = QDBusConnection::sessionBus().interface();
    QDBusReply<QStringList> reply             = interface->registeredServiceNames();

    if (reply.isValid())
    {
        QStringList serviceNames = reply.value();

        return serviceNames.contains(QLatin1String("org.kde.digikam.DatabaseServer"));
    }

    return false;
}
QTM_BEGIN_NAMESPACE

#if defined(BACKEND_NM)
static bool NetworkManagerAvailable()
{
    QDBusConnection dbusConnection = QDBusConnection::systemBus();
    if (dbusConnection.isConnected()) {
        QDBusConnectionInterface *dbiface = dbusConnection.interface();
        QDBusReply<bool> reply = dbiface->isServiceRegistered("org.freedesktop.NetworkManager");
        if (reply.isValid())
            return reply.value();
    }
    return false;
}
Esempio n. 28
0
bool NDBusDevice::update()
{
	if (NDBusStateTools::getInstance()->isSystemBusConnected() == false)
		return false;

	QDBusInterface iface(NM_DBUS_SERVICE, _path.path(), NM_DBUS_INTERFACE_DEVICES,
						 QDBusConnection::systemBus());

	if (iface.isValid()) {
		QDBusMessage msg = iface.call("getProperties");

		QDBusReply< QDBusObjectPath > reply = msg;
		if (reply.isValid())
			this->setObjectPath (reply.value().path());

		QList<QVariant> args = msg.arguments();

		if (args.count() < 21)
			return false;

		this->setInterface (args.at(1).toString());
        this->setType (args.at(2).toUInt());
        this->setUdi (args.at(3).toString());
		this->setActive (args.at(4).toBool());
		this->setActivationStage (args.at(5).toInt());
		this->setIPv4Address (args.at(6).toString());
		this->setSubnetmask (args.at(7).toString());
		this->setBroadcast (args.at(8).toString());
		this->setHardwareAddress (args.at(9).toString());
		this->setRoute (args.at(10).toString());
		this->setPrimaryDNS (args.at(11).toString());
		this->setSecondaryDNS (args.at(12).toString());
		this->setMode (args.at(13).toInt());
		this->setStrength (args.at(14).toInt());
		this->setLinkActive (args.at(15).toBool());
		this->setSpeed (args.at(16).toInt());
		this->setCapabilities (args.at(17).toUInt());
		this->setCapabilitiesType (args.at(18).toUInt());
		this->setActiveNetworkPath(args.at(19).toString());
		if (this->isWireless())
			this->setupNetworks(args.at(20).toStringList());
	}

	fprintf(stderr, "%s\n",
            qPrintable(QDBusConnection::systemBus().lastError().message()));

	return false;


}
Esempio n. 29
0
void KMailCVT::endImport()
{
    QDBusConnectionInterface * sessionBus = 0;
    sessionBus = QDBusConnection::sessionBus().interface();
    if ( sessionBus && !sessionBus->isServiceRegistered( "org.kde.kmail" ) )
       KToolInvocation::startServiceByDesktopName( "kmail", QString() ); // Will wait until kmail is started

    org::kde::kmail::kmail kmail("org.kde.kmail", "/KMail", QDBusConnection::sessionBus());
    QDBusReply<int> reply = kmail.dbusAddMessage(QString(), QString(),QString());
    if ( !reply.isValid() ) return;

    QDBusReply<void> reply2 = kmail.dbusResetAddMessage();
    if ( !reply2.isValid() ) return;
}
Esempio n. 30
0
void RemoteEditorSupport::testScriptedTutorial(const QString& filename,
                                               const QString& stepId)
                                                        throw (DBusException) {
    QDBusReply<void> reply;
    if (stepId.isEmpty()) {
        reply = call("testScriptedTutorial", filename);
    } else {
        reply = call("testScriptedTutorial", filename, stepId);
    }

    if (!reply.isValid()) {
        throw DBusException(reply.error().message());
    }
}