def testTransferToRemote(self): phoneBrowser = PhoneBrowserStub() transferMgr = TransferManager(phoneBrowser) transferMgr.connect('transferscompleted', self.transfersCompletedCb) fileCollection = Directory() fileCollection.addFile(File('file1.tst', 100)) fileCollection.addFile(File('subdir/file2.tst', 200)) fileCollection.addFile(File('subdir/file3.tst', 300)) transferMgr.copyToRemote(fileCollection) self.assertEqual('file1.tst', phoneBrowser.lastFileCopied) self.assertFalse(self.transfersCompleted) phoneBrowser.emit('completed') self.assertEqual('subdir/file2.tst', phoneBrowser.lastFileCopied) self.assertFalse(self.transfersCompleted) phoneBrowser.emit('completed') self.assertEqual('subdir/file3.tst', phoneBrowser.lastFileCopied) phoneBrowser.emit('completed') self.assertTrue(self.transfersCompleted)
def __dragDataGet(self, widget, dragContext, selectionData, info, timestamp): property = dragContext.source_window.property_get(gtk.gdk.atom_intern('XdndDirectSave0'), 'text/plain', pdelete = False) if property[0] != 'text/plain' or property[1] != 8: return destinationPath = urllib.unquote(urlparse.urlparse(property[2]).path) fileCollection = Directory() items = self.__iconView.get_selected_items() for item in items: iter = self.__treeModel.get_iter(item) name = self.__treeModel.get_value(iter, 0) isDir = self.__treeModel.get_value(iter, 2) directory = Directory() if not isDir: fileSize = self.__treeModel.get_value(iter, 3) fileCollection.addFile(File(name, fileSize)) else: dir = self.__transferManager.buildDirectoryStructure(name) dir.parent = fileCollection fileCollection.addDirectory(dir) selectionData.set('text/plain', 8, 'S') self.__transferFilesToLocal(fileCollection, os.path.dirname(destinationPath)) dragContext.source_window.property_delete(gtk.gdk.atom_intern('XdndDirectSave0'))
def __iconActivated(self, widget, path): iter = self.__treeModel.iter_nth_child(None, int(path[0])) item = self.__treeModel.get_value(iter, 0) isDir = self.__treeModel.get_value(iter, 2) if isDir == True: self.__cleanNavigationBar() newButton = gtk.ToggleButton(item) newButton.set_border_width(3) newButton.connect('toggled', self.__naviGationButtonClick) self.__navigationBox.pack_start(newButton, expand=False, fill=False) newButton.set_active(True) self.__navigationBox.set_homogeneous(False) self.__navigationBox.show_all() else: chooser = gtk.FileChooserDialog( title='Choose directory', parent=self.__parent, action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) if chooser.run() == gtk.RESPONSE_OK: dir = chooser.get_filename() chooser.destroy() fileCollection = Directory() fileCollection.addFile( File(item, self.__treeModel.get_value(iter, 3))) self.__transferFilesToLocal(fileCollection, dir) else: chooser.destroy()
def __iconActivated(self, widget, path): iter = self.__treeModel.iter_nth_child(None, int(path[0])) item = self.__treeModel.get_value(iter, 0) isDir = self.__treeModel.get_value(iter, 2) if isDir == True: self.__cleanNavigationBar() newButton = gtk.ToggleButton(item) newButton.set_border_width(3) newButton.connect('toggled', self.__naviGationButtonClick) self.__navigationBox.pack_start(newButton, expand = False, fill = False) newButton.set_active(True) self.__navigationBox.set_homogeneous(False) self.__navigationBox.show_all() else: chooser = gtk.FileChooserDialog(title = 'Choose directory', parent = self.__parent, action = gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) if chooser.run() == gtk.RESPONSE_OK: dir = chooser.get_filename() chooser.destroy() fileCollection = Directory() fileCollection.addFile(File(item, self.__treeModel.get_value(iter, 3))) self.__transferFilesToLocal(fileCollection, dir) else: chooser.destroy()
def testTransferToLocal(self): phoneBrowser = PhoneBrowserStub() transferMgr = TransferManager(phoneBrowser) transferMgr.connect('transferscompleted', self.transfersCompletedCb) fileCollection = Directory('.') fileCollection.addFile(File('file1.tst', 100)) dir = Directory('subdir') dir.parent = fileCollection dir.addFile(File('subfile1.tst', 200)) dir.addFile(File('subfile2.tst', 300)) fileCollection.addDirectory(dir) transferMgr.copyToLocal(fileCollection, '.') self.assertEqual('subdir', phoneBrowser.curDir) self.assertEqual('subfile1.tst', phoneBrowser.lastFileCopied) self.assertFalse(self.transfersCompleted) phoneBrowser.emit('completed') self.assertEqual('subdir', phoneBrowser.curDir) self.assertEqual('subfile2.tst', phoneBrowser.lastFileCopied) self.assertFalse(self.transfersCompleted) phoneBrowser.emit('completed') self.assertTrue(phoneBrowser.dirUp) self.assertEqual('file1.tst', phoneBrowser.lastFileCopied) phoneBrowser.emit('completed') self.assertTrue(self.transfersCompleted)
def __dragDataReceived(self, widget, dragContext, x, y, selectionData, info, timestamp): directory = Directory() for url in selectionData.data.split('\r\n'): if len(url) > 0: filePath = urllib.unquote(urlparse.urlparse(url).path) if os.path.isdir(filePath): for root, dirs, files in os.walk(filePath): for file in files: filePath = os.path.join(root, file) directory.addFile(File(filePath, os.path.getsize(filePath))) else: directory.addFile(File(filePath, os.path.getsize(filePath))) dragContext.drop_finish(True, 0L) self.transferFilesToRemote(directory)
def __dragDataGet(self, widget, dragContext, selectionData, info, timestamp): property = dragContext.source_window.property_get( gtk.gdk.atom_intern('XdndDirectSave0'), 'text/plain', pdelete=False) if property[0] != 'text/plain' or property[1] != 8: return destinationPath = urllib.unquote(urlparse.urlparse(property[2]).path) fileCollection = Directory() items = self.__iconView.get_selected_items() for item in items: iter = self.__treeModel.get_iter(item) name = self.__treeModel.get_value(iter, 0) isDir = self.__treeModel.get_value(iter, 2) directory = Directory() if not isDir: fileSize = self.__treeModel.get_value(iter, 3) fileCollection.addFile(File(name, fileSize)) else: dir = self.__transferManager.buildDirectoryStructure(name) dir.parent = fileCollection fileCollection.addDirectory(dir) selectionData.set('text/plain', 8, 'S') self.__transferFilesToLocal(fileCollection, os.path.dirname(destinationPath)) dragContext.source_window.property_delete( gtk.gdk.atom_intern('XdndDirectSave0'))
def testTransferToLocalFilesOnly(self): phoneBrowser = PhoneBrowserStub() transferMgr = TransferManager(phoneBrowser) transferMgr.connect('transferscompleted', self.transfersCompletedCb) fileCollection = Directory('.') fileCollection.addFile(File('file1.tst', 200)) fileCollection.addFile(File('file2.tst', 300)) transferMgr.copyToLocal(fileCollection, '.') self.assertEqual('file1.tst', phoneBrowser.lastFileCopied) self.assertFalse(self.transfersCompleted) phoneBrowser.emit('completed') self.assertEqual('file2.tst', phoneBrowser.lastFileCopied) phoneBrowser.emit('completed') self.assertTrue(self.transfersCompleted)
def buildDirectoryStructure(self, directoryName = '.', parent = None): directory = Directory() directory.parent = parent directory.name = directoryName if directoryName != '.': self.__phoneBrowser.changeDirectory(directoryName) dirs, files = self.__phoneBrowser.getDirectoryListing() for file in files: directory.addFile(file) for dir in dirs: directory.addDirectory(self.buildFileCollectionFromDir(dir, directory)) if directoryName != '.': self.__phoneBrowser.directoryUp() return directory
def __dragDataReceived(self, widget, dragContext, x, y, selectionData, info, timestamp): directory = Directory() for url in selectionData.data.split('\r\n'): if len(url) > 0: filePath = urllib.unquote(urlparse.urlparse(url).path) if os.path.isdir(filePath): for root, dirs, files in os.walk(filePath): for file in files: filePath = os.path.join(root, file) directory.addFile( File(filePath, os.path.getsize(filePath))) else: directory.addFile(File(filePath, os.path.getsize(filePath))) dragContext.drop_finish(True, 0L) self.transferFilesToRemote(directory)
def testTransferToLocalDirOnly(self): phoneBrowser = PhoneBrowserStub() transferMgr = TransferManager(phoneBrowser) transferMgr.connect('transferscompleted', self.transfersCompletedCb) fileCollection = Directory('.') dir1 = Directory('subdir1') dir1.parent = fileCollection dir1.addFile(File('sub1file1.tst', 200)) dir1.addFile(File('sub1file2.tst', 300)) dir2 = Directory('subdir2') dir2.parent = fileCollection dir2.addFile(File('sub2file1.tst', 200)) dir2.addFile(File('sub2file2.tst', 300)) fileCollection.addDirectory(dir1) fileCollection.addDirectory(dir2) transferMgr.copyToLocal(fileCollection, '.') self.assertEqual('subdir1', phoneBrowser.curDir) self.assertEqual('sub1file1.tst', phoneBrowser.lastFileCopied) self.assertFalse(self.transfersCompleted) self.assertTrue(os.path.exists('subdir1')) self.assertTrue(os.path.isdir('subdir1')) phoneBrowser.emit('completed') self.assertEqual('subdir1', phoneBrowser.curDir) self.assertEqual('sub1file2.tst', phoneBrowser.lastFileCopied) self.assertFalse(self.transfersCompleted) phoneBrowser.emit('completed') self.assertTrue(phoneBrowser.dirUp) self.assertEqual('subdir2', phoneBrowser.curDir) self.assertEqual('sub2file1.tst', phoneBrowser.lastFileCopied) self.assertTrue(os.path.exists('subdir2')) self.assertTrue(os.path.isdir('subdir2')) phoneBrowser.emit('completed') self.assertEqual('subdir2', phoneBrowser.curDir) self.assertEqual('sub2file2.tst', phoneBrowser.lastFileCopied) phoneBrowser.emit('completed') self.assertTrue(self.transfersCompleted)
def testGetSize(self): dir = Directory('subdir') dir.addFile(File('subfile1.tst', 200)) dir.addFile(File('subfile2.tst', 300)) fileCollection = Directory() fileCollection.addFile(File('file1.tst', 100)) fileCollection.addDirectory(dir) self.assertEqual(600, fileCollection.getSize())