Subversion Repositories basico

Rev

Rev 254 | Rev 256 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
113 t00mlabs 1
#!/usr/bin/python
246 t00m 2
"""
113 t00mlabs 3
# -*- coding: utf-8 -*-
246 t00m 4
# File: wdg_menuview.py
113 t00mlabs 5
# Author: Tomás Vírseda
6
# License: GPL v3
133 t00mlabs 7
# Description: SAPNoteViewMenu Widget
246 t00m 8
"""
113 t00mlabs 9
 
243 t00m 10
from enum import IntEnum
113 t00mlabs 11
from cgi import escape
211 t00m 12
from collections import OrderedDict
113 t00mlabs 13
import gi
14
gi.require_version('Gdk', '3.0')
15
gi.require_version('Gtk', '3.0')
16
from gi.repository import Gdk
17
from gi.repository import Gtk
18
from gi.repository import Pango
19
from gi.repository.GdkPixbuf import Pixbuf
20
from dateutil import parser as dateparser
243 t00m 21
from basico.widgets.wdg_cols import CollectionsMgtView
113 t00mlabs 22
 
23
 
243 t00m 24
class Column(IntEnum):
25
    rowtype = 0
26
    checkbox = 1
27
    icon = 2
28
    component = 3
29
    category = 4
30
    type = 5
31
    id = 6
32
    title = 7
33
    priority = 8
34
    language = 9
35
    released = 10
36
 
37
 
38
class SAPNoteView(Gtk.TreeView):
39
    def __init__(self, app):
40
        Gtk.TreeView.__init__(self)
41
        self.app = app
42
 
43
        self.get_services()
44
        self.toggled = 0
45
        self.selected = set()
46
        self.count = 0
246 t00m 47
        self.completion = self.srvgui.add_widget('gtk_entrycompletion_viewmenu', Gtk.EntryCompletion())
243 t00m 48
        self.completion.set_match_func(self.completion_match_func)
49
        self.completion_model = Gtk.ListStore(str)
50
        self.completion.set_model(self.completion_model)
51
        self.completion.set_text_column(0)
52
        # ~ self.completion.set_inline_completion(True)
53
 
54
        # Setup treeview and model
55
        Gtk.TreeView.__init__(self)
56
        self.model = Gtk.TreeStore(
57
            str,            # RowType@RowId
58
            bool,           # CheckBox
59
            Pixbuf,         # Icon
60
            str,            # Component key
61
            str,            # Category
62
            str,            # Type
63
            str,            # SAP Note Id
64
            str,            # Title
65
            str,            # Priority
66
            str,            # Language
67
            str             # Release date
68
        )
69
        self.set_model(self.model)
70
 
71
        # Setup columns
72
        # RowType
73
        self.renderer_rowtype = Gtk.CellRendererText()
74
        self.column_rowtype = Gtk.TreeViewColumn('', self.renderer_rowtype, text=Column.rowtype.value)
75
        self.column_rowtype.set_visible(False)
76
        self.column_rowtype.set_expand(False)
77
        self.column_rowtype.set_clickable(False)
78
        self.column_rowtype.set_sort_indicator(False)
79
        self.append_column(self.column_rowtype)
80
 
81
        # Checkbox
82
        self.renderer_checkbox = Gtk.CellRendererToggle()
83
        #~ self.renderer_checkbox.connect("toggled", self.on_cell_toggled)
84
        self.column_checkbox = Gtk.TreeViewColumn('', self.renderer_checkbox, active=1)
85
        self.column_checkbox.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
86
        self.column_checkbox.set_visible(False)
87
        self.column_checkbox.set_expand(False)
88
        self.column_checkbox.set_clickable(False)
89
        self.column_checkbox.set_sort_indicator(False)
90
        self.append_column(self.column_checkbox)
91
        #~ self.column_checkbox.set_cell_data_func(self.renderer_checkbox, self.cell_data_func)
92
 
93
        # Icon
94
        self.renderer_icon = Gtk.CellRendererPixbuf()
95
        self.renderer_icon.set_alignment(0.0, 0.5)
96
        self.column_icon = Gtk.TreeViewColumn('', self.renderer_icon, pixbuf=2)
97
        self.column_icon.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
98
        self.column_icon.set_visible(False)
99
        self.column_icon.set_expand(False)
100
        self.column_icon.set_clickable(False)
101
        self.column_icon.set_sort_indicator(False)
102
        self.append_column(self.column_icon)
103
 
104
        # Component key
105
        self.renderer_compkey = Gtk.CellRendererText()
255 t00m 106
        # ~ self.renderer_compkey.set_property("editable", True)
107
        # ~ self.renderer_compkey.connect('edited', self.edit_title)
243 t00m 108
        # ~ self.renderer_compkey.set_editable(True)
109
        #~ self.renderer_compkey.set_property('background', 'Lemon Chiffon')
110
        self.column_component = Gtk.TreeViewColumn('SAP Notes', self.renderer_compkey, markup=3)
111
        self.column_component.set_visible(True)
112
        self.column_component.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
113
        self.column_component.set_clickable(True)
114
        self.column_component.set_sort_indicator(True)
115
        self.column_component.set_sort_column_id(3)
116
        self.column_component.set_sort_order(Gtk.SortType.ASCENDING)
117
        self.column_component.set_expand(True)
118
        self.append_column(self.column_component)
119
 
120
        # Category
121
        self.renderer_cat = Gtk.CellRendererText()
122
        self.column_cat = Gtk.TreeViewColumn('Category', self.renderer_cat, markup=4)
123
        self.column_cat.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
124
        self.column_cat.set_visible(False)
125
        self.column_cat.set_expand(False)
126
        self.column_cat.set_clickable(True)
127
        self.column_cat.set_sort_indicator(True)
128
        self.column_cat.set_sort_column_id(4)
129
        self.column_cat.set_sort_order(Gtk.SortType.ASCENDING)
130
        self.append_column(self.column_cat)
131
 
132
        # Type
133
        self.renderer_sntype = Gtk.CellRendererText()
134
        self.column_sntype = Gtk.TreeViewColumn('Type', self.renderer_sntype, markup=5)
135
        self.column_sntype.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
136
        self.column_sntype.set_visible(False)
137
        self.column_sntype.set_expand(False)
138
        self.column_sntype.set_clickable(True)
139
        self.column_sntype.set_sort_indicator(True)
140
        self.column_sntype.set_sort_column_id(5)
141
        self.column_sntype.set_sort_order(Gtk.SortType.ASCENDING)
142
        self.append_column(self.column_sntype)
143
 
144
        # SAP Note Id
145
        self.renderer_sid = Gtk.CellRendererText()
146
        self.renderer_sid.set_alignment(1.0, 0.5)
147
        self.column_sid = Gtk.TreeViewColumn('SAP Note', self.renderer_sid, markup=6)
148
        self.column_sid.set_visible(False)
149
        self.column_sid.set_expand(False)
150
        self.column_sid.set_clickable(True)
151
        self.column_sid.set_sort_indicator(True)
152
        self.column_sid.set_sort_column_id(6)
153
        self.column_sid.set_sort_order(Gtk.SortType.ASCENDING)
154
        self.append_column(self.column_sid)
155
 
156
        # Title
157
        self.renderer_title = Gtk.CellRendererText()
158
        self.renderer_title.set_property('ellipsize', Pango.EllipsizeMode.MIDDLE)
159
        self.column_title = Gtk.TreeViewColumn('Title', self.renderer_title, text=7)
160
        self.column_title.set_visible(False)
161
        self.column_title.set_expand(True)
162
        self.column_title.set_clickable(True)
163
        self.column_title.set_sort_indicator(True)
164
        self.column_title.set_sort_column_id(7)
165
        self.column_title.set_sort_order(Gtk.SortType.ASCENDING)
166
        self.append_column(self.column_title)
167
 
168
        # Priority
169
        self.renderer_priority = Gtk.CellRendererText()
170
        self.column_priority = Gtk.TreeViewColumn('Priority', self.renderer_priority, markup=8)
171
        self.column_priority.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
172
        self.column_priority.set_visible(True)
173
        self.column_priority.set_expand(False)
174
        self.column_priority.set_clickable(True)
175
        self.column_priority.set_sort_indicator(True)
176
        self.column_priority.set_sort_column_id(8)
177
        self.column_priority.set_sort_order(Gtk.SortType.ASCENDING)
178
        self.append_column(self.column_priority)
179
 
180
        # Language
181
        self.renderer_lang = Gtk.CellRendererText()
182
        self.column_lang = Gtk.TreeViewColumn('Language', self.renderer_lang, markup=9)
183
        self.column_lang.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
184
        self.column_lang.set_visible(False)
185
        self.column_lang.set_expand(False)
186
        self.column_lang.set_clickable(True)
187
        self.column_lang.set_sort_indicator(True)
188
        self.column_lang.set_sort_column_id(9)
189
        self.column_lang.set_sort_order(Gtk.SortType.ASCENDING)
190
        self.append_column(self.column_lang)
191
 
192
        # Release date
193
        self.renderer_reldate = Gtk.CellRendererText()
194
        self.column_rel = Gtk.TreeViewColumn('Released on', self.renderer_reldate, markup=10)
195
        self.column_rel.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
196
        self.column_rel.set_visible(False)
197
        self.column_rel.set_expand(False)
198
        self.column_rel.set_clickable(True)
199
        self.column_rel.set_sort_indicator(True)
200
        self.column_rel.set_sort_column_id(10)
201
        self.column_rel.set_sort_order(Gtk.SortType.ASCENDING)
202
        self.append_column(self.column_rel)
203
 
204
        # TreeView common
205
        #~ self.set_level_indentation(6)
206
        self.set_can_focus(True)
207
        self.set_headers_visible(False)
208
        self.set_enable_search(True)
209
        self.set_hover_selection(False)
210
        self.set_grid_lines(Gtk.TreeViewGridLines.NONE)
246 t00m 211
        self.set_search_entry(self.srvgui.get_widget('stySearchInfo'))
243 t00m 212
        self.set_search_column(3)
213
        #~ self.set_row_separator_func(self.row_separator_func)
214
 
215
        # Selection
216
        self.selection = self.get_selection()
217
        self.selection.set_mode(Gtk.SelectionMode.SINGLE)
218
 
219
        font_desc = Pango.FontDescription('Monospace 10')
220
        if font_desc:
221
            self.modify_font(font_desc)
222
 
223
        self.prepare()
224
        self.show_all()
225
 
226
 
227
    def get_services(self):
246 t00m 228
        self.srvgui = self.app.get_service("GUI")
229
        self.srvclb = self.app.get_service('Callbacks')
230
        self.srvsap = self.app.get_service('SAP')
231
        self.srvicm = self.app.get_service('IM')
232
        self.srvstg = self.app.get_service('Settings')
233
        self.srvdtb = self.app.get_service('DB')
234
        self.srvant = self.app.get_service('Annotation')
235
        self.srvuif = self.app.get_service('UIF')
243 t00m 236
 
237
 
238
    def get_node(self, key, checkbox, icon, component, cat='', sntype='', sid='', title='', priority='', lang='', rel=''):
246 t00m 239
        completion = self.srvgui.get_widget('gtk_entrycompletion_viewmenu')
243 t00m 240
        completion_model = completion.get_model()
241
        completion_model.append([component])
242
 
243
        node = []
244
        node.append(key)
245
        node.append(checkbox)
246
        node.append(icon)
247
        node.append(component)
248
        node.append(cat)
249
        node.append(sntype)
250
        node.append(sid)
251
        node.append(title)
252
        node.append(priority)
253
        node.append(lang)
254
        node.append(rel)
255
        return node
256
 
257
 
258
    def get_node_date_year(self, date, token_date):
259
        title = "%s" % token_date
260
        return self.get_node('date-year@%s' % token_date, 0, None, title)
261
 
262
 
263
    def get_node_date_month(self, date, token_date):
264
        title = "%s" % date.strftime("%B")
265
        return self.get_node('date-month@%s' % token_date, 0, None, title)
266
 
267
 
268
    def get_node_date_day(self, date, token_date):
269
        title = "%s" % date.strftime("%d - %A")
270
        return self.get_node('date-day@%s' % token_date, 0, None, title)
271
 
272
 
273
    def get_node_priority(self, priority):
274
        icon = None
275
        if len(priority) == 0:
276
            title = "No priority assigned"
277
        else:
278
            title = "%s" % priority
279
 
280
        return self.get_node('priority@%s' % priority, 0, icon, title)
281
 
282
 
283
    def get_node_collection(self, collection_id, collection_name, icon=None):
284
        icon = None
285
        return self.get_node('collection@%s' % collection_id, 0, icon, collection_name)
286
 
287
 
288
    def get_node_type(self, sntype):
246 t00m 289
        icon = self.srvicm.get_icon('basico-type', 32, 32)
243 t00m 290
        if len(sntype) == 0:
291
            title = "SAP Note type not found"
292
        else:
293
            title = "%s" % sntype
294
        return self.get_node('type@%s' % sntype, 0, icon, title)
295
 
296
 
297
    def get_node_category(self, category=''):
298
        icon = None
299
        if len(category) == 0:
300
            catname = "No category assigned"
301
        else:
302
            catname = "%s" % category
303
        return self.get_node('category@%s' % catname, 0, icon, catname)
304
 
305
 
306
    def get_node_component(self, compkey, comptxt):
246 t00m 307
        icon = self.srvicm.get_icon('basico-component', 32, 32)
308
        # ~ node = []
309
        # ~ count = len(self.srvdtb.get_notes_by_node("componentkey", compkey))
310
        # ~ component = "%s" % (compkey)
311
        return self.get_node('componentkey@%s' % compkey, 0, icon, compkey)
243 t00m 312
 
313
 
314
    def get_node_component_desc(self, compkey, comptxt):
246 t00m 315
        icon = self.srvicm.get_icon('basico-description', 32, 32)
243 t00m 316
        node = []
246 t00m 317
        count = len(self.srvdtb.get_notes_by_node("componentkey", compkey))
243 t00m 318
        if len(comptxt) == 0:
319
            component = "%s" % (compkey)
320
        else:
321
            component = "%s" % (comptxt)
322
        return self.get_node('componentkey@%s' % compkey, 0, icon, component)
323
 
324
 
246 t00m 325
    def completion_match_func(self, completion, key, treeiter):
243 t00m 326
        model = completion.get_model()
246 t00m 327
        text = model.get_value(treeiter, 0)
243 t00m 328
        if key.upper() in text.upper():
329
            return True
330
        return False
331
 
332
class SAPNoteViewMenu(SAPNoteView):
178 t00m 333
    view = 'component'
334
 
134 t00mlabs 335
    def __init__(self, app):
336
        SAPNoteView.__init__(self, app)
337
        self.app = app
232 t00m 338
        self.row_type = None
134 t00mlabs 339
 
340
 
113 t00mlabs 341
    def prepare(self):
240 t00m 342
        # ~ self.renderer_title.set_property("editable", True)
343
        # ~ self.renderer_title.connect('edited', self.edit_title)
113 t00mlabs 344
        self.column_rowtype.set_visible(False)
345
        self.column_checkbox.set_visible(False)
346
        self.column_icon.set_visible(False)
347
        self.column_component.set_visible(True)
348
        self.column_cat.set_visible(False)
349
        self.column_sntype.set_visible(False)
350
        self.column_sid.set_visible(False)
351
        self.column_priority.set_visible(True)
352
        self.column_lang.set_visible(False)
353
        self.column_rel.set_visible(False)
354
 
355
        # TreeView common
356
        self.set_can_focus(True)
357
        self.set_headers_visible(False)
358
        self.set_enable_search(True)
359
        self.set_hover_selection(False)
360
        self.set_grid_lines(Gtk.TreeViewGridLines.NONE)
361
        self.set_level_indentation(0)
186 t00m 362
        self.sig_selection_changed = self.selection.connect('changed', self.row_changed)
241 t00m 363
        self.connect('button_press_event', self.right_click)
115 t00mlabs 364
 
174 t00m 365
    def refresh(self):
254 t00m 366
        visor = self.srvgui.get_widget('visor_sapnotes')
175 t00m 367
        try:
368
            self.set_view(self.view)
232 t00m 369
            if self.row_type is not None:
246 t00m 370
                matches = self.srvdtb.get_notes_by_node(self.row_type, self.cid)
237 t00m 371
                visor.populate_sapnotes(matches)
217 t00m 372
        except Exception as error:
255 t00m 373
            pass
374
            # ~ raise
116 t00mlabs 375
 
201 t00m 376
 
116 t00mlabs 377
    def row_changed(self, selection):
378
        if self.current_status is None:
254 t00m 379
            visor = self.srvgui.get_widget('visor_sapnotes')
246 t00m 380
            # ~ self.srvuif.set_widget_visibility('widget_annotation', False)
235 t00m 381
 
116 t00mlabs 382
            try:
239 t00m 383
                model, treeiter = selection.get_selected()
384
                row = model[treeiter][0]
255 t00m 385
                row_title = model[treeiter][3]
174 t00m 386
                self.row_type, self.cid = row.split('@')
239 t00m 387
                iter_has_child = model.iter_has_child(treeiter)
388
 
389
                if self.row_type == 'collection':
390
                    if not iter_has_child:
246 t00m 391
                        matches = self.srvdtb.get_notes_by_node(self.row_type, self.cid)
239 t00m 392
                        visor.populate_sapnotes(matches, self.cid)
393
                    else:
255 t00m 394
                        matches = set()
395
                        cols = self.srvclt.get_collections_by_row_title(row_title)
396
                        for col in cols:
397
                            for sid in self.srvdtb.get_notes_by_node(self.row_type, col):
398
                                matches.add(sid)
241 t00m 399
                        if len(matches) > 0:
255 t00m 400
                            visor.populate_sapnotes(list(matches))
241 t00m 401
                        else:
402
                            visor.populate_sapnotes([])
239 t00m 403
                else:
246 t00m 404
                    matches = self.srvdtb.get_notes_by_node(self.row_type, self.cid)
239 t00m 405
                    visor.populate_sapnotes(matches, self.cid)
255 t00m 406
            except:
407
                raise
113 t00mlabs 408
 
409
 
241 t00m 410
    def right_click(self, treeview, event, data=None):
411
        if event.button == 3:
412
            rect = Gdk.Rectangle()
413
            rect.x = x = int(event.x)
414
            rect.y = y = int(event.y)
246 t00m 415
            pthinfo = treeview.get_path_at_pos(x, y)
241 t00m 416
            if pthinfo is not None:
246 t00m 417
                path, col, cellx, celly = pthinfo
241 t00m 418
                model = treeview.get_model()
419
                treeiter = model.get_iter(path)
420
                rid = model[treeiter][0]
421
                rtype = rid[:rid.find('@')]
422
                if rtype == 'collection':
246 t00m 423
                    popcollections = self.srvgui.add_widget('gtk_popover_button_manage_collections_single_note', Gtk.Popover.new(treeview))
241 t00m 424
                    popcollections.set_position(Gtk.PositionType.RIGHT)
425
                    popcollections.set_pointing_to(rect)
426
                    popcollections.add(CollectionsMgtView(self.app, '0000000000', popcollections))
246 t00m 427
                    self.srvclb.gui_show_popover(None, popcollections)
241 t00m 428
 
429
 
142 t00mlabs 430
    def set_view(self, view=None):
246 t00m 431
        statusbar = self.srvgui.get_widget('widget_statusbar')
113 t00mlabs 432
        # FIXME: Get last view visited from config
130 t00mlabs 433
        if view is None:
246 t00m 434
            view = 'chronologic'
142 t00mlabs 435
 
246 t00m 436
        iconview = self.srvgui.get_widget('gtk_image_current_view')
437
        icon = self.srvicm.get_pixbuf_icon('basico-%s' % view, 24, 24)
113 t00mlabs 438
        iconview.set_from_pixbuf(icon)
203 t00m 439
        iconview.show_all()
117 t00mlabs 440
        self.view = view
242 t00m 441
        # ~ self.debug("Set current view to: %s" % view)
117 t00mlabs 442
 
113 t00mlabs 443
        # Change label
246 t00m 444
        viewlabel = self.srvgui.get_widget('gtk_label_current_view')
141 t00mlabs 445
        name = "<b>%s</b>" % view.capitalize()
113 t00mlabs 446
        viewlabel.set_markup(name)
141 t00mlabs 447
        viewlabel.set_xalign(0.0)
448
        viewlabel.set_justify(Gtk.Justification.LEFT)
203 t00m 449
        viewlabel.show_all()
116 t00mlabs 450
        self.populate([])
113 t00mlabs 451
 
239 t00m 452
        # ~ self.info('Displaying view: %s' % view.capitalize())
116 t00mlabs 453
 
203 t00m 454
 
117 t00mlabs 455
    def get_view(self):
456
        return self.view
457
 
186 t00m 458
 
235 t00m 459
    def populate(self, sapnotes=[]):
116 t00mlabs 460
        self.current_status = "working"
186 t00m 461
        self.column_component.set_title('Categories')
462
        self.set_headers_visible(False) # Set
463
        self.column_sid.set_visible(True)
113 t00mlabs 464
        self.column_icon.set_visible(False)
186 t00m 465
        self.column_component.set_visible(True)
466
        self.column_component.set_expand(True)
467
        self.column_title.set_visible(False)
468
        self.column_title.set_expand(True)
469
        self.column_priority.set_expand(False)
470
        self.column_cat.set_visible(False)
471
        self.column_sid.set_expand(False)
246 t00m 472
        tgbshowmenu = self.srvgui.get_widget('gtk_toogletoolbutton_menu_view')
122 t00mlabs 473
        tgbshowmenu.set_active(True)
246 t00m 474
        completion = self.srvgui.get_widget('gtk_entrycompletion_viewmenu')
242 t00m 475
        completion_model = completion.get_model()
476
        completion_model.clear()
122 t00mlabs 477
 
116 t00mlabs 478
        if len(sapnotes) == 0:
246 t00m 479
            sapnotes = self.srvdtb.get_notes()
116 t00mlabs 480
 
157 t00m 481
        if self.view == 'component':
113 t00mlabs 482
            self.populate_by_components(sapnotes)
483
        elif self.view == 'description':
484
            self.populate_by_component_descriptions(sapnotes)
122 t00mlabs 485
        elif self.view == 'bookmarks':
486
            self.populate_by_bookmarks()
113 t00mlabs 487
        elif self.view == 'projects':
488
            self.populate_by_projects(sapnotes)
229 t00m 489
        elif self.view == 'collections':
490
            self.populate_by_collections(sapnotes)
113 t00mlabs 491
        elif self.view == 'tags':
492
            self.populate_by_tags(sapnotes)
493
        elif self.view == 'category':
494
            self.populate_by_category(sapnotes)
495
        elif self.view == 'chronologic':
496
            self.populate_by_chronologic(sapnotes)
497
        elif self.view == 'priority':
498
            self.populate_by_priority(sapnotes)
499
        elif self.view == 'type':
500
            self.populate_by_type(sapnotes)
229 t00m 501
        elif self.view == 'collection':
502
            self.populate_by_collection(sapnotes)
217 t00m 503
        elif self.view == 'annotation':
225 t00m 504
            self.populate_annotations()
113 t00mlabs 505
        else:
506
            self.populate_by_components(sapnotes)
507
 
246 t00m 508
        viewfilter = self.srvgui.get_widget('gtk_entry_filter_view')
509
        completion = self.srvgui.get_widget('gtk_entrycompletion_viewmenu')
242 t00m 510
        completion.set_model(completion_model)
511
        viewfilter.set_completion(completion)
512
        # ~ self.debug("View '%s' populated" % (self.view))
246 t00m 513
        self.srvclb.gui_show_dashboard()
116 t00mlabs 514
        self.current_status = None
113 t00mlabs 515
 
122 t00mlabs 516
 
517
    def populate_by_bookmarks(self):
518
        matches = []
246 t00m 519
        sapnotes = self.srvdtb.get_notes()
122 t00mlabs 520
        for sid in sapnotes:
521
            if sapnotes[sid]['bookmark']:
522
                matches.append(sid)
523
        matches.sort()
524
 
254 t00m 525
        visor = self.srvgui.get_widget('visor_sapnotes')
246 t00m 526
        self.srvclb.gui_toggle_menu_view(False)
237 t00m 527
        visor.populate_sapnotes(matches)
246 t00m 528
        statusbar = self.srvgui.get_widget('widget_statusbar')
529
        # ~ self.debug('View %s populated with %d SAP Notes' % (self.view.capitalize(), len(matches)))
122 t00mlabs 530
 
531
 
113 t00mlabs 532
    def populate_by_components(self, sapnotes, only_bookmarks=False):
533
        self.model.clear()
534
        self.treepids = {}
535
 
536
        if len(sapnotes) == 0:
537
            return
538
 
539
        scomp = set()
540
        dcomp = {}
541
 
542
        for sid in sapnotes:
543
            compkey = escape(sapnotes[sid]['componentkey'])
544
            comptxt = escape(sapnotes[sid]['componenttxt'])
545
            scomp.add(compkey)
546
            dcomp[compkey] = comptxt
547
        lcomp = list(scomp)
548
        lcomp.sort()
549
 
550
        for compkey in lcomp:
551
            subkeys = compkey.split('-')
552
            ppid = None
553
            for i in range(1, len(subkeys)+1):
554
                key = ('-').join(subkeys[0:i])
555
                try:
556
                    ppid = self.treepids[key]
557
                except:
558
                    if i == len(subkeys):
559
                        title = dcomp[compkey]
560
                    else:
561
                        title = ""
562
                    node = self.get_node_component(key, title)
563
                    ppid = self.model.append(ppid, node)
564
                    self.treepids[key] = ppid
565
 
566
 
114 t00mlabs 567
    def populate_by_priority(self, sapnotes):
568
        self.model.clear()
569
        treepids = {}
570
 
571
        if len(sapnotes) == 0:
572
            return
573
 
574
        scomp = set()
575
        dcomp = {}
576
        pset = set()
577
 
578
        for sid in sapnotes:
579
            try:
580
                priority = sapnotes[sid]['priority']
581
                pset.add(priority)
582
            except: pass
583
 
584
        plist = []
585
        plist.extend(pset)
586
        plist.sort()
587
 
588
        for priority in plist:
589
            node = self.get_node_priority(priority)
590
            pid = self.model.append(None, node)
591
            treepids[priority] = pid
592
 
593
 
594
    def populate_by_type(self, sapnotes):
595
        self.model.clear()
596
        treepids = {}
597
 
598
        if len(sapnotes) == 0:
599
            return
600
 
601
        scomp = set()
602
        dcomp = {}
603
        pset = set()
604
 
605
        for sid in sapnotes:
606
            try:
607
                sntype = sapnotes[sid]['type']
608
                pset.add(sntype)
609
            except: pass
610
 
611
        plist = []
612
        plist.extend(pset)
613
        plist.sort()
614
 
615
        for sntype in plist:
616
            node = self.get_node_type(sntype)
617
            pid = self.model.append(None, node)
618
            treepids[sntype] = pid
619
 
620
 
113 t00mlabs 621
    def populate_by_component_descriptions(self, sapnotes, only_bookmarks=False):
622
        self.model.clear()
623
        self.treepids = {}
624
 
625
        if len(sapnotes) == 0:
626
            return
627
 
628
        scomp = set()
629
        dcomp = {}
630
 
631
        for sid in sapnotes:
632
            compkey = escape(sapnotes[sid]['componentkey'])
633
            comptxt = escape(sapnotes[sid]['componenttxt'])
634
            scomp.add(compkey)
635
            dcomp[compkey] = comptxt
636
        lcomp = list(scomp)
637
        lcomp.sort()
638
 
639
        for compkey in lcomp:
640
            subkeys = compkey.split('-')
641
            ppid = None
642
            for i in range(1, len(subkeys)+1):
643
                key = ('-').join(subkeys[0:i])
644
                try:
645
                    ppid = self.treepids[key]
646
                except:
647
                    if i == len(subkeys):
648
                        title = dcomp[compkey]
649
                    else:
650
                        title = ""
651
                    node = self.get_node_component_desc(key, title)
652
                    ppid = self.model.append(ppid, node)
653
                    self.treepids[key] = ppid
114 t00mlabs 654
 
655
 
656
    def populate_by_category(self, sapnotes):
657
        self.model.clear()
658
        treepids = {}
659
 
660
        if len(sapnotes) == 0:
661
            return
662
 
663
        scomp = set()
664
        dcomp = {}
665
        catset = set()
666
 
667
        for sid in sapnotes:
668
            try:
669
                cat = sapnotes[sid]['category']
670
                catset.add(cat)
671
            except: pass
672
 
673
        catlist = []
674
        catlist.extend(catset)
675
        catlist.sort()
676
 
677
        for cat in catlist:
187 t00m 678
            node = self.get_node_category(cat)
114 t00mlabs 679
            pid = self.model.append(None, node)
680
            treepids[cat] = pid
681
 
187 t00m 682
 
229 t00m 683
    def populate_by_collection(self, sapnotes):
239 t00m 684
        treepids = {}
685
        scomp = set()
686
        dcomp = {}
186 t00m 687
        self.model.clear()
246 t00m 688
        self.srvclt = self.app.get_service('Collections')
689
        collections = self.srvclt.get_all()
229 t00m 690
        od = OrderedDict(sorted(collections.items(), key=lambda t: t[1]))
239 t00m 691
 
211 t00m 692
        for tid in od:
239 t00m 693
            compkey = od[tid]
694
            subkeys = compkey.split(' ')
695
            ppid = None
696
            for i in range(1, len(subkeys)+1):
697
                key = (' ').join(subkeys[0:i])
698
                try:
699
                    ppid = treepids[key]
700
                except:
701
                    title = key
255 t00m 702
                    if title == compkey:
703
                        node = self.get_node_collection(tid, title)
704
                    else:
705
                        node = self.get_node_collection('', title)
239 t00m 706
                    ppid = self.model.append(ppid, node)
707
                    treepids[key] = ppid
114 t00mlabs 708
 
187 t00m 709
 
226 t00m 710
    def populate_annotations(self, annotations=None):
254 t00m 711
        visor = self.srvgui.get_widget('visor_annotations')
246 t00m 712
        self.srvclb.gui_toggle_menu_view(False)
225 t00m 713
        visor.populate_annotations(annotations)
217 t00m 714
 
715
 
114 t00mlabs 716
    def populate_by_chronologic(self, sapnotes):
717
        self.model.clear()
718
        treepids = {}
719
 
720
        if len(sapnotes) == 0:
721
            return
722
 
723
        years = set()
724
        months = set()
725
        days = set()
726
        for sid in sapnotes:
727
            try:
728
                downloaded = dateparser.parse(sapnotes[sid]['feedupdate'])
729
                year = "%d" % downloaded.year
730
                month = "%02d" % downloaded.month
731
                day = "%02d" % downloaded.day
246 t00m 732
                key_year = year
733
                key_month = year + month
734
                key_day = year + month + day
114 t00mlabs 735
                years.add(key_year)
736
                months.add(key_month)
737
                days.add(key_day)
738
            except:
739
                pass
740
        years = list(years)
741
        years.sort(reverse=True)
742
        months = list(months)
743
        months.sort(reverse=True)
744
        days = list(days)
745
        days.sort(reverse=True)
746
 
747
        for key_year in years:
748
            try:
749
                treepids[key_year]
750
            except:
751
                adate = key_year + '0101'
752
                downloaded = dateparser.parse(adate)
753
                node = self.get_node_date_year(downloaded, key_year)
754
                treepids[key_year] = self.model.append(None, node)
755
 
756
        for key_month in months:
757
            try:
758
                treepids[key_month]
759
            except:
760
                adate = key_month + '01'
761
                downloaded = dateparser.parse(adate)
762
                node = self.get_node_date_month(downloaded, key_month)
763
                key_year = key_month[0:4]
764
                treepids[key_month] = self.model.append(treepids[key_year], node)
765
 
766
        for key_day in days:
767
            try:
768
                treepids[key_day]
769
            except:
770
                downloaded = dateparser.parse(key_day)
771
                key_month = key_day[0:6]
772
                node = self.get_node_date_day(downloaded, key_day)
773
                treepids[key_day] = self.model.append(treepids[key_month], node)
774
 
775
 
255 t00m 776
    # ~ def edit_title(self, widget, path, target):
777
        # ~ model = self.get_model()
778
        # ~ treeiter = model.get_iter(path)
779
        # ~ row = model[treeiter][0]
780
        # ~ rowtype, cid = row.split('@')
781
        # ~ iter_has_child = model.iter_has_child(treeiter)
240 t00m 782
 
255 t00m 783
        # ~ if rowtype == 'collection':
784
            # ~ if not iter_has_child:
785
                # ~ if len(target) > 0:
786
                    # ~ self.srvclt.rename(cid, target)
787
                    # ~ self.populate()