1#!/usr/bin/env python3 2 3# __init__.py 4# 5# Copyright ® 2016-2020 Georges Basile Stavracas Neto <georges.stavracas@gmail.com> 6# 7# This program is free software: you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation, either version 3 of the License, or 10# (at your option) any later version. 11# 12# This program is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with this program. If not, see <http://www.gnu.org/licenses/>. 19 20import gi 21 22gi.require_version('Gtd', '1.0') 23gi.require_version('Peas', '1.0') 24 25from gi.repository import Gio, GLib, GObject, Gtd, Gtk, Peas 26 27try: 28 import gettext 29 gettext.bindtextdomain('gnome-todo') 30 gettext.textdomain('gnome-todo') 31 _ = gettext.gettext 32except Exception: 33 def _(s): 34 return s 35 36 37class UnscheduledPanel(Gtk.Box, Gtd.Panel): 38 39 menu = GObject.Property(type=Gio.Menu, default=None) 40 name = GObject.Property(type=str, default="unscheduled-panel") 41 title = GObject.Property(type=str, default=_("Unscheduled")) 42 subtitle = GObject.Property(type=str, default=None) 43 priority = GObject.Property(type=int, default=0) 44 icon = GObject.Property(type=Gio.ThemedIcon, default=None) 45 46 47 def __init__(self): 48 Gtk.Box.__init__(self) 49 50 manager = Gtd.Manager.get_default() 51 manager.connect('list-added', self._count_tasks) 52 manager.connect('list-changed', self._count_tasks) 53 manager.connect('list-removed', self._count_tasks) 54 55 self.task_counter = 0 56 57 self.view = Gtd.TaskListView(hexpand=True, vexpand=True) 58 self.view.set_show_list_name(True) 59 self.view.set_handle_subtasks(False) 60 61 self.menu = Gio.Menu() 62 self.menu.append(_("Clear completed tasks…"), 63 "list.clear-completed-tasks") 64 65 self.icon = Gio.ThemedIcon.new("appointment-missed-symbolic") 66 67 self.add(self.view) 68 self.show_all() 69 70 self._count_tasks() 71 72 def _count_tasks(self, unused_0=None, unused_1=None): 73 74 previous_task_counter = self.task_counter 75 self.task_counter = 0 76 77 manager = Gtd.Manager.get_default() 78 current_tasks = [] 79 80 for tasklist in manager.get_task_lists(): 81 for task in tasklist.get_tasks(): 82 83 if not task.get_due_date() is None: 84 continue 85 86 current_tasks.append(task) 87 88 # Update the counter 89 if not task.get_complete(): 90 self.task_counter += 1 91 92 self.view.set_list(current_tasks) 93 94 if previous_task_counter != self.task_counter: 95 self.notify("title") 96 97 def do_get_header_widgets(self): 98 return None 99 100 def do_get_menu(self): 101 return self.menu 102 103 def do_get_priority(self): 104 return self.priority 105 106 def do_get_panel_name(self): 107 return "unscheduled-panel" 108 109 def do_get_panel_title(self): 110 if self.task_counter == 0: 111 # Translators: 'Unscheduled' as in 'Unscheduled tasks' 112 return _("Unscheduled") 113 else: 114 # Translators: 'Unscheduled' as in 'Unscheduled tasks' 115 return _("Unscheduled (%d)") % self.task_counter 116 117 118class UnscheduledPanelPlugin(GObject.Object, Gtd.Activatable): 119 120 preferences_panel = GObject.Property(type=Gtk.Widget, default=None) 121 122 def __init__(self): 123 GObject.Object.__init__(self) 124 125 self.panel = UnscheduledPanel() 126 127 def do_activate(self): 128 pass 129 130 def do_deactivate(self): 131 pass 132 133 def do_get_preferences_panel(self): 134 return None 135