def __init__(self, parent, acc): self._acc = acc builder = Gtk.Builder() builder.set_translation_domain(PACKAGE_NAME) builder.add_from_file(get_data_file("account_dialog.ui")) builder.connect_signals({ \ "account_type_changed" : self._on_cmb_account_type_changed, \ "entry_changed" : self._on_entry_changed, \ "btn_cancel_clicked" : self._on_btn_cancel_clicked, \ "btn_save_clicked" : self._on_btn_save_clicked \ }) self._window = builder.get_object("account_dialog") self._window.set_transient_for(parent) self._cmb_account_type = builder.get_object("cmb_account_type") self._entry_account_name = builder.get_object("entry_account_name") self._entry_account_user = builder.get_object("entry_account_user") self._entry_account_password = builder.get_object("entry_account_password") self._entry_account_server = builder.get_object("entry_account_server") self._entry_account_port = builder.get_object("entry_account_port") self._label_account_folder = builder.get_object("label_account_folder") self._entry_account_folder = builder.get_object("entry_account_folder") self._chk_account_push = builder.get_object("chk_account_push") self._chk_account_ssl = builder.get_object("chk_account_ssl") self._button_save = builder.get_object("button_save") self._entry_account_port.set_placeholder_text(_("optional")) self._entry_account_folder.set_placeholder_text(_("optional"))
def check(self, accounts): with self._mailcheck_lock: print 'Checking %s email account(s) at: %s' % (len(accounts), time.asctime()) self._pid.kill() # kill all zombies if not is_online(): print 'Error: No internet connection' return self._mail_list = self._mailsyncer.sync(accounts) unseen_mails = [] new_mails = [] script_data = "" script_data_mailcount = 0 for mail in self._mail_list: if self._reminder.contains(mail.id): # mail was fetched before if self._reminder.unseen(mail.id): # mail was not marked as seen unseen_mails.append(mail) if self._firstcheck: new_mails.append(mail) else: # mail is fetched the first time unseen_mails.append(mail) new_mails.append(mail) script_data += ' "<%s> %s"' % (mail.sender, mail.subject) script_data_mailcount += 1 script_data = str(script_data_mailcount) + script_data if len(self._mail_list) == 0: # no mails (e.g. email client has been launched) -> close notifications for n in self._notifications.itervalues(): n.close() self._notifications = {} elif len(new_mails) > 0: if self._cfg.get('general', 'notification_mode') == '1': self._notify_summary(unseen_mails) else: self._notify_single(new_mails) # play sound if it is enabled in mailnags settings and # gnome-shell notifications aren't disabled if (self._cfg.get('general', 'playsound') == '1') and \ (self._gsettings.get_int('saved-session-presence') != 2): gstplay(get_data_file(self._cfg.get('general', 'soundfile'))) self._reminder.save(self._mail_list) self._run_user_scripts("on_mail_check", script_data) # process user scripts sys.stdout.flush() # write stdout to log file self._firstcheck = False return
def show_message(self, message): # dialog to show keyring messages builder = Gtk.Builder() builder.set_translation_domain(PACKAGE_NAME) builder.add_from_file(get_data_file("message_dialog.ui")) builder.connect_signals({"gtk_main_quit" : self.exit_message, \ "on_button_cancel_clicked" : self.exit_message, \ "on_button_ok_clicked" : self.ok_message}) self.window = builder.get_object("dialog_message") self.message = builder.get_object("label_message") self.message.set_text(message) # put message text into label self.window.show()
def show_keyring_dialog(self): # dialog to get password to unlock keyring self.was_locked = True builder = Gtk.Builder() builder.set_translation_domain(PACKAGE_NAME) builder.add_from_file(get_data_file("keyring_dialog.ui")) builder.connect_signals({"gtk_main_quit" : self.exit_keyring_dialog, \ "on_button_cancel_clicked" : self.exit_keyring_dialog, \ "on_button_ok_clicked" : self.ok_keyring_dialog, \ "on_entry_password_activate" : self.ok_keyring_dialog}) # hit RETURN in entry field self.window = builder.get_object("dialog_keyring") self.password = builder.get_object("entry_password") self.window.show()
def check(self, firstcheck = False): with self.mailcheck_lock: print 'Checking email accounts at:', time.asctime() self.pid.kill() # kill all zombies if firstcheck: # Manual firststart self.reminder.load() self.mail_list = self.mails.get_mail('desc') # get all mails from all inboxes unseen_mails = [] new_mails = [] script_data = "" script_data_mailcount = 0 for mail in self.mail_list: if self.reminder.contains(mail.id): # mail was fetched before if self.reminder.unseen(mail.id): # mail was not marked as seen unseen_mails.append(mail) if firstcheck: # first check after startup new_mails.append(mail) else: # mail is fetched the first time unseen_mails.append(mail) new_mails.append(mail) script_data += ' "<%s> %s"' % (mail.sender, mail.subject) script_data_mailcount += 1 script_data = str(script_data_mailcount) + script_data if len(self.mail_list) == 0: # no mails (e.g. email client has been launched) -> close notifications for n in self.notifications.itervalues(): n.close() self.notifications = {} elif len(new_mails) > 0: if self.cfg.get('general', 'notification_mode') == '1': self.notify_summary(unseen_mails) else: self.notify_single(new_mails) if self.cfg.get('general', 'playsound') == '1': # play sound? gstplay(get_data_file(self.cfg.get('general', 'soundfile'))) self.reminder.save(self.mail_list) self.run_user_scripts("on_mail_check", script_data) # process user scripts sys.stdout.flush() # write stdout to log file return True
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 mails_added_hook(new_mails, all_mails): config = self.get_config() gstplay(get_data_file(config['soundfile']))
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()
def _load_stylesheet(self, stylesheet): provider = Gtk.CssProvider() provider.load_from_path(get_data_file(stylesheet)) Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)