2013-04-07 09:16:23 -03:00
|
|
|
#! /usr/bin/python3
|
2013-03-31 14:31:33 -03:00
|
|
|
# -*- coding:utf-8 -*-
|
2013-02-02 10:02:18 -03:00
|
|
|
|
2013-02-22 12:43:52 -03:00
|
|
|
from gi.repository import Gtk, GObject
|
2013-09-26 13:02:07 -03:00
|
|
|
from subprocess import call
|
2013-07-13 05:34:44 -04:00
|
|
|
from time import sleep
|
2013-09-26 13:02:07 -03:00
|
|
|
import threading
|
|
|
|
from pamac import common, transaction
|
|
|
|
|
|
|
|
GObject.threads_init()
|
2013-02-11 11:45:24 -03:00
|
|
|
|
2013-03-31 14:31:33 -03:00
|
|
|
# i18n
|
|
|
|
import gettext
|
|
|
|
gettext.bindtextdomain('pamac', '/usr/share/locale')
|
|
|
|
gettext.textdomain('pamac')
|
|
|
|
_ = gettext.gettext
|
|
|
|
|
2013-09-17 03:06:32 -03:00
|
|
|
update_icon = '/usr/share/pamac/icons/24x24/status/pamac-update.png'
|
2013-03-31 14:31:33 -03:00
|
|
|
update_info = _('{number} available updates')
|
|
|
|
one_update_info = _('1 available update')
|
2013-09-17 03:06:32 -03:00
|
|
|
noupdate_icon = '/usr/share/pamac/icons/24x24/status/pamac-tray.png'
|
2013-03-31 14:31:33 -03:00
|
|
|
noupdate_info = _('Your system is up-to-date')
|
2013-07-19 10:14:09 -04:00
|
|
|
icon = noupdate_icon
|
|
|
|
info = noupdate_info
|
2013-03-18 07:07:58 -03:00
|
|
|
|
2013-02-10 11:59:53 -03:00
|
|
|
class Tray:
|
2013-02-16 13:27:46 -03:00
|
|
|
def __init__(self):
|
2013-02-10 11:59:53 -03:00
|
|
|
self.statusIcon = Gtk.StatusIcon()
|
2013-09-26 13:02:07 -03:00
|
|
|
self.statusIcon.set_visible(True)
|
2013-07-13 05:34:44 -04:00
|
|
|
|
2013-07-19 10:14:09 -04:00
|
|
|
self.menu = Gtk.Menu()
|
|
|
|
self.menuItem = Gtk.ImageMenuItem(_('Update Manager'))
|
2013-09-22 05:02:23 -03:00
|
|
|
self.menuItem.set_image(Gtk.Image.new_from_file('/usr/share/pamac/icons/16x16/apps/pamac-updater.png'))
|
2013-07-19 10:14:09 -04:00
|
|
|
self.menuItem.connect('activate', self.execute_update, self.statusIcon)
|
|
|
|
self.menu.append(self.menuItem)
|
|
|
|
self.menuItem = Gtk.ImageMenuItem(_('Package Manager'))
|
2013-09-22 05:02:23 -03:00
|
|
|
self.menuItem.set_image(Gtk.Image.new_from_file('/usr/share/pamac/icons/16x16/apps/pamac.png'))
|
2013-07-19 10:14:09 -04:00
|
|
|
self.menuItem.connect('activate', self.execute_manager, self.statusIcon)
|
|
|
|
self.menu.append(self.menuItem)
|
|
|
|
self.menuItem = Gtk.ImageMenuItem(_('Quit'))
|
2013-09-22 05:02:23 -03:00
|
|
|
self.menuItem.set_image(Gtk.Image.new_from_file('/usr/share/pamac/icons/16x16/apps/exit.png'))
|
2013-07-19 10:14:09 -04:00
|
|
|
self.menuItem.connect('activate', self.quit_tray, self.statusIcon)
|
|
|
|
self.menu.append(self.menuItem)
|
|
|
|
|
|
|
|
self.statusIcon.connect('popup-menu', self.popup_menu_cb, self.menu)
|
|
|
|
self.statusIcon.connect('activate', self.activate_cb)
|
|
|
|
|
|
|
|
def execute_update(self, widget, event, data = None):
|
2013-09-26 13:02:07 -03:00
|
|
|
call(['/usr/bin/pamac-updater'])
|
2013-07-19 10:14:09 -04:00
|
|
|
|
|
|
|
def execute_manager(self, widget, event, data = None):
|
2013-09-26 13:02:07 -03:00
|
|
|
call(['/usr/bin/pamac-manager'])
|
2013-07-19 10:14:09 -04:00
|
|
|
|
|
|
|
def quit_tray(self, widget, data = None):
|
2013-09-26 13:02:07 -03:00
|
|
|
t1.shutdown()
|
|
|
|
t2.shutdown()
|
2013-07-19 10:14:09 -04:00
|
|
|
Gtk.main_quit()
|
|
|
|
|
|
|
|
def popup_menu_cb(self, widget, button, time, data = None):
|
|
|
|
if button == 3:
|
|
|
|
if data:
|
|
|
|
data.show_all()
|
|
|
|
data.popup(None, None, Gtk.StatusIcon.position_menu, self.statusIcon, 3, time)
|
2013-02-10 11:59:53 -03:00
|
|
|
|
2013-03-18 07:07:58 -03:00
|
|
|
def activate_cb(self, widget, data = None):
|
2013-07-13 05:34:44 -04:00
|
|
|
if icon == update_icon:
|
2013-09-26 13:02:07 -03:00
|
|
|
call(['/usr/bin/pamac-updater'])
|
2013-03-18 07:07:58 -03:00
|
|
|
|
2013-02-16 13:27:46 -03:00
|
|
|
def update_icon(self, icon, info):
|
2013-09-26 13:02:07 -03:00
|
|
|
GObject.idle_add(self.statusIcon.set_from_file, icon)
|
|
|
|
GObject.idle_add(self.statusIcon.set_tooltip_markup, info)
|
2013-02-10 11:59:53 -03:00
|
|
|
|
2013-07-13 05:34:44 -04:00
|
|
|
def set_visible(self, boolean):
|
|
|
|
self.statusIcon.set_visible(boolean)
|
|
|
|
|
2013-09-26 13:02:07 -03:00
|
|
|
class PeriodicRefresh(threading.Thread):
|
2013-02-16 13:27:46 -03:00
|
|
|
"""Thread that executes a task every N seconds"""
|
|
|
|
def __init__(self):
|
|
|
|
threading.Thread.__init__(self)
|
|
|
|
self._finished = threading.Event()
|
2013-02-23 13:02:53 -03:00
|
|
|
self._interval = 3600*3
|
2013-02-16 13:27:46 -03:00
|
|
|
|
|
|
|
def setInterval(self, interval):
|
|
|
|
"""Set the number of seconds we sleep between executing our task"""
|
|
|
|
self._interval = interval
|
|
|
|
|
|
|
|
def shutdown(self):
|
|
|
|
"""Stop this thread"""
|
|
|
|
self._finished.set()
|
|
|
|
|
|
|
|
def run(self):
|
2013-09-26 13:02:07 -03:00
|
|
|
while True:
|
2013-02-16 13:27:46 -03:00
|
|
|
if self._finished.isSet():
|
|
|
|
return
|
2013-09-26 13:02:07 -03:00
|
|
|
call(['/usr/bin/pamac-refresh'])
|
2013-02-16 13:27:46 -03:00
|
|
|
self._finished.wait(self._interval)
|
|
|
|
|
2013-09-26 13:02:07 -03:00
|
|
|
class PeriodicCheck(threading.Thread):
|
|
|
|
"""Thread that executes a task every N seconds"""
|
|
|
|
def __init__(self):
|
|
|
|
threading.Thread.__init__(self)
|
|
|
|
self._finished = threading.Event()
|
|
|
|
self._interval = 1
|
|
|
|
self.trans = transaction.Transaction()
|
|
|
|
|
|
|
|
def setInterval(self, interval):
|
|
|
|
"""Set the number of seconds we sleep between executing our task"""
|
|
|
|
self._interval = interval
|
|
|
|
|
|
|
|
def shutdown(self):
|
|
|
|
"""Stop this thread"""
|
|
|
|
self._finished.set()
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
pid_file = True
|
|
|
|
while True:
|
|
|
|
if self._finished.isSet():
|
|
|
|
return
|
2013-10-02 10:20:14 -03:00
|
|
|
elif common.pid_file_exists():
|
|
|
|
if not pid_file:
|
|
|
|
pid_file = True
|
|
|
|
self._finished.wait(self._interval)
|
2013-09-26 13:02:07 -03:00
|
|
|
elif pid_file:
|
|
|
|
self.trans.update_dbs()
|
|
|
|
set_icon(len(self.trans.get_updates()[1]))
|
|
|
|
pid_file = False
|
|
|
|
else:
|
|
|
|
self._finished.wait(self._interval)
|
2013-02-16 13:27:46 -03:00
|
|
|
|
2013-02-23 13:02:53 -03:00
|
|
|
def set_icon(updates):
|
2013-03-18 07:07:58 -03:00
|
|
|
global icon
|
|
|
|
global info
|
2013-02-10 11:59:53 -03:00
|
|
|
if updates:
|
2013-03-18 07:07:58 -03:00
|
|
|
icon = update_icon
|
2013-03-31 14:31:33 -03:00
|
|
|
if int(updates) == 1:
|
|
|
|
info = one_update_info
|
|
|
|
else:
|
|
|
|
info = update_info.format(number = updates)
|
2013-07-13 05:34:44 -04:00
|
|
|
if not common.pid_file_exists():
|
2013-09-26 13:02:07 -03:00
|
|
|
call(['notify-send', '-i', '/usr/share/pamac/icons/32x32/apps/pamac-updater.png', '-u', 'normal', _('Update Manager'), info])
|
2013-02-10 11:59:53 -03:00
|
|
|
else:
|
2013-03-18 07:07:58 -03:00
|
|
|
icon = noupdate_icon
|
|
|
|
info = noupdate_info
|
2013-02-22 12:43:52 -03:00
|
|
|
print(info)
|
2013-02-16 13:27:46 -03:00
|
|
|
tray.update_icon(icon, info)
|
2013-09-26 13:02:07 -03:00
|
|
|
return False
|
2013-02-11 11:45:24 -03:00
|
|
|
|
2013-02-22 12:43:52 -03:00
|
|
|
tray = Tray()
|
2013-09-26 13:02:07 -03:00
|
|
|
t1 = PeriodicRefresh()
|
|
|
|
t1.start()
|
|
|
|
t2 = PeriodicCheck()
|
|
|
|
t2.start()
|
2013-02-22 12:43:52 -03:00
|
|
|
Gtk.main()
|