⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filechooserwinc.c

📁 linux下的E_MAIL客户端源码
💻 C
📖 第 1 页 / 共 3 页
字号:
   unsigned char	spol;   XtVaGetValues(fileList, XmNselectionPolicy, &spol, NULL);   singleSelect = get_boolean(cl, *this, "singleSelect", spol==XmSINGLE_SELECT);   if ( singleSelect && spol != XmSINGLE_SELECT )      XtVaSetValues(fileList, XmNselectionPolicy, XmSINGLE_SELECT, NULL);   showDirsInFileList    = get_boolean(cl, *this, "showDirsInFileList",  False);   showFilesInFileList   = get_boolean(cl, *this, "showFilesInFileList", True);   acceptFileDoubleClick = get_boolean(cl, *this, "acceptFileDoubleClick",True);   dirName   = get_string(cl, *this, "directory", ".");   if ( !IsDir(dirName) ) dirName = ".";   filterStr = get_string(cl, *this, "filter",    "*");   XmTextFieldSetString(filterTF, filterStr);   if ( singleSelect ) {      XtManageChild(selectTF);      XtUnmanageChild(selectTextSW);      XtVaSetValues(selectForm, XmNinitialFocus, selectTF, NULL);//// Set special titles for single selection//      StringC	str = get_string(cl, *this, "singleTitle", "Select File");      if ( str.size() > 0 )	 XtVaSetValues(*this, XmNtitle, (char*)str, XmNiconName, (char*)str, 0);      str = get_string(cl, selectLabel, "singleString", "Selected File");      if ( str.size() > 0 ) {	 WXmString	wstr = (char*)str;	 XtVaSetValues(selectLabel, XmNlabelString, (XmString)wstr, NULL);      }   } else {      XtManageChild(selectTextSW);      XtUnmanageChild(selectTF);      XtVaSetValues(selectForm, XmNinitialFocus, selectText, NULL);   }   XtAddCallback(*this, XmNpopupCallback, (XtCallbackProc)DoPopup,		 (XtPointer)this);} // End constructor/*----------------------------------------------------------------------- *  Destructor */FileChooserWinC::~FileChooserWinC(){   DeleteCallbacks(verifyCalls);   DeleteCallbacks(okCalls);}/*----------------------------------------------------------------------- *  Handle initial display */voidFileChooserWinC::DoPopup(Widget, FileChooserWinC *This, XtPointer){   if ( This->singleSelect ) {//// Fix size of selectForm since this is single selection mode//      Dimension	ht;      XtVaGetValues(This->selectForm, XmNheight, &ht, NULL);      XtVaSetValues(This->selectForm, XmNpaneMinimum, ht, XmNpaneMaximum, ht,0);   }   if ( XmToggleButtonGetState(This->listTB) )      This->ShowList();}/*----------------------------------------------------------------------- *  Display list portion */voidFileChooserWinC::ShowList(){   if ( listVisible ) return;   XtManageChild(listForm);   XmToggleButtonSetState(listTB, True, False);   listVisible = True;   SetDirectory(dirName);}/*----------------------------------------------------------------------- *  Display directories in file list */voidFileChooserWinC::ShowDirsInFileList(Boolean val){   if ( showDirsInFileList == val ) return;   showDirsInFileList = val;   if ( !listVisible ) return;   SetDirectory(dirName);}/*----------------------------------------------------------------------- *  Display files in file list */voidFileChooserWinC::ShowFilesInFileList(Boolean val){   if ( showFilesInFileList == val ) return;   showFilesInFileList = val;   if ( !listVisible ) return;   SetDirectory(dirName);}/*----------------------------------------------------------------------- *  Removed list portion */voidFileChooserWinC::HideList(){   if ( !listVisible ) return;   XtUnmanageChild(listForm);   XmToggleButtonSetState(listTB, False, False);   listVisible = False;//// Re-read the names in the selected text field.  They could possibly have//    been expanded to full pathnames internally.//   if ( singleSelect ) SelectTFChanged(NULL, this, NULL);   else		       SelectTextChanged(NULL, this, NULL);}/*----------------------------------------------------------------------- *  Method to clear current selection */voidFileChooserWinC::ClearSelection(){   XmListDeselectAllItems(fileList);   XmTextSetString(selectText, "");   XmTextSetString(selectTF, "");}/*----------------------------------------------------------------------- *  Display dialog */voidFileChooserWinC::Show(Widget parent){   WArgList	args;   if ( showImap ) {      XtManageChild(imapForm);      args.BottomAttachment(XmATTACH_WIDGET, imapForm);   }   else {      XtUnmanageChild(imapForm);      args.BottomAttachment(XmATTACH_FORM);   }   XtSetValues(selectTextForm, ARGS);   HalDialogC::Show(parent);//// Update the directory listing if it has changed since the last time we// listed it.//   if ( listVisible && dirName.size() > 0 ) {      struct stat	statbuf;      if ( stat(dirName, &statbuf) == 0 && statbuf.st_mtime > lastTimeListed )	 SetDirectory(dirName);   }} // End Show/*----------------------------------------------------------------------- *  Show the contents of the given directory */voidFileChooserWinC::SetDefaultDir(const char *dir){   defaultDir = dir;}/*----------------------------------------------------------------------- *  Show the contents of the given directory */voidFileChooserWinC::SetDirectory(StringC dir){   if ( debuglev > 0 ) cout <<"Setting directory to \"" <<dir <<"\"" <<endl;   if ( UsingImap() ) {      dirName = dir;   }   else {      ShellExpand(dir);      if ( debuglev > 0 )	 cout <<"Shell expanded name is \"" <<dir <<"\"" <<endl;      char	*sp = strchr((char *)dir, ' ');      if ( sp ) {	 int	pos = sp - (char*)dir;	 dir.Clear(pos);      }      dir = FullPathname(dir);      if ( debuglev > 0 ) cout <<"Full pathname is \"" <<dir <<"\"" <<endl;      if ( !IsDir(dir) ) return;      dirName = dir;      if ( dirName.size() == 0 )	     dirName = ".";      else if ( dirName.size() > 1 && dirName.EndsWith("/") )	 dirName.Clear(dirName.size()-1);   }   if ( debuglev > 0 ) cout <<"Final name is \"" <<dirName <<"\"" <<endl;   XmTextFieldSetString(dirNameTF, dirName);   XmTextFieldShowPosition(dirNameTF, XmTextFieldGetLastPosition(dirNameTF));   if ( !listVisible ) return;   BusyCursor(True);//// Get the directory entries//   ListDirectory(dirName, fileNames, subdirNames);//// Allow caller to preview lists and adjust if desired//   Message("Sorting names...");   CallCallbacks(verifyCalls, &fileNames);   CallCallbacks(verifyCalls, &subdirNames);//// Display names//   subdirNames.sort();   SetList(dirList, subdirNames);//// Apply the file filter to the file list//   Message("Applying filter...");   FilterFiles();//// Re-read the names in the selected text field.  If there are any names//    still there, the full pathnames need to be updated.//   if ( singleSelect ) SelectTFChanged(NULL, this, NULL);   else		       SelectTextChanged(NULL, this, NULL);   ClearMessage();   BusyCursor(False);} // End SetDirectory/*----------------------------------------------------------------------- *  Method to get list of files in specified directory */voidFileChooserWinC::ListDirectory(const char *dir, StringListC& files,						StringListC& dirs){   if ( UsingImap() ) {      ListDirectoryImap(dir, files, dirs);      return;   }   files.removeAll();   dirs.removeAll();   DIR	*dirp = opendir(dir);   if ( !dirp ) {      StringC	msg("Cannot read directory: ");      msg += dir;      PopupMessage(msg);      return;   }   StringC	path(dir);   if ( !path.EndsWith("/") ) path += "/";   int		prefixlen = path.size();   StringC	name;   char		*baseMsg = "Reading files: ";   StringC	msg;   int		count = 0;   struct dirent	*dp;   while ( (dp=readdir(dirp)) != NULL) {      if ( count % 10 == 0 ) {	 msg = baseMsg, msg += count;	 Message(msg);      }      name = dp->d_name;      if ( name == "." ) continue;      if ( name == ".." ) {	 dirs.add(name);      }      else {	 path += name;	 if ( IsDir(path) ) {	    dirs.add(name);	    if ( showDirsInFileList ) {	       name += "/";	       files.add(name);	    }	 }	 else if ( showFilesInFileList )	    files.add(name);	 path.Clear(prefixlen);      }      count++;   }   ClearMessage();   closedir(dirp);   struct stat	statbuf;   if ( stat(dir, &statbuf) == 0 )      lastTimeListed = statbuf.st_mtime;   else      lastTimeListed = time(0);} // End ListDirectory/*----------------------------------------------------------------------- *  Method to open a connection to the IMAP server */BooleanFileChooserWinC::GetImapServerName(StringC& name){//// Get the name of the IMAP server//   char	*cs = XmTextFieldGetString(imapTF);   name = cs;   name.Trim();   if ( name.size() == 0 ) {      set_invalid(imapTF, True, True);      StringC	errmsg("Please enter the name of an IMAP server.");      PopupMessage(errmsg);      return False;   }   return True;} // End GetImapServerName/*----------------------------------------------------------------------- *  Method to get list of files in specified directory on current IMAP server */voidFileChooserWinC::ListDirectoryImap(CharC dir, StringListC& files,					      StringListC& dirs){   files.removeAll();   dirs.removeAll();   StringC	serverName;   if ( !GetImapServerName(serverName) ) return;   ImapServerC	*server = FindImapServer(serverName);//// Get file listing//   StringC	pat = dir;   if ( pat.size() > 0 && !pat.EndsWith('/') ) pat += '/';   pat += '*';   dir = pat;   dir.CutEnd(1);   StringListC	output;   if ( !server->ListMailboxes(pat, files, output) )      return;//// Remove directory name from beginning of files//   dir = pat;   dir.CutEnd(1);   u_int	count = files.size();   int i=0; for (i=0; i<count; i++) {      StringC	*name = files[i];      if ( name->StartsWith(dir) ) name->CutBeg(dir.Length());      if ( *name == "." ) {	 files.remove(i);	 i--;	 count--;	 continue;      }      if ( *name == ".." ) {	 dirs.add(*name);	 files.remove(i);	 i--;	 count--;	 continue;      }   } // End for each entry   return;} // End ListDirectoryImap/*----------------------------------------------------------------------- *  Method to return the last component of a pathname */StringCFileChooserWinC::BaseName(StringC& path){   static RegexC*	basePat = NULL;   if ( !basePat ) basePat = new RegexC(".*/\\([^/]+\\)/?$");   if ( basePat->search(path) >= 0 ) {	return path((*basePat)[1]);   } else {      return path;   }} // End BaseName/*----------------------------------------------------------------------- *  Method to apply filter to file names */voidFileChooserWinC::FilterFiles(){   filtNames.removeAll();   filterPat = ShellToRegex(filterStr);   unsigned		count = fileNames.size();   int i=0; for (i=0; i<count; i++) {      StringC*	name = fileNames[i];      if ( filterPat.match(*name) ) filtNames.add(*name);   }   filtNames.sort();   SetList(fileList, filtNames);} // End FilterFiles/*----------------------------------------------------------------------- *  Method to set an XmList using a StringList */voidFileChooserWinC::SetList(Widget wlist, StringListC& slist){   int		count = slist.size();   XmString	*strList = new XmString[count];   int i=0; for (i=0; i<count; i++) {      char	*cs = *slist[i];      strList[i] = XmStringCreateLtoR(cs, XmFONTLIST_DEFAULT_TAG);   }   Boolean	resize;   XtVaGetValues(*this, XtNallowShellResize, &resize, NULL);   XtVaSetValues(*this, XtNallowShellResize, False, NULL);   XtVaSetValues(wlist, XmNitems, strList, XmNitemCount, count, NULL);   XtVaSetValues(*this, XtNallowShellResize, resize, NULL);   for (i=0; i<count; i++) XmStringFree(strList[i]);   delete strList;}/*----------------------------------------------------------------------- *  Method to display names in select list */voidFileChooserWinC::UpdateSelectText(){   localTextChange = True;   if ( singleSelect ) {      if ( selectNames.size() > 0 ) {	 XmTextFieldSetString(selectTF, *selectNames[0]);	 XtSetSensitive(okPB, True);      } else {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -