ftp.nice.ch/pub/next/connectivity/news/NGService.1.1.NIHS.bs.tar.gz#/NGService/Source/MMCell.m

This is MMCell.m in view mode; [Download] [Up]

/*
 *      You may freely copy, distribute and reuse the code
 *      in this example.  Scott Anguish disclaims any warranty of
 *      any kind, expressed or implied, as to its fitness
 *      for any particular use.
 *		Please keep this notice intact
 *      Written by: Scott Anguish  sanguish@digifix.com
 */

#import "MMCell.h"

#import <libc.h>					  /* MAXPATHLEN */
#import <stdio.h>
#import <strings.h>
#include <sys/types.h>
#include <ctype.h>
#include <stdlib.h>

#import <appkit/appkit.h>

#import <streams/streams.h>


@implementation MMCell:Cell

- initFromFilename:(const char *)filename
{
	[super init];
	displayContents=NO;
	[self imageFromFilename:filename];
	return self;
}


- imageFromAttachment
{
	return self;
}


- imageFromFilename:(const char *)filename
{
	return self;
}



- free
{
    fprintf(stderr,"Free\n");
	[theImage free];
	[self removeData];
	[super free];
	return self;
}

- calcCellSize:(NXSize *)theSize
{
    NXSize s;
	
    [theImage getSize: &s];
    s.height += 4.0;
    s.width += 4.0;
    *theSize = s;
    return self;
}

- highlight:(const NXRect *)cellFrame inView:controlView lit:(BOOL)flag;
{
    return self;
}


- writeRichText:(NXStream *)stream forView:view
{

	
	NXPrintf(stream, "NXPRINTF\n");
	return self;
}

- readPrivate:(NXStream *)stream name:(char *)name
{
	

    NXScanf(stream, "%s\n", name); 
	strcpy(attachmentName,name);
    NXScanf(stream, "%d ", &attachmentSize);
	

	attachmentData=malloc(attachmentSize);
	NXRead(stream, attachmentData,attachmentSize);
    return self;
}

- readRichText:(NXStream *)stream forView:view
{
    char name[MAXPATHLEN+1];

	MMView = view;
    [self readPrivate:stream name:name];
	[self uudecodeAttachment];
	[self imageFromAttachment];

    return self;
}

- (BOOL)trackMouse:(NXEvent *)theEvent 
	inRect:(const NXRect *)cellFrame 
	ofView:controlView;
{
	NXEvent eventBuf, *ev;
	NXPoint thePoint;
	NXRect theRect;
	id localImage;
	char filename[MAXPATHLEN+1];
	NXAtom thetype;

	sprintf(filename,"/tmp/%s",attachmentName);

	if ((theEvent->data.mouse.click == 1)) {
		ev = [NXApp peekNextEvent:NX_MOUSEDOWNMASK|NX_MOUSEUPMASK
			into:&eventBuf waitFor:0.3 threshold:NX_MODALRESPTHRESHOLD];
		if (!ev || ev->type == NX_MOUSEDRAGGED) {

			thePoint=theEvent->location;
			[controlView convertPoint:&thePoint fromView:NULL];
			NXSetRect(&theRect,thePoint.x-24,thePoint.y-24,48,48);
			[controlView dragFile:filename fromRect:&theRect slideBack:YES event:theEvent];
			return YES;
		}
    } 
	else if ((theEvent->data.mouse.click == 2)) {
		
		[[Application workspace] getInfoForFile:filename application:NULL type:&thetype];
		if ((thetype==NXApplicationFileType)||(thetype==NXShellCommandFileType))
			{
			 if (NXRunAlertPanel("NGService","This is an executable, and could be a security breach. Go ahead?","Yes", "Cancel", 
			 						NULL)==NX_ALERTALTERNATE){return YES;} 
			}
			 
		theRect = *cellFrame;
		NX_Y(&theRect) += 48.0;
		localImage=theImage;
		if (displayContents) 
			localImage=[[Application workspace] getIconForFile:filename];
		[[Application workspace] openFile:filename fromImage:localImage at:&theRect.origin inView:controlView];
		return YES;
    }
    return NO;
}

- read:(NXTypedStream *)stream
{
	[super read:stream];
	return self;
};
 
- write:(NXTypedStream *)stream
{
	[super write:stream];
	return self;
};
 
- drawInside: (const NXRect *)cellFrame inView:controlView
{
	NXPoint	compositePlace;


	compositePlace.x = cellFrame->origin.x+ 2.0;
	compositePlace.y = NX_MAXY(cellFrame) + 2.0;
	if (!theImage) NXFrameRect(cellFrame); else [theImage composite:NX_SOVER toPoint:&compositePlace];

	return self;
}

- uudecodeAttachment
{
	FILE *fp;
	char commandStr[BUFSIZ];
	
	sprintf(commandStr,"rm -f /tmp/%s.Z; /usr/bin/uudecode ",attachmentName);
	fp = popen (commandStr,"w");
	if (fp != (FILE *)NULL)
		{
		fprintf(fp,"begin 644 /tmp/%s.Z\n",attachmentName);
		fwrite(attachmentData,sizeof(char),attachmentSize,fp);
		fprintf(fp,"end\n");
    	fprintf(stderr,"Pipe Result %d \n",pclose(fp));
		}
		else
		fprintf(stderr,"Pipe did not open \n");

	sprintf(commandStr,"rm -fR /tmp/%s; cd /tmp; zcat %s.Z | /NextApps/Mail.app/safetar xf -; rm -f %s.Z", attachmentName, attachmentName, attachmentName);
	fp = popen (commandStr,"r");
	if (fp != (FILE *)NULL)
		{
    	fprintf(stderr,"Pipe Result %d \n",pclose(fp));
		}
		else
		fprintf(stderr,"Pipe did not open \n");
	return self;
};

- removeData
{
	FILE *fp;
	char commandStr[BUFSIZ];
	
	sprintf(commandStr,"rm -f %s", attachmentName);
	fp = popen (commandStr,"r");
	if (fp != (FILE *)NULL)
		{
    	fprintf(stderr,"Pipe Result %d \n",pclose(fp));
		}
		else
		fprintf(stderr,"Pipe did not open \n");
	return self;

}
@end

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.