2009-06-01 09:55:11 +00:00
|
|
|
import logging
|
|
|
|
|
2010-11-20 11:42:15 +00:00
|
|
|
from jobprogress import job
|
|
|
|
from hscommon import cocoa
|
2011-09-24 20:21:20 +00:00
|
|
|
from hscommon.cocoa import install_exception_hook
|
2011-11-27 17:47:00 +00:00
|
|
|
from hscommon.cocoa.inter import signature, subproxy, PyFairware
|
2011-09-24 20:21:20 +00:00
|
|
|
from hscommon.cocoa.objcmin import (NSNotificationCenter, NSSearchPathForDirectoriesInDomains,
|
|
|
|
NSApplicationSupportDirectory, NSUserDomainMask, NSWorkspace)
|
2011-11-09 16:02:15 +00:00
|
|
|
from hscommon.trans import trget
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-09-21 20:02:13 +00:00
|
|
|
from core.app import JobType
|
2011-11-27 17:47:00 +00:00
|
|
|
from .result_table import PyResultTable
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-11-09 16:02:15 +00:00
|
|
|
tr = trget('ui')
|
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
JOBID2TITLE = {
|
2011-09-21 17:55:26 +00:00
|
|
|
JobType.Scan: tr("Scanning for duplicates"),
|
|
|
|
JobType.Load: tr("Loading"),
|
|
|
|
JobType.Move: tr("Moving"),
|
|
|
|
JobType.Copy: tr("Copying"),
|
|
|
|
JobType.Delete: tr("Sending to Trash"),
|
2009-06-01 09:55:11 +00:00
|
|
|
}
|
|
|
|
|
2011-09-20 22:40:27 +00:00
|
|
|
class PyDupeGuruBase(PyFairware):
|
|
|
|
def _init(self, modelclass):
|
|
|
|
logging.basicConfig(level=logging.WARNING, format='%(levelname)s %(message)s')
|
|
|
|
install_exception_hook()
|
|
|
|
appdata = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, True)[0]
|
|
|
|
self.py = modelclass(self, appdata)
|
|
|
|
self.progress = cocoa.ThreadedJobPerformer()
|
|
|
|
|
2011-09-21 19:24:26 +00:00
|
|
|
def bindCocoa_(self, cocoa):
|
|
|
|
self.cocoa = cocoa
|
|
|
|
|
2011-11-27 17:47:00 +00:00
|
|
|
resultTable = subproxy('resultTable', 'result_table', PyResultTable)
|
|
|
|
|
2011-09-20 22:40:27 +00:00
|
|
|
#---Directories
|
|
|
|
def addDirectory_(self, directory):
|
|
|
|
return self.py.add_directory(directory)
|
|
|
|
|
|
|
|
def removeDirectory_(self, index):
|
|
|
|
self.py.remove_directory(index)
|
|
|
|
|
|
|
|
#---Results
|
|
|
|
def clearIgnoreList(self):
|
|
|
|
self.py.scanner.ignore_list.Clear()
|
|
|
|
|
|
|
|
def doScan(self):
|
2011-09-22 14:35:17 +00:00
|
|
|
self.py.start_scanning()
|
2011-09-20 22:40:27 +00:00
|
|
|
|
|
|
|
def exportToXHTMLwithColumns_(self, column_ids):
|
|
|
|
return self.py.export_to_xhtml(column_ids)
|
|
|
|
|
|
|
|
def loadSession(self):
|
|
|
|
self.py.load()
|
|
|
|
|
|
|
|
def loadResultsFrom_(self, filename):
|
|
|
|
self.py.load_from(filename)
|
|
|
|
|
|
|
|
def markAll(self):
|
|
|
|
self.py.mark_all()
|
|
|
|
|
|
|
|
def markNone(self):
|
|
|
|
self.py.mark_none()
|
|
|
|
|
|
|
|
def markInvert(self):
|
|
|
|
self.py.mark_invert()
|
|
|
|
|
|
|
|
def purgeIgnoreList(self):
|
|
|
|
self.py.purge_ignore_list()
|
|
|
|
|
|
|
|
def toggleSelectedMark(self):
|
|
|
|
self.py.toggle_selected_mark_state()
|
|
|
|
|
|
|
|
def saveSession(self):
|
|
|
|
self.py.save()
|
|
|
|
|
|
|
|
def saveResultsAs_(self, filename):
|
|
|
|
self.py.save_as(filename)
|
|
|
|
|
|
|
|
#---Actions
|
|
|
|
def addSelectedToIgnoreList(self):
|
|
|
|
self.py.add_selected_to_ignore_list()
|
|
|
|
|
|
|
|
def deleteMarked(self):
|
|
|
|
self.py.delete_marked()
|
|
|
|
|
|
|
|
def hardlinkMarked(self):
|
|
|
|
self.py.delete_marked(replace_with_hardlinks=True)
|
|
|
|
|
|
|
|
def applyFilter_(self, filter):
|
|
|
|
self.py.apply_filter(filter)
|
|
|
|
|
|
|
|
def makeSelectedReference(self):
|
|
|
|
self.py.make_selected_reference()
|
|
|
|
|
|
|
|
def copyOrMove_markedTo_recreatePath_(self, copy, destination, recreate_path):
|
|
|
|
self.py.copy_or_move_marked(copy, destination, recreate_path)
|
|
|
|
|
|
|
|
def openSelected(self):
|
|
|
|
self.py.open_selected()
|
|
|
|
|
|
|
|
def removeMarked(self):
|
|
|
|
self.py.remove_marked()
|
|
|
|
|
|
|
|
def renameSelected_(self,newname):
|
|
|
|
return self.py.rename_selected(newname)
|
|
|
|
|
|
|
|
def revealSelected(self):
|
|
|
|
self.py.reveal_selected()
|
|
|
|
|
|
|
|
def invokeCommand_(self, cmd):
|
|
|
|
self.py.invoke_command(cmd)
|
|
|
|
|
|
|
|
#---Information
|
|
|
|
def getIgnoreListCount(self):
|
|
|
|
return len(self.py.scanner.ignore_list)
|
|
|
|
|
|
|
|
def getMarkCount(self):
|
|
|
|
return self.py.results.mark_count
|
|
|
|
|
|
|
|
@signature('i@:')
|
|
|
|
def scanWasProblematic(self):
|
|
|
|
return bool(self.py.results.problems)
|
|
|
|
|
|
|
|
@signature('i@:')
|
|
|
|
def resultsAreModified(self):
|
|
|
|
return self.py.results.is_modified
|
|
|
|
|
|
|
|
def deltaColumns(self):
|
2011-09-21 14:26:58 +00:00
|
|
|
return list(self.py.DELTA_COLUMNS)
|
2011-09-20 22:40:27 +00:00
|
|
|
|
|
|
|
#---Properties
|
|
|
|
@signature('v@:c')
|
|
|
|
def setMixFileKind_(self, mix_file_kind):
|
|
|
|
self.py.scanner.mix_file_kind = mix_file_kind
|
|
|
|
|
|
|
|
@signature('v@:c')
|
|
|
|
def setEscapeFilterRegexp_(self, escape_filter_regexp):
|
|
|
|
self.py.options['escape_filter_regexp'] = escape_filter_regexp
|
|
|
|
|
|
|
|
@signature('v@:c')
|
|
|
|
def setRemoveEmptyFolders_(self, remove_empty_folders):
|
|
|
|
self.py.options['clean_empty_dirs'] = remove_empty_folders
|
|
|
|
|
|
|
|
@signature('v@:c')
|
|
|
|
def setIgnoreHardlinkMatches_(self, ignore_hardlink_matches):
|
|
|
|
self.py.options['ignore_hardlink_matches'] = ignore_hardlink_matches
|
|
|
|
|
|
|
|
#---Worker
|
|
|
|
def getJobProgress(self):
|
|
|
|
try:
|
|
|
|
return self.progress.last_progress
|
|
|
|
except AttributeError:
|
|
|
|
# I have *no idea* why this can possible happen (last_progress is always set by
|
|
|
|
# create_job() *before* any threaded job notification, which shows the progress panel,
|
|
|
|
# is sent), but it happens anyway, so there we go. ref: #106
|
|
|
|
return -1
|
|
|
|
|
|
|
|
def getJobDesc(self):
|
|
|
|
try:
|
|
|
|
return self.progress.last_desc
|
|
|
|
except AttributeError:
|
|
|
|
# see getJobProgress
|
|
|
|
return ''
|
|
|
|
|
|
|
|
def cancelJob(self):
|
|
|
|
self.progress.job_cancelled = True
|
|
|
|
|
|
|
|
def jobCompleted_(self, jobid):
|
|
|
|
self.py._job_completed(jobid)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-09-20 22:40:27 +00:00
|
|
|
#--- model --> view
|
|
|
|
def open_path(self, path):
|
2010-08-11 14:39:06 +00:00
|
|
|
NSWorkspace.sharedWorkspace().openFile_(str(path))
|
2010-02-06 11:36:43 +00:00
|
|
|
|
2011-09-20 22:40:27 +00:00
|
|
|
def reveal_path(self, path):
|
2010-08-11 14:39:06 +00:00
|
|
|
NSWorkspace.sharedWorkspace().selectFile_inFileViewerRootedAtPath_(str(path), '')
|
2010-02-06 14:31:35 +00:00
|
|
|
|
2011-09-20 22:40:27 +00:00
|
|
|
def start_job(self, jobid, func, args=()):
|
2009-06-01 09:55:11 +00:00
|
|
|
try:
|
2011-09-20 22:40:27 +00:00
|
|
|
j = self.progress.create_job()
|
2010-09-25 13:37:18 +00:00
|
|
|
args = tuple([j] + list(args))
|
2011-09-20 22:40:27 +00:00
|
|
|
self.progress.run_threaded(func, args=args)
|
2009-06-01 09:55:11 +00:00
|
|
|
except job.JobInProgressError:
|
|
|
|
NSNotificationCenter.defaultCenter().postNotificationName_object_('JobInProgress', self)
|
|
|
|
else:
|
|
|
|
ud = {'desc': JOBID2TITLE[jobid], 'jobid':jobid}
|
|
|
|
NSNotificationCenter.defaultCenter().postNotificationName_object_userInfo_('JobStarted', self, ud)
|
|
|
|
|
2011-09-20 19:06:29 +00:00
|
|
|
def show_extra_fairware_reminder(self):
|
2011-09-22 14:35:17 +00:00
|
|
|
self.cocoa.showExtraFairwareReminder()
|
|
|
|
|
|
|
|
def show_message(self, msg):
|
|
|
|
self.cocoa.showMessage_(msg)
|
|
|
|
|