From 279a060265d9cac9762a4b2c8cf250822b63f74e Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Fri, 28 May 2004 04:20:30 +0000 Subject: [PATCH] - idle in a C module, auto away / xa feature is back - no need to store .mo files : they are now created by make --- Makefile | 4 +++ Messages/fr/LC_MESSAGES/gajim.mo | Bin 8794 -> 0 bytes common/idle.cpp | 49 ++++++++++++++++++++++++++++ common/sleepy.py | 54 +++++++------------------------ plugins/gtkgui/config.py | 8 ++--- plugins/gtkgui/gtkgui.py | 48 +++++++++++++++------------ setup.py | 11 +++++++ 7 files changed, 106 insertions(+), 68 deletions(-) create mode 100644 Makefile delete mode 100644 Messages/fr/LC_MESSAGES/gajim.mo create mode 100644 common/idle.cpp create mode 100644 setup.py diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..6f079def8 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +all: + python setup.py build_ext -i + mv idle.so common/ + msgfmt Messages/fr/LC_MESSAGES/gajim.po -o Messages/fr/LC_MESSAGES/gajim.mo diff --git a/Messages/fr/LC_MESSAGES/gajim.mo b/Messages/fr/LC_MESSAGES/gajim.mo deleted file mode 100644 index 1dbb245679f9420266577e9007244bfbb1f54869..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8794 zcmb7|du(M_b%!@0kYFASp(UXWWrxhfNt5gG%w&>@=aG19PsYQH$FV(=2PDq9_ikUG znS0NhlYp=cb+Uxl5F1_$GhU-(v709y}8uLwf%{8d@%6i@KVZO2=BiJUq|^5;m^b8;l=Pf@U`$o_Ik;rZi% zpM=u?vw>d>diu??AQt z2Glq!Q1kh7sCE1{R6qX;wNC#A`{92>wcmo1OW$o!^>#r_YW6}@Hb=tqd!Xjogz6`O z((`^O{XYg}|KEVp^Es&g{s!`AUgAgXUxAwUe?jSa!P~0(7r|eqyaf)x5x4_pa0~n` zcnH1#uZC}9Q0o9ok3x<2d8l?z!LipE z^E8wlUt#g2Umt@?pUa@uWh+#_yP(=14xENs@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WS5Cv;krixt-U?M3JsB;L-72eP9%QGbYv*Ke7UNp>3LBLGXSh>J?N)PYX23Fr zji4mkKj0H_-3f_Ze6F21W|x~2xTA9HY;|$hXW1*uiSHd{xYfWR*`{TcZTsb!WanuA zG#aIg+f_DHW<%yM4waVkkratyTl7a^2jW+qNVZu`z0X&-a&f#YG(v&#wT(nBLjH>!VOoe!9dF@;>c7I`nxttG#ZhaPX6V zttRG510w=Zn_z;)6}L&T7PM)vU>GS1{+rmr` zKMvkmSjHZ&oH5?g_#C#p6+++-mg4qHb2nbT{~g;5a1&)BYST;C8zXR1#<#>^({ab zR9Z-ve#)y5kT-t~Fw?S&{_1<>S>nU!hW?dotq!0C^Iryd&{6zLGh@%`WC-hz1=Z%DmuYKs~vxwdCG$&27KVEzBQyy!5+kD*VXSst-Rx8}mqjaIYs|-N zv8d!9V*27<`#K?*%d7nHZr8p`M(ED1m8*}EF8?}YFtQc?cg1$&3?OphdzEdf!;1OQ zpI-!@!WlvfX#lMhhRI2pO7B}mX?6>5+xT=fR|t>8hsmbO;puAS)eO;8oB4kMyUN{n diff --git a/common/idle.cpp b/common/idle.cpp new file mode 100644 index 000000000..6cf5f970f --- /dev/null +++ b/common/idle.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include + +#include + +static PyObject * idle_init(PyObject *self, PyObject *args) { + gtk_init (NULL, NULL); + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject * idle_getIdleSec(PyObject *self, PyObject *args) { + static XScreenSaverInfo *mit_info = NULL; + int idle_time, event_base, error_base; + + gtk_init (NULL, NULL); + if (XScreenSaverQueryExtension(GDK_DISPLAY(), &event_base, &error_base)) { + if (mit_info == NULL) { + mit_info = XScreenSaverAllocInfo(); + } + XScreenSaverQueryInfo(GDK_DISPLAY(), GDK_ROOT_WINDOW(), mit_info); + idle_time = (mit_info->idle) / 1000; + } + else + idle_time = 0; + return Py_BuildValue("i", idle_time); +} + +static PyObject * idle_close(PyObject *self, PyObject *args) { + gtk_main_quit (); + Py_INCREF(Py_None); + return Py_None; +} + +static PyMethodDef idleMethods[] = { + {"init", idle_init, METH_VARARGS, "init gtk"}, + {"getIdleSec", idle_getIdleSec, METH_VARARGS, "Give the idle time in secondes"}, + {"close", idle_close, METH_VARARGS, "close gtk"}, + {NULL, NULL, 0, NULL} +}; + +PyMODINIT_FUNC +initidle(void) +{ + (void) Py_InitModule("idle", idleMethods); +} diff --git a/common/sleepy.py b/common/sleepy.py index e5e58442c..23bf19ab3 100644 --- a/common/sleepy.py +++ b/common/sleepy.py @@ -2,6 +2,7 @@ """A Quick class to tell if theres any activity on your machine""" import time +import idle from string import find, lower @@ -16,45 +17,26 @@ class Sleepy: def __init__(self, interval1 = 60, interval2 = 120, devices = ['keyboard', 'mouse', 'ts'] ): - self.devices = devices - self.time_marker = time.time() - self.interval = self.interval_orig = interval1 - self.interval_orig2 = interval2 - self.last_proc_vals = {} - for dev in self.devices: self.last_proc_vals[dev] = 0 - + self.interval1 = interval1 + self.interval2 = interval2 self.state = STATE_AWAKE ## assume were awake to stake with try: - self.proc_int_fh = open("/proc/interrupts",'r') + idle.init() except: NOT_SUPPORTED = 1 self.state = STATE_UNKNOWN - self.proc_int_fh.close() - def poll(self): if NOT_SUPPORTED: return -1 now = time.time() - changed = 0 ## figure out if we have recieved interupts - for dev in self.devices: ## any of the selected devices - proc_val = self._read_proc(dev) - changed = changed or ( self.last_proc_vals[dev] != proc_val ) - self.last_proc_vals[dev] = proc_val - - if changed: - ## we are awake :) - self.time_marker = time.time() ## reset marker - self.state = STATE_AWAKE - self.interval = self.interval_orig - else: - if (now - self.time_marker >= self.interval): - ## we are asleep - if self.state == STATE_AWAKE: - self.state = STATE_AWAY - self.interval = self.interval_orig2 #second interval - else: - self.state = STATE_XAWAY + idleTime = idle.getIdleSec() + if idleTime > self.interval2: + self.state = STATE_XAWAY + elif idleTime > self.interval1: + self.state = STATE_AWAY + else: + self.state = STATE_AWAKE return 1 def getState(self): @@ -63,20 +45,8 @@ class Sleepy: def setState(self,val): self.state = val - def _read_proc(self, device = 'mouse'): - proc_int_fh = open("/proc/interrupts",'r') - info = proc_int_fh.readlines() - ## ignore first line - for line in info[1:]: - cols = line.strip().split() - if (find(lower(cols[-1]),device) != -1): - proc_int_fh.close() - return int(cols[1]) - proc_int_fh.close() - return 1 - if __name__ == '__main__': s = Sleepy(10) while s.poll(): print "state is %s" % s.getState() - time.sleep(10) + time.sleep(5) diff --git a/plugins/gtkgui/config.py b/plugins/gtkgui/config.py index 2653a9384..c4e54c9dd 100644 --- a/plugins/gtkgui/config.py +++ b/plugins/gtkgui/config.py @@ -23,6 +23,7 @@ import gtk from gtk import TRUE, FALSE import gtk.glade,gobject import os,string +import common.sleepy from common import i18n _ = i18n._ APP = i18n.APP @@ -216,7 +217,8 @@ class preference_Window: self.plugin.config['autoxatime'] = axt if self.plugin.sleeper: self.plugin.sleeper = common.sleepy.Sleepy(\ - self.plugin['autoawaytime']*60, self.plugin['autoxatime']*60) + self.plugin.config['autoawaytime']*60, \ + self.plugin.config['autoxatime']*60) self.plugin.send('CONFIG', None, ('GtkGui', self.plugin.config)) self.plugin.roster.draw_roster() @@ -306,28 +308,24 @@ class preference_Window: if self.plugin.config.has_key('autoaway'): st = self.plugin.config['autoaway'] self.chk_autoaway.set_active(st) - self.chk_autoaway.set_sensitive(0) #Autoawaytime st = 10 if self.plugin.config.has_key('autoawaytime'): st = self.plugin.config['autoawaytime'] self.spin_autoawaytime.set_value(st) - self.spin_autoawaytime.set_sensitive(0) #Autoxa st = 1 if self.plugin.config.has_key('autoxa'): st = self.plugin.config['autoxa'] self.chk_autoxa.set_active(st) - self.chk_autoxa.set_sensitive(0) #Autoxatime st = 20 if self.plugin.config.has_key('autoxatime'): st = self.plugin.config['autoxatime'] self.spin_autoxatime.set_value(st) - self.spin_autoxatime.set_sensitive(0) self.xml.signal_connect('gtk_widget_destroy', self.delete_event) self.xml.signal_connect('on_but_col_clicked', \ diff --git a/plugins/gtkgui/gtkgui.py b/plugins/gtkgui/gtkgui.py index d1ec68d9f..f42faa7db 100644 --- a/plugins/gtkgui/gtkgui.py +++ b/plugins/gtkgui/gtkgui.py @@ -785,6 +785,8 @@ class roster_Window: else: txt = status self.plugin.send('STATUS', account, (status, txt)) + if status == 'online': + self.plugin.sleeper_state[account] = 1 def on_optionmenu_changed(self, widget): """When we change our status""" @@ -805,6 +807,8 @@ class roster_Window: return for acct in accounts: self.plugin.send('STATUS', acct, (status, txt)) + if status == 'online': + self.plugin.sleeper_state[acct] = 1 def set_optionmenu(self): #table to change index in plugin.connected to index in optionmenu @@ -833,9 +837,10 @@ class roster_Window: for user in luser: self.chg_user_status(user, 'offline', 'Disconnected', account) elif self.plugin.connected[account] == 0: - self.plugin.sleeper = None#common.sleepy.Sleepy(\ - #self.plugin.config['autoawaytime']*60, \ - #self.plugin.config['autoxatime']*60) + if (self.plugin.config['autoaway'] or self.plugin.config['autoxa']): + self.plugin.sleeper = common.sleepy.Sleepy(\ + self.plugin.config['autoawaytime']*60, \ + self.plugin.config['autoxatime']*60) self.plugin.connected[account] = statuss.index(status) self.set_optionmenu() @@ -1349,25 +1354,25 @@ class plugin: def read_sleepy(self): """Check if we are idle""" - if self.sleeper and (self.config['autoaway'] or self.config['autoxa'])\ - and (self.roster.optionmenu.get_history()==0 or \ - self.sleeper_state!=common.sleepy.STATE_AWAKE): + if self.sleeper: self.sleeper.poll() state = self.sleeper.getState() - if state != self.sleeper_state: - if state == common.sleepy.STATE_AWAKE: - #we go online - self.roster.optionmenu.set_history(0) - self.send('STATUS', None, ('online', '')) - elif state == common.sleepy.STATE_AWAY and self.config['autoaway']: - #we go away - self.roster.optionmenu.set_history(1) - self.send('STATUS', None, ('away', 'auto away (idle)')) - elif state == common.sleepy.STATE_XAWAY and self.config['autoxa']: - #we go extended away - self.roster.optionmenu.set_history(2) - self.send('STATUS',('xa', 'auto away (idel)')) - self.sleeper_state = state + for account in self.accounts.keys(): + if self.sleeper_state[account]: + if state == common.sleepy.STATE_AWAKE and \ + self.connected[account] > 1: + #we go online + self.send('STATUS', account, ('online', '')) + elif state == common.sleepy.STATE_AWAY and \ + self.connected[account] == 1 and \ + self.config['autoaway']: + #we go away + self.send('STATUS', account, ('away', 'auto away (idle)')) + elif state == common.sleepy.STATE_XAWAY and \ + self.connected[account] == 2 and \ + self.config['autoxa']: + #we go extended away + self.send('STATUS', account, ('xa', 'auto away (idle)')) return 1 def __init__(self, quIN, quOUT): @@ -1392,6 +1397,7 @@ class plugin: self.queues = {} self.connected = {} self.nicks = {} + self.sleeper_state = {} #whether we pass auto away / xa or not for a in self.accounts.keys(): self.windows[a] = {} self.windows[a]['infos'] = {} @@ -1399,11 +1405,11 @@ class plugin: self.queues[a] = {} self.connected[a] = 0 self.nicks[a] = self.accounts[a]['name'] + self.sleeper_state[a] = 0 self.roster = roster_Window(self) gtk.timeout_add(100, self.read_queue) gtk.timeout_add(1000, self.read_sleepy) self.sleeper = None - self.sleeper_state = None gtk.main() gtk.threads_leave() diff --git a/setup.py b/setup.py new file mode 100644 index 000000000..ecf4c94c0 --- /dev/null +++ b/setup.py @@ -0,0 +1,11 @@ +from distutils.core import setup, Extension + +module1 = Extension( 'idle', + sources = ['common/idle.cpp'], +# extra_compile_args = ['-W'], + libraries = ['gtk-x11-2.0','gdk-x11-2.0','glib-2.0','X11','Xext','Xss','atk-1.0'], + library_dirs = ['/usr/X11R6/lib'], + include_dirs = ['/usr/include/gtk-2.0', '/usr/include/glib-2.0','/usr/lib/gtk-2.0/include','/usr/lib/glib-2.0/include','/usr/include/pango-1.0','/usr/include/atk-1.0'] + ) + +setup (name = 'idle', version = '1.0', description = 'interface to X11/scrnserver.h', ext_modules = [module1])