1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2025-03-10 05:34:36 +00:00

[#52] Added file recycling support on OS X.

--HG--
extra : convert_revision : svn%3Ac306627e-7827-47d3-bdf0-9a457c9553a1/trunk%40102
This commit is contained in:
hsoft 2009-08-31 12:04:43 +00:00
parent 4cebd142ed
commit 047b4aff0c
7 changed files with 250 additions and 13 deletions

View File

@ -9,6 +9,7 @@
import logging import logging
import os.path as op import os.path as op
import sys
import traceback import traceback
from PyQt4.QtCore import Qt, QTimer, QObject, QCoreApplication, QUrl, SIGNAL from PyQt4.QtCore import Qt, QTimer, QObject, QCoreApplication, QUrl, SIGNAL
@ -21,6 +22,13 @@ from hsutil.reg import RegistrationRequired
from dupeguru.app import (DupeGuru as DupeGuruBase, JOB_SCAN, JOB_LOAD, JOB_MOVE, JOB_COPY, from dupeguru.app import (DupeGuru as DupeGuruBase, JOB_SCAN, JOB_LOAD, JOB_MOVE, JOB_COPY,
JOB_DELETE) 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 main_window import MainWindow
from directories_dialog import DirectoriesDialog from directories_dialog import DirectoriesDialog
from about_box import AboutBox from about_box import AboutBox
@ -146,6 +154,10 @@ class DupeGuru(DupeGuruBase, QObject):
raise NotImplementedError() raise NotImplementedError()
#--- Override #--- Override
@staticmethod
def _recycle_dupe(dupe):
recycle_file(dupe.path)
def _start_job(self, jobid, func): def _start_job(self, jobid, func):
title = JOBID2TITLE[jobid] title = JOBID2TITLE[jobid]
try: try:

View File

@ -9,6 +9,7 @@
# http://www.hardcoded.net/licenses/hs_license # http://www.hardcoded.net/licenses/hs_license
import os import os
import sys
def print_and_do(cmd): def print_and_do(cmd):
print cmd print cmd
@ -21,3 +22,9 @@ 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 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("pyuic4 error_report_dialog.ui > error_report_dialog_ui.py")
print_and_do("pyrcc4 dg.qrc > dg_rc.py") 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('../..')

View File

@ -0,0 +1,23 @@
#import <Cocoa/Cocoa.h>
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;
}

View File

@ -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 = "<group>"; };
08FB779EFE84155DC02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
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 = "<absolute>"; };
/* 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 = "<group>";
};
08FB7795FE84155DC02AAC07 /* Source */ = {
isa = PBXGroup;
children = (
08FB7796FE84155DC02AAC07 /* SendToTrash.m */,
);
name = Source;
sourceTree = "<group>";
};
08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */ = {
isa = PBXGroup;
children = (
08FB779EFE84155DC02AAC07 /* Foundation.framework */,
CEFA8C5F104BD73200E2A946 /* Cocoa.framework */,
);
name = "External Frameworks and Libraries";
sourceTree = "<group>";
};
1AB674ADFE9D54B511CA2CBB /* Products */ = {
isa = PBXGroup;
children = (
8DD76FA10486AA7600D96B5E /* SendToTrash */,
);
name = Products;
sourceTree = "<group>";
};
/* 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 */;
}

19
base/qt/osx/__init__.py Normal file
View File

@ -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)))

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
# Created By: Virgil Dupras # Created By: Virgil Dupras
# Created On: 2009-05-24 # Created On: 2009-08-31
# $Id$ # $Id$
# Copyright 2009 Hardcoded Software (http://www.hardcoded.net) # Copyright 2009 Hardcoded Software (http://www.hardcoded.net)
# #
@ -9,10 +10,5 @@
import winshell import winshell
import app def recycle_file(path):
winshell.delete_file(unicode(path), no_confirm=True)
class DupeGuru(app.DupeGuru):
@staticmethod
def _recycle_dupe(dupe):
winshell.delete_file(unicode(dupe.path), no_confirm=True)

View File

@ -12,9 +12,6 @@ from PyQt4.QtGui import QApplication, QIcon, QPixmap
import base.dg_rc 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__": if __name__ == "__main__":