コード例 #1
0
bool SessionManager::registerDBus()
{
    QDBusConnection bus = QDBusConnection::sessionBus();

    // Start the D-Bus service
    (void)new SessionAdaptor(this);
    if (!bus.registerObject(objectPath, this)) {
        qWarning() << "Couldn't register /U2TSession D-Bus object:"
                                   << qPrintable(bus.lastError().message());
        return false;
    }
    if (!bus.registerService(interfaceName)) {
        qWarning() << "Couldn't register io.u2t.session D-Bus service:"
                                   << qPrintable(bus.lastError().message());
        return false;
    }
    qDebug() << "Registered" << interfaceName << "D-Bus interface";

    // Register process launcher service
    if (!m_launcher->registerInterface())
        return false;
    //
    // // Register screen saver interface
    // if (!m_screenSaver->registerInterface())
    //     return false;

    return true;
}
コード例 #2
0
ファイル: DBusInterface.cpp プロジェクト: karanluthra/trojita
bool registerInstance(Gui::MainWindow *window, QString &error)
{
    QDBusConnection conn = QDBusConnection::sessionBus();
    if (!conn.isConnected()) {
        error = conn.lastError().message();
        return false;
    }

    bool serviceOk = conn.registerService(service());
    if (!serviceOk) {
        error = conn.lastError().message();
        return false;
    }

    MainWindowBridge *object = new MainWindowBridge(window);
    bool objectOk = conn.registerObject(path, object, QDBusConnection::ExportAllSlots);
    if (!objectOk) {
        error = conn.lastError().message();
        delete object;
        conn.unregisterService(service());
        return false;
    }

    return true;
}
コード例 #3
0
FakeAccounts::FakeAccounts(QObject *parent)
    : QObject(parent)
    , m_lastUid(1000)
{
    QDBusConnection bus = QDBusConnection::sessionBus();

    if (!bus.registerObject(QStringLiteral("/org/freedesktop/Accounts"), this))
        qFatal("Unable to register object: %s", qPrintable(bus.lastError().message()));
    if (!bus.registerService(QStringLiteral("org.freedesktop.Accounts")))
        qFatal("Unable to register service: %s", qPrintable(bus.lastError().message()));
}
コード例 #4
0
ファイル: netctlhelper.cpp プロジェクト: arcan1s/netctl-gui
void NetctlHelper::createInterface()
{
    if (debug) qDebug() << PDEBUG;

    QDBusConnection bus = QDBusConnection::systemBus();
    if (!bus.registerService(DBUS_HELPER_SERVICE)) {
        if (debug) qDebug() << PDEBUG << ":" << "Could not register service";
        if (debug) qDebug() << PDEBUG << ":" << bus.lastError().message();
        return quitHelper();
    }
    if (!bus.registerObject(DBUS_LIB_PATH,
                            new NetctlAdaptor(this, debug, configuration),
                            QDBusConnection::ExportAllContents)) {
        if (debug) qDebug() << PDEBUG << ":" << "Could not register library object";
        if (debug) qDebug() << PDEBUG << ":" << bus.lastError().message();
        return quitHelper();
    }
    if (!bus.registerObject(DBUS_CTRL_PATH,
                            new ControlAdaptor(this, debug, configuration),
                            QDBusConnection::ExportAllContents)) {
        if (debug) qDebug() << PDEBUG << ":" << "Could not register control object";
        if (debug) qDebug() << PDEBUG << ":" << bus.lastError().message();
        return quitHelper();
    }
    if (!bus.registerObject(DBUS_INTERFACE_PATH,
                            new InterfaceAdaptor(this, debug, configuration),
                            QDBusConnection::ExportAllContents)) {
        if (debug) qDebug() << PDEBUG << ":" << "Could not register interface object";
        if (debug) qDebug() << PDEBUG << ":" << bus.lastError().message();
        return quitHelper();
    }
    // session bus
    if (!session) return;
    QDBusConnection sessionBus = QDBusConnection::sessionBus();
    if (!sessionBus.registerService(DBUS_HELPER_SERVICE)) {
        if (debug) qDebug() << PDEBUG << ":" << "Could not register session service";
        if (debug) qDebug() << PDEBUG << ":" << sessionBus.lastError().message();
    }
    if (!sessionBus.registerObject(DBUS_LIB_PATH,
                                   new NetctlAdaptor(this, debug, configuration),
                                   QDBusConnection::ExportAllContents)) {
        if (debug) qDebug() << PDEBUG << ":" << "Could not register session library object";
        if (debug) qDebug() << PDEBUG << ":" << sessionBus.lastError().message();
    }
    if (!sessionBus.registerObject(DBUS_CTRL_PATH,
                                   new ControlAdaptor(this, debug, configuration),
                                   QDBusConnection::ExportAllContents)) {
        if (debug) qDebug() << PDEBUG << ":" << "Could not register session control object";
        if (debug) qDebug() << PDEBUG << ":" << sessionBus.lastError().message();
    }
    if (!sessionBus.registerObject(DBUS_INTERFACE_PATH,
                                   new InterfaceAdaptor(this, debug, configuration),
                                   QDBusConnection::ExportAllContents)) {
        if (debug) qDebug() << PDEBUG << ":" << "Could not register session interface object";
        if (debug) qDebug() << PDEBUG << ":" << bus.lastError().message();
        return quitHelper();
    }
}
コード例 #5
0
/*!
    Destroy this QCop service handling object.
*/
QtopiaAbstractService::~QtopiaAbstractService()
{
#if defined(QTOPIA_DBUS_IPC)
    QDBusConnection dbc = QDBus::sessionBus();
    if (!dbc.isConnected()) {
        qWarning() << "Unable to connect to D-BUS:" << dbc.lastError();
        return;
    }

    qLog(Services) << "Unregistering service" << m_data->m_service;

    QString path = dbusPathBase;
    path.append(m_data->m_service);
    dbc.unregisterObject(path);

    QDBusConnectionInterface *iface = dbc.interface();
    QString service = dbusInterface;
    service.append(".");
    service.append(m_data->m_service);

    iface->unregisterService(service);
#endif

    if (m_data)
        delete m_data;
}
コード例 #6
0
bool QNetworkManagerSettingsConnection::setConnections()
{
    if(!isValid() )
        return false;

    QDBusConnection dbusConnection = QDBusConnection::systemBus();
    bool allOk = false;
    if(!dbusConnection.connect(d->service, d->path,
                           QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), QLatin1String("Updated"),
                           this, SIGNAL(updated(QNmSettingsMap)))) {
        allOk = true;
    } else {
        QDBusError error = dbusConnection.lastError();
    }

    delete nmDBusHelper;
    nmDBusHelper = new QNmDBusHelper(this);
    connect(nmDBusHelper, SIGNAL(pathForSettingsRemoved(QString)),
            this,SIGNAL(removed(QString)));

    if (!dbusConnection.connect(d->service, d->path,
                           QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), QLatin1String("Removed"),
                           nmDBusHelper, SIGNAL(slotSettingsRemoved()))) {
        allOk = true;
    }

    return allOk;
}
コード例 #7
0
ファイル: launcher.cpp プロジェクト: muromec/qtopia-ezx
void Launcher::startup(const QString &app)
{
    QDBusConnection dbc = QDBus::sessionBus();

    if (!dbc.isConnected()) {
        fprintf(stderr, "QtopiaLauncher: Could not connect to DBUS bus\n");
        exit(1);
    }

    bool r = dbc.connect(QString(),                           // Service
                         "/DBusLauncher",                     // Path
                         "com.trolltech.qtopia.DBusLauncher", // Interface
                         "launched",                          // Name
                         this,
                         SLOT(handleSignalReceived(QString,QDBusMessage)));

    QDBusMessage message =
            QDBusMessage::methodCall("com.trolltech.qtopia.DBusLauncher",
                                     "/DBusLauncher",
                                     "com.trolltech.qtopia.DBusLauncher",
                                     "launch", dbc);
    message << app;

    bool ret = dbc.send(message);
    if (!ret)
        fprintf(stderr, "Unable to send message: %s", dbc.lastError().message().toAscii().constData());

    m_app = app;
}
コード例 #8
0
ファイル: dbus.cpp プロジェクト: surfhh/dontpanic
 // ---------------------------------------------------------------------------------
 bool detail::service_to_register_with_dbus::at_system_bus()
 {
   QDBusConnection con = dbus().system_bus();
   if ( !con.isConnected() )
   {
     qWarning() << "not connected to system bus";
     return false;
   }
   if ( _M_op == REGISTER )
   {
     bool result = con.registerService ( _M_service );
     if ( result == false )
     {
       qDebug() << "something went wrong when trying to register the DBUS service: " << _M_service;
       qDebug() << con.lastError();
       return false;
     }
     return true;
   }
   else
   {
     if ( con.interface()->isServiceRegistered ( _M_service ) )
     {
       return con.unregisterService ( _M_service );
     }
   }
   return true;
 }
コード例 #9
0
void DeclarativeDBusAdaptor::componentComplete()
{
    QDBusConnection conn = DeclarativeDBus::connection(m_bus);

    // Register service name only if it has been set.
    if (!m_service.isEmpty()) {
        if (!conn.registerService(m_service)) {
            qmlInfo(this) << "Failed to register service" << m_service;
            qmlInfo(this) << conn.lastError().message();
        }
    }

    // It is still valid to publish an object on the bus without first registering a service name,
    // a remote process would have to connect directly to the DBus address.
    if (!conn.registerVirtualObject(m_path, this)) {
        qmlInfo(this) << "Failed to register object" << m_path;
        qmlInfo(this) << conn.lastError().message();
    }
}
コード例 #10
0
static QDBusConnectionInterface *tryToInitDBusConnection()
{
    // Check the D-Bus connection health
    QDBusConnectionInterface *dbusService = 0;
    QDBusConnection sessionBus = QDBusConnection::sessionBus();
    if (!sessionBus.isConnected() || !(dbusService = sessionBus.interface())) {
        kError() << "KUniqueApplication: Cannot find the D-Bus session server: " << sessionBus.lastError().message() << endl;
        ::exit(255);
    }
    return dbusService;
}
コード例 #11
0
void MainController::creatDBusService()
{
    // 用于建立到session bus的连接
    QDBusConnection bus = QDBusConnection::sessionBus();
    // 在session bus上注册名为"com.fcitx_qimpanel.hotel"的service
    if (!bus.registerService("com.fcitx_qimpanel.hotel")) {  //注意命名规则-和_
            qDebug() << bus.lastError().message();
            exit(1);
    }
    // "QDBusConnection::ExportAllSlots"表示把类Hotel的所有Slot都导出为这个Object的method
    bus.registerObject("/", mSelf ,QDBusConnection::ExportAllSlots);//可以优化只导出需要的
}
コード例 #12
0
SailorgramInterface::SailorgramInterface(QObject *parent) : QObject(parent)
{
    new SailorgramAdaptor(this);

    QDBusConnection connection = QDBusConnection::sessionBus();

    if(!connection.isConnected())
    {
        qWarning("Cannot connect to the D-Bus session bus.");
        return;
    }

    if(!connection.registerService(SailorgramInterface::INTERFACE_NAME))
    {
        qWarning() << connection.lastError().message();
        return;
    }

    if(!connection.registerObject("/", this))
        qWarning() << connection.lastError().message();
}
コード例 #13
0
Callbacks::Callbacks()
{
    new MediaCallbacksAdaptor( this );
    QDBusConnection connection = QDBusConnection::systemBus();
    if ( !connection.isConnected() ) {
	qFatal( "Cannot connect to the D-Bus system bus" );
	exit( 1 );
    }
    connection.registerObject( "/Media", this );
    if ( !connection.registerService( "org.opensuse.MediaCallbacks" ) ) {
	qDebug() << qPrintable( connection.lastError().message() );
	exit( 1 );
    }
}
コード例 #14
0
FakeUser::FakeUser(const QString &path, qlonglong uid, const QString &name,
                   const QString &fullName, int accountType, QObject *parent)
    : QObject(parent)
    , cached(false)
    , m_uid(uid)
    , m_name(name)
    , m_fullName(fullName)
    , m_accountType(accountType)
    , m_path(QDBusObjectPath(path))
{
    QDBusConnection bus = QDBusConnection::sessionBus();

    if (!bus.registerObject(path, this))
        qFatal("Unable to register object: %s", qPrintable(bus.lastError().message()));
}
コード例 #15
0
ファイル: timed.cpp プロジェクト: special/timed
void Timed::init_backup_object()
{
  backup_object = new QObject ;
  new backup_t(this, backup_object) ;
  // XXX: what if we're using system bus: how should backup know this?
  // TODO: if using system bus, keep track of started/terminated sessions? (omg!)
  QDBusConnection conn = Maemo::Timed::bus() ;
  const char * const path = "/com/nokia/timed/backup" ;
  if (conn.registerObject(path, backup_object))
    log_info("backup interface object registered on path '%s'", path) ;
  else
  {
    log_critical("failed to register backup object on path '%s': %s", path, conn.lastError().message().toStdString().c_str()) ;
    log_critical("backup/restore not available") ;
  }
}
コード例 #16
0
/**
 * main
 */
int main(int argc, char ** argv) {

  QCoreApplication app(argc, argv);
  DBusWatcher * watcher = new DBusWatcher;
  QDBusConnection conn = QDBusConnection::connectToBus(
    QDBusConnection::SystemBus, "org.freedesktop.NetworkManager");
  if(!conn.isConnected()) {
    qDebug() << "Oh. Connection failed:" << conn.lastError();
    return -1;
  }
  conn.connect("org.freedesktop.NetworkManager",
    "/org/freedesktop/NetworkManager", "org.freedesktop.NetworkManager",
    "StateChanged", "u", watcher, SLOT(watch(uint)));

  return app.exec();
}
コード例 #17
0
void DeclarativeDBusInterface::call(const QString &method, const QJSValue &arguments)
{
    QVariantList dbusArguments = argumentsFromScriptValue(arguments);

    QDBusMessage message = QDBusMessage::createMethodCall(
                m_service,
                m_path,
                m_interface,
                method);
    message.setArguments(dbusArguments);

    QDBusConnection conn = DeclarativeDBus::connection(m_bus);

    if (!conn.send(message))
        qmlInfo(this) << conn.lastError();
}
コード例 #18
0
ファイル: timed.cpp プロジェクト: special/timed
void Timed::init_backup_dbus_name()
{
  // We're using an another name for backup interface
  //   to avoid mess while switching to system bus and back again (later)
  // XXX: But for now it's just the same connection as com.nokia.time
  QDBusConnection conn = Maemo::Timed::bus() ;
  const char * const name = "com.nokia.timed.backup" ;
  const string conn_name = conn.name().toStdString() ;
  if (conn.registerService(name))
    log_info("service name '%s' registered on bus '%s'", name, conn_name.c_str()) ;
  else
  {
    const string msg = conn.lastError().message().toStdString() ;
    log_critical("can't register service '%s' on bus '%s': '%s'", name, conn_name.c_str(), msg.c_str()) ;
    log_critical("backup/restore not available") ;
  }
}
コード例 #19
0
ConnectionManager::SocketConnectionStatus
ConnectionManager::setupSocketConnection()
{
    QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
    QLatin1String one("1");
    if (environment.value(QLatin1String("SSO_USE_PEER_BUS"), one) != one) {
        return SocketConnectionUnavailable;
    }

#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
    QString runtimeDir =
        QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
#else
    QString runtimeDir = environment.value(QLatin1String("XDG_RUNTIME_DIR"));
#endif
    if (runtimeDir.isEmpty()) return SocketConnectionUnavailable;

    QString socketFileName =
        QString::fromLatin1("unix:path=%1/" SIGNOND_SOCKET_FILENAME).arg(runtimeDir);
    static int count = 0;

    QDBusConnection connection =
        QDBusConnection::connectToPeer(socketFileName,
                                       QString(QLatin1String("libsignon-qt%1")).arg(count++));
    if (!connection.isConnected()) {
        QDBusError error = connection.lastError();
        QString name = error.name();
        BLAME() << "p2p error:" << error << error.type();
        if (name == QLatin1String("org.freedesktop.DBus.Error.FileNotFound") &&
            m_serviceStatus != ServiceActivated) {
            return SocketConnectionNoService;
        } else {
            return SocketConnectionUnavailable;
        }
    }

    m_connection = connection;
    m_connection.connect(QString(),
                         QLatin1String("/org/freedesktop/DBus/Local"),
                         QLatin1String("org.freedesktop.DBus.Local"),
                         QLatin1String("Disconnected"),
                         this, SLOT(onDisconnected()));

    return SocketConnectionOk;
}
コード例 #20
0
QBluetoothPasskeyAgent_Private::QBluetoothPasskeyAgent_Private(QBluetoothPasskeyAgent *parent, const QString &name) : QDBusAbstractAdaptor(parent)
{
    m_parent = parent;
    m_name = name;
    m_error = QBluetoothPasskeyAgent::NoError;

    QDBusConnection dbc = QDBusConnection::systemBus();
    if (!dbc.isConnected()) {
        qWarning() << "Unable to connect to D-BUS:" << dbc.lastError();
        return;
    }

    QString path = "/" + m_name;
    if(dbc.registerObject(path, parent))
        qLog(Bluetooth) << "Registered pairing agent object on dbus path=" << path;
    else
        qWarning() << "Registering BT pairing agent object on dbus failed";
}
コード例 #21
0
QBluetoothPasskeyAgent_Private::QBluetoothPasskeyAgent_Private(QBluetoothPasskeyAgent *parent, const QString &name) : QObject(parent)
{
    m_parent = parent;
    m_name = name;
    m_error = QBluetoothPasskeyAgent::NoError;

    QDBusConnection dbc = QDBusConnection::systemBus();
    if (!dbc.isConnected()) {
        qWarning() << "Unable to connect to D-BUS:" << dbc.lastError();
        return;
    }


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

    new PasskeyAgentDBusAdaptor(this);
    dbc.registerObject(path, this, QDBusConnection::ExportNonScriptableSlots);
}
コード例 #22
0
/*!
    Publishes all slots on this object within subclasses of QtopiaAbstractService.
    This is typically called from a subclass constructor.
*/
void QtopiaAbstractService::publishAll()
{
#if defined(QTOPIA_DBUS_IPC)
    QDBusConnection dbc = QDBus::sessionBus();
    if (!dbc.isConnected()) {
        qWarning() << "Unable to connect to D-BUS:" << dbc.lastError();
        return;
    }

    qLog(Services) << "Registering service" << m_data->m_service;

    QDBusConnectionInterface *iface = dbc.interface();
    QString service = dbusInterface;
    service.append(".");
    service.append(m_data->m_service);
    if (iface->registerService(service) == QDBusConnectionInterface::ServiceNotRegistered) {
        qWarning() << "WARNING: could not request name" << service;
        return;
    }

    new QtopiaDBusAdaptor(this);
    QString path = dbusPathBase;
    path.append(m_data->m_service);
    dbc.registerObject(path, this, QDBusConnection::ExportNonScriptableSlots);
#else
    const QMetaObject *meta = metaObject();
    if ( !m_data->m_publishAllCalled ) {
        int count = meta->methodCount();
        int index = QtopiaAbstractService::staticMetaObject.methodCount();
        for ( ; index < count; ++index ) {
            QMetaMethod method = meta->method( index );
            if ( method.methodType() == QMetaMethod::Slot &&
                 method.access() == QMetaMethod::Public) {
                QByteArray name = method.signature();
                QtopiaIpcAdaptor::connect(m_data->m_copobject, "3" + name, this, "1" + name);
            }
        }
        m_data->m_publishAllCalled = true;
    }
#endif
}
コード例 #23
0
ファイル: engine.cpp プロジェクト: drewbug/kandas
Kandas::Daemon::Engine::Engine()
    : QObject()
    , m_clean(true)
    , m_clientCount(0)
    , m_system(Kandas::SystemUnchecked)
{
    //auto refresh
    connect(&m_autoRefreshTimer, SIGNAL(timeout()), this, SLOT(refreshData()));
    //D-Bus
    new KandasAdaptor(this);
    QDBusConnection bus = QDBusConnection::systemBus();
    if (!bus.registerService("org.kandas"))
    {
        kError() << "Could not register service. D-Bus returned:" << bus.lastError().message();
        m_clean = false;
    }
    else
        bus.registerObject("/", this);
    //schedule initial data updates
    QTimer::singleShot(0, this, SLOT(refreshData()));
}
コード例 #24
0
HomeApplication::HomeApplication(int &argc, char **argv, const QString &qmlPath)
    : QGuiApplication(argc, argv)
    , _mainWindowInstance(0)
    , _qmlPath(qmlPath)
    , originalSigIntHandler(signal(SIGINT, quitSignalHandler))
    , originalSigTermHandler(signal(SIGTERM, quitSignalHandler))
    , updatesEnabled(true)
    , homeReadySent(false)
    , onUpdatesDisabledUnfocusedWindowId(0)
{
    setApplicationName("Lipstick");
    // TODO: autogenerate this from tags
    setApplicationVersion(VERSION);

    QTranslator *engineeringEnglish = new QTranslator(this);
    engineeringEnglish->load("lipstick_eng_en", "/usr/share/translations");
    installTranslator(engineeringEnglish);
    QTranslator *translator = new QTranslator(this);
    translator->load(QLocale(), "lipstick", "-", "/usr/share/translations");
    installTranslator(translator);

    // Initialize the QML engine
    qmlEngine = new QQmlEngine(this);

    // Initialize the notification manager
    NotificationManager::instance();
    new NotificationPreviewPresenter(this);

    // Create screen lock logic - not parented to "this" since destruction happens too late in that case
    screenLock = new ScreenLock;
    LipstickSettings::instance()->setScreenLock(screenLock);
    new ScreenLockAdaptor(screenLock);

    deviceLock = new DeviceLock(this);
    new DeviceLockAdaptor(deviceLock);

    volumeControl = new VolumeControl;
    new BatteryNotifier(this);
    new DiskSpaceNotifier(this);
    new ThermalNotifier(this);
    usbModeSelector = new USBModeSelector(this);
    connect(usbModeSelector, SIGNAL(dialogShown()), screenLock, SLOT(unlockScreen()));
    shutdownScreen = new ShutdownScreen(this);
    new ShutdownScreenAdaptor(shutdownScreen);
    connectionSelector = new ConnectionSelector(this);

    // MCE and usb-moded expect services to be registered on the system bus
    QDBusConnection systemBus = QDBusConnection::systemBus();
    if (!systemBus.registerService(LIPSTICK_DBUS_SERVICE_NAME)) {
        qWarning("Unable to register D-Bus service %s: %s", LIPSTICK_DBUS_SERVICE_NAME, systemBus.lastError().message().toUtf8().constData());
    }

    new HomeApplicationAdaptor(this);

    registerDBusObject(systemBus, LIPSTICK_DBUS_PATH, this);
    registerDBusObject(systemBus, LIPSTICK_DBUS_SCREENLOCK_PATH, screenLock);
    registerDBusObject(systemBus, LIPSTICK_DBUS_DEVICELOCK_PATH, deviceLock);
    registerDBusObject(systemBus, LIPSTICK_DBUS_SHUTDOWN_PATH, shutdownScreen);

    ScreenshotService *screenshotService = new ScreenshotService(this);
    new ScreenshotServiceAdaptor(screenshotService);
    QDBusConnection sessionBus = QDBusConnection::sessionBus();

    registerDBusObject(sessionBus, LIPSTICK_DBUS_SCREENSHOT_PATH, screenshotService);

    connect(this, SIGNAL(homeReady()), this, SLOT(sendStartupNotifications()));
}
コード例 #25
0
static void registerDBusObject(QDBusConnection &bus, const char *path, QObject *object)
{
    if (!bus.registerObject(path, object)) {
        qWarning("Unable to register object at path %s: %s", path, bus.lastError().message().toUtf8().constData());
    }
}
コード例 #26
0
ファイル: main.cpp プロジェクト: rohieb/StratumsphereTrayIcon
/**
 * Constructive constructor takes no parameters.
 */
StratumsphereTrayIcon::StratumsphereTrayIcon() : QObject(0), nam_(0),
  trayMenu_(0), trayIcon_(0), status_(UNDEFINED), lastStatus_(UNDEFINED),
  lastStatusBeforeUndefined_(UNDEFINED), timeoutTimer_(0),
  toggleNotifyAction_(0) {

  // set up network connection stuff
  nam_ = new QNetworkAccessManager(this);
  connect(nam_, SIGNAL(finished(QNetworkReply*)), this,
    SLOT(reply(QNetworkReply*)));

#ifdef HAVE_DBUS
  QDBusConnection conn = QDBusConnection::connectToBus(
    QDBusConnection::SystemBus, "org.freedesktop.NetworkManager");
  if(!conn.isConnected()) {
    qDebug() << "Oh. Connection failed:" << conn.lastError();
  } else {
    conn.connect("org.freedesktop.NetworkManager",
      "/org/freedesktop/NetworkManager", "org.freedesktop.NetworkManager",
      "StateChanged", "u", this, SLOT(networkStateChanged(uint)));
  }
#endif // HAVE_DBUS

  // set up icons
  int sizes[] = {16, 22, 32, 64, 128, 256};
  for(const int size : sizes) {
    openIcon_.addFile(QString(":/res/open-%1.png").arg(size));
    closedIcon_.addFile(QString(":/res/closed-%1.png").arg(size));
    undefinedIcon_.addFile(QString(":/res/undefined-%1.png").arg(size));
  }

  // set up menu
  trayMenu_ = new QMenu;

  toggleNotifyAction_ = new QAction(tr("Show &notifications"), this);
  toggleNotifyAction_->setCheckable(true);
  toggleNotifyAction_->setChecked(true);
  trayMenu_->addAction(toggleNotifyAction_);

  updateAction_ = new QAction(tr("&Update status"), trayMenu_);
  connect(updateAction_, SIGNAL(triggered()), this, SLOT(updateStatus()));
  trayMenu_->addAction(updateAction_);

  QAction * exitAction = new QAction(tr("&Exit"), trayMenu_);
  connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
  trayMenu_->addAction(exitAction);

  // set up tray icon
  trayIcon_ = new QSystemTrayIcon(this);
  trayIcon_->setContextMenu(trayMenu_);
  trayIcon_->setIcon(undefinedIcon_);
  trayIcon_->show();

  // fire up a timer to poll the status every n minutes
  startTimer(updateInterval_ * 1000);

  // also set up the timeout timer
  timeoutTimer_ = new QTimer(this);
  connect(timeoutTimer_, SIGNAL(timeout()), this, SLOT(timeout()));

  updateStatus();
}
コード例 #27
0
ファイル: shutdown.cpp プロジェクト: serghei/kde3-kdebase
void KSMServer::shutdown(KApplication::ShutdownConfirm confirm, KApplication::ShutdownType sdtype, KApplication::ShutdownMode sdmode)
{
    pendingShutdown.stop();
    if(dialogActive)
        return;
    if(state >= Shutdown) // already performing shutdown
        return;
    if(state != Idle) // performing startup
    {
        // perform shutdown as soon as startup is finished, in order to avoid saving partial session
        if(!pendingShutdown.isActive())
        {
            pendingShutdown.start(1000);
            pendingShutdown_confirm = confirm;
            pendingShutdown_sdtype = sdtype;
            pendingShutdown_sdmode = sdmode;
        }
        return;
    }

    KConfig *config = KGlobal::config();
    config->reparseConfiguration(); // config may have changed in the KControl module

    config->setGroup("General");
    bool logoutConfirmed = (confirm == KApplication::ShutdownConfirmYes) ? false : (confirm == KApplication::ShutdownConfirmNo)
                                                                                       ? true
                                                                                       : !config->readBoolEntry("confirmLogout", true);

    bool mayShutdown = (config->readBoolEntry("offerShutdown", true) && DM().canShutdown());
    bool maySuspend = config->readBoolEntry("offerSuspend", true);
    bool mayHibernate = config->readBoolEntry("offerHibernate", true);
    bool lockBeforeSuspendHibernate = config->readBoolEntry("lockBeforeSuspendHibernate", true);

    // FIXME At this moment we can't query for SuspendAllowed/HibernateAllowed because
    //       we haven't support for ConsoleKit yet

    // query upower for suspend/hibernate capability
    QDBusConnection dbusConnection;
    if(maySuspend || mayHibernate)
    {

        dbusConnection = QDBusConnection::addConnection(QDBusConnection::SystemBus);

        if(dbusConnection.isConnected())
        {

            // can suspend?
            if(maySuspend)
            {
#ifdef WITH_LOGIND
                QDBusMessage dbusMessage = QDBusMessage::methodCall(DBUS_UPOWER_SERVICE, DBUS_UPOWER_PATH, DBUS_UPOWER_INTERFACE, "CanSuspend");
#else
                QDBusMessage dbusMessage = QDBusMessage::methodCall(DBUS_UPOWER_SERVICE, DBUS_UPOWER_PATH, DBUS_PROPERTIES_INTERFACE, "Get");
                dbusMessage << QDBusData::fromString(DBUS_UPOWER_INTERFACE) << QDBusData::fromString("CanSuspend");
#endif

                QDBusMessage dbusReply = dbusConnection.sendWithReply(dbusMessage);

                if(dbusReply.type() == QDBusMessage::ReplyMessage && dbusReply.count() == 1)
#ifdef WITH_LOGIND
                    maySuspend = ("yes" == dbusReply[0].toString());
#else
                    maySuspend = dbusReply[0].toVariant().value.toBool();
#endif
                else
                {
                    maySuspend = false;
                    kdDebug() << "[dbus/upower] CanSuspend: " << dbusConnection.lastError().message() << "\n";
                }
            }

            // can hibernate?
            if(mayHibernate)
            {
#ifdef WITH_LOGIND
                QDBusMessage dbusMessage = QDBusMessage::methodCall(DBUS_UPOWER_SERVICE, DBUS_UPOWER_PATH, DBUS_UPOWER_INTERFACE, "CanHibernate");
#else
                QDBusMessage dbusMessage = QDBusMessage::methodCall(DBUS_UPOWER_SERVICE, DBUS_UPOWER_PATH, DBUS_PROPERTIES_INTERFACE, "Get");
                dbusMessage << QDBusData::fromString(DBUS_UPOWER_INTERFACE) << QDBusData::fromString("CanHibernate");
#endif

                QDBusMessage dbusReply = dbusConnection.sendWithReply(dbusMessage);

                if(dbusReply.type() == QDBusMessage::ReplyMessage && dbusReply.count() == 1)
#ifdef WITH_LOGIND
                    mayHibernate = ("yes" == dbusReply[0].toString());
#else
                    mayHibernate = dbusReply[0].toVariant().value.toBool();
#endif
                else
                {
                    mayHibernate = false;
                    kdDebug() << "[dbus/upower] CanHibernate: " << dbusConnection.lastError().message() << "\n";
                }
            }
コード例 #28
0
ファイル: timed.cpp プロジェクト: special/timed
void Timed::send_next_bootup_event(int value)
{
#if HAVE_DSME
  QDBusConnection dsme = QDBusConnection::systemBus() ;
  QString path = Maemo::Timed::objpath() ;
  QString iface = Maemo::Timed::interface() ;
  QString signal = "next_bootup_event" ;
  QDBusMessage m = QDBusMessage::createSignal(path, iface, signal) ;
  m << value ;
  if(dsme.send(m))
    log_info("signal %s(%d) sent", string_q_to_std(signal).c_str(), value) ;
  else
    log_error("Failed to send the signal %s(%d) on system bus: %s", string_q_to_std(signal).c_str(), value, dsme.lastError().message().toStdString().c_str()) ;
#endif
}
コード例 #29
0
ファイル: main.cpp プロジェクト: zhangjingpu/moonplayer
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    //check whether another MoonPlayer instance is running
#ifdef Q_OS_LINUX
    std::cout << "Checking another instance..." << std::endl;

    QDBusInterface iface("com.moonsoft.MoonPlayer", "/", "local.Playlist");
    if (iface.isValid())
    {
        if (argc == 1)
        {
            qDebug("Another instance is running. Quit.\n");
            return EXIT_FAILURE;
        }
        QString f = QString::fromUtf8(argv[1]);
        if (f.startsWith("http://"))
            iface.call("addUrl", f);
        else if (f.endsWith(".m3u") || f.endsWith("m3u8") || f.endsWith(".xspf")) //playlist
            iface.call("addList", f);
        else
            iface.call("addFileAndPlay", f.section('/', -1), f);
        return EXIT_SUCCESS;
    }
    QDBusConnection conn = QDBusConnection::sessionBus();
    if (!conn.registerService("com.moonsoft.MoonPlayer"))
    {
        qDebug() << conn.lastError().message();
        return EXIT_FAILURE;
    }
#endif

    //init
#ifdef Q_OS_WIN
    Settings::path = QString(argv[0]).section('\\', 0, -2);
#endif
    std::cout << "Initialize settings..." << std::endl;
    Settings::initSettings();

    std::cout << "Initialize API for Python..." << std::endl;
    initAPI();

    //translate moonplayer
    std::cout << "Initialize language support..." << std::endl;
    QTranslator translator;
    QDir path(Settings::path);
    translator.load(path.filePath("moonplayer_" + QLocale::system().name()));
    a.installTranslator(&translator);

    Player w;
    w.show();

    if (argc > 1)
    {
        std::cout << "Loading file..." << std::endl;
        QTextCodec* codec = QTextCodec::codecForLocale();
        QString file = codec->toUnicode(argv[1]);
        if (file.startsWith("http://"))
            w.playlist->addUrl(file);
        else if (file.endsWith(".m3u") || file.endsWith("m3u8") || file.endsWith(".xspf")) //playlist
            w.playlist->addList(file);
        else
            w.playlist->addFileAndPlay(file.section('/', -1), file);
    }
    a.exec();
    Py_Finalize();
    return 0;
}
コード例 #30
0
ファイル: homeapplication.cpp プロジェクト: kaltsi/lipstick
HomeApplication::HomeApplication(int &argc, char **argv, const QString &qmlPath)
    : QGuiApplication(argc, argv)
    , _mainWindowInstance(0)
    , _qmlPath(qmlPath)
    , originalSigIntHandler(signal(SIGINT, quitSignalHandler))
    , originalSigTermHandler(signal(SIGTERM, quitSignalHandler))
{
    setApplicationName("Lipstick");
    // TODO: autogenerate this from tags
    setApplicationVersion(VERSION);

    QTranslator *engineeringEnglish = new QTranslator(this);
    engineeringEnglish->load("lipstick_eng_en", "/usr/share/translations");
    installTranslator(engineeringEnglish);
    QTranslator *translator = new QTranslator(this);
    translator->load(QLocale(), "lipstick", "-", "/usr/share/translations");
    installTranslator(translator);

    // launch a timer for sending a dbus-signal upstart when basic construct is done
    QTimer::singleShot(0, this, SLOT(sendStartupNotifications()));

    // Initialize the QML engine
    qmlEngine = new QQmlEngine(this);

    // Initialize the notification manager
    NotificationManager::instance();
    new NotificationPreviewPresenter(this);
    new NotificationFeedbackPlayer(this);

    // Create screen lock logic - not parented to "this" since destruction happens too late in that case
    screenLock = new ScreenLock;
    LipstickSettings::instance()->setScreenLock(screenLock);
    new ScreenLockAdaptor(screenLock);

    volumeControl = new VolumeControl;
    batteryNotifier = new BatteryNotifier(this);
    usbModeSelector = new USBModeSelector(this);
    connect(usbModeSelector, SIGNAL(dialogShown()), screenLock, SLOT(unlockScreen()));
    shutdownScreen = new ShutdownScreen(this);
    connectionSelector = new ConnectionSelector(this);

    // MCE expects the service to be registered on the system bus
    static const char *SCREENLOCK_DBUS_SERVICE = "org.nemomobile.lipstick";
    static const char *SCREENLOCK_DBUS_PATH = "/screenlock";
    QDBusConnection systemBus = QDBusConnection::systemBus();
    if (!systemBus.registerService(SCREENLOCK_DBUS_SERVICE)) {
        qWarning("Unable to register screen lock D-Bus service %s: %s", SCREENLOCK_DBUS_SERVICE, systemBus.lastError().message().toUtf8().constData());
    }
    if (!systemBus.registerObject(SCREENLOCK_DBUS_PATH, screenLock)) {
        qWarning("Unable to register screen lock object at path %s: %s", SCREENLOCK_DBUS_PATH, systemBus.lastError().message().toUtf8().constData());
    }
}