Ejemplo n.º 1
0
status_t AVIProducer::SniffRef( const entry_ref &file, char *outMimeType, float *outQuality)
{
	status_t retVal = B_MEDIA_NO_HANDLER;
		
	// Create a file from entry_ref
	BFile *theFile = new BFile(&file, B_READ_ONLY);
	
	if (theFile->InitCheck() == B_NO_ERROR){
		if ( IsRIFFFile(theFile)){
			//	We like this file
			retVal = B_OK;
			
			//	Set the MIME type
			strcpy(outMimeType, "video/x-msvideo");
			
			//	Set quality and ID
			*outQuality = 1.0;
		}
	}
	
	//	Clean up 
	delete theFile;
	
	//	Return result
	return retVal;
}
Ejemplo n.º 2
0
bool PrintTransport::IsPrintToFileCanceled() const
{
	// The BeOS "Print To File" transport add-on returns a non-NULL BDataIO *
	// even after user filepanel cancellation!
	BFile* file = dynamic_cast<BFile*>(fDataIO);
	return fDataIO == NULL || (file != NULL && file->InitCheck() != B_OK);
}
Ejemplo n.º 3
0
status_t
write_midi_settings(struct midi_settings settings)
{
	BPath path;
	status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
	if (status != B_OK)
		return status;

	path.Append(SETTINGS_FILE);

	BFile file;
	if (file.SetTo(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE)
		!= B_OK)
		return B_ERROR;

	char buffer[B_FILE_NAME_LENGTH + 128];
	snprintf(buffer, sizeof(buffer), "# Midi\n\tsoundfont \"%s\"\n",
			settings.soundfont_file);

	size_t bufferSize = strlen(buffer);
	if (file.InitCheck() != B_OK
		|| file.Write(buffer, bufferSize) != (ssize_t)bufferSize)
		return B_ERROR;

	return B_OK;
}
Ejemplo n.º 4
0
WorkspacesSettings::WorkspacesSettings()
	:
	fAutoRaising(false),
	fAlwaysOnTop(false),
	fHasTitle(true),
	fHasBorder(true),
	fSwitchOnWheel(false),
	fLoaded(false)
{
	UpdateScreenFrame();

	BScreen screen;

	BFile file;
	if (_Open(file, B_READ_ONLY) == B_OK) {
		BMessage settings;
		if (settings.Unflatten(&file) == B_OK) {
			if (settings.FindRect("window", &fWindowFrame) == B_OK
				&& settings.FindRect("screen", &fScreenFrame) == B_OK)
				fLoaded = true;

			settings.FindBool("auto-raise", &fAutoRaising);
			settings.FindBool("always on top", &fAlwaysOnTop);

			if (settings.FindBool("has title", &fHasTitle) != B_OK)
				fHasTitle = true;
			if (settings.FindBool("has border", &fHasBorder) != B_OK)
				fHasBorder = true;
			if (settings.FindBool("switch on wheel", &fSwitchOnWheel) != B_OK)
				fSwitchOnWheel = false;
		}
	} else {
		// try reading BeOS compatible settings
		BPath path;
		if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
			path.Append(kOldSettingFile);
			BFile file(path.Path(), B_READ_ONLY);
			if (file.InitCheck() == B_OK
				&& file.Read(&fWindowFrame, sizeof(BRect)) == sizeof(BRect)) {
				// we now also store the frame of the screen to know
				// in which context the window frame has been chosen
				BRect frame;
				if (file.Read(&frame, sizeof(BRect)) == sizeof(BRect))
					fScreenFrame = frame;
				else
					fScreenFrame = screen.Frame();

				fLoaded = true;
			}
		}
	}

	if (fLoaded) {
		// if the current screen frame is different from the one
		// just loaded, we need to alter the window frame accordingly
		if (fScreenFrame != screen.Frame())
			UpdateFramesForScreen(screen.Frame());
	}
}
Ejemplo n.º 5
0
void Filters::Load()
{
	status_t err;

	// figure out where the file should be
	BPath path;
	err = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true);
	if (err != B_NO_ERROR)
		return;
	path.Append(FileNames::filtersFileName);

	// open the file
	BFile* file = new BFile(path.Path(), B_READ_ONLY);
	if (file->InitCheck() != B_NO_ERROR) {
		delete file;
		return;
		}

	// load the text
	off_t fileSize;
	file->GetSize(&fileSize);
	char* text = new char[fileSize];
	file->ReadAt(0, text, fileSize);
	delete file;

	// parse it
	TextReader reader(string_slice(text, text + fileSize));
	FilterGroup* curGroup = NULL;
	while (!reader.AtEOF()) {
		// get the groupName
		string_slice groupName = reader.NextTabField();
		if (groupName.length() > 0) {
			curGroup = GetFilterGroup(groupName);
			if (curGroup == NULL) {
				curGroup = new FilterGroup(groupName);
				AddFilterGroup(curGroup);
				}
			reader.NextLine();
			}

		// if none, this is a filter line (if it's not blank)
		else {
			string_slice filterLine = reader.NextLine();
			if (filterLine.length() > 0 && curGroup != NULL) {
				Filter* filter = new Filter();
				TextReader lineReader(filterLine);
				filter->ReadFrom(&lineReader);
				curGroup->AddFilter(filter);
				}
			}
		}

	// clean up
	delete text;
}
Ejemplo n.º 6
0
status_t TaskFS::TaskToFile(Task *theTask, bool overwrite)
{
	BFile		taskFile;
	BEntry		entry;
	status_t	err;
	TaskList	*tskLst	= theTask->GetTaskList();
	
	BDirectory	dir		= BDirectory();

	bool	completed	= theTask->IsCompleted();
	uint32	priority	= theTask->Priority();
	time_t	due			= theTask->DueTime();


	//first find directory.. then create files in this directory
	if (tskLst!=NULL)
		dir.SetTo(&tasksDir,tskLst->Name());
	else
		dir.SetTo(&tasksDir,".");

	
	//first check if the File already exists..
	//if not and overwrite is on check the ids..
	// and search for the correspondending file...

	if (dir.FindEntry(theTask->Title(),&entry) == B_OK) {
		taskFile.SetTo((const BEntry*)&entry,B_READ_WRITE);
		err = B_OK;
	} 
	else {
		entry_ref *ref= FileForId(theTask);
		if (ref==NULL){
			dir.CreateFile(theTask->Title(),&taskFile,overwrite);
			dir.FindEntry(theTask->Title(),&entry);
		}
		else {
			entry.SetTo(ref);
			taskFile.SetTo((const BEntry*)ref,B_READ_WRITE);
		}
	}
	if (taskFile.InitCheck() == B_OK){
		taskFile.WriteAttr("META:completed",B_BOOL_TYPE, 0, &completed, sizeof(completed));
		entry.Rename(theTask->Title());
		taskFile.WriteAttrString("META:tasks",new BString(theTask->GetTaskList()->ID()));
		taskFile.WriteAttrString("META:notes",new BString(theTask->Notes()));
		taskFile.WriteAttr("META:priority", B_UINT32_TYPE, 0, &priority, sizeof(priority));
		taskFile.WriteAttr("META:due", B_TIME_TYPE, 0, &due, sizeof(due));
		taskFile.WriteAttrString("META:task_id",  new BString(theTask->ID()));
		taskFile.WriteAttrString("META:task_url",new BString(theTask->URL()));
	}
	else
		err=B_ERROR;
	return err; 
}
Ejemplo n.º 7
0
Preferences::~Preferences()
{
	if (fSavePreferences) {
		BFile file;
		status_t set = B_ERROR;
		if (fSettingsFile)
			file.SetTo(fSettingsFile, B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
		else {
			BPath prefpath;
			if (find_directory(B_USER_SETTINGS_DIRECTORY, &prefpath, true) == B_OK) {
				BDirectory prefdir(prefpath.Path());
				set = prefdir.CreateFile(fName, &file, false);
			}
		}

		if (file.InitCheck () == B_OK) {
			Flatten(&file);
			if (fSignature) {
				file.WriteAttr("BEOS:TYPE", B_MIME_STRING_TYPE, 0, fSignature,
					strlen(fSignature) + 1);
			}
		} else {
			// implement saving somewhere else!
			BString error;
			snprintf(error.LockBuffer(256), 256,
				B_TRANSLATE("Your setting file could not be saved!\n(%s)"),
				strerror(file.InitCheck()));
			error.UnlockBuffer();
			BAlert *alert = new BAlert(B_TRANSLATE("Error saving file"),
				error.String(), B_TRANSLATE("Damned!"), NULL, NULL,
				B_WIDTH_AS_USUAL, B_STOP_ALERT);
			alert->SetShortcut(0, B_ESCAPE);

			alert->Go();
		}
	}
	delete fSettingsFile;
	free(fName);
	free(fSignature);
}
Ejemplo n.º 8
0
void am_log_cstr(const char* str)
{
	BFile		file;

	if (!gLogged) {
		gLogged = true;
		file.SetTo(LOG_STR, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
	} else {
		file.SetTo(LOG_STR, B_WRITE_ONLY | B_CREATE_FILE | B_OPEN_AT_END);
	}
	
	if (file.InitCheck() != B_OK) return;
	file.Write(str, strlen(str));
}
Ejemplo n.º 9
0
void am_log_bstr(BString& str)
{
	BFile		file;

	if (!gLogged) {
		gLogged = true;
		file.SetTo(LOG_STR, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
	} else {
		file.SetTo(LOG_STR, B_WRITE_ONLY | B_CREATE_FILE | B_OPEN_AT_END);
	}
	
	if (file.InitCheck() != B_OK) return;
	file.Write(str.String(), str.Length());
}
Ejemplo n.º 10
0
static BFile *
get_file(BDataIO * data)
{
	// try to cast to BFile then perform a series of
	// sanity checks to ensure that the file is okay
	BFile * file = dynamic_cast<BFile *>(data);
	if (file == 0) {
		return 0;
	}
	if (file->InitCheck() != B_OK) {
		return 0;
	}
	return file;
}
Ejemplo n.º 11
0
void
TSigTextView::MessageReceived(BMessage *msg)
{
	char		type[B_FILE_NAME_LENGTH];
	char		*text;
	int32		end;
	int32		start;
	BFile		file;
	BNodeInfo	*node;
	entry_ref	ref;
	off_t		size;

	switch (msg->what) {
		case B_SIMPLE_DATA:
			if (msg->HasRef("refs")) {
				msg->FindRef("refs", &ref);
				file.SetTo(&ref, O_RDONLY);
				if (file.InitCheck() == B_NO_ERROR) {
					node = new BNodeInfo(&file);
					node->GetType(type);
					delete node;
					file.GetSize(&size);
					if ((!strncasecmp(type, "text/", 5)) && (size)) {
						text = (char *)malloc(size);
						file.Read(text, size);
						Delete();
						GetSelection(&start, &end);
						Insert(text, size);
						Select(start, start + size);
						free(text);
					}
				}
			}
			else
				BTextView::MessageReceived(msg);
			break;

		case M_SELECT:
			if (IsSelectable())
				Select(0, TextLength());
			break;

		default:
			BTextView::MessageReceived(msg);
	}
}
Ejemplo n.º 12
0
void
TPeopleApp::RefsReceived(BMessage* message)
{
	int32 index = 0;
	while (message->HasRef("refs", index)) {
		entry_ref ref;
		message->FindRef("refs", index++, &ref);
		PersonWindow* window = _FindWindow(ref);
		if (window != NULL) {
			window->Activate(true);
		} else {
			BFile* file = new BFile(&ref, B_READ_WRITE);
			if (file->InitCheck() == B_OK)
				_NewWindow(&ref, file);
		}
	}
}
Ejemplo n.º 13
0
int Language::Load(const char* name) {
  BFile *languageFile = new BFile (name, B_READ_ONLY);
  
  if (languageFile->InitCheck() != B_OK) return B_ERROR;
 
  for (int i = 0; i < L_MAX_LINES; i++) {
    strcpy( lines[i], "");
    char k = '.';
    while (k != '\n') {
      if (languageFile->Read(&k,1) != 1) return B_ERROR;
      if (k != '\n' && k != '+') strncat(lines[i],&k,1);
      if (k == '+') strncat(lines[i],"\n",1);
    }
  }

  return B_OK;
}
Ejemplo n.º 14
0
BPopUpMenu*
TPrefsWindow::_BuildSignatureMenu(char* sig)
{
	char name[B_FILE_NAME_LENGTH];
	BEntry entry;
	BFile file;
	BMenuItem* item;
	BMessage* msg;
	BQuery query;
	BVolume vol;
	BVolumeRoster volume;

	BPopUpMenu* menu = new BPopUpMenu("");

	msg = new BMessage(P_SIG);
	msg->AddString("signature", B_TRANSLATE("None"));
	menu->AddItem(item = new BMenuItem(B_TRANSLATE("None"), msg));
	if (!strcmp(sig, B_TRANSLATE("None")))
		item->SetMarked(true);

	msg = new BMessage(P_SIG);
	msg->AddString("signature", B_TRANSLATE("Random"));
	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Random"), msg));
	if (!strcmp(sig, B_TRANSLATE("Random")))
		item->SetMarked(true);
	menu->AddSeparatorItem();

	volume.GetBootVolume(&vol);
	query.SetVolume(&vol);
	query.SetPredicate("_signature = *");
	query.Fetch();

	while (query.GetNextEntry(&entry) == B_NO_ERROR) {
		file.SetTo(&entry, O_RDONLY);
		if (file.InitCheck() == B_NO_ERROR) {
			msg = new BMessage(P_SIG);
			file.ReadAttr("_signature", B_STRING_TYPE, 0, name, sizeof(name));
			msg->AddString("signature", name);
			menu->AddItem(item = new BMenuItem(name, msg));
			if (!strcmp(sig, name))
				item->SetMarked(true);
		}
	}
	return menu;
}
Ejemplo n.º 15
0
bool
WriteMessageDriverSettings(BFile& file, const BMessage& message)
{
	if(file.InitCheck() != B_OK || !file.IsWritable())
		return false;
	
	file.SetSize(0);
	file.Seek(0, SEEK_SET);
	
	BMessage parameter;
	for(int32 index = 0; message.FindMessage(MDSU_PARAMETERS, index, &parameter) == B_OK;
			index++) {
		if(index > 0)
			file.Write("\n", 1);
		WriteParameter(file, parameter, 0);
	}
	
	return true;
}
Ejemplo n.º 16
0
void Include(const char *file)
{
	BFile f;
	const char **i = gIncludePaths;
	char path[PATH_MAX];

	do
	{
		strcpy(path, *i++);
		strcat(path, "/");
		strcat(path, file);
	}
	while (f.SetTo(path, B_READ_ONLY) != B_OK && *i);

	if (f.InitCheck() != B_OK) error("Error opening file %s: %s", file, strerror(errno));

	if (resFile)
		resFile->MergeFrom(&f);
	else
		error("Should write to a resource file for Include to work!");
} // Include
Ejemplo n.º 17
0
status_t
PoorManWindow::SaveSettings()
{
	BPath p;
	BFile f;
	BMessage m(MSG_PREF_FILE);
		
	//site tab
	m.AddString("fWebDirectory", fWebDirectory);
	m.AddString("fIndexFileName", fIndexFileName);
	m.AddBool("fDirListFlag", fDirListFlag);
	
	//logging tab
	m.AddBool("fLogConsoleFlag", fLogConsoleFlag);
	m.AddBool("fLogFileFlag", fLogFileFlag);
	m.AddString("fLogPath", fLogPath);
	
	//advance tab
	m.AddInt16("fMaxConnections", fMaxConnections);
	
	//windows' position and size
	m.AddRect("frame", fFrame);
	m.AddRect("fSetwindowFrame", fSetwindowFrame);
	m.AddBool("fIsZoomed", fIsZoomed);
	m.AddFloat("fLastWidth", fLastWidth);
	m.AddFloat("fLastHeight", fLastHeight);
		
	if (find_directory(B_USER_SETTINGS_DIRECTORY, &p) != B_OK)
		return B_ERROR;
	p.Append(STR_SETTINGS_FILE_NAME);
	
	f.SetTo(p.Path(), B_WRITE_ONLY | B_ERASE_FILE | B_CREATE_FILE);
	if (f.InitCheck() != B_OK)
		return B_ERROR;
	
	if (m.Flatten(&f) != B_OK)
		return B_ERROR;

	return B_OK;
}
Ejemplo n.º 18
0
void Filters::Save()
{
	status_t err;

	// figure out where to put it
	BPath path;
	err = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true);
	if (err != B_NO_ERROR)
		return;
	path.Append(FileNames::filtersFileName);

	// open the file
	BFile* file = new BFile(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
	if (file->InitCheck() != B_NO_ERROR)
		return;

	// write
	WalkObjects(WriteFilterGroup, file);

	// clean up
	delete file;
}
Ejemplo n.º 19
0
status_t
IMAPStorage::OpenMessage(int32 uid, BPositionIO** file)
{
    *file = NULL;

    MailEntryMap::const_iterator it = fMailEntryMap.find(uid);
    if (it == fMailEntryMap.end())
        return B_BAD_VALUE;

    const StorageMailEntry& storageEntry = (*it).second;
    BPath filePath = fMailboxPath;
    filePath.Append(storageEntry.fileName);
    BFile* ourFile = new BFile(filePath.Path(), B_READ_WRITE);
    if (!ourFile)
        return B_NO_MEMORY;
    status_t status = ourFile->InitCheck();
    if (status != B_OK) {
        delete *file;
        return status;
    }
    *file = ourFile;
    return B_OK;
}
Ejemplo n.º 20
0
status_t
BShelf::Save()
{
	status_t status = B_ERROR;
	if (fEntry != NULL) {
		BFile *file = new BFile(fEntry, B_READ_WRITE | B_ERASE_FILE);
		status = file->InitCheck();
		if (status < B_OK) {
			delete file;
			return status;
		}
		fStream = file;
	}

	if (fStream != NULL) {
		BMessage message;
		status = _Archive(&message);
		if (status == B_OK)
			status = message.Flatten(fStream);
	}

	return status;
}
Ejemplo n.º 21
0
void
PoorManWindow::SetLogPath(const char* str)
{
	if (!strcmp(fLogPath, str))
		return;
	
	BFile* temp = new BFile(str, B_CREATE_FILE | B_WRITE_ONLY | B_OPEN_AT_END);
	
	if (temp->InitCheck() != B_OK) {
		delete temp;
		return;
	}
	
	if (pthread_rwlock_wrlock(&fLogFileLock) == 0) {
		delete fLogFile;
		fLogFile = temp;
		pthread_rwlock_unlock(&fLogFileLock);
	} else {
		delete temp;
		return;
	}
	
	fLogPath.SetTo(str);
}
BFile*
MilkySettingsApplication::_OpenSettingsFile(uint32 openMode)
{
    BPath path;
    find_directory(B_USER_SETTINGS_DIRECTORY, &path);
    path.Append("MilkyTracker");

    BEntry dirEntry(path.Path());
    if (!dirEntry.Exists()) {
        // MilkyTracker settings dir doesn't exist, create it
        BDirectory temp;
        temp.CreateDirectory(path.Path(), NULL);
    }

    path.Append("platform_settings");
    BFile* file = new BFile(path.Path(), openMode);

    if (file->InitCheck() != B_OK) {
        delete file;
        return NULL;
    }

    return file;
}
Ejemplo n.º 23
0
status_t
PPDParser::InitData(BFile& file)
{
	// Check if file exists...
	if ((fInitErr = file.InitCheck()) != B_OK)
		return fInitErr;

	// Read entire file into BString
	ssize_t len;
	char buffer[1025];
	while ((len = file.Read(buffer, sizeof(buffer)-1)) > 0) {
		buffer[len] = '\0';
		fContent << buffer;
	}

	// Convert DOS/Windows newlines to UNIX ones
	fContent.ReplaceAll("\r\n", "\n");
	// Handle line continuation
	fContent.ReplaceAll("&&\n", "");
	// Make sure file ends with newline
	fContent << '\n';

	return B_OK;
}
Ejemplo n.º 24
0
int32 DCCSend::Transfer(void* arg)
{
	BMessenger msgr(reinterpret_cast<DCCSend*>(arg));
	BMessage reply, ipdata;
	BLooper* looper(NULL);

	if (msgr.IsValid()) msgr.SendMessage(M_DCC_GET_CONNECT_DATA, &reply);

	BMessenger callmsgr;
	reply.FindMessenger("caller", &callmsgr);

	callmsgr.SendMessage(M_GET_IP, &ipdata);

	BPath path(reply.FindString("name"));
	BString fileName, status;
	struct sockaddr_in address;
	struct in_addr sendaddr;
	memset(&sendaddr, 0, sizeof(struct in_addr));
	int sd, dccSock(-1);

	fileName.Append(path.Leaf());
	fileName.ReplaceAll(" ", "_");

	if ((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
		UpdateStatus(msgr, S_DCC_ESTABLISH_ERROR);
		return 0;
	}

	memset(&address, 0, sizeof(struct sockaddr_in));
	address.sin_family = AF_INET;
	address.sin_addr.s_addr = INADDR_ANY;
	address.sin_port = htons(atoi(reply.FindString("port")));

	int sin_size;
	sin_size = (sizeof(struct sockaddr_in));

	UpdateStatus(msgr, S_DCC_LOCK_ACQUIRE B_UTF8_ELLIPSIS);

	vision_app->AcquireDCCLock();

	if (!msgr.IsValid() || bind(sd, (sockaddr*)&address, sin_size) < 0) {
		UpdateStatus(msgr, S_DCC_ESTABLISH_ERROR);
		vision_app->ReleaseDCCLock();

		close(sd);
		return 0;
	}

	UpdateStatus(msgr, S_DCC_ACK_WAIT);

	sendaddr.s_addr = inet_addr(ipdata.FindString("ip"));

	if (msgr.IsValid()) {
		status = "PRIVMSG ";
		status << reply.FindString("nick") << " :\1DCC SEND " << fileName << " "
			   << htonl(sendaddr.s_addr) << " " << reply.FindString("port") << " "
			   << reply.FindString("size") << "\1";

		BMessage msg(M_SERVER_SEND);
		msg.AddString("data", status.String());
		if (callmsgr.IsValid()) callmsgr.SendMessage(&msg);

		UpdateStatus(msgr, S_DCC_LISTEN_CALL);
		if (listen(sd, 1) < 0) {
			UpdateStatus(msgr, S_DCC_ESTABLISH_ERROR);
			vision_app->ReleaseDCCLock();
			close(sd);
			return 0;
		}
	}

	struct timeval t;
	t.tv_sec = 2;
	t.tv_usec = 0;

	uint32 try_count(0);

	while (msgr.Target(&looper) != NULL) {
		fd_set rset;

		FD_ZERO(&rset);
		FD_SET(sd, &rset);

		if (select(sd + 1, &rset, 0, 0, &t) < 0) {
			UpdateStatus(msgr, S_DCC_ESTABLISH_ERROR);
			vision_app->ReleaseDCCLock();
			close(sd);
			return 0;
		}

		if (FD_ISSET(sd, &rset)) {
			dccSock = accept(sd, (sockaddr*)&address, (socklen_t*)&sin_size);
			UpdateStatus(msgr, S_DCC_ESTABLISH_SUCCEEDED);
			break;
		}

		++try_count;
		status = S_DCC_WAIT_FOR_CONNECTION;
		status << try_count << ".";
		UpdateStatus(msgr, status.String());
	}

	vision_app->ReleaseDCCLock();

	char set[4];
	memset(set, 1, sizeof(set));
	close(sd);
	BFile file;

	file.SetTo(reply.FindString("name"), B_READ_ONLY);
	int32 bytes_sent(0L), seekpos(0L);

	BMessage resumeData;
	msgr.SendMessage(M_DCC_GET_RESUME_POS, &resumeData);

	if (resumeData.HasInt32("pos")) {
		resumeData.FindInt32("pos", &seekpos);
		file.Seek(seekpos, SEEK_SET);
		UpdateBar(msgr, seekpos, 0, 0, true);
		bytes_sent = seekpos;
	}

	status = S_DCC_SEND1;
	status << path.Leaf() << S_DCC_SEND2 << reply.FindString("nick") << ".";
	UpdateStatus(msgr, status.String());

	int cps(0);

	if (file.InitCheck() == B_NO_ERROR) {
		bigtime_t last(system_time()), now;
		const uint32 DCC_BLOCK_SIZE(atoi(vision_app->GetString("dccBlockSize")));
#ifdef __INTEL__
		char buffer[DCC_BLOCK_SIZE];
#else
		char* buffer = new char[DCC_BLOCK_SIZE];
#endif
		int period(0);
		ssize_t count(0);
		bigtime_t start = system_time();

		while ((msgr.Target(&looper) != NULL) &&
			   (count = file.Read(buffer, DCC_BLOCK_SIZE - 1)) > 0) {
			int sent;

			if ((sent = send(dccSock, buffer, count, 0)) < count) {
				UpdateStatus(msgr, S_DCC_WRITE_ERROR);
				break;
			}

			uint32 confirm(0), newSize(bytes_sent + count);
			fd_set rset, eset;
			FD_ZERO(&rset);
			FD_ZERO(&eset);
			FD_SET(dccSock, &rset);
			t.tv_sec = 0;
			t.tv_usec = 10;

			while ((confirm < newSize) && (recv(dccSock, &confirm, sizeof(confirm), 0) > 0)) {
				confirm = ntohl(confirm);
				bytes_sent = confirm;
			}

			BMessage msg(M_DCC_UPDATE_TRANSFERRED);
			msg.AddInt32("transferred", bytes_sent);
			msgr.SendMessage(&msg);

			now = system_time();
			period += sent;

			bool hit(false);

			if (now - last > 500000) {
				cps = (int)ceil((bytes_sent - seekpos) / ((now - start) / 1000000.0));
				BMessage updmsg(M_DCC_UPDATE_AVERAGE);
				updmsg.AddInt32("average", cps);
				msgr.SendMessage(&updmsg);
				last = now;
				period = 0;
				hit = true;
			}
			UpdateBar(msgr, sent, cps, bytes_sent, hit);
		}
#ifndef __INTEL__
		delete[] buffer;
#endif
	}
	if (msgr.IsValid()) {
		BMessage msg(M_DCC_STOP_BUTTON);
		msgr.SendMessage(&msg);
	}

	if (dccSock > 0) {
		close(dccSock);
	}

	if (file.InitCheck() == B_OK) file.Unset();

	return 0;
}
Ejemplo n.º 25
0
// DispatchMessage
void	TexWin::DispatchMessage(BMessage *mess, BHandler *target)
{
	BFile *file; BEntry *entry;
	BDirectory *dir; char filename[B_FILE_NAME_LENGTH];
	BAlert *al; char ch[256]; int32 i;
	char *data;
	entry_ref ref;
	switch(mess->what) {
	case B_PASTE :
		savedoc = false;
	case B_CUT :
	case B_COPY :
	case B_UNDO :
	case B_SELECT_ALL :
		BWindow::DispatchMessage(mess, view);
		break;
	case TEX_FULL_ANALYSE :
		view->Analyse(true);
		break;
	case TEX_SAVE :
		if (newdoc) {
			BMessage *messa = new BMessage(TEX_SAVE_AS);
			messa->AddPointer("window", (void *)this);
			be_app->PostMessage(messa); break;}
		else if (savedoc) break;
		else {
			file = new BFile (&fileref, B_READ_WRITE | B_ERASE_FILE);
			if (file->InitCheck()<0) {
				sprintf(ch, "An error as occured during saving %s.", Title());
				al = new BAlert("alert",ch,"Ok");
				al->Go();
			}
			else {
				file->Write(view->Text(), view->TextLength());
				savedoc = true;
				if (file->SetSize(view->TextLength())<0) {
					sprintf(ch, "An error as occured during saving %s.", Title());
					al = new BAlert("alert",ch,"Ok");
					al->Go();
				}
				if (file->WriteAttr("BEOS:TYPE",'MIMS',0,"text/plain\0",11)<0) {
					sprintf(ch, "An error as occured during saving %s.", Title());
					al = new BAlert("alert",ch,"Ok");
					al->Go();
				}
				else if (file->WriteAttr("BEOS:PREF_APP",'MIMS',0,"application/x-vnd.shin-TexEdit\0",31)<0) {
						sprintf(ch, "An error as occured during saving %s.", Title());
						al = new BAlert("alert",ch,"Ok");
						al->Go();
				}
				if (isQuitting)
					if (be_app->CountWindows()<4)
						be_app->PostMessage(B_QUIT_REQUESTED);
					else
						Quit();
			}
			delete file;
			break;
		}	
	case B_SAVE_REQUESTED :
		char ch[256];
		sprintf(ch, "An error as occured during saving %s.", mess->FindString("name"));
		SetTitle(mess->FindString("name"));
		mess->FindRef("directory", &ref);
		dir = new BDirectory(&ref);
		entry = new BEntry(dir, mess->FindString("name"));
		file = new BFile (entry, B_READ_WRITE | B_ERASE_FILE | B_CREATE_FILE);
		if (entry->InitCheck() < 0) {
			al = new BAlert("alert", ch,"Ok");
			al->Go();
		} else if (file->InitCheck() < 0) {
			al = new BAlert("alert", ch,"Ok");
			al->Go();
		} else {
			file->Write(view->Text(), view->TextLength());
			newdoc = false; savedoc = true;
			entry->GetRef(&fileref);
			if (file->WriteAttr("BEOS:TYPE",'MIMS',0,"text/plain\0",11)<0) {
					sprintf(ch, "An error as occured during saving %s.", Title());
					al = new BAlert("alert",ch,"Ok");
					al->Go();
				}
				else if (file->WriteAttr("BEOS:PREF_APP",'MIMS',0,"application/x-vnd.shin-TexEdit\0",31)<0) {
						sprintf(ch, "An error as occured during saving %s.", Title());
						al = new BAlert("alert",ch,"Ok");
						al->Go();
				}
			if (isQuitting) be_app->PostMessage(B_QUIT_REQUESTED);
		}
		delete entry; delete file; delete dir;
		break;
	case B_REFS_RECEIVED :
		int32 j;
		i = 0;
		mess->FindRef("refs", &fileref);
		entry = new BEntry(&fileref);
		if (entry->InitCheck() < 0) {
			al = new BAlert("alert","An error as occured : cannot use BEntry.","Ok");
			al->Go();
			break;
		}
		entry->GetName(filename);
		SetTitle(filename);
		sprintf(ch,"An error as occured : cannot open %s.", filename);
		file = new BFile(entry, B_READ_ONLY);
		if (file->InitCheck() < 0) {
			al = new BAlert("alert",ch,"Ok");
			al->Go();
			break;
		}
		data = (char *) malloc(1024 * sizeof(char));
		view->openMode = true;
		while ((j = file->ReadAt(i, (void *)data, 1024)) == 1024) {
			view->Insert(data, 1024); i +=1024;
		}
		if (j < 0) {
			al = new BAlert("alert",ch,"Ok");
			al->Go();
		} else
			view->Insert(data, j);
		view->openMode = false;
		view->Analyse(true);
		newdoc = false; savedoc = true;
		delete entry; delete file;
		break;
	case B_KEY_DOWN :
		savedoc = false;
	default :
		BWindow::DispatchMessage(mess, target);
		break;
	}
}
Ejemplo n.º 26
0
WorkspacesSettings::WorkspacesSettings()
	:
	fAutoRaising(false),
	fAlwaysOnTop(false),
	fHasTitle(true),
	fHasBorder(true)
{
	UpdateScreenFrame();

	bool loaded = false;
	BScreen screen;

	BFile file;
	if (_Open(file, B_READ_ONLY) == B_OK) {
		BMessage settings;
		if (settings.Unflatten(&file) == B_OK) {
			if (settings.FindRect("window", &fWindowFrame) == B_OK
				&& settings.FindRect("screen", &fScreenFrame) == B_OK)
				loaded = true;

			settings.FindBool("auto-raise", &fAutoRaising);
			settings.FindBool("always on top", &fAlwaysOnTop);

			if (settings.FindBool("has title", &fHasTitle) != B_OK)
				fHasTitle = true;
			if (settings.FindBool("has border", &fHasBorder) != B_OK)
				fHasBorder = true;
		}
	} else {
		// try reading BeOS compatible settings
		BPath path;
		if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
			path.Append(kOldSettingFile);
			BFile file(path.Path(), B_READ_ONLY);
			if (file.InitCheck() == B_OK
				&& file.Read(&fWindowFrame, sizeof(BRect)) == sizeof(BRect)) {
				// we now also store the frame of the screen to know
				// in which context the window frame has been chosen
				BRect frame;
				if (file.Read(&frame, sizeof(BRect)) == sizeof(BRect))
					fScreenFrame = frame;
				else
					fScreenFrame = screen.Frame();

				loaded = true;
			}
		}
	}

	if (loaded) {
		// if the current screen frame is different from the one
		// just loaded, we need to alter the window frame accordingly
		if (fScreenFrame != screen.Frame())
			UpdateFramesForScreen(screen.Frame());
	}

	if (!loaded
		|| !(screen.Frame().right + 5 >= fWindowFrame.right
			&& screen.Frame().bottom + 5 >= fWindowFrame.bottom
			&& screen.Frame().left - 5 <= fWindowFrame.left
			&& screen.Frame().top - 5 <= fWindowFrame.top)) {
		// set to some usable defaults
		float screenWidth = screen.Frame().Width();
		float screenHeight = screen.Frame().Height();
		float aspectRatio = screenWidth / screenHeight;

		uint32 columns, rows;
		BPrivate::get_workspaces_layout(&columns, &rows);

		// default size of ~1/10 of screen width
		float workspaceWidth = screenWidth / 10;
		float workspaceHeight = workspaceWidth / aspectRatio;

		float width = floor(workspaceWidth * columns);
		float height = floor(workspaceHeight * rows);

		float tabHeight = 20;
			// TODO: find tabHeight without being a window

		// shrink to fit more
		while (width + 2 * kScreenBorderOffset > screenWidth
			|| height + 2 * kScreenBorderOffset + tabHeight > screenHeight) {
			width = floor(0.95 * width);
			height = floor(0.95 * height);
		}

		fWindowFrame = fScreenFrame;
		fWindowFrame.OffsetBy(-kScreenBorderOffset, -kScreenBorderOffset);
		fWindowFrame.left = fWindowFrame.right - width;
		fWindowFrame.top = fWindowFrame.bottom - height;
	}
}
Ejemplo n.º 27
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.º 28
0
status_t
PoorManWindow::ReadSettings()
{
	BPath p;
	BFile f;
	BMessage m;
	
	if (find_directory(B_USER_SETTINGS_DIRECTORY, &p) != B_OK)
		return B_ERROR;
	p.Append(STR_SETTINGS_FILE_NAME);
	
	f.SetTo(p.Path(), B_READ_ONLY);
	if (f.InitCheck() != B_OK)
		return B_ERROR;
	
	if (m.Unflatten(&f) != B_OK)
		return B_ERROR;
	
	if (MSG_PREF_FILE != m.what)
		return B_ERROR;
	
	//site tab
	if (m.FindString("fWebDirectory", &fWebDirectory) != B_OK)
		fWebDirectory.SetTo(STR_DEFAULT_WEB_DIRECTORY);
	if (m.FindString("fIndexFileName", &fIndexFileName) != B_OK)
		fIndexFileName.SetTo("index.html");
	if (m.FindBool("fDirListFlag", &fDirListFlag) != B_OK)
		fDirListFlag = false;
	
	//logging tab
	if (m.FindBool("fLogConsoleFlag", &fLogConsoleFlag) != B_OK)
		fLogConsoleFlag = true;
	if (m.FindBool("fLogFileFlag", &fLogFileFlag) != B_OK)
		fLogFileFlag = false;
	if (m.FindString("fLogPath", &fLogPath) != B_OK)
		fLogPath.SetTo("");
	
	//advance tab
	if (m.FindInt16("fMaxConnections", &fMaxConnections) != B_OK)
		fMaxConnections = (int16)32;
	
	//windows' position and size
	if (m.FindRect("frame", &fFrame) != B_OK)
		fFrame.Set(82.0f, 30.0f, 400.0f, 350.0f);
	if (m.FindRect("fSetwindowFrame", &fSetwindowFrame) != B_OK)
		fSetwindowFrame.Set(112.0f, 60.0f, 492.0f, 340.0f);
	if (m.FindBool("fIsZoomed", &fIsZoomed) != B_OK)
		fIsZoomed = true;
	if (m.FindFloat("fLastWidth", &fLastWidth) != B_OK)
		fLastWidth = 318.0f;
	if (m.FindFloat("fLastHeight", &fLastHeight) != B_OK)
		fLastHeight = 320.0f;
	
	fIsZoomed?ResizeTo(fLastWidth, fLastHeight):ResizeTo(318, 53);
	MoveTo(fFrame.left, fFrame.top);
	
	fLogFile = new BFile(fLogPath.String(), B_CREATE_FILE | B_WRITE_ONLY
		| B_OPEN_AT_END);
	if (fLogFile->InitCheck() != B_OK) {
		fLogFileFlag = false;
		//log it to console, "log to file unavailable."
		return B_OK;
	}
	
	SetDirLabel(fWebDirectory.String());
	
	return B_OK;
}
Ejemplo n.º 29
0
void
TMailApp::RefsReceived(BMessage *msg)
{
	bool		have_names = false;
	BString		names;
	char		type[B_FILE_NAME_LENGTH];
	int32		item = 0;
	BFile		file;
	TMailWindow	*window;
	entry_ref	ref;

	//
	// If a tracker window opened me, get a messenger from it.
	//
	BMessenger messenger;
	if (msg->HasMessenger("TrackerViewToken"))
		msg->FindMessenger("TrackerViewToken", &messenger);

	while (msg->HasRef("refs", item)) {
		msg->FindRef("refs", item++, &ref);
		if ((window = FindWindow(ref)) != NULL)
			window->Activate(true);
		else {
			file.SetTo(&ref, O_RDONLY);
			if (file.InitCheck() == B_NO_ERROR) {
				BNodeInfo	node(&file);
				node.GetType(type);
				if (strcmp(type, B_MAIL_TYPE) == 0
					|| strcmp(type, B_PARTIAL_MAIL_TYPE) == 0) {
					window = NewWindow(&ref, NULL, false, &messenger);
					window->Show();
				} else if(strcmp(type, "application/x-person") == 0) {
					/* Got a People contact info file, see if it has an Email address. */
					BString name;
					BString email;
					attr_info	info;
					char *attrib;

					if (file.GetAttrInfo("META:email", &info) == B_NO_ERROR) {
						attrib = (char *) malloc(info.size + 1);
						file.ReadAttr("META:email", B_STRING_TYPE, 0, attrib, info.size);
						attrib[info.size] = 0; // Just in case it wasn't NUL terminated.
						email << attrib;
						free(attrib);

						/* we got something... */
						if (email.Length() > 0) {
							/* see if we can get a username as well */
							if(file.GetAttrInfo("META:name", &info) == B_NO_ERROR) {
								attrib = (char *) malloc(info.size + 1);
								file.ReadAttr("META:name", B_STRING_TYPE, 0, attrib, info.size);
								attrib[info.size] = 0; // Just in case it wasn't NUL terminated.
								name << "\"" << attrib << "\" ";
								email.Prepend("<");
								email.Append(">");
								free(attrib);
							}

							if (names.Length() == 0) {
								names << name << email;
							} else {
								names << ", " << name << email;
							}
							have_names = true;
							email.SetTo("");
							name.SetTo("");
						}
					}
				}
				else if (strcmp(type, kDraftType) == 0) {
					window = NewWindow();

					// If it's a draft message, open it
					window->OpenMessage(&ref);
					window->Show();
				}
			} /* end of else(file.InitCheck() == B_NO_ERROR */
		}
	}

	if (have_names) {
		window = NewWindow(NULL, names.String());
		window->Show();
	}
}
Ejemplo n.º 30
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);
	}
}