~ubuntu-branches/ubuntu/trusty/tomahawk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/libtomahawk/utils/TomahawkUtils_Mac.mm

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-03-07 21:50:13 UTC
  • Revision ID: package-import@ubuntu.com-20130307215013-6gdjkdds7i9uenvs
Tags: upstream-0.6.0+dfsg
ImportĀ upstreamĀ versionĀ 0.6.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
 
2
 *
 
3
 *   Copyright 2012, Leo Franchi <lfranchi@kde.org
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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/>.
 
17
 */
 
18
 
 
19
#include "mac/FileHelpers.h"
 
20
 
 
21
#import <Cocoa/Cocoa.h>
 
22
 
 
23
#include "TomahawkUtils.h"
 
24
#include "TomahawkUtils_Mac.h"
 
25
 
 
26
#include <QDir>
 
27
#include <QTemporaryFile>
 
28
 
 
29
@implementation MoveDelegate
 
30
 
 
31
 
 
32
-(void) setReceiver:(QObject*) object
 
33
{
 
34
    receiver = object;
 
35
}
 
36
 
 
37
-(void) setMoveTo:(QString) p
 
38
{
 
39
    path = p;
 
40
}
 
41
 
 
42
- (void)moveFinished
 
43
{
 
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
 
46
 
 
47
    NSLog(@"Move succeeded!, handling result");
 
48
 
 
49
    NSFileManager *manager = [[[NSFileManager alloc] init] autorelease];
 
50
    NSError* error;
 
51
    NSDictionary* attrs = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:0755], NSFilePosixPermissions, nil];
 
52
 
 
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];
 
56
    if (!success) {
 
57
        NSLog( @"Failed to do chmod +x of moved resolver! %@", [[error userInfo] objectForKey: NSLocalizedDescriptionKey] );
 
58
    }
 
59
 
 
60
    if ( receiver )
 
61
        QMetaObject::invokeMethod(receiver, "installSucceeded", Qt::DirectConnection, Q_ARG(QString, path));
 
62
 
 
63
    [target release];
 
64
 
 
65
}
 
66
 
 
67
- (void)moveFailedWithError:(NSError *)error
 
68
{
 
69
    NSLog(@"Move failed, handling result");
 
70
    if ( receiver )
 
71
        QMetaObject::invokeMethod(receiver, "installFailed", Qt::DirectConnection);
 
72
}
 
73
@end
 
74
 
 
75
namespace TomahawkUtils
 
76
{
 
77
 
 
78
void
 
79
bringToFront() {
 
80
    [NSApp activateIgnoringOtherApps:YES];
 
81
}
 
82
 
 
83
void
 
84
copyWithAuthentication( const QString& srcFile, const QDir dest, QObject* receiver )
 
85
{
 
86
  /**
 
87
    On OS X, we have to do the following:
 
88
    1) Authenticate to be able to have write access to the /Applications folder
 
89
    2) Copy file to dest
 
90
    5) Call result slots on receiver object
 
91
  */
 
92
 
 
93
    MoveDelegate* del = [[MoveDelegate alloc] init];
 
94
    [del setReceiver: receiver];
 
95
 
 
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];
 
100
 
 
101
    const QFileInfo info( srcFile );
 
102
    const QString destPath = dest.absoluteFilePath( info.fileName() );
 
103
 
 
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];
 
107
}
 
108
 
 
109
 
 
110
}