³ò
¢bc        "   @   sü  d  Z  d d k l Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k	 Z	 d d k
 Z
 d d k Z d d k Z d d k Z d d k l Z d d k l Z e i Z d d k Z e i d ƒ d d k l Z d d k Z d d k Z d d k Z d d k l Z d d	 k l Z l Z l Z l Z d d
 k l  Z! d d k l" Z" d d k# l$ Z$ l% Z% yE d d k Z e i d ƒ d d k l Z d d k Z d d k Z Wn e& j
 o n Xd e$ i' f d „  ƒ  YZ' d d „ Z) d S(   s6   

    KeepNote
    Import folder structure extension

iÿÿÿÿ(   t   get_timestampN(   t   minidom(   t   escapes   2.0(   t   gdk(   t   unicode_gtk(   t   NoteBookErrort   get_valid_unique_filenamet   CONTENT_TYPE_DIRt   attach_file(   t   notebook(   t   tasklib(   t	   extensiont   FileChooserDialogt	   Extensionc           B   s8   e  Z d  „  Z d „  Z d „  Z d „  Z d d „ Z RS(   c         C   s    t  i i |  | ƒ | |  _ d S(   s   Initialize extensionN(   R   R   t   __init__t   app(   t   selfR   (    (    sK   C:\Users\PCB\AppData\Roaming\keepnote\extensions\import_folders\__init__.pyR   Q   s    c         C   s   d d d f g S(   Nt   keepnotes   >=i    i   i   (   i    i   i   (    (   R   (    (    sK   C:\Users\PCB\AppData\Roaming\keepnote\extensions\import_folders\__init__.pyt   get_dependsX   s    c      
      sK   ˆ  i  ˆ d d ‡  ‡ f d †  d t d ƒ d t i ƒˆ  i ˆ d ƒ d S(	   s,   Initialize extension for a particular windows   Import Folders   _Attach Folder...c            s   ˆ  i  ˆ ˆ i ƒ  ƒ S(    (   t   on_import_folder_treet   get_notebook(   t   w(   R   t   window(    sK   C:\Users\PCB\AppData\Roaming\keepnote\extensions\import_folders\__init__.pyt   <lambda>b   s   t   tooltips0   Attach a folder and its contents to the notebookt   stock_idsˆ  
            <ui>
            <menubar name="main_menu_bar">
               <menu action="Edit">
                 <placeholder name="Viewer">
                     <menuitem action="Import Folder"/>
                 </placeholder>
               </menu>
            </menubar>
            
            <menubar name="popup_menus">
                <menu action="treeview_popup">
                    <menuitem action="Import Folder"/>
                </menu>
            
                <menu action="listview_popup">
                    <menuitem action="Import Folder"/>
                </menu>
            </menubar>
            </ui>
            N(   t
   add_actiont   _t   gtkt	   STOCK_ADDt   add_ui(   R   R   (    (   R   R   sK   C:\Users\PCB\AppData\Roaming\keepnote\extensions\import_folders\__init__.pyt	   on_add_ui\   s    	
	c      
   C   sÎ   | i  ƒ  } t | ƒ d j o d Sn | d } t d | d t i d d t i d t i f ƒ} | i ƒ  } | t i j oC | i ƒ  o6 t	 | i ƒ  ƒ } | i
 ƒ  |  i | | d | ƒn | i
 ƒ  d S(   s-   Callback from gui for importing a folder treei    Ns   Attach Foldert   actiont   buttonst   CancelR   (   t   get_selected_nodest   lenR   R   t!   FILE_CHOOSER_ACTION_SELECT_FOLDERt   RESPONSE_CANCELt   RESPONSE_OKt   runt   get_filenameR   t   destroyt   import_folder_tree(   R   R   R	   t   nodest   nodet   dialogt   responset   filename(    (    sK   C:\Users\PCB\AppData\Roaming\keepnote\extensions\import_folders\__init__.pyR   €   s    
			
c         C   s  y3 t  | | d d  ƒ| o | i d ƒ n t SWnÙ t j
 o` | o. | i d ƒ | i d | t i ƒ  d ƒ n! |  i i d | t i ƒ  d ƒ t	 Sno t
 j
 ob } | o. | i d ƒ | i d | t i ƒ  d ƒ n! |  i i d | t i ƒ  d ƒ t	 Sn Xd  S(   Nt   tasks   Folder imported.t    s   Error while importing folder.i   s   unknown error(   t   import_foldert   Nonet
   set_statust   TrueR   t   errort   syst   exc_infoR   t   Falset	   Exception(   R   R-   R0   R   t   e(    (    sK   C:\Users\PCB\AppData\Roaming\keepnote\extensions\import_folders\__init__.pyR+   š   s&    	! N(   t   __name__t
   __module__R   R   R   R   R4   R+   (    (    (    sK   C:\Users\PCB\AppData\Roaming\keepnote\extensions\import_folders\__init__.pyR   O   s
   			$	c      	   C   s#  | d	 j o t i ƒ  } n d } d } xG t i | ƒ D]6 \ } } } | t | ƒ 7} | i d d | f ƒ q9 W|  i t t i	 i
 | ƒ ƒ } | i d t i	 i
 | ƒ ƒ h  | | <}	 xVt i | ƒ D]E\ } } } | | j o
 | }
 nw |	 i t i	 i | ƒ d	 ƒ } | d	 j o qÌ n | i t t i	 i
 | ƒ ƒ }
 |
 i d t i	 i
 | ƒ ƒ |
 |	 | <x¦ | D]ž } t i ƒ  d j o d t i	 i | | ƒ } n t i	 i | | ƒ } t | |
 ƒ } | d 7} | i d d | | f f ƒ | i t | ƒ t | ƒ ƒ qoWqÌ W| i ƒ  d	 S(
   sÆ   
    Import a folder tree as a subfolder of the current item

    node     -- node to attach folder to
    filename -- filename of folder to import
    task     -- Task object to track progress
    i    t   texts   Found %i files...t   titlet   windowss   \\?\i   s   Imported %i / %i files...N(   R4   R
   t   Taskt   ost   walkR$   t   set_messaget	   new_childR   t   patht   basenamet   set_attrt   gett   dirnameR   t   get_platformt   joinR   t   set_percentt   floatt   finish(   R-   R0   R1   t   nfilest   nfilescompletet   roott   dirst   filest   rootnodet   filename2nodet   parentt   parent2t   fnt   child(    (    sK   C:\Users\PCB\AppData\Roaming\keepnote\extensions\import_folders\__init__.pyR3   ¶   sB      
	
 
%(*   t   __doc__t   keepnote.timestampR    t   codecst   gettextt	   mimetypesRC   R8   t   timet   shutilt   urllibt   urlparset   urllib2t   xml.domt   xmlR   t   xml.sax.saxutilsR   R   t   pygtkt   requireR   R   t	   gtk.gladet   gobjectR   R   t   keepnote.notebookR   R   R   R   R	   t   notebooklibR
   t   keepnote.guiR   R   t   ImportErrorR   R4   R3   (    (    (    sK   C:\Users\PCB\AppData\Roaming\keepnote\extensions\import_folders\__init__.pys   <module>   sH   	"g