【问题标题】:open file folder in the directory打开目录中的文件夹
【发布时间】:2014-09-18 23:12:41
【问题描述】:

我希望我的 C++ 应用程序能够像在那个 Firefox 和下载管理器中那样实现“打开文件夹”功能。这是我想出的代码。

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;
}

但是,它打开了 3 个窗口,而不是一个 nautilus 窗口。知道这是什么原因吗?我怎样才能让 nautilus “打开方式”对话框而不是在目录上显示它?

【问题讨论】:

    标签: c++ c file unix fork


    【解决方案1】:

    打开文件夹时,我使用xdg-open 命令打开指定的文件夹,并使用给定桌面环境的首选文件管理器。

    在我的系统上,当我运行KDE 时,它调用dolphin 来显示文件夹,而xfce4 它调用thunar,因为根据我的设置,这些是首选的文件管理器。我经常不想使用nautilus,因为界面与我喜欢的应用程序不同,看起来与其他应用程序不一致 - 在小部件、样式等方面 - 并且不会在我的任务栏。

    它还对我的默认打开方式设置使用单独的首选项,并与我的工作流程冲突。

    此外,nautilus 不一定保证在我的系统上。 例如,在我的一些旧系统上,我有 emergeda 自定义 gentoo 系统,我要么受到 RAM 或 HDD 空间的限制,我只有 emerged 说 twmxfce4,所以nautilus 不存在。

    就特定于 nautilus 的行为而言,我在 nautilus 在初始调用时创建桌面时遇到了类似问题(就像我运行 twm 时的情况一样)。

    调用nautilus --help 显示以下选项:

    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
    

    不幸的是,我无法帮助您专门调用nautilus“打开方式...”对话框,尽管xdg-open 将在指定文件时使用默认应用程序。可能会在mimeapps.list 文件中轮询配置(可以位于多个级联覆盖位置之一:包括但不限于 user-desktop、user、sysadmin-desktop、sysadmin、default-desktop 和 default)。

    【讨论】:

    • 先生,这绝对是我想要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-21
    • 2013-10-24
    • 1970-01-01
    • 2017-05-27
    • 1970-01-01
    • 2012-07-09
    相关资源
    最近更新 更多