Ejemplo n.º 1
0
void UPower::ChangeState (State state)
{
    QDBusInterface face ("org.freedesktop.UPower",
                         "/org/freedesktop/UPower",
                         "org.freedesktop.UPower",
                         QDBusConnection::systemBus ());

    face.call (QDBus::NoBlock, State2Method (state));
}
Ejemplo n.º 2
0
void TestContactsd::importTest()
{
    const QString host("com.nokia.contactsd");
    QDBusConnection bus = QDBusConnection::sessionBus();
    QDBusInterface *interface = new QDBusInterface("com.nokia.contactsd",
            "/","com.nokia.contacts.importprogress",bus,this);
    QDBusReply<QStringList> result = interface->call("hasActiveImports");
    QVERIFY2(result.isValid() == true, result.error().message().toLatin1());
    QCOMPARE(result.value().count(), 0);
}
Ejemplo n.º 3
0
void Profile::showProfileDialog()
{

  QDBusInterface launcher ("com.nokia.DuiControlPanel", "/",
                                  "com.nokia.DuiControlPanelIf");
  launcher.call ("appletPage", "Profile");
  // Hide the status indicator menu
  if(MStatusIndicatorMenuInterface *menu = plugin->statusIndicatorMenuInterface()) {
        menu->hideStatusIndicatorMenu();
  }
}
Ejemplo n.º 4
0
QVariant QUPowerInterface::getProperty(const QString &property)
{
    QVariant var;
    QDBusInterface *interface = new QDBusInterface(UPOWER_SERVICE, UPOWER_PATH,
                                             "org.freedesktop.DBus.Properties",
                                             QDBusConnection::systemBus());
    if (interface && interface->isValid()) {
        QDBusReply<QVariant> r = interface->call("Get", UPOWER_PATH, property);
        var = r.value();
    }
    return var;
}
Ejemplo n.º 5
0
void SoundPref::onChangeDevices()
{
	// Notify AnticoDeluxe WM for changing sound devices
	QDBusInterface *iface = new QDBusInterface("org.freedesktop.AnticoDeluxe",
		"/", "org.freedesktop.AnticoDeluxe.WMCtrl",
		QDBusConnection::sessionBus(), this);
	if (!iface->isValid())
		qDebug() << "NOT VALID INTERFACE" << qPrintable(QDBusConnection::sessionBus().lastError().message());
	else {
		iface->call("changeSoundDevices", mixerCard, mixerDevice);
	}
}
Ejemplo n.º 6
0
QVariant QUDisksDeviceInterface::getProperty(const QString &property)
{
    QVariant var;
    QDBusInterface *iface = new QDBusInterface(UDISKS_SERVICE, path,
                                               "org.freedesktop.DBus.Properties",
                                               QDBusConnection::systemBus());
    if (iface && iface->isValid()) {
        QDBusReply<QVariant> r = iface->call("Get", path, property);
        var = r.value();
    }
    return var;
}
Ejemplo n.º 7
0
void SoundPref::onShowHideVolumeCtrl()
{
	// Notify AnticoDeluxe WM for show / hide volume control
	QDBusInterface *iface = new QDBusInterface("org.freedesktop.AnticoDeluxe",
		"/", "org.freedesktop.AnticoDeluxe.WMCtrl",
		QDBusConnection::sessionBus(), this);
	if (!iface->isValid())
		qDebug() << "NOT VALID INTERFACE" << qPrintable(QDBusConnection::sessionBus().lastError().message());
	else {
		iface->call("showSoundVolumeCtrl", ui.showCtrlChk->isChecked());
	}
	saveSettings();
}
Ejemplo n.º 8
0
void SoundPref::onVolumeFeedback()
{
	// Notify AnticoDeluxe WM for playing volume feedback
	QDBusInterface *iface = new QDBusInterface("org.freedesktop.AnticoDeluxe",
		"/", "org.freedesktop.AnticoDeluxe.WMCtrl",
		QDBusConnection::sessionBus(), this);
	if (!iface->isValid())
		qDebug() << "NOT VALID INTERFACE" << qPrintable(QDBusConnection::sessionBus().lastError().message());
	else {
		iface->call("soundVolumeFeedback", ui.sndVolFeedbackChk->isChecked());
	}
	saveSettings();
}
Ejemplo n.º 9
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();
}
Ejemplo n.º 10
0
void DataHandler::startDaemon()
{
    QDBusInterface* interface = new QDBusInterface("org.kde.kdenow", "/KDENow");

    //Call a method, to start the kdenowd daemon if it hasn't yet started
    QDBusReply< QString > reply = interface->call("startDaemon");
    if (reply.isValid()) {
        qDebug() << "Valid Reply received from org.kde.kdenow /KDENow";
        qDebug() << reply.value();
    }
    else {
        qDebug() << "Did not receive a valid reply from org.kde.kdenow /KDENow";
        return;
    }
}
Ejemplo n.º 11
0
ActionReply Helper::dbusaction(const QVariantMap& args)
{
  ActionReply reply;
  QDBusMessage dbusreply;
  
  // Get arguments to method call
  QString service = args["service"].toString();
  QString path = args["path"].toString();
  QString interface = args["interface"].toString();
  QString method = args["method"].toString();
  QList<QVariant> argsForCall = args["argsForCall"].toList();
  
  QDBusConnection systembus = QDBusConnection::systemBus();  
  QDBusInterface *iface = new QDBusInterface (service,
					      path,
					      interface,
					      systembus,
					      this);
  if (iface->isValid())
    dbusreply = iface->callWithArgumentList(QDBus::AutoDetect, method, argsForCall);
  delete iface;
  
  // Error handling
  if (method != "Reexecute")
  {
    if (dbusreply.type() == QDBusMessage::ErrorMessage)
    {
      reply.setErrorCode(ActionReply::DBusError);
      reply.setErrorDescription(dbusreply.errorMessage());
    }
  }

  // Reload systemd daemon to update the enabled/disabled status
  if (method == "EnableUnitFiles" || method == "DisableUnitFiles" || method == "MaskUnitFiles" || method == "UnmaskUnitFiles")
  {
    // systemd does not update properties when these methods are called so we
    // need to reload the systemd daemon.
    iface = new QDBusInterface ("org.freedesktop.systemd1",
				"/org/freedesktop/systemd1",
				"org.freedesktop.systemd1.Manager",
				systembus,
				this);
    dbusreply = iface->call(QDBus::AutoDetect, "Reload");
    delete iface;
  }
  // return a reply
  return reply;
}
Ejemplo n.º 12
0
	void DBusConnector::enumerateDevices()
	{
		QDBusInterface face ("org.freedesktop.UPower",
				"/org/freedesktop/UPower",
				"org.freedesktop.UPower",
				SB_);

		auto res = face.call ("EnumerateDevices");
		for (const auto& argument : res.arguments ())
		{
			auto arg = argument.value<QDBusArgument> ();
			QList<QDBusObjectPath> paths;
			arg >> paths;
			for (const auto& path : paths)
				requeryDevice (path.path ());
		}
	}
Ejemplo n.º 13
0
QString
BTAdaptor::adapterPath ()
{
    // Get the Bluez manager dbus interface
    QDBusInterface mgrIface ("org.bluez", "/", "org.bluez.Manager", QDBusConnection::systemBus ());
    if (!mgrIface.isValid ())
    {
        qWarning() << "Unable to get bluez manager iface";
        return "";
    }

    // Fetch the default bluetooth adapter
    QDBusReply<QDBusObjectPath> reply = mgrIface.call (QLatin1String ("DefaultAdapter"));
    
    QString adapterPath = reply.value ().path ();
    qDebug() << "Bluetooth adapter path:" << adapterPath;
    
    return adapterPath;
}
Ejemplo n.º 14
0
// Perform initialization, create the unique KSystemTimeZones instance,
// whose only function is to receive D-Bus signals from KTimeZoned,
// and create the unique KSystemTimeZonesPrivate instance.
KSystemTimeZonesPrivate *KSystemTimeZonesPrivate::instance()
{
    if (!m_instance)
    {
        m_instance = new KSystemTimeZonesPrivate;

        // A KSystemTimeZones instance is required only to catch D-Bus signals.
        m_parent = new KSystemTimeZones;
        // Ensure that the KDED time zones module has initialized. The call loads the module on demand.
        if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String("org.kde.kded")))
            KToolInvocation::klauncher();   // this calls startKdeinit, and blocks until it returns
        const QString dbusIface = QString::fromLatin1(KTIMEZONED_DBUS_IFACE);
        QDBusInterface *ktimezoned = new QDBusInterface(QLatin1String("org.kde.kded"), QLatin1String("/modules/ktimezoned"), dbusIface);
        QDBusReply<void> reply = ktimezoned->call(QLatin1String("initialize"), false);
        m_ktimezonedError = !reply.isValid();
        if (m_ktimezonedError)
            kError(161) << "KSystemTimeZones: ktimezoned initialize() D-Bus call failed: " << reply.error().message() << endl;
kDebug(161)<<"instance(): ... initialised";
        delete ktimezoned;

        // Read the time zone config written by ktimezoned
        readConfig(true);

        // Go read the database.
#ifdef Q_OS_WIN
        // On Windows, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones
        // is the place to look. The TZI binary value is the TIME_ZONE_INFORMATION structure.
        m_instance->updateTimezoneInformation(false);
#else
        // For Unix, read zone.tab.
        if (!m_zonetab.isEmpty())
            m_instance->readZoneTab(false);
#endif
        setLocalZone();
        if (!m_localZone.isValid())
            m_localZone = KTimeZone::utc();   // ensure a time zone is always returned

        qAddPostRoutine(KSystemTimeZonesPrivate::cleanup);
    }
    return m_instance;
}
Ejemplo n.º 15
0
// Perform initialization, create the unique KSystemTimeZones instance,
// whose only function is to receive D-Bus signals from KTimeZoned,
// and create the unique KSystemTimeZonesPrivate instance.
KSystemTimeZonesPrivate *KSystemTimeZonesPrivate::instance()
{
    if (!m_instance)
    {
        m_instance = new KSystemTimeZonesPrivate;
#if !defined(TIMED_SUPPORT) && !defined(KCALCORE_FOR_MEEGO)
        // A KSystemTimeZones instance is required only to catch D-Bus signals.
        m_parent = new KSystemTimeZones;
        // Ensure that the KDED time zones module has initialized. The call loads the module on demand.
        QDBusInterface *ktimezoned = new QDBusInterface("org.kde.kded", "/modules/ktimezoned", KTIMEZONED_DBUS_IFACE);
        QDBusReply<void> reply = ktimezoned->call("initialize", false);
        if (!reply.isValid())
            kError(161) << "KSystemTimeZones: ktimezoned initialize() D-Bus call failed: " << reply.error().message() << endl;
kDebug(161)<<"instance(): ... initialised";
        delete ktimezoned;
#endif
        // Read the time zone config written by ktimezoned
        readConfig(true);

        // Go read the database.
#ifdef Q_OS_WIN
        // On Windows, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones
        // is the place to look. The TZI binary value is the TIME_ZONE_INFORMATION structure.
#else
        // For Unix, read zone.tab.
        if (!m_zonetab.isEmpty())
            m_instance->readZoneTab(false);
#endif
        setLocalZone();
        if (!m_localZone.isValid()) {
            kDebug() << "m_localZone invalid";
            m_localZone = KTimeZone::utc();   // ensure a time zone is always returned
        }

        qAddPostRoutine(KSystemTimeZonesPrivate::cleanup);
    }
    return m_instance;
}
LNetworkConnectionMonitor::LNetworkConnectionMonitor( QObject* parent ) :
    NetworkConnectionMonitor( parent )
{
    m_nmInterface = new QDBusInterface( QString( "org.freedesktop.NetworkManager" ),
                                        QString( "/org/freedesktop/NetworkManager" ),
                                        QString( "org.freedesktop.NetworkManager" ),
                                        QDBusConnection::systemBus(),
                                        this );

    //get current connection state
    QDBusInterface* dbusInterface = new QDBusInterface( QString( "org.freedesktop.NetworkManager" ),
                                                        QString( "/org/freedesktop/NetworkManager" ),
                                                        QString( "org.freedesktop.DBus.Properties" ),
                                                        QDBusConnection::systemBus(),
                                                        this );

    QDBusReply<QVariant> reply = dbusInterface->call( "Get", "org.freedesktop.NetworkManager", "state" );
    if ( reply.isValid() )
    {
        if ( reply.value() == Connected )
        {
            setConnected( true );
        }
        else if ( reply.value() == Disconnected )
        {
            setConnected( false );
        }
    }
    else
    {
        qDebug() << "Error: " << reply.error();
    }
    delete dbusInterface;

    //connect network manager signals
   connect( m_nmInterface, SIGNAL( StateChange( uint ) ), this, SLOT( onStateChange( uint ) ) );

}
**     from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/

//! [0]
QDBusInterface remoteApp( "com.example.Calculator", "/Calculator/Operations",
                          "org.mathematics.RPNCalculator" );
remoteApp.call( "PushOperand", 2 );
remoteApp.call( "PushOperand", 2 );
remoteApp.call( "ExecuteOperation", "+" );
QDBusReply<int> reply = remoteApp.call( "PopOperand" );

if ( reply.isValid() )
    printf( "%d", reply.value() );          // prints 4
//! [0]
Ejemplo n.º 18
0
int main (int argc, char *argv[]) {
	QApplication app (argc, argv);
	QStringList args = app.arguments ();
	if (!args.isEmpty ()) args.pop_front ();	// The command itself
	qputenv ("DESKTOP_STARTUP_ID", qgetenv ("STARTUP_ID_COPY"));	// for startup notifications (set via rkward.desktop)
	qputenv ("STARTUP_ID_COPY", "");

	// Parse arguments that need handling in the wrapper
	bool usage = false;
	QStringList debugger_args;
	QStringList file_args;
	bool reuse = false;
	bool warn_external = true;
	QString r_exe_arg;
	int debug_level = 2;

	for (int i=0; i < args.size (); ++i) {
		if (args[i] == "--debugger") {
			args.removeAt (i);
			while (i < args.size ()) {
				QString arg = args.takeAt (i);
				if (arg == "--") break;
				debugger_args.append (arg);
			}
			if (debugger_args.isEmpty ()) usage = true;
		} else if (args[i] == "--r-executable") {
			if ((i+1) < args.size ()) {
				r_exe_arg = args.takeAt (i + 1);
			} else usage = true;
			args.removeAt (i);
			--i;
		} else if (args[i] == "--debug-level") {
			if ((i+1) < args.size ()) {
				debug_level = args[i+1].toInt ();
			}
		} else if (args[i] == "--reuse") {
			reuse = true;
		} else if (args[i] == "--nowarn-external") {
			warn_external = false;
		} else if (args[i].startsWith ("--")) {
			// all RKWard and KDE options (other than --reuse) are of the for --option <value>. So skip over the <value>
			i++;
		} else {
			QUrl url (args[i]);
			if (url.isRelative ()) {
				file_args.append (QDir::current ().absoluteFilePath (url.toLocalFile ()));
			} else {
				file_args.append (args[i]);
			}
		}
	}

	if (reuse) {
		if (!QDBusConnection::sessionBus ().isConnected ()) {
			if (debug_level > 2) qDebug ("Could not connect to session dbus");
		} else {
			QDBusInterface iface (RKDBUS_SERVICENAME, "/", "", QDBusConnection::sessionBus ());
			if (iface.isValid ()) {
				QDBusReply<void> reply = iface.call ("openAnyUrl", file_args, warn_external);
				if (!reply.isValid ()) {
					if (debug_level > 2) qDebug ("Error while placing dbus call: %s", qPrintable (reply.error ().message ()));
					return 1;
				}
				return 0;
			}
		}
	}

	// MacOS may need some path adjustments, first
#ifdef Q_WS_MAC
	QString oldpath = qgetenv ("PATH");
	if (!oldpath.contains (INSTALL_PATH)) {
		//ensure that PATH is set to include what we deliver with the bundle
		qputenv ("PATH", QString ("%1/bin:%1/sbin:%2").arg (INSTALL_PATH).arg (oldpath).toLocal8Bit ());
		if (debug_level > 3) qDebug ("Adjusting system path to %s", qPrintable (qgetenv ("PATH")));
	}
	// ensure that RKWard finds its own packages
	qputenv ("R_LIBS", R_LIBS);
	QProcess::execute ("launchctl", QStringList () << "load" << "-w" << INSTALL_PATH "/Library/LaunchAgents/org.freedesktop.dbus-session.plist");
#endif

	// Locate KDE and RKWard installations
	QString kde4_config_exe = findExeAtPath ("kde4-config", QDir::currentPath ());
	if (kde4_config_exe.isNull ()) kde4_config_exe = findExeAtPath ("kde4-config", app.applicationDirPath ());
	if (kde4_config_exe.isNull ()) kde4_config_exe = findExeAtPath ("kde4-config", QDir (app.applicationDirPath ()).filePath ("KDE/bin"));
	if (kde4_config_exe.isNull ()) {
#ifdef Q_WS_WIN
	QStringList syspath = QString (qgetenv ("PATH")).split (';');
#else
	QStringList syspath = QString (qgetenv ("PATH")).split (':');
#endif
		for (int i = 0; i < syspath.size (); ++i) {
			kde4_config_exe = findExeAtPath ("kde4-config", syspath[i]);
			if (!kde4_config_exe.isNull ()) break;
		}
	}

	if (kde4_config_exe.isNull ()) {
		QMessageBox::critical (0, "Could not find KDE installation", "The KDE installation could not be found (kde4-config). When moving / copying RKWard, make sure to copy the whole application folder, or create a shorcut / link, instead.");
		exit (1);
	}

	QDir kde_dir (QFileInfo (kde4_config_exe).absolutePath ());
	kde_dir.makeAbsolute ();
	QString kde_dir_safe_path = quoteCommand (kde_dir.path ());
#ifdef Q_WS_WIN
	QString kdeinit4_exe = findExeAtPath ("kdeinit4", kde_dir.path ());
	qputenv ("PATH", QString (kde_dir_safe_path + ';' + qgetenv ("PATH")).toLocal8Bit ());
	if (debug_level > 3) qDebug ("Adding %s to the system path", qPrintable (kde_dir_safe_path));
#endif
	// important if RKWard is not in KDEPREFIX/bin but e.g. KDEPREFIX/lib/libexec
	qputenv ("RKWARD_ENSURE_PREFIX", kde_dir_safe_path.toLocal8Bit ());
	if (debug_level > 3) qDebug ("Setting environment variable RKWARD_ENSURE_PREFIX=%s", qPrintable (kde_dir_safe_path));

	QString rkward_frontend_exe = findRKWardAtPath (app.applicationDirPath ());	// this is for running directly from a build tree
#ifdef Q_WS_MAC
	if (rkward_frontend_exe.isNull ()) rkward_frontend_exe = findRKWardAtPath (app.applicationDirPath () + "/rkward.frontend.app/Contents/MacOS"); 	// this is for running directly from a build tree
#endif
	if (rkward_frontend_exe.isNull ()) rkward_frontend_exe = findRKWardAtPath (RKWARD_FRONTEND_LOCATION);
	if (rkward_frontend_exe.isNull ()) rkward_frontend_exe = findRKWardAtPath (kde_dir.absoluteFilePath ("bin"));
	if (rkward_frontend_exe.isNull ()) rkward_frontend_exe = findRKWardAtPath (kde_dir.absoluteFilePath ("../lib/libexec"));

	if (rkward_frontend_exe.isNull ()) {
		QMessageBox::critical (0, "RKWard frontend binary missing", "RKWard frontend binary could not be found. When moving / copying RKWard, make sure to copy the whole application folder, or create a shorcut / link, instead.");
		exit (1);
	}

	if (usage) {
		QProcess::execute (rkward_frontend_exe, QStringList ("--help"));
		exit (1);
	}

#ifdef Q_WS_WIN
	// Explicit initialization of KDE, in case Windows 7 asks for admin privileges
	if (kdeinit4_exe.isNull ()) {
		kdeinit4_exe = findExeAtPath ("kdeinit4", QFileInfo (rkward_frontend_exe).absolutePath ());
	}
	if (!kdeinit4_exe.isNull ()) QProcess::execute (kdeinit4_exe, QStringList ());
#endif

	// Look for R:
	//- command line parameter
	//- Specified in cfg file next to rkward executable
	//- compile-time default
	QString r_exe = r_exe_arg;
	if (!r_exe.isNull ()) {
		if (!QFileInfo (r_exe).isExecutable ()) {
			QMessageBox::critical (0, "Specified R executable does not exist", QString ("The R executable specified on the command line (%1) does not exist or is not executable.").arg (r_exe));
			exit (1);
		}
		if (debug_level > 3) qDebug ("Using R specified on command line");
	} else {
		QFileInfo frontend_info (rkward_frontend_exe);
		QDir frontend_path = frontend_info.absoluteDir ();
		QFileInfo rkward_ini_file (frontend_path.absoluteFilePath ("rkward.ini"));
		if (rkward_ini_file.isReadable ()) {
			QSettings rkward_ini (rkward_ini_file.absoluteFilePath (), QSettings::IniFormat);
			r_exe = rkward_ini.value ("R executable").toString ();
			if (!r_exe.isNull ()) {
				if (QDir::isRelativePath (r_exe)) {
					r_exe = frontend_path.absoluteFilePath (r_exe);
				}
				if (!QFileInfo (r_exe).isExecutable ()) {
					QMessageBox::critical (0, "Specified R executable does not exist", QString ("The R executable specified in the rkward.ini file (%1) does not exist or is not executable.").arg (rkward_ini_file.absoluteFilePath ()));
					exit (1);
				}
			}
			if (debug_level > 3) qDebug ("Using R as configured in config file %s", qPrintable (rkward_ini_file.absoluteFilePath ()));
		}
		if (r_exe.isNull ()) {
			r_exe = R_EXECUTABLE;
			if (!QFileInfo (r_exe).isExecutable ()) {
				QMessageBox::critical (0, "Specified R executable does not exist", QString ("The R executable specified at compile time (%1) does not exist or is not executable. Probably the installation of R has moved. You can use the command line parameter '--R', or supply an rkward.ini file to specify the new location.").arg (r_exe));
				exit (1);
			}
			if (debug_level > 3) qDebug ("Using R as configured at compile time");
		}
	}

	qputenv ("R_BINARY", r_exe.toLocal8Bit ());
	QStringList call_args ("CMD");
	call_args.append (debugger_args);
	call_args.append (quoteCommand (rkward_frontend_exe));

	if (!args.isEmpty ()) {
		// NOTE: QProcess quotes its arguments, *but* properly passing all spaces and quotes through the R CMD wrapper, seems near(?) impossible on Windows. Instead, we use percent encoding, internally.
		for (int i = 0; i < args.size (); ++i) {
			call_args.append (QString::fromUtf8 (QUrl::toPercentEncoding (args[i], QByteArray (), " \"")));
		}
	}

	if (debug_level > 2) qDebug ("Starting frontend: %s %s", qPrintable (r_exe), qPrintable (call_args.join (" ")));

	InteractiveProcess proc;
#ifdef Q_WS_WIN
	if (debugger_args.isEmpty ()) {
		// start _without_ opening an annoying console window
		QTemporaryFile *vbsf = new QTemporaryFile (QDir::tempPath () + "/rkwardlaunchXXXXXX.vbs");
		vbsf->setAutoRemove (false);
		if (vbsf->open ()) {
			QTextStream vbs (vbsf);
			vbs << "Dim WinScriptHost\r\nSet WinScriptHost = CreateObject(\"WScript.Shell\")\r\nWinScriptHost.Run \"" << quoteCommand (r_exe);
			for (int i = 0;  i < call_args.length (); ++i) {
				vbs << " " << call_args[i];
			}
			vbs << "\", 0\r\nSet WomScriptHost = Nothing\r\n";
			vbsf->close ();
			QString filename = vbsf->fileName ();
			delete (vbsf);  // somehow, if creating vbsf on the stack, we cannot launch it, because "file is in use by another process", despite we have closed it.
			proc.start ("WScript.exe", QStringList (filename));
			bool ok = proc.waitForFinished (-1);
			if (proc.exitCode () || !ok) {
				QMessageBox::critical (0, "Error starting RKWard", QString ("Starting RKWard failed with error \"%1\"").arg (proc.errorString ()));
			}
			QFile (filename).remove ();
			return (0);
		}
	}
	// if that did not work or not on windows:
#endif
	proc.setProcessChannelMode (QProcess::ForwardedChannels);
	proc.start (quoteCommand (r_exe), call_args);
	bool ok = proc.waitForFinished (-1);
	if (proc.exitCode () || !ok) {
		QMessageBox::critical (0, "Error starting RKWard", QString ("Starting RKWard failed with error \"%1\"").arg (proc.errorString ()));
	}

	return (0);
}
Ejemplo n.º 19
0
int main(int argc, char *argv[])
{
    // TODO: Clean this up, update API, etc.
    if (argc < 5 || argc > 6)
    {
        qWarning() << "Error detected! Insufficient number of arguments.";
        qWarning() << "";
        qWarning() << "Usage: ambdbusaccess <R/W> <Object> <Property> <Zone> [Value]";
        qWarning() << "- <R/W>";
        qWarning() << "  Used for specifying [R]ead or [W]rite.";
        qWarning() << "- <Object>";
        qWarning() << "  The AMB object to access.";
        qWarning() << "- <Property>";
        qWarning() << "  The property within the object to access.";
        qWarning() << "- <Zone>";
        qWarning() << "  The AMB zone to access.";
        qWarning() << "- [Value]";
        qWarning() << "  The value to write, if writing.";
        qWarning() << "Example: ambdbusaccess Write ClimateControl FanSpeedLevel 0 7";
        qWarning() << "";
        qWarning() << "This program returns an int under the following conditions:";
        qWarning() << "Successful Read: <Value Read>";
        qWarning() << "Unsuccessful Read: -1";
        qWarning() << "Successful Write: <Value Written>";
        qWarning() << "Unsuccessful Write: -1";

        return -1;
    }

    // TODO: Error check input.
    bool read = !strncmp(argv[1], "R", 1);
    QString object = argv[2];
    QString property = argv[3];
    qint32 zone = atoi(argv[4]);
    qint32 value = 0;

    if (argc == 6)
    {
        value = atoi(argv[5]);
    }

    // Necessary to suppress Qt messages about touching the D-Bus before the application was created.
    QCoreApplication a(argc, argv);

    // Sanity check that the system bus is actually present.
    if (!QDBusConnection::systemBus().isConnected())
    {
        qCritical() << "Could not access system D-Bus!";
        return -1;
    }

    // Get ahold of the manager object.
    QDBusInterface *manager = new QDBusInterface("org.automotive.message.broker", "/", "org.automotive.Manager",
                                                 QDBusConnection::systemBus());

    // Go fetch the path for the AMB object we are concerned with.
    qDebug().nospace() << "Looking for property " << property.toStdString().c_str() << " of object " <<
                          object.toStdString().c_str() << " in zone " << zone << ".";
    QDBusReply<QDBusObjectPath> propertyPath = manager->call("FindObjectForZone", object.toStdString().c_str(), zone);
    if (!propertyPath.isValid())
    {
        qDebug() << "Invalid reply!" << propertyPath.error() << "Got the path:" << propertyPath.value().path();
    }

    // Now that we have the path, open an interface to the object.
    QDBusInterface *propertyInterface = new QDBusInterface("org.automotive.message.broker", propertyPath.value().path(),
                                                           "org.automotive.ClimateControl", QDBusConnection::systemBus());

    // Perform our read or write operation.
    if (read)
    {
        QVariant reply = propertyInterface->property(property.toStdString().c_str());
        if (!reply.isValid())
        {
            qDebug() << "Invalid reply when reading the property!" << propertyInterface->lastError() << "Property:" <<
                        reply.toString();
            value = -1;
        }
        else
        {
            qDebug().nospace() << "Got a valid reply for the property of " << reply.toString().toStdString().c_str() << ".";
            value = reply.toInt();
        }
    }
    else
    {
        QVariant reply = propertyInterface->setProperty(property.toStdString().c_str(), value);
        if (reply.toBool())
        {
            qDebug() << "Successfully wrote the property.";
        }
        else
        {
            qDebug() << "Failed to write the property.";
            value = -1;
        }
    }

    // Clean up.
    delete propertyInterface;
    delete manager;

    // Either provide the read value or some feedback to the calling application.
    return value;
}
Ejemplo n.º 20
0
	return false;
#endif
#ifdef Q_OS_WIN
	return ExitWindowsEx(EWX_POWEROFF | (force ? EWX_FORCE : 0), SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);
#endif
}

bool SystemSession::suspend(bool force) const
{
#ifdef Q_OS_LINUX
	Q_UNUSED(force)

	if(mCapabilities & FreedesktopUPower)
	{
		QDBusInterface dbusInterface("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.UPower", QDBusConnection::systemBus());
		QDBusMessage reply = dbusInterface.call("Suspend");

		if(reply.type() != QDBusMessage::ErrorMessage)
			return true;
	}
	if(mCapabilities & FreedesktopDeviceKit)
	{
		QDBusInterface dbusInterface("org.freedesktop.DeviceKit.Power", "/org/freedesktop/DeviceKit/Power", "org.freedesktop.DeviceKit.Power", QDBusConnection::systemBus());
		QDBusMessage reply = dbusInterface.call("Suspend");

		if(reply.type() != QDBusMessage::ErrorMessage)
			return true;
	}
	if(mCapabilities & FreedesktopHal)
	{
		QDBusInterface dbusInterface("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/computer", "org.freedesktop.Hal.Device.SystemPowerManagement", QDBusConnection::systemBus());
static void setDeviceMode(QString deviceMode)
{
    mceConnectionInterface.call("req_device_mode_change", deviceMode);
}
static void setDeviceMode(int deviceMode)
{
    //"req_radio_states_change"
   QDBusMessage msg = mceConnectionInterface.call("req_radio_states_change", deviceMode,1);
//   qDebug() << Q_FUNC_INFO << msg.errorMessage();
}
Ejemplo n.º 23
0
void DataHandler::onLoadedRestaurantPlugin()
{
    QDBusInterface* interface = new QDBusInterface("org.kde.kdenow", "/Restaurant");
    QDBusReply< void > reply = interface->call("getDatabaseRecordsOverDBus");
}