Commit 28b8db6a authored by Kristof Vansant's avatar Kristof Vansant

make it easier to later replace the gnome specific icon

parent 832c10be
......@@ -29,6 +29,8 @@ gettext.bindtextdomain(domain)
gettext.textdomain(domain)
_ = gettext.gettext
# TODO: remove this class and let mainWindow generate this dialogbox
class AddWindow:
def __init__(self, parent):
self.ParentClass = parent
......@@ -42,8 +44,7 @@ class AddWindow:
self.xml.signal_connect("on_select_cancel_button_clicked", self.on_cancel_button_clicked)
self.xml.signal_connect("on_select_ok_button_clicked", self.on_ok_button_clicked)
# TODO: make them add themself remove from glade
self.at_radio = self.xml.get_widget("at_radio")
self.crontab_radio = self.xml.get_widget("crontab_radio")
self.crontab_radio.set_active (gtk.TRUE)
......@@ -58,9 +59,7 @@ class AddWindow:
def on_ok_button_clicked (self, *args):
self.widget.hide()
# TODO: make them add themself
if self.crontab_radio.get_active ():
# TODO: necessary?
self.ParentClass.editor = self.ParentClass.crontab_editor
self.ParentClass.editor.showadd (self.ParentClass.edit_mode)
else:
......
......@@ -47,6 +47,9 @@ class At:
self.root = root
self.set_rights(user,uid,gid)
# TODO: shouldn't be gnome specific
self.defaultIcon = "/usr/share/icons/gnome/48x48/mimetypes/gnome-mime-application.png"
self.atRecordRegex = re.compile('([^\s]+)\s([^\s]+)\s([^\s]+)\s([^\s]+)\s([^\s]+)')
self.atRecordRegexAdd = re.compile('([^\s]+)\s([^\s]+)\s')
self.atRecordRegexAdded = re.compile('[^\s]+\s([0-9]+)\sat')
......@@ -60,6 +63,7 @@ class At:
def get_type (self):
return "at"
def parse (self, line, output = 0):
if output == 0:
if len (line) > 1 and line[0] != '#':
......@@ -99,7 +103,7 @@ class At:
return job_id
return False
# TODO: throw exception
def checkfield (self, runat):
#TODO: fix bug $0:19 2004-12-8$ not valid by regexp
......@@ -194,6 +198,7 @@ class At:
return False, "other"
return True, "ok"
#TODO merge code of append and update
def append (self, runat, command, title, icon):
......@@ -214,7 +219,6 @@ class At:
temp = None
# TODO: get this info
if self.root == 1:
if self.user != "root":
#changes the ownership
......@@ -252,7 +256,6 @@ class At:
tmp.write (command + "\n")
tmp.close ()
# TODO: get this info
if self.root == 1:
if self.user != "root":
#changes the ownership
......@@ -273,7 +276,6 @@ class At:
commands.getoutput(execute)
def read (self):
data = []
......@@ -287,15 +289,7 @@ class At:
if array_or_false != False:
(job_id, date, time, class_id, user, lines, title, icon, prelen, dangerous) = array_or_false
#if icon != None:
# try:
# icon_pix = gtk.gdk.pixbuf_new_from_file_at_size (icon, 21, 21)
#
# except:
# icon_pix = None
#else:
# icon_pix = None
preview = self.__make_preview__ (lines, prelen)
if dangerous == 1:
preview = "DANGEROUS PARSE: " + preview
......@@ -319,8 +313,7 @@ class At:
return data
def __prepare_script__ (self, script):
# It looks like at prepends a bunch of stuff to each script
......@@ -357,8 +350,8 @@ class At:
prelen = prelen + len(icon) + 6
else:
# TODO: shouldn't be gnome specific
icon = "/usr/share/icons/gnome/48x48/mimetypes/gnome-mime-application.png"
icon = self.defaultIcon
else:
#print "method 2"
dangerous = 1
......@@ -388,8 +381,7 @@ class At:
prelen = prelen + len(icon) + 6
else:
# TODO: shouldn't be gnome specific
icon = "/usr/share/icons/gnome/48x48/mimetypes/gnome-mime-application.png"
icon = self.defaultIcon
return script, title, icon, prelen, dangerous
......
......@@ -52,6 +52,9 @@ class AtEditor:
self.fieldRegex = re.compile('^(\*)$|^([0-9]+)$|^\*\\\([0-9]+)$|^([0-9]+)-([0-9]+)$|(^([0-9]+[,])+([0-9]+)$)')
self.nooutputRegex = re.compile('([^#\n$]*)>(\s|)/dev/null\s2>&1')
self.defaultIcon = "/usr/share/icons/gnome/48x48/mimetypes/gnome-mime-application.png"
#self.editing = gtk.FALSE
self.noevents = False
self.NOACTION = False #getting alot of these now.. this is for abosultely noactions of the syncing and templates stuff
......@@ -414,15 +417,15 @@ class AtEditor:
self.template_image.set_from_pixbuf(pixbuf)
self.icon = nautilus_icon
else:
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size ("/usr/share/icons/gnome/48x48/mimetypes/gnome-mime-application.png", 60, 60)
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size (self.defaultIcon, 60, 60)
self.template_image.set_from_pixbuf(pixbuf)
self.icon = "/usr/share/icons/gnome/48x48/mimetypes/gnome-mime-application.png"
self.icon = self.defaultIcon
def __reset__ (self):
self.title = "Untitled"
self.command = ""
self.icon = "/usr/share/icons/gnome/48x48/mimetypes/gnome-mime-application.png"
self.icon = self.defaultIcon
ctime = time.gmtime()
year = ctime[0]
......
......@@ -42,17 +42,23 @@ class Crontab:
self.preview_len = 50
self.root = 0
# TODO: shouldn't be gnome specific
self.defaultIcon = "/usr/share/icons/gnome/48x48/mimetypes/gnome-mime-application.png"
self.nooutputtag = ">/dev/null 2>&1"
self.crontabRecordRegex = re.compile('([^\s]+)\s([^\s]+)\s([^\s]+)\s([^\s]+)\s([^\s]+)\s([^#\n$]*)(\s#\s([^\n$]*)|$)')
def set_rights(self,user,uid,gid):
self.user = user
self.uid = uid
self.gid = gid
def get_type (self):
return "crontab"
def checkfield (self, field, type, regex):
m = regex.match (field)
num = 0
......@@ -156,26 +162,7 @@ class Crontab:
# TODO: let write trow an exception if failed
self.__write__ ()
##if written:
#self.ParentClass.treemodel.set_value (parentiter, 1, easystring)
#if nooutput:
# space = " "
# if command[len(command)-1] == " ":
# space = ""
# self.ParentClass.treemodel.set_value (parentiter, 2, self.__make_preview__ (command + space + self.nooutputtag))
#else:
# self.ParentClass.treemodel.set_value (parentiter, 2, self.__make_preview__ (command))
#self.ParentClass.treemodel.set_value (parentiter, 5, minute + " " + hour + " " + day + " " + month + " " + weekday)
#self.ParentClass.treemodel.set_value (parentiter, 0, title)
#if icon != None:
# self.ParentClass.treemodel.set_value (parentiter, 6, gtk.gdk.pixbuf_new_from_file_at_size (icon, 21, 21))
#self.ParentClass.treemodel.set_value (parentiter, 3, record)
##
def delete (self, linenumber, iter):
number = 0
newlines = list ()
......@@ -189,8 +176,6 @@ class Crontab:
self.__write__ ()
def append (self, minute, hour, day, month, weekday, command, nooutput, title, icon = None):
record = minute + " " + hour + " " + day + " " + month + " " + weekday + " " + command
if nooutput:
......@@ -216,7 +201,6 @@ class Crontab:
data = []
# TODO: getRoot withit
if self.root:
execute = config.getCrontabbin () + " -l -u " + self.user
else:
......@@ -231,7 +215,6 @@ class Crontab:
(minute, hour, day, month, weekday, command, title, icon) = array_or_false
time = minute + " " + hour + " " + day + " " + month + " " + weekday
#make the command smaller if the lenght is to long
preview = self.__make_preview__ (command)
......@@ -245,6 +228,7 @@ class Crontab:
print data
return data
def translate_frequency (self, frequency):
if frequency == "minute":
......@@ -280,8 +264,7 @@ class Crontab:
command = m.groups ()[5]
#icon path is in comment of the task, this is the default
# TODO: shouldn't be gnome specific
icon = "/usr/share/icons/gnome/48x48/mimetypes/gnome-mime-application.png"
icon = self.defaultIcon
#title is in comment of the task
title = None
......@@ -301,11 +284,13 @@ class Crontab:
else:
print "ERROR: Failed to parse crontab record"
return False
# TODO: throw exception
def __easy__ (self, minute, hour, day, month, weekday):
return lang.translate_crontab_easy (minute, hour, day, month, weekday)
#create temp file with old tasks and new ones and then updates crontab
def __write__ (self):
tmpfile = tempfile.mkstemp ()
......@@ -336,15 +321,11 @@ class Crontab:
# print config.getCrontabbin () + " " + path
os.system (config.getCrontabbin () + " " + path)
os.unlink (path)
#TODO needs exception handler
#TODO: check into
#if a command his lenght is to long the last part is removed
#XXX if the beginning is just a long path it's maybe better to cut there
#XXX instead of in the front .../bin/updatedb instead of /dfdffd/bin/upda...
def __make_preview__ (self, str, preview_len = 0):
if preview_len == 0:
preview_len = self.preview_len
......
......@@ -23,7 +23,6 @@ import gobject
#python modules
#import string
import re
import os
......@@ -46,7 +45,6 @@ class CrontabEditor:
def __init__(self, parent, backend, scheduler):
self.ParentClass = parent
#self.schedule = self.ParentClass #needed for the crontabeditorhelper
self.backend = backend
self.scheduler = scheduler
......@@ -54,12 +52,18 @@ class CrontabEditor:
self.widget = self.xml.get_widget("crontabEditor")
self.widget.connect("delete-event", self.on_cancel_button_clicked)
# TODO: move to crontab?
self.fieldRegex = re.compile('^(\*)$|^([0-9]+)$|^\*\/([0-9]+)$|^([0-9]+)-([0-9]+)$|(^([0-9]+[,])+([0-9]+)$)')
self.nooutputRegex = re.compile('([^#\n$]*)>(\s|)/dev/null\s2>&1')
self.defaultIcon = "/usr/share/icons/gnome/48x48/mimetypes/gnome-mime-application.png"
#self.editing = gtk.FALSE
self.noevents = False
##simple tab
self.notebook = self.xml.get_widget("notebook")
self.template_image = self.xml.get_widget ("template_image")
......@@ -72,7 +76,6 @@ class CrontabEditor:
self.template_combobox = self.xml.get_widget ("template_combobox")
self.template_combobox_model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)
#self.template_combobox.set_text_column (0)
self.template_combobox.set_model (self.template_combobox_model)
self.title_entry = self.xml.get_widget ("title_entry")
......@@ -96,6 +99,7 @@ class CrontabEditor:
self.ok_button = self.xml.get_widget ("ok_button")
self.template_combobox.get_child().connect ("changed", self.on_template_combobox_entry_changed)
self.xml.signal_connect("on_remove_button_clicked", self.on_remove_button_clicked)
self.xml.signal_connect("on_add_help_button_clicked", self.on_add_help_button_clicked)
self.xml.signal_connect("on_cancel_button_clicked", self.on_cancel_button_clicked)
......@@ -120,10 +124,11 @@ class CrontabEditor:
self.setting_label = self.xml.get_widget ("setting_label")
##
self.editorhelper = crontabEditorHelper.CrontabEditorHelper(self)
self.backend.add_scheduler_type("crontab")
def showadd (self, mode):
self.__loadicon__ ()
self.__reset__ ()
......@@ -133,6 +138,12 @@ class CrontabEditor:
self.widget.show ()
self.__reload_templates__ ()
self.chkNoOutput.set_active (gtk.TRUE)
#switch to advanced tab if required
if mode == "advanced":
self.notebook.set_current_page(1)
else:
self.notebook.set_current_page(0)
def showedit (self, record, linenumber, iter, mode):
......@@ -223,9 +234,9 @@ class CrontabEditor:
self.icon = nautilus_icon
else:
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size ("/usr/share/icons/gnome/48x48/mimetypes/gnome-mime-application.png", 60, 60)
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size (self.defaultIcon, 60, 60)
self.template_image.set_from_pixbuf(pixbuf)
self.icon = "/usr/share/icons/gnome/48x48/mimetypes/gnome-mime-application.png"
self.icon = self.defaultIcon
#save template
......
......@@ -450,7 +450,7 @@ class main:
self.dialog.run ()
self.dialog.destroy ()
def on_set_user_menu_activate(self, *args):
def on_set_user_menu_activate(self, *args):
self.setuserWindow.ShowSetuserWindow()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment