def getFromAmarok(self): try: import Amarok Dialogs.showState(translate("CoverTable", "Checking For Amarok..."), 0, 1) if Amarok.checkAmarok(): from Amarok import Operations directoriesAndValues = Operations.getDirectoriesAndValues() Dialogs.showState(translate("CoverTable", "Values Are Being Processed"), 1, 1) if directoriesAndValues is not None: for rowNo in range(self.rowCount()): if (getMainWindow().checkHiddenColumn("sourceCover") and getMainWindow().checkHiddenColumn("destinationCover")): if self.isChangeableItem(rowNo, "sourceCover"): directoryPath = fu.joinPath( fu.getDirName(fu.getDirName(self.values[rowNo]["path"])), str(self.item(rowNo, 0).text()), str(self.item(rowNo, 1).text())) if directoryPath in directoriesAndValues: directoryAndValues = directoriesAndValues[directoryPath] self.item(rowNo, 3).setText( directoryAndValues["coverPath"][0].replace(directoryPath, ".")) self.item(rowNo, 4).setText("./" + Organizer.getIconName( directoryAndValues["artist"][0], directoryAndValues["album"][0], directoryAndValues["genre"][0], directoryAndValues["year"][0])) except: ReportBug.ReportBug()
def changeFilePath(_oldPath, _newPath): _oldPath, _newPath = str(_oldPath), str(_newPath) withOutDevicePointValues, withOutDeviceValues = [], [] for devicePoint in getDevices(): if devicePoint[1] + "/" == _oldPath[:len(devicePoint[1]) + 1]: if devicePoint[1] + "/" == _newPath[:len(devicePoint[1]) + 1]: withOutDevicePointValues.append({"id": devicePoint[0], "oldPath": Databases.correctForSql(_oldPath[len(devicePoint[1]):]), "newPath": Databases.correctForSql(_newPath[len(devicePoint[1]):]) }) else: withOutDeviceValues.append({"id": devicePoint[0], "oldPath": Databases.correctForSql(_oldPath[len(devicePoint[1]):]), "newPath": Databases.correctForSql(_newPath) }) _oldPath, _newPath = Databases.correctForSql(_oldPath), Databases.correctForSql(_newPath) _oldPathUrl, _newPathUrl = Databases.correctForSql(Organizer.quote(_oldPath)), Databases.correctForSql(Organizer.quote(_newPath)) db = Amarok.checkAndGetDB() db.query("UPDATE urls SET rpath='.%s' WHERE rpath='.%s'" % (_newPath, _oldPath)) for withOutDevice in withOutDeviceValues: directoryID = getOrInsertDirectory(fu.getDirName(withOutDevice["newPath"]), "-1") db.query("UPDATE urls SET rpath='.%s', directory=%s, deviceid = -1 WHERE deviceid = %s and rpath = '.%s' " % ( withOutDevice["newPath"], directoryID, withOutDevice["id"], withOutDevice["oldPath"])) for withOutDevicePoint in withOutDevicePointValues: directoryID = getOrInsertDirectory(fu.getDirName(withOutDevicePoint["newPath"]), withOutDevicePoint["id"]) db.query("UPDATE urls SET rpath='.%s', directory=%s WHERE deviceid = %s and rpath = '.%s'" % ( withOutDevicePoint["newPath"], directoryID, withOutDevicePoint["id"], withOutDevicePoint["oldPath"])) db.query("UPDATE images SET path='%s' WHERE path='%s'" % (_newPath, _oldPath)) db.query("UPDATE lyrics SET url='.%s' WHERE url='.%s'" % (_newPath, _oldPath)) db.query("UPDATE statistics_permanent SET url='file://%s' WHERE url='file://%s'" % (_newPathUrl, _oldPathUrl)) db.commit() return True
def readMusicFile(_filePath, _isAlertWhenNotAvailable=True): _directoryPath = fu.getDirName(_filePath) isCanNoncompatible = False if fu.isReadableFileOrDir(_filePath): tagger = Taggers.getTagger() try: tagger.loadFile(_filePath) except: Dialogs.showError(translate("FileUtils/Musics", "Incorrect Tag"), str(translate("FileUtils/Musics", "\"%s\" : this file has the incorrect tag so can't read tags.") ) % Organizer.getLink(_filePath)) if tagger.isAvailableFile() is False: isCanNoncompatible = True content = {} content["path"] = _filePath content["baseNameOfDirectory"] = fu.getBaseName(_directoryPath) content["baseName"] = fu.getBaseName(_filePath) content["artist"] = tagger.getArtist() content["title"] = tagger.getTitle() content["album"] = tagger.getAlbum() content["albumArtist"] = tagger.getAlbumArtist() content["trackNum"] = tagger.getTrackNum() content["year"] = tagger.getYear() content["genre"] = tagger.getGenre() content["firstComment"] = tagger.getFirstComment() content["firstLyrics"] = tagger.getFirstLyrics() content["images"] = tagger.getImages() if isCanNoncompatible and _isAlertWhenNotAvailable: Dialogs.show(translate("FileUtils/Musics", "Possible ID3 Mismatch"), translate("FileUtils/Musics", "Some of the files presented in the table may not support ID3 technology.<br>Please check the files and make sure they support ID3 information before proceeding.")) return content
def willDownload(self, _request): try: defaultFileName = str(MFileInfo(str(trStr(_request.url()))).fileName()) fileDialogTitle = translate("UpdateControl", "You Can Click Cancel To Update Without Saving The Package.") if self.isNotInstall: fileDialogTitle = translate("UpdateControl", "Save New Version Of Hamsi Manager") fileName = Dialogs.getSaveFileName(fileDialogTitle, fu.joinPath(fu.getDirName(fu.HamsiManagerDirectory), defaultFileName)) if self.isNotInstall is False or fileName is not None: if fileName is None: import random fileName = fu.joinPath(fu.getTempDir(), defaultFileName[:-7] + "-" + str( random.randrange(0, 1000000)) + defaultFileName[-7:]) self.pbtnDownloadAndInstall.setEnabled(False) newRequest = _request newRequest.setAttribute(MNetworkRequest.User, trQVariant(fileName)) networkManager = self.wvWeb.page().networkAccessManager() reply = networkManager.get(newRequest) self.isFileExist = True self.connect(reply, SIGNAL("downloadProgress(qint64,qint64)"), self.downloading) self.connect(reply, SIGNAL("finished()"), self.downloaded) self.connect(reply, SIGNAL("error(QNetworkReply::NetworkError)"), self.errorOccurred) except: ReportBug.ReportBug()
def changeFile(self, _filePath, _isNew=False): self.fileValues = fu.readTextFile(_filePath, uni.MySettings["fileSystemEncoding"]) self.setWindowTitle(str(fu.getBaseName(self.fileValues["path"]))) if self.pnlClearable is not None: clearAllChildren(self.pnlClearable, True) self.pnlClearable = MWidget() self.vblMain.insertWidget(0, self.pnlClearable, 20) vblClearable = MVBoxLayout(self.pnlClearable) self.infoLabels["path"] = MLabel(self.labels[0]) self.infoLabels["content"] = MLabel(self.labels[1]) dirPath = fu.getDirName(self.fileValues["path"]) baseName = fu.getBaseName(self.fileValues["path"]) self.infoValues["path"] = MLineEdit(str(fu.joinPath(dirPath, Organizer.emend(baseName, "file")))) self.infoValues["content"] = MPlainTextEdit( str(Organizer.emend(self.fileValues["content"], "text", False, True))) self.infoValues["content"].setLineWrapMode(MPlainTextEdit.NoWrap) self.sourceCharSet = MComboBox() self.sourceCharSet.addItems(uni.getCharSets()) self.sourceCharSet.setCurrentIndex(self.sourceCharSet.findText(uni.MySettings["fileSystemEncoding"])) MObject.connect(self.sourceCharSet, SIGNAL("currentIndexChanged(int)"), self.sourceCharSetChanged) HBOXs = [] HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["path"]) HBOXs[-1].addWidget(self.infoValues["path"]) HBOXs[-1].addWidget(self.sourceCharSet) for hbox in HBOXs: vblClearable.addLayout(hbox) vblClearable.addWidget(self.infoLabels["content"]) vblClearable.addWidget(self.infoValues["content"])
def createPage(self, _pageNo): pnlPage = MWidget() HBox = MHBoxLayout() pnlPage.setLayout(HBox) if _pageNo == 0: VBox = MVBoxLayout() self.lblAreYouSure = MLabel( translate( "Uninstall", "Are you sure you want to uninstall Hamsi Manager?")) VBox.addStretch(10) VBox.addWidget(self.lblAreYouSure) VBox.addStretch(10) HBox.addLayout(VBox) if _pageNo == 1: lblPleaseSelect = MLabel( translate( "Uninstall", "Please Select Directory Of Hamsi Manager To Uninstall." )) UninstallationDirPath = fu.getDirName( str( Settings.getUniversalSetting( "HamsiManagerPath", str(fu.HamsiManagerDirectory)))) self.leUninstallationDirectory = MLineEdit( str( Settings.getUniversalSetting( "pathOfInstallationDirectory", str(UninstallationDirPath)))) self.pbtnSelectUninstallationDirectory = MPushButton( translate("Uninstall", "Browse")) self.connect(self.pbtnSelectUninstallationDirectory, SIGNAL("clicked()"), self.selectUninstallationDirectory) VBox = MVBoxLayout() VBox.addStretch(2) VBox.addWidget(lblPleaseSelect) HBox1 = MHBoxLayout() HBox1.addWidget(self.leUninstallationDirectory) HBox1.addWidget(self.pbtnSelectUninstallationDirectory) VBox.addLayout(HBox1) VBox.addStretch(2) HBox.addLayout(VBox) elif _pageNo == 2: import MyPlugins self.lblFinished = MLabel( translate("Uninstall", "Uninstallation Completed.")) VBox = MVBoxLayout() VBox.addStretch(2) VBox.addWidget(self.lblFinished) VBox.addStretch(2) wPlugins = MyPlugins.MyPluginsForSystem(pnlPage, "uninstall") VBox.addWidget(wPlugins) VBox.addStretch(2) HBox.addLayout(VBox) return pnlPage
def writeMusicFile(_oldMusicTagsValues, _newMusicTagsValues, _isImageAction=False, _ImageType=False, _ImagePath=False, _imageDescription=u""): if fu.isWritableFileOrDir(_oldMusicTagsValues["path"]): baseNameOfDirectory = _oldMusicTagsValues["baseNameOfDirectory"] baseName = _oldMusicTagsValues["baseName"] tagger = Taggers.getTagger() tagger.loadFileForWrite(_oldMusicTagsValues["path"]) if _isImageAction is False: if _newMusicTagsValues["artist"] != _oldMusicTagsValues["artist"]: tagger.setArtist(str(_newMusicTagsValues["artist"])) if _newMusicTagsValues["title"] != _oldMusicTagsValues["title"]: tagger.setTitle(str(_newMusicTagsValues["title"])) if _newMusicTagsValues["album"] != _oldMusicTagsValues["album"]: tagger.setAlbum(str(_newMusicTagsValues["album"])) if _newMusicTagsValues["albumArtist"] != _oldMusicTagsValues["albumArtist"]: tagger.setAlbumArtist(str(_newMusicTagsValues["albumArtist"])) if _newMusicTagsValues["trackNum"] != _oldMusicTagsValues["trackNum"]: tagger.setTrackNum(_newMusicTagsValues["trackNum"]) if _newMusicTagsValues["year"] != _oldMusicTagsValues["year"]: tagger.setDate(str(_newMusicTagsValues["year"])) if _newMusicTagsValues["genre"] != _oldMusicTagsValues["genre"]: tagger.setGenre(str(_newMusicTagsValues["genre"])) if _newMusicTagsValues["firstComment"] != _oldMusicTagsValues["firstComment"]: tagger.setFirstComment(str(_newMusicTagsValues["firstComment"])) if _newMusicTagsValues["firstLyrics"] != _oldMusicTagsValues["firstLyrics"]: tagger.setFirstLyrics(str(_newMusicTagsValues["firstLyrics"])) tagger.update() if _newMusicTagsValues["baseNameOfDirectory"] != _oldMusicTagsValues["baseNameOfDirectory"]: baseNameOfDirectory = str(_newMusicTagsValues["baseNameOfDirectory"]) if _newMusicTagsValues["baseName"] != _oldMusicTagsValues["baseName"]: baseName = str(_newMusicTagsValues["baseName"]) newFilePath = fu.joinPath(fu.getDirName(fu.getDirName(_oldMusicTagsValues["path"])), baseNameOfDirectory, baseName) if fu.getRealPath(_oldMusicTagsValues["path"]) != fu.getRealPath(newFilePath): return fu.moveOrChange(_oldMusicTagsValues["path"], newFilePath, fu.getObjectType(_oldMusicTagsValues["path"])) #Making changes on image files else: if _ImagePath is False: tagger.removeImage(_imageDescription) else: tagger.addImage(_ImageType, _ImagePath, _imageDescription) tagger.update() return None return _oldMusicTagsValues["path"]
def selectImage(self): try: imagePath = Dialogs.getOpenFileName(translate("MusicDetails", "Choose Image"), fu.getDirName(self.musicValues["path"]), str( translate("MusicDetails", "Images")) + " " + uni.imageExtStringOnlyPNGAndJPG, 0) if imagePath is not None: self.leImagePath.setText(imagePath) except: ReportBug.ReportBug()
def selectImage(self): try: imagePath = Dialogs.getOpenFileName( translate("MusicDetails", "Choose Image"), fu.getDirName(self.musicValues["path"]), str(translate("MusicDetails", "Images")) + " " + uni.imageExtStringOnlyPNGAndJPG, 0) if imagePath is not None: self.leImagePath.setText(imagePath) except: ReportBug.ReportBug()
def getFromAmarok(self): try: import Amarok Dialogs.showState( translate("CoverTable", "Checking For Amarok..."), 0, 1) if Amarok.checkAmarok(): from Amarok import Operations directoriesAndValues = Operations.getDirectoriesAndValues() Dialogs.showState( translate("CoverTable", "Values Are Being Processed"), 1, 1) if directoriesAndValues is not None: for rowNo in range(self.rowCount()): if (getMainWindow().checkHiddenColumn("sourceCover") and getMainWindow().checkHiddenColumn( "destinationCover")): if self.isChangeableItem(rowNo, "sourceCover"): directoryPath = fu.joinPath( fu.getDirName( fu.getDirName( self.values[rowNo]["path"])), str(self.item(rowNo, 0).text()), str(self.item(rowNo, 1).text())) if directoryPath in directoriesAndValues: directoryAndValues = directoriesAndValues[ directoryPath] self.item(rowNo, 3).setText( directoryAndValues["coverPath"] [0].replace(directoryPath, ".")) self.item(rowNo, 4).setText( "./" + Organizer.getIconName( directoryAndValues["artist"][0], directoryAndValues["album"][0], directoryAndValues["genre"][0], directoryAndValues["year"][0])) except: ReportBug.ReportBug()
def saveAsImage(self): try: if self.lstwImages.currentRow() != -1: imagePath = Dialogs.getSaveFileName(translate("MusicDetails", "Save As"), fu.getDirName(self.musicValues["path"]), str(translate("MusicDetails", "Images (*.%s)")) % (str( self.musicValues["images"][self.lstwImages.currentRow()][ 2]).split("/")[1]), 0) if imagePath is not None: sourceFile = fu.joinPath(fu.getTempDir(), "HamsiManager-image-file." + self.musicValues["images"][self.lstwImages.currentRow()][2].split("/")[1]) fu.writeToBinaryFile(sourceFile, self.musicValues["images"][self.lstwImages.currentRow()][3]) fu.moveOrChange(sourceFile, imagePath) except: ReportBug.ReportBug()
def createPage(self, _pageNo): pnlPage = MWidget() HBox = MHBoxLayout() pnlPage.setLayout(HBox) if _pageNo == 0: VBox = MVBoxLayout() self.lblAreYouSure = MLabel(translate("Uninstall", "Are you sure you want to uninstall Hamsi Manager?")) VBox.addStretch(10) VBox.addWidget(self.lblAreYouSure) VBox.addStretch(10) HBox.addLayout(VBox) if _pageNo == 1: lblPleaseSelect = MLabel( translate("Uninstall", "Please Select Directory Of Hamsi Manager To Uninstall.")) UninstallationDirPath = fu.getDirName( str(Settings.getUniversalSetting("HamsiManagerPath", str(fu.HamsiManagerDirectory)))) self.leUninstallationDirectory = MLineEdit( str(Settings.getUniversalSetting("pathOfInstallationDirectory", str(UninstallationDirPath)))) self.pbtnSelectUninstallationDirectory = MPushButton(translate("Uninstall", "Browse")) self.connect(self.pbtnSelectUninstallationDirectory, SIGNAL("clicked()"), self.selectUninstallationDirectory) VBox = MVBoxLayout() VBox.addStretch(2) VBox.addWidget(lblPleaseSelect) HBox1 = MHBoxLayout() HBox1.addWidget(self.leUninstallationDirectory) HBox1.addWidget(self.pbtnSelectUninstallationDirectory) VBox.addLayout(HBox1) VBox.addStretch(2) HBox.addLayout(VBox) elif _pageNo == 2: import MyPlugins self.lblFinished = MLabel(translate("Uninstall", "Uninstallation Completed.")) VBox = MVBoxLayout() VBox.addStretch(2) VBox.addWidget(self.lblFinished) VBox.addStretch(2) wPlugins = MyPlugins.MyPluginsForSystem(pnlPage, "uninstall") VBox.addWidget(wPlugins) VBox.addStretch(2) HBox.addLayout(VBox) return pnlPage
def saveAsImage(self): try: if self.lstwImages.currentRow() != -1: imagePath = Dialogs.getSaveFileName( translate("MusicDetails", "Save As"), fu.getDirName(self.musicValues["path"]), str(translate("MusicDetails", "Images (*.%s)")) % (str(self.musicValues["images"][ self.lstwImages.currentRow()][2]).split("/")[1]), 0) if imagePath is not None: sourceFile = fu.joinPath( fu.getTempDir(), "HamsiManager-image-file." + self.musicValues["images"] [self.lstwImages.currentRow()][2].split("/")[1]) fu.writeToBinaryFile( sourceFile, self.musicValues["images"][ self.lstwImages.currentRow()][3]) fu.moveOrChange(sourceFile, imagePath) except: ReportBug.ReportBug()
def willDownload(self, _request): try: defaultFileName = str( MFileInfo(str(trStr(_request.url()))).fileName()) fileDialogTitle = translate( "UpdateControl", "You Can Click Cancel To Update Without Saving The Package.") if self.isNotInstall: fileDialogTitle = translate( "UpdateControl", "Save New Version Of Hamsi Manager") fileName = Dialogs.getSaveFileName( fileDialogTitle, fu.joinPath(fu.getDirName(fu.HamsiManagerDirectory), defaultFileName)) if self.isNotInstall is False or fileName is not None: if fileName is None: import random fileName = fu.joinPath( fu.getTempDir(), defaultFileName[:-7] + "-" + str(random.randrange(0, 1000000)) + defaultFileName[-7:]) self.pbtnDownloadAndInstall.setEnabled(False) newRequest = _request newRequest.setAttribute(MNetworkRequest.User, trQVariant(fileName)) networkManager = self.wvWeb.page().networkAccessManager() reply = networkManager.get(newRequest) self.isFileExist = True self.connect(reply, SIGNAL("downloadProgress(qint64,qint64)"), self.downloading) self.connect(reply, SIGNAL("finished()"), self.downloaded) self.connect(reply, SIGNAL("error(QNetworkReply::NetworkError)"), self.errorOccurred) except: ReportBug.ReportBug()
def refreshTable(self, _path): self.values = [] self.setColumnWidth(6, 70) self.setColumnWidth(7, 40) uni.startThreadAction() import Amarok Dialogs.showState(translate("AmarokMusicTable", "Getting Values From Amarok"), 0, 1) if Amarok.checkAmarok(): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: from Amarok import Operations musicFileValuesWithNames = Operations.getAllMusicFileValuesWithNames( uni.MySettings[self.amarokFilterKeyName]) Dialogs.showState(translate("AmarokMusicTable", "Values Are Being Processed"), 1, 1) isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: if musicFileValuesWithNames is not None: allItemNumber = len(musicFileValuesWithNames) self.setRowCount(allItemNumber) rowNo = 0 for musicFileRow in musicFileValuesWithNames: isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: if (fu.isFile(musicFileRow["filePath"]) and fu.isReadableFileOrDir(musicFileRow["filePath"], False, True)): details = fu.getDetails(musicFileRow["filePath"]) content = {} if Amarok.getSelectedTagSourseType("AmarokCopyTable") == "Amarok (Smart)": content["path"] = musicFileRow["filePath"] content["baseNameOfDirectory"] = fu.getBaseName( fu.getDirName(musicFileRow["filePath"])) content["baseName"] = fu.getBaseName(musicFileRow["filePath"]) content["artist"] = musicFileRow["artist"] content["title"] = musicFileRow["title"] content["album"] = musicFileRow["album"] content["albumArtist"] = musicFileRow["albumArtist"] content["trackNum"] = musicFileRow["trackNumber"] content["year"] = musicFileRow["year"] content["genre"] = musicFileRow["genre"] content["firstComment"] = musicFileRow["comment"] content["firstLyrics"] = musicFileRow["lyrics"] tagger = Taggers.getTagger() try: tagger.loadFile(musicFileRow["filePath"]) except: if tagger.isSupportInfo: content["length"] = "" content["bitrate"] = "" content["sampleRate"] = "" content["mode"] = "" else: if content["artist"].strip() == "": content["artist"] = tagger.getArtist() if content["title"].strip() == "": content["title"] = tagger.getTitle() if content["album"].strip() == "": content["album"] = tagger.getAlbum() if content["albumArtist"].strip() == "": content["albumArtist"] = tagger.getAlbumArtist() if str(content["trackNum"]).strip() == "": content["trackNum"] = tagger.getTrackNum() if str(content["year"]).strip() == "": content["year"] = tagger.getYear() if content["genre"].strip() == "": content["genre"] = tagger.getGenre() if content["firstComment"].strip() == "": content["firstComment"] = tagger.getFirstComment() if content["firstLyrics"].strip() == "": content["firstLyrics"] = tagger.getFirstLyrics() if tagger.isSupportInfo: content["length"] = tagger.getLength() content["bitrate"] = tagger.getBitrate() content["sampleRate"] = tagger.getSampleRate() content["mode"] = tagger.getMode() elif Amarok.getSelectedTagSourseType("AmarokCopyTable") == "Only Amarok": content["path"] = musicFileRow["filePath"] content["baseNameOfDirectory"] = "" content["baseName"] = fu.getBaseName(musicFileRow["filePath"]) content["artist"] = musicFileRow["artist"] content["title"] = musicFileRow["title"] content["album"] = musicFileRow["album"] content["albumArtist"] = musicFileRow["albumArtist"] content["trackNum"] = musicFileRow["trackNumber"] content["year"] = musicFileRow["year"] content["genre"] = musicFileRow["genre"] content["firstComment"] = musicFileRow["comment"] content["firstLyrics"] = musicFileRow["lyrics"] tagger = Taggers.getTagger() if tagger.isSupportInfo: try: tagger.loadFile(musicFileRow["filePath"]) except: content["length"] = "" content["bitrate"] = "" content["sampleRate"] = "" content["mode"] = "" else: content["length"] = tagger.getLength() content["bitrate"] = tagger.getBitrate() content["sampleRate"] = tagger.getSampleRate() content["mode"] = tagger.getMode() else: tagger = Taggers.getTagger() try: tagger.loadFile(musicFileRow["filePath"]) except: Dialogs.showError(translate("FileUtils/Musics", "Incorrect Tag"), str(translate("FileUtils/Musics", "\"%s\" : this file has the incorrect tag so can't read tags.") ) % Organizer.getLink(musicFileRow["filePath"])) content["path"] = musicFileRow["filePath"] content["baseNameOfDirectory"] = "" content["baseName"] = fu.getBaseName(musicFileRow["filePath"]) content["artist"] = tagger.getArtist() content["title"] = tagger.getTitle() content["album"] = tagger.getAlbum() content["albumArtist"] = tagger.getAlbumArtist() content["trackNum"] = tagger.getTrackNum() content["year"] = tagger.getYear() content["genre"] = tagger.getGenre() content["firstComment"] = tagger.getFirstComment() content["firstLyrics"] = tagger.getFirstLyrics() if tagger.isSupportInfo: content["length"] = tagger.getLength() content["bitrate"] = tagger.getBitrate() content["sampleRate"] = tagger.getSampleRate() content["mode"] = tagger.getMode() content["size"] = details[stat.ST_SIZE] content["lastAccessed"] = details[stat.ST_ATIME] content["lastModified"] = details[stat.ST_MTIME] content["lastMetadataChanged"] = details[stat.ST_CTIME] self.values.append(content) newBaseNameOfDirectory = Organizer.emend( self.values[rowNo]["baseNameOfDirectory"], "directory") self.createItem(rowNo, "baseNameOfDirectory", newBaseNameOfDirectory, self.values[rowNo]["baseNameOfDirectory"]) newBaseName = Organizer.emend(self.values[rowNo]["baseName"], "file") self.createItem(rowNo, "baseName", newBaseName, self.values[rowNo]["baseName"]) newArtist = Organizer.emend(self.values[rowNo]["artist"]) self.createItem(rowNo, "artist", newArtist, self.values[rowNo]["artist"]) newTitle = Organizer.emend(self.values[rowNo]["title"]) self.createItem(rowNo, "title", newTitle, self.values[rowNo]["title"]) newAlbum = Organizer.emend(self.values[rowNo]["album"]) self.createItem(rowNo, "album", newAlbum, self.values[rowNo]["album"]) newAlbumArtist = Organizer.emend(self.values[rowNo]["albumArtist"]) self.createItem(rowNo, "albumArtist", newAlbumArtist, self.values[rowNo]["albumArtist"]) newTrackNum = str(self.values[rowNo]["trackNum"]) self.createItem(rowNo, "trackNum", newTrackNum, self.values[rowNo]["trackNum"]) newYear = Organizer.emend(self.values[rowNo]["year"]) self.createItem(rowNo, "year", newYear, self.values[rowNo]["year"]) newGenre = Organizer.emend(self.values[rowNo]["genre"]) self.createItem(rowNo, "genre", newGenre, self.values[rowNo]["genre"]) newFirstComment = Organizer.emend(self.values[rowNo]["firstComment"]) self.createItem(rowNo, "firstComment", newFirstComment, self.values[rowNo]["firstComment"]) newFirstLyrics = Organizer.emend(self.values[rowNo]["firstLyrics"]) self.createItem(rowNo, "firstLyrics", newFirstLyrics, self.values[rowNo]["firstLyrics"]) if Taggers.getTagger().isSupportInfo: self.createItem(rowNo, "length", content["length"]) self.createItem(rowNo, "bitrate", content["bitrate"]) self.createItem(rowNo, "sampleRate", content["sampleRate"]) self.createItem(rowNo, "mode", content["mode"]) self.createItem(rowNo, "size", Organizer.getCorrectedFileSize(content["size"])) self.createItem(rowNo, "lastAccessed", Organizer.getCorrectedTime(content["lastAccessed"])) self.createItem(rowNo, "lastModified", Organizer.getCorrectedTime(content["lastModified"])) self.createItem(rowNo, "lastMetadataChanged", Organizer.getCorrectedTime(content["lastMetadataChanged"])) rowNo += 1 else: allItemNumber -= 1 except: ReportBug.ReportBug() allItemNumber -= 1 else: allItemNumber = rowNo Dialogs.showState(translate("Tables", "Generating Table..."), rowNo, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() self.setRowCount(len(self.values)) # In case of Non Readable Files and Canceled process
def writeContents(self): self.changedValueNumber = 0 oldAndNewPathValues = [] startRowNo, rowStep = 0, 1 uni.startThreadAction() allItemNumber = len(self.values) Dialogs.showState(translate("FileUtils/Covers", "Writing Cover Informations"), 0, allItemNumber, True) for rowNo in range(startRowNo, self.rowCount(), rowStep): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: if fu.isWritableFileOrDir(self.values[rowNo]["path"], False, True): if self.isRowHidden(rowNo): fu.removeFileOrDir(self.values[rowNo]["path"]) self.changedValueNumber += 1 else: pathOfParentDirectory = str( self.values[rowNo]["pathOfParentDirectory"]) baseName = str(self.values[rowNo]["baseName"]) if self.isChangeableItem(rowNo, "sourceCover") or self.isChangeableItem(rowNo, "destinationCover"): sourcePath = self.values[rowNo]["sourceCover"] destinationPath = self.values[rowNo]["destinationCover"] if self.isChangeableItem(rowNo, "sourceCover"): sourcePath = str(self.item(rowNo, 3).text()).strip() if self.isChangeableItem(rowNo, "destinationCover"): destinationPath = str(self.item(rowNo, 4).text()).strip() if (str(self.item(rowNo, 2).text()) != sourcePath or sourcePath != destinationPath or str( self.item(rowNo, 2).text()) != destinationPath) or ( str(self.item(rowNo, 2).text()) != self.values[rowNo]["currentCover"] and ( str(self.item(rowNo, 2).text()) != sourcePath and str( self.item(rowNo, 2).text()) != destinationPath)): if str(self.item(rowNo, 3).text()).strip() != "": sourcePath = fu.getRealPath(sourcePath, self.values[rowNo]["path"]) sourcePath = fu.checkSource(sourcePath, "file") if sourcePath is not None: if destinationPath != "": destinationPath = fu.getRealPath(destinationPath, self.values[ rowNo]["path"]) if sourcePath != destinationPath: destinationPath = fu.moveOrChange(sourcePath, destinationPath) else: destinationPath = sourcePath fu.setIconToDirectory(self.values[rowNo]["path"], destinationPath) self.changedValueNumber += 1 else: fu.setIconToDirectory(self.values[rowNo]["path"], "") self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "baseNameOfDirectory", pathOfParentDirectory): pathOfParentDirectory = str(self.item(rowNo, 0).text()) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "baseName", baseName, False): baseName = str(self.item(rowNo, 1).text()) self.changedValueNumber += 1 newFilePath = fu.joinPath(pathOfParentDirectory, baseName) oldFilePath = fu.getRealPath(self.values[rowNo]["path"]) newFilePath = fu.getRealPath(newFilePath) if oldFilePath != newFilePath: oldAndNewPaths = {} oldAndNewPaths["oldPath"] = oldFilePath oldAndNewPaths["newPath"] = fu.moveOrChange(oldFilePath, newFilePath, "directory") if oldFilePath != oldAndNewPaths["newPath"]: oldAndNewPathValues.append(oldAndNewPaths) oldDirName = fu.getDirName(oldFilePath) if uni.getBoolValue("isClearEmptyDirectoriesWhenFileMove"): fu.checkEmptyDirectories(oldDirName, True, True, uni.getBoolValue("isAutoCleanSubFolderWhenFileMove")) except: ReportBug.ReportBug() else: allItemNumber = rowNo + 1 Dialogs.showState(translate("FileUtils/Covers", "Writing Cover Informations"), rowNo + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() if len(oldAndNewPathValues) > 0: from Amarok import Operations Operations.changePaths(oldAndNewPathValues) return True
def refreshTable(self, _path): self.values = [] uni.startThreadAction() import Amarok Dialogs.showState( translate("AmarokMusicTable", "Getting Values From Amarok"), 0, 1) if Amarok.checkAmarok(): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: from Amarok import Operations directoriesAndValues = Operations.getDirectoriesAndValues( uni.MySettings[self.amarokFilterKeyName]) Dialogs.showState( translate("AmarokMusicTable", "Values Are Being Processed"), 1, 1) isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: if directoriesAndValues is not None: allItemNumber = len(directoriesAndValues) self.setRowCount(allItemNumber) rowNo = 0 for dirPath, dirRow in directoriesAndValues.items(): isContinueThreadAction = uni.isContinueThreadAction( ) if isContinueThreadAction: try: if fu.isReadableFileOrDir( dirPath, False, True) and fu.isReadableFileOrDir( fu.joinPath( dirPath, ".directory"), False, True): content = {} content["path"] = dirPath content[ "pathOfParentDirectory"] = fu.getDirName( dirPath) content["baseName"] = fu.getBaseName( dirPath) currentCover, isCorrectedFileContent = fu.getIconFromDirectory( dirPath) if currentCover is None: currentCover = "" content["currentCover"] = ( currentCover) content["sourceCover"] = ( dirRow["coverPath"][0].replace( dirPath, ".")) content["destinationCover"] = ( "./" + Organizer.getIconName( dirRow["artist"][0], dirRow["album"][0], dirRow["genre"][0], dirRow["year"][0])) content["flagColor"] = {} if isCorrectedFileContent is False: content["flagColor"][ "currentCover"] = 255, 163, 163 if fu.isFile(content["sourceCover"] ) is False: content["flagColor"][ "sourceCover"] = 255, 163, 163 self.values.append(content) newPathOfParentDirectory = Organizer.emend( self.values[rowNo] ["pathOfParentDirectory"], "directory") self.createItem( rowNo, "pathOfParentDirectory", newPathOfParentDirectory, self.values[rowNo] ["pathOfParentDirectory"]) newBaseName = Organizer.emend( self.values[rowNo]["baseName"], "directory") self.createItem( rowNo, "pathOfParentDirectory", newBaseName, self.values[rowNo]["baseName"]) newCurrentCover = fu.getShortPath( self.values[rowNo]["currentCover"], self.values[rowNo]["path"]) itemCurrentCover = self.createItem( rowNo, "currentCover", newCurrentCover, newCurrentCover, True) self.setItemColor( itemCurrentCover, rowNo, 2, "currentCover") newSourceCover = fu.getShortPath( self.values[rowNo]["sourceCover"], self.values[rowNo]["path"]) itemSourceCover = self.createItem( rowNo, "sourceCover", newSourceCover, fu.getShortPath( self.values[rowNo] ["currentCover"], self.values[rowNo]["path"])) self.setItemColor( itemSourceCover, rowNo, 3, "sourceCover") newDestinationCover = Organizer.emend( fu.getShortPath( self.values[rowNo] ["destinationCover"], self.values[rowNo]["path"]), "file") itemDestinationCover = self.createItem( rowNo, "destinationCover", newDestinationCover, fu.getShortPath( self.values[rowNo] ["currentCover"], self.values[rowNo]["path"])) self.setItemColor( itemDestinationCover, rowNo, 4, "destinationCover") rowNo += 1 else: allItemNumber -= 1 except: ReportBug.ReportBug() allItemNumber -= 1 else: allItemNumber = rowNo Dialogs.showState( translate("Tables", "Generating Table..."), rowNo, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() self.setRowCount(len( self.values)) # In case of Non Readable Files and Canceled process
def refreshTable(self, _path): self.values = [] allFilesAndDirectories = fu.readDirectoryWithSubDirectoriesThread(_path, int(uni.MySettings["CoversSubDirectoryDeep"]), "directory", uni.getBoolValue("isShowHiddensInCoverTable")) allItemNumber = len(allFilesAndDirectories) uni.startThreadAction() rowNo = 0 self.setRowCount(allItemNumber) for dirName in allFilesAndDirectories: isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: if fu.isReadableFileOrDir(dirName, False, True) and fu.isReadableFileOrDir( fu.joinPath(dirName, ".directory"), False, True): content = {} content["path"] = dirName content["baseNameOfDirectory"] = str(str(fu.getBaseName(_path)) + str(fu.getDirName(dirName)).replace(_path, "")) content["baseName"] = fu.getBaseName(dirName) currentCover, isCorrectedFileContent = fu.getIconFromDirectory(dirName) selectedName = None if isCorrectedFileContent and currentCover is not None: selectedName = fu.getBaseName(currentCover) sourceCover = fu.getFirstImageInDirectory(dirName, selectedName, False, False) if currentCover is None: currentCover = "" if sourceCover is None: sourceCover = "" else: sourceCover = fu.joinPath(dirName, sourceCover) content["currentCover"] = (currentCover) content["sourceCover"] = (sourceCover) content["destinationCover"] = (sourceCover) content["isCorrectedFileContent"] = (isCorrectedFileContent) self.values.append(content) newBaseNameOfDirectory = Organizer.emend(self.values[rowNo]["baseNameOfDirectory"], "directory") self.createItem(rowNo, "baseNameOfDirectory", newBaseNameOfDirectory, self.values[rowNo]["baseNameOfDirectory"]) newBaseName = Organizer.emend(self.values[rowNo]["baseName"], "directory") self.createItem(rowNo, "baseName", newBaseName, self.values[rowNo]["baseName"]) newCurrentCover = str(self.values[rowNo]["currentCover"]) newCurrentCover = newCurrentCover.replace(self.values[rowNo]["path"], ".") itemCurrentCover = self.createItem(rowNo, "currentCover", newCurrentCover, newCurrentCover, True) if self.values[rowNo]["isCorrectedFileContent"] is False: itemCurrentCover.setBackground(MBrush(MColor(255, 163, 163))) newSourceCover = str(self.values[rowNo]["sourceCover"]) newSourceCover = newSourceCover.replace(self.values[rowNo]["path"], ".") oldSourceCover = self.values[rowNo]["currentCover"] oldSourceCover = oldSourceCover.replace(self.values[rowNo]["path"], ".") self.createItem(rowNo, "sourceCover", newSourceCover, oldSourceCover) newDestinationCover = self.values[rowNo]["destinationCover"] newDestinationCover = newDestinationCover.replace(self.values[rowNo]["path"], ".") newDestinationCover = Organizer.emend(newDestinationCover, "file") oldDestinationCover = self.values[rowNo]["currentCover"] oldDestinationCover = oldDestinationCover.replace(self.values[rowNo]["path"], ".") self.createItem(rowNo, "destinationCover", newDestinationCover, oldDestinationCover) rowNo += 1 else: allItemNumber -= 1 except: ReportBug.ReportBug() allItemNumber -= 1 else: allItemNumber = rowNo Dialogs.showState(translate("Tables", "Generating Table..."), rowNo, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() self.setRowCount(len(self.values)) # In case of Non Readable Files and Canceled process
def writeContents(self): self.changedValueNumber = 0 oldAndNewPathValues = [] changingTags = [] uni.startThreadAction() import Amarok allItemNumber = len(self.values) Dialogs.showState(translate("FileUtils/Musics", "Writing Music Tags"), 0, allItemNumber, True) for rowNo in range(self.rowCount()): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: if self.isRowHidden(rowNo): isWritableFileOrDir = fu.isFile( self.values[rowNo]["path"]) and fu.isWritableFileOrDir( self.values[rowNo]["path"], False, True) if isWritableFileOrDir: fu.removeFileOrDir(self.values[rowNo]["path"]) self.changedValueNumber += 1 else: changingTag = {"path": self.values[rowNo]["path"]} isWritableFileOrDir = fu.isFile( self.values[rowNo]["path"]) and fu.isWritableFileOrDir( self.values[rowNo]["path"], False, True) isSetTagOfFile = False if isWritableFileOrDir: baseNameOfDirectory = str( self.values[rowNo]["baseNameOfDirectory"]) baseName = str(self.values[rowNo]["baseName"]) if Amarok.getSelectedTagTargetType("AmarokMusicTable").find("To File") > -1: isSetTagOfFile = True tagger = Taggers.getTagger() tagger.loadFileForWrite(self.values[rowNo]["path"]) if self.isChangeableItem(rowNo, "artist"): value = str(self.item(rowNo, 2).text()) if isSetTagOfFile: tagger.setArtist(value) changingTag["artist"] = value Records.add(str(translate("MusicTable", "Artist")), str(self.values[rowNo]["artist"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "title"): value = str(self.item(rowNo, 3).text()) if isSetTagOfFile: tagger.setTitle(value) changingTag["title"] = value Records.add(str(translate("MusicTable", "Title")), str(self.values[rowNo]["title"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "album"): value = str(self.item(rowNo, 4).text()) if isSetTagOfFile: tagger.setAlbum(value) changingTag["album"] = value Records.add(str(translate("MusicTable", "Album")), str(self.values[rowNo]["album"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "albumArtist"): value = str(self.item(rowNo, 5).text()) if isSetTagOfFile: tagger.setAlbumArtist(value) changingTag["albumArtist"] = value Records.add(str(translate("MusicTable", "Album Artist")), str(self.values[rowNo]["albumArtist"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "trackNum"): value = str(self.item(rowNo, 6).text()) if isSetTagOfFile: tagger.setTrackNum(value) changingTag["trackNum"] = value Records.add(str(translate("MusicTable", "Track No")), str(self.values[rowNo]["trackNum"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "year"): value = str(self.item(rowNo, 7).text()) if isSetTagOfFile: tagger.setDate(value) changingTag["year"] = value Records.add(str(translate("MusicTable", "Year")), str(self.values[rowNo]["year"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "genre"): value = str(self.item(rowNo, 8).text()) if isSetTagOfFile: tagger.setGenre(value) changingTag["genre"] = value Records.add(str(translate("MusicTable", "Genre")), str(self.values[rowNo]["genre"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "firstComment"): value = str(self.item(rowNo, 9).text()) if isSetTagOfFile: tagger.setFirstComment(value) changingTag["firstComment"] = value Records.add(str(translate("MusicTable", "Comment")), str(self.values[rowNo]["firstComment"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "firstLyrics"): value = str(self.item(rowNo, 10).text()) if isSetTagOfFile: tagger.setFirstLyrics(value) changingTag["firstLyrics"] = value Records.add(str(translate("MusicTable", "Lyrics")), str(self.values[rowNo]["firstLyrics"]), value) self.changedValueNumber += 1 if len(changingTag) > 1: changingTags.append(changingTag) if isWritableFileOrDir: if isSetTagOfFile: tagger.update() if self.isChangeableItem(rowNo, "baseNameOfDirectory", baseNameOfDirectory): baseNameOfDirectory = str(self.item(rowNo, 0).text()) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "baseName", baseName, False): baseName = str(self.item(rowNo, 1).text()) self.changedValueNumber += 1 newFilePath = fu.joinPath( fu.getDirName(fu.getDirName(self.values[rowNo]["path"])), baseNameOfDirectory, baseName) oldFilePath = fu.getRealPath(self.values[rowNo]["path"]) newFilePath = fu.getRealPath(newFilePath) if oldFilePath != newFilePath: oldAndNewPaths = {} oldAndNewPaths["oldPath"] = oldFilePath oldAndNewPaths["newPath"] = fu.moveOrChange(oldFilePath, newFilePath, "file") if oldFilePath != oldAndNewPaths["newPath"]: oldAndNewPathValues.append(oldAndNewPaths) oldDirName = fu.getDirName(oldFilePath) if uni.getBoolValue("isClearEmptyDirectoriesWhenFileMove"): fu.checkEmptyDirectories(oldDirName, True, True, uni.getBoolValue("isAutoCleanSubFolderWhenFileMove")) except: ReportBug.ReportBug() else: allItemNumber = rowNo + 1 Dialogs.showState(translate("FileUtils/Musics", "Writing Music Tags And Informations"), rowNo + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() from Amarok import Operations if Amarok.getSelectedTagTargetType("AmarokMusicTable").find("Amarok") > -1: Operations.changeTags(changingTags) if len(oldAndNewPathValues) > 0: Operations.changePaths(oldAndNewPathValues, "file") return True
def writeContents(self): self.changedValueNumber = 0 oldAndNewPathValues = [] startRowNo, rowStep = 0, 1 uni.startThreadAction() allItemNumber = len(self.values) Dialogs.showState( translate("FileUtils/Covers", "Writing Cover Informations"), 0, allItemNumber, True) for rowNo in range(startRowNo, self.rowCount(), rowStep): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: if fu.isWritableFileOrDir(self.values[rowNo]["path"], False, True): if self.isRowHidden(rowNo): fu.removeFileOrDir(self.values[rowNo]["path"]) self.changedValueNumber += 1 else: pathOfParentDirectory = str( self.values[rowNo]["pathOfParentDirectory"]) baseName = str(self.values[rowNo]["baseName"]) if self.isChangeableItem( rowNo, "sourceCover") or self.isChangeableItem( rowNo, "destinationCover"): sourcePath = self.values[rowNo]["sourceCover"] destinationPath = self.values[rowNo][ "destinationCover"] if self.isChangeableItem(rowNo, "sourceCover"): sourcePath = str( self.item(rowNo, 3).text()).strip() if self.isChangeableItem( rowNo, "destinationCover"): destinationPath = str( self.item(rowNo, 4).text()).strip() if (str(self.item(rowNo, 2).text()) != sourcePath or sourcePath != destinationPath or str(self.item(rowNo, 2).text()) != destinationPath ) or (str(self.item(rowNo, 2).text()) != self.values[rowNo]["currentCover"] and (str(self.item(rowNo, 2).text()) != sourcePath and str(self.item(rowNo, 2).text()) != destinationPath)): if str(self.item(rowNo, 3).text()).strip() != "": sourcePath = fu.getRealPath( sourcePath, self.values[rowNo]["path"]) sourcePath = fu.checkSource( sourcePath, "file") if sourcePath is not None: if destinationPath != "": destinationPath = fu.getRealPath( destinationPath, self.values[rowNo]["path"]) if sourcePath != destinationPath: destinationPath = fu.moveOrChange( sourcePath, destinationPath) else: destinationPath = sourcePath fu.setIconToDirectory( self.values[rowNo]["path"], destinationPath) self.changedValueNumber += 1 else: fu.setIconToDirectory( self.values[rowNo]["path"], "") self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "baseNameOfDirectory", pathOfParentDirectory): pathOfParentDirectory = str( self.item(rowNo, 0).text()) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "baseName", baseName, False): baseName = str(self.item(rowNo, 1).text()) self.changedValueNumber += 1 newFilePath = fu.joinPath(pathOfParentDirectory, baseName) oldFilePath = fu.getRealPath( self.values[rowNo]["path"]) newFilePath = fu.getRealPath(newFilePath) if oldFilePath != newFilePath: oldAndNewPaths = {} oldAndNewPaths["oldPath"] = oldFilePath oldAndNewPaths["newPath"] = fu.moveOrChange( oldFilePath, newFilePath, "directory") if oldFilePath != oldAndNewPaths["newPath"]: oldAndNewPathValues.append(oldAndNewPaths) oldDirName = fu.getDirName(oldFilePath) if uni.getBoolValue( "isClearEmptyDirectoriesWhenFileMove" ): fu.checkEmptyDirectories( oldDirName, True, True, uni.getBoolValue( "isAutoCleanSubFolderWhenFileMove" )) except: ReportBug.ReportBug() else: allItemNumber = rowNo + 1 Dialogs.showState( translate("FileUtils/Covers", "Writing Cover Informations"), rowNo + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() if len(oldAndNewPathValues) > 0: from Amarok import Operations Operations.changePaths(oldAndNewPathValues) return True
def createPage(self, _pageNo): pnlPage = MWidget() HBox = MHBoxLayout() pnlPage.setLayout(HBox) if _pageNo == 0: if fu.isFile( fu.joinPath(fu.HamsiManagerDirectory, "Languages", "About_" + defaultLangCode)): aboutFileContent = fu.readFromFile( fu.joinPath(fu.HamsiManagerDirectory, "Languages", "About_" + defaultLangCode), "utf-8") else: aboutFileContent = fu.readFromFile( fu.joinPath(fu.HamsiManagerDirectory, "Languages", "About_en_GB"), "utf-8") lblAbout = MLabel(str(aboutFileContent)) lblAbout.setWordWrap(True) HBox.addWidget(lblAbout) elif _pageNo == 1: if fu.isFile( fu.joinPath(fu.HamsiManagerDirectory, "Languages", "License_" + defaultLangCode)): licenceFileContent = fu.readFromFile( fu.joinPath(fu.HamsiManagerDirectory, "Languages", "License_" + defaultLangCode), "utf-8") else: licenceFileContent = fu.readFromFile( fu.joinPath(fu.HamsiManagerDirectory, "Languages", "License_en_GB"), "utf-8") teCopying = MTextEdit() teCopying.setPlainText(str(licenceFileContent)) HBox.addWidget(teCopying) elif _pageNo == 2: lblPleaseSelect = MLabel( translate("Install", "Please Select A Folder For Installation.")) installationDirPath = Settings.getUniversalSetting( "HamsiManagerPath", None) if installationDirPath is not None: installationDirPath = fu.getDirName(installationDirPath) else: installationDirPath = fu.joinPath( fu.getDirName(fu.HamsiManagerDirectory), "Hamsi") self.leInstallationDirectory = MLineEdit( str( Settings.getUniversalSetting( "pathOfInstallationDirectory", str(installationDirPath)))) self.pbtnSelectInstallationDirectory = MPushButton( translate("Install", "Browse")) self.connect(self.pbtnSelectInstallationDirectory, SIGNAL("clicked()"), self.selectInstallationDirectory) VBox = MVBoxLayout() VBox.addStretch(10) VBox.addWidget(lblPleaseSelect) HBox1 = MHBoxLayout() HBox1.addWidget(self.leInstallationDirectory) HBox1.addWidget(self.pbtnSelectInstallationDirectory) VBox.addLayout(HBox1) VBox.addStretch(10) HBox.addLayout(VBox) elif _pageNo == 3: VBox = MVBoxLayout() self.lblActions = MLabel("") self.prgbState = MProgressBar() VBox.addWidget(self.lblActions) VBox.addWidget(self.prgbState) HBox.addLayout(VBox) elif _pageNo == 4: VBox = MVBoxLayout() self.lblFinished = MLabel( translate("Install", "Installation Complete.")) VBox.addStretch(10) VBox.addWidget(self.lblFinished) VBox.addStretch(2) self.isCreateDesktopShortcut = None self.isCreateExecutableLink = None if uni.isRunningAsRoot(): self.isCreateExecutableLink = MCheckBox( translate("Install", "Add To The System")) self.isCreateExecutableLink.setCheckState(Mt.Checked) lblExecutableLink = MLabel( translate("Install", "Executable Link Path : ")) self.leExecutableLink = MLineEdit( str( Settings.getUniversalSetting( "HamsiManagerExecutableLinkPath", "/usr/bin/hamsi"))) self.connect(self.isCreateExecutableLink, SIGNAL("stateChanged(int)"), self.createExecutableLinkChanged) VBox.addWidget(self.isCreateExecutableLink) HBox1 = MHBoxLayout() HBox1.addWidget(lblExecutableLink) HBox1.addWidget(self.leExecutableLink) VBox.addLayout(HBox1) else: self.isCreateDesktopShortcut = MCheckBox( translate("Install", "Create Desktop Shortcut.")) self.isCreateDesktopShortcut.setCheckState(Mt.Checked) VBox.addWidget(self.isCreateDesktopShortcut) VBox.addStretch(10) HBox.addLayout(VBox) return pnlPage
def writeContents(self): self.changedValueNumber = 0 oldAndNewPathValues = [] isNewDirectoriesSame = True isMovedToNewDirectory = False currentDirectoryPath = "" newDirectoryPath = "" startRowNo, rowStep = 0, 1 uni.startThreadAction() allItemNumber = len(self.values) Dialogs.showState(translate("FileUtils/Covers", "Writing Cover Informations"), 0, allItemNumber, True) for rowNo in range(startRowNo, self.rowCount(), rowStep): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: if fu.isWritableFileOrDir(self.values[rowNo]["path"], False, True): if self.isRowHidden(rowNo): fu.removeFileOrDir(self.values[rowNo]["path"]) self.changedValueNumber += 1 else: baseNameOfDirectory = str( self.values[rowNo]["baseNameOfDirectory"]) baseName = str(self.values[rowNo]["baseName"]) if (self.isChangeableItem(rowNo, "sourceCover") or self.isChangeableItem(rowNo, "destinationCover")): sourcePath = self.values[rowNo]["sourceCover"] destinationPath = self.values[rowNo]["destinationCover"] if self.isChangeableItem(rowNo, "sourceCover"): sourcePath = str(self.item(rowNo, 3).text()).strip() if self.isChangeableItem(rowNo, "destinationCover"): destinationPath = str(self.item(rowNo, 4).text()).strip() if (str(self.item(rowNo, 2).text()) != sourcePath or sourcePath != destinationPath or str( self.item(rowNo, 2).text()) != destinationPath) or ( str(self.item(rowNo, 2).text()) != self.values[rowNo]["currentCover"] and ( str(self.item(rowNo, 2).text()) != sourcePath and str( self.item(rowNo, 2).text()) != destinationPath)): if str(self.item(rowNo, 3).text()).strip() != "": sourcePath = fu.getRealPath(sourcePath, self.values[rowNo]["path"]) sourcePath = fu.checkSource(sourcePath, "file") if sourcePath is not None: if destinationPath != "": destinationPath = fu.getRealPath(destinationPath, self.values[ rowNo]["path"]) if sourcePath != destinationPath: destinationPath = fu.moveOrChange(sourcePath, destinationPath) else: destinationPath = sourcePath fu.setIconToDirectory(self.values[rowNo]["path"], destinationPath) self.changedValueNumber += 1 else: fu.setIconToDirectory(self.values[rowNo]["path"], "") self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "baseNameOfDirectory", baseNameOfDirectory): baseNameOfDirectory = str(self.item(rowNo, 0).text()) self.changedValueNumber += 1 isMovedToNewDirectory = True currentDirectoryPath = fu.getDirName( self.values[rowNo]["path"]) newDirectoryPath = fu.joinPath( fu.getDirName(fu.getDirName(self.values[rowNo]["path"])), baseNameOfDirectory) self.setNewDirectory(newDirectoryPath) if rowNo > 0: if str(self.item(rowNo - 1, 0).text()) != baseNameOfDirectory: isNewDirectoriesSame = False if self.isChangeableItem(rowNo, "baseName", baseName, False): baseName = str(self.item(rowNo, 1).text()) self.changedValueNumber += 1 newFilePath = fu.joinPath( fu.getDirName(fu.getDirName(self.values[rowNo]["path"])), baseNameOfDirectory, baseName) oldFilePath = fu.getRealPath(self.values[rowNo]["path"]) newFilePath = fu.getRealPath(newFilePath) if oldFilePath != newFilePath: oldAndNewPaths = {} oldAndNewPaths["oldPath"] = oldFilePath oldAndNewPaths["newPath"] = fu.moveOrChange(oldFilePath, newFilePath, "directory") if oldFilePath != oldAndNewPaths["newPath"]: oldAndNewPathValues.append(oldAndNewPaths) oldDirName = fu.getDirName(oldFilePath) if uni.getBoolValue("isClearEmptyDirectoriesWhenFileMove"): fu.checkEmptyDirectories(oldDirName, True, True, uni.getBoolValue("isAutoCleanSubFolderWhenFileMove")) except: ReportBug.ReportBug() else: allItemNumber = rowNo + 1 Dialogs.showState(translate("FileUtils/Covers", "Writing Cover Informations"), rowNo + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() if self.rowCount() == len(oldAndNewPathValues) and isMovedToNewDirectory and isNewDirectoriesSame: otherFileNames = fu.readDirectory(currentDirectoryPath, "fileAndDirectory", True) if len(otherFileNames) > 0: answer = Dialogs.ask(translate("FileUtils/Musics", "There Are More Files"), str(translate("FileUtils/Musics", "\"%s\" : there are more files in this directory.<br>Are you want to move all found files into new directory?<br>New Directory : \"%s\"")) % ( Organizer.getLink(currentDirectoryPath), Organizer.getLink(newDirectoryPath))) if answer == Dialogs.Yes: uni.startThreadAction() allItemNumber = len(otherFileNames) for rowNo, fileName in enumerate(otherFileNames): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: oldFilePath = fu.getRealPath(fu.joinPath(currentDirectoryPath, fileName)) newFilePath = fu.getRealPath(fu.joinPath(newDirectoryPath, fileName)) if oldFilePath != newFilePath: oldAndNewPaths = {} oldAndNewPaths["oldPath"] = oldFilePath oldAndNewPaths["newPath"] = fu.moveOrChange(oldFilePath, newFilePath, fu.getObjectType(oldFilePath)) if oldFilePath != oldAndNewPaths["newPath"]: oldAndNewPathValues.append(oldAndNewPaths) except: ReportBug.ReportBug() else: allItemNumber = rowNo + 1 Dialogs.showState(translate("FileUtils/Covers", "Writing Directory And File Informations"), rowNo + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() if uni.getBoolValue("isClearEmptyDirectoriesWhenFileMove"): fu.checkEmptyDirectories(currentDirectoryPath, True, True, uni.getBoolValue("isAutoCleanSubFolderWhenFileMove")) if (uni.isActiveDirectoryCover and uni.getBoolValue("isActiveAutoMakeIconToDirectory") and uni.getBoolValue("isAutoMakeIconToDirectoryWhenFileMove")): fu.checkIcon(newDirectoryPath) return True
def writeContents(self): self.changedValueNumber = 0 oldAndNewPathValues = [] changingTags = [] uni.startThreadAction() import Amarok allItemNumber = len(self.values) Dialogs.showState(translate("FileUtils/Musics", "Writing Music Tags"), 0, allItemNumber, True) for rowNo in range(self.rowCount()): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: if self.isRowHidden(rowNo): isWritableFileOrDir = fu.isFile( self.values[rowNo] ["path"]) and fu.isWritableFileOrDir( self.values[rowNo]["path"], False, True) if isWritableFileOrDir: fu.removeFileOrDir(self.values[rowNo]["path"]) self.changedValueNumber += 1 else: changingTag = {"path": self.values[rowNo]["path"]} isWritableFileOrDir = fu.isFile( self.values[rowNo] ["path"]) and fu.isWritableFileOrDir( self.values[rowNo]["path"], False, True) isSetTagOfFile = False if isWritableFileOrDir: baseNameOfDirectory = str( self.values[rowNo]["baseNameOfDirectory"]) baseName = str(self.values[rowNo]["baseName"]) if Amarok.getSelectedTagTargetType( "AmarokMusicTable").find("To File") > -1: isSetTagOfFile = True tagger = Taggers.getTagger() tagger.loadFileForWrite( self.values[rowNo]["path"]) if self.isChangeableItem(rowNo, "artist"): value = str(self.item(rowNo, 2).text()) if isSetTagOfFile: tagger.setArtist(value) changingTag["artist"] = value Records.add(str(translate("MusicTable", "Artist")), str(self.values[rowNo]["artist"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "title"): value = str(self.item(rowNo, 3).text()) if isSetTagOfFile: tagger.setTitle(value) changingTag["title"] = value Records.add(str(translate("MusicTable", "Title")), str(self.values[rowNo]["title"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "album"): value = str(self.item(rowNo, 4).text()) if isSetTagOfFile: tagger.setAlbum(value) changingTag["album"] = value Records.add(str(translate("MusicTable", "Album")), str(self.values[rowNo]["album"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "albumArtist"): value = str(self.item(rowNo, 5).text()) if isSetTagOfFile: tagger.setAlbumArtist(value) changingTag["albumArtist"] = value Records.add( str(translate("MusicTable", "Album Artist")), str(self.values[rowNo]["albumArtist"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "trackNum"): value = str(self.item(rowNo, 6).text()) if isSetTagOfFile: tagger.setTrackNum(value) changingTag["trackNum"] = value Records.add( str(translate("MusicTable", "Track No")), str(self.values[rowNo]["trackNum"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "year"): value = str(self.item(rowNo, 7).text()) if isSetTagOfFile: tagger.setDate(value) changingTag["year"] = value Records.add(str(translate("MusicTable", "Year")), str(self.values[rowNo]["year"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "genre"): value = str(self.item(rowNo, 8).text()) if isSetTagOfFile: tagger.setGenre(value) changingTag["genre"] = value Records.add(str(translate("MusicTable", "Genre")), str(self.values[rowNo]["genre"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "firstComment"): value = str(self.item(rowNo, 9).text()) if isSetTagOfFile: tagger.setFirstComment(value) changingTag["firstComment"] = value Records.add( str(translate("MusicTable", "Comment")), str(self.values[rowNo]["firstComment"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "firstLyrics"): value = str(self.item(rowNo, 10).text()) if isSetTagOfFile: tagger.setFirstLyrics(value) changingTag["firstLyrics"] = value Records.add(str(translate("MusicTable", "Lyrics")), str(self.values[rowNo]["firstLyrics"]), value) self.changedValueNumber += 1 if len(changingTag) > 1: changingTags.append(changingTag) if isWritableFileOrDir: if isSetTagOfFile: tagger.update() if self.isChangeableItem(rowNo, "baseNameOfDirectory", baseNameOfDirectory): baseNameOfDirectory = str( self.item(rowNo, 0).text()) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "baseName", baseName, False): baseName = str(self.item(rowNo, 1).text()) self.changedValueNumber += 1 newFilePath = fu.joinPath( fu.getDirName( fu.getDirName(self.values[rowNo]["path"])), baseNameOfDirectory, baseName) oldFilePath = fu.getRealPath( self.values[rowNo]["path"]) newFilePath = fu.getRealPath(newFilePath) if oldFilePath != newFilePath: oldAndNewPaths = {} oldAndNewPaths["oldPath"] = oldFilePath oldAndNewPaths["newPath"] = fu.moveOrChange( oldFilePath, newFilePath, "file") if oldFilePath != oldAndNewPaths["newPath"]: oldAndNewPathValues.append(oldAndNewPaths) oldDirName = fu.getDirName(oldFilePath) if uni.getBoolValue( "isClearEmptyDirectoriesWhenFileMove" ): fu.checkEmptyDirectories( oldDirName, True, True, uni.getBoolValue( "isAutoCleanSubFolderWhenFileMove" )) except: ReportBug.ReportBug() else: allItemNumber = rowNo + 1 Dialogs.showState( translate("FileUtils/Musics", "Writing Music Tags And Informations"), rowNo + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() from Amarok import Operations if Amarok.getSelectedTagTargetType("AmarokMusicTable").find( "Amarok") > -1: Operations.changeTags(changingTags) if len(oldAndNewPathValues) > 0: Operations.changePaths(oldAndNewPathValues, "file") return True
def changeFile(self, _filePath, _readFrom="tag"): self.musicFile = _filePath self.musicValues = None self.isPlayNow = MToolButton() self.isPlayNow.setToolTip( translate("MusicDetails", "Play Suddenly Music When Open")) self.isPlayNow.setText(translate("MusicDetails", "Play When Open")) self.isPlayNow.setCheckable(True) self.isPlayNow.setChecked(uni.getBoolValue("isPlayNow")) self.isGetFromAmarok = MToolButton() self.isGetFromAmarok.setToolTip( translate("MusicDetails", "Get Values From Amarok")) self.isGetFromAmarok.setText( translate("MusicDetails", "Get From Amarok")) self.isGetFromAmarok.setCheckable(True) if _readFrom.count("Amarok") > 0: import Amarok uni.startThreadAction() Dialogs.showState( translate("MusicDetails", "Getting Values From Amarok"), 0, 1) if Amarok.checkAmarok(): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: from Amarok import Operations musicFileRows = Operations.getAllMusicFileValuesWithNames( "filename:\"" + _filePath + "\"") Dialogs.showState( translate("MusicDetails", "Values Are Being Processed"), 1, 1) if len(musicFileRows) > 0: musicFileRow = musicFileRows[0] content = {} content["path"] = musicFileRow["filePath"] content["baseNameOfDirectory"] = fu.getBaseName( fu.getDirName(musicFileRow["filePath"])) content["baseName"] = fu.getBaseName( musicFileRow["filePath"]) content["artist"] = musicFileRow["artist"] content["title"] = musicFileRow["title"] content["album"] = musicFileRow["album"] content["albumArtist"] = musicFileRow["albumArtist"] content["trackNum"] = musicFileRow["trackNumber"] content["year"] = musicFileRow["year"] content["genre"] = musicFileRow["genre"] content["firstComment"] = musicFileRow["comment"] content["firstLyrics"] = musicFileRow["lyrics"] content["images"] = [] if _readFrom == "Amarok (Smart)": tagger = Taggers.getTagger() try: tagger.loadFile(musicFileRow["filePath"]) except: pass else: if content["artist"].strip() == "": content["artist"] = tagger.getArtist() if content["title"].strip() == "": content["title"] = tagger.getTitle() if content["album"].strip() == "": content["album"] = tagger.getAlbum() if content["albumArtist"].strip() == "": content[ "albumArtist"] = tagger.getAlbumArtist( ) if str(content["trackNum"]).strip() == "": content["trackNum"] = tagger.getTrackNum() if str(content["year"]).strip() == "": content["year"] = tagger.getYear() if content["genre"].strip() == "": content["genre"] = tagger.getGenre() if content["firstComment"].strip() == "": content[ "firstComment"] = tagger.getFirstComment( ) if content["firstLyrics"].strip() == "": content[ "firstLyrics"] = tagger.getFirstLyrics( ) content["images"] = tagger.getImages() self.isGetFromAmarok.setChecked(True) self.musicValues = content else: Dialogs.show( translate("MusicDetails", "Not Exist In Amarok"), translate( "MusicDetails", "This music file not exist in Amarok DB.")) uni.finishThreadAction() if self.musicValues is None: self.isGetFromAmarok.setChecked(False) self.musicValues = Musics.readMusicFile(self.musicFile) self.setWindowTitle(str(fu.getBaseName(self.musicFile))) if self.pnlClearable is not None: clearAllChildren(self.pnlClearable, True) self.pnlClearable = MWidget() self.vblMain.insertWidget(0, self.pnlClearable, 20) vblClearable = MVBoxLayout(self.pnlClearable) self.player = MusicPlayer.MusicPlayer(self, "dialog", _filePath) self.infoLabels["baseNameOfDirectory"] = MLabel(self.labels[0]) self.infoLabels["baseName"] = MLabel(self.labels[1]) self.infoLabels["artist"] = MLabel(self.labels[2]) self.infoLabels["title"] = MLabel(self.labels[3]) self.infoLabels["album"] = MLabel(self.labels[4]) self.infoLabels["albumArtist"] = MLabel(self.labels[5]) self.infoLabels["trackNum"] = MLabel(self.labels[6]) self.infoLabels["year"] = MLabel(self.labels[7]) self.infoLabels["genre"] = MLabel(self.labels[8]) self.infoValues["baseNameOfDirectory"] = MLineEdit( str( Organizer.emend(self.musicValues["baseNameOfDirectory"], "directory", False))) self.infoValues["baseName"] = MLineEdit( str(Organizer.emend(self.musicValues["baseName"], "file"))) self.infoValues["artist"] = MLineEdit( str(Organizer.emend(self.musicValues["artist"]))) self.infoValues["title"] = MLineEdit( str(Organizer.emend(self.musicValues["title"]))) self.infoValues["album"] = MLineEdit( str(Organizer.emend(self.musicValues["album"]))) self.infoValues["albumArtist"] = MLineEdit( str(Organizer.emend(self.musicValues["albumArtist"]))) self.infoValues["trackNum"] = MLineEdit( str(Organizer.emend(self.musicValues["trackNum"]))) self.infoValues["year"] = MLineEdit( str(Organizer.emend(self.musicValues["year"]))) self.infoValues["genre"] = MLineEdit( str(Organizer.emend(self.musicValues["genre"]))) self.infoValues["firstComment"] = MPlainTextEdit( str(Organizer.emend(self.musicValues["firstComment"]))) self.infoValues["firstLyrics"] = MPlainTextEdit( str(Organizer.emend(self.musicValues["firstLyrics"]))) self.infoValues["firstComment"].setLineWrapMode(MPlainTextEdit.NoWrap) self.infoValues["firstLyrics"].setLineWrapMode(MPlainTextEdit.NoWrap) if Taggers.getTagger().isSupportImages: self.isOpenImageDetailsOnNewWindow = MCheckBox( translate("MusicDetails", "Show Images In New Window")) self.pbtnAddImage = MPushButton(translate("MusicDetails", "Append")) self.pbtnDeleteImage = MPushButton( translate("MusicDetails", "Delete")) self.pbtnSaveAsImage = MPushButton( translate("MusicDetails", "Save As ...")) self.pbtnCancelAddImage = MPushButton( translate("MusicDetails", "Cancel")) self.pbtnSelectImage = MPushButton( translate("MusicDetails", "Choose Image")) MObject.connect(self.pbtnAddImage, SIGNAL("clicked()"), self.addImage) MObject.connect(self.pbtnDeleteImage, SIGNAL("clicked()"), self.deleteImage) MObject.connect(self.pbtnSaveAsImage, SIGNAL("clicked()"), self.saveAsImage) MObject.connect(self.pbtnCancelAddImage, SIGNAL("clicked()"), self.cancelAddImage) MObject.connect(self.pbtnSelectImage, SIGNAL("clicked()"), self.selectImage) self.leImagePath = MLineEdit("") self.lblImagePath = MLabel( translate("MusicDetails", "Image Path: ")) self.cbImageType = MComboBox() self.cbImageType.addItems(Taggers.getTagger().getImageTypes()) self.lblImageType = MLabel( translate("MusicDetails", "Image Type: ")) self.lstwImages = MListWidget() self.lstwImages.setGridSize(MSize(350, 100)) self.lstwImages.setIconSize(MSize(98, 98)) MObject.connect(self.lstwImages, SIGNAL("doubleClicked(QModelIndex)"), self.openImageDetails) MObject.connect(self.isGetFromAmarok, SIGNAL("toggled(bool)"), self.isGetFromAmarokTiggered) self.lstwImages.clear() for image in self.musicValues["images"]: if len(image) == 5: pixmImage = MPixmap() pixmImage.loadFromData(image[3]) icnImage = QIcon(pixmImage) icnImage.actualSize(MSize(98, 98)) item = MListWidgetItem(icnImage, image[1] + "\n(" + image[2] + ")") item.setSizeHint(MSize(1, 100)) self.lstwImages.addItem(item) HBOXs = [] HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["baseNameOfDirectory"]) HBOXs[-1].addWidget(self.infoValues["baseNameOfDirectory"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["baseName"]) HBOXs[-1].addWidget(self.infoValues["baseName"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["artist"]) HBOXs[-1].addWidget(self.infoValues["artist"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["title"]) HBOXs[-1].addWidget(self.infoValues["title"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["album"]) HBOXs[-1].addWidget(self.infoValues["album"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["albumArtist"]) HBOXs[-1].addWidget(self.infoValues["albumArtist"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["trackNum"]) HBOXs[-1].addWidget(self.infoValues["trackNum"]) HBOXs[-1].addWidget(self.infoLabels["year"]) HBOXs[-1].addWidget(self.infoValues["year"]) HBOXs[-1].addWidget(self.infoLabels["genre"]) HBOXs[-1].addWidget(self.infoValues["genre"]) vblInfos = MVBoxLayout() for hbox in HBOXs: vblInfos.addLayout(hbox) if Taggers.getTagger().isSupportImages: imageBoxs = [] imageBoxs.append(MHBoxLayout()) imageBoxs[0].addWidget(self.leImagePath) imageBoxs[0].addWidget(self.pbtnSelectImage) imageBoxs.append(MHBoxLayout()) imageBoxs[1].addWidget(self.lblImageType) imageBoxs[1].addWidget(self.cbImageType) imageBoxs.append(MHBoxLayout()) imageBoxs[2].addWidget(self.pbtnAddImage) imageBoxs[2].addWidget(self.pbtnDeleteImage) imageBoxs[2].addWidget(self.pbtnSaveAsImage) imageBoxs[2].addWidget(self.pbtnCancelAddImage) vblImages = MVBoxLayout() vblImages.addWidget(self.lstwImages) vblImages.addWidget(self.isOpenImageDetailsOnNewWindow) vblImages.addWidget(self.lblImagePath) vblImages.addLayout(imageBoxs[0]) vblImages.addLayout(imageBoxs[1]) vblImages.addLayout(imageBoxs[2]) vblComments = MVBoxLayout() vblComments.addWidget(self.infoValues["firstComment"]) vblLyrics = MVBoxLayout() vblLyrics.addWidget(self.infoValues["firstLyrics"]) self.tabwTabs = MTabWidget(self.pnlMain) self.pnlComments = MWidget(self.tabwTabs) self.pnlComments.setLayout(vblComments) self.tabwTabs.addTab(self.pnlComments, translate("MusicDetails", "Comments")) self.pnlLyrics = MWidget(self.tabwTabs) self.pnlLyrics.setLayout(vblLyrics) self.tabwTabs.addTab(self.pnlLyrics, translate("MusicDetails", "Lyrics")) if Taggers.getTagger().isSupportImages: self.pnlImages = MWidget(self.tabwTabs) self.pnlImages.setLayout(vblImages) self.tabwTabs.addTab(self.pnlImages, translate("MusicDetails", "Images")) self.pbtnSelectImage.hide() self.leImagePath.hide() self.lblImagePath.hide() self.lblImageType.hide() self.cbImageType.hide() self.pbtnCancelAddImage.hide() hblPlayer = MHBoxLayout() vblExtraButtons = MVBoxLayout() hblPlayer.addWidget(self.player) vblExtraButtons.addWidget(self.isPlayNow) vblExtraButtons.addWidget(self.isGetFromAmarok) hblPlayer.addLayout(vblExtraButtons) vblClearable.addLayout(hblPlayer) vblClearable.addLayout(vblInfos) vblClearable.addWidget(self.tabwTabs)
def writeContents(self): self.changedValueNumber = 0 oldAndNewPathValues = [] changingTags = [] isNewDirectoriesSame = True isMovedToNewDirectory = False currentDirectoryPath = "" newDirectoryPath = "" if uni.isActiveAmarok and uni.getBoolValue("isMusicTableValuesChangeInAmarokDB"): import Amarok if Amarok.checkAmarok(True, False) is False: return False uni.startThreadAction() allItemNumber = len(self.values) Dialogs.showState(translate("FileUtils/Musics", "Writing Music Tags"), 0, allItemNumber, True) for rowNo in range(self.rowCount()): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: changingTag = {"path": self.values[rowNo]["path"]} if fu.isWritableFileOrDir(self.values[rowNo]["path"], False, True): if self.isRowHidden(rowNo): fu.removeFileOrDir(self.values[rowNo]["path"]) self.changedValueNumber += 1 else: baseNameOfDirectory = str( self.values[rowNo]["baseNameOfDirectory"]) baseName = str(self.values[rowNo]["baseName"]) tagger = Taggers.getTagger() tagger.loadFileForWrite(self.values[rowNo]["path"]) isCheckLike = (tagger.isNeedUpdate or (uni.isActiveAmarok and uni.getBoolValue("isMusicTableValuesChangeInAmarokDB"))) if self.isChangeableItem(rowNo, "artist", self.values[rowNo]["artist"], True, isCheckLike): value = str(self.item(rowNo, 2).text()) tagger.setArtist(value) changingTag["artist"] = value Records.add(str(translate("MusicTable", "Artist")), str(self.values[rowNo]["artist"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "title", self.values[rowNo]["title"], True, isCheckLike): value = str(self.item(rowNo, 3).text()) tagger.setTitle(value) changingTag["title"] = value Records.add(str(translate("MusicTable", "Title")), str(self.values[rowNo]["title"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "album", self.values[rowNo]["album"], True, isCheckLike): value = str(self.item(rowNo, 4).text()) tagger.setAlbum(value) changingTag["album"] = value Records.add(str(translate("MusicTable", "Album")), str(self.values[rowNo]["album"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "albumArtist", self.values[rowNo]["albumArtist"], True, isCheckLike): value = str(self.item(rowNo, 5).text()) tagger.setAlbumArtist(value) changingTag["albumArtist"] = value Records.add(str(translate("MusicTable", "Album Artist")), str(self.values[rowNo]["albumArtist"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "trackNum", self.values[rowNo]["trackNum"], True, isCheckLike): value = str(self.item(rowNo, 6).text()) tagger.setTrackNum(value) changingTag["trackNum"] = value Records.add(str(translate("MusicTable", "Track No")), str(self.values[rowNo]["trackNum"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "year", self.values[rowNo]["year"], True, isCheckLike): value = str(self.item(rowNo, 7).text()) tagger.setDate(value) changingTag["year"] = value Records.add(str(translate("MusicTable", "Year")), str(self.values[rowNo]["year"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "genre", self.values[rowNo]["genre"], True, isCheckLike): value = str(self.item(rowNo, 8).text()) tagger.setGenre(value) changingTag["genre"] = value Records.add(str(translate("MusicTable", "Genre")), str(self.values[rowNo]["genre"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "firstComment", self.values[rowNo]["firstComment"], True, isCheckLike): value = str(self.item(rowNo, 9).text()) tagger.setFirstComment(value) changingTag["firstComment"] = value Records.add(str(translate("MusicTable", "Comment")), str(self.values[rowNo]["firstComment"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "firstLyrics", self.values[rowNo]["firstLyrics"], True, isCheckLike): value = str(self.item(rowNo, 10).text()) tagger.setFirstLyrics(value) changingTag["firstLyrics"] = value Records.add(str(translate("MusicTable", "Lyrics")), str(self.values[rowNo]["firstLyrics"]), value) self.changedValueNumber += 1 if len(changingTag) > 1: changingTags.append(changingTag) tagger.update() if self.isChangeableItem(rowNo, "baseNameOfDirectory", baseNameOfDirectory): baseNameOfDirectory = str(self.item(rowNo, 0).text()) self.changedValueNumber += 1 isMovedToNewDirectory = True currentDirectoryPath = fu.getDirName( self.values[rowNo]["path"]) newDirectoryPath = fu.joinPath( fu.getDirName(fu.getDirName(self.values[rowNo]["path"])), baseNameOfDirectory) self.setNewDirectory(newDirectoryPath) if rowNo > 0: if str(self.item(rowNo - 1, 0).text()) != baseNameOfDirectory: isNewDirectoriesSame = False if self.isChangeableItem(rowNo, "baseName", baseName, False): baseName = str(self.item(rowNo, 1).text()) self.changedValueNumber += 1 newFilePath = fu.joinPath( fu.getDirName(fu.getDirName(self.values[rowNo]["path"])), baseNameOfDirectory, baseName) oldFilePath = fu.getRealPath(self.values[rowNo]["path"]) newFilePath = fu.getRealPath(newFilePath) if oldFilePath != newFilePath: oldAndNewPaths = {} oldAndNewPaths["oldPath"] = oldFilePath oldAndNewPaths["newPath"] = fu.moveOrChange(oldFilePath, newFilePath, "file") if oldFilePath != oldAndNewPaths["newPath"]: oldAndNewPathValues.append(oldAndNewPaths) oldDirName = fu.getDirName(oldFilePath) if uni.getBoolValue("isClearEmptyDirectoriesWhenFileMove"): fu.checkEmptyDirectories(oldDirName, True, True, uni.getBoolValue("isAutoCleanSubFolderWhenFileMove")) except: ReportBug.ReportBug() else: allItemNumber = rowNo + 1 Dialogs.showState(translate("FileUtils/Musics", "Writing Music Tags And Informations"), rowNo + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() if self.rowCount() == len(oldAndNewPathValues) and isMovedToNewDirectory and isNewDirectoriesSame: otherFileNames = fu.readDirectory(currentDirectoryPath, "fileAndDirectory", True) if len(otherFileNames) > 0: answer = Dialogs.ask(translate("FileUtils/Musics", "There Are More Files"), str(translate("FileUtils/Musics", "\"%s\" : there are more files in this directory.<br>Are you want to move all found files into new directory?<br>New Directory : \"%s\"")) % ( Organizer.getLink(currentDirectoryPath), Organizer.getLink(newDirectoryPath))) if answer == Dialogs.Yes: uni.startThreadAction() allItemNumber = len(otherFileNames) for rowNo, fileName in enumerate(otherFileNames): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: oldFilePath = fu.getRealPath(fu.joinPath(currentDirectoryPath, fileName)) newFilePath = fu.getRealPath(fu.joinPath(newDirectoryPath, fileName)) if oldFilePath != newFilePath: oldAndNewPaths = {} oldAndNewPaths["oldPath"] = oldFilePath oldAndNewPaths["newPath"] = fu.moveOrChange(oldFilePath, newFilePath, fu.getObjectType(oldFilePath)) if oldFilePath != oldAndNewPaths["newPath"]: oldAndNewPathValues.append(oldAndNewPaths) except: ReportBug.ReportBug() else: allItemNumber = rowNo + 1 Dialogs.showState(translate("FileUtils/Covers", "Writing Directory And File Informations"), rowNo + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() if uni.getBoolValue("isClearEmptyDirectoriesWhenFileMove"): fu.checkEmptyDirectories(currentDirectoryPath, True, True, uni.getBoolValue("isAutoCleanSubFolderWhenFileMove")) if (uni.isActiveDirectoryCover and uni.getBoolValue("isActiveAutoMakeIconToDirectory") and uni.getBoolValue("isAutoMakeIconToDirectoryWhenFileMove")): fu.checkIcon(newDirectoryPath) if uni.isActiveAmarok and uni.getBoolValue("isMusicTableValuesChangeInAmarokDB"): import Amarok from Amarok import Operations Operations.changeTags(changingTags) if len(oldAndNewPathValues) > 0: Operations.changePaths(oldAndNewPathValues, "file") return True
def changeFile(self, _filePath, _readFrom="tag"): self.musicFile = _filePath self.musicValues = None self.isPlayNow = MToolButton() self.isPlayNow.setToolTip(translate("MusicDetails", "Play Suddenly Music When Open")) self.isPlayNow.setText(translate("MusicDetails", "Play When Open")) self.isPlayNow.setCheckable(True) self.isPlayNow.setChecked(uni.getBoolValue("isPlayNow")) self.isGetFromAmarok = MToolButton() self.isGetFromAmarok.setToolTip(translate("MusicDetails", "Get Values From Amarok")) self.isGetFromAmarok.setText(translate("MusicDetails", "Get From Amarok")) self.isGetFromAmarok.setCheckable(True) if _readFrom.count("Amarok") > 0: import Amarok uni.startThreadAction() Dialogs.showState(translate("MusicDetails", "Getting Values From Amarok"), 0, 1) if Amarok.checkAmarok(): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: from Amarok import Operations musicFileRows = Operations.getAllMusicFileValuesWithNames("filename:\"" + _filePath + "\"") Dialogs.showState(translate("MusicDetails", "Values Are Being Processed"), 1, 1) if len(musicFileRows)>0: musicFileRow = musicFileRows[0] content = {} content["path"] = musicFileRow["filePath"] content["baseNameOfDirectory"] = fu.getBaseName( fu.getDirName(musicFileRow["filePath"])) content["baseName"] = fu.getBaseName(musicFileRow["filePath"]) content["artist"] = musicFileRow["artist"] content["title"] = musicFileRow["title"] content["album"] = musicFileRow["album"] content["albumArtist"] = musicFileRow["albumArtist"] content["trackNum"] = musicFileRow["trackNumber"] content["year"] = musicFileRow["year"] content["genre"] = musicFileRow["genre"] content["firstComment"] = musicFileRow["comment"] content["firstLyrics"] = musicFileRow["lyrics"] content["images"] = [] if _readFrom == "Amarok (Smart)": tagger = Taggers.getTagger() try: tagger.loadFile(musicFileRow["filePath"]) except: pass else: if content["artist"].strip() == "": content["artist"] = tagger.getArtist() if content["title"].strip() == "": content["title"] = tagger.getTitle() if content["album"].strip() == "": content["album"] = tagger.getAlbum() if content["albumArtist"].strip() == "": content["albumArtist"] = tagger.getAlbumArtist() if str(content["trackNum"]).strip() == "": content["trackNum"] = tagger.getTrackNum() if str(content["year"]).strip() == "": content["year"] = tagger.getYear() if content["genre"].strip() == "": content["genre"] = tagger.getGenre() if content["firstComment"].strip() == "": content["firstComment"] = tagger.getFirstComment() if content["firstLyrics"].strip() == "": content["firstLyrics"] = tagger.getFirstLyrics() content["images"] = tagger.getImages() self.isGetFromAmarok.setChecked(True) self.musicValues = content else: Dialogs.show(translate("MusicDetails", "Not Exist In Amarok"), translate("MusicDetails", "This music file not exist in Amarok DB.")) uni.finishThreadAction() if self.musicValues is None: self.isGetFromAmarok.setChecked(False) self.musicValues = Musics.readMusicFile(self.musicFile) self.setWindowTitle(str(fu.getBaseName(self.musicFile))) if self.pnlClearable is not None: clearAllChildren(self.pnlClearable, True) self.pnlClearable = MWidget() self.vblMain.insertWidget(0, self.pnlClearable, 20) vblClearable = MVBoxLayout(self.pnlClearable) self.player = MusicPlayer.MusicPlayer(self, "dialog", _filePath) self.infoLabels["baseNameOfDirectory"] = MLabel(self.labels[0]) self.infoLabels["baseName"] = MLabel(self.labels[1]) self.infoLabels["artist"] = MLabel(self.labels[2]) self.infoLabels["title"] = MLabel(self.labels[3]) self.infoLabels["album"] = MLabel(self.labels[4]) self.infoLabels["albumArtist"] = MLabel(self.labels[5]) self.infoLabels["trackNum"] = MLabel(self.labels[6]) self.infoLabels["year"] = MLabel(self.labels[7]) self.infoLabels["genre"] = MLabel(self.labels[8]) self.infoValues["baseNameOfDirectory"] = MLineEdit( str(Organizer.emend(self.musicValues["baseNameOfDirectory"], "directory", False))) self.infoValues["baseName"] = MLineEdit(str(Organizer.emend(self.musicValues["baseName"], "file"))) self.infoValues["artist"] = MLineEdit(str(Organizer.emend(self.musicValues["artist"]))) self.infoValues["title"] = MLineEdit(str(Organizer.emend(self.musicValues["title"]))) self.infoValues["album"] = MLineEdit(str(Organizer.emend(self.musicValues["album"]))) self.infoValues["albumArtist"] = MLineEdit(str(Organizer.emend(self.musicValues["albumArtist"]))) self.infoValues["trackNum"] = MLineEdit(str(Organizer.emend(self.musicValues["trackNum"]))) self.infoValues["year"] = MLineEdit(str(Organizer.emend(self.musicValues["year"]))) self.infoValues["genre"] = MLineEdit(str(Organizer.emend(self.musicValues["genre"]))) self.infoValues["firstComment"] = MPlainTextEdit(str(Organizer.emend(self.musicValues["firstComment"]))) self.infoValues["firstLyrics"] = MPlainTextEdit(str(Organizer.emend(self.musicValues["firstLyrics"]))) self.infoValues["firstComment"].setLineWrapMode(MPlainTextEdit.NoWrap) self.infoValues["firstLyrics"].setLineWrapMode(MPlainTextEdit.NoWrap) if Taggers.getTagger().isSupportImages: self.isOpenImageDetailsOnNewWindow = MCheckBox(translate("MusicDetails", "Show Images In New Window")) self.pbtnAddImage = MPushButton(translate("MusicDetails", "Append")) self.pbtnDeleteImage = MPushButton(translate("MusicDetails", "Delete")) self.pbtnSaveAsImage = MPushButton(translate("MusicDetails", "Save As ...")) self.pbtnCancelAddImage = MPushButton(translate("MusicDetails", "Cancel")) self.pbtnSelectImage = MPushButton(translate("MusicDetails", "Choose Image")) MObject.connect(self.pbtnAddImage, SIGNAL("clicked()"), self.addImage) MObject.connect(self.pbtnDeleteImage, SIGNAL("clicked()"), self.deleteImage) MObject.connect(self.pbtnSaveAsImage, SIGNAL("clicked()"), self.saveAsImage) MObject.connect(self.pbtnCancelAddImage, SIGNAL("clicked()"), self.cancelAddImage) MObject.connect(self.pbtnSelectImage, SIGNAL("clicked()"), self.selectImage) self.leImagePath = MLineEdit("") self.lblImagePath = MLabel(translate("MusicDetails", "Image Path: ")) self.cbImageType = MComboBox() self.cbImageType.addItems(Taggers.getTagger().getImageTypes()) self.lblImageType = MLabel(translate("MusicDetails", "Image Type: ")) self.lstwImages = MListWidget() self.lstwImages.setGridSize(MSize(350, 100)) self.lstwImages.setIconSize(MSize(98, 98)) MObject.connect(self.lstwImages, SIGNAL("doubleClicked(QModelIndex)"), self.openImageDetails) MObject.connect(self.isGetFromAmarok, SIGNAL("toggled(bool)"), self.isGetFromAmarokTiggered) self.lstwImages.clear() for image in self.musicValues["images"]: if len(image) == 5: pixmImage = MPixmap() pixmImage.loadFromData(image[3]) icnImage = QIcon(pixmImage) icnImage.actualSize(MSize(98, 98)) item = MListWidgetItem(icnImage, image[1] + "\n(" + image[2] + ")") item.setSizeHint(MSize(1, 100)) self.lstwImages.addItem(item) HBOXs = [] HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["baseNameOfDirectory"]) HBOXs[-1].addWidget(self.infoValues["baseNameOfDirectory"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["baseName"]) HBOXs[-1].addWidget(self.infoValues["baseName"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["artist"]) HBOXs[-1].addWidget(self.infoValues["artist"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["title"]) HBOXs[-1].addWidget(self.infoValues["title"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["album"]) HBOXs[-1].addWidget(self.infoValues["album"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["albumArtist"]) HBOXs[-1].addWidget(self.infoValues["albumArtist"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["trackNum"]) HBOXs[-1].addWidget(self.infoValues["trackNum"]) HBOXs[-1].addWidget(self.infoLabels["year"]) HBOXs[-1].addWidget(self.infoValues["year"]) HBOXs[-1].addWidget(self.infoLabels["genre"]) HBOXs[-1].addWidget(self.infoValues["genre"]) vblInfos = MVBoxLayout() for hbox in HBOXs: vblInfos.addLayout(hbox) if Taggers.getTagger().isSupportImages: imageBoxs = [] imageBoxs.append(MHBoxLayout()) imageBoxs[0].addWidget(self.leImagePath) imageBoxs[0].addWidget(self.pbtnSelectImage) imageBoxs.append(MHBoxLayout()) imageBoxs[1].addWidget(self.lblImageType) imageBoxs[1].addWidget(self.cbImageType) imageBoxs.append(MHBoxLayout()) imageBoxs[2].addWidget(self.pbtnAddImage) imageBoxs[2].addWidget(self.pbtnDeleteImage) imageBoxs[2].addWidget(self.pbtnSaveAsImage) imageBoxs[2].addWidget(self.pbtnCancelAddImage) vblImages = MVBoxLayout() vblImages.addWidget(self.lstwImages) vblImages.addWidget(self.isOpenImageDetailsOnNewWindow) vblImages.addWidget(self.lblImagePath) vblImages.addLayout(imageBoxs[0]) vblImages.addLayout(imageBoxs[1]) vblImages.addLayout(imageBoxs[2]) vblComments = MVBoxLayout() vblComments.addWidget(self.infoValues["firstComment"]) vblLyrics = MVBoxLayout() vblLyrics.addWidget(self.infoValues["firstLyrics"]) self.tabwTabs = MTabWidget(self.pnlMain) self.pnlComments = MWidget(self.tabwTabs) self.pnlComments.setLayout(vblComments) self.tabwTabs.addTab(self.pnlComments, translate("MusicDetails", "Comments")) self.pnlLyrics = MWidget(self.tabwTabs) self.pnlLyrics.setLayout(vblLyrics) self.tabwTabs.addTab(self.pnlLyrics, translate("MusicDetails", "Lyrics")) if Taggers.getTagger().isSupportImages: self.pnlImages = MWidget(self.tabwTabs) self.pnlImages.setLayout(vblImages) self.tabwTabs.addTab(self.pnlImages, translate("MusicDetails", "Images")) self.pbtnSelectImage.hide() self.leImagePath.hide() self.lblImagePath.hide() self.lblImageType.hide() self.cbImageType.hide() self.pbtnCancelAddImage.hide() hblPlayer = MHBoxLayout() vblExtraButtons = MVBoxLayout() hblPlayer.addWidget(self.player) vblExtraButtons.addWidget(self.isPlayNow) vblExtraButtons.addWidget(self.isGetFromAmarok) hblPlayer.addLayout(vblExtraButtons) vblClearable.addLayout(hblPlayer) vblClearable.addLayout(vblInfos) vblClearable.addWidget(self.tabwTabs)
def writeContents(self): self.changedValueNumber = 0 oldAndNewPathValues = [] if uni.isActiveAmarok and uni.getBoolValue("isSubFolderTableValuesChangeInAmarokDB"): import Amarok if Amarok.checkAmarok(True, False) is False: return False uni.startThreadAction() allItemNumber = len(self.values) Dialogs.showState(translate("FileUtils/SubFolders", "Writing File Informations"), 0, allItemNumber, True) for rowNo in range(self.rowCount()): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: if fu.isWritableFileOrDir(self.values[rowNo]["path"], False, True): if self.isRowHidden(rowNo): fu.removeFileOrDir(self.values[rowNo]["path"]) self.changedValueNumber += 1 else: baseNameOfDirectory = str(self.values[rowNo]["baseNameOfDirectory"]) baseName = str(self.values[rowNo]["baseName"]) if self.isChangeableItem(rowNo, "baseNameOfDirectory", baseNameOfDirectory): baseNameOfDirectory = str(self.item(rowNo, 0).text()) self.changedValueNumber += 1 newDirectoryPath = fu.joinPath( fu.getDirName(fu.getDirName(self.values[rowNo]["path"])), baseNameOfDirectory) self.setNewDirectory(newDirectoryPath) if self.isChangeableItem(rowNo, "baseName", baseName, False): baseName = str(self.item(rowNo, 1).text()) self.changedValueNumber += 1 newFilePath = fu.joinPath(str(self.values[rowNo]["path"]).replace( fu.joinPath(str(self.values[rowNo]["baseNameOfDirectory"]), str(self.values[rowNo]["baseName"])), ""), baseNameOfDirectory, baseName) oldFilePath = fu.getRealPath(self.values[rowNo]["path"]) newFilePath = fu.getRealPath(newFilePath) if oldFilePath != newFilePath: oldAndNewPaths = {} oldAndNewPaths["oldPath"] = oldFilePath oldAndNewPaths["newPath"] = fu.moveOrChange(oldFilePath, newFilePath, "file") if oldFilePath != oldAndNewPaths["newPath"]: oldAndNewPathValues.append(oldAndNewPaths) oldDirName = fu.getDirName(oldFilePath) if uni.getBoolValue("isClearEmptyDirectoriesWhenFileMove"): fu.checkEmptyDirectories(oldDirName, True, True, uni.getBoolValue("isAutoCleanSubFolderWhenFileMove")) if (uni.isActiveDirectoryCover and uni.getBoolValue("isActiveAutoMakeIconToDirectory") and uni.getBoolValue("isAutoMakeIconToDirectoryWhenFileMove")): fu.checkIcon(oldDirName) fu.checkIcon(fu.getDirName(oldAndNewPaths["newPath"])) except: ReportBug.ReportBug() else: allItemNumber = rowNo + 1 Dialogs.showState(translate("FileUtils/SubFolders", "Writing File Informations"), rowNo + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() if (uni.isActiveAmarok and uni.getBoolValue("isSubFolderTableValuesChangeInAmarokDB") and len(oldAndNewPathValues) > 0): import Amarok from Amarok import Operations Operations.changePaths(oldAndNewPathValues, "file") return True
def refreshTable(self, _path): self.values = [] uni.startThreadAction() import Amarok Dialogs.showState(translate("AmarokMusicTable", "Getting Values From Amarok"), 0, 1) if Amarok.checkAmarok(): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: from Amarok import Operations directoriesAndValues = Operations.getDirectoriesAndValues(uni.MySettings[self.amarokFilterKeyName]) Dialogs.showState(translate("AmarokMusicTable", "Values Are Being Processed"), 1, 1) isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: if directoriesAndValues is not None: allItemNumber = len(directoriesAndValues) self.setRowCount(allItemNumber) rowNo = 0 for dirPath, dirRow in directoriesAndValues.items(): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: if fu.isReadableFileOrDir(dirPath, False, True) and fu.isReadableFileOrDir( fu.joinPath(dirPath, ".directory"), False, True): content = {} content["path"] = dirPath content["pathOfParentDirectory"] = fu.getDirName(dirPath) content["baseName"] = fu.getBaseName(dirPath) currentCover, isCorrectedFileContent = fu.getIconFromDirectory(dirPath) if currentCover is None: currentCover = "" content["currentCover"] = (currentCover) content["sourceCover"] = (dirRow["coverPath"][0].replace(dirPath, ".")) content["destinationCover"] = ("./" + Organizer.getIconName( dirRow["artist"][0], dirRow["album"][0], dirRow["genre"][0], dirRow["year"][0])) content["flagColor"] = {} if isCorrectedFileContent is False: content["flagColor"]["currentCover"] = 255, 163, 163 if fu.isFile(content["sourceCover"]) is False: content["flagColor"]["sourceCover"] = 255, 163, 163 self.values.append(content) newPathOfParentDirectory = Organizer.emend( self.values[rowNo]["pathOfParentDirectory"], "directory") self.createItem(rowNo, "pathOfParentDirectory", newPathOfParentDirectory, self.values[rowNo]["pathOfParentDirectory"]) newBaseName = Organizer.emend(self.values[rowNo]["baseName"], "directory") self.createItem(rowNo, "pathOfParentDirectory", newBaseName, self.values[rowNo]["baseName"]) newCurrentCover = fu.getShortPath(self.values[rowNo]["currentCover"], self.values[rowNo]["path"]) itemCurrentCover = self.createItem(rowNo, "currentCover", newCurrentCover, newCurrentCover, True) self.setItemColor(itemCurrentCover, rowNo, 2, "currentCover") newSourceCover = fu.getShortPath(self.values[rowNo]["sourceCover"], self.values[rowNo]["path"]) itemSourceCover = self.createItem(rowNo, "sourceCover", newSourceCover, fu.getShortPath( self.values[rowNo]["currentCover"], self.values[rowNo]["path"])) self.setItemColor(itemSourceCover, rowNo, 3, "sourceCover") newDestinationCover = Organizer.emend( fu.getShortPath(self.values[rowNo]["destinationCover"], self.values[rowNo]["path"]), "file") itemDestinationCover = self.createItem(rowNo, "destinationCover", newDestinationCover, fu.getShortPath( self.values[rowNo]["currentCover"], self.values[rowNo]["path"])) self.setItemColor(itemDestinationCover, rowNo, 4, "destinationCover") rowNo += 1 else: allItemNumber -= 1 except: ReportBug.ReportBug() allItemNumber -= 1 else: allItemNumber = rowNo Dialogs.showState(translate("Tables", "Generating Table..."), rowNo, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() self.setRowCount(len(self.values)) # In case of Non Readable Files and Canceled process
def goUp(self): try: self.goTo(str(fu.getDirName(self.currentDirectory))) except: ReportBug.ReportBug()
def writeContents(self): self.changedValueNumber = 0 oldAndNewPathValues = [] isNewDirectoriesSame = True isMovedToNewDirectory = False currentDirectoryPath = "" newDirectoryPath = "" startRowNo, rowStep = 0, 1 uni.startThreadAction() allItemNumber = len(self.values) Dialogs.showState( translate("FileUtils/Covers", "Writing Cover Informations"), 0, allItemNumber, True) for rowNo in range(startRowNo, self.rowCount(), rowStep): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: if fu.isWritableFileOrDir(self.values[rowNo]["path"], False, True): if self.isRowHidden(rowNo): fu.removeFileOrDir(self.values[rowNo]["path"]) self.changedValueNumber += 1 else: baseNameOfDirectory = str( self.values[rowNo]["baseNameOfDirectory"]) baseName = str(self.values[rowNo]["baseName"]) if (self.isChangeableItem(rowNo, "sourceCover") or self.isChangeableItem( rowNo, "destinationCover")): sourcePath = self.values[rowNo]["sourceCover"] destinationPath = self.values[rowNo][ "destinationCover"] if self.isChangeableItem(rowNo, "sourceCover"): sourcePath = str( self.item(rowNo, 3).text()).strip() if self.isChangeableItem( rowNo, "destinationCover"): destinationPath = str( self.item(rowNo, 4).text()).strip() if (str(self.item(rowNo, 2).text()) != sourcePath or sourcePath != destinationPath or str(self.item(rowNo, 2).text()) != destinationPath ) or (str(self.item(rowNo, 2).text()) != self.values[rowNo]["currentCover"] and (str(self.item(rowNo, 2).text()) != sourcePath and str(self.item(rowNo, 2).text()) != destinationPath)): if str(self.item(rowNo, 3).text()).strip() != "": sourcePath = fu.getRealPath( sourcePath, self.values[rowNo]["path"]) sourcePath = fu.checkSource( sourcePath, "file") if sourcePath is not None: if destinationPath != "": destinationPath = fu.getRealPath( destinationPath, self.values[rowNo]["path"]) if sourcePath != destinationPath: destinationPath = fu.moveOrChange( sourcePath, destinationPath) else: destinationPath = sourcePath fu.setIconToDirectory( self.values[rowNo]["path"], destinationPath) self.changedValueNumber += 1 else: fu.setIconToDirectory( self.values[rowNo]["path"], "") self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "baseNameOfDirectory", baseNameOfDirectory): baseNameOfDirectory = str( self.item(rowNo, 0).text()) self.changedValueNumber += 1 isMovedToNewDirectory = True currentDirectoryPath = fu.getDirName( self.values[rowNo]["path"]) newDirectoryPath = fu.joinPath( fu.getDirName( fu.getDirName( self.values[rowNo]["path"])), baseNameOfDirectory) self.setNewDirectory(newDirectoryPath) if rowNo > 0: if str(self.item( rowNo - 1, 0).text()) != baseNameOfDirectory: isNewDirectoriesSame = False if self.isChangeableItem(rowNo, "baseName", baseName, False): baseName = str(self.item(rowNo, 1).text()) self.changedValueNumber += 1 newFilePath = fu.joinPath( fu.getDirName( fu.getDirName(self.values[rowNo]["path"])), baseNameOfDirectory, baseName) oldFilePath = fu.getRealPath( self.values[rowNo]["path"]) newFilePath = fu.getRealPath(newFilePath) if oldFilePath != newFilePath: oldAndNewPaths = {} oldAndNewPaths["oldPath"] = oldFilePath oldAndNewPaths["newPath"] = fu.moveOrChange( oldFilePath, newFilePath, "directory") if oldFilePath != oldAndNewPaths["newPath"]: oldAndNewPathValues.append(oldAndNewPaths) oldDirName = fu.getDirName(oldFilePath) if uni.getBoolValue( "isClearEmptyDirectoriesWhenFileMove" ): fu.checkEmptyDirectories( oldDirName, True, True, uni.getBoolValue( "isAutoCleanSubFolderWhenFileMove" )) except: ReportBug.ReportBug() else: allItemNumber = rowNo + 1 Dialogs.showState( translate("FileUtils/Covers", "Writing Cover Informations"), rowNo + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() if self.rowCount() == len( oldAndNewPathValues ) and isMovedToNewDirectory and isNewDirectoriesSame: otherFileNames = fu.readDirectory(currentDirectoryPath, "fileAndDirectory", True) if len(otherFileNames) > 0: answer = Dialogs.ask( translate("FileUtils/Musics", "There Are More Files"), str( translate( "FileUtils/Musics", "\"%s\" : there are more files in this directory.<br>Are you want to move all found files into new directory?<br>New Directory : \"%s\"" )) % (Organizer.getLink(currentDirectoryPath), Organizer.getLink(newDirectoryPath))) if answer == Dialogs.Yes: uni.startThreadAction() allItemNumber = len(otherFileNames) for rowNo, fileName in enumerate(otherFileNames): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: oldFilePath = fu.getRealPath( fu.joinPath(currentDirectoryPath, fileName)) newFilePath = fu.getRealPath( fu.joinPath(newDirectoryPath, fileName)) if oldFilePath != newFilePath: oldAndNewPaths = {} oldAndNewPaths["oldPath"] = oldFilePath oldAndNewPaths[ "newPath"] = fu.moveOrChange( oldFilePath, newFilePath, fu.getObjectType(oldFilePath)) if oldFilePath != oldAndNewPaths["newPath"]: oldAndNewPathValues.append( oldAndNewPaths) except: ReportBug.ReportBug() else: allItemNumber = rowNo + 1 Dialogs.showState( translate( "FileUtils/Covers", "Writing Directory And File Informations"), rowNo + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() if uni.getBoolValue("isClearEmptyDirectoriesWhenFileMove"): fu.checkEmptyDirectories( currentDirectoryPath, True, True, uni.getBoolValue( "isAutoCleanSubFolderWhenFileMove")) if (uni.isActiveDirectoryCover and uni.getBoolValue("isActiveAutoMakeIconToDirectory") and uni.getBoolValue( "isAutoMakeIconToDirectoryWhenFileMove")): fu.checkIcon(newDirectoryPath) return True
def refreshTable(self, _path): self.values = [] self.setColumnWidth(6, 70) self.setColumnWidth(7, 40) musicFileNames = fu.readDirectoryWithSubDirectoriesThread(_path, int(uni.MySettings["subDirectoryDeep"]), "music", uni.getBoolValue( "isShowHiddensInSubFolderMusicTable")) isCanNoncompatible = False allItemNumber = len(musicFileNames) uni.startThreadAction() rowNo = 0 self.setRowCount(allItemNumber) for filePath in musicFileNames: isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: if fu.isReadableFileOrDir(filePath, False, True): tagger = Taggers.getTagger() try: tagger.loadFile(filePath) except: Dialogs.showError(translate("FileUtils/Musics", "Incorrect Tag"), str(translate("FileUtils/Musics", "\"%s\" : this file has the incorrect tag so can't read tags.") ) % Organizer.getLink(filePath)) if tagger.isAvailableFile() is False: isCanNoncompatible = True details = fu.getDetails(filePath) content = {} content["path"] = filePath content["baseNameOfDirectory"] = str( str(fu.getBaseName(_path)) + str(fu.getDirName(filePath)).replace(_path, "")) content["baseName"] = fu.getBaseName(filePath) content["artist"] = tagger.getArtist() content["title"] = tagger.getTitle() content["album"] = tagger.getAlbum() content["albumArtist"] = tagger.getAlbumArtist() content["trackNum"] = tagger.getTrackNum() content["year"] = tagger.getYear() content["genre"] = tagger.getGenre() content["firstComment"] = tagger.getFirstComment() content["firstLyrics"] = tagger.getFirstLyrics() if tagger.isSupportInfo: content["length"] = tagger.getLength() content["bitrate"] = tagger.getBitrate() content["sampleRate"] = tagger.getSampleRate() content["mode"] = tagger.getMode() content["size"] = details[stat.ST_SIZE] content["lastAccessed"] = details[stat.ST_ATIME] content["lastModified"] = details[stat.ST_MTIME] content["lastMetadataChanged"] = details[stat.ST_CTIME] self.values.append(content) newBaseNameOfDirectory = Organizer.emend(self.values[rowNo]["baseNameOfDirectory"], "directory") self.createItem(rowNo, "baseNameOfDirectory", newBaseNameOfDirectory, self.values[rowNo]["baseNameOfDirectory"]) newBaseName = Organizer.emend(self.values[rowNo]["baseName"], "file") self.createItem(rowNo, "baseName", newBaseName, self.values[rowNo]["baseName"]) newArtist = Organizer.emend(self.values[rowNo]["artist"]) self.createItem(rowNo, "artist", newArtist, self.values[rowNo]["artist"]) newTitle = Organizer.emend(self.values[rowNo]["title"]) self.createItem(rowNo, "title", newTitle, self.values[rowNo]["title"]) newAlbum = Organizer.emend(self.values[rowNo]["album"]) self.createItem(rowNo, "album", newAlbum, self.values[rowNo]["album"]) newAlbumArtist = Organizer.emend(self.values[rowNo]["albumArtist"]) self.createItem(rowNo, "albumArtist", newAlbumArtist, self.values[rowNo]["albumArtist"]) newTrackNum = str(self.values[rowNo]["trackNum"]) self.createItem(rowNo, "trackNum", newTrackNum, self.values[rowNo]["trackNum"]) newYear = Organizer.emend(self.values[rowNo]["year"]) self.createItem(rowNo, "year", newYear, self.values[rowNo]["year"]) newGenre = Organizer.emend(self.values[rowNo]["genre"]) self.createItem(rowNo, "genre", newGenre, self.values[rowNo]["genre"]) newFirstComment = Organizer.emend(self.values[rowNo]["firstComment"]) self.createItem(rowNo, "firstComment", newFirstComment, self.values[rowNo]["firstComment"]) newFirstLyrics = Organizer.emend(self.values[rowNo]["firstLyrics"]) self.createItem(rowNo, "firstLyrics", newFirstLyrics, self.values[rowNo]["firstLyrics"]) if tagger.isSupportInfo: self.createItem(rowNo, "length", content["length"]) self.createItem(rowNo, "bitrate", content["bitrate"]) self.createItem(rowNo, "sampleRate", content["sampleRate"]) self.createItem(rowNo, "mode", content["mode"]) self.createItem(rowNo, "size", Organizer.getCorrectedFileSize(content["size"])) self.createItem(rowNo, "lastAccessed", Organizer.getCorrectedTime(content["lastAccessed"])) self.createItem(rowNo, "lastModified", Organizer.getCorrectedTime(content["lastModified"])) self.createItem(rowNo, "lastMetadataChanged", Organizer.getCorrectedTime(content["lastMetadataChanged"])) rowNo += 1 else: allItemNumber -= 1 except: ReportBug.ReportBug() allItemNumber -= 1 else: allItemNumber = rowNo Dialogs.showState(translate("Tables", "Generating Table..."), rowNo, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() self.setRowCount(len(self.values)) # In case of Non Readable Files and Canceled process if isCanNoncompatible: Dialogs.show(translate("FileUtils/Musics", "Possible ID3 Mismatch"), translate("FileUtils/Musics", "Some of the files presented in the table may not support ID3 technology.<br>Please check the files and make sure they support ID3 information before proceeding."))
def refreshTable(self, _path): self.values = [] allFilesAndDirectories = fu.readDirectoryWithSubDirectoriesThread( _path, int(uni.MySettings["CoversSubDirectoryDeep"]), "directory", uni.getBoolValue("isShowHiddensInCoverTable")) allItemNumber = len(allFilesAndDirectories) uni.startThreadAction() rowNo = 0 self.setRowCount(allItemNumber) for dirName in allFilesAndDirectories: isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: if fu.isReadableFileOrDir( dirName, False, True) and fu.isReadableFileOrDir( fu.joinPath(dirName, ".directory"), False, True): content = {} content["path"] = dirName content["baseNameOfDirectory"] = str( str(fu.getBaseName(_path)) + str(fu.getDirName(dirName)).replace(_path, "")) content["baseName"] = fu.getBaseName(dirName) currentCover, isCorrectedFileContent = fu.getIconFromDirectory( dirName) selectedName = None if isCorrectedFileContent and currentCover is not None: selectedName = fu.getBaseName(currentCover) sourceCover = fu.getFirstImageInDirectory( dirName, selectedName, False, False) if currentCover is None: currentCover = "" if sourceCover is None: sourceCover = "" else: sourceCover = fu.joinPath(dirName, sourceCover) content["currentCover"] = (currentCover) content["sourceCover"] = (sourceCover) content["destinationCover"] = (sourceCover) content["isCorrectedFileContent"] = ( isCorrectedFileContent) self.values.append(content) newBaseNameOfDirectory = Organizer.emend( self.values[rowNo]["baseNameOfDirectory"], "directory") self.createItem( rowNo, "baseNameOfDirectory", newBaseNameOfDirectory, self.values[rowNo]["baseNameOfDirectory"]) newBaseName = Organizer.emend( self.values[rowNo]["baseName"], "directory") self.createItem(rowNo, "baseName", newBaseName, self.values[rowNo]["baseName"]) newCurrentCover = str( self.values[rowNo]["currentCover"]) newCurrentCover = newCurrentCover.replace( self.values[rowNo]["path"], ".") itemCurrentCover = self.createItem( rowNo, "currentCover", newCurrentCover, newCurrentCover, True) if self.values[rowNo][ "isCorrectedFileContent"] is False: itemCurrentCover.setBackground( MBrush(MColor(255, 163, 163))) newSourceCover = str(self.values[rowNo]["sourceCover"]) newSourceCover = newSourceCover.replace( self.values[rowNo]["path"], ".") oldSourceCover = self.values[rowNo]["currentCover"] oldSourceCover = oldSourceCover.replace( self.values[rowNo]["path"], ".") self.createItem(rowNo, "sourceCover", newSourceCover, oldSourceCover) newDestinationCover = self.values[rowNo][ "destinationCover"] newDestinationCover = newDestinationCover.replace( self.values[rowNo]["path"], ".") newDestinationCover = Organizer.emend( newDestinationCover, "file") oldDestinationCover = self.values[rowNo][ "currentCover"] oldDestinationCover = oldDestinationCover.replace( self.values[rowNo]["path"], ".") self.createItem(rowNo, "destinationCover", newDestinationCover, oldDestinationCover) rowNo += 1 else: allItemNumber -= 1 except: ReportBug.ReportBug() allItemNumber -= 1 else: allItemNumber = rowNo Dialogs.showState(translate("Tables", "Generating Table..."), rowNo, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() self.setRowCount(len( self.values)) # In case of Non Readable Files and Canceled process
def createPage(self, _pageNo): pnlPage = MWidget() HBox = MHBoxLayout() pnlPage.setLayout(HBox) if _pageNo == 0: if fu.isFile(fu.joinPath(fu.HamsiManagerDirectory, "Languages", "About_" + defaultLangCode)): aboutFileContent = fu.readFromFile( fu.joinPath(fu.HamsiManagerDirectory, "Languages", "About_" + defaultLangCode), "utf-8") else: aboutFileContent = fu.readFromFile( fu.joinPath(fu.HamsiManagerDirectory, "Languages", "About_en_GB"), "utf-8") lblAbout = MLabel(str(aboutFileContent)) lblAbout.setWordWrap(True) HBox.addWidget(lblAbout) elif _pageNo == 1: if fu.isFile(fu.joinPath(fu.HamsiManagerDirectory, "Languages", "License_" + defaultLangCode)): licenceFileContent = fu.readFromFile( fu.joinPath(fu.HamsiManagerDirectory, "Languages", "License_" + defaultLangCode), "utf-8") else: licenceFileContent = fu.readFromFile( fu.joinPath(fu.HamsiManagerDirectory, "Languages", "License_en_GB"), "utf-8") teCopying = MTextEdit() teCopying.setPlainText(str(licenceFileContent)) HBox.addWidget(teCopying) elif _pageNo == 2: lblPleaseSelect = MLabel(translate("Install", "Please Select A Folder For Installation.")) installationDirPath = Settings.getUniversalSetting("HamsiManagerPath", None) if installationDirPath is not None: installationDirPath = fu.getDirName(installationDirPath) else: installationDirPath = fu.joinPath(fu.getDirName(fu.HamsiManagerDirectory), "Hamsi") self.leInstallationDirectory = MLineEdit( str(Settings.getUniversalSetting("pathOfInstallationDirectory", str(installationDirPath)))) self.pbtnSelectInstallationDirectory = MPushButton(translate("Install", "Browse")) self.connect(self.pbtnSelectInstallationDirectory, SIGNAL("clicked()"), self.selectInstallationDirectory) VBox = MVBoxLayout() VBox.addStretch(10) VBox.addWidget(lblPleaseSelect) HBox1 = MHBoxLayout() HBox1.addWidget(self.leInstallationDirectory) HBox1.addWidget(self.pbtnSelectInstallationDirectory) VBox.addLayout(HBox1) VBox.addStretch(10) HBox.addLayout(VBox) elif _pageNo == 3: VBox = MVBoxLayout() self.lblActions = MLabel("") self.prgbState = MProgressBar() VBox.addWidget(self.lblActions) VBox.addWidget(self.prgbState) HBox.addLayout(VBox) elif _pageNo == 4: VBox = MVBoxLayout() self.lblFinished = MLabel(translate("Install", "Installation Complete.")) VBox.addStretch(10) VBox.addWidget(self.lblFinished) VBox.addStretch(2) self.isCreateDesktopShortcut = None self.isCreateExecutableLink = None if uni.isRunningAsRoot(): self.isCreateExecutableLink = MCheckBox(translate("Install", "Add To The System")) self.isCreateExecutableLink.setCheckState(Mt.Checked) lblExecutableLink = MLabel(translate("Install", "Executable Link Path : ")) self.leExecutableLink = MLineEdit( str(Settings.getUniversalSetting("HamsiManagerExecutableLinkPath", "/usr/bin/hamsi"))) self.connect(self.isCreateExecutableLink, SIGNAL("stateChanged(int)"), self.createExecutableLinkChanged) VBox.addWidget(self.isCreateExecutableLink) HBox1 = MHBoxLayout() HBox1.addWidget(lblExecutableLink) HBox1.addWidget(self.leExecutableLink) VBox.addLayout(HBox1) else: self.isCreateDesktopShortcut = MCheckBox(translate("Install", "Create Desktop Shortcut.")) self.isCreateDesktopShortcut.setCheckState(Mt.Checked) VBox.addWidget(self.isCreateDesktopShortcut) VBox.addStretch(10) HBox.addLayout(VBox) return pnlPage
def refreshTable(self, _path): self.values = [] allFilesAndDirectories = fu.readDirectoryWithSubDirectoriesThread(_path, int(uni.MySettings["subDirectoryDeep"]), "file", uni.getBoolValue( "isShowHiddensInSubFolderTable")) allItemNumber = len(allFilesAndDirectories) uni.startThreadAction() rowNo = 0 self.setRowCount(allItemNumber) for baseName in allFilesAndDirectories: isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: if fu.isReadableFileOrDir(baseName, False, True): details = fu.getExtendedDetails(fu.joinPath(_path, baseName)) content = {} content["path"] = baseName content["baseNameOfDirectory"] = str( str(fu.getBaseName(_path)) + str(fu.getDirName(baseName)).replace(_path, "")) content["baseName"] = fu.getBaseName(baseName) content.update(details) self.values.append(content) newBaseNameOfDirectory = Organizer.emend(content["baseNameOfDirectory"], "directory") self.createItem(rowNo, "baseNameOfDirectory", newBaseNameOfDirectory, content["baseNameOfDirectory"]) newBaseName = Organizer.emend(content["baseName"], "file") self.createItem(rowNo, "baseName", newBaseName, content["baseName"]) self.createItem(rowNo, "size", Organizer.getCorrectedFileSize(content["size"])) self.createItem(rowNo, "lastAccessed", Organizer.getCorrectedTime(content["lastAccessed"])) self.createItem(rowNo, "lastModified", Organizer.getCorrectedTime(content["lastModified"])) self.createItem(rowNo, "lastMetadataChanged", Organizer.getCorrectedTime(content["lastMetadataChanged"])) if not uni.isWindows: self.createItem(rowNo, "accessRights", content["accessRights"]) self.createItem(rowNo, "userIDOfOwner", content["userIDOfOwner"]) self.createItem(rowNo, "groupIDOfOwner", content["groupIDOfOwner"]) self.createItem(rowNo, "numberOfHardLinks", content["numberOfHardLinks"]) rowNo += 1 else: allItemNumber -= 1 except: ReportBug.ReportBug() allItemNumber -= 1 else: allItemNumber = rowNo Dialogs.showState(translate("Tables", "Generating Table..."), rowNo, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() self.setRowCount(len(self.values)) # In case of Non Readable Files and Canceled process
def refreshTable(self, _path): self.values = [] self.setColumnWidth(6, 70) self.setColumnWidth(7, 40) uni.startThreadAction() import Amarok Dialogs.showState( translate("AmarokMusicTable", "Getting Values From Amarok"), 0, 1) if Amarok.checkAmarok(): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: from Amarok import Operations musicFileValuesWithNames = Operations.getAllMusicFileValuesWithNames( uni.MySettings[self.amarokFilterKeyName]) Dialogs.showState( translate("AmarokMusicTable", "Values Are Being Processed"), 1, 1) isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: if musicFileValuesWithNames is not None: allItemNumber = len(musicFileValuesWithNames) self.setRowCount(allItemNumber) rowNo = 0 for musicFileRow in musicFileValuesWithNames: isContinueThreadAction = uni.isContinueThreadAction( ) if isContinueThreadAction: try: if (fu.isFile(musicFileRow["filePath"]) and fu.isReadableFileOrDir( musicFileRow["filePath"], False, True)): details = fu.getDetails( musicFileRow["filePath"]) content = {} if Amarok.getSelectedTagSourseType( "AmarokMusicTable" ) == "Amarok (Smart)": content["path"] = musicFileRow[ "filePath"] content[ "baseNameOfDirectory"] = fu.getBaseName( fu.getDirName(musicFileRow[ "filePath"])) content[ "baseName"] = fu.getBaseName( musicFileRow["filePath"]) content["artist"] = musicFileRow[ "artist"] content["title"] = musicFileRow[ "title"] content["album"] = musicFileRow[ "album"] content[ "albumArtist"] = musicFileRow[ "albumArtist"] content["trackNum"] = musicFileRow[ "trackNumber"] content["year"] = musicFileRow[ "year"] content["genre"] = musicFileRow[ "genre"] content[ "firstComment"] = musicFileRow[ "comment"] content[ "firstLyrics"] = musicFileRow[ "lyrics"] tagger = Taggers.getTagger() try: tagger.loadFile( musicFileRow["filePath"]) except: if tagger.isSupportInfo: content["length"] = "" content["bitrate"] = "" content["sampleRate"] = "" content["mode"] = "" else: if content["artist"].strip( ) == "": content[ "artist"] = tagger.getArtist( ) if content["title"].strip( ) == "": content[ "title"] = tagger.getTitle( ) if content["album"].strip( ) == "": content[ "album"] = tagger.getAlbum( ) if content[ "albumArtist"].strip( ) == "": content[ "albumArtist"] = tagger.getAlbumArtist( ) if str(content["trackNum"] ).strip() == "": content[ "trackNum"] = tagger.getTrackNum( ) if str(content["year"]).strip( ) == "": content[ "year"] = tagger.getYear( ) if content["genre"].strip( ) == "": content[ "genre"] = tagger.getGenre( ) if content[ "firstComment"].strip( ) == "": content[ "firstComment"] = tagger.getFirstComment( ) if content[ "firstLyrics"].strip( ) == "": content[ "firstLyrics"] = tagger.getFirstLyrics( ) if tagger.isSupportInfo: content[ "length"] = tagger.getLength( ) content[ "bitrate"] = tagger.getBitrate( ) content[ "sampleRate"] = tagger.getSampleRate( ) content[ "mode"] = tagger.getMode( ) elif Amarok.getSelectedTagSourseType( "AmarokMusicTable" ) == "Only Amarok": content["path"] = musicFileRow[ "filePath"] content[ "baseNameOfDirectory"] = fu.getBaseName( fu.getDirName(musicFileRow[ "filePath"])) content[ "baseName"] = fu.getBaseName( musicFileRow["filePath"]) content["artist"] = musicFileRow[ "artist"] content["title"] = musicFileRow[ "title"] content["album"] = musicFileRow[ "album"] content[ "albumArtist"] = musicFileRow[ "albumArtist"] content["trackNum"] = musicFileRow[ "trackNumber"] content["year"] = musicFileRow[ "year"] content["genre"] = musicFileRow[ "genre"] content[ "firstComment"] = musicFileRow[ "comment"] content[ "firstLyrics"] = musicFileRow[ "lyrics"] tagger = Taggers.getTagger() if tagger.isSupportInfo: try: tagger.loadFile( musicFileRow[ "filePath"]) except: content["length"] = "" content["bitrate"] = "" content["sampleRate"] = "" content["mode"] = "" else: content[ "length"] = tagger.getLength( ) content[ "bitrate"] = tagger.getBitrate( ) content[ "sampleRate"] = tagger.getSampleRate( ) content[ "mode"] = tagger.getMode( ) else: tagger = Taggers.getTagger() try: tagger.loadFile( musicFileRow["filePath"]) except: Dialogs.showError( translate( "FileUtils/Musics", "Incorrect Tag"), str( translate( "FileUtils/Musics", "\"%s\" : this file has the incorrect tag so can't read tags." )) % Organizer.getLink( musicFileRow[ "filePath"])) content["path"] = musicFileRow[ "filePath"] content[ "baseNameOfDirectory"] = fu.getBaseName( fu.getDirName(musicFileRow[ "filePath"])) content[ "baseName"] = fu.getBaseName( musicFileRow["filePath"]) content[ "artist"] = tagger.getArtist() content["title"] = tagger.getTitle( ) content["album"] = tagger.getAlbum( ) content[ "albumArtist"] = tagger.getAlbumArtist( ) content[ "trackNum"] = tagger.getTrackNum( ) content["year"] = tagger.getYear() content["genre"] = tagger.getGenre( ) content[ "firstComment"] = tagger.getFirstComment( ) content[ "firstLyrics"] = tagger.getFirstLyrics( ) if tagger.isSupportInfo: content[ "length"] = tagger.getLength( ) content[ "bitrate"] = tagger.getBitrate( ) content[ "sampleRate"] = tagger.getSampleRate( ) content[ "mode"] = tagger.getMode() content["size"] = details[stat.ST_SIZE] content["lastAccessed"] = details[ stat.ST_ATIME] content["lastModified"] = details[ stat.ST_MTIME] content[ "lastMetadataChanged"] = details[ stat.ST_CTIME] self.values.append(content) newBaseNameOfDirectory = Organizer.emend( self.values[rowNo] ["baseNameOfDirectory"], "directory") self.createItem( rowNo, "baseNameOfDirectory", newBaseNameOfDirectory, self.values[rowNo] ["baseNameOfDirectory"]) newBaseName = Organizer.emend( self.values[rowNo]["baseName"], "file") self.createItem( rowNo, "baseName", newBaseName, self.values[rowNo]["baseName"]) newArtist = Organizer.emend( self.values[rowNo]["artist"]) self.createItem( rowNo, "artist", newArtist, self.values[rowNo]["artist"]) newTitle = Organizer.emend( self.values[rowNo]["title"]) self.createItem( rowNo, "title", newTitle, self.values[rowNo]["title"]) newAlbum = Organizer.emend( self.values[rowNo]["album"]) self.createItem( rowNo, "album", newAlbum, self.values[rowNo]["album"]) newAlbumArtist = Organizer.emend( self.values[rowNo]["albumArtist"]) self.createItem( rowNo, "albumArtist", newAlbumArtist, self.values[rowNo]["albumArtist"]) newTrackNum = str( self.values[rowNo]["trackNum"]) self.createItem( rowNo, "trackNum", newTrackNum, self.values[rowNo]["trackNum"]) newYear = Organizer.emend( self.values[rowNo]["year"]) self.createItem( rowNo, "year", newYear, self.values[rowNo]["year"]) newGenre = Organizer.emend( self.values[rowNo]["genre"]) self.createItem( rowNo, "genre", newGenre, self.values[rowNo]["genre"]) newFirstComment = Organizer.emend( self.values[rowNo]["firstComment"]) self.createItem( rowNo, "firstComment", newFirstComment, self.values[rowNo]["firstComment"]) newFirstLyrics = Organizer.emend( self.values[rowNo]["firstLyrics"]) self.createItem( rowNo, "firstLyrics", newFirstLyrics, self.values[rowNo]["firstLyrics"]) if Taggers.getTagger().isSupportInfo: self.createItem( rowNo, "length", content["length"]) self.createItem( rowNo, "bitrate", content["bitrate"]) self.createItem( rowNo, "sampleRate", content["sampleRate"]) self.createItem( rowNo, "mode", content["mode"]) self.createItem( rowNo, "size", Organizer.getCorrectedFileSize( content["size"])) self.createItem( rowNo, "lastAccessed", Organizer.getCorrectedTime( content["lastAccessed"])) self.createItem( rowNo, "lastModified", Organizer.getCorrectedTime( content["lastModified"])) self.createItem( rowNo, "lastMetadataChanged", Organizer.getCorrectedTime( content["lastMetadataChanged"]) ) rowNo += 1 else: allItemNumber -= 1 except: ReportBug.ReportBug() allItemNumber -= 1 else: allItemNumber = rowNo Dialogs.showState( translate("Tables", "Generating Table..."), rowNo, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() self.setRowCount(len( self.values)) # In case of Non Readable Files and Canceled process
def refreshTable(self, _path): self.values = [] self.setColumnWidth(6, 70) self.setColumnWidth(7, 40) musicFileNames = fu.readDirectoryWithSubDirectoriesThread( _path, int(uni.MySettings["subDirectoryDeep"]), "music", uni.getBoolValue("isShowHiddensInSubFolderMusicTable")) isCanNoncompatible = False allItemNumber = len(musicFileNames) uni.startThreadAction() rowNo = 0 self.setRowCount(allItemNumber) for filePath in musicFileNames: isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: if fu.isReadableFileOrDir(filePath, False, True): tagger = Taggers.getTagger() try: tagger.loadFile(filePath) except: Dialogs.showError( translate("FileUtils/Musics", "Incorrect Tag"), str( translate( "FileUtils/Musics", "\"%s\" : this file has the incorrect tag so can't read tags." )) % Organizer.getLink(filePath)) if tagger.isAvailableFile() is False: isCanNoncompatible = True details = fu.getDetails(filePath) content = {} content["path"] = filePath content["baseNameOfDirectory"] = str( str(fu.getBaseName(_path)) + str(fu.getDirName(filePath)).replace(_path, "")) content["baseName"] = fu.getBaseName(filePath) content["artist"] = tagger.getArtist() content["title"] = tagger.getTitle() content["album"] = tagger.getAlbum() content["albumArtist"] = tagger.getAlbumArtist() content["trackNum"] = tagger.getTrackNum() content["year"] = tagger.getYear() content["genre"] = tagger.getGenre() content["firstComment"] = tagger.getFirstComment() content["firstLyrics"] = tagger.getFirstLyrics() if tagger.isSupportInfo: content["length"] = tagger.getLength() content["bitrate"] = tagger.getBitrate() content["sampleRate"] = tagger.getSampleRate() content["mode"] = tagger.getMode() content["size"] = details[stat.ST_SIZE] content["lastAccessed"] = details[stat.ST_ATIME] content["lastModified"] = details[stat.ST_MTIME] content["lastMetadataChanged"] = details[stat.ST_CTIME] self.values.append(content) newBaseNameOfDirectory = Organizer.emend( self.values[rowNo]["baseNameOfDirectory"], "directory") self.createItem( rowNo, "baseNameOfDirectory", newBaseNameOfDirectory, self.values[rowNo]["baseNameOfDirectory"]) newBaseName = Organizer.emend( self.values[rowNo]["baseName"], "file") self.createItem(rowNo, "baseName", newBaseName, self.values[rowNo]["baseName"]) newArtist = Organizer.emend( self.values[rowNo]["artist"]) self.createItem(rowNo, "artist", newArtist, self.values[rowNo]["artist"]) newTitle = Organizer.emend(self.values[rowNo]["title"]) self.createItem(rowNo, "title", newTitle, self.values[rowNo]["title"]) newAlbum = Organizer.emend(self.values[rowNo]["album"]) self.createItem(rowNo, "album", newAlbum, self.values[rowNo]["album"]) newAlbumArtist = Organizer.emend( self.values[rowNo]["albumArtist"]) self.createItem(rowNo, "albumArtist", newAlbumArtist, self.values[rowNo]["albumArtist"]) newTrackNum = str(self.values[rowNo]["trackNum"]) self.createItem(rowNo, "trackNum", newTrackNum, self.values[rowNo]["trackNum"]) newYear = Organizer.emend(self.values[rowNo]["year"]) self.createItem(rowNo, "year", newYear, self.values[rowNo]["year"]) newGenre = Organizer.emend(self.values[rowNo]["genre"]) self.createItem(rowNo, "genre", newGenre, self.values[rowNo]["genre"]) newFirstComment = Organizer.emend( self.values[rowNo]["firstComment"]) self.createItem(rowNo, "firstComment", newFirstComment, self.values[rowNo]["firstComment"]) newFirstLyrics = Organizer.emend( self.values[rowNo]["firstLyrics"]) self.createItem(rowNo, "firstLyrics", newFirstLyrics, self.values[rowNo]["firstLyrics"]) if tagger.isSupportInfo: self.createItem(rowNo, "length", content["length"]) self.createItem(rowNo, "bitrate", content["bitrate"]) self.createItem(rowNo, "sampleRate", content["sampleRate"]) self.createItem(rowNo, "mode", content["mode"]) self.createItem( rowNo, "size", Organizer.getCorrectedFileSize(content["size"])) self.createItem( rowNo, "lastAccessed", Organizer.getCorrectedTime( content["lastAccessed"])) self.createItem( rowNo, "lastModified", Organizer.getCorrectedTime( content["lastModified"])) self.createItem( rowNo, "lastMetadataChanged", Organizer.getCorrectedTime( content["lastMetadataChanged"])) rowNo += 1 else: allItemNumber -= 1 except: ReportBug.ReportBug() allItemNumber -= 1 else: allItemNumber = rowNo Dialogs.showState(translate("Tables", "Generating Table..."), rowNo, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() self.setRowCount(len( self.values)) # In case of Non Readable Files and Canceled process if isCanNoncompatible: Dialogs.show( translate("FileUtils/Musics", "Possible ID3 Mismatch"), translate( "FileUtils/Musics", "Some of the files presented in the table may not support ID3 technology.<br>Please check the files and make sure they support ID3 information before proceeding." ))