Ejemplo n.º 1
0
static PyObject *
cups_setPasswordCB (PyObject *self, PyObject *args)
{
  struct TLS *tls = get_TLS ();
  PyObject *cb;

  if (!PyArg_ParseTuple (args, "O:cups_setPasswordCB", &cb))
    return NULL;

  if (!PyCallable_Check (cb)) {
    PyErr_SetString (PyExc_TypeError, "Parameter must be callable");
    return NULL;
  }

  debugprintf ("-> cups_setPasswordCB\n");
#ifdef HAVE_CUPS_1_4
  Py_XDECREF (tls->cups_password_callback_context);
  tls->cups_password_callback_context = NULL;
#endif /* HAVE_CUPS_1_4 */

  Py_XINCREF (cb);
  Py_XDECREF (tls->cups_password_callback);
  tls->cups_password_callback = cb;

#ifdef HAVE_CUPS_1_4
  cupsSetPasswordCB2 (password_callback_oldstyle, NULL);
#else
  cupsSetPasswordCB (do_password_callback);
#endif

  debugprintf ("<- cups_setPasswordCB\n");
  Py_INCREF (Py_None);
  return Py_None;
}
Ejemplo n.º 2
0
static PyObject *
cups_setPasswordCB2 (PyObject *self, PyObject *args)
{
  struct TLS *tls = get_TLS ();
  PyObject *cb;
  PyObject *cb_context = NULL;

  if (!PyArg_ParseTuple (args, "O|O", &cb, &cb_context))
    return NULL;

  if (cb == Py_None && cb_context != NULL) {
    PyErr_SetString (PyExc_TypeError, "Default callback takes no context");
    return NULL;
  }
  else if (cb != Py_None && !PyCallable_Check (cb)) {
    PyErr_SetString (PyExc_TypeError, "Parameter must be callable");
    return NULL;
  }

  debugprintf ("-> cups_setPasswordCB2\n");

  Py_XINCREF (cb_context);
  Py_XDECREF (tls->cups_password_callback_context);
  tls->cups_password_callback_context = cb_context;

  if (cb == Py_None)
  {
    Py_XDECREF (tls->cups_password_callback);
    tls->cups_password_callback = NULL;
    cupsSetPasswordCB2 (NULL, NULL);
  }
  else
  {
    Py_XINCREF (cb);
    Py_XDECREF (tls->cups_password_callback);
    tls->cups_password_callback = cb;
    cupsSetPasswordCB2 (password_callback_newstyle, cb_context);
  }

  debugprintf ("<- cups_setPasswordCB2\n");
  Py_INCREF (Py_None);
  return Py_None;
}
Ejemplo n.º 3
0
void KCupsConnection::run()
{
    // This is dead cool, cups will call the thread_password_cb()
    // function when a password set is needed, as we passed the
    // password dialog pointer the functions just need to call
    // it on a blocking mode.
    cupsSetPasswordCB2(password_cb, m_passwordDialog);

    // Creates the timer that will renew the DBus subscription
    m_renewTimer = new QTimer;
    m_renewTimer->setInterval(RENEW_INTERVAL);
    m_renewTimer->moveToThread(this);
    connect(m_renewTimer, SIGNAL(timeout()), this, SLOT(renewDBusSubscription()), Qt::DirectConnection);

    m_inited = true;
    exec();
}