Пример #1
0
XqueryIdle(char *display)
{
        int first_event, first_error;
        Time IdleTime;

        (void) signal (SIGALRM, abortOpen);
        (void) alarm ((unsigned) 10);
        if (!setjmp (openAbort)) {
                if (!(dpy= XOpenDisplay(display))) {
                        syslog(LOG_ERR, "Cannot open display %s", display);
                        return(-1);
                }
                if (XidleQueryExtension(dpy, &first_event, &first_error)) {
                        if (!XGetIdleTime(dpy, &IdleTime)) {
                                syslog(LOG_ERR, "%s: unable to get idle time", display);
                                return(-1);
                        }
                }
                else {
                        syslog(LOG_ERR, "%s: Xidle extension not loaded", display);
                        return(-1);
                }
                XCloseDisplay(dpy);
        }
        else {
                syslog(LOG_ERR, "%s: server grabbed for over 10 seconds", display);
                return(-1);
        }
        (void) signal (SIGALRM, SIG_DFL);
        (void) alarm ((unsigned) 0);

        IdleTime /= 1000;
        return((IdleTime + 30) / 60);
}
Пример #2
0
Kopete::Away::Away() : QObject( kapp , "Kopete::Away")
{
    int dummy = 0;
    dummy = dummy; // shut up

    d = new KopeteAwayPrivate;

    // Set up the away messages
    d->awayMessage = QString::null;
    d->autoAwayMessage = QString::null;
    d->useAutoAwayMessage = false;
    d->globalAway = false;
    d->autoaway = false;
    d->useAutoAway = true;

    // Empty the list
    d->awayMessageList.clear();

    // set the XAutoLock info
#ifdef Q_WS_X11
    Display *dsp = qt_xdisplay();
#endif
    d->mouse_x = d->mouse_y=0;
    d->mouse_mask = 0;
#ifdef Q_WS_X11
    d->root = DefaultRootWindow (dsp);
    d->screen = ScreenOfDisplay (dsp, DefaultScreen (dsp));
#endif
    d->useXidle = false;
    d->useMit = false;
#ifdef HasXidle
    d->useXidle = XidleQueryExtension(qt_xdisplay(), &dummy, &dummy);
#endif
#ifdef HasScreenSaver
    if(!d->useXidle)
        d->useMit = XScreenSaverQueryExtension(qt_xdisplay(), &dummy, &dummy);
#endif
#ifdef Q_WS_X11
    d->xIdleTime = 0;
#endif
    kdDebug(14010) << k_funcinfo << "Idle detection methods:" << endl;
    kdDebug(14010) << k_funcinfo << "\tKScreensaverIface::isBlanked()" << endl;
#ifdef Q_WS_X11
    kdDebug(14010) << k_funcinfo << "\tX11 XQueryPointer()" << endl;
#endif
    if (d->useXidle)
    {
        kdDebug(14010) << k_funcinfo << "\tX11 Xidle extension" << endl;
    }
    if (d->useMit)
    {
        kdDebug(14010) << k_funcinfo << "\tX11 MIT Screensaver extension" << endl;
    }


    load();
    KSettings::Dispatcher::self()->registerInstance( KGlobal::instance(), this, SLOT( load() ) );
    // Set up the config object
    KConfig *config = KGlobal::config();
    /* Load the saved away messages */
    config->setGroup("Away Messages");

    // Away Messages
    if(config->hasKey("Messages"))
    {
        d->awayMessageList = config->readListEntry("Messages");
    }
    else if(config->hasKey("Titles"))  // Old config format
    {
        QStringList titles = config->readListEntry("Titles");  // Get the titles
        for(QStringList::iterator i = titles.begin(); i != titles.end(); ++i)
        {
            d->awayMessageList.append( config->readEntry(*i) ); // And add it to the list
        }

        /* Save this list to disk */
        save();
    }
    else
    {
        d->awayMessageList.append( i18n( "Sorry, I am busy right now" ) );
        d->awayMessageList.append( i18n( "I am gone right now, but I will be back later" ) );

        /* Save this list to disk */
        save();
    }

    // Auto away message
    if(config->hasKey("AutoAwayMessage"))
    {
        d->autoAwayMessage = config->readEntry("AutoAwayMessage");
    }
    else
    {
        d->autoAwayMessage = i18n( "I am gone right now, but I will be back later" );

        // Save the default auto away message to disk
        save();
    }

    // init the timer
    d->timer = new QTimer(this, "AwayTimer");
    connect(d->timer, SIGNAL(timeout()), this, SLOT(slotTimerTimeout()));
    d->timer->start(4000);

    //init the time and other
    setActive();
}