sandun dhammika
sandun dhammika

Reputation: 921

open file folder in the directory

I want my C++ application to implement "open File Folder" functionality like in that firefox and download manager. This is the code that I've come up with.

int File::openTempFile(std::string temp_file_dir)
{
  std::string file_path = temp_file_dir + "/" ;
  file_path = file_path + this->additional_info ;

  // if there is already an temporary file then delete it//
  if( temporary_file != "" )
  {
    // :TODO: open temporary file stack //
    // so when the application dinit we could remove those //
    // remove(temporary_file.c_str() );
  } 

  /* write temporary file */
  FILE* fp = fopen (file_path.c_str(), "w");
  if( fp== NULL)
    return FALSE;
  fwrite( m_data, 1, m_size, fp);
  fclose(fp); 

  // now open it using natulus //
  char * parmList[] = {strdup("nautilus"),strdup(file_path.c_str() )} ;
  int pid;
  if(( pid= fork() ) == -1) 
    perror("fork failed");
  if( pid ==0 ){
    int a = execvp("nautilus" , parmList);
    printf("exevp failed to load the temporary file");
  }
  temporary_file = file_path ;
  return TRUE;
}

But Instead of a one nautilus window , it open 3 windows.Any idea what is the reason for that ?And how could I get nautilus "open with" dialog just instead of showing it on the directory ?

Upvotes: 2

Views: 705

Answers (1)

polarysekt
polarysekt

Reputation: 572

When opening a folder, I use the xdg-open command which opens the specified folder with the preferred file manager for a given desktop environment.

On my system when I'm running KDE, it calls dolphin to display the folder, and xfce4, it invokes thunar, as these are the preferred file managers as per my settings. I often don't want nautilus to be used, as the interface differs from my preferred apps, doesn't look consistent with the other applications - in terms of widgets, style, etc. - and won't group the same in my taskbar.

It also uses separate preferences for my default open-with settings, and conflicts with my workflow.

Additionally, nautilus isn't necessarily guaranteed to be on my system. For example, on some of my older systems, where I've emerged a custom gentoo system where I'm either constrained by RAM or HDD space, I've only emerged say twm and xfce4, so nautilus doesn't exist.

As far as the nautilus-specific behaviour is concerned, I have had similar problems with nautilus creates a desktop on initial invokation (as is the case when I am running twm).

Invoking nautilus --help shows the following options:

Application Options:
  -c, --check                 Perform a quick set of self-check tests.
  --version                   Show the version of the program.
  -g, --geometry=GEOMETRY     Create the initial window with the given geometry.
  -w, --new-window            Always open a new window for browsing specified URIs
  -n, --no-default-window     Only create windows for explicitly specified URIs.
  --no-desktop                Never manage the desktop (ignore the GSettings preference).
  --force-desktop             Always manage the desktop (ignore the GSettings preference).
  -q, --quit                  Quit Nautilus.
  -s, --select                Select specified URI in parent folder.
  --display=DISPLAY           X display to use

Unfortunately, I can't help you specifically invoke the nautilus "open with..." dialog, although xdg-open will use the default application when a file is specified. Perhaps polling configurations within the mimeapps.list file (which can be in one of several cascading override locations: including, but not limited to, user-desktop, user, sysadmin-desktop, sysadmin, default-desktop, and default).

Upvotes: 2

Related Questions