def save(self): try: from Core import Records Records.setTitle(translate("MusicDetails", "Music File")) newMusicValues = {} newMusicValues["baseNameOfDirectory"] = str(self.infoValues["baseNameOfDirectory"].text()) newMusicValues["baseName"] = str(self.infoValues["baseName"].text()) newMusicValues["artist"] = str(self.infoValues["artist"].text()) newMusicValues["title"] = str(self.infoValues["title"].text()) newMusicValues["album"] = str(self.infoValues["album"].text()) newMusicValues["albumArtist"] = str(self.infoValues["albumArtist"].text()) newMusicValues["trackNum"] = str(self.infoValues["trackNum"].text()) newMusicValues["year"] = str(self.infoValues["year"].text()) newMusicValues["genre"] = str(self.infoValues["genre"].text()) newMusicValues["firstComment"] = str(self.infoValues["firstComment"].toPlainText()) newMusicValues["firstLyrics"] = str(self.infoValues["firstLyrics"].toPlainText()) newPath = Musics.writeMusicFile(self.musicValues, newMusicValues) if newPath != self.musicValues["path"]: self.changeFile(newPath) if hasattr(getMainWindow(), "FileManager") and getMainWindow().FileManager is not None: getMainWindow().FileManager.makeRefresh() Records.saveAllRecords() except: ReportBug.ReportBug()
def save(self): try: filePath = str(self.leFilePath.text()) if self.fileValues is not None: from Core import Records Records.setTitle(translate("TextCorrector", "Text File")) newFileValues = {} newFileValues["path"] = filePath newFileValues["content"] = str( self.pteFileContent.toPlainText()) newPath = fu.writeTextFile(self.fileValues, newFileValues, str(self.charSet.currentText())) if newPath != self.fileValues["path"]: self.changeFile(newPath) if hasattr(getMainWindow(), "FileManager") and getMainWindow( ).FileManager is not None: getMainWindow().FileManager.makeRefresh() Records.saveAllRecords() else: Dialogs.showError( translate("TextCorrector", "File Does Not Exist"), str( translate( "TextDetails", "\"%s\" does not exist.<br>Please select an exist file and try again." )) % Organizer.getLink(str(filePath))) except: ReportBug.ReportBug()
def writeContents(self): self.changedValueNumber = 0 changedArtistValues = [] 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: if self.isRowHidden(rowNo) is False: if self.isChangeableItem(rowNo, "correctedArtist", str(self.values[rowNo]["currentArtist"])): changedArtistValues.append({}) changedArtistValues[-1]["id"] = str(self.values[rowNo]["id"]) value = str(self.item(rowNo, 1).text()) changedArtistValues[-1]["name"] = value Records.add(str(translate("AmarokArtistTable", "Artist")), str(self.values[rowNo]["currentArtist"]), value) self.changedValueNumber += 1 except: ReportBug.ReportBug() else: allItemNumber = rowNo + 1 Dialogs.showState(translate("FileUtils/Musics", "Writing Music Tags"), rowNo + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() Operations.changeArtistValues(changedArtistValues) return True
def save(self): try: from Core import Records Records.setTitle(translate("MusicDetails", "Music File")) newMusicValues = {} newMusicValues["baseNameOfDirectory"] = str( self.infoValues["baseNameOfDirectory"].text()) newMusicValues["baseName"] = str( self.infoValues["baseName"].text()) newMusicValues["artist"] = str(self.infoValues["artist"].text()) newMusicValues["title"] = str(self.infoValues["title"].text()) newMusicValues["album"] = str(self.infoValues["album"].text()) newMusicValues["albumArtist"] = str( self.infoValues["albumArtist"].text()) newMusicValues["trackNum"] = str( self.infoValues["trackNum"].text()) newMusicValues["year"] = str(self.infoValues["year"].text()) newMusicValues["genre"] = str(self.infoValues["genre"].text()) newMusicValues["firstComment"] = str( self.infoValues["firstComment"].toPlainText()) newMusicValues["firstLyrics"] = str( self.infoValues["firstLyrics"].toPlainText()) newPath = Musics.writeMusicFile(self.musicValues, newMusicValues) if newPath != self.musicValues["path"]: self.changeFile(newPath) if hasattr( getMainWindow(), "FileManager") and getMainWindow().FileManager is not None: getMainWindow().FileManager.makeRefresh() Records.saveAllRecords() except: ReportBug.ReportBug()
def executeStringCommand(_command): if uni.isWindows: _command = "start" + _command Records.add("Execute >>> " + str(_command)) try: correctedCommand = uni.trEncode(_command, fu.fileSystemEncoding) except: correctedCommand = _command return os.popen(correctedCommand)
def setRecordsFile(self, _filePath=None): try: if _filePath is None: self.teRecords.setPlainText(str(Records.read())) else: self.teRecords.setPlainText(str(Records.read(_filePath))) except: ReportBug.ReportBug()
def save(self): try: Records.setTitle(translate("AmarokArtistDetails", "Amarok - Artist")) Operations.changeArtistValues( [{"id": self.artistId, "name": str(self.infoValues["correctedArtist"].text())}]) if self.artistName != str(self.infoValues["correctedArtist"].text()): self.changeArtist(Commands.getArtistId(str(self.infoValues["correctedArtist"].text()))) if hasattr(getMainWindow(),"FileManager") and getMainWindow().FileManager is not None: getMainWindow().FileManager.makeRefresh() Records.saveAllRecords() except: ReportBug.ReportBug()
def save(self): try: from Core import Records Records.setTitle(uni.getTableTypesNames()[uni.tableType]) fu.activateSmartCheckIcon() fu.activateSmartCheckEmptyDirectories() from Core import MyThread myProcs = MyThread.MyThread(self.saveTable, self.continueSave) myProcs.run() except: ReportBug.ReportBug()
def execute(_command=[], _executableName=None): if _executableName in ["HamsiManager", "HamsiManagerInstaller"]: pathOfExecutable = findExecutablePath(_executableName) if pathOfExecutable.find(".py") > -1 or pathOfExecutable.find(".py3") > -1 or pathOfExecutable.find(".pyw") > -1: pathOfExecutable = [getPythonPath(), pathOfExecutable] else: pathOfExecutable = [pathOfExecutable] _command = pathOfExecutable + _command if len(_command) > 1 and _command[1][0] is not "-" and _command[0].find("kdesu") > -1: tCommand = _command[0] del _command[0] for c in _command: if c.find(" ") > -1 or c.find("'") > -1: c = "'" + c + "'" tCommand += " \"" + (" ".join(_command)) + "\"" _command = tCommand Records.add("Execute >>> " + str(_command)) Records.saveAllRecords() return subprocess.Popen(args=uni.trEncode(_command, fu.fileSystemEncoding), stdin=subprocess.PIPE, stdout=subprocess.PIPE, bufsize=1, shell=True) else: Records.add("Execute >>> " + str(_command)) Records.saveAllRecords() try: correctedCommand = uni.trEncodeList(_command, fu.fileSystemEncoding) except: correctedCommand = _command return subprocess.Popen(args=correctedCommand, stdin=subprocess.PIPE, stdout=subprocess.PIPE, bufsize=1)
def getCommandResult(_command, _cwd=None): if uni.isWindows: _command = ["start"] + _command Records.add("Execute >>> " + str(_command)) try: correctedCommand = uni.trEncodeList(_command, fu.fileSystemEncoding) except: correctedCommand = _command if _cwd is not None: myPopen = subprocess.Popen(correctedCommand, stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True, cwd=_cwd) else: myPopen = subprocess.Popen(correctedCommand, stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True) po, pi = myPopen.stdin, myPopen.stdout po.close() return pi.read()
def save(self): try: from Core import Records Records.setTitle(translate("TextDetails", "Text File")) newFileValues = {} newFileValues["path"] = str(self.infoValues["path"].text()) newFileValues["content"] = str(self.infoValues["content"].toPlainText()) newPath = fu.writeTextFile(self.fileValues, newFileValues, str(self.charSet.currentText())) if newPath != self.fileValues["path"]: self.changeFile(newPath) if hasattr(getMainWindow(), "FileManager") and getMainWindow().FileManager is not None: getMainWindow().FileManager.makeRefresh() Records.saveAllRecords() except: ReportBug.ReportBug()
def openWith(_command): if uni.isWindows: Records.add("Open With >>> " + str(_command)) try: _command = uni.trEncodeList(_command, fu.fileSystemEncoding) except: _command = _command correctedCommand = "" for x, commandPart in enumerate(_command): if x > 0: correctedCommand += " " correctedCommand += commandPart return os.startfile(correctedCommand) else: _command = ["xdg-open"] + _command Records.add("Open With >>> " + str(_command)) try: correctedCommand = uni.trEncodeList(_command, fu.fileSystemEncoding) except: correctedCommand = _command return subprocess.Popen(correctedCommand)
def continueSave(self, _returned=None): try: if _returned: from Core import Records if uni.tableType in ["0", "1", "2", "3", "4", "9"]: if uni.getBoolValue("isClearEmptyDirectoriesWhenSave"): fu.checkEmptyDirectories( self.currentDirectoryPath, True, True, uni.getBoolValue("isAutoCleanSubFolderWhenSave")) fu.completeSmartCheckEmptyDirectories(True, True) isDirStillExist = fu.isDir(self.currentDirectoryPath) if uni.tableType in ["0", "1", "2", "3", "9"]: if (uni.isActiveDirectoryCover and uni.getBoolValue("isActiveAutoMakeIconToDirectory") and uni.getBoolValue( "isAutoMakeIconToDirectoryWhenSave")): if isDirStillExist: fu.checkIcon(self.currentDirectoryPath) if self.currentDirectoryPath != self.newDirectoryPath: fu.checkIcon(self.newDirectoryPath) fu.completeSmartCheckIcon() Records.saveAllRecords() if self.changedValueNumber == 0: Dialogs.show( translate("Tables", "Did Not Change Any Things"), translate( "Tables", "Did not change any things in this table.Please check the criteria you select." )) else: if uni.getBoolValue("isShowTransactionDetails"): Dialogs.show( translate("Tables", "Transaction Details"), str(translate("Tables", "%s value(s) changed.")) % self.changedValueNumber) if not isDirStillExist and self.currentDirectoryPath == self.newDirectoryPath: getMainWindow().FileManager.goUp() elif not isDirStillExist and self.currentDirectoryPath != self.newDirectoryPath: getMainWindow().FileManager.makeRefresh( self.newDirectoryPath) else: getMainWindow().FileManager.makeRefresh("") if uni.tableType in ["5", "6", "7", "8"]: self.refresh(self.newDirectoryPath) except: ReportBug.ReportBug()
def changeArtistValues(_values): uni.startThreadAction() allItemNumber = len(_values) Dialogs.showState(translate("Amarok/Operations", "Writing Music Tags"), 0, allItemNumber, True) for x, value in enumerate(_values): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: musicFilePathAndArtist = Commands.changeArtistValue(value) if musicFilePathAndArtist is not None: artistName = musicFilePathAndArtist[0] for musicFilePath in musicFilePathAndArtist[1]: if fu.isWritableFileOrDir(musicFilePath, False, True): Records.add(str(translate("Amarok/Operations", "File will be updated")), str(musicFilePath)) currentArtistName = "" tagger = Taggers.getTagger() if tagger is not None: try: tagger.loadFileForWrite(musicFilePath) currentArtistName = tagger.getArtist() except: tagger.loadFileForWrite(musicFilePath) tagger.setArtist(artistName) tagger.update() Records.add(str(translate("Amarok/Operations", "Artist")), str(currentArtistName), artistName) for musicFilePath in musicFilePathAndArtist[2]: if fu.isWritableFileOrDir(musicFilePath, False, True): Records.add(str(translate("Amarok/Operations", "File will be updated")), str(musicFilePath)) currentArtistName = "" tagger = Taggers.getTagger() if tagger is not None: try: tagger.loadFileForWrite(musicFilePath) currentArtistName = tagger.getAlbumArtist() except: tagger.loadFileForWrite(musicFilePath) tagger.setAlbumArtist(artistName) tagger.update() Records.add(str(translate("Amarok/Operations", "albumArtist")), str(currentArtistName), artistName) except: ReportBug.ReportBug() else: allItemNumber = x + 1 Dialogs.showState(translate("Amarok/Operations", "Writing Music Tags"), x + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction()
def clear(self): try: answer = Dialogs.ask( translate("RecordsForm", "Are You Sure?"), translate("RecordsForm", "Are you sure you want to remove this record file?")) if answer == Dialogs.Yes: if self.cbRecordsList.currentIndex() == 0: Records.clearRecords() else: recordFilePath = self.recordsList[ self.cbRecordsList.currentIndex()] fu.removeFile( fu.joinPath(fu.oldRecordsDirectoryPath, recordFilePath)) self.recordsList = [ translate("RecordsForm", "Current Records") ] + Records.getBackupRecordsList() self.cbRecordsList.clear() self.cbRecordsList.addItems(self.recordsList) self.setRecordsFile() except: ReportBug.ReportBug()
def save(self): try: filePath = str(self.leFilePath.text()) if self.fileValues is not None: from Core import Records Records.setTitle(translate("TextCorrector", "Text File")) newFileValues = {} newFileValues["path"] = filePath newFileValues["content"] = str(self.pteFileContent.toPlainText()) newPath = fu.writeTextFile(self.fileValues, newFileValues, str(self.charSet.currentText())) if newPath != self.fileValues["path"]: self.changeFile(newPath) if hasattr(getMainWindow(), "FileManager") and getMainWindow().FileManager is not None: getMainWindow().FileManager.makeRefresh() Records.saveAllRecords() else: Dialogs.showError(translate("TextCorrector", "File Does Not Exist"), str(translate("TextDetails", "\"%s\" does not exist.<br>Please select an exist file and try again.") ) % Organizer.getLink(str(filePath))) except: ReportBug.ReportBug()
def execute(_command=[], _executableName=None): if _executableName in ["HamsiManager", "HamsiManagerInstaller"]: pathOfExecutable = findExecutablePath(_executableName) if pathOfExecutable.find(".py") > -1 or pathOfExecutable.find( ".py3") > -1 or pathOfExecutable.find(".pyw") > -1: pathOfExecutable = [getPythonPath(), pathOfExecutable] else: pathOfExecutable = [pathOfExecutable] _command = pathOfExecutable + _command if len(_command) > 1 and _command[1][0] is not "-" and _command[0].find( "kdesu") > -1: tCommand = _command[0] del _command[0] for c in _command: if c.find(" ") > -1 or c.find("'") > -1: c = "'" + c + "'" tCommand += " \"" + (" ".join(_command)) + "\"" _command = tCommand Records.add("Execute >>> " + str(_command)) Records.saveAllRecords() return subprocess.Popen(args=uni.trEncode(_command, fu.fileSystemEncoding), stdin=subprocess.PIPE, stdout=subprocess.PIPE, bufsize=1, shell=True) else: Records.add("Execute >>> " + str(_command)) Records.saveAllRecords() try: correctedCommand = uni.trEncodeList(_command, fu.fileSystemEncoding) except: correctedCommand = _command return subprocess.Popen(args=correctedCommand, stdin=subprocess.PIPE, stdout=subprocess.PIPE, bufsize=1)
def __init__(self, _parent): MDialog.__init__(self, _parent) if isActivePyKDE4: self.setButtons(MDialog.NoDefault) pbtnClose = MPushButton(translate("RecordsForm", "Close")) pbtnClear = MPushButton(translate("RecordsForm", "Clear")) self.connect(pbtnClose, SIGNAL("clicked()"), self.close) self.connect(pbtnClear, SIGNAL("clicked()"), self.clear) lblRecordList = MLabel(translate("RecordsForm", "Record File")) self.recordsList = [translate("RecordsForm", "Current Records") ] + Records.getBackupRecordsList() self.cbRecordsList = Options.MyComboBox( self, self.recordsList, _currentIndexChanged=self.getFromRecordList) self.teRecords = MTextEdit() self.teRecords.setWordWrapMode(MTextOption.ManualWrap) self.setRecordsFile() pnlMain = MWidget(self) vblMain = MVBoxLayout(pnlMain) hbox = MHBoxLayout() hbox.addStretch(1) hbox.addWidget(pbtnClear, 1) hbox.addWidget(pbtnClose, 1) hbox1 = MHBoxLayout() hbox1.addWidget(lblRecordList) hbox1.addWidget(self.cbRecordsList) vblMain.addLayout(hbox1) vblMain.addWidget(self.teRecords) vblMain.addLayout(hbox) if isActivePyKDE4: self.setMainWidget(pnlMain) else: self.setLayout(vblMain) self.setWindowTitle(translate("RecordsForm", "Last Records")) self.setWindowIcon(MIcon("Images:lastActions.png")) self.setMinimumWidth(500) self.setMinimumHeight(450) self.show()
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 changeArtistValues(_values): uni.startThreadAction() allItemNumber = len(_values) Dialogs.showState(translate("Amarok/Operations", "Writing Music Tags"), 0, allItemNumber, True) for x, value in enumerate(_values): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: musicFilePathAndArtist = Commands.changeArtistValue(value) if musicFilePathAndArtist is not None: artistName = musicFilePathAndArtist[0] for musicFilePath in musicFilePathAndArtist[1]: if fu.isWritableFileOrDir(musicFilePath, False, True): Records.add( str( translate("Amarok/Operations", "File will be updated")), str(musicFilePath)) currentArtistName = "" tagger = Taggers.getTagger() if tagger is not None: try: tagger.loadFileForWrite(musicFilePath) currentArtistName = tagger.getArtist() except: tagger.loadFileForWrite(musicFilePath) tagger.setArtist(artistName) tagger.update() Records.add( str( translate("Amarok/Operations", "Artist")), str(currentArtistName), artistName) for musicFilePath in musicFilePathAndArtist[2]: if fu.isWritableFileOrDir(musicFilePath, False, True): Records.add( str( translate("Amarok/Operations", "File will be updated")), str(musicFilePath)) currentArtistName = "" tagger = Taggers.getTagger() if tagger is not None: try: tagger.loadFileForWrite(musicFilePath) currentArtistName = tagger.getAlbumArtist() except: tagger.loadFileForWrite(musicFilePath) tagger.setAlbumArtist(artistName) tagger.update() Records.add( str( translate("Amarok/Operations", "albumArtist")), str(currentArtistName), artistName) except: ReportBug.ReportBug() else: allItemNumber = x + 1 Dialogs.showState(translate("Amarok/Operations", "Writing Music Tags"), x + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction()
def writeContents(self): self.changedValueNumber = 0 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) is False: 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 if self.isChangeableItem(rowNo, "baseName", baseName, False): baseName = str(self.item(rowNo, 1).text()) self.changedValueNumber += 1 newFilePath = fu.getRealPath( fu.joinPath(str(self.leDestinationDirPath.text()), baseNameOfDirectory, baseName)) if fu.isFile(self.values[rowNo] ["path"]) and fu.isReadableFileOrDir( self.values[rowNo]["path"], False, True): if fu.isWritableFileOrDir(newFilePath, False, True): newFilePathCopied = fu.copyOrChange( self.values[rowNo]["path"], newFilePath) if self.values[rowNo][ "path"] != newFilePathCopied: newFilePath = newFilePathCopied try: tagger = Taggers.getTagger() tagger.loadFileForWrite(newFilePath) if self.isChangeableItem( rowNo, "artist"): value = str( self.item(rowNo, 2).text()) tagger.setArtist(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()) tagger.setTitle(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()) tagger.setAlbum(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()) tagger.setAlbumArtist(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()) tagger.setTrackNum(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()) tagger.setDate(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()) tagger.setGenre(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()) tagger.setFirstComment(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()) tagger.setFirstLyrics(value) Records.add( str( translate( "MusicTable", "Lyrics")), str(self.values[rowNo] ["firstLyrics"]), value) self.changedValueNumber += 1 tagger.update() except: Dialogs.showError( translate("MusicTable", "Tags Cannot Changed"), str( translate( "MusicTable", "\"%s\" : cannot be changed tags." )) % Organizer.getLink(newFilePath)) except: ReportBug.ReportBug() else: allItemNumber = rowNo + 1 Dialogs.showState( translate("FileUtils/Musics", "Writing Music Tags"), rowNo + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() 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 writeContents(self): self.changedValueNumber = 0 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) is False: 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 if self.isChangeableItem(rowNo, "baseName", baseName, False): baseName = str(self.item(rowNo, 1).text()) self.changedValueNumber += 1 newFilePath = fu.getRealPath( fu.joinPath(str(self.leDestinationDirPath.text()), baseNameOfDirectory, baseName)) if fu.isFile(self.values[rowNo]["path"]) and fu.isReadableFileOrDir( self.values[rowNo]["path"], False, True): if fu.isWritableFileOrDir(newFilePath, False, True): newFilePathCopied = fu.copyOrChange(self.values[rowNo]["path"], newFilePath) if self.values[rowNo]["path"] != newFilePathCopied: newFilePath = newFilePathCopied try: tagger = Taggers.getTagger() tagger.loadFileForWrite(newFilePath) if self.isChangeableItem(rowNo, "artist"): value = str(self.item(rowNo, 2).text()) tagger.setArtist(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()) tagger.setTitle(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()) tagger.setAlbum(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()) tagger.setAlbumArtist(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()) tagger.setTrackNum(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()) tagger.setDate(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()) tagger.setGenre(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()) tagger.setFirstComment(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()) tagger.setFirstLyrics(value) Records.add(str(translate("MusicTable", "Lyrics")), str(self.values[rowNo]["firstLyrics"]), value) self.changedValueNumber += 1 tagger.update() except: Dialogs.showError(translate("MusicTable", "Tags Cannot Changed"), str(translate("MusicTable", "\"%s\" : cannot be changed tags.") ) % Organizer.getLink(newFilePath)) except: ReportBug.ReportBug() else: allItemNumber = rowNo + 1 Dialogs.showState(translate("FileUtils/Musics", "Writing Music Tags"), rowNo + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() return True
def clickedAnAction(_action): try: actionName = _action.objectName() if actionName == "Open State": f = Dialogs.getOpenFileName(translate("MenuBar", "Open State Of Hamsi Manager"), fu.userDirectoryPath, translate("MenuBar", "Application Runner") + " (*.desktop)") if f is not None: Settings.openStateOfSettings(f) elif actionName == "Save State": f = Dialogs.getSaveFileName(translate("MenuBar", "Save State Of Hamsi Manager"), fu.joinPath(fu.userDirectoryPath, "HamsiManager.desktop"), translate("MenuBar", "Application Runner") + " (*.desktop)") if f is not None: Settings.saveStateOfSettings(f) Dialogs.show(translate("MenuBar", "Current State Saved"), translate("MenuBar", "Current state saved with preferences.<br>You can continue where you left off.")) elif actionName == "With This Profile (My Settings)": if Execute.executeAsRootWithThread(["--sDirectoryPath", fu.pathOfSettingsDirectory], "HamsiManager"): getMainWindow().close() else: Dialogs.showError(translate("MenuBar", "Can Not Run As Root"), translate("MenuBar", "Hamsi Manager can not run as root.")) elif actionName == "With Root Profile (Own Settings)": if Execute.executeAsRootWithThread([], "HamsiManager"): getMainWindow().close() else: Dialogs.showError(translate("MenuBar", "Can Not Run As Root"), translate("MenuBar", "Hamsi Manager can not run as root.")) elif actionName == "Quit": getMainWindow().close() elif actionName == "HTML Format": if _action.parent().objectName() == "Export To File": getMainTable().exportValues("file", "html", "title") elif _action.parent().objectName() == "Show In New Window": getMainTable().exportValues("dialog", "html", "title") elif _action.parent().objectName() == "Copy To Clipboard": getMainTable().exportValues("clipboard", "html", "title") elif actionName == "Text Format": if _action.parent().objectName() == "Export To File": getMainTable().exportValues("file", "plainText", "title") elif _action.parent().objectName() == "Show In New Window": getMainTable().exportValues("dialog", "plainText", "title") elif _action.parent().objectName() == "Copy To Clipboard": getMainTable().exportValues("clipboard", "plainText", "title") elif actionName == "HTML Format (File Tree)": if _action.parent().objectName() == "Export To File": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "file", "html", "fileTree", "title") elif _action.parent().objectName() == "Show In New Window": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "dialog", "html", "fileTree", "title") elif _action.parent().objectName() == "Copy To Clipboard": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "clipboard", "html", "fileTree", "title") elif actionName == "Text Format (File Tree)": if _action.parent().objectName() == "Export To File": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "file", "plainText", "fileTree", "title") elif _action.parent().objectName() == "Show In New Window": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "dialog", "plainText", "fileTree", "title") elif _action.parent().objectName() == "Copy To Clipboard": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "clipboard", "plainText", "fileTree", "title") elif actionName == "About QT": if isActivePyKDE4: QMessageBox.aboutQt(getMainWindow(), translate("MenuBar", "About QT")) else: MMessageBox.aboutQt(getMainWindow(), translate("MenuBar", "About QT")) elif actionName == "Options": from Options import OptionsForm OptionsForm.OptionsForm(getMainWindow()) elif actionName == "My Plugins": import MyPlugins MyPlugins.MyPlugins() elif actionName == "Reconfigure": from Tools import Configurator Configurator.Configurator("configurePage") elif actionName == "My Plugins (System)": Execute.execute(["--qm", "--plugins", "--runAsRoot"], "HamsiManager") elif actionName == "Reconfigure (System)": Execute.execute(["--qm", "--configurator", "--runAsRoot"], "HamsiManager") elif actionName == "Update": from Core import UpdateControl UpdateControl.UpdateControl(getMainWindow()) elif actionName == "Report Bug": ReportBug.ReportBug(True) elif actionName == "Suggest Idea": from Core import SuggestIdea SuggestIdea.SuggestIdea() elif actionName == "About Hamsi Manager": if isActivePyKDE4 is False: MMessageBox.about(getMainWindow(), translate("MenuBar", "About Hamsi Manager"), uni.aboutOfHamsiManager) elif actionName == translate("ToolsBar", "Check Icon"): getMainWindow().setEnabled(False) fu.checkIcon(getMainWindow().FileManager.getCurrentDirectoryPath()) Dialogs.show(translate("ToolsBar", "Directory Icon Checked"), translate("ToolsBar", "Current directory icon checked.<br>The default action based on the data is executed.")) getMainWindow().setEnabled(True) elif actionName == "Clear Empty Directories": if getMainTable().checkUnSavedValues() is False: _action.setChecked(False) return False answer = Dialogs.ask(translate("ToolsBar", "Empty Directories Will Be Removed"), str(translate("ToolsBar", "Are you sure you want to remove empty directories based on the criteria you set in \"%s\"?")) % Organizer.getLink( getMainWindow().FileManager.getCurrentDirectoryPath())) if answer == Dialogs.Yes: getMainWindow().setEnabled(False) currentDirPath = getMainWindow().FileManager.getCurrentDirectoryPath() if fu.isWritableFileOrDir(currentDirPath): fu.checkEmptyDirectories(currentDirPath, True, True, True, True) Dialogs.show(translate("ToolsBar", "Directory Cleaned"), translate("ToolsBar", "The current directory is cleaned based on the criteria you set.")) getMainWindow().setEnabled(True) getMainWindow().FileManager.makeRefresh() elif actionName == "Pack": from Tools import Packager Packager.Packager(getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Hash": from Tools import Hasher Hasher.Hasher(getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Clear": from Tools import Cleaner Cleaner.Cleaner(getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Text Corrector": from Tools import TextCorrector TextCorrector.TextCorrector(getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "File Tree": from Tools import FileTreeBuilder FileTreeBuilder.FileTreeBuilder(getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Search": from Tools import Searcher Searcher.Searcher([getMainWindow().FileManager.getCurrentDirectoryPath()]) elif actionName == "Script Manager": from Tools import ScriptManager if ScriptManager.ScriptManager.checkScriptManager(): ScriptManager.ScriptManager(getMainWindow()) elif actionName == "Show Last Actions": from Core import RecordsForm RecordsForm.RecordsForm(getMainWindow()) elif actionName == "Remove Sub Files": answer = Dialogs.ask(translate("ToolsBar", "All Files Will Be Removed"), str(translate("ToolsBar", "Are you sure you want to remove only all files in \"%s\"?<br>Note:Do not will remove directory and subfolders.")) % Organizer.getLink( getMainWindow().FileManager.getCurrentDirectoryPath())) if answer == Dialogs.Yes: getMainWindow().setEnabled(False) fu.removeOnlySubFiles(getMainWindow().FileManager.getCurrentDirectoryPath()) getMainWindow().setEnabled(True) Dialogs.show(translate("ToolsBar", "Removed Only All Files"), str(translate("ToolsBar", "Removed only all files in \"%s\".<br>Note:Do not removed directory and subfolders.")) % Organizer.getLink( getMainWindow().FileManager.getCurrentDirectoryPath())) elif actionName == "Amarok Embedded Database Configurator": import Amarok if Amarok.checkAmarok(): Amarok.openEmbeddedDBConfigurator() elif _action.parent().objectName() == "Table Types": changeTableType(_action) elif _action.parent().objectName() == "File Renamer Types": changeReNamerType(_action) elif _action.parent().objectName() == "Scripts": from Core import Scripts Scripts.runScriptFile(fu.joinPath(Scripts.pathOfScripsDirectory, actionName)) Records.saveAllRecords() except: ReportBug.ReportBug()
def clickedAnAction(_action): try: actionName = _action.objectName() if actionName == "Open State": f = Dialogs.getOpenFileName( translate("MenuBar", "Open State Of Hamsi Manager"), fu.userDirectoryPath, translate("MenuBar", "Application Runner") + " (*.desktop)") if f is not None: Settings.openStateOfSettings(f) elif actionName == "Save State": f = Dialogs.getSaveFileName( translate("MenuBar", "Save State Of Hamsi Manager"), fu.joinPath(fu.userDirectoryPath, "HamsiManager.desktop"), translate("MenuBar", "Application Runner") + " (*.desktop)") if f is not None: Settings.saveStateOfSettings(f) Dialogs.show( translate("MenuBar", "Current State Saved"), translate( "MenuBar", "Current state saved with preferences.<br>You can continue where you left off." )) elif actionName == "With This Profile (My Settings)": if Execute.executeAsRootWithThread( ["--sDirectoryPath", fu.pathOfSettingsDirectory], "HamsiManager"): getMainWindow().close() else: Dialogs.showError( translate("MenuBar", "Can Not Run As Root"), translate("MenuBar", "Hamsi Manager can not run as root.")) elif actionName == "With Root Profile (Own Settings)": if Execute.executeAsRootWithThread([], "HamsiManager"): getMainWindow().close() else: Dialogs.showError( translate("MenuBar", "Can Not Run As Root"), translate("MenuBar", "Hamsi Manager can not run as root.")) elif actionName == "Quit": getMainWindow().close() elif actionName == "HTML Format": if _action.parent().objectName() == "Export To File": getMainTable().exportValues("file", "html", "title") elif _action.parent().objectName() == "Show In New Window": getMainTable().exportValues("dialog", "html", "title") elif _action.parent().objectName() == "Copy To Clipboard": getMainTable().exportValues("clipboard", "html", "title") elif actionName == "Text Format": if _action.parent().objectName() == "Export To File": getMainTable().exportValues("file", "plainText", "title") elif _action.parent().objectName() == "Show In New Window": getMainTable().exportValues("dialog", "plainText", "title") elif _action.parent().objectName() == "Copy To Clipboard": getMainTable().exportValues("clipboard", "plainText", "title") elif actionName == "HTML Format (File Tree)": if _action.parent().objectName() == "Export To File": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "file", "html", "fileTree", "title") elif _action.parent().objectName() == "Show In New Window": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "dialog", "html", "fileTree", "title") elif _action.parent().objectName() == "Copy To Clipboard": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "clipboard", "html", "fileTree", "title") elif actionName == "Text Format (File Tree)": if _action.parent().objectName() == "Export To File": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "file", "plainText", "fileTree", "title") elif _action.parent().objectName() == "Show In New Window": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "dialog", "plainText", "fileTree", "title") elif _action.parent().objectName() == "Copy To Clipboard": fu.getFileTree((getMainWindow().FileManager.currentDirectory), 0, "clipboard", "plainText", "fileTree", "title") elif actionName == "About QT": if isActivePyKDE4: QMessageBox.aboutQt(getMainWindow(), translate("MenuBar", "About QT")) else: MMessageBox.aboutQt(getMainWindow(), translate("MenuBar", "About QT")) elif actionName == "Options": from Options import OptionsForm OptionsForm.OptionsForm(getMainWindow()) elif actionName == "My Plugins": import MyPlugins MyPlugins.MyPlugins() elif actionName == "Reconfigure": from Tools import Configurator Configurator.Configurator("configurePage") elif actionName == "My Plugins (System)": Execute.execute(["--qm", "--plugins", "--runAsRoot"], "HamsiManager") elif actionName == "Reconfigure (System)": Execute.execute(["--qm", "--configurator", "--runAsRoot"], "HamsiManager") elif actionName == "Update": from Core import UpdateControl UpdateControl.UpdateControl(getMainWindow()) elif actionName == "Report Bug": ReportBug.ReportBug(True) elif actionName == "Suggest Idea": from Core import SuggestIdea SuggestIdea.SuggestIdea() elif actionName == "About Hamsi Manager": if isActivePyKDE4 is False: MMessageBox.about(getMainWindow(), translate("MenuBar", "About Hamsi Manager"), uni.aboutOfHamsiManager) elif actionName == translate("ToolsBar", "Check Icon"): getMainWindow().setEnabled(False) fu.checkIcon(getMainWindow().FileManager.getCurrentDirectoryPath()) Dialogs.show( translate("ToolsBar", "Directory Icon Checked"), translate( "ToolsBar", "Current directory icon checked.<br>The default action based on the data is executed." )) getMainWindow().setEnabled(True) elif actionName == "Clear Empty Directories": if getMainTable().checkUnSavedValues() is False: _action.setChecked(False) return False answer = Dialogs.ask( translate("ToolsBar", "Empty Directories Will Be Removed"), str( translate( "ToolsBar", "Are you sure you want to remove empty directories based on the criteria you set in \"%s\"?" )) % Organizer.getLink( getMainWindow().FileManager.getCurrentDirectoryPath())) if answer == Dialogs.Yes: getMainWindow().setEnabled(False) currentDirPath = getMainWindow( ).FileManager.getCurrentDirectoryPath() if fu.isWritableFileOrDir(currentDirPath): fu.checkEmptyDirectories(currentDirPath, True, True, True, True) Dialogs.show( translate("ToolsBar", "Directory Cleaned"), translate( "ToolsBar", "The current directory is cleaned based on the criteria you set." )) getMainWindow().setEnabled(True) getMainWindow().FileManager.makeRefresh() elif actionName == "Pack": from Tools import Packager Packager.Packager( getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Hash": from Tools import Hasher Hasher.Hasher( getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Clear": from Tools import Cleaner Cleaner.Cleaner( getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Text Corrector": from Tools import TextCorrector TextCorrector.TextCorrector( getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "File Tree": from Tools import FileTreeBuilder FileTreeBuilder.FileTreeBuilder( getMainWindow().FileManager.getCurrentDirectoryPath()) elif actionName == "Search": from Tools import Searcher Searcher.Searcher( [getMainWindow().FileManager.getCurrentDirectoryPath()]) elif actionName == "Script Manager": from Tools import ScriptManager if ScriptManager.ScriptManager.checkScriptManager(): ScriptManager.ScriptManager(getMainWindow()) elif actionName == "Show Last Actions": from Core import RecordsForm RecordsForm.RecordsForm(getMainWindow()) elif actionName == "Remove Sub Files": answer = Dialogs.ask( translate("ToolsBar", "All Files Will Be Removed"), str( translate( "ToolsBar", "Are you sure you want to remove only all files in \"%s\"?<br>Note:Do not will remove directory and subfolders." )) % Organizer.getLink( getMainWindow().FileManager.getCurrentDirectoryPath())) if answer == Dialogs.Yes: getMainWindow().setEnabled(False) fu.removeOnlySubFiles( getMainWindow().FileManager.getCurrentDirectoryPath()) getMainWindow().setEnabled(True) Dialogs.show( translate("ToolsBar", "Removed Only All Files"), str( translate( "ToolsBar", "Removed only all files in \"%s\".<br>Note:Do not removed directory and subfolders." )) % Organizer.getLink( getMainWindow().FileManager.getCurrentDirectoryPath())) elif actionName == "Amarok Embedded Database Configurator": import Amarok if Amarok.checkAmarok(): Amarok.openEmbeddedDBConfigurator() elif _action.parent().objectName() == "Table Types": changeTableType(_action) elif _action.parent().objectName() == "File Renamer Types": changeReNamerType(_action) elif _action.parent().objectName() == "Scripts": from Core import Scripts Scripts.runScriptFile( fu.joinPath(Scripts.pathOfScripsDirectory, actionName)) Records.saveAllRecords() except: ReportBug.ReportBug()
def __init__(self, _isOnlyReport=False): global bugDialog, lastErrorDetails self.pathOfReportFile = None realErrorDetails = "" if bugDialog is not None: self.pathOfReportFile = bugDialog.pathOfReportFile if lastErrorDetails is not None: realErrorDetails += lastErrorDetails errorDetails = "<b>" + str( translate("ReportBug", "Note : You can check and delete your personal informations.")) + "</b><br>" try: Records.saveAllRecords() except: pass try: uni.saveSettings() except: pass if _isOnlyReport is False: lastErrorDetailsValues = sys.exc_info() uni.isRaisedAnError = True cla, error, trbk = lastErrorDetailsValues try: excArgs = error.__dict__["args"] except: excArgs = "" try: tbf = "" for x in traceback.format_tb(trbk, 5): tbf += str(x) + "<br>" except: tbf = "" realErrorDetails += "<p><b><a name='errorDetails'>" + str( translate("ReportBug", "Errors : ")) + "</a></b>" + tbf + "</p>" realErrorDetails += ( "<p><b>" + str(translate("ReportBug", "Error Name : ")) + "</b>" + str(cla.__name__) + "<br><b>" + str(translate("ReportBug", "Error : ")) + "</b>" + str(error) + "<br><b>" + str(translate("ReportBug", "Error arguments : ")) + "</b>" + str(excArgs) + "</p><hr><p><b>" + str(translate("ReportBug", "Last Signal Sender (Object Name,Object Text) : ")) + "</b>"") try: realErrorDetails += uni.trUnicode(getMainWindow().sender().objectName()) except: pass realErrorDetails += "","" try: realErrorDetails += uni.trUnicode(getMainWindow().sender().text()) except: pass realErrorDetails += """ realErrorDetails += "</p>" realErrorDetails = realErrorDetails.replace("\\n", "<br>").replace("\'", "'") lastErrorDetails = realErrorDetails errorDetails += "<hr><b>" + str(translate("ReportBug", "Active Dialog`s Titles : ")) + "</b>" try: errorDetails += str(getApplication().activeModalWidget().windowTitle()) + "," except: pass try: errorDetails += str(getApplication().activePopupWidget().windowTitle()) + "," except: pass try: errorDetails += str(getApplication().activeWindow().windowTitle()) + "," except: pass errorDetails += "<br>" try: errorDetails += "<b>" + str(translate("ReportBug", "Application Version : ")) + "</b>" errorDetails += str(uni.version) + "<br>" except: errorDetails += "<br>" try: errorDetails += "<b>" + str(translate("ReportBug", "Is Starting Successfully : ")) + "</b>" errorDetails += str(uni.isStartingSuccessfully) + "<br>" errorDetails += "<b>" + str(translate("ReportBug", "Is Quick Make : ")) + "</b>" errorDetails += str(isQuickMake) + "<br>" errorDetails += "<b>" + str(translate("ReportBug", "Quick Make Parameters : ")) + "</b>" errorDetails += str(QuickMakeParameters) + "<br>" errorDetails += "<b>" + str(translate("ReportBug", "My Parameters : ")) + "</b>" errorDetails += str(myArgvs) + "<br>" errorDetails += "<b>FileSystemCharSet : </b>" errorDetails += str(fu.defaultFileSystemEncoding) + " / " + str( sys.getfilesystemencoding()).lower() + "<br>" errorDetails += "<b>SystemCharSet : </b>" errorDetails += str(sys.getdefaultencoding().lower()) + "<br>" try: errorDetails += "<b>OS Name : </b>" errorDetails += str(os.name) + "<br>" except: errorDetails += "<br>" try: import platform errorDetails += "<b>Python Version : </b>" errorDetails += str(platform.python_version()) + "<br>" errorDetails += "<b>uname : </b>" errorDetails += str(platform.uname()) + "<br>" try: errorDetails += "<b>Linux Distribution : </b>" errorDetails += str(platform.linux_distribution()) + "<br>" except: errorDetails += "<br>" except: errorDetails += "<br>" try: errorDetails += "<b>PyQt4 (Qt) Version : </b>" errorDetails += str(PYQT_VERSION_STR) + " (" + str(MT_VERSION_STR) + ")<br>" except: errorDetails += "<br>" try: from PyKDE4 import kdecore errorDetails += "<b>PyKDE4 Version : </b>" errorDetails += str(kdecore.versionString()) + "<br>" except: errorDetails += "<br>" settingKeys = list(uni.MySettings.keys()) settingKeys.sort() for keyName in settingKeys: if uni.willNotReportSettings.count(keyName) == 0: errorDetails += "<b>" + str(keyName) + " : " + "</b>" errorDetails += str(uni.MySettings[keyName]) + "<br>" except: pass try: errorDetails += "<b>" + str(translate("ReportBug", "Table Type No : ")) + "</b>" + str( uni.tableType) + "<br>" except: pass errorDetails += str(realErrorDetails) self.createErrorPage(errorDetails) if bugDialog is None: bugDialog = ReportBugDialog(errorDetails, self.pathOfReportFile) else: try: bugDialog.teErrorDetails.setHtml(str(errorDetails.replace("<hr>", ""))) except: bugDialog.teErrorDetails.setHtml(translate("ReportBug", "I cannot send the error details due to some character errors.<br>To see the details, please click on the \"Show details file\" button.")) bugDialog.teErrorDetails.setEnabled(False) bugDialog.show()
def doAfterCloseProcesses(self): Records.saveAllRecords() Records.checkSize()
def closeEvent(self, _event): try: if uni.isRaisedAnError is False: if uni.isContinueThreadAction(): uni.cancelThreadAction() _event.ignore() uni.isStartedCloseProcess = True uni.printForDevelopers("Started closeEvent") MApplication.setQuitOnLastWindowClosed(True) try: self.PlayerBar.MusicPlayer.stop() except: pass Details.closeAllDialogs() uni.printForDevelopers("Closed Dialogs") if uni.isRaisedAnError is False: if self.Table.checkUnSavedValues() is False: uni.isStartedCloseProcess = False uni.printForDevelopers("Close ignored") _event.ignore() uni.printForDevelopers("Before self.doBeforeCloseProcesses") if self.doBeforeCloseProcesses() is False: _event.ignore() return None uni.printForDevelopers("After self.doBeforeCloseProcesses") if isActivePyKDE4: uni.printForDevelopers("Before Save KDE Configs") kconf = MGlobal.config() kconfGroup = MConfigGroup(kconf, "DirectoryOperator") self.FileManager.dirOperator.writeConfig(kconfGroup) self.FileManager.actCollection.writeSettings(kconfGroup) uni.printForDevelopers("After Save KDE Configs") uni.printForDevelopers("Before Save Configs") uni.setMySetting(self.Table.hiddenTableColumnsSettingKey, self.Table.hiddenTableColumns) Bars.setAllBarsStyleToMySettings() Records.setRecordType(1) fu.writeToBinaryFile( fu.joinPath(fu.pathOfSettingsDirectory, "LastState"), self.saveState()) Records.restoreRecordType() geometry = [self.geometry().x(), self.geometry().y(), self.geometry().width(), self.geometry().height()] uni.setMySetting("MainWindowGeometries", geometry) uni.setMySetting("lastDirectory", self.FileManager.currentDirectory) uni.setMySetting("isMainWindowMaximized", self.isMaximized()) uni.setMySetting("isShowAdvancedSelections", self.SpecialTools.isShowAdvancedSelections) uni.setMySetting("tableType", uni.tableType) uni.setMySetting("activeTabNoOfSpecialTools", self.SpecialTools.tabwTabs.currentIndex()) uni.saveSettings() Settings.saveUniversalSettings() if uni.isActiveAmarok and uni.getBoolValue("amarokIsUseHost") is False: import Amarok uni.printForDevelopers("Before Amarok.stopEmbeddedDB") Amarok.stopEmbeddedDB() uni.printForDevelopers("After Amarok.stopEmbeddedDB") uni.printForDevelopers("After Save Configs") uni.printForDevelopers("Before self.doAfterCloseProcesses") self.doAfterCloseProcesses() uni.printForDevelopers("After self.doAfterCloseProcesses") except: if ReportBug.isClose is False: ReportBug.ReportBug() _event.ignore()
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