#!/usr/bin/env python # # Save and Load Links - Epiphany Extension # Copyright © Igor Stribu # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import gtk import datetime import epiphany _ui_str = """ """ def _menu_load_cb(action, window): fc = gtk.FileChooserDialog('Load Links',None,gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN,gtk.RESPONSE_OK)) fc.set_default_response(gtk.RESPONSE_OK) response = fc.run() if response == gtk.RESPONSE_OK: file = open(fc.get_filename(), "r") urls = file.readlines() tab = window.get_active_tab() flags = epiphany.NEW_TAB_IN_EXISTING_WINDOW \ | epiphany.NEW_TAB_APPEND_LAST \ | epiphany.NEW_TAB_OPEN_PAGE for url in urls: epiphany.ephy_shell_get_default().new_tab( window, tab, url, flags) file.close() fc.destroy() def _menu_save_cb(action, window): name = "Saved Links %s" % datetime.date.today() fc = gtk.FileChooserDialog('Save as',None,gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN,gtk.RESPONSE_OK)) fc.set_default_response(gtk.RESPONSE_OK) fc.set_current_name(name) response = fc.run() if response == gtk.RESPONSE_OK: file = open(fc.get_filename(), "w") tabs = window.get_tabs() urls = [] for tab in tabs: emb = tab.get_embed() urls.append("%s\n" % emb.get_location(0)) file.writelines(urls) file.close() fc.destroy() _actions = [('SaveLinks', None, 'Save Links', None, None, _menu_save_cb), ('LoadLinks', None, 'Load Links', None, None, _menu_load_cb)] def attach_window(window): ui_manager = window.get_ui_manager() group = gtk.ActionGroup('Save Links') group.add_actions(_actions, (window)) ui_manager.insert_action_group(group, 0) ui_id = ui_manager.add_ui_from_string(_ui_str) window._menu_save_data = (group, ui_id) def detach_window(window): group, ui_id = window._menu_save_data del window._menu_save_data ui_manager = window.get_ui_manager() ui_manager.remove_ui(ui_id) ui_manager.remove_action_group(group) ui_manager.ensure_update()