Ejemplo n.º 1
0
bool
DialUpView::SaveSettingsToFile()
{
	bool settingsChanged, profileChanged;
	IsModified(&settingsChanged, &profileChanged);
	if(!settingsChanged && !profileChanged)
		return true;
	
	BMessage settings, profile;
	if(!SaveSettings(&settings, &profile, false))
		return false;
	
	BDirectory settingsDirectory;
	BDirectory profileDirectory;
	GetPPPDirectories(&settingsDirectory, &profileDirectory);
	if(settingsDirectory.InitCheck() != B_OK || profileDirectory.InitCheck() != B_OK)
		return false;
	
	BFile file;
	if(settingsChanged) {
		settingsDirectory.CreateFile(fCurrentItem->Label(), &file);
		WriteMessageDriverSettings(file, settings);
	}
	
	if(profileChanged) {
		profileDirectory.CreateFile(fCurrentItem->Label(), &file);
		WriteMessageDriverSettings(file, profile);
	}
	
	return true;
}
Ejemplo n.º 2
0
/*!	Adds a menu populated with the keyboard layouts found in the passed
	in directory to the passed in menu. Each subdirectory in the passed
	in directory is added as a submenu recursively.
*/
void
KeymapWindow::_AddKeyboardLayoutMenu(BMenu* menu, BDirectory directory)
{
	entry_ref ref;

	while (directory.GetNextRef(&ref) == B_OK) {
		if (menu->FindItem(ref.name) != NULL)
			continue;

		BDirectory subdirectory;
		subdirectory.SetTo(&ref);
		if (subdirectory.InitCheck() == B_OK) {
			BMenu* submenu = new BMenu(B_TRANSLATE_NOCOLLECT(ref.name));

			_AddKeyboardLayoutMenu(submenu, subdirectory);
			menu->AddItem(submenu);
		} else {
			BMessage* message = new BMessage(kChangeKeyboardLayout);

			message->AddRef("ref", &ref);
			menu->AddItem(new BMenuItem(B_TRANSLATE_NOCOLLECT(ref.name),
				message));
		}
	}
}
Ejemplo n.º 3
0
void
PrinterListView::_AddPrinter(BDirectory& printer, bool calculateLayout)
{
	BString state;
	node_ref node;
		// If the entry is a directory
	if (printer.InitCheck() == B_OK
		&& printer.GetNodeRef(&node) == B_OK
		&& _FindItem(&node) == NULL
		&& printer.ReadAttrString(PSRV_PRINTER_ATTR_STATE, &state) == B_OK
		&& state == "free") {
			// Check it's Mime type for a spool director
		BNodeInfo info(&printer);
		char buffer[256];

		if (info.GetType(buffer) == B_OK
			&& strcmp(buffer, PSRV_PRINTER_FILETYPE) == 0) {
				// Yes, it is a printer definition node
			AddItem(new PrinterItem(static_cast<PrintersWindow*>(Window()),
				printer, fLayoutData));
			if (calculateLayout)
				_LayoutPrinterItems();
		}
	}
}
Ejemplo n.º 4
0
BEntry* TaskFS::ListToDirectory(TaskList *theList)
{
	BEntry		*entry	= NULL;
	BDirectory	*dir	= new BDirectory();
	int32		i		= 0;
	if (tasksDir.InitCheck()==B_OK) {
		if (tasksDir.CreateDirectory(theList->Name(),dir)==B_OK)
		{
			if (dir->InitCheck()==B_OK){
				dir->WriteAttrString("META:task_id",  new BString(theList->ID()));
				dir->WriteAttrString("META:task_url",new BString(theList->URL()));
				ssize_t written = tasksDir.WriteAttr("_trk/columns_le", B_RAW_TYPE,
					0, task_columns, sizeof(task_columns));
				if (written < 0)
					printf("Failed to write column info (%s)\n", strerror(written));
				for (i=0;i<theList->GetTasks()->CountItems();i++)
				{
					TaskToFile(theList->GetTasks()->ItemAt(i));
				}
				dir->SetModificationTime(theList->LastUpdate());
			}
		}
	}
	delete dir;
	return entry;
}
Ejemplo n.º 5
0
void 
Settings::_SaveCurrentSettings(bool onlyIfNonDefault)
{
	BDirectory fSettingsDir;
	_MakeSettingsDirectory(&fSettingsDir);

	if (fSettingsDir.InitCheck() != B_OK)
		return;

	printf("+++++++++++ Settings::_SaveCurrentSettings %s\n", fFileName);
	// nuke old settings
	BEntry entry(&fSettingsDir, fFileName);
	entry.Remove();
	
	BFile prefs(&entry, O_RDWR | O_CREAT);
	if (prefs.InitCheck() != B_OK)
		return;

	fCurrentSettings = &prefs;
	for (int32 index = 0; index < fCount; index++) {
		fList[index]->SaveSettings(this, onlyIfNonDefault);
	}

	fCurrentSettings = 0;
}
Ejemplo n.º 6
0
/*
 * This function is lifted from Simple Directmedia Layer (SDL):
 *  http://www.libsdl.org/
 */
static void tryDir(const char *d, PHYSFS_StringCallback callback, void *data)
{
    BDirectory dir;
    dir.SetTo(d);
    if (dir.InitCheck() != B_NO_ERROR)
        return;

    dir.Rewind();
    BEntry entry;
    while (dir.GetNextEntry(&entry) >= 0)
    {
        BPath path;
        const char *name;
        entry_ref e;

        if (entry.GetPath(&path) != B_NO_ERROR)
            continue;

        name = path.Path();

        if (entry.GetRef(&e) != B_NO_ERROR)
            continue;

        if (entry.IsDirectory())
        {
            if (strcmp(e.name, "floppy") != 0)
                tryDir(name, callback, data);
        } /* if */

        else
        {
            bool add_it = false;
            int devfd;
            device_geometry g;

            if (strcmp(e.name, "raw") == 0)  /* ignore partitions. */
            {
                int devfd = open(name, O_RDONLY);
                if (devfd >= 0)
                {
                    if (ioctl(devfd, B_GET_GEOMETRY, &g, sizeof(g)) >= 0)
                    {
                        if (g.device_type == B_CD)
                        {
                            char *mntpnt = getMountPoint(name);
                            if (mntpnt != NULL)
                            {
                                callback(data, mntpnt);
                                allocator.Free(mntpnt);  /* !!! FIXME: lose this malloc! */
                            } /* if */
                        } /* if */
                    } /* if */
                } /* if */
            } /* if */

            close(devfd);
        } /* else */
    } /* while */
} /* tryDir */
Ejemplo n.º 7
0
// Scan directory for CD-ROM drives, add them to prefs
static void scan_for_cdrom_drives(const char *directory)
{
	// Set directory
	BDirectory dir;
	dir.SetTo(directory);
	if (dir.InitCheck() != B_NO_ERROR)
		return;
	dir.Rewind();

	// Scan each entry
	BEntry entry;
	while (dir.GetNextEntry(&entry) >= 0) {

		// Get path and ref for entry
		BPath path;
		if (entry.GetPath(&path) != B_NO_ERROR)
			continue;
		const char *name = path.Path();
		entry_ref e;
		if (entry.GetRef(&e) != B_NO_ERROR)
			continue;

		// Recursively enter subdirectories (except for floppy)
		if (entry.IsDirectory()) {
			if (!strcmp(e.name, "floppy"))
				continue;
			scan_for_cdrom_drives(name);
		} else {

			D(bug(" checking '%s'\n", name));

			// Ignore partitions
			if (strcmp(e.name, "raw"))
				continue;

			// Open device
			int fd = open(name, O_RDONLY);
			if (fd < 0)
				continue;

			// Get geometry and device type
			device_geometry g;
			if (ioctl(fd, B_GET_GEOMETRY, &g, sizeof(g)) < 0) {
				close(fd);
				continue;
			}

			// Insert to list if it is a CD drive
			if (g.device_type == B_CD)
				PrefsAddString("cdrom", name);
			close(fd);
		}
	}
}
Ejemplo n.º 8
0
void
InitialIterator::_ExamineSubdir(BEntry& entry)
{
	if (!FollowSubdir(entry))
		return;

	BDirectory* dir = new (nothrow) BDirectory(&entry);
	if (dir == NULL || dir->InitCheck() != B_OK || !fDirectories.AddItem(dir)) {
		// clean up
		delete dir;
		return;
	}

	fCurrentDir = dir;
}
Ejemplo n.º 9
0
    /*
     * This function is lifted from Simple Directmedia Layer (SDL):
     *  https://www.libsdl.org/  ... this is zlib-licensed code, too.
     */
static void tryDir(const char *d, PHYSFS_StringCallback callback, void *data)
{
    BDirectory dir;
    dir.SetTo(d);
    if (dir.InitCheck() != B_NO_ERROR)
        return;

    dir.Rewind();
    BEntry entry;
    while (dir.GetNextEntry(&entry) >= 0)
    {
        BPath path;
        const char *name;
        entry_ref e;

        if (entry.GetPath(&path) != B_NO_ERROR)
            continue;

        name = path.Path();

        if (entry.GetRef(&e) != B_NO_ERROR)
            continue;

        if (entry.IsDirectory())
        {
            if (strcmp(e.name, "floppy") != 0)
                tryDir(name, callback, data);
            continue;
        } /* if */

        const int devfd = open(name, O_RDONLY);
        if (devfd < 0)
            continue;

        device_geometry g;
        const int rc = ioctl(devfd, B_GET_GEOMETRY, &g, sizeof (g));
        close(devfd);
        if (rc < 0)
            continue;

        if (g.device_type != B_CD)
            continue;

        char mntpnt[B_FILE_NAME_LENGTH];
        if (getMountPoint(name, mntpnt, sizeof (mntpnt)))
            callback(data, mntpnt);
    } /* while */
} /* tryDir */
BDirectory *
create_mydir(char *str)
{
	BDirectory *dir;
	
	if ((dir = new BDirectory(str)))
	{
		if (dir->InitCheck() == B_OK)
		{
			return(dir);
		}

		delete dir;
	}	
			
	return(NULL);	
}
Ejemplo n.º 11
0
/*	isProject
* checks if an selected folder is a lava project folder.
*/
bool
ProjectTypeSelector::isProject()
{
	BNode objNode;
	BString *Project = (BString*)FileList->FirstItem();
	objNode.SetTo(Project->String());
	
	char buffer[500];
	memset(buffer, 0, sizeof(buffer));

	if(objNode.ReadAttr("LAVA:Type", B_STRING_TYPE, 0, buffer, sizeof(buffer)) == B_ENTRY_NOT_FOUND)
		return false;
	else {
		BDirectory objDir;
		objDir.SetTo(Project->String());
		if(objDir.InitCheck() != B_OK)
			return false;
		else
			return true;
	}
}
Ejemplo n.º 12
0
void
VirtualKeyboardWindow::_LoadLayoutMenu(BMenu* menu, BDirectory directory)
{
	entry_ref ref;

	while (directory.GetNextRef(&ref) == B_OK) {
		if (menu->FindItem(ref.name) != NULL)
			continue;

		BDirectory subdirectory;
		subdirectory.SetTo(&ref);
		if (subdirectory.InitCheck() == B_OK) {
			BMenu* submenu = new BMenu(ref.name);
			_LoadLayoutMenu(submenu, subdirectory);
			menu->AddItem(submenu);
		} else {
			//BMessage* message = new BMessage(kChangeKeyboardLayout);
			//message->AddRed("ref",&ref);
			menu->AddItem(new BMenuItem(ref.name, NULL));
		}
	}
}
Ejemplo n.º 13
0
void PrefsWindow::add_serial_names(BPopUpMenu *menu, uint32 msg)
{
	BSerialPort *port = new BSerialPort;
	char name[B_PATH_NAME_LENGTH];
	for (int i=0; i<port->CountDevices(); i++) {
		port->GetDeviceName(i, name);
		menu->AddItem(new BMenuItem(name, new BMessage(msg)));
	}
	if (sys_info.platform_type == B_BEBOX_PLATFORM) {
		BDirectory dir;
		BEntry entry;
		dir.SetTo("/dev/parallel");
		if (dir.InitCheck() == B_NO_ERROR) {
			dir.Rewind();
			while (dir.GetNextEntry(&entry) >= 0) {
				if (!entry.IsDirectory()) {
					entry.GetName(name);
					menu->AddItem(new BMenuItem(name, new BMessage(msg)));
				}
			}
		}
	}
	delete port;
}
Ejemplo n.º 14
0
void MyApplication::RefsReceived(BMessage *message)
{
//	be_app->Lock();

	uint32			ref_num;
	entry_ref		ref;
	BMediaTrack 	*audTrack(NULL);
	media_format	format;
	memset(&format, 0, sizeof(format));
//	media_raw_audio_format *raf(NULL);
//	short			audioFrameSize(1);
//	char			*audioData(NULL);
	int32			frame_size, channels = 1;
	
	Pool.sample_type = NONE;		// for frame moving / resize
	bool temp_pause = play_cookie.pause;;

	ref_num=0;
	if (message->FindRef("refs",ref_num, &ref) == B_OK){

		BMediaFile		inFile(&ref);
		if (inFile.InitCheck() == B_OK){

			char s[B_FILE_NAME_LENGTH +20];
			sprintf(s, "BeAE - %s", ref.name);
			mainWindow->SetTitle(s);

			Pool.sample_view_dirty = true;	// update the sample-view
			Pool.update_index = true;
			Pool.RedrawWindow();
			play_cookie.pause = true;

			// gather the necessary format information
			int32 tracks = inFile.CountTracks();
			for (int32 i = 0; i < tracks; i++) {
				BMediaTrack *inTrack = inFile.TrackAt(i);
				inTrack->EncodedFormat(&format);

				if (format.IsAudio()) {
					audTrack = inTrack;
					inTrack->DecodedFormat(&format);

//					Pool.m_format = format;
					memcpy(&Pool.m_format, &format, sizeof(Pool.m_format));

					Pool.sample_bits = (format.u.raw_audio.format & 0xf)*8;
					Pool.selection = NONE;
					Pool.frequency = format.u.raw_audio.frame_rate;

//					printf("format : %x\n", format.u.raw_audio.format);

					Pool.size = audTrack->CountFrames()-1;
					channels = format.u.raw_audio.channel_count;

					Pool.StartProgress(Language.get("LOADING_FILE"), Pool.size);
					
					frame_size = (format.u.raw_audio.format & 0xf)*channels;

#ifndef __VM_SYSTEM	//RAM
					if (Pool.sample_memory)						// create buffer for sample memory, add an extra frame to be able to do
						free(Pool.sample_memory);				//  32bit to 16 bit conversions
					
					Pool.sample_memory = (float*)malloc(Pool.size * channels *4 +1024);
#endif					
				}else{
					inFile.ReleaseAllTracks();
				}
			}

			int64 frameCount, framesRead;
			status_t err;
			media_header mh;
			int32 lastPercent, currPercent;
			float completePercent;
			BString status;
			char *buffer = (char*)malloc(format.u.raw_audio.buffer_size);		// temp memory
#ifndef __VM_SYSTEM	//RAM
			float *mem = Pool.sample_memory;									// dest memory
			// read audio from source and write to destination, if necessary
			if (mem) {
#else
			VM.Reset();

			float *convert_buffer = (float*)malloc(format.u.raw_audio.buffer_size*4);		// make sure there can be floats in it
			// read audio from source and write to destination, if necessary
			if (convert_buffer) {
				float *mem = NULL;
#endif			
				frameCount = audTrack->CountFrames();
				int64 count =0;
				lastPercent = -1;
				for (int64 i = 0; i < frameCount; i += framesRead) {
				
					#ifdef __VM_SYSTEM	//RAM
					mem = convert_buffer;
					#endif
					
					// clear buffer first
					memset( buffer, 0, format.u.raw_audio.buffer_size);
					if ((err = audTrack->ReadFrames(buffer, &framesRead, &mh)) != B_OK) {
						printf("Error reading audio frames: %s\n", strerror(err));
						break;
					}

					count += framesRead;			// now correct for crashes if bigger than file
					if (count > frameCount)
						framesRead -= (count - frameCount);
		
					switch(format.u.raw_audio.format){
					case 0x24:	// 0 == mid, -1.0 == bottom, 1.0 == top (the preferred format for non-game audio)
					{	float *tmp = (float*)buffer;
						float x;
						for (int32 count = 0; count<framesRead*channels; count++){
							x = *tmp++;
							if (x<-1.0)		x = -1.0;
							else if (x>1.0)	x = 1.0;
							*mem++ = x;
						}
					}	break;
					case 0x4:	// 0 == mid, 0x80000001 == bottom, 0x7fffffff == top (all >16-bit formats, left-adjusted)
					{	int32 *tmp = (int32*)buffer;
						float x;
						for (int32 count = 0; count<framesRead*channels; count++){
							x = *tmp++/0x80000000;
							if (x<-1.0)		x = -1.0;
							else if (x>1.0)	x = 1.0;
							*mem++ = x;
						}
					}	break;
					case 0x2:	// 0 == mid, -32767 == bottom, +32767 == top
					{	int16 *tmp = (int16*)buffer;
						float x;
						for (int32 count = 0; count<framesRead*channels; count++){
							x = *tmp++/32767.0;
							if (x<-1.0)		x = -1.0;
							else if (x>1.0)	x = 1.0;
							*mem++ = x;
						}
					}	break;
					case 0x11:	// 128 == mid, 1 == bottom, 255 == top (discouraged but supported format)
					{	uint8 *tmp = (uint8*)buffer;
						float x;
						for (int32 count = 0; count<framesRead*channels; count++){
							x = *tmp++/127.0 -1.0;
							if (x<-1.0)		x = -1.0;
							else if (x>1.0)	x = 1.0;
							*mem++ = x;
						}
					}	break;
					case 0x1:		// 0 == mid, -127 == bottom, +127 == top (not officially supported format)
					{	int8 *tmp = (int8*)buffer;
						float x;
						for (int32 count = 0; count<framesRead*channels; count++){
							x = *tmp++/127.0;		// xor 128 to invert sign bit
							if (x<-1.0)		x = -1.0;
							else if (x>1.0)	x = 1.0;
							*mem++ = x;
						}
					}	break;
					}
					
					#ifdef __VM_SYSTEM	//RAM
					VM.WriteBlock( convert_buffer, framesRead*channels );
					#endif

					Pool.ProgressUpdate( framesRead );

					completePercent = ((float)i) / ((float)frameCount) * 100;
					currPercent = (int16)floor(completePercent);
					if (currPercent > lastPercent) {
						lastPercent = currPercent;
					}
				}
				inFile.ReleaseAllTracks();
				#ifdef __VM_SYSTEM	//RAM
				free(convert_buffer);
				#endif
			}else{
				Pool.play_mode = NONE;
				Pool.pointer = 0;
				Pool.play_pointer = 0;
				Pool.l_pointer = 0;
				Pool.r_pointer = 0;
				Pool.r_sel_pointer = 0;
				Pool.size = 0;
				Pool.selection = NONE;
				Pool.sample_type = NONE;
				Pool.sample_bits = 16;
				Pool.frequency = 41400.0;

		         (new BAlert(NULL,Language.get("MEM_ERROR"),Language.get("OK")))->Go();

			}
			
			if (channels == 1)
				Pool.sample_type = MONO;
			else
				Pool.sample_type = STEREO;

			Pool.r_pointer = Pool.size;
			Pool.pointer = 0;
			Pool.r_sel_pointer = Pool.pointer;
			Pool.l_pointer = 0;

#ifndef __VM_SYSTEM	//RAM
			play_cookie.mem = Pool.sample_memory;
			play_cookie.start_mem = Pool.sample_memory;
			play_cookie.end_mem = Pool.sample_memory + Pool.size*Pool.sample_type;
			play_cookie.frequency = Pool.frequency;
			play_cookie.add = 0;
#else			
			play_cookie.mem = 0;
			play_cookie.start_mem = 0;
//			play_cookie.end_mem = Pool.size*Pool.sample_type;
			play_cookie.frequency = Pool.frequency;
			play_cookie.add = 0;
#endif
			Pool.changed = false;
			Pool.HideProgress();

			// create the PeakFile
			Pool.ResetIndexView();
			Hist.Reset();				// reset undo class

			if (IsLaunching() && Prefs.play_when_loaded)
				Pool.mainWindow->PostMessage(TRANSPORT_PLAYS);
			
		}else{
			(new BAlert(NULL,Language.get("LOADING_NO_AUDIO"),Language.get("OK")))->Go();
		}
	}
	
	Pool.sample_view_dirty = true;	// update the sample-view
	Pool.update_draw_cache = true;	// update the draw cache
	Pool.update_index = true;		// update the draw cache
	Pool.update_peak = true;
	Pool.RedrawWindow();
	Pool.InitBufferPlayer( Pool.frequency );

	play_cookie.pause = temp_pause;
	Pool.UpdateMenu();
	mainWindow->UpdateRecent();
//	be_app->Unlock();
}

//------------------------------------------------------------------ Save

void MyApplication::Save(BMessage *message){
	// Grab the stuff we know is there .. or should be :P

	entry_ref dir_ref, file_ref;
	const char *name;
	BFile newFile;
	BDirectory dir;
	float t;
	
	if ((message->FindRef("directory", &dir_ref) == B_OK)
		&& (message->FindString("name", &name) == B_OK))
	{
		dir.SetTo(&dir_ref);
		if (dir.InitCheck() != B_OK)
			return;
			
		dir.CreateFile(name, &newFile);
		
		BEntry entry(&dir, name);
		if (entry.InitCheck() != B_OK) {
			(new BAlert(NULL, Language.get("CANT_OVERWRITE_FILE"), Language.get("OK")))->Go();
			return;
		}
		entry.GetRef(&file_ref);

		media_codec_info *audioCodec;
		media_file_format *fileFormat;
		media_raw_audio_format *raf(NULL), *raf_in(NULL);
		media_format format;
		memset(&format, 0, sizeof(format));
		char *buffer(NULL);
		int32 frame_size(1);

		fSavePanel->GetSelectedFormatInfo(&fileFormat, &audioCodec);

		if (audioCodec != NULL){

//			format = Pool.m_format;
			memcpy(&format, &Pool.m_format, sizeof(format));
			raf_in = &(format.u.raw_audio);
			format.type = B_MEDIA_RAW_AUDIO;

			if (raf_in->format == 1)	raf_in->format = 0x11;
			
			// create media file
			BMediaFile file(&file_ref, fileFormat, B_MEDIA_FILE_REPLACE_MODE);
			if (file.InitCheck() != B_OK){
				(new BAlert(NULL, Language.get("CANT_OVERWRITE_FILE"), Language.get("OK")))->Go();
				return;
			}
			
			BMediaTrack *outTrack = file.CreateTrack(&format, audioCodec);

			if (outTrack){
				file.CommitHeader();

				if (save_start == 0){			// save as
					char s[B_FILE_NAME_LENGTH +20];
					sprintf(s, "BeAE - %s", file_ref.name);
					mainWindow->SetTitle(s);
				}

				raf = &(format.u.raw_audio);
				buffer = (char*)malloc(raf->buffer_size);
				int32 channels = raf->channel_count;
				frame_size = (raf->format & 0xf) * raf->channel_count;
				
				int32 buffer_step = raf->buffer_size / frame_size;
#ifndef __VM_SYSTEM	//RAM
				float *mem = Pool.sample_memory + save_start*Pool.sample_type;	// src memory
#else
				float *convert_buffer = (float*)malloc(buffer_step*channels*4);		// make sure there can be floats in it
				// read audio from source and write to destination, if necessary
				if (convert_buffer) {
					VM.ReadBlockAt(save_start, convert_buffer, buffer_step*channels );
					float *mem = convert_buffer;
#endif			

				Pool.StartProgress(Language.get("SAVING_FILE"), save_end-save_start);
				for (int64 i=save_start; i<save_end; i+=buffer_step){

				// fill up the buffer

					int32 block = MIN( (save_end-i) , buffer_step);
					switch(format.u.raw_audio.format){
					case 0x24:	// 0 == mid, -1.0 == bottom, 1.0 == top (the preferred format for non-game audio)
					{	float *tmp = (float*)buffer;
						for (int32 count = 0; count<block*channels; count++){
							*tmp++ = *mem++;
						}
					}	break;
					case 0x4:	// 0 == mid, 0x80000001 == bottom, 0x7fffffff == top (all >16-bit formats, left-adjusted)
					{	int32 *tmp = (int32*)buffer;
						for (int32 count = 0; count<block*channels; count++){
							t = *mem++;
							*tmp++ = ROUND(t*0x7fffffff);
						}
					}	break;
					case 0x2:	// 0 == mid, -32767 == bottom, +32767 == top
					{	int16 *tmp = (int16*)buffer;
						for (int32 count = 0; count<block*channels; count++){
							t = *mem++;
							*tmp++ = ROUND(t*32767.0);
						}
					}	break;
					case 0x11:	// 128 == mid, 1 == bottom, 255 == top (discouraged but supported format)
					{	uint8 *tmp = (uint8*)buffer;
						for (int32 count = 0; count<block*channels; count++){
							t = *mem++;
							*tmp = ROUND(t*127.0);
							tmp++;
							*tmp = *tmp ^ 0x80;
						}
					}	break;
					case 0x1:		// 0 == mid, -127 == bottom, +127 == top (not officially supported format)
					{	int8 *tmp = (int8*)buffer;
						for (int32 count = 0; count<block*channels; count++){
							t = *mem++;
							*tmp++ = ROUND(t*127.0);		// xor 128 to invert sign bit
						}
					}	break;
					}

					Pool.ProgressUpdate( block );
					outTrack->WriteFrames(buffer, block);
					#ifdef __VM_SYSTEM	//RAM
					VM.ReadBlock(convert_buffer, block*channels );
					mem = convert_buffer;
					#endif
				}

				#ifdef __VM_SYSTEM	//RAM
				free(convert_buffer);
				}
				#endif
				
				Pool.changed = false;

				outTrack->Flush();

				BMimeType result;
				BEntry ent(&dir,name);
				entry_ref fref;
				ent.GetRef(&fref);
				BMimeType::GuessMimeType(&fref,&result);
				BNodeInfo ninfo(&newFile); 
				ninfo.SetType(result.Type()); 

			}else{
				(new BAlert(NULL, Language.get("CODEC_FORMAT_ERROR"), Language.get("OK")))->Go();
			}

			file.CloseFile();
			
			free(buffer);
			Pool.HideProgress();
		}
	}else{
		(new BAlert(NULL, Language.get("SAVE_ERROR"), Language.get("OK")))->Go();
	}

	if (Pool.save_mode == 2)
		PostMessage(B_QUIT_REQUESTED);
	if (Pool.save_mode == 1)
		mainWindow->PostMessage(OPEN);

	Pool.save_mode = 0;
}
Ejemplo n.º 15
0
status_t
PackageLink::WriteToPath(const char *path, ItemState *state)
{
	if (state == NULL)
		return B_ERROR;

	status_t ret = B_OK;
	BSymLink symlink;
	parser_debug("Symlink: %s WriteToPath() called!\n", fPath.String());

	BPath &destination = state->destination;
	BDirectory *dir = &state->parent;

	if (state->status == B_NO_INIT || destination.InitCheck() != B_OK
		|| dir->InitCheck() != B_OK) {
		// Not yet initialized
		ret = InitPath(path, &destination);
		if (ret != B_OK)
			return ret;

		BString linkName(destination.Leaf());
		parser_debug("%s:%s:%s\n", fPath.String(), destination.Path(),
			linkName.String());

		BPath dirPath;
		ret = destination.GetParent(&dirPath);
		ret = dir->SetTo(dirPath.Path());

		if (ret == B_ENTRY_NOT_FOUND) {
			ret = create_directory(dirPath.Path(), kDefaultMode);
			if (ret != B_OK) {
				parser_debug("create_directory()) failed\n");
				return B_ERROR;
			}
		}
		if (ret != B_OK) {
			parser_debug("destination InitCheck failed %s for %s\n",
				strerror(ret), dirPath.Path());
			return ret;
		}

		ret = dir->CreateSymLink(destination.Path(), fLink.String(), &symlink);
		if (ret == B_FILE_EXISTS) {
			// We need to check if the existing symlink is pointing at the same path
			// as our new one - if not, let's prompt the user
			symlink.SetTo(destination.Path());
			BPath oldLink;

			ret = symlink.MakeLinkedPath(dir, &oldLink);
			chdir(dirPath.Path());

			if (ret == B_BAD_VALUE || oldLink != fLink.String())
				state->status = ret = B_FILE_EXISTS;
			else
				ret = B_OK;
		}
	}

	if (state->status == B_FILE_EXISTS) {
		switch (state->policy) {
			case P_EXISTS_OVERWRITE:
			{
				BEntry entry;
				ret = entry.SetTo(destination.Path());
				if (ret != B_OK)
					return ret;

				entry.Remove();
				ret = dir->CreateSymLink(destination.Path(), fLink.String(),
					&symlink);
				break;
			}

			case P_EXISTS_NONE:
			case P_EXISTS_ASK:
				ret = B_FILE_EXISTS;
				break;

			case P_EXISTS_SKIP:
				return B_OK;
		}
	}

	if (ret != B_OK) {
		parser_debug("CreateSymLink failed\n");
		return ret;
	}

	parser_debug(" Symlink created!\n");

	ret = symlink.SetPermissions(static_cast<mode_t>(fMode));

	if (fCreationTime && ret == B_OK)
		ret = symlink.SetCreationTime(static_cast<time_t>(fCreationTime));

	if (fModificationTime && ret == B_OK) {
		ret = symlink.SetModificationTime(static_cast<time_t>(
			fModificationTime));
	}

	if (ret != B_OK) {
		parser_debug("Failed to set symlink attributes\n");
		return ret;
	}

	if (fOffset) {
		// Symlinks also seem to have attributes - so parse them
		ret = HandleAttributes(&destination, &symlink, "LnDa");
	}

	return ret;
}
Ejemplo n.º 16
0
void
NamesView::MouseMoved (BPoint myPoint, uint32 transitcode, const BMessage *dragMessage)
{
 if ((dragMessage != NULL) && (dragMessage->HasRef("refs")))
 {
	 // make sure the ref isn't a dir
	 entry_ref ref;
	 dragMessage->FindRef("refs", &ref);
	 BDirectory dir (&ref);
	 if (dir.InitCheck() != B_OK)
	 {
		 int32 nameIndex (IndexOf(myPoint));
		 if (nameIndex >= 0)
			 Select(nameIndex);
	 }
 }
 else if (fTracking)
 {
	 if (transitcode == B_INSIDE_VIEW)
	 {
		 BListItem *item = ItemAt (IndexOf(myPoint));
		 if (item)
		 {
			 BListItem *lastitem (NULL);
			 int32 first (CurrentSelection (0));
			 int32 last (first);
			 int32 i (1);
			 while ((last = CurrentSelection(i++)) != -1)
				 lastitem = ItemAt(last);
			 if (lastitem)
				 last = IndexOf(lastitem);
			 else
				 last = first;
			 int32 current (IndexOf (myPoint));

			 if (current >= 0)
			 {
				 if (current < first)
				 {
					 // sweep up
					 Select (current, last, true);
				 }
				 else if (current > last)
				 {
					 // sweep down
					 Select (first, current, true);
				 }
				 else if (fCurrentindex > current)
				 {
					 // backtrack up
					 DeselectExcept (first, current);
				 }
				 else if (fCurrentindex < current)
				 {
					 // backtrack down
					 DeselectExcept (current, last);
				 }
				 fCurrentindex = current;
			 }
		 }
	 }
 }
 else
	 BListView::MouseMoved (myPoint, transitcode, dragMessage);
}
Ejemplo n.º 17
0
void
PersonWindow::MessageReceived(BMessage* msg)
{
	msg->PrintToStream();
	char			str[256];
	BDirectory		directory;
	BEntry			entry;
	BFile			file;
//	BNodeInfo		*node;

	switch (msg->what) {
		case M_SAVE:
			if (!fRef) {
				SaveAs();
				break;
			}
			// supposed to fall through
		case M_REVERT:
		case M_SELECT:
			fView->MessageReceived(msg);
			break;

		case M_SAVE_AS:
			int32 format;
			if (msg->FindInt32("format", &format) == B_OK)
				SaveAs(format);
			break;

		case M_ADD_FIELD:
		case M_SHOW_LOCATIONS:
		case M_SHOW_GROUPS:
			fView->MessageReceived(msg);
			break;
		case B_UNDO: // fall through
		case B_CUT:
		case B_COPY:
		case B_PASTE:
		{
			BView* view = CurrentFocus();
			if (view != NULL)
				view->MessageReceived(msg);
			break;
		}

		case B_SAVE_REQUESTED:
		{
			entry_ref dir;
			if (msg->FindRef("directory", &dir) == B_OK) {
				const char* name = NULL;
				msg->FindString("name", &name);
				directory.SetTo(&dir);
				if (directory.InitCheck() == B_NO_ERROR) {
					directory.CreateFile(name, &file);
					if (file.InitCheck() == B_NO_ERROR) {
						int32 format;
						if (msg->FindInt32("format", &format) == B_OK) {
							directory.FindEntry(name, &entry);
							entry.GetRef(&dir);
							_SetToRef(new entry_ref(dir));
							SetTitle(fRef->name);
							fView->CreateFile(fRef, format);
						}
					}
					else {
						sprintf(str, B_TRANSLATE("Could not create %s."), name);
						(new BAlert("", str, B_TRANSLATE("Sorry")))->Go();
					}
				}
			}
			break;
		}

		case B_CONTACT_REMOVED:
			// We lost our file. Close the window.
			PostMessage(B_QUIT_REQUESTED);
			break;
		
		case B_CONTACT_MOVED:
		{
			// We may have renamed our entry. Obtain relevant data
			// from message.
			BString name;
			msg->FindString("name", &name);

			int64 directory;
			msg->FindInt64("to directory", &directory);

			int32 device;
			msg->FindInt32("device", &device);

			// Update our file
			fRef = new entry_ref(device,
				directory, name.String());
			fWatcher->SetRef(fRef);
			fView->Reload(fRef);

			// And our window title.
			SetTitle(name);

			// If moved to Trash, close window.
			BVolume volume(device);
			BPath trash;
			find_directory(B_TRASH_DIRECTORY, &trash, false,
				&volume);
			BPath folder(fRef);
			folder.GetParent(&folder);
			if (folder == trash)
				be_app->PostMessage(B_QUIT_REQUESTED);	
			break;
		}
		
		case B_CONTACT_MODIFIED:
		{
			fView->Reload();
			break;
		}

		default:
			BWindow::MessageReceived(msg);
	}
}
Ejemplo n.º 18
0
void
NamesView::MessageReceived (BMessage *msg)
{
	switch (msg->what)
	{
		case M_THEME_FOREGROUND_CHANGE:
		{
			int16 which (msg->FindInt16 ("which"));
			bool refresh (false);
			switch (which)
			{
				case C_NAMES_BACKGROUND:
					fActiveTheme->ReadLock();
					SetViewColor (fActiveTheme->ForegroundAt (C_NAMES_BACKGROUND));
					refresh = true;
					fActiveTheme->ReadUnlock();
					break;

				case C_OP:
				case C_VOICE:
				case C_HELPER:
				case C_NAMES_SELECTION:
					refresh = true;
					break;

				default:
					break;
			}
			if (refresh)
				Invalidate();
		}
		break;

		case M_THEME_FONT_CHANGE:
		{
			int16 which (msg->FindInt16 ("which"));
			if (which == F_NAMES)
			{
				fActiveTheme->ReadLock();
				BFont newFont (fActiveTheme->FontAt (F_NAMES));
				fActiveTheme->ReadUnlock();
				SetFont (&newFont);
				for (int32 i = 0; i < CountItems(); i++)
					ItemAt(i)->Update(this, &newFont);
				Invalidate();
			}
		}
		break;

		case B_SIMPLE_DATA:
		{
			if (msg->HasRef("refs"))
			{
				// this only grabs the first ref for now
				// TODO: maybe implement queueing of multiple sends next time
				entry_ref ref;
				msg->FindRef("refs", &ref);
				BDirectory dir (&ref);
				// don't try to dcc send a dir
				if (dir.InitCheck() == B_OK)
					break;
				int32 idx (CurrentSelection());
				if (idx >= 0)
				{
					NameItem *item (dynamic_cast<NameItem *>(ItemAt(idx)));
					BMessage message (M_CHOSE_FILE);
					message.AddString ("nick", item->Name());
					message.AddRef ("refs", &ref);
					ClientAgent *myParent (dynamic_cast<ClientAgent *>(Parent()->Parent()));
					if (myParent)
						myParent->fSMsgr.SendMessage (&message);
				}
			}
		}
		break;

		default:
		{
			BListView::MessageReceived (msg);
		}
		break;
	}
}
Ejemplo n.º 19
0
void
TStatusWindow::MessageReceived(BMessage* msg)
{
	switch (msg->what) {
		case STATUS:
			break;

		case OK:
		{
			if (!_Exists(fStatus->Text())) {
				int32 index = 0;
				uint32 loop;
				status_t result;
				BDirectory dir;
				BEntry entry;
				BFile file;
				BNodeInfo* node;
				BPath path;

				find_directory(B_USER_SETTINGS_DIRECTORY, &path, true);
				dir.SetTo(path.Path());
				if (dir.FindEntry("Mail", &entry) == B_NO_ERROR)
					dir.SetTo(&entry);
				else
					dir.CreateDirectory("Mail", &dir);
				if (dir.InitCheck() != B_NO_ERROR)
					goto err_exit;
				if (dir.FindEntry("status", &entry) == B_NO_ERROR)
					dir.SetTo(&entry);
				else
					dir.CreateDirectory("status", &dir);
				if (dir.InitCheck() == B_NO_ERROR) {
					char name[B_FILE_NAME_LENGTH];
					char newName[B_FILE_NAME_LENGTH];

					sprintf(name, "%s", fStatus->Text());
					if (strlen(name) > B_FILE_NAME_LENGTH - 10)
						name[B_FILE_NAME_LENGTH - 10] = 0;
					for (loop = 0; loop < strlen(name); loop++) {
						if (name[loop] == '/')
							name[loop] = '\\';
					}
					strcpy(newName, name);
					while (1) {
						if ((result = dir.CreateFile(newName, &file, true)) == B_NO_ERROR)
							break;
						if (result != EEXIST)
							goto err_exit;
						sprintf(newName, "%s_%" B_PRId32, name, index++);
					}
					dir.FindEntry(newName, &entry);
					node = new BNodeInfo(&file);
					node->SetType("text/plain");
					delete node;
					file.Write(fStatus->Text(), strlen(fStatus->Text()) + 1);
					file.SetSize(file.Position());
					file.WriteAttr(INDEX_STATUS, B_STRING_TYPE, 0, fStatus->Text(),
						strlen(fStatus->Text()) + 1);
				}
			}
		err_exit:
			{
				BMessage close(M_CLOSE_CUSTOM);
				close.AddString("status", fStatus->Text());
				fTarget.SendMessage(&close);
				// will fall through
			}
		}
		case CANCEL:
			Quit();
			break;
	}
}
Ejemplo n.º 20
0
void
PersonWindow::MessageReceived(BMessage* msg)
{
	char			str[256];
	BDirectory		directory;
	BEntry			entry;
	BFile			file;
	BNodeInfo		*node;

	switch (msg->what) {
		case M_SAVE:
			if (!fRef) {
				SaveAs();
				break;
			}
			// supposed to fall through
		case M_REVERT:
		case M_SELECT:
			fView->MessageReceived(msg);
			break;

		case M_SAVE_AS:
			SaveAs();
			break;

		case B_UNDO: // fall through
		case B_CUT:
		case B_COPY:
		case B_PASTE:
		{
			BView* view = CurrentFocus();
			if (view != NULL)
				view->MessageReceived(msg);
			break;
		}

		case B_SAVE_REQUESTED:
		{
			entry_ref dir;
			if (msg->FindRef("directory", &dir) == B_OK) {
				const char* name = NULL;
				msg->FindString("name", &name);
				directory.SetTo(&dir);
				if (directory.InitCheck() == B_NO_ERROR) {
					directory.CreateFile(name, &file);
					if (file.InitCheck() == B_NO_ERROR) {
						node = new BNodeInfo(&file);
						node->SetType("application/x-person");
						delete node;

						directory.FindEntry(name, &entry);
						entry.GetRef(&dir);
						_SetToRef(new entry_ref(dir));
						SetTitle(fRef->name);
						fView->CreateFile(fRef);
					}
					else {
						sprintf(str, B_TRANSLATE("Could not create %s."), name);
						BAlert* alert = new BAlert("", str, B_TRANSLATE("Sorry"));
						alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
						alert->Go();
					}
				}
			}
			break;
		}

		case B_NODE_MONITOR:
		{
			int32 opcode;
			if (msg->FindInt32("opcode", &opcode) == B_OK) {
				switch (opcode) {
					case B_ENTRY_REMOVED:
						// We lost our file. Close the window.
						PostMessage(B_QUIT_REQUESTED);
						break;

					case B_ENTRY_MOVED:
					{
						// We may have renamed our entry. Obtain relevant data
						// from message.
						BString name;
						msg->FindString("name", &name);

						int64 directory;
						msg->FindInt64("to directory", &directory);

						int32 device;
						msg->FindInt32("device", &device);

						// Update our ref.
						delete fRef;
						fRef = new entry_ref(device, directory, name.String());

						// And our window title.
						SetTitle(name);

						// If moved to Trash, close window.
						BVolume volume(device);
						BPath trash;
						find_directory(B_TRASH_DIRECTORY, &trash, false,
							&volume);
						BPath folder(fRef);
						folder.GetParent(&folder);
						if (folder == trash)
							PostMessage(B_QUIT_REQUESTED);

						break;
					}

					case B_ATTR_CHANGED:
					{
						// An attribute was updated.
						BString attr;
						if (msg->FindString("attr", &attr) == B_OK)
							fView->SetAttribute(attr.String(), true);
						break;
					}
					case B_STAT_CHANGED:
						fView->UpdatePicture(fRef);
						break;
				}
			}
			break;
		}

		default:
			BWindow::MessageReceived(msg);
	}
}
Ejemplo n.º 21
0
void PictureViewer::HandleCopyTarget(BMessage *e) {
  entry_ref targetRef;
   
  BBitmap *toSend;
  if (clipping == true) toSend = GetClipping();
                   else toSend = thePic;
  


  // memory or file transfer ?
  if (e->FindRef("directory",&targetRef) == B_OK)  {

      BDirectory *targetDir = new BDirectory( &targetRef );
      if (targetDir->InitCheck() == B_OK) {
         BFile *targetFile = new BFile(targetDir,e->FindString("name"),B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
         if (targetFile->InitCheck() == B_OK) {

          BBitmap *dragImage = NULL;
          BBitmapStream *strm;
          strm = new BBitmapStream(toSend);

          translator_id trans_id;
          uint32 type;

          GetTranslatorInfo(e->FindString("be:filetypes"),&trans_id,&type);
          BTranslatorRoster::Default()->Translate(trans_id,strm,NULL,targetFile,type);
          BNodeInfo *ni = new BNodeInfo(targetFile);
          ni->SetType(e->FindString("be:filetypes"));
          if (dragImage == NULL) strm->DetachBitmap(&toSend);
           else {
            strm->DetachBitmap(&dragImage);
            delete dragImage;
           }
          delete ni;
          delete strm;
         } 
        delete targetFile;
       }   
     delete targetDir;
     return;
   } 
   
  else {
     BMallocIO *data = new BMallocIO;
     BBitmapStream *imageSrc;
     imageSrc = new BBitmapStream(toSend);

     BMessage *package = new BMessage(B_MIME_DATA);
     translator_id trans_id;
     uint32 type;

     GetTranslatorInfo(e->FindString("be:types"),&trans_id,&type);
     if (BTranslatorRoster::Default()->Translate( trans_id, imageSrc, NULL, data, type ) != B_OK) return;
     package->AddData( e->FindString("be:types"),  B_MIME_DATA, data->Buffer(), data->BufferLength());
     e->SendReply(package);        

     imageSrc->DetachBitmap(&toSend);

     delete data;
     delete imageSrc;
     delete package;
  } 

 if (clipping) delete toSend;

}
Ejemplo n.º 22
0
void
NetworkSetupWindow::_BuildShowTabView(int32 msg_what)
{
    BPath path;
    BPath addon_path;
    BDirectory dir;
    BEntry entry;

    char* search_paths = getenv("ADDON_PATH");
    if (!search_paths)
        return;

    float minimumWidth = be_control_look->DefaultItemSpacing() * 37;
    float minimumHight = be_control_look->DefaultItemSpacing() * 25;

    fMinAddonViewRect.Set(0, 0, minimumWidth, minimumHight);
    // Minimum size

    search_paths = strdup(search_paths);
    char* next_path_token;
    char* search_path = strtok_r(search_paths, ":", &next_path_token);

    while (search_path) {
        if (strncmp(search_path, "%A/", 3) == 0) {
            app_info ai;
            be_app->GetAppInfo(&ai);
            entry.SetTo(&ai.ref);
            entry.GetPath(&path);
            path.GetParent(&path);
            path.Append(search_path + 3);
        } else {
            path.SetTo(search_path);
            path.Append("Network Setup");
        }

        search_path = strtok_r(NULL, ":", &next_path_token);

        dir.SetTo(path.Path());
        if (dir.InitCheck() != B_OK)
            continue;

        dir.Rewind();
        while (dir.GetNextEntry(&entry) >= 0) {
            if (entry.IsDirectory())
                continue;

            entry.GetPath(&addon_path);
            image_id addon_id = load_add_on(addon_path.Path());
            if (addon_id < 0) {
                printf("Failed to load %s addon: %s.\n", addon_path.Path(),
                       strerror(addon_id));
                continue;
            }

            network_setup_addon_instantiate get_nth_addon;
            status_t status = get_image_symbol(addon_id, "get_nth_addon",
                                               B_SYMBOL_TYPE_TEXT, (void **) &get_nth_addon);

            int tabCount = 0;

            if (status != B_OK) {
                //  No "addon instantiate function" symbol found in this addon
                printf("No symbol \"get_nth_addon\" found in %s addon: not a "
                       "network setup addon!\n", addon_path.Path());
                unload_add_on(addon_id);
                continue;
            }

            while ((fNetworkAddOnMap[fAddonCount]
                    = get_nth_addon(addon_id, tabCount)) != NULL) {
                printf("Adding Tab: %d\n", fAddonCount);
                BMessage* msg = new BMessage(msg_what);

                BRect r(0, 0, 0, 0);
                BView* addon_view
                    = fNetworkAddOnMap[fAddonCount]->CreateView(&r);
                fMinAddonViewRect = fMinAddonViewRect | r;

                msg->AddInt32("image_id", addon_id);
                msg->AddString("addon_path", addon_path.Path());
                msg->AddPointer("addon", fNetworkAddOnMap[fAddonCount]);
                msg->AddPointer("addon_view", addon_view);

                BTab* tab = new BTab;
                fPanel->AddTab(addon_view, tab);
                tab->SetLabel(fNetworkAddOnMap[fAddonCount]->Name());
                fAddonCount++;
                // Number of tab addons total
                tabCount++;
                // Tabs for *this* addon
            }
        }
    }

    free(search_paths);
}
Ejemplo n.º 23
0
TagsWindow :: TagsWindow(BMessage *fSaveMessage, BHandler *handler)
		   : BWindow (BRect(300,300,700,550),"Set Tags for this note",B_TITLED_WINDOW, B_NOT_RESIZABLE){
		   
	//Variables
	fMessenger = new BMessenger(handler);
	
	BDirectory		dir;
	entry_ref		ref;
	status_t		err;
	const char		*name;
		
	BView			*fTagsView;
	char			bufferTag1[30];
	char			bufferTag2[30];
	char			bufferTag3[30];
									
	// Create the main view	
	fTagsView = new BView(Bounds(), "TagsView", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS);
		 		
	// Create the Text Field 
	fTag1 = new BTextControl(BRect(20,40,200,55), "tag1", "First Tag: ", NULL, NULL);
	fTag2 = new BTextControl(BRect(20,70,200,85), "tag2", "Second Tag: ", NULL, NULL);
	fTag3 = new BTextControl(BRect(20,100,200,135), "tag3", "Third Tag: ", NULL, NULL);

	//Create the OK and UNDO button	
	fDoneButton = new BButton(BRect(340,200,390,210), "ok", "OK", new BMessage(BUTTON_OK));
	fUndoButton = new BButton(BRect(270,200,320,210), "undo", "Undo", new BMessage(BUTTON_UNDO));
		
	/*
	* Add the view as window's child, set back ground color, 
	* then add the tag TextControl as children
	*/
	fTagsView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
		
	AddChild(fTagsView);
	fTagsView->AddChild(fTag1);
	fTagsView->AddChild(fTag2);
	fTagsView->AddChild(fTag3);
	
	// Add OK and UNDO button as children
	fTagsView->AddChild(fDoneButton);
	fTagsView->AddChild(fUndoButton);
			
	// Open the file from FS starting from the fSaveMessage message
	if (fSaveMessage->FindRef("directory",&ref) == B_OK && fSaveMessage->FindString("name", &name) == B_OK){
			
		dir.SetTo(&ref);
		if ((err = dir.InitCheck()) != B_OK){
			BAlert *myalert = new BAlert("ERR","errore di inizializzazione del file","OK");
			myalert->Go();
			exit(-1);	
			
		}
		fFile.SetTo(&dir, name, B_READ_WRITE);
	}
		
	printf("$$$$TAGONE$$$$: %s\n", bufferTag1);
		
	// Read the old values for this file
	fFile.ReadAttr("TAKENOTES:tagone", B_STRING_TYPE, 0, &bufferTag1, 30);
	fFile.ReadAttr("TAKENOTES:tagtwo", B_STRING_TYPE, 0, &bufferTag2, 30);
	fFile.ReadAttr("TAKENOTES:tagthree", B_STRING_TYPE, 0, &bufferTag3, 30);
			
	// Initialize text field to old values
	fTag1->SetText(bufferTag1);
	fTag2->SetText(bufferTag2);
	fTag3->SetText(bufferTag3);		

}
Ejemplo n.º 24
0
/*!	\brief		Opens the file with preferences packed into BMessage for reading.
 *		\param[out]		out		Link to the BFile used to read the preferences from.
 *		\param[in]		openMode	Defines how the file should be opened. Read / write...
 *		\returns		B_OK in case of success.
 *		\note			
 *						Whatever was in the "out" variable, will be overwritten.
 */
status_t			OpenFileWithPreferences( BFile* out, uint32 openMode )
{
	status_t 	status = B_OK;
	BPath path;
	BString sb;
	BDirectory eventualSettingsDir;
	
	//	Access the overall settings directory
	status = find_directory( B_USER_SETTINGS_DIRECTORY,
							 		 &path,
							 		 true );	// Create directory if necessary
	if ( status != B_OK )
	{
		return status;
	}
	
	// Descent to application's settings directory
	path.Append( "Eventual" );
	eventualSettingsDir.SetTo( path.Path() );
	status = eventualSettingsDir.InitCheck();
	switch ( status )
	{
		case B_ENTRY_NOT_FOUND:
			// The directory does not exist. Create it!
			status = eventualSettingsDir.CreateDirectory( path.Path(),
																	    &eventualSettingsDir );
			if ( status != B_OK )
			{
				/* Panic! */
				sb.SetTo( "Error in creating Eventual Settings directory! Error = " );
				sb << ( uint32 )status;
				utl_Deb = new DebuggerPrintout( sb.String() );
				return status;
			}
			
			/* I assume at this point the directory is set. */
			break;
		
		case B_NAME_TOO_LONG:	/* Intentional fall-through */
		case B_BAD_VALUE:
		case B_FILE_ERROR:
		case B_NO_MORE_FDS:
			utl_Deb = new DebuggerPrintout( "Name is too long, input is invalid or node is busy." );
			return status;
			break;
			
		case B_LINK_LIMIT:
			utl_Deb = new DebuggerPrintout( "Loop is detected in the filesystem!" );
			return status;
			break;
			
		case B_BUSY:
			utl_Deb = new DebuggerPrintout( "The directory does not exist!" );
			return status;
			break;
		
		case B_OK:				/* Everything went smooth */
			break;
			
		default:
			utl_Deb = new DebuggerPrintout( "Unknown error has occurred." );
			break;
	};
	
	/* Anyway, at this point the directory is set, or we have exitted. */
	
	// Descend into preferences file.
	path.Append( "Preferences" );
	out->SetTo( path.Path(),
				   openMode );
							   
	if ( ( status = out->InitCheck() ) != B_OK )
	{
		/* Panic! */
		return status;
	}
	
	return B_OK;
	
}	// <-- end of function OpenFileWithPreferences
Ejemplo n.º 25
0
void
NetworkSetupWindow::_BuildShowMenu(BMenu* menu, int32 msg_what)
{
	menu->SetRadioMode(true);		
	BPath path;
	BPath addon_path;
	BDirectory dir;
	BEntry entry;

	char* search_paths = getenv("ADDON_PATH");
	if (!search_paths)
		return;

	fMinAddonViewRect.Set(0, 0, 200, 200);	// Minimum size
		
	search_paths = strdup(search_paths);	
	char* next_path_token;
	char* search_path = strtok_r(search_paths, ":", &next_path_token);
	
	while (search_path) {
		if (strncmp(search_path, "%A/", 3) == 0) {
			app_info ai;			
			be_app->GetAppInfo(&ai);
			entry.SetTo(&ai.ref);
			entry.GetPath(&path);
			path.GetParent(&path);
			path.Append(search_path + 3);
		} else {
			path.SetTo(search_path);
			path.Append("network_setup");
		}

		search_path = strtok_r(NULL, ":", &next_path_token);
		
		dir.SetTo(path.Path());
		if (dir.InitCheck() != B_OK)
			continue;
		
		dir.Rewind();
		while (dir.GetNextEntry(&entry) >= 0) {
			if (entry.IsDirectory())
				continue;

			entry.GetPath(&addon_path);
			image_id addon_id = load_add_on(addon_path.Path());
			if (addon_id < 0) {
				printf("Failed to load %s addon: %s.\n", addon_path.Path(), 
					strerror(addon_id));
				continue;
			}

			network_setup_addon_instantiate get_nth_addon;
			status_t status = get_image_symbol(addon_id, "get_nth_addon", 
				B_SYMBOL_TYPE_TEXT, (void **) &get_nth_addon);
				
			if (status == B_OK) {
				NetworkSetupAddOn *addon;
				int n = 0;
				while ((addon = get_nth_addon(addon_id, n)) != NULL) {
					BMessage* msg = new BMessage(msg_what);
					
					BRect r(0, 0, 0, 0);
					BView* addon_view = addon->CreateView(&r);
					fMinAddonViewRect = fMinAddonViewRect | r;
					
					msg->AddInt32("image_id", addon_id);
					msg->AddString("addon_path", addon_path.Path());
					msg->AddPointer("addon", addon);
					msg->AddPointer("addon_view", addon_view);
					menu->AddItem(new BMenuItem(addon->Name(), msg));
					n++;
				}
				continue;
			}

			//  No "addon instantiate function" symbol found in this addon
			printf("No symbol \"get_nth_addon\" found in %s addon: not a "
				"network setup addon!\n", addon_path.Path());
			unload_add_on(addon_id);
		}
	}

	free(search_paths);
}	
Ejemplo n.º 26
0
void MainView::MessageReceived(BMessage* message)
{
	switch(message->what)
	{
		case RegisterViewSelectedMSG:
		{
			Tra* t = curAvs->rv->GetSelectedTra();
			curAvs->cv->UpdateTra(t);
		}
		break;
		case CheckPopNumMSG:
		case CheckPopDateMSG:
		case CheckPopPyeMSG:
		case CheckPopPaymentMSG:
		case CheckPopDepositMSG:
		case CheckPopCatMSG:
		case ClearSplitMSG:
		case CheckPopTransferMSG:
		case ClearTransferMSG:
		case CheckPyeTextModMSG:
		case CheckCatTextModMSG:
		case CheckNumTextModMSG:
		case CheckDatTextModMSG:
			curAvs->cv->MessageReceived(message);
		break;
		case CheckEnterPressMSG:
		{
			Tra* newT = GetNewTra(curAcc);
			if (newT)
			{
				Tra* currentT = curAvs->rv->GetSelectedTra();
				if (currentT)
					theProxy->EditTra(curAcc, currentT, newT);
				else
					theProxy->AddTra(curAcc, newT);
				curAvs->rv->DeselectAll();
				curAvs->cv->UpdateTra(0);
			}
		}
		break;
		case CheckNewPressMSG:
		{
			Tra* newT = GetNewTra(curAcc);
			if (newT)
			{
				BAlert* alert = new BAlert("Save Changes?", 
					"Save Changes to Transaction?", "Don't Save", "Save");
				uint8 bi = alert->Go();
				if (bi == 1)
				{
					Tra* currentT = curAvs->rv->GetSelectedTra();
					if (currentT)
						theProxy->EditTra(curAcc, currentT, newT);
					else
						theProxy->AddTra(curAcc, newT);
				}
			}
			curAvs->rv->DeselectAll();
			curAvs->cv->UpdateTra(0);
		}
		break;
		case CheckSplitPressMSG:
		{
			pair<uint32, uint8> p = curAvs->cv->GetAmount();
			if (p.second != 3)
			{
				SplitWindow* sw = new SplitWindow(BRect(200, 200, 500, 330),
					theProxy, this, theProxy->GetPrefs(), p.first, p.second, curAvs->cv->GetSplCat());
				sw->Show();
			}
		}
		break;
		case CheckDeletePressMSG:
		{
			Tra* currentT = curAvs->rv->GetSelectedTra();
			theProxy->DeleteTra(curAcc, currentT);
		}
		break;
		case SplitMSG:
		{
			Cat* sc;
			bool pam;
			int32 amt;
			message->FindPointer("cat", (void**)&sc);
			message->FindBool("pam", &pam);
			message->FindInt32("amt", &amt);
			if (sc->spl)
				curAvs->cv->SetSplCat((SplCat*)sc, pam);
			else
				curAvs->cv->SetCat(sc, pam, amt);
		}
		break;
		case AccSelectedMSG:
		{
			Acc* acc = alv->GetSelectedAcc();
			if (!acc)
				break;
			AccViewSet* avs = AccVws[acc];
			if (curAvs)
			{
				curAvs->cv->Hide();
				curAvs->rv->Hide();
				if (!curAvs->pg->IsHidden())
					curAvs->pg->Hide();
				curAvs->lg->Hide();
				if (!curAvs->rcv->IsHidden())
					curAvs->rcv->Hide();
			}
			if (avs->cv->IsHidden())
				avs->cv->Show();
			avs->cv->MakeEnterDefault();
			if (avs->rv->IsHidden())
				avs->rv->Show();
			if (!avs->recon && avs->pg->IsHidden())
				avs->pg->Show();
			if (avs->lg->IsHidden())
				avs->lg->Show();
			if (avs->recon && avs->rcv->IsHidden())
				avs->rcv->Show();
			curAvs = avs;
			curAcc = acc;
			reconB->SetEnabled(!curAvs->recon);
			BMessenger msngr(Window());
			BMessage msg;
			if (curAvs->recon)
				msg.what = CannotRecMSG;
			else
				msg.what = CanRecMSG;
			msngr.SendMessage(&msg);
		}
		break;
		case ReconcileMSG:
		{
			curAvs->rcv->Show();
			curAvs->pg->Hide();
			reconB->SetEnabled(false);
			BMessenger msngr(Window());
			BMessage msg(CannotRecMSG);
			msngr.SendMessage(&msg);
		 	int32 balance = theProxy->GetRecBal(curAcc);
			if (!curAvs->recon)
			{
				curAvs->rcv->SetRecBalAtStart(balance);
				curAvs->rcv->SetRecBal(balance);
				curAvs->recon = true;
			}
		}
		break;
		case RegisterViewInvokedMSG:
		{
			if (!curAvs->recon)
				break;
			Tra* t = curAvs->rv->GetSelectedTra();
			if (t->rec == 0)
			{
				t->rec = 1;
				theProxy->ReconTra(curAcc, t);
				curAvs->rv->EditTra();
			}
			else if (t->rec == 1)
			{
				t->rec = 0;
				theProxy->ReconTra(curAcc, t);
				curAvs->rv->EditTra();
			}
			else if (t->rec == 2)
			{
				BAlert* alert = new BAlert("Reconciliation Error",
					"Change status of Confirmed Transaction?",
					"Yes", "No");
				if (alert->Go() == 0)
				{
					t->rec = 0;
					theProxy->ReconTra(curAcc, t);
					curAvs->rv->EditTra();
				}
			}
		}
		break;
		case ReconcileCancelMSG:
		{
			curAvs->rcv->Hide();
			curAvs->pg->Show();
			reconB->SetEnabled(true);
			BMessenger msngr(Window());
			BMessage msg(CanRecMSG);
			msngr.SendMessage(&msg);
		}
		break;
		case ReconcileFinishMSG:
		{
			theProxy->ReconFinish(curAcc);
			curAvs->rv->InvalidateLV();
			curAvs->rcv->Hide();
			curAvs->pg->Show();
			reconB->SetEnabled(true);
			curAvs->recon = false;
			BMessenger msngr(Window());
			BMessage msg(CanRecMSG);
			msngr.SendMessage(&msg);
		}
		break;
		case ReconcileModifiedMSG:
			curAvs->rcv->RedoBals();
		break;
		case ImportMSG:
		{
			entry_ref er;
			if (message->FindRef("refs", &er) != B_OK)
				break;
			BEntry entry(&er);
			if (!entry.Exists())
			{
				BAlert* alert = new BAlert("Open Warning",
					"File Does Not Exist", "OK");
				alert->Go();
				break;
			}
			BNode n(&entry);
			BNodeInfo ni(&n);
			char* type = new char[B_MIME_TYPE_LENGTH];
			ni.GetType(type);
			if (!strcmp(type, "account/x-TMS-BMC"))
				theProxy->BMCImport(curAcc, &entry);
			else
				try
				{
					Window()->Lock();
					theProxy->Import(curAcc, &entry);
					Window()->Unlock();
				}
				catch (invalid_argument)
				{
					BAlert* alert = new BAlert("Import Warning",
						"File Could not be Imported", "OK");
					alert->Go();
				}
			delete[] type;
		}
		break;
		case ExportMSG:
		{
			BDirectory directory;
			BFile file;
			BEntry entry;
			entry_ref dir;
			const char* name;
			if (message->FindRef("directory", &dir) != B_OK)
				break;
			if (message->FindString("name", &name) != B_OK)
				break;
			directory.SetTo(&dir);
			if (directory.InitCheck() == B_NO_ERROR)
			{
				directory.CreateFile(name, &file);
				if (file.InitCheck() == B_NO_ERROR)
				{
					directory.FindEntry(name, &entry);
					theProxy->Export(curAcc, &entry);
				}
			}
		}
		break;
		case AccSetMSG:
		case SettingsMSG:
		{
			AccSettingsWindow* asw = new AccSettingsWindow(curAcc, this, theProxy->GetPrefs());
			asw->Show();
		}
		break;
		case ManPyeMSG:
		{
			if (!pmw)
				pmw = new PyeManagerWindow(this, theProxy);
			pmw->Show();
		}
		break;
		case ManCatMSG:
		{
			if (!cmw)
				cmw = new CatManagerWindow(this, theProxy);
			cmw->Show();
		}
		break;
		case PyeManagerWindowExitMSG:
			pmw = 0;
		break;
		case CatManagerWindowExitMSG:
			cmw = 0;
		break;
		case PieZoomMSG:
		{
			if (curAvs->pieZoomed)
			{
				UnzoomPie();
				curAvs->rv->Show();
				curAvs->cv->Show();
			}
			else
			{
				if (curAvs->lineZoomed)
				{
					UnzoomLine();
				}
				else
				{
					curAvs->rv->Hide();
					curAvs->cv->Hide();
				}
				ZoomPie();
			}
		}
		break;
		case LineZoomMSG:
		{
			if (curAvs->lineZoomed)
			{
				UnzoomLine();
				curAvs->rv->Show();
				curAvs->cv->Show();
			}
			else
			{
				if (curAvs->pieZoomed)
				{
					UnzoomPie();
				}
				else
				{
					curAvs->rv->Hide();
					curAvs->cv->Hide();
				}
				ZoomLine();
			}
		}
		break;
		case 1347638341:
			rgb_color* color;
			ssize_t st;
			message->FindData("RGBColor", 'RGBC', (const void**)&color, &st);
			SetViewColor(*color);
			Invalidate();
		break;
		default:
			BView::MessageReceived(message);
	}
}
Ejemplo n.º 27
0
void
TSignatureWindow::Save()
{
	char			name[B_FILE_NAME_LENGTH];
	int32			index = 0;
	status_t		result;
	BDirectory		dir;
	BEntry			entry;
	BNodeInfo		*node;
	BPath			path;

	if (!fFile) {
		find_directory(B_USER_SETTINGS_DIRECTORY, &path, true);
		dir.SetTo(path.Path());
		
		if (dir.FindEntry("bemail", &entry) == B_NO_ERROR)
			dir.SetTo(&entry);
		else
			dir.CreateDirectory("bemail", &dir);
			
		if (dir.InitCheck() != B_NO_ERROR)
			goto err_exit;

		if (dir.FindEntry("signatures", &entry) == B_NO_ERROR)
			dir.SetTo(&entry);
		else
			dir.CreateDirectory("signatures", &dir);
			
		if (dir.InitCheck() != B_NO_ERROR)
			goto err_exit;

		fFile = new BFile();
		while(true) {
			sprintf(name, "signature_%ld", index++);
			if ((result = dir.CreateFile(name, fFile, true)) == B_NO_ERROR)
				break;
			if (result != EEXIST)
				goto err_exit;
		}
		dir.FindEntry(name, &fEntry);
		node = new BNodeInfo(fFile);
		node->SetType("text/plain");
		delete node;
	}

	fSigView->fTextView->fDirty = false;
	fFile->Seek(0, 0);
	fFile->Write(fSigView->fTextView->Text(),
				 fSigView->fTextView->TextLength());
	fFile->SetSize(fFile->Position());
	fFile->WriteAttr(INDEX_SIGNATURE, B_STRING_TYPE, 0, fSigView->fName->Text(),
					 strlen(fSigView->fName->Text()) + 1);
	return;

err_exit:
	beep();
	(new BAlert("", MDR_DIALECT_CHOICE (
		"An error occurred trying to save this signature.",
		"署名を保存しようとした時にエラーが発生しました。"),
		MDR_DIALECT_CHOICE ("Sorry","了解")))->Go();
}
Ejemplo n.º 28
0
// MakeLinkedPathTest
void
SymLinkTest::MakeLinkedPathTest()
{
	const char *dirLink = dirLinkname;
	const char *fileLink = fileLinkname;
	const char *relDirLink = relDirLinkname;
	const char *relFileLink = relFileLinkname;
	const char *cyclicLink1 = cyclicLinkname1;
	const char *cyclicLink2 = cyclicLinkname2;
	const char *existingDir = existingDirname;
	const char *existingSuperDir = existingSuperDirname;
	const char *existingFile = existingFilename;
	const char *existingSuperFile = existingSuperFilename;
	const char *nonExisting = nonExistingDirname;
	BSymLink link;
	BPath path;
	// 1. MakeLinkedPath(const char*, BPath*)
	// uninitialized
	NextSubTest();
	CPPUNIT_ASSERT( link.InitCheck() == B_NO_INIT );
	CPPUNIT_ASSERT( equals(link.MakeLinkedPath("/boot", &path), B_BAD_ADDRESS,
						   B_FILE_ERROR) );
	link.Unset();
	path.Unset();
	// existing absolute dir link
	NextSubTest();
	CPPUNIT_ASSERT( link.SetTo(dirLink) == B_OK );
	CPPUNIT_ASSERT( link.MakeLinkedPath("/boot", &path)
					== (ssize_t)strlen(existingDir) );
	CPPUNIT_ASSERT( path.InitCheck() == B_OK );
	CPPUNIT_ASSERT( string(existingDir) == path.Path() );
	link.Unset();
	path.Unset();
	// existing absolute file link
	NextSubTest();
	CPPUNIT_ASSERT( link.SetTo(fileLink) == B_OK );
	CPPUNIT_ASSERT( link.MakeLinkedPath("/boot", &path)
					== (ssize_t)strlen(existingFile) );
	CPPUNIT_ASSERT( path.InitCheck() == B_OK );
	CPPUNIT_ASSERT( string(existingFile) == path.Path() );
	link.Unset();
	path.Unset();
	// existing absolute cyclic link
	NextSubTest();
	CPPUNIT_ASSERT( link.SetTo(cyclicLink1) == B_OK );
	CPPUNIT_ASSERT( link.MakeLinkedPath("/boot", &path)
					== (ssize_t)strlen(cyclicLink2) );
	CPPUNIT_ASSERT( path.InitCheck() == B_OK );
	CPPUNIT_ASSERT( string(cyclicLink2) == path.Path() );
	link.Unset();
	path.Unset();
	// existing relative dir link
	NextSubTest();
	BEntry entry;
	BPath entryPath;
	CPPUNIT_ASSERT( entry.SetTo(existingDir) == B_OK );
	CPPUNIT_ASSERT( entry.GetPath(&entryPath) == B_OK );
	CPPUNIT_ASSERT( link.SetTo(relDirLink) == B_OK );
	CPPUNIT_ASSERT( link.MakeLinkedPath(existingSuperDir, &path)
					== (ssize_t)strlen(entryPath.Path()) );
	CPPUNIT_ASSERT( path.InitCheck() == B_OK );
	CPPUNIT_ASSERT( entryPath == path );
	link.Unset();
	path.Unset();
	entry.Unset();
	entryPath.Unset();
	// existing relative file link
	NextSubTest();
	CPPUNIT_ASSERT( entry.SetTo(existingFile) == B_OK );
	CPPUNIT_ASSERT( entry.GetPath(&entryPath) == B_OK );
	CPPUNIT_ASSERT( link.SetTo(relFileLink) == B_OK );
	CPPUNIT_ASSERT( link.MakeLinkedPath(existingSuperFile, &path)
					== (ssize_t)strlen(entryPath.Path()) );
	CPPUNIT_ASSERT( path.InitCheck() == B_OK );
	CPPUNIT_ASSERT( entryPath == path );
	link.Unset();
	path.Unset();
	entry.Unset();
	entryPath.Unset();
	// bad args
	NextSubTest();
	CPPUNIT_ASSERT( link.SetTo(dirLink) == B_OK );
// R5: crashs, when passing a NULL path
#if !TEST_R5
	CPPUNIT_ASSERT( link.MakeLinkedPath("/boot", NULL) == B_BAD_VALUE );
#endif
	CPPUNIT_ASSERT( link.MakeLinkedPath((const char*)NULL, &path)
					== B_BAD_VALUE );
// R5: crashs, when passing a NULL path
#if !TEST_R5
	CPPUNIT_ASSERT( link.MakeLinkedPath((const char*)NULL, NULL)
					== B_BAD_VALUE );
#endif
	link.Unset();
	path.Unset();

	// 2. MakeLinkedPath(const BDirectory*, BPath*)
	// uninitialized
	NextSubTest();
	link.Unset();
	CPPUNIT_ASSERT( link.InitCheck() == B_NO_INIT );
	BDirectory dir;
	CPPUNIT_ASSERT( dir.SetTo("/boot") == B_OK);
	CPPUNIT_ASSERT( equals(link.MakeLinkedPath(&dir, &path), B_BAD_ADDRESS,
						   B_FILE_ERROR) );
	link.Unset();
	path.Unset();
	dir.Unset();
	// existing absolute dir link
	NextSubTest();
	CPPUNIT_ASSERT( link.SetTo(dirLink) == B_OK );
	CPPUNIT_ASSERT( dir.SetTo("/boot") == B_OK);
	CPPUNIT_ASSERT( link.MakeLinkedPath(&dir, &path)
					== (ssize_t)strlen(existingDir) );
	CPPUNIT_ASSERT( path.InitCheck() == B_OK );
	CPPUNIT_ASSERT( string(existingDir) == path.Path() );
	link.Unset();
	path.Unset();
	dir.Unset();
	// existing absolute file link
	NextSubTest();
	CPPUNIT_ASSERT( link.SetTo(fileLink) == B_OK );
	CPPUNIT_ASSERT( dir.SetTo("/boot") == B_OK);
	CPPUNIT_ASSERT( link.MakeLinkedPath(&dir, &path)
					== (ssize_t)strlen(existingFile) );
	CPPUNIT_ASSERT( path.InitCheck() == B_OK );
	CPPUNIT_ASSERT( string(existingFile) == path.Path() );
	link.Unset();
	path.Unset();
	dir.Unset();
	// existing absolute cyclic link
	NextSubTest();
	CPPUNIT_ASSERT( link.SetTo(cyclicLink1) == B_OK );
	CPPUNIT_ASSERT( dir.SetTo("/boot") == B_OK);
	CPPUNIT_ASSERT( link.MakeLinkedPath(&dir, &path)
					== (ssize_t)strlen(cyclicLink2) );
	CPPUNIT_ASSERT( path.InitCheck() == B_OK );
	CPPUNIT_ASSERT( string(cyclicLink2) == path.Path() );
	link.Unset();
	path.Unset();
	dir.Unset();
	// existing relative dir link
	NextSubTest();
	CPPUNIT_ASSERT( entry.SetTo(existingDir) == B_OK );
	CPPUNIT_ASSERT( entry.GetPath(&entryPath) == B_OK );
	CPPUNIT_ASSERT( link.SetTo(relDirLink) == B_OK );
	CPPUNIT_ASSERT( dir.SetTo(existingSuperDir) == B_OK);
	CPPUNIT_ASSERT( link.MakeLinkedPath(&dir, &path)
					== (ssize_t)strlen(entryPath.Path()) );
	CPPUNIT_ASSERT( path.InitCheck() == B_OK );
	CPPUNIT_ASSERT( entryPath == path );
	link.Unset();
	path.Unset();
	dir.Unset();
	entry.Unset();
	entryPath.Unset();
	// existing relative file link
	NextSubTest();
	CPPUNIT_ASSERT( entry.SetTo(existingFile) == B_OK );
	CPPUNIT_ASSERT( entry.GetPath(&entryPath) == B_OK );
	CPPUNIT_ASSERT( link.SetTo(relFileLink) == B_OK );
	CPPUNIT_ASSERT( dir.SetTo(existingSuperFile) == B_OK);
	CPPUNIT_ASSERT( link.MakeLinkedPath(&dir, &path)
					== (ssize_t)strlen(entryPath.Path()) );
	CPPUNIT_ASSERT( path.InitCheck() == B_OK );
	CPPUNIT_ASSERT( entryPath == path );
	link.Unset();
	path.Unset();
	dir.Unset();
	entry.Unset();
	entryPath.Unset();
	// absolute link, uninitialized dir
	NextSubTest();
	CPPUNIT_ASSERT( link.SetTo(dirLink) == B_OK );
	CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT);
	CPPUNIT_ASSERT( link.MakeLinkedPath(&dir, &path)
					== (ssize_t)strlen(existingDir) );
	CPPUNIT_ASSERT( path.InitCheck() == B_OK );
	CPPUNIT_ASSERT( string(existingDir) == path.Path() );
	// absolute link, badly initialized dir
	NextSubTest();
	CPPUNIT_ASSERT( link.SetTo(dirLink) == B_OK );
	CPPUNIT_ASSERT( dir.SetTo(nonExisting) == B_ENTRY_NOT_FOUND);
	CPPUNIT_ASSERT( link.MakeLinkedPath(&dir, &path)
					== (ssize_t)strlen(existingDir) );
	CPPUNIT_ASSERT( path.InitCheck() == B_OK );
	CPPUNIT_ASSERT( string(existingDir) == path.Path() );
	link.Unset();
	path.Unset();
	dir.Unset();
	// relative link, uninitialized dir
	NextSubTest();
	CPPUNIT_ASSERT( link.SetTo(relDirLink) == B_OK );
	CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT);
	CPPUNIT_ASSERT( equals(link.MakeLinkedPath(&dir, &path), B_NO_INIT,
						   B_BAD_VALUE) );
	link.Unset();
	// relative link, badly initialized dir
	NextSubTest();
	CPPUNIT_ASSERT( link.SetTo(relDirLink) == B_OK );
	CPPUNIT_ASSERT( dir.SetTo(nonExisting) == B_ENTRY_NOT_FOUND);
	CPPUNIT_ASSERT( equals(link.MakeLinkedPath(&dir, &path), B_NO_INIT,
						   B_BAD_VALUE) );
	link.Unset();
	path.Unset();
	dir.Unset();
	// bad args
	NextSubTest();
	CPPUNIT_ASSERT( link.SetTo(dirLink) == B_OK );
	CPPUNIT_ASSERT( dir.SetTo("/boot") == B_OK);
// R5: crashs, when passing a NULL path
#if !TEST_R5
	CPPUNIT_ASSERT( link.MakeLinkedPath(&dir, NULL) == B_BAD_VALUE );
#endif

	CPPUNIT_ASSERT( link.MakeLinkedPath((const BDirectory*)NULL, &path)
					== B_BAD_VALUE );
// R5: crashs, when passing a NULL path
#if !TEST_R5
	CPPUNIT_ASSERT( link.MakeLinkedPath((const BDirectory*)NULL, NULL)
					== B_BAD_VALUE );
#endif
	link.Unset();
	path.Unset();
	dir.Unset();
}
Ejemplo n.º 29
0
bool GenesisCopyWindow::CopyLink(const char *linkname, const char *destination, const char *destfilename)
////////////////////////////////////////////////////////////////////////
{
	BSymLink srclink;
	BSymLink dstlink;
	BDirectory dstdir;
	BEntry srcentry;
	BEntry symlinkentry;
	BPath LinkPath;
	char name[B_FILE_NAME_LENGTH];
	struct stat statbuf;
	entry_ref ref;
		
	srcentry.SetTo(linkname);
	srcentry.GetName(name);
	srcentry.GetRef(&ref);
	symlinkentry.SetTo(&ref, true);
	symlinkentry.GetPath(&LinkPath);

	if (destfilename)
		sprintf(name,"%s",destfilename);
	
	if (srcentry.GetStat(&statbuf)!=B_OK)
		return false;

	dstdir.SetTo(destination);
	
	if (dstdir.InitCheck()!=B_OK)
		return false;

	Lock();
	m_FileBar->Update(-m_FileBar->CurrentValue());	// Reset to 0.0
	m_FileBar->SetMaxValue(1);
	m_FileBar->SetTrailingText(name);
	Unlock();

	if (dstdir.CreateSymLink(name, LinkPath.Path(), &dstlink)!=B_OK && !m_SkipSymLinkCreationError)
	{
		BString text;
		
		text << "Cannot create '" << name << "' symbolic link in '" << LinkPath.Path() << "'";
		
		BAlert *myAlert = new BAlert("Copy",text.String(),"Abort","Skip all","Skip",B_WIDTH_AS_USUAL,B_OFFSET_SPACING,B_WARNING_ALERT);
		myAlert->SetShortcut(0, B_ESCAPE);
		switch (myAlert->Go())
		{
			case 0:
				Close();
				kill_thread(m_CopyThread);
				break;
			case 1:
				m_SkipSymLinkCreationError = true;
				break;
		}	

		return false;
	}

	Lock();
	m_FileBar->Update(1);
	Unlock();
		
	dstlink.SetPermissions(statbuf.st_mode);
	dstlink.SetOwner(statbuf.st_uid);
	dstlink.SetGroup(statbuf.st_gid);
	dstlink.SetModificationTime(statbuf.st_mtime);
	dstlink.SetCreationTime(statbuf.st_crtime);

	// Copy attributes...
	BString destlinkname;
	destlinkname.SetTo("");
	destlinkname << destination << "/" << name;
	CopyAttr(linkname, destlinkname.String());

	return true;
}
Ejemplo n.º 30
0
void
ServerAgent::DCCGetDialog (
	BString nick,
	BString file,
	BString size,
	BString ip,
	BString port)
{
	BMessage msg (M_DCC_ACCEPT), reply;
	
	msg.AddString ("vision:nick", nick.String());
	msg.AddString ("vision:file", file.String());
	msg.AddString ("vision:size", size.String());
	msg.AddString ("vision:ip", ip.String());
	msg.AddString ("vision:port", port.String());

      BFilePanel *panel;
	  BString text;

	  text << nick
        << ": "
        << file
        << " ("
        << size
        << " bytes)";

	  panel = new BFilePanel (
        B_SAVE_PANEL,
        &fSMsgr,
        0,
        0,
        false,
        &msg);
      panel->SetButtonLabel (B_DEFAULT_BUTTON, "Accept");
      panel->SetButtonLabel (B_CANCEL_BUTTON, "Refuse");
      panel->SetSaveText (file.String());
      
      BWindow *panelWindow (panel->Window());

      if (panelWindow->Lock())
      {
        panelWindow->SetTitle (text.String());
        panelWindow->SetFlags (panelWindow->Flags() | B_AVOID_FOCUS); 
        panelWindow->AddFilter (new DCCFileFilter (panel, msg));
        if (vision_app->GetBool ("dccAutoAccept"))
        {
          BDirectory path (vision_app->GetString ("dccDefPath"));
          if (path.InitCheck() == B_OK)
            panel->SetPanelDirectory(&path);
        }
        if (vision_app->GetBool ("dccAutoAccept"))
        {
          panelWindow->Hide();
          BButton *button (dynamic_cast<BButton *>(panel->Window()->FindView ("default button")));
          if (button)
            button->Invoke();
        }
        panelWindow->Unlock();
        panel->Show();
        // hack trick to ensure that the file panel doesn't take over the keyboard focus
        // when it pops up
        panelWindow->Lock();
        panelWindow->SetFlags (panelWindow->Flags() & ~B_AVOID_FOCUS);
        panelWindow->Unlock();
      }
}