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
|
|
|
#
|
|
|
|
# This software is licensed under the "HS" License as described in the "LICENSE" file,
|
|
|
|
# which should be included with this package. The terms are also available at
|
|
|
|
# http://www.hardcoded.net/licenses/hs_license
|
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
import logging
|
|
|
|
import os.path as op
|
|
|
|
|
2010-07-13 06:08:18 +00:00
|
|
|
from hscommon import cocoa, job
|
|
|
|
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)
|
2010-07-13 06:08:18 +00:00
|
|
|
from hscommon.reg import RegistrationRequired
|
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 = {
|
|
|
|
app.JOB_SCAN: "Scanning for duplicates",
|
|
|
|
app.JOB_LOAD: "Loading",
|
|
|
|
app.JOB_MOVE: "Moving",
|
|
|
|
app.JOB_COPY: "Copying",
|
|
|
|
app.JOB_DELETE: "Sending to Trash",
|
|
|
|
}
|
|
|
|
|
|
|
|
def demo_method(method):
|
|
|
|
def wrapper(self, *args, **kwargs):
|
|
|
|
try:
|
|
|
|
return method(self, *args, **kwargs)
|
|
|
|
except RegistrationRequired:
|
|
|
|
NSNotificationCenter.defaultCenter().postNotificationName_object_('RegistrationRequired', self)
|
|
|
|
|
|
|
|
return wrapper
|
|
|
|
|
2010-02-05 20:09:04 +00:00
|
|
|
class DupeGuru(app.DupeGuru):
|
2009-06-01 09:55:11 +00:00
|
|
|
def __init__(self, data_module, appdata_subdir, appid):
|
|
|
|
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)
|
2009-06-01 09:55:11 +00:00
|
|
|
app.DupeGuru.__init__(self, data_module, appdata, appid)
|
|
|
|
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
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
def _start_job(self, jobid, func):
|
|
|
|
try:
|
|
|
|
j = self.progress.create_job()
|
|
|
|
self.progress.run_threaded(func, args=(j, ))
|
|
|
|
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
|
|
|
|
copy_or_move_marked = demo_method(app.DupeGuru.copy_or_move_marked)
|
|
|
|
delete_marked = demo_method(app.DupeGuru.delete_marked)
|
|
|
|
|
|
|
|
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
|
|
|
|
|