2009-08-05 08:59:46 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2006/11/11
|
2010-01-01 20:11:34 +00:00
|
|
|
# Copyright 2010 Hardcoded Software (http://www.hardcoded.net)
|
2009-08-05 08:59:46 +00:00
|
|
|
#
|
2010-09-30 10:17:41 +00:00
|
|
|
# This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
2009-08-05 08:59:46 +00:00
|
|
|
# which should be included with this package. The terms are also available at
|
2010-09-30 10:17:41 +00:00
|
|
|
# http://www.hardcoded.net/licenses/bsd_license
|
2009-08-05 08:59:46 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
import logging
|
|
|
|
import os.path as op
|
|
|
|
|
2010-11-20 11:42:15 +00:00
|
|
|
from jobprogress import job
|
|
|
|
from hscommon import cocoa
|
2010-07-13 06:08:18 +00:00
|
|
|
from hscommon.cocoa import install_exception_hook
|
|
|
|
from hscommon.cocoa.objcmin import (NSNotificationCenter, NSUserDefaults,
|
2010-02-04 16:12:58 +00:00
|
|
|
NSSearchPathForDirectoriesInDomains, NSApplicationSupportDirectory, NSUserDomainMask,
|
2010-04-07 07:11:36 +00:00
|
|
|
NSWorkspace)
|
2011-01-18 16:33:33 +00:00
|
|
|
from hscommon.trans import tr
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2010-04-07 07:11:36 +00:00
|
|
|
from . import app
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
JOBID2TITLE = {
|
2011-01-18 16:33:33 +00:00
|
|
|
app.JOB_SCAN: tr("Scanning for duplicates"),
|
|
|
|
app.JOB_LOAD: tr("Loading"),
|
|
|
|
app.JOB_MOVE: tr("Moving"),
|
|
|
|
app.JOB_COPY: tr("Copying"),
|
|
|
|
app.JOB_DELETE: tr("Sending to Trash"),
|
2009-06-01 09:55:11 +00:00
|
|
|
}
|
|
|
|
|
2010-02-05 20:09:04 +00:00
|
|
|
class DupeGuru(app.DupeGuru):
|
2010-09-29 14:49:50 +00:00
|
|
|
def __init__(self, data_module, appdata_subdir):
|
2009-06-01 09:55:11 +00:00
|
|
|
LOGGING_LEVEL = logging.DEBUG if NSUserDefaults.standardUserDefaults().boolForKey_('debug') else logging.WARNING
|
|
|
|
logging.basicConfig(level=LOGGING_LEVEL, format='%(levelname)s %(message)s')
|
|
|
|
logging.debug('started in debug mode')
|
|
|
|
install_exception_hook()
|
2009-09-29 14:07:50 +00:00
|
|
|
appsupport = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, True)[0]
|
|
|
|
appdata = op.join(appsupport, appdata_subdir)
|
2010-09-29 14:49:50 +00:00
|
|
|
app.DupeGuru.__init__(self, data_module, appdata)
|
2009-06-01 09:55:11 +00:00
|
|
|
self.progress = cocoa.ThreadedJobPerformer()
|
|
|
|
|
|
|
|
#--- Override
|
2010-02-06 11:36:43 +00:00
|
|
|
@staticmethod
|
|
|
|
def _open_path(path):
|
2010-08-11 14:39:06 +00:00
|
|
|
NSWorkspace.sharedWorkspace().openFile_(str(path))
|
2010-02-06 11:36:43 +00:00
|
|
|
|
2010-02-06 14:31:35 +00:00
|
|
|
@staticmethod
|
|
|
|
def _reveal_path(path):
|
2010-08-11 14:39:06 +00:00
|
|
|
NSWorkspace.sharedWorkspace().selectFile_inFileViewerRootedAtPath_(str(path), '')
|
2010-02-06 14:31:35 +00:00
|
|
|
|
2010-09-25 13:37:18 +00:00
|
|
|
def _start_job(self, jobid, func, *args):
|
2009-06-01 09:55:11 +00:00
|
|
|
try:
|
|
|
|
j = self.progress.create_job()
|
2010-09-25 13:37:18 +00:00
|
|
|
args = tuple([j] + list(args))
|
|
|
|
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)
|
|
|
|
|
|
|
|
#---Public
|
|
|
|
def start_scanning(self):
|
2010-02-05 19:32:57 +00:00
|
|
|
self._select_dupes([])
|
2009-06-01 09:55:11 +00:00
|
|
|
try:
|
|
|
|
app.DupeGuru.start_scanning(self)
|
|
|
|
return 0
|
|
|
|
except app.NoScannableFileError:
|
|
|
|
return 3
|
|
|
|
|