PDA

View Full Version : Nssavepanel question




DavidBlack
May 21, 2013, 04:35 PM
Ok I am making a youtube downloader it works fine and all but I want to implement a NSSAVEPanel. My youtube downloader currently saves the file to the desktop and uses the NSDateFormatter to save the files as the name of the current date. But I want to use a save panel and I am getting trouble.

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd-hh-mma"];
NSString *dateString = [dateFormat stringFromDate: [NSDate date]];
[dateFormat release];

NSString *randomFilename = [NSString stringWithFormat: @"download_%@", dateString];


Can anyone help me please?



chown33
May 21, 2013, 05:12 PM
Rules of Thumb:
1. Be specific.
2. Post your code.
3. Describe what you expected to happen.
4. Describe what actually happened.

You've done #2 somewhat. In particular, you haven't shown what method or class the posted code resides in. If it's in the wrong method or class, it won't be executed. If that's the problem, then we need to see where it resides, so we understand when it's supposed to be executed.

You haven't done #1, #3, or #4 at all.

Sonnestah
May 22, 2013, 11:14 AM
Do you understand your code or did you simply copy/paste from somewhere?

DavidBlack
May 22, 2013, 04:39 PM
Do you understand your code or did you simply copy/paste from somewhere?

Yea I understand my code and I wrote it.
1. It takes the current Date format.
2. Then the date is used to name the file. e.g download_2013-05-22-05-36PM.
3. What I want to do is when the user click the download button it will open a save panel then the name that the user chooses I want to put into a string.
Can you help me?

DavidBlack
May 22, 2013, 04:48 PM
Rules of Thumb:
1. Be specific.
2. Post your code.
3. Describe what you expected to happen.
4. Describe what actually happened.

You've done #2 somewhat. In particular, you haven't shown what method or class the posted code resides in. If it's in the wrong method or class, it won't be executed. If that's the problem, then we need to see where it resides, so we understand when it's supposed to be executed.

You haven't done #1, #3, or #4 at all.
1. It takes the current Date format.
2. Then the date is used to name the file. e.g download_2013-05-22-05-36PM.
3. What I want to do is when the user click the download button it will open a save panel then the name that the user chooses I want to put into a string.
Can you help me?

Also it's a IB Action

Sonnestah
May 22, 2013, 06:07 PM
Yea I understand my code and I wrote it.
1. It takes the current Date format.
2. Then the date is used to name the file. e.g download_2013-05-22-05-36PM.
3. What I want to do is when the user click the download button it will open a save panel then the name that the user chooses I want to put into a string.
Can you help me?

mmm wrong

you did not write it, thats a project called utubely you got from github.

it does not take the current date format, the code you pasted formats the current date and then appends the formatted date to the name of the file which is then saved to the desktop

if you understand the code, you are familiar with the basics and with the documentation apple provides as well, I am sure:

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/nssavepanel_Class/Reference/Reference.html

The link above gives everything you need, even sample code.


PS: Please, always credit the developer you took the code from

DavidBlack
May 22, 2013, 06:17 PM
mmm wrong

you did not write it, thats a project called utubely you got from github.

it does not take the current date format, the code you pasted formats the current date and then appends the formatted date to the name of the file which is then saved to the desktop

if you understand the code, you are familiar with the basics and with the documentation apple provides as well, I am sure:

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/nssavepanel_Class/Reference/Reference.html

The link above gives everything you need, even sample code.


PS: Please, always credit the developer you took the code from

Thanks I am kinda of embarrassed for lying.
I am a really basic developer i won't even call myself a dev.

----------

mmm wrong

you did not write it, thats a project called utubely you got from github.

it does not take the current date format, the code you pasted formats the current date and then appends the formatted date to the name of the file which is then saved to the desktop

if you understand the code, you are familiar with the basics and with the documentation apple provides as well, I am sure:

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/nssavepanel_Class/Reference/Reference.html

The link above gives everything you need, even sample code.


PS: Please, always credit the developer you took the code from

Can you guide me a little bit more like how to display a NSSave panel?
Thanks

Sonnestah
May 22, 2013, 06:24 PM
NSSavePanel *savePanel = [NSSavePanel savePanel];
[savePanel setTitle:@"Choose location..."];

NSInteger result = [savePanel runModal];
if (result != NSFileHandlingPanelOKButton)
return;

NSURL *outputURL = [savePanel URL];


Now you have to figure it out

DavidBlack
May 22, 2013, 06:38 PM
NSSavePanel *savePanel = [NSSavePanel savePanel];
[savePanel setTitle:@"Choose location..."];

NSInteger result = [savePanel runModal];
if (result != NSFileHandlingPanelOKButton)
return;

NSString *outputURL = [savePanel URL];


Now you have to figure it out

Thanks but i don't want the output URL but the name that the user typed as a string.

Sonnestah
May 22, 2013, 06:42 PM
you are going to have to experiment with it, as it is virtually the same code

I already gave you the documents and the code

chown33
May 22, 2013, 06:43 PM
Can you guide me a little bit more like how to display a NSSave panel?

That's why sample code exists. So you can see the whole project, build it, run it, and then look at what the code does.

Sonnestah linked to the class reference doc for NSSavePanel. On that page, located near the top, are links to 5 separate sample code projects. You should be able to download, build, run, and then explore the source code for each one.

The class reference doc also has links to Companion Guides at the left. You should read those to understand the high-level workings, and read the discussion of how to use the class.

If you can't read reference docs or sample code to learn how a class works, then you're trying to work beyond your skill level. You should go back to the fundamental classes, read the reference docs and sample code for them, and learn how things work. The ability to read reference docs and sample code is a fundamental and reusable skill. Without it, you won't get far in programming.

DavidBlack
May 22, 2013, 06:56 PM
you are going to have to experiment with it, as it is virtually the same code

I already gave you the documents and the code

This is what I have NSSavePanel *savePanel = [NSSavePanel savePanel];
[savePanel setTitle:@"Choose location..."];

NSInteger result = [savePanel runModal];
if (result != NSFileHandlingPanelOKButton)
return;

NSString *outputURL = [savePanel URL];

NSString *randomFilename = outputURL;

r = [ASIHTTPRequest requestWithURL: self.extractedURL];

NSString *local_full_path = [ [NSString stringWithFormat: @"~/Desktop/%@.mp4", savePanel] stringByExpandingTildeInPath];
NSLog(@"Saving to: %@", local_full_path);
NSLog(@"Saving to the parent folder: %@", [local_full_path stringByDeletingLastPathComponent]);
[r setTimeOutSeconds: 10];


it works but the output is:

Sonnestah
May 22, 2013, 07:00 PM
theres obviously a mistake I made on the code I gave you

if you read the warning I am sure you're going to be able to fix it.

DavidBlack
May 22, 2013, 07:07 PM
theres obviously a mistake I made on the code I gave you

if you read the warning I am sure you're going to be able to fix it.

This is the warning.
Thanks for your help so far I am getting closer to getting it to work right.

Sonnestah
May 22, 2013, 07:10 PM
plus you've got the local_full_path wrong

----------

This is the warning.
Thanks for your help so far I am getting closer to getting it to work right.

the highlighted line is
NSString *outputURL = [savePanel URL];

Read the warning and make the change it says

DavidBlack
May 22, 2013, 07:14 PM
plus you've got the local_full_path wrong

----------



the highlighted line is
NSString *outputURL = [savePanel URL];

Read the warning and make the change it says

Can you help me?
:confused:

DavidBlack
May 22, 2013, 07:20 PM
plus you've got the local_full_path wrong

----------



the highlighted line is
NSString *outputURL = [savePanel URL];

Read the warning and make the change it says

BTW This is the NSLOG MESSAGES

DavidBlack
May 22, 2013, 07:23 PM
theres obviously a mistake I made on the code I gave you

if you read the warning I am sure you're going to be able to fix it.

And btw how to correct the local_full_path.

DavidBlack
May 22, 2013, 07:39 PM
BTW This is the NSLOG MESSAGES

I don't understand what the warning is telling me. :confused:

----------

theres obviously a mistake I made on the code I gave you

if you read the warning I am sure you're going to be able to fix it.

I don't understand what the warning is telling me.