public static int Main(string[] args) { new QCoreApplication(args); if (!QDBusConnection.SessionBus().IsConnected()) { Console.WriteLine("Cannot connect to the D-BUS session bus.\n" + "To start it, run:\n" + "\teval `dbus-launch --auto-syntax`\n"); return 1; } QDBusInterface iface = new QDBusInterface(SERVICE_NAME, "/", "", QDBusConnection.SessionBus()); if (iface.IsValid()) { QDBusMessage message = iface.Call("ping", args.Length > 0 ? args[0] : ""); QDBusReply<string> reply = new QDBusReply<string>(message); if (reply.IsValid()) { Console.WriteLine("Reply was: {0}", reply.Value()); return 0; } Console.WriteLine("Call failed: {0}\n", reply.Error().Message()); return 1; } Console.WriteLine(QDBusConnection.SessionBus().LastError().Message()); return 1; }
public void SetUrlInBrowser(QTableWidgetItem item) { QDBusInterface iface = new QDBusInterface("org.kde.Browser", "/", "", QDBusConnection.SessionBus()); if (iface.IsValid()) { iface.Call("SetUrl", item.Text()); } else { Console.Error.WriteLine("Error with DBUS"); } }
public void BookLocation() { QDBusInterface iface = new QDBusInterface("org.kde.BookMarkList", "/", "", QDBusConnection.SessionBus()); if (iface.IsValid()) { iface.Call("add", location.Text); } else { Console.Error.WriteLine("Error with DBUS\n"); } }
public static void Method2() { Console.WriteLine("Method 2:"); QDBusConnection bus = QDBusConnection.SessionBus(); QDBusInterface dbus_iface = new QDBusInterface("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", bus); foreach (string name in dbus_iface.Call("ListNames").Arguments()[0].Value<List<string>>()) { Console.WriteLine(name); } }
public void Start(string name, string oldValue, string newValue) { if (name != SERVICE_NAME || newValue == "") return; // find our remote iface = new QDBusInterface(SERVICE_NAME, "/", "com.trolltech.QtDBus.ComplexPong.Pong", QDBusConnection.SessionBus(), this); if (!iface.IsValid()) { Console.Error.WriteLine(QDBusConnection.SessionBus().LastError().Message()); QCoreApplication.Quit(); } Connect(iface, SIGNAL("aboutToQuit()"), QCoreApplication.Instance(), SLOT("quit()")); while (true) { Console.Write("Ask your question: "); string line = Console.ReadLine().Trim(); if (line == "") { iface.Call("quit"); return; } else if (line == "value") { QVariant reply = iface.Property("value"); if (!reply.IsNull()) Console.WriteLine("value = {0}", reply.ToString()); } else if (line.StartsWith("value=")) { iface.SetProperty("value", new QVariant(line.Substring(6))); } else { QDBusReply<string> reply = new QDBusReply<string>(iface.Call("query", new QVariant(line))); if (reply.IsValid()) Console.WriteLine("Reply was: {0}", reply.Value()); } if (iface.LastError().IsValid()) Console.Error.WriteLine("Call failed: {0}", iface.LastError().Message()); } }