def init(self): with self._lock: if self._disposed: raise InvalidOperationException("Daemon has been disposed") if self._initialized: raise InvalidOperationException("Daemon has already been initialized") self._cfg = read_cfg() self._accounts = AccountList() self._accounts.load_from_cfg(self._cfg, enabled_only = True) hook_registry = HookRegistry() memorizer = Memorizer() memorizer.load() self._mailchecker = MailChecker(self._cfg, memorizer, hook_registry) # Note: all code following _load_plugins() should be executed # asynchronously because the dbus plugin requires an active mainloop # (usually started in the programs main function). self._load_plugins(memorizer, hook_registry) # Start checking for mails asynchronously. self._start_thread = threading.Thread(target = self._start) self._start_thread.start() self._initialized = True
def read_config(): ret, ret_data = config.read_cfg(path=CONFIG_PATH, keys="servermangement") if ret == config.FAIL: err_info = "read config file failed, err info:%s!" % ret_data log.debug_err(err_info) ret_data = {} return ret_data
def __init__(self): builder = Gtk.Builder() builder.set_translation_domain(PACKAGE_NAME) builder.add_from_file(get_data_file("config_window.ui")) builder.connect_signals( { "config_window_deleted": self.__on_config_window_deleted, "btn_add_clicked": self.__on_btn_add_clicked, "btn_edit_clicked": self.__on_btn_edit_clicked, "btn_remove_clicked": self.__on_btn_remove_clicked, "treeview_accounts_row_activated": self.__on_treeview_accounts_row_activated, "liststore_accounts_row_deleted": self.__on_liststore_accounts_row_deleted, "liststore_accounts_row_inserted": self.__on_liststore_accounts_row_inserted, "chk_enable_filter_toggled": self.__on_chk_enable_filter_toggled, "chk_script0_toggled": self.__on_chk_script0_toggled, "chk_script1_toggled": self.__on_chk_script1_toggled, } ) self.window = builder.get_object("config_window") self.window.set_icon(GdkPixbuf.Pixbuf.new_from_file_at_size(get_data_file("mailnag.svg"), 48, 48)) self.cfg = read_cfg() # # account tab # self.accounts = AccountList() self.treeview_accounts = builder.get_object("treeview_accounts") self.liststore_accounts = builder.get_object("liststore_accounts") self.button_edit = builder.get_object("button_edit") self.button_remove = builder.get_object("button_remove") renderer_on = Gtk.CellRendererToggle() renderer_on.connect("toggled", self.__on_account_toggled) # bind toggle signal column_on = Gtk.TreeViewColumn(_("Enabled"), renderer_on) # Account On/Off column_on.add_attribute(renderer_on, "active", 1) column_on.set_alignment(0.5) # center column heading self.treeview_accounts.append_column(column_on) renderer_name = Gtk.CellRendererText() column_name = Gtk.TreeViewColumn(_("Name"), renderer_name, text=2) # Account Name self.treeview_accounts.append_column(column_name) # # general tab # self.entry_label = builder.get_object("entry_label") self.spinbutton_interval = builder.get_object("spinbutton_interval") self.cb_notification_mode = builder.get_object("cb_notification_mode") cell = Gtk.CellRendererText() self.cb_notification_mode.pack_start(cell, True) self.cb_notification_mode.add_attribute(cell, "text", 0) self.chk_playsound = builder.get_object("chk_playsound") self.chk_autostart = builder.get_object("chk_autostart") # # spam filter tab # self.chk_enable_filter = builder.get_object("chk_enable_filter") self.textview_filter = builder.get_object("textview_filter") self.textbuffer_filter = builder.get_object("textbuffer_filter") # # events tab # self.chk_script0 = builder.get_object("chk_script0") self.filechooser_script0 = builder.get_object("filechooser_script0") self.chk_script1 = builder.get_object("chk_script1") self.filechooser_script1 = builder.get_object("filechooser_script1") # # about tab # self.image_logo = builder.get_object("image_logo") pb = GdkPixbuf.Pixbuf.new_from_file_at_size(get_data_file("mailnag.svg"), 200, 200) self.image_logo.set_from_pixbuf(pb) self.load_config() self.window.show()
def __init__(self): builder = Gtk.Builder() builder.set_translation_domain(PACKAGE_NAME) builder.add_from_file(get_data_file("config_window.ui")) builder.connect_signals({ \ "config_window_deleted" : self._on_config_window_deleted, \ "btn_add_clicked" : self._on_btn_add_clicked, \ "btn_edit_clicked" : self._on_btn_edit_clicked, \ "btn_remove_clicked" : self._on_btn_remove_clicked, \ "treeview_accounts_row_activated" : self._on_treeview_accounts_row_activated, \ "liststore_accounts_row_deleted" : self._on_liststore_accounts_row_deleted, \ "liststore_accounts_row_inserted" : self._on_liststore_accounts_row_inserted, \ "chk_enable_filter_toggled" : self._on_chk_enable_filter_toggled, \ "chk_script0_toggled" : self._on_chk_script0_toggled, \ "chk_script1_toggled" : self._on_chk_script1_toggled \ }) self._window = builder.get_object("config_window") self._window.set_icon(GdkPixbuf.Pixbuf.new_from_file_at_size(get_data_file("mailnag.svg"), 48, 48)); self._cfg = read_cfg() # # account tab # self._accounts = AccountList() self._treeview_accounts = builder.get_object("treeview_accounts") self._liststore_accounts = builder.get_object("liststore_accounts") self._button_edit = builder.get_object("button_edit") self._button_remove = builder.get_object("button_remove") renderer_on = Gtk.CellRendererToggle() renderer_on.connect("toggled", self._on_account_toggled) # bind toggle signal column_on = Gtk.TreeViewColumn(_('Enabled'), renderer_on) # Account On/Off column_on.add_attribute(renderer_on, "active", 1) column_on.set_alignment(0.5) # center column heading self._treeview_accounts.append_column(column_on) renderer_name = Gtk.CellRendererText() column_name = Gtk.TreeViewColumn(_('Name'), renderer_name, text=2) # Account Name self._treeview_accounts.append_column(column_name) # # general tab # self._entry_label = builder.get_object("entry_label") self._spinbutton_interval = builder.get_object("spinbutton_interval") self._cb_notification_mode = builder.get_object("cb_notification_mode") cell = Gtk.CellRendererText() self._cb_notification_mode.pack_start(cell, True) self._cb_notification_mode.add_attribute(cell, "text", 0) self._chk_playsound = builder.get_object("chk_playsound") self._chk_autostart = builder.get_object("chk_autostart") # # spam filter tab # self._chk_enable_filter = builder.get_object("chk_enable_filter") self._textview_filter = builder.get_object("textview_filter") self._textbuffer_filter = builder.get_object("textbuffer_filter") # # events tab # self._chk_script0 = builder.get_object("chk_script0") self._filechooser_script0 = builder.get_object("filechooser_script0") self._chk_script1 = builder.get_object("chk_script1") self._filechooser_script1 = builder.get_object("filechooser_script1") # # about tab # self._image_logo = builder.get_object("image_logo") pb = GdkPixbuf.Pixbuf.new_from_file_at_size(get_data_file("mailnag.svg"), 180, 180) pb = pb.new_subpixbuf(0, 10, 180, 146) # crop whitespace at the bottom self._image_logo.set_from_pixbuf(pb) self._label_app_desc = builder.get_object("label_app_desc") self._label_app_desc.set_markup("<span font=\"24\"><b>Mailnag</b></span>\nVersion %s" % str(APP_VERSION)) self._load_config() self._window.show()
def read_config(): if not cfg_exists(): return None else: return read_cfg()
def __init__(self): builder = Gtk.Builder() builder.set_translation_domain(PACKAGE_NAME) builder.add_from_file(get_data_file("config_window.ui")) builder.connect_signals({ \ "config_window_deleted" : self._on_config_window_deleted, \ "btn_page_toggled" : self._on_btn_page_toggled, \ "btn_add_account_clicked" : self._on_btn_add_account_clicked, \ "btn_edit_account_clicked" : self._on_btn_edit_account_clicked, \ "btn_remove_account_clicked" : self._on_btn_remove_account_clicked, \ "treeview_accounts_row_activated" : self._on_treeview_accounts_row_activated, \ "liststore_accounts_row_deleted" : self._on_liststore_accounts_row_deleted, \ "liststore_accounts_row_inserted" : self._on_liststore_accounts_row_inserted, \ "btn_edit_plugin_clicked" : self._on_btn_edit_plugin_clicked, \ "treeview_plugins_row_activated" : self._on_treeview_plugins_row_activated, \ "treeview_plugins_cursor_changed" : self._on_treeview_plugins_cursor_changed, \ }) # Add icons in alternative data paths (e.g. ./data/icons) # to the icon search path in case Mailnag is launched # from a local directory (without installing). icon_theme = Gtk.IconTheme.get_default() for path in get_data_paths(): icon_theme.append_search_path(os.path.join(path, "icons")) self._window = builder.get_object("config_window") self._window.set_icon_name("mailnag") self._load_stylesheet('config_window.css') self._cfg = read_cfg() self.daemon_enabled = False # # toggle buttons / notebook # self._notebook = builder.get_object("notebook") self._box_navigation = builder.get_object("box_navigation") self._box_navigation.get_children()[0].set_active(True) # # general page # # The dimension of the png is expected to be 180x180 px pb = GdkPixbuf.Pixbuf.new_from_file(get_data_file("mailnag.png")) pb = pb.new_subpixbuf(0, 10, 180, 146) # crop whitespace at the bottom self._image_logo = builder.get_object("image_logo") self._image_logo.set_from_pixbuf(pb) self._label_app_desc = builder.get_object("label_app_desc") self._label_app_desc.set_markup("<span font=\"24\"><b>Mailnag</b></span>\nVersion %s" % str(APP_VERSION)) self._switch_daemon_enabled = builder.get_object("switch_daemon_enabled") # # accounts page # self._accounts = AccountList() self._treeview_accounts = builder.get_object("treeview_accounts") self._liststore_accounts = builder.get_object("liststore_accounts") self._button_edit_account = builder.get_object("btn_edit_account") self._button_remove_account = builder.get_object("btn_remove_account") self._button_edit_account.set_sensitive(False) self._button_remove_account.set_sensitive(False) renderer_acc_enabled = Gtk.CellRendererToggle() renderer_acc_enabled.connect("toggled", self._on_account_toggled) column_acc_enabled = Gtk.TreeViewColumn(_('Enabled'), renderer_acc_enabled) column_acc_enabled.add_attribute(renderer_acc_enabled, "active", 1) column_acc_enabled.set_alignment(0.5) self._treeview_accounts.append_column(column_acc_enabled) renderer_acc_name = Gtk.CellRendererText() column_acc_name = Gtk.TreeViewColumn(_('Name'), renderer_acc_name, text = 2) self._treeview_accounts.append_column(column_acc_name) # # plugins page # self._treeview_plugins = builder.get_object("treeview_plugins") self._liststore_plugins = builder.get_object("liststore_plugins") self._button_edit_plugin = builder.get_object("btn_edit_plugin") self._button_edit_plugin.set_sensitive(False) def renderer_plugin_enabled_func(column, cell_renderer, model, iter, data): plugin = model.get_value(iter, 0) name, desc, ver, author, mandatory = plugin.get_manifest() cell_renderer.set_sensitive(not mandatory) renderer_plugin_enabled = Gtk.CellRendererToggle() renderer_plugin_enabled.connect("toggled", self._on_plugin_toggled) column_plugin_enabled = Gtk.TreeViewColumn(_('Enabled'), renderer_plugin_enabled) column_plugin_enabled.add_attribute(renderer_plugin_enabled, "active", 1) column_plugin_enabled.set_alignment(0.5) column_plugin_enabled.set_cell_data_func(renderer_plugin_enabled, renderer_plugin_enabled_func) self._treeview_plugins.append_column(column_plugin_enabled) renderer_plugin_name = Gtk.CellRendererText() column_plugin_name = Gtk.TreeViewColumn(_('Name'), renderer_plugin_name, markup = 2) self._treeview_plugins.append_column(column_plugin_name) # load config self._load_config() self._window.show()