~woutc/specto/specto-dbus-client

« back to all changes in this revision

Viewing changes to spectlib/export_watch.py

  • Committer: Jean-François Fortin Tam
  • Author(s): Wout Clymans
  • Date: 2008-07-22 23:22:49 UTC
  • Revision ID: jeff@kiki-20080722232249-l64srclhp6u6qyrw
WARNING: this commit contains all the significant changes that happened in a specto-woutc branch over the past year. Large change log follows. Some commit log lines were intentionally left out.

- A dialog with debug information is shown when specto has a system/programming error.
- Disable renaming watches in the listview, make it a Jump To action instead
- All mandatory fields have to be filled in now (add and edit watch)
- The error log now shows the lines in color according to the severity
- Better file size cache name
- Added more error-handling
- The filesize is now saved in a different cache file (not in watches.list), may fix issue 37?
- Icons are now shown in the combobox when you add a new watch (buggy, patches welcome)
- Improved the pop3, imap and gmail watches
- The gmail watch now saves what unread mails there already were last time
- Convert HTML entities for the web diff
- Moved some code so the file dialog will show faster
- A watch will be marked updated when you didn't clear it on quit.
- Removed double call to refresh the watch info
- Made a general gtkutil file where you can define widgets used in the edit and add watch windows
- Removed the class name from the logger
- Clear the watch when you open it using the balloon
- Make some watch names clearer
- Error log tab in notifier window
- Added "clear" button in the edit menu
- Show simple diff from webpage difference
- Console mode (specto --console or specto --console --help)
- Watch menu when you right-click a watch entry in the notifier window
- Ability to run a command when a watch is updated
- Ability to run a command when a watch is cleared
- Fields in the add and edit windows are now dynamic; when creating a new watch plugin, you don't have to write all the gui code anymore
- More space for the extra information in the info panel
- code cleanup
- use plugin-system

- Fix issue 150: Gmail.com - that address is disabled in Germany - hence you can't go to messages directly
- Fix issue 93: Gmail library can support no more than 19 new mails
- Fix issue 131: bombs on special characters
- Fix issue 134: harmonized colors
- Fix issue 119: don't let the log file get huge
- Fix issue 143: Site adress in "About" box is not clickable
- Fix issue 146: Per-watch option to prevent URL redirects; To use this option add "redirect = True" to the watch that is allowed to redirect
- Fix issue 145: abnormal behavior with ampersands in a web watch
- Fix issue 51: Specto stores passwords in plaintext (started keyring support)
- Fix issue 135: Proxy support (already proxy support for web watch)
- Fix issue 128: allow specifying a port for mail watches (add 'port = 323' to your watch config)
- Fix issue 132: removing a watch should remove its cache files
- Fix issue 136: Support specific folder monitor over IMAP (add 'folder = work' to your imap watch config)
- Fix issue 63: Google Reader Watch does not support more than 20 items
- Fix issue 39: POP3 & IMAP watches not on par with gmail watch's message counting logic
- Fix issue 100: gmail with google apps should point to the right domain when clicking Jump to
- Fix issue 95: statusbar should show something else when updates are done
- Fix issue 112: hide error log tabs when debug mode is deactivated
- Fix issue 101: show the import dialog after the file chooser
- Fix issue 114: removing a watch should show a confirmation dialog
- Fix issue 73: brackets in watch name lead to startup crash (brackets can now be used in the name!)
- Fix issue 69: startup fails due to wrong glade file path  
- Fix issue 12: provide more information
- Fix issue 13: watch list importing and exporting
- Fix issue 20: Organise specto source into modules
- Fix issue 33: ability to run a command instead of notifying
- Fix issue 54: freedesktop-compliant user directories
- Fix issue 72: "show in window list" preference is not saved
- Fix issue 77: don't mess up if ekiga's sound files are not present
- Fix issue 118: add http:// automatically for web watches (also @gmail.com added for gmail accounts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
# Boston, MA 02111-1307, USA.
23
23
from spectlib.i18n import _
24
24
import os
25
 
from spectlib.iniparser import ini_namespace
 
25
from spectlib.watch import Watch_io, Watch_collection
26
26
 
27
27
try:
28
28
    import pygtk
37
37
except:
38
38
    pass
39
39
 
40
 
class Import_watch:
 
40
class Export_watch:
41
41
    """
42
42
    Class to create the import/export watch dialog.
43
43
    """
44
44
    
45
 
    def __init__(self, specto, action):
 
45
    def __init__(self, specto, notifier):
46
46
        self.specto = specto
 
47
        self.notifier = notifier
 
48
 
47
49
        #create tree
48
50
        gladefile= self.specto.PATH + 'glade/import_export.glade' 
49
51
        windowname= "import_export"
50
52
        self.wTree=gtk.glade.XML(gladefile,windowname, self.specto.glade_gettext)
51
 
        self.model = gtk.ListStore(gobject.TYPE_BOOLEAN, gtk.gdk.Pixbuf, gobject.TYPE_STRING, gobject.TYPE_INT, gobject.TYPE_INT)
52
 
        self.action = action
53
 
 
 
53
        self.export_watch=self.wTree.get_widget("import_export")
 
54
        self.export_watch.set_title(_("Export watches"))
 
55
        self.wTree.get_widget("button_action").set_label(_("Export watches"))
 
56
        
 
57
        self.model = gtk.ListStore(gobject.TYPE_BOOLEAN, gtk.gdk.Pixbuf, gobject.TYPE_STRING, gobject.TYPE_INT, gobject.TYPE_STRING)
 
58
        self.new_watch_db = {}
 
59
                
54
60
        #catch some events
55
61
        dic= { "on_button_select_all_clicked": self.select_all,
56
62
            "on_button_deselect_all_clicked": self.deselect_all,
60
66
        #attach the events
61
67
        self.wTree.signal_autoconnect(dic)
62
68
 
63
 
        self.import_watch=self.wTree.get_widget("import_export")
64
69
        icon = gtk.gdk.pixbuf_new_from_file(self.specto.PATH + 'icons/specto_window_icon.png' )
65
 
        self.import_watch.set_icon(icon)
66
 
        
67
 
        if action == True:
68
 
            self.save = Save_dialog(self.specto, True, None)
69
 
            self.import_watch.set_title(_("Import watches"))
70
 
            self.wTree.get_widget("button_action").set_label(_("Import watches"))
71
 
        else:
72
 
            self.import_watch.set_title(_("Export watches"))
73
 
            self.wTree.get_widget("button_action").set_label(_("Export watches"))
74
 
        
 
70
        self.export_watch.set_icon(icon)
 
71
                        
75
72
        self.treeview=self.wTree.get_widget("treeview")
76
73
        self.treeview.set_model(self.model)
77
74
        self.treeview.set_flags(gtk.TREE_MODEL_ITERS_PERSIST)
81
78
        self.renderer = gtk.CellRendererToggle()
82
79
        self.renderer.set_property("activatable", True)
83
80
        self.renderer.connect("toggled", self.check_clicked, self.model)
84
 
        self.columnCheck = gtk.TreeViewColumn(_("Active"), self.renderer, active=0)
85
 
        #self.columnCheck.connect("clicked", self.sort_column_active)
86
 
        #self.columnCheck.set_sort_column_id(0)
87
 
        #self.column.set_resizable(True)
 
81
        self.columnCheck = gtk.TreeViewColumn(_("Select"), self.renderer, active=0)
88
82
        self.treeview.append_column(self.columnCheck)
89
83
 
90
84
        ### Icon
91
85
        self.renderer = gtk.CellRendererPixbuf()
92
86
        self.columnIcon = gtk.TreeViewColumn(_("Type"), self.renderer, pixbuf=1)
93
 
        #self.columnIcon.set_clickable(True)
94
 
        #self.columnIcon.connect("clicked", self.sort_column_type)
95
87
        self.treeview.append_column(self.columnIcon)
96
88
 
97
89
        ### Titre
98
90
        self.renderer = gtk.CellRendererText()
99
 
        #self.renderer.set_property("editable", True)
100
 
        #self.renderer.connect('edited', self.change_entry_name)
101
91
        self.columnTitel = gtk.TreeViewColumn(_("Name"), self.renderer, markup=2)
102
 
        #self.columnTitel.connect("clicked", self.sort_column_name)
103
92
        self.columnTitel.set_expand(True)
104
93
        self.columnTitel.set_resizable(True)
105
 
        #self.columnTitel.set_sort_column_id(2)
106
94
        self.treeview.append_column(self.columnTitel)
107
95
        
108
96
        ### ID
118
106
        self.columnType.set_visible(False)
119
107
        #self.columnType.set_sort_column_id(4)
120
108
        self.treeview.append_column(self.columnType)
121
 
        
122
 
        
123
 
        for i in self.specto.watch_db:
124
 
            watch = self.specto.watch_db[i]
125
 
            self.add_watch_entry(watch.name, watch.type, watch.id)
126
 
 
 
109
                
 
110
        for watch in self.specto.watch_db:
 
111
            if watch.deleted == False:
 
112
                self.add_watch_entry(watch.id)        
127
113
        
128
114
    def select_all(self, widget):
129
 
        for i in self.specto.watch_db:
130
 
            self.model.set_value(self.iter[i], 0, 1)
 
115
        db = self.specto.watch_db
 
116
 
 
117
        for watch in db:
 
118
            if watch.deleted == False:
 
119
                self.model.set_value(self.iter[watch.id], 0, 1)
131
120
        
132
121
    def deselect_all(self, widget):
133
 
        for i in self.specto.watch_db:
134
 
            self.model.set_value(self.iter[i], 0, 0)
 
122
        db = self.specto.watch_db
 
123
            
 
124
        for watch in db:
 
125
            if watch.deleted == False:
 
126
                self.model.set_value(self.iter[watch.id], 0, 0)
135
127
        
136
128
    def do_action(self, widget):
137
 
        if self.action == True:
138
 
            pass
139
 
        else:
140
 
            self.save = Save_dialog(self.specto, False, self.get_selected_watches())
 
129
        self.export_watch.hide_all()
 
130
        self.save = Save_dialog(self.specto, None, False, self.get_selected_watches())
141
131
        
142
132
    def delete_event(self, widget, *args):
143
133
        """ Destroy the window. """
144
 
        self.import_watch.destroy()
 
134
        self.export_watch.destroy()
145
135
        return True
146
136
    
147
137
    def get_selected_watches(self):
148
138
        selected_watches_db = {}
149
 
        
150
 
        for i in self.specto.watch_db:
151
 
            if self.model.get_value(self.iter[i], 0) == True:
152
 
                id = len(selected_watches_db)
153
 
                selected_watches_db[id] = self.specto.watch_db[i]
 
139
        i = 0
 
140
        watch_db = self.specto.watch_db
 
141
            
 
142
        for watch in watch_db:
 
143
            if watch.deleted == False:
 
144
                if self.model.get_value(self.iter[watch.id], 0) == True:
 
145
                    selected_watches_db[i] = watch
 
146
                    i += 1
154
147
        return selected_watches_db
155
148
       
156
149
    
157
 
    def add_watch_entry(self, name, type, id):
 
150
    def add_watch_entry(self, id):
158
151
        """ Add an entry to the notifier list. """
159
 
        i = id
160
 
 
161
 
        icon = self.specto.icon_theme.load_icon("error", 22, 0)
162
 
        if type == 0:#website
163
 
            icon = self.specto.icon_theme.load_icon("applications-internet", 22, 0)
164
 
        elif type == 1:#email
165
 
            icon = self.specto.icon_theme.load_icon("emblem-mail", 22, 0)
166
 
        elif type == 2:#file/folder
167
 
            icon = self.specto.icon_theme.load_icon("folder", 22, 0)
168
 
        elif type == 3:#system process
169
 
            icon = self.specto.icon_theme.load_icon("applications-system", 22, 0)
170
 
        elif type == 4:#port
171
 
            icon = self.specto.icon_theme.load_icon("network-transmit-receive", 22, 0)
172
 
 
173
 
        self.iter[i] = self.model.insert_before(None, None)
174
 
        self.model.set_value(self.iter[i], 0, 0)
175
 
        self.model.set_value(self.iter[i], 1, icon)#self.specto.notifier.make_transparent(icon, 50))#does not need transparency here
176
 
        self.model.set_value(self.iter[i], 2, name)
177
 
        self.model.set_value(self.iter[i], 3, id)
178
 
        self.model.set_value(self.iter[i], 4, type)
179
 
        #self.watches = self.watches + 1 #this line was in notifier.py. Should it be here also?
 
152
        watch = self.specto.watch_db[id]
 
153
        entry_name = watch.name.replace("&", "&")
 
154
        icon = self.notifier.get_icon(watch.icon, 50, False)
 
155
        self.iter[id] = self.model.insert_before(None, None)
 
156
        self.model.set_value(self.iter[id], 0, 0)
 
157
        self.model.set_value(self.iter[id], 1, icon)#self.specto.notifier.make_transparent(icon, 50))#does not need transparency here
 
158
        self.model.set_value(self.iter[id], 2, entry_name)
 
159
        self.model.set_value(self.iter[id], 3, watch.id)
 
160
        self.model.set_value(self.iter[id], 4, watch.type)
 
161
        
 
162
    def set_new_watch_db(self, watch_db):
 
163
        self.new_watch_db = watch_db
180
164
        
181
165
    def check_clicked(self, object, path, model):
182
166
        """ Call the main function to start/stop the selected watch. """
197
181
    Class for displaying the save as dialog.
198
182
    """
199
183
        
200
 
    def __init__(self, specto, action_type, watches_db):
 
184
    def __init__(self, specto, _import, action_type, watches_db):
201
185
        self.specto = specto
 
186
        self._export = _import
202
187
        #create tree
203
188
        gladefile= self.specto.PATH + 'glade/import_export.glade' 
204
189
        windowname= "filechooser"
206
191
        self.save_dialog = self.wTree.get_widget("filechooser")
207
192
        self.action_type = action_type
208
193
        
209
 
        if action_type == False: 
210
 
            self.save_dialog.set_action(gtk.FILE_CHOOSER_ACTION_SAVE)
211
 
            self.wTree.get_widget("button_save").set_label("gtk-save") 
212
 
            self.watches_db = watches_db   
 
194
        self.save_dialog.set_action(gtk.FILE_CHOOSER_ACTION_SAVE)
 
195
        self.wTree.get_widget("button_save").set_label("gtk-save") 
 
196
        self.watches_db = watches_db   
213
197
            
214
198
        dic={
215
199
        "on_button_cancel_clicked": self.cancel,
230
214
        """ Save the file. """
231
215
        file_name = self.save_dialog.get_filename()
232
216
        
233
 
        if self.action_type == True:
234
 
            print "not implemented yet!"
235
 
        else:
236
 
            for i in self.watches_db:
237
 
                values =  self.watches_db[i].dict_values()
238
 
                self.write_options(file_name,values)
 
217
        for i in self.watches_db.keys():
 
218
            values = {}
 
219
            values['name'] = self.watches_db[i].name
 
220
            values['type'] = self.watches_db[i].type
 
221
            values['refresh'] = self.watches_db[i].refresh
 
222
            values.update(self.watches_db[i].get_values())
 
223
            self.write_options(file_name,values)
239
224
        
240
225
        self.save_dialog.destroy()
241
226
        
245
230
        Values has to be a dictionary with the name from the options and the value. example: { 'name':'value', 'name':'value' }
246
231
        If the name is not found, a new watch will be added, else the excisting watch will be changed.
247
232
        """
248
 
        if not os.path.exists(file_name):
249
 
            f = open(file_name, "w")
250
 
            f.close()
251
 
        self.cfg = ini_namespace(file(file_name))
252
 
        name = values['name']
253
 
 
254
 
        if not self.cfg._sections.has_key(name):
255
 
            self.cfg.new_namespace(name) #add a new watch
256
 
 
257
 
        del values['name']
258
 
        for option, value  in values.iteritems():
259
 
            self.cfg[name][option] = value
260
 
 
261
 
        f = open(file_name, "w")
262
 
        f.write(str(self.cfg).strip()) #write the new configuration file
263
 
        f.close()
 
233
        watch_io = Watch_io(file_name)
 
234
        watch_io.write_watch(values)
264
235
        
265
236
if __name__ == "__main__":
266
237
    #run the gui
267
 
    app=import_watch()
 
238
    app=export_watch()
268
239
    gtk.main()