Esempio n. 1
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;
}
Esempio n. 2
0
bool QBluetoothPasskeyAgent_Private::unregisterAgent(const QString &localAdapter,
        const QString &addr)
{
    QString bluezAdapter = "/org/bluez";

    if (!localAdapter.isNull()) {
        bluezAdapter.append("/");
        bluezAdapter.append(localAdapter);
    }

    QDBusInterface *iface = new QDBusInterface("org.bluez",
                                               bluezAdapter,
                                               "org.bluez.Security",
                                               QDBusConnection::systemBus());

    if (!iface->isValid())
        return false;

    QString bluezMethod;
    QVariantList args;

    QString path = m_name;
    path.prepend('/');
    args << path;

    if (addr.isNull()) {
        bluezMethod = "UnregisterDefaultPasskeyAgent";
    }
    else {
        bluezMethod = "UnregisterPasskeyAgent";
        args << addr;
    }

    QDBusReply<void> reply = iface->callWithArgumentList(QDBus::Block,
            bluezMethod, args);

    if (!reply.isValid()) {
        handleError(reply.error());
        return false;
    }

    return true;
}
Esempio n. 3
0
QVariant UnitModel::data(const QModelIndex & index, int role) const
{

  if (!index.isValid())
    return QVariant();

  if (role == Qt::DisplayRole)
  {
    if (index.column() == 0)
      return unitList->at(index.row()).load_state;
    else if (index.column() == 1)
      return unitList->at(index.row()).active_state;
    else if (index.column() == 2)
      return unitList->at(index.row()).sub_state;
    else if (index.column() == 3)
      return unitList->at(index.row()).id;
  }

  else if (role == Qt::ForegroundRole)
  {
    const KColorScheme scheme(QPalette::Normal);
    if (unitList->at(index.row()).active_state == "active")
      return scheme.foreground(KColorScheme::PositiveText);
    else if (unitList->at(index.row()).active_state == "failed")
      return scheme.foreground(KColorScheme::NegativeText);
    else if (unitList->at(index.row()).active_state == "-")
      return scheme.foreground(KColorScheme::InactiveText);
    else
      return QVariant();
  }

  else if (role == Qt::ToolTipRole)
  {
    QString selUnit = unitList->at(index.row()).id;
    QString selUnitPath = unitList->at(index.row()).unit_path.path();
    QString selUnitFile = unitList->at(index.row()).unit_file;

    QString toolTipText;
    toolTipText.append("<FONT COLOR=white>");
    toolTipText.append("<b>" + selUnit + "</b><hr>");

    // Create a DBus interface
    QDBusConnection bus("");
    if (!userBus.isEmpty())
      bus = QDBusConnection::connectToBus(userBus, "org.freedesktop.systemd1");
    else
      bus = QDBusConnection::systemBus();
    QDBusInterface *iface;

    // Use the DBus interface to get unit properties
    if (!selUnitPath.isEmpty())
    {
      // Unit has a valid path

      iface = new QDBusInterface ("org.freedesktop.systemd1",
                                  selUnitPath,
                                  "org.freedesktop.systemd1.Unit",
                                  bus);
      if (iface->isValid())
      {
        // Unit has a valid unit DBus object
        toolTipText.append(i18n("<b>Description: </b>"));
        toolTipText.append(iface->property("Description").toString());
        toolTipText.append(i18n("<br><b>Unit file: </b>"));
        toolTipText.append(iface->property("FragmentPath").toString());
        toolTipText.append(i18n("<br><b>Unit file state: </b>"));
        toolTipText.append(iface->property("UnitFileState").toString());

        qulonglong ActiveEnterTimestamp = iface->property("ActiveEnterTimestamp").toULongLong();
        toolTipText.append(i18n("<br><b>Activated: </b>"));
        if (ActiveEnterTimestamp == 0)
          toolTipText.append("n/a");
        else
        {
          QDateTime timeActivated;
          timeActivated.setMSecsSinceEpoch(ActiveEnterTimestamp/1000);
          toolTipText.append(timeActivated.toString());
        }

        qulonglong InactiveEnterTimestamp = iface->property("InactiveEnterTimestamp").toULongLong();
        toolTipText.append(i18n("<br><b>Deactivated: </b>"));
        if (InactiveEnterTimestamp == 0)
          toolTipText.append("n/a");
        else
        {
          QDateTime timeDeactivated;
          timeDeactivated.setMSecsSinceEpoch(InactiveEnterTimestamp/1000);
          toolTipText.append(timeDeactivated.toString());
        }
      }
      delete iface;

    }
    else
    {
      // Unit does not have a valid unit DBus object
      // Retrieve UnitFileState from Manager object

      iface = new QDBusInterface ("org.freedesktop.systemd1",
                                  "/org/freedesktop/systemd1",
                                  "org.freedesktop.systemd1.Manager",
                                  bus);
      QList<QVariant> args;
      args << selUnit;

      toolTipText.append(i18n("<b>Unit file: </b>"));
      if (!selUnitFile.isEmpty())
        toolTipText.append(selUnitFile);

      toolTipText.append(i18n("<br><b>Unit file state: </b>"));
      if (!selUnitFile.isEmpty())
        toolTipText.append(iface->callWithArgumentList(QDBus::AutoDetect, "GetUnitFileState", args).arguments().at(0).toString());

      delete iface;
    }

    // Journal entries for units
    toolTipText.append(i18n("<hr><b>Last log entries:</b>"));
    QStringList log = getLastJrnlEntries(selUnit);
    if (log.isEmpty())
      toolTipText.append(i18n("<br><i>No log entries found for this unit.</i>"));
    else
    {
      for(int i = log.count()-1; i >= 0; --i)
      {
        if (!log.at(i).isEmpty())
          toolTipText.append(QString("<br>" + log.at(i)));
      }
    }

    toolTipText.append("</FONT");

    return toolTipText;
  }

  return QVariant();
}