Exemplo n.º 1
0
int XFE_ComposeAttachDrop::processTargets(Atom *targets,const char **data,int numItems)
{
    XDEBUG(printf("XFE_ComposeAttachDrop::processTargets()\n"));
    
    if (!targets || !data || numItems==0)
        return FALSE;

    // pass dropped data to attachment panel

    char **dropInfo=new char*[numItems];
    int numDropInfo=0;
    int i;
    
    for (i=0;i<numItems;i++) {
        if (targets[i]==None || data[i]==NULL || strlen(data[i])==0)
            continue;

        XDEBUG(printf("  [%d] %s: \"%s\"\n",i,XmGetAtomName(XtDisplay(_widget),targets[i]),data[i]));

        if (targets[i]==_XA_FILE_NAME) {
            dropInfo[numDropInfo++]=XP_STRDUP(data[i]);
        }
        if (targets[i]==_XA_NETSCAPE_URL) {
            XFE_URLDesktopType urlData(data[i]);
            for (int j=0;j<urlData.numItems();j++) {
                dropInfo[numDropInfo++]=XP_STRDUP(urlData.url(j));
            }
        }
        if (targets[i]==XA_STRING) {
            dropInfo[numDropInfo++]=XP_STRDUP(data[i]);
        }
    }
    
    int dropStatus=_attachPanel->dropAttachments((const char **)dropInfo,numDropInfo);

    // free drop info
    for(i=0;i<numDropInfo; i++)
        if (dropInfo[i])
            XP_FREE(dropInfo[i]);
    delete dropInfo;
    
    return dropStatus;
}
Exemplo n.º 2
0
// external access for old xfe code - if a url points to a URL file (NetscapeURL, WebJumper)
// then extract the URL and return it.
//
// Note:'translateWebJumper' determines whether SGI WebJumpers will be resolved or not.
// In some cases, we want to keep them as indirect jumpers (attaching to an email.)
// In other cases we want to resolve them (opening a WebJumper in the browser.)
extern "C" int XFE_DesktopTypeTranslate(const char *url,char **desktop_url,int translateWebJumper) {
    if (desktop_url==NULL)
        return FALSE;

    *desktop_url=NULL;
    
    if (url==NULL || strlen(url)==0)
        return FALSE;    
    
    // if url points to a local file, extract the filename
    char *filename;
    if (strncmp(url,"file:",5)==0 && strlen(url+5)>0)
        filename=XP_STRDUP(url+5);
    else if (strncmp(url,"/",1)==0)
        filename=XP_STRDUP(url);
    else
        return FALSE;

    // strip trailing spaces
    int i=strlen(filename);
    while (isspace(filename[--i]))
        filename[i]='\0';
    
    int retval=FALSE;

    // open file and see if it's a Netscape desktop file
    FILE *fp;
    if (fp=fopen(filename,"r")) {
        const int MAX_LENGTH=4000;
        char line[MAX_LENGTH+1];
        line[MAX_LENGTH]='\0';
        line[0]='\0'; // ensure string will be null-terminated
        fgets(line,MAX_LENGTH,fp);

        // NetscapeURL
        if (XFE_URLDesktopType::isDesktopType(line)) {
            XFE_URLDesktopType urlData(fp);
            if (urlData.numItems()>0) {
                *desktop_url=XP_STRDUP(urlData.url(0));
                retval=TRUE;
            }
        }
        // WebJumper
        else if (translateWebJumper && XFE_WebJumperDesktopType::isDesktopType(line)) {
            XFE_WebJumperDesktopType wjData(fp);
            if (wjData.url()) {
                *desktop_url=XP_STRDUP(wjData.url());
                retval=TRUE;
            }
        }   
        // nyi - check for other Netscape desktop types here
        
        // file is not a Netscape desktop file
        else {
            retval=FALSE;
        }
        
        fclose(fp);
    }
    return retval;
}