From 047b4aff0c5fca59e7f9e91c864edb105d4067f3 Mon Sep 17 00:00:00 2001 From: hsoft Date: Mon, 31 Aug 2009 12:04:43 +0000 Subject: [PATCH] [#52] Added file recycling support on OS X. --HG-- extra : convert_revision : svn%3Ac306627e-7827-47d3-bdf0-9a457c9553a1/trunk%40102 --- base/qt/app.py | 12 ++ base/qt/gen.py | 9 +- base/qt/osx/SendToTrashProject/SendToTrash.m | 23 +++ .../SendToTrash.xcodeproj/project.pbxproj | 183 ++++++++++++++++++ base/qt/osx/__init__.py | 19 ++ se/qt/app_win.py => base/qt/win/__init__.py | 12 +- se/qt/start.py | 5 +- 7 files changed, 250 insertions(+), 13 deletions(-) create mode 100644 base/qt/osx/SendToTrashProject/SendToTrash.m create mode 100644 base/qt/osx/SendToTrashProject/SendToTrash.xcodeproj/project.pbxproj create mode 100644 base/qt/osx/__init__.py rename se/qt/app_win.py => base/qt/win/__init__.py (64%) diff --git a/base/qt/app.py b/base/qt/app.py index f8e9d180..8bb7c24c 100644 --- a/base/qt/app.py +++ b/base/qt/app.py @@ -9,6 +9,7 @@ import logging import os.path as op +import sys import traceback from PyQt4.QtCore import Qt, QTimer, QObject, QCoreApplication, QUrl, SIGNAL @@ -20,6 +21,13 @@ from hsutil.reg import RegistrationRequired from dupeguru.app import (DupeGuru as DupeGuruBase, JOB_SCAN, JOB_LOAD, JOB_MOVE, JOB_COPY, JOB_DELETE) + +if sys.platform == 'win32': + from .win import recycle_file +elif sys.platform == 'darwin': + from .osx import recycle_file +else: + logging.warning("Unsupported Platform!!!") from main_window import MainWindow from directories_dialog import DirectoriesDialog @@ -146,6 +154,10 @@ class DupeGuru(DupeGuruBase, QObject): raise NotImplementedError() #--- Override + @staticmethod + def _recycle_dupe(dupe): + recycle_file(dupe.path) + def _start_job(self, jobid, func): title = JOBID2TITLE[jobid] try: diff --git a/base/qt/gen.py b/base/qt/gen.py index 2843e82e..754209f1 100644 --- a/base/qt/gen.py +++ b/base/qt/gen.py @@ -9,6 +9,7 @@ # http://www.hardcoded.net/licenses/hs_license import os +import sys def print_and_do(cmd): print cmd @@ -20,4 +21,10 @@ print_and_do("pyuic4 about_box.ui > about_box_ui.py") print_and_do("pyuic4 reg_submit_dialog.ui > reg_submit_dialog_ui.py") print_and_do("pyuic4 reg_demo_dialog.ui > reg_demo_dialog_ui.py") print_and_do("pyuic4 error_report_dialog.ui > error_report_dialog_ui.py") -print_and_do("pyrcc4 dg.qrc > dg_rc.py") \ No newline at end of file +print_and_do("pyrcc4 dg.qrc > dg_rc.py") + +if sys.platform == 'darwin': + os.chdir('osx/SendToTrashProject') + print_and_do('xcodebuild') + print_and_do('cp build/Release/SendToTrash ../') + os.chdir('../..') \ No newline at end of file diff --git a/base/qt/osx/SendToTrashProject/SendToTrash.m b/base/qt/osx/SendToTrashProject/SendToTrash.m new file mode 100644 index 00000000..26401bcf --- /dev/null +++ b/base/qt/osx/SendToTrashProject/SendToTrash.m @@ -0,0 +1,23 @@ +#import + +int main (int argc, const char * argv[]) { + if(argc == 1){ + NSLog(@"A file path to send to trash is needed"); + return 1; + } + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + NSString *filepath = [NSString stringWithCString:argv[1] encoding:NSUTF8StringEncoding]; + NSLog(@"%@",filepath); + NSMutableArray *split = [NSMutableArray arrayWithArray:[filepath componentsSeparatedByString:@"/"]]; + NSString *filename = [split lastObject]; + [split removeLastObject]; + NSString *dirpath = [split componentsJoinedByString:@"/"]; + int result; + [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation + source:dirpath + destination:@"" + files:[NSArray arrayWithObject:filename] + tag:&result]; + [pool drain]; + return result; +} diff --git a/base/qt/osx/SendToTrashProject/SendToTrash.xcodeproj/project.pbxproj b/base/qt/osx/SendToTrashProject/SendToTrash.xcodeproj/project.pbxproj new file mode 100644 index 00000000..43f432d4 --- /dev/null +++ b/base/qt/osx/SendToTrashProject/SendToTrash.xcodeproj/project.pbxproj @@ -0,0 +1,183 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 45; + objects = { + +/* Begin PBXBuildFile section */ + 8DD76F9A0486AA7600D96B5E /* SendToTrash.m in Sources */ = {isa = PBXBuildFile; fileRef = 08FB7796FE84155DC02AAC07 /* SendToTrash.m */; settings = {ATTRIBUTES = (); }; }; + 8DD76F9C0486AA7600D96B5E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 08FB779EFE84155DC02AAC07 /* Foundation.framework */; }; + CEFA8C60104BD73200E2A946 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CEFA8C5F104BD73200E2A946 /* Cocoa.framework */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 8DD76F9E0486AA7600D96B5E /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 8; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 08FB7796FE84155DC02AAC07 /* SendToTrash.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SendToTrash.m; sourceTree = ""; }; + 08FB779EFE84155DC02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = ""; }; + 8DD76FA10486AA7600D96B5E /* SendToTrash */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = SendToTrash; sourceTree = BUILT_PRODUCTS_DIR; }; + CEFA8C5F104BD73200E2A946 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 8DD76F9B0486AA7600D96B5E /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 8DD76F9C0486AA7600D96B5E /* Foundation.framework in Frameworks */, + CEFA8C60104BD73200E2A946 /* Cocoa.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 08FB7794FE84155DC02AAC07 /* SendToTrash */ = { + isa = PBXGroup; + children = ( + 08FB7795FE84155DC02AAC07 /* Source */, + 08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */, + 1AB674ADFE9D54B511CA2CBB /* Products */, + ); + name = SendToTrash; + sourceTree = ""; + }; + 08FB7795FE84155DC02AAC07 /* Source */ = { + isa = PBXGroup; + children = ( + 08FB7796FE84155DC02AAC07 /* SendToTrash.m */, + ); + name = Source; + sourceTree = ""; + }; + 08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */ = { + isa = PBXGroup; + children = ( + 08FB779EFE84155DC02AAC07 /* Foundation.framework */, + CEFA8C5F104BD73200E2A946 /* Cocoa.framework */, + ); + name = "External Frameworks and Libraries"; + sourceTree = ""; + }; + 1AB674ADFE9D54B511CA2CBB /* Products */ = { + isa = PBXGroup; + children = ( + 8DD76FA10486AA7600D96B5E /* SendToTrash */, + ); + name = Products; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 8DD76F960486AA7600D96B5E /* SendToTrash */ = { + isa = PBXNativeTarget; + buildConfigurationList = 1DEB927408733DD40010E9CD /* Build configuration list for PBXNativeTarget "SendToTrash" */; + buildPhases = ( + 8DD76F990486AA7600D96B5E /* Sources */, + 8DD76F9B0486AA7600D96B5E /* Frameworks */, + 8DD76F9E0486AA7600D96B5E /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = SendToTrash; + productInstallPath = "$(HOME)/bin"; + productName = SendToTrash; + productReference = 8DD76FA10486AA7600D96B5E /* SendToTrash */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 08FB7793FE84155DC02AAC07 /* Project object */ = { + isa = PBXProject; + buildConfigurationList = 1DEB927808733DD40010E9CD /* Build configuration list for PBXProject "SendToTrash" */; + compatibilityVersion = "Xcode 3.1"; + hasScannedForEncodings = 1; + mainGroup = 08FB7794FE84155DC02AAC07 /* SendToTrash */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 8DD76F960486AA7600D96B5E /* SendToTrash */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 8DD76F990486AA7600D96B5E /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 8DD76F9A0486AA7600D96B5E /* SendToTrash.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 1DEB927608733DD40010E9CD /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_MODEL_TUNING = G5; + GCC_PRECOMPILE_PREFIX_HEADER = NO; + GCC_PREFIX_HEADER = ""; + INSTALL_PATH = /usr/local/bin; + PRODUCT_NAME = SendToTrash; + }; + name = Release; + }; + 1DEB927A08733DD40010E9CD /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_ENABLE_SYMBOL_SEPARATION = NO; + GCC_THREADSAFE_STATICS = NO; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.4; + PREBINDING = NO; + PRECOMPS_INCLUDE_HEADERS_FROM_BUILT_PRODUCTS_DIR = NO; + SDKROOT = macosx10.5; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 1DEB927408733DD40010E9CD /* Build configuration list for PBXNativeTarget "SendToTrash" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1DEB927608733DD40010E9CD /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 1DEB927808733DD40010E9CD /* Build configuration list for PBXProject "SendToTrash" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1DEB927A08733DD40010E9CD /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 08FB7793FE84155DC02AAC07 /* Project object */; +} diff --git a/base/qt/osx/__init__.py b/base/qt/osx/__init__.py new file mode 100644 index 00000000..768bcadc --- /dev/null +++ b/base/qt/osx/__init__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Created By: Virgil Dupras +# Created On: 2009-08-31 +# $Id$ +# Copyright 2009 Hardcoded Software (http://www.hardcoded.net) +# +# 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 + +import os +import os.path as op + +CMD = unicode(op.join(op.dirname(__file__), 'SendToTrash')) +print CMD + +def recycle_file(path): + print u'%s "%s"' % (CMD, unicode(path)) + os.system(u'%s "%s"' % (CMD, unicode(path))) diff --git a/se/qt/app_win.py b/base/qt/win/__init__.py similarity index 64% rename from se/qt/app_win.py rename to base/qt/win/__init__.py index 777d012c..960cbfb7 100644 --- a/se/qt/app_win.py +++ b/base/qt/win/__init__.py @@ -1,5 +1,6 @@ +# -*- coding: utf-8 -*- # Created By: Virgil Dupras -# Created On: 2009-05-24 +# Created On: 2009-08-31 # $Id$ # Copyright 2009 Hardcoded Software (http://www.hardcoded.net) # @@ -9,10 +10,5 @@ import winshell -import app - -class DupeGuru(app.DupeGuru): - @staticmethod - def _recycle_dupe(dupe): - winshell.delete_file(unicode(dupe.path), no_confirm=True) - +def recycle_file(path): + winshell.delete_file(unicode(path), no_confirm=True) diff --git a/se/qt/start.py b/se/qt/start.py index 7ff9828a..8f97430f 100644 --- a/se/qt/start.py +++ b/se/qt/start.py @@ -12,10 +12,7 @@ from PyQt4.QtGui import QApplication, QIcon, QPixmap import base.dg_rc -if sys.platform == 'win32': - from app_win import DupeGuru -else: - from app import DupeGuru +from app import DupeGuru if __name__ == "__main__": app = QApplication(sys.argv)