我希望我的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;
}
但是,它没有打开一个nautilus窗口,而是打开了3个窗口。您知道是什么原因吗?我怎么能获得nautilus“打开方式”对话框而不是在目录中显示呢?
当打开文件夹时,我使用xdg-open
命令为给定的桌面环境使用首选的文件管理器打开指定的文件夹。
在我的系统上,当我运行时KDE
,它会调用dolphin
以显示该文件夹,然后xfce4
它会调用thunar
,因为根据我的设置,这是首选的文件管理器。我经常不希望nautilus
被使用,因为界面与我的首选应用程序不同,在小部件,样式等方面看起来与其他应用程序不一致,并且不会在任务栏中进行分组。
它还为我的默认打开方式设置使用了单独的首选项,并且与我的工作流程冲突。
此外,nautilus
不一定保证可以在我的系统上使用。例如,在我的一些较旧的系统上,如果我有一个emerge
自定义gentoo系统,而我要么受制于RAM或HDD空间,要么只emerge
说twm
和xfce4
,所以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
文件中的配置(可以位于多个级联覆盖位置之一中:包括但不限于用户桌面,用户,sysadmin桌面,sysadmin,default-desktop和default)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句