1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
3
* Copyright 2012, Leo Franchi <lfranchi@kde.org
5
* Tomahawk is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* Tomahawk is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
19
#include "mac/FileHelpers.h"
21
#import <Cocoa/Cocoa.h>
23
#include "TomahawkUtils.h"
24
#include "TomahawkUtils_Mac.h"
27
#include <QTemporaryFile>
29
@implementation MoveDelegate
32
-(void) setReceiver:(QObject*) object
37
-(void) setMoveTo:(QString) p
44
// HACK since I can't figure out how to get QuaZip to maintain executable permissions after unzip (nor find the info)
45
// we set the binary to executable here
47
NSLog(@"Move succeeded!, handling result");
49
NSFileManager *manager = [[[NSFileManager alloc] init] autorelease];
51
NSDictionary* attrs = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:0755], NSFilePosixPermissions, nil];
53
NSString* target = [[NSString alloc] initWithBytes:path.toUtf8() length:path.length() encoding: NSUTF8StringEncoding];
54
NSLog(@"Changing permissions to executable for: %@", target);
55
BOOL success = [manager setAttributes:attrs ofItemAtPath:target error:&error];
57
NSLog( @"Failed to do chmod +x of moved resolver! %@", [[error userInfo] objectForKey: NSLocalizedDescriptionKey] );
61
QMetaObject::invokeMethod(receiver, "installSucceeded", Qt::DirectConnection, Q_ARG(QString, path));
67
- (void)moveFailedWithError:(NSError *)error
69
NSLog(@"Move failed, handling result");
71
QMetaObject::invokeMethod(receiver, "installFailed", Qt::DirectConnection);
75
namespace TomahawkUtils
80
[NSApp activateIgnoringOtherApps:YES];
84
copyWithAuthentication( const QString& srcFile, const QDir dest, QObject* receiver )
87
On OS X, we have to do the following:
88
1) Authenticate to be able to have write access to the /Applications folder
90
5) Call result slots on receiver object
93
MoveDelegate* del = [[MoveDelegate alloc] init];
94
[del setReceiver: receiver];
96
// Get the filename + path to save for later
97
QFileInfo srcInfo( srcFile );
98
const QString resultingPath = dest.absoluteFilePath( srcInfo.fileName() );
99
[del setMoveTo: resultingPath];
101
const QFileInfo info( srcFile );
102
const QString destPath = dest.absoluteFilePath( info.fileName() );
104
NSString* src = [[NSString alloc] initWithBytes: srcFile.toUtf8() length: srcFile.length() encoding: NSUTF8StringEncoding];
105
NSString* destStr = [[NSString alloc] initWithBytes: destPath.toUtf8() length: destPath.length() encoding: NSUTF8StringEncoding];
106
[FileHelpers moveFile:src to:destStr withDelegate:del];