【发布时间】: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 “打开方式”对话框而不是在目录上显示它?
【问题讨论】: