def handle(self):
        logger.info("OpenFileActionHandler.handle invoked")
        try:
            selFiles = self._tool.gui.selectedFiles()
            if len(selFiles) != 1:
                raise err.MsgException(self.tr("Select one file, please."))

            selFile = selFiles[0]
            assert os.path.isabs(
                selFiles[0]), "Path '{}' should be absolute".format(selFile)

            if os.path.isdir(selFile):
                self._extAppMgr.openContainingDirWithExtAppManager(selFile)
            elif os.path.isfile(selFile):
                self._extAppMgr.openFileWithExtApp(selFile)
            else:
                raise err.MsgException(
                    self.
                    tr("This is not a file and not a directory, cannot open it."
                       ))

            stats.sendEvent("file_browser.open_file")

        except Exception as ex:
            show_exc_info(self._tool.gui, ex)

        else:
            self._emitHandlerSignal(HandlerSignals.STATUS_BAR_MESSAGE,
                                    self.tr("Done."), consts.STATUSBAR_TIMEOUT)
    def handle(self):
        try:
            self._tool.checkActiveRepoIsNotNone()

            rows = self._tool.gui.selectedRows()
            if len(rows) == 0:
                raise errors.MsgException(
                    self.tr("There are no selected items."))

            exportFilename = self._dialogs.getSaveFileName(
                self._tool.gui, self.tr('Save results in a file.'))
            if not exportFilename:
                raise errors.MsgException(self.tr("Operation canceled."))

            with open(exportFilename, "w", newline='') as exportFile:
                for row in rows:
                    item = self._tool.gui.itemAtRow(row)
                    if not item.hasDataRef():
                        continue
                    textline = self._tool.repo.base_path + \
                        os.sep + self._tool.gui.itemAtRow(row).data_ref.url + os.linesep
                    exportFile.write(textline)

            stats.sendEvent("items_table.export_items_file_paths")

        except Exception as ex:
            show_exc_info(self._tool.gui, ex)

        else:
            self._emitHandlerSignal(HandlerSignals.STATUS_BAR_MESSAGE,
                                    self.tr("Operation completed."),
                                    consts.STATUSBAR_TIMEOUT)
    def handle(self):
        try:
            selRows = self._tool.gui.selectedRows()
            if len(selRows) != 1:
                raise errors.MsgException(self.tr("Select one item, please."))

            dataRef = self._tool.gui.itemAtRow(selRows.pop()).data_ref

            if dataRef is None or dataRef.type != db.DataRef.FILE:
                raise errors.MsgException(
                    self.
                    tr("This action can be applied only to the items linked with files."
                       ))

            self._extAppMgr.openFileWithExtApp(
                os.path.join(self._tool.repo.base_path, dataRef.url))

            stats.sendEvent("items_table.open_item")

        except Exception as ex:
            show_exc_info(self._tool.gui, ex)

        else:
            self._emitHandlerSignal(HandlerSignals.STATUS_BAR_MESSAGE,
                                    self.tr("Done."), consts.STATUSBAR_TIMEOUT)
    def handle(self):
        try:
            self._tool.checkActiveRepoIsNotNone()

            itemIds = self._tool.gui.selectedItemIds()
            if len(itemIds) == 0:
                raise errors.MsgException(
                    self.tr("There are no selected items."))

            exportFilename = self._dialogs.getSaveFileName(
                self._tool.gui, self.tr('Save data as..'),
                self.tr("Reggata Archive File (*.raf)"))
            if not exportFilename:
                raise errors.MsgException(
                    self.tr("You haven't chosen a file. Operation canceled."))

            if not exportFilename.endswith(".raf"):
                exportFilename += ".raf"

            if os.path.exists(exportFilename):
                mbRes = self._dialogs.execMessageBox(
                    self._tool.gui,
                    text=self.tr(
                        "File {} already exists. Do you want to overwrite it?"
                    ).format(exportFilename),
                    buttons=[QtGui.QMessageBox.Yes | QtGui.QMessageBox.No])
                if mbRes != QtGui.QMessageBox.Yes:
                    return

            thread = threads.ExportItemsThread(self, self._tool.repo, itemIds,
                                               exportFilename)

            self._dialogs.startThreadWithWaitDialog(thread,
                                                    self._tool.gui,
                                                    indeterminate=False)

            self._exported = thread.exportedCount
            self._skipped = thread.skippedCount

            stats.sendEvent("items_table.export_items")

        except Exception as ex:
            show_exc_info(self._tool.gui, ex)

        else:
            self._emitHandlerSignal(
                HandlerSignals.STATUS_BAR_MESSAGE,
                self.tr("Operation completed. Exported {}, skipped {} items.").
                format(self._exported, self._skipped))
    def handle(self):
        try:
            self._tool.checkActiveRepoIsNotNone()
            self._tool.checkActiveUserIsNotNone()

            rows = self._tool.gui.selectedRows()
            if len(rows) == 0:
                raise errors.MsgException(
                    self.tr("There are no selected items."))

            tmpDir = UserConfig().get("tmp_dir", consts.DEFAULT_TMP_DIR)
            if not os.path.exists(tmpDir):
                os.makedirs(tmpDir)

            m3uFilename = str(os.getpid()) + self._tool.user.login + str(
                time.time()) + ".m3u"
            with open(os.path.join(tmpDir, m3uFilename), "wt") as m3uFile:
                for row in rows:
                    item = self._tool.gui.itemAtRow(row)
                    if item.data_ref is None:
                        continue
                    m3uFile.write(
                        os.path.join(self._tool.repo.base_path,
                                     item.data_ref.url) + os.linesep)

            self._extAppMgr.openFileWithExtApp(
                os.path.join(tmpDir, m3uFilename))

            self._emitHandlerSignal(HandlerSignals.STATUS_BAR_MESSAGE,
                                    self.tr("Done."), consts.STATUSBAR_TIMEOUT)

            stats.sendEvent("items_table.export_items_to_m3u_and_open_it")

        except Exception as ex:
            show_exc_info(self._tool.gui, ex)
    def handle(self):
        logger.info("AddFilesToRepoActionHandler.handle invoked")
        try:
            self._tool.checkActiveRepoIsNotNone()
            self._tool.checkActiveUserIsNotNone()

            files = self._tool.gui.selectedFiles()
            if len(files) == 0:
                raise err.MsgException(self.tr("There are no selected files."))

            (self._itemsCreatedCount, self._filesSkippedCount, self.lastSavedItemIds) = \
                AddItemAlgorithms.addItems(self._tool, self._dialogs, files)

            self._emitHandlerSignal(HandlerSignals.ITEM_CREATED)

            stats.sendEvent("file_browser.add_files")

        except err.CancelOperationError:
            return
        except Exception as ex:
            show_exc_info(self._tool.gui, ex)
        finally:
            self._emitHandlerSignal(
                HandlerSignals.STATUS_BAR_MESSAGE,
                self.tr(
                    "Operation completed. Added {}, skipped {} files.").format(
                        self._itemsCreatedCount, self._filesSkippedCount))
    def handle(self):
        try:
            self._tool.checkActiveRepoIsNotNone()
            self._tool.checkActiveUserIsNotNone()

            rows = self._tool.gui.selectedRows()
            if len(rows) == 0:
                raise errors.MsgException(
                    self.tr("There are no selected items."))

            startIndex = 0  #This is the index of the first image to show
            items = []
            if len(rows) == 1:
                #If there is only one selected item, pass to viewer all items in this table model
                for row in range(self._tool.gui.rowCount()):
                    items.append(self._tool.gui.itemAtRow(row))
                startIndex = rows.pop()

            else:
                for row in rows:
                    items.append(self._tool.gui.itemAtRow(row))

            iv = ImageViewer(self._tool.gui, self._tool.widgetsUpdateManager,
                             self._tool.repo, self._tool.user.login, items,
                             startIndex)
            iv.show()
            self._emitHandlerSignal(HandlerSignals.STATUS_BAR_MESSAGE,
                                    self.tr("Done."), consts.STATUSBAR_TIMEOUT)

            stats.sendEvent("items_table.open_item_with_internal_image_viewer")

        except Exception as ex:
            show_exc_info(self._tool.gui, ex)
    def handle(self):
        logger.info("RenameFileActionHandler.handle invoked")
        try:
            self._tool.checkActiveRepoIsNotNone()
            self._tool.checkActiveUserIsNotNone()

            selFiles = self._tool.gui.selectedFiles()
            if len(selFiles) != 1:
                raise err.MsgException(
                    self.tr("Please select one file or directory"))

            selFile = selFiles[0]

            newName, isOk = self._dialogs.execGetTextDialog(
                self._tool.gui, self.tr("Rename File"),
                self.tr("Enter new file name:"), os.path.basename(selFile))

            if not isOk or newName == os.path.basename(selFile):
                return

            if is_none_or_empty(newName.strip()):
                raise err.MsgException(
                    self.tr("Wrong input, file name cannot be empty."))

            if os.path.isdir(selFile):
                self.__renameDir(selFile, newName)
            elif os.path.isfile(selFile):
                self.__renameFile(selFile, newName)
            else:
                raise err.MsgException(
                    self.
                    tr("Cannot rename '{}' because it is not a file or directory."
                       .format(selFile)))

            self._emitHandlerSignal(HandlerSignals.STATUS_BAR_MESSAGE,
                                    self.tr("Done."), consts.STATUSBAR_TIMEOUT)
            self._emitHandlerSignal(HandlerSignals.ITEM_CHANGED)

            stats.sendEvent("file_browser.rename_file")

        except Exception as ex:
            show_exc_info(self._tool.gui, ex)
    def handle(self):
        try:
            selRows = self._tool.gui.selectedRows()
            if len(selRows) != 1:
                raise errors.MsgException(self.tr("Select one item, please."))

            dataRef = self._tool.gui.itemAtRow(selRows.pop()).data_ref

            if dataRef is None or dataRef.type != db.DataRef.FILE:
                raise errors.MsgException(
                    self.
                    tr("This action can be applied only to the items linked with files."
                       ))

            self._extAppMgr.openContainingDirWithExtAppManager(
                os.path.join(self._tool.repo.base_path, dataRef.url))

            stats.sendEvent("items_table.open_item_with_ext_file_manager")

        except Exception as ex:
            show_exc_info(self._tool.gui, ex)
Exemplo n.º 10
0
    def query(self, queryText, limit=0, page=1):

        self.queryText = queryText
        self.limit = limit
        self.page = page

        directory = "ASC" if self.orderDir == Qt.AscendingOrder else "DESC"

        orderBy = []
        if self.orderByColumnId is not None:
            if self.orderByColumnId == self.ID:
                orderBy.append(("id", directory))
            elif self.orderByColumnId == self.TITLE:
                orderBy.append(("title", directory))
            #This is not exactly sorting by pure rating, but by fields and their values...
            elif self.orderByColumnId == self.RATING:
                orderBy.append(("items_fields_field_id", "DESC"))
                orderBy.append(("items_fields_field_value", directory))

        def resetRow(row):
            self.resetSingleRow(row)
            QtCore.QCoreApplication.processEvents()

        uow = self._repo.createUnitOfWork()
        items = []
        try:
            if self._thread is not None and self._thread.isRunning():
                self._thread.interrupt = True
                self._thread.wait(5 * 1000)

            if queryText is None or queryText.strip() == "":
                items = uow.executeCommand(
                    cmds.GetUntaggedItems(limit, page, orderBy))
            else:
                queryTree = query_parser.parse(queryText)
                cmd = cmds.QueryItemsByParseTree(queryTree, limit, page,
                                                 orderBy)
                items = uow.executeCommand(cmd)

            self._thread = ThumbnailBuilderThread(self, self._repo, items,
                                                  self._lock)
            self.connect(self._thread, QtCore.SIGNAL("progress"),
                         lambda percents, row: resetRow(row))
            self._thread.start()

        except (errors.YaccError, errors.LexError) as ex:
            raise errors.MsgException(
                self.tr("Error in the query. Detail info: {}").format(str(ex)))

        finally:
            uow.close()
            self.setObjs(items)
    def handle(self):
        def refresh(percent, row):
            self._emitHandlerSignal(
                HandlerSignals.STATUS_BAR_MESSAGE,
                self.tr("Rebuilding thumbnails ({0}%)").format(percent))
            self._emitHandlerSignal(HandlerSignals.RESET_SINGLE_ROW, row)
            QtCore.QCoreApplication.processEvents()

        try:
            self._tool.checkActiveRepoIsNotNone()
            self._tool.checkActiveUserIsNotNone()

            rows = self._tool.gui.selectedRows()
            if len(rows) == 0:
                raise errors.MsgException(
                    self.tr("There are no selected items."))

            uow = self._tool.repo.createUnitOfWork()
            try:
                items = []
                for row in rows:
                    item = self._tool.gui.itemAtRow(row)
                    item.table_row = row
                    items.append(item)

                thread = threads.ThumbnailBuilderThread(self._tool.gui,
                                                        self._tool.repo,
                                                        items,
                                                        self._tool.itemsLock,
                                                        rebuild=True)

                self.connect(
                    thread, QtCore.SIGNAL("exception"), lambda exc_info:
                    show_exc_info(self._tool.gui,
                                  exc_info[1],
                                  details=format_exc_info(*exc_info)))
                self.connect(thread, QtCore.SIGNAL("progress"),
                             lambda percents, row: refresh(percents, row))
                self.connect(
                    thread, QtCore.SIGNAL("finished"),
                    lambda: self._emitHandlerSignal(
                        HandlerSignals.STATUS_BAR_MESSAGE,
                        self.tr("Rebuild thumbnails is done.")))
                thread.start()

            finally:
                uow.close()

            stats.sendEvent("items_table.rebuild_item_thumbnail")

        except Exception as ex:
            show_exc_info(self._tool.gui, ex)
    def handle(self):
        try:
            self._tool.checkActiveRepoIsNotNone()

            itemIds = self._tool.gui.selectedItemIds()
            if len(itemIds) == 0:
                raise errors.MsgException(
                    self.tr("There are no selected items."))

            dstDirPath = self._dialogs.getExistingDirectory(
                self._tool.gui,
                self.tr("Choose a directory path to export files into."))

            if not dstDirPath:
                raise errors.MsgException(
                    self.
                    tr("You haven't chosen existent directory. Operation canceled."
                       ))

            thread = threads.ExportItemsFilesThread(self, self._tool.repo,
                                                    itemIds, dstDirPath)

            self._dialogs.startThreadWithWaitDialog(thread,
                                                    self._tool.gui,
                                                    indeterminate=False)

            self._filesExported = thread.filesExportedCount
            self._filesSkipped = thread.filesSkippedCount

            stats.sendEvent("items_table.export_items_files")

        except Exception as ex:
            show_exc_info(self._tool.gui, ex)

        else:
            self._emitHandlerSignal(
                HandlerSignals.STATUS_BAR_MESSAGE,
                self.tr("Operation completed. Exported {}, skipped {} files.".
                        format(self._filesExported, self._filesSkipped)))
    def handle(self):
        try:
            self._tool.checkActiveRepoIsNotNone()
            self._tool.checkActiveUserIsNotNone()

            itemIds = self._tool.gui.selectedItemIds()
            if len(itemIds) == 0:
                raise errors.MsgException(
                    self.tr("There are no selected items."))

            mbResult = self._dialogs.execMessageBox(
                self._tool.gui,
                text=self.
                tr("Do you really want to delete {} selected file(s)?").format(
                    len(itemIds)),
                buttons=[QtGui.QMessageBox.Yes, QtGui.QMessageBox.No])
            if mbResult != QtGui.QMessageBox.Yes:
                raise errors.CancelOperationError()

            thread = threads.DeleteGroupOfItemsThread(self._tool.gui,
                                                      self._tool.repo, itemIds,
                                                      self._tool.user.login)

            self._dialogs.startThreadWithWaitDialog(thread,
                                                    self._tool.gui,
                                                    indeterminate=False)

            if thread.errors > 0:
                self._dialogs.execMessageBox(
                    self._tool.gui,
                    text=self.tr("There were {0} errors.").format(
                        thread.errors),
                    detailedText=thread.detailed_message)

            stats.sendEvent("items_table.delete_item")

        except errors.CancelOperationError:
            self._emitHandlerSignal(HandlerSignals.STATUS_BAR_MESSAGE,
                                    self.tr("Operation cancelled."),
                                    consts.STATUSBAR_TIMEOUT)

        except Exception as ex:
            show_exc_info(self._tool.gui, ex)

        else:
            #TODO: display information about how many items were deleted
            self._emitHandlerSignal(HandlerSignals.STATUS_BAR_MESSAGE,
                                    self.tr("Operation completed."),
                                    consts.STATUSBAR_TIMEOUT)
            self._emitHandlerSignal(HandlerSignals.ITEM_DELETED)
    def handle(self):
        def refresh(percent, row):
            self._emitHandlerSignal(
                HandlerSignals.STATUS_BAR_MESSAGE,
                self.tr("Integrity fix {0}%").format(percent))
            self._emitHandlerSignal(HandlerSignals.RESET_SINGLE_ROW, row)
            QtCore.QCoreApplication.processEvents()

        try:
            self._tool.checkActiveRepoIsNotNone()
            self._tool.checkActiveUserIsNotNone()

            rows = self._tool.gui.selectedRows()
            if len(rows) == 0:
                raise errors.MsgException(
                    self.tr("There are no selected items."))

            items = []
            for row in rows:
                item = self._tool.gui.itemAtRow(row)
                item.table_row = row
                items.append(item)

            thread = threads.ItemIntegrityFixerThread(self._tool.gui,
                                                      self._tool.repo, items,
                                                      self._tool.itemsLock,
                                                      self.__strategy,
                                                      self._tool.user.login)

            self.connect(thread, QtCore.SIGNAL("progress"),
                         lambda percents, row: refresh(percents, row))
            self.connect(
                thread, QtCore.SIGNAL("finished"),
                lambda: self._emitHandlerSignal(
                    HandlerSignals.STATUS_BAR_MESSAGE,
                    self.tr("Integrity fixing is done.")))
            self.connect(
                thread, QtCore.SIGNAL("exception"), lambda exc_info:
                show_exc_info(self._tool.gui,
                              exc_info[1],
                              details=format_exc_info(*exc_info)))
            thread.start()

            stats.sendEvent("items_table.fix_item_integrity_error")

        except Exception as ex:
            show_exc_info(self._tool.gui, ex)
    def handle(self):
        def refresh(percent, topRow, bottomRow):
            self._emitHandlerSignal(
                HandlerSignals.STATUS_BAR_MESSAGE,
                self.tr("Integrity check {0}%").format(percent))
            self._emitHandlerSignal(HandlerSignals.RESET_ROW_RANGE, topRow,
                                    bottomRow)
            QtCore.QCoreApplication.processEvents()

        try:
            self._tool.checkActiveRepoIsNotNone()
            self._tool.checkActiveUserIsNotNone()

            rows = self._tool.gui.selectedRows()
            if len(rows) == 0:
                raise errors.MsgException(
                    self.tr("There are no selected items."))

            items = []
            for row in rows:
                item = self._tool.gui.itemAtRow(row)
                item.table_row = row
                items.append(item)

            thread = threads.ItemIntegrityCheckerThread(
                self._tool.gui, self._tool.repo, items, self._tool.itemsLock)

            self.connect(
                thread, QtCore.SIGNAL("progress"),
                lambda percents, topRow, bottomRow: refresh(
                    percents, topRow, bottomRow))
            self.connect(
                thread, QtCore.SIGNAL("finished_with_1_arg"),
                lambda errorCount: self._emitHandlerSignal(
                    HandlerSignals.STATUS_BAR_MESSAGE,
                    self.tr("Integrity check is done. {} Items with errors.".
                            format(errorCount))))
            thread.start()

            stats.sendEvent("items_table.check_item_integrity_error")

        except Exception as ex:
            show_exc_info(self._tool.gui, ex)
Exemplo n.º 16
0
    def query_exec(self):
        try:
            if self.__table_model is None:
                raise errors.MsgException(
                    self.tr("Items Table Widget has no Model."))

            query_text = self.query_text()
            limit = self.query_limit()
            page = self.query_page()

            self.__table_model.query(query_text, limit, page)

            self.resize_rows_to_contents()

            stats.sendEvent("items_table.query_exec")

        except Exception as ex:
            logger.warning(str(ex))
            helpers.show_exc_info(self, ex)
Exemplo n.º 17
0
    def handle(self):
        try:
            self._tool.checkActiveRepoIsNotNone()
            self._tool.checkActiveUserIsNotNone()

            itemIds = self._tool.gui.selectedItemIds()
            if len(itemIds) == 0:
                raise err.MsgException(self.tr("There are no selected items."))

            if len(itemIds) > 1:
                updated, skipped = self.__editManyItems(itemIds)
            else:
                updated, skipped = self.__editSingleItem(itemIds.pop())

            self._emitHandlerSignal(
                HandlerSignals.STATUS_BAR_MESSAGE,
                self.tr("Editing done. Updated={}, skipped={} items.".format(
                    updated, skipped)))
            self._emitHandlerSignal(HandlerSignals.ITEM_CHANGED)

        except Exception as ex:
            hlp.show_exc_info(self._tool.gui, ex)
Exemplo n.º 18
0
 def checkThatCurrentPasswordIsCorrect(self):
     if self.__user.password != self.__currentPasswordHash:
         raise errors.MsgException("Current password is wrong.")
Exemplo n.º 19
0
 def checkThatTwoNewPasswordsAreTheSame(self):
     if self.__newPassword1Hash != self.__newPassword2Hash:
         raise errors.MsgException("Entered new passwords do not match.")