After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 390735 - prompt for save path if none specified when adding a nzb via command-line.
prompt for save path if none specified when adding a nzb via command-line.
Status: RESOLVED FIXED
Product: Pan
Classification: Other
Component: general
pre-1.0 betas
Other All
: Normal normal
: 1.0
Assigned To: Charles Kerr
Pan QA Team
Depends on:
Blocks:
 
 
Reported: 2006-12-29 18:20 UTC by Darren Albers
Modified: 2007-01-22 14:45 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch to add a save dialog when a nzb is passed from the command line (1.75 KB, patch)
2007-01-01 03:37 UTC, Darren Albers
none Details | Review
Attachment to open Save dialog when nzb added via command line (1.65 KB, patch)
2007-01-01 03:42 UTC, Darren Albers
none Details | Review
Add save dialog when nzb is opened from a command line (1.67 KB, patch)
2007-01-01 03:53 UTC, Darren Albers
none Details | Review
Patch to add save dialog when a NZB is added via command line (1.82 KB, patch)
2007-01-01 04:28 UTC, Darren Albers
none Details | Review
Try #5 for save attachment patch (1.70 KB, patch)
2007-01-03 01:18 UTC, Darren Albers
none Details | Review
revision of previous patch. (4.68 KB, patch)
2007-01-04 17:01 UTC, Charles Kerr
none Details | Review
Try #7 (4.71 KB, patch)
2007-01-04 17:51 UTC, Charles Kerr
none Details | Review
Try #8 -- same as #7, but exit if user hits `cancel' in NZB dialog (4.79 KB, patch)
2007-01-14 17:24 UTC, Charles Kerr
committed Details | Review

Description Darren Albers 2006-12-29 18:20:46 UTC
Please describe the problem:
When adding a nzb via command-line it always defaults to saving in $home, I added the following to preferences.xml:
 <string name='default-save-attachments-path' value='/home/darren/News'/>

and it still saved it in $home.   When I import the NZB via the GUI it does seem to default to using the path above (The save dialog opens there) and when I check group preferences it is listed there.

Steps to reproduce:
1. open an nzb via pan --nzb file.nzb
2. Check the task manager and it is being saved to $home



Actual results:
Check the task manager and it is being saved to $home


Expected results:
It would use my default value or ask me where to save the files

Does this happen every time?
Yes

Other information:
Comment 1 Duncan 2006-12-29 22:57:47 UTC
I haven't actually tested this yet, but I suspect this is another case of bug #355047, article download (to cache) becomes save after restart, which was fixed a couple months ago, and that it's not specifically $HOME, but rather $PWD, which is normally $HOME unless someone is starting pan from a shell where they've switched to a different dir.

Or more technically, I think #355047 was a subset bug of this one, only it was reported first and the fix for it, retaining the cache vs. save info, didn't fix the other half, that it was saving to $PWD instead of the default save dir, so that half is showing up again here.  Maybe the work from it will make fixing this one a bit easier.

Alternatively... this could be declared a feature not a bug, as when the *.nzb is fed to pan on the command line, it uses the working dir rather than the configured default dir as the save location.  However, if that is to be the case, then a parallel command line option to change the save location from the default $PWD would be useful as well.  That could be implemented either as an option to have pan change to that working dir before doing anything else, or as a command-line save location, possibly taking precedence over any configured default.
Comment 2 Darren Albers 2006-12-30 01:52:02 UTC
Good catch Duncan!  That was it, so in the meantime I can just use a script to launch Pan to avoid this problem.

I think it is probably a common use case for people to open a nzb in pan from their browser rather than save it and then open it with Pan so I think it might be better from a user perspective to behave the same way when a nzb is imported from a command line as it does when imported from inside the app and ask the user where they want to save the attachments.

While I would like to see this I can understand if it needs to slip to 1.1 due to time constraints, especially since there is an easy workaround.

Comment 3 Darren Albers 2007-01-01 01:47:02 UTC
Just some follow-up to this, Duncan here is the proof that you are 100% correct:
from pan.cc ~line 194

  char * pch = g_get_current_dir ();
  std::string nzb_output_path = pch;
  g_free (pch);


So now let me see if I can hack in some way of opening the standard gtk save dialog box to populate that variable rather than just using the current path.
Comment 4 Darren Albers 2007-01-01 03:37:45 UTC
Created attachment 79130 [details] [review]
Patch to add a save dialog when a nzb is passed from the command line

Ok this is a hack, I took the save dialog from gui.cc and hacked it in so that when pan.cc calls for the save path instead of it returning pwd it opens the save dialog and returns that path.

Rather than add some additional code to import the preferences I had it return the current path as the starting point for the save.  I might take a look at adding that back in once I figure out how  ;-)   

I am sure I am making a ton of mistakes and that Charles will find it easier to just write this himself rather than fix my mistakes but it gave me some experience in how the dialogs work in gtk.  Too bad I will forget it all due to the champagne tonight!
Comment 5 Darren Albers 2007-01-01 03:42:04 UTC
Created attachment 79131 [details] [review]
Attachment to open Save dialog when nzb added via command line

Oops, I had some whitespace that got carried over into the diff.
Comment 6 Darren Albers 2007-01-01 03:53:07 UTC
Created attachment 79132 [details] [review]
Add save dialog when nzb is opened from a command line

I did something stupid, pch isn't needed anymore since I can just use nzb_output_path directly.
Comment 7 Darren Albers 2007-01-01 04:28:06 UTC
Created attachment 79134 [details] [review]
Patch to add save dialog when a NZB is added via command line

*smacks head*  Ok my previous patches caused pan to prompt for a save location when it started rather than just when a nzb was passed via command line.   I changed my patch to only call the save dialog when a nzb was passed to it.

Ok now time to go celebrate the New Year!
Comment 8 Charles Kerr 2007-01-02 17:30:57 UTC
does this patch pop up the save dialog even if --nogui is passed in?
Comment 9 Darren Albers 2007-01-02 18:12:33 UTC
I am not sure, I will test it tonight and find out.  If it does I will fix it.
Comment 10 Darren Albers 2007-01-02 19:08:06 UTC
Yes, it looks like it will pop-up even if --nogui is passed since the check for no gui occurs after the nzb's are loaded..  I am not quite sure how to handle it except to break --no-gui into a new function.  Would that clutter it up or do you have any suggestions?

Comment 11 Charles Kerr 2007-01-02 19:17:07 UTC
Well I'm assuming this patch is for the benefit of URL handlers, since someone
just running Pan from the command line can use -o or --output= to specify
where the files get saved. 

So I guess in the case where Pan is being used as a URL handler, the dialog
makes sense.
Comment 12 Darren Albers 2007-01-02 19:21:56 UTC
Correct that is exactly what I do and why I wrote the patch.  However even if they specify -o the prompt still comes out so I need to fix that.

How about this (I haven't actually tried this but so this isn't a real patch just me playing around in gedit)
     // load the nzb files...
-     std::vector<Task*> tasks;
-     foreach_const (strings_t, nzb_files, it)
-       NZB :: tasks_from_nzb_file (*it,get_save_attachments_path_from_user (), cache, data, data, data,tasks);
-     queue.add_tasks (tasks, Queue::BOTTOM);

     // don't open the full-blown Pan, just act as a nzb client,
     // with a gui or without.
     if (gui) {
+       std::vector<Task*> tasks;
+       foreach_const (strings_t, nzb_files, it)
+          NZB :: tasks_from_nzb_file (*it,get_save_attachments_path_from_user (), cache, data, data, data,tasks);
+       queue.add_tasks (tasks, Queue::BOTTOM);
       TaskPane * pane = new TaskPane (queue, prefs);
       GtkWidget * w (pane->root());
       gtk_widget_show_all (w);
       g_signal_connect (w, "destroy", G_CALLBACK(destroy_cb), 0);
       g_signal_connect (G_OBJECT(w), "delete-event",G_CALLBACK(delete_event_cb), 0);
     } else {
+     std::vector<Task*> tasks;
+     foreach_const (strings_t, nzb_files, it)
+       NZB :: tasks_from_nzb_file (*it,nzb_output_path, cache, data, data, data,tasks);
+     queue.add_tasks (tasks, Queue::BOTTOM);
+       nongui_gmainloop = g_main_loop_new (NULL, false);
     }
     register_shutdown_signals ();
     mainloop ();

Comment 13 Darren Albers 2007-01-02 19:26:08 UTC
That muffed up the formatting but the basic idea is that rather than load the nzb's before we go into the decision for if we load the GUI or not we load it after that decision is made.

It doesn't look very elegant to me since we are replicating code but I /think/ it would work.  I won't be able to try it until tonight.  

Thoughts?
Comment 14 Darren Albers 2007-01-03 01:18:41 UTC
Created attachment 79239 [details] [review]
Try #5 for save attachment patch

Ok this is much better, after we check if nzb is true I then do a check if gui is true and at that point set nzb_output_path = the save function and then return back as normal.  The only difference is that now nzb_output_path has the users preferred save path rather than pwd.

How does this look?  Any chance it can make it in before 1.0?  With a lot of people using NZB files from websites I think there are a large number of users who would appreciate this functionality.

Thanks!
Comment 15 Charles Kerr 2007-01-04 17:01:27 UTC
Created attachment 79397 [details] [review]
revision of previous patch.

Here's another try.  It's basically the same as #5, but:

* always honors the -o argument, if specified

* falls back to user's home dir, rather than current dir,
  which makes more sense when Pan's being invoked by another app

* makes the gui.cc dialog function public, so that pan.cc can
  call it instead of duplicating the code

What do you think?
Comment 16 Darren Albers 2007-01-04 17:29:45 UTC
I think it looks great!  One question though, so if the user hits cancel and no path is returned it will just save to the users preferred path?
Comment 17 Charles Kerr 2007-01-04 17:51:27 UTC
Created attachment 79401 [details] [review]
Try #7

The previous patch wouldn't work if the user pressed cancel,
but in this version it will fall back to the user's
home directory.
Comment 18 Darren Albers 2007-01-04 17:56:02 UTC
Oh I see, there will be a new preferences option to prompt for save path.  If
that is not set and the user did not use the -o option then $home will be used.

I think that looks perfect though to avoid usability issues I would say that
the default should probably be to prompt.

On another note if the user does have it set to prompt and then hits cancel shouldn't that cancel the entire process and not just fallback to $home?   
Comment 19 Duncan 2007-01-04 20:51:07 UTC
(In reply to comment #15)
> Created an attachment (id=79397) [edit]
> revision of previous patch.
> 
> Here's another try.  It's basically the same as #5, but:
> 
> * always honors the -o argument, if specified
> 
> * falls back to user's home dir, rather than current dir,
>   which makes more sense when Pan's being invoked by another app
> 
> * makes the gui.cc dialog function public, so that pan.cc can
>   call it instead of duplicating the code
> 
> What do you think?

I think I don't want additional files dumped directly in my home dir under any conditions, unless I specifically dump them there (and defaulting to it doesn't count as specifically dumping them there!).  I already have enough stuff there to worry about and don't need anything more to need to sort thru.  There's a reason my current pan starter scripts cd to a ~/pan/scraps/ subdir, since pan did at one point without warning start dumping stuff in its current working dir, which by default is $HOME.

However, if I get this code correct, I can simply test to see if -o is passed to my script on the commandline, and if not, add "-o ~/pan/scraps" to the line, just in case, in addition to cding to ~/pan/scraps before I start pan, and that should keep stuff out of $HOME.  I don't particularly like it, preferring $PWD as the default if there's no configured default, but as long as I can set -o unconditionally in the script (it won't do weird stuff if pan isn't invoked with a *.nzb, right?), I don't suppose I can protest /too/ loudly. =8^)

Duncan (who's a bit grouchy today due to nothing pan related, hope it doesn't come thru /too/ badly)
Comment 20 Charles Kerr 2007-01-04 21:33:58 UTC
The problem with using $PWD as the default is: what is $PWD when pan's
invoked from another application?  Is it the directory where pan or the
other application reside?  Does it vary by circumstances?  This is likely
to confuse users.

Yes, your script can check for -o and add it as necessary.
Comment 21 Darren Albers 2007-01-06 04:18:29 UTC
In my opinion if the user doesn't pass -o then if cancel is clicked it should cancel the whole operation.  It feels more natural for a user if the cancel dialog being clicked actually cancels the download.

Either way your patch works for my use case which is all that matters to me  ;)
Comment 22 Darren Albers 2007-01-08 18:34:31 UTC
Charles, out of curiosity will this make 1.0 or is it a 1.1 item?

Thanks!
Comment 23 Charles Kerr 2007-01-08 20:20:53 UTC
It's not too large, and doesn't break the string freeze... IMO 1.0
Comment 24 Charles Kerr 2007-01-14 17:24:47 UTC
Created attachment 80250 [details] [review]
Try #8 -- same as #7, but exit if user hits `cancel' in NZB dialog
Comment 25 Charles Kerr 2007-01-14 17:26:58 UTC
Also since try #8 prompts whenever no path is specified,
and exits if the user hits cancel,
then Pan will never default to $PWD, $HOME, or anywhere else...