Commits

Iñigo Serna  committed 33bae64

Add books: check folder to import must be located inside library base path

  • Participants
  • Parent commits 4cb4359

Comments (0)

Files changed (3)

 ============================================================================
-Last update:	Time-stamp: <2012-05-25 19:19:04 inigo>
+Last update:	Time-stamp: <2012-05-27 18:04:07 inigo>
 ============================================================================
 
 
 ========
 . added documentation skeleton
 . fix bug: stop loading covers if library changed 
+. add books: check folder to import must be located inside library base path
 
 
 v0.6
 . before delete, bulkedit => thaw
-. add books: check if path does not belong to lib base
 . refresh library:
   "Found 13 new books. 7 missing files, do you want to review and delete their entries in library?"
 . copy book(s) to path => preference: default path (f.e. "/media/DR800/Books"), filename format
             self.ids_filtered.append(b.id)
             if i % 50 == 0:
                 yield i
-        self.model.set_sort_column_id(lib.sort_col[0], lib.sort_col[1])
         # self.listview.thaw_child_notify()
         # self.prettyview.thaw_child_notify()
         # self.iconview.thaw_child_notify()
         self.listview.set_model(self.model_filtered)
         self.prettyview.set_model(self.model_filtered)
         self.iconview.set_model(self.model_filtered)
+        self.model.set_sort_column_id(lib.sort_col[0], lib.sort_col[1])
         t1 = time.time()
         log.debug('END create model in %d secs' % (t1-t0))
         yield i

File ui/wizards.py

         self.connect('cancel', self.on_cancel)
         self.connect('apply', self.on_apply)
         self.connect('prepare', self.on_prepare)
+        self.base_path = initialpath if initialpath!= '' else os.path.expandvars('$HOME')
         self.finished = False
         self.res = {'finished': False}
         # 1st. page: Introduction
         table.attach(AlignedLabel('<b>Folder:</b>'), 0, 1, 0, 1)
         self.btn_folder = gtk.FileChooserButton('Select the folder')
         self.btn_folder.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)
-        initialpath = initialpath if initialpath!= '' else os.path.expandvars('$HOME')
-        self.btn_folder.set_current_folder(initialpath)
+        self.btn_folder.set_current_folder(self.base_path)
+        self.btn_folder.connect_after('current-folder-changed', self.check_folder)
         table.attach(self.btn_folder, 1, 2, 0, 1)
         table.attach(AlignedLabel('<b>File name pattern:</b>'), 0, 1, 1, 2)
         model = gtk.ListStore(str)
         self.show_all()
 
 
-    def check_pattern(self, cell):
+    def check_folder(self, *args):
+        page = self.get_nth_page(1)
+        if self.btn_folder.get_filename().startswith(self.base_path):
+            self.set_page_complete(page, True)
+        else:
+            self.set_page_complete(page, False)
+            dlg_error(self, 'ERROR!',
+                      'Folder to import must be located under library base path.')
+        return True
+
+
+    def check_pattern(self, *args):
         page = self.get_nth_page(1)
         if len(self.combobox_pattern.get_active_text().strip()) > 0:
             self.set_page_complete(page, True)
 
     def on_prepare(self, assistant, *args):
         if self.get_current_page() == 2:
+            if not self.check_folder():
+                dlg_error(self, 'ERROR!',
+                          'Folder to import must be located under library base path.')
+                self.set_current_page(0)
+                return
             pattern = self.combobox_pattern.get_active_text()
             if not check_pattern(pattern):
                 dlg_error(self, 'ERROR!',
                           '<i>%s</i> is not a valid pattern, please select a valid one.' % txt2pango(pattern))
                 self.set_current_page(0)
+                return
         elif self.get_current_page() == 3:
             folder = txt2pango(self.btn_folder.get_filename())
             pattern = txt2pango(self.combobox_pattern.get_active_text())