Пример #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;
}
Пример #2
0
int32_t
PDirectoryCreateFile(void *pobject, void *in, void *out, void *extraData)
{
	if (!pobject || !in || !out)
		return B_ERROR;
	
	PDirectory *parent = static_cast<PDirectory*>(pobject);
	if (!parent)
		return B_BAD_TYPE;
	
	BDirectory *backend = (BDirectory*)parent->GetBackend();
	
	PArgs *args = static_cast<PArgs*>(in), *outArgs = static_cast<PArgs*>(out);
	
	BString path;
	if (args->FindString("path", &path) != B_OK)
		return B_ERROR;
	
	bool dontClobber = false;
	if (args->FindBool("dontclobber", &dontClobber) != B_OK)
		return B_ERROR;
	
	BFile newFile;
	status_t status = backend->CreateFile(path.String(), &newFile,
										dontClobber);
	
	outArgs->MakeEmpty();
	outArgs->AddInt32("status", status);
	
	return B_OK;
}
Пример #3
0
PDoc* PApp::OpenWorksheet()
{
	try
	{
		if (!gPrefsDir.Contains("Worksheet", B_FILE_NODE | B_SYMLINK_NODE))
		{
			BFile file;
			gPrefsDir.CreateFile("Worksheet", &file);
		}

		BEntry w;
		entry_ref wr;

		FailOSErr(gPrefsDir.FindEntry("Worksheet", &w, true));
		FailOSErr(w.GetRef(&wr));
		OpenWindow(wr);

		PDoc *d = dynamic_cast<PDoc*>(CDoc::FindDoc(wr));
		if (d)
			d->MakeWorksheet();

		return d;
	}
	catch (HErr& e)
	{
		e.DoError();
	}

	return NULL;
} /* PApp::OpenWorksheet */
Пример #4
0
status_t
ThemeManager::SaveTheme(int32 id, bool excl)
{
	FENTRY;
	status_t err;
	BString name, fname;
	BPath path;
	BDirectory dir;
	BDirectory tdir;
	BFile tfile;
	BMessage names;
	BString location;
	BMessage *theme;
	theme = ThemeAt(id);
	if (!theme)
		return EINVAL;
	err = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
	if (err)	return err;
	path.Append(Z_THEMES_FOLDER_NAME);
	err = dir.SetTo(path.Path());
	if (err)	return err;
	err = ThemeName(id, name);
	if (err)	return err;
	fname = name;
	NormalizeThemeFolderName(fname);

	err = ThemeLocation(id, location);
	if (!err) {
		if (location.FindFirst("/boot/beos") >= 0) {
			PRINT(("trying to save theme '%s' to system dir!\n", name.String()));
			return B_PERMISSION_DENIED;
		}
	}
	path.Append(fname.String());
	err = theme->ReplaceString(Z_THEME_LOCATION, path.Path());
	if (err)
		err = theme->AddString(Z_THEME_LOCATION, path.Path());
	
	if (dir.CreateDirectory(fname.String(), NULL) < B_OK) {
		if (excl)
			return B_FILE_EXISTS;
	}
	err = tdir.SetTo(&dir, fname.String());
	if (err)	return err;
	err = tdir.CreateFile(Z_THEME_FILE_NAME, &tfile);
	if (err)	return err;
	
	BMessage tosave(*theme);
	err = tosave.RemoveName(Z_THEME_LOCATION);
	err = GetNames(names);
	
	err = DumpMessageToStream(&tosave, tfile, 0, &names);
	if (err)	return err;
	return B_OK;
}
Пример #5
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; 
}
Пример #6
0
CMimeItem::CMimeItem(const char *mime)
{
	fMime.SetTo(mime);
	
	memset(fIcon, B_TRANSPARENT_8_BIT, 256);
	memset(fIconSelected, B_TRANSPARENT_8_BIT, 256);

	BBitmap bm(BRect(0, 0, 15, 15), B_COLOR_8_BIT);
	if (fMime.GetIcon(&bm, B_MINI_ICON) != B_OK)
	{
		try
		{
			char p[PATH_MAX];
			if (find_directory(B_SYSTEM_TEMP_DIRECTORY, 0, true, p, PATH_MAX) == B_OK)
			{
				BDirectory tmpdir;
				FailOSErr(tmpdir.SetTo(p));

				time_t t;
				time(&t);
				sprintf(p, "tmp.pe_is_looking_for_a_mime_icon:%ld", t);

				BFile f;
				FailOSErr(tmpdir.CreateFile(p, &f));

				BNodeInfo ni;
				FailOSErr(ni.SetTo(&f));
				FailOSErr(ni.SetType(mime));
				FailOSErr(ni.GetTrackerIcon(&bm, B_MINI_ICON));
			}
		}
		catch (HErr& e) { }
	}

	for (int i = 0; i < 16; i++)
	{
		unsigned char *ba = (unsigned char *)((unsigned char *)bm.Bits() + bm.BytesPerRow() * i);
		memcpy(fIcon + i * 16, ba, 16);
		
		for (int j = 0; j < 16; j++)
			if (ba[j] < 255)
				fIconSelected[j + i * 16] = gSelectedMap[ba[j]];
	}
} /* CMimeItem::CMimeItem */
Пример #7
0
bool
DeskbarView::_CreateMenuLinks(BDirectory& directory, BPath& path)
{
	status_t status = directory.SetTo(path.Path());
	if (status == B_OK)
		return true;

	// Check if the directory has to be created (and do it in this case,
	// filling it with some standard links).  Normally the installer will
	// create the directory and fill it with links, so normally this doesn't
	// get used.

	BEntry entry(path.Path());
	if (status != B_ENTRY_NOT_FOUND
		|| entry.GetParent(&directory) < B_OK
		|| directory.CreateDirectory(path.Leaf(), NULL) < B_OK
		|| directory.SetTo(path.Path()) < B_OK)
		return false;

	BPath targetPath;
	find_directory(B_USER_DIRECTORY, &targetPath);
	targetPath.Append("mail/in");

	directory.CreateSymLink("Open Inbox Folder", targetPath.Path(), NULL);
	targetPath.GetParent(&targetPath);
	directory.CreateSymLink("Open Mail Folder", targetPath.Path(), NULL);

	// create the draft query

	BFile file;
	if (directory.CreateFile("Open Draft", &file) < B_OK)
		return true;

	BString string("MAIL:draft==1");
	file.WriteAttrString("_trk/qrystr", &string);
	string = "E-mail";
	file.WriteAttrString("_trk/qryinitmime", &string);
	BNodeInfo(&file).SetType("application/x-vnd.Be-query");

	return true;
}
/*!	\brief		Main function of the class.
 *		\param[in]	in		BMessage to respond to.
 */
void EventEditorMainWindow::MessageReceived( BMessage *in )
{
	BView* view;
	BEntry entry;
	BFile  file;
	BString tempString;
	BDirectory directory;
	BMessage saveMessage( kSaveRequested );
	entry_ref	ref;
	
	switch( in->what )
	{
		case B_SELECT_ALL:
		case B_COPY:
		case B_CUT:
		case B_PASTE:
		case B_UNDO:
			view = CurrentFocus();
			if ( view )
				view->MessageReceived( in );
			break;
		
		case kFileOpen:
			fOpenFile->Show();
			break;

			
		case kFileSaveAs:
			fSaveFile->Show();
			break;
		
		case kFileRevert:				// Intentional fall-through
		case kFileOpenConfirmed:
			if ( in->what == kFileRevert ) {		
				if ( fData.GetRef() != NULL )
				{
						// ...Prepare it for usage
					ref = *( fData.GetRef() );
				} else {
						// Ask the user what to do
					fOpenFile->Show();
					break;
				}
			} else {
				if ( B_OK != in->FindRef( "refs", &ref ) ||
					  B_OK != entry.SetTo( &ref, true ) ||
					  B_OK != entry.GetRef( &ref ) )
				{
					entry.Unset();
					break;
				}
			}
			fData.InitFromFile( ref );
			if ( Looper()->Lock() ) {
//				fData.Revert();
				MainView->RemoveSelf();
				delete MainView;
				InitUI();
				Looper()->Unlock();
			}
			entry.Unset();
			break;

		case kFileSave:				// Intentional fall-through			
		case kFileSaveConfirmed:
			
				// Save user's changes
			if ( genView ) genView->MessageReceived( &saveMessage );
			if ( remView ) remView->MessageReceived( &saveMessage );
			if ( actView ) actView->SaveData();
			if ( noteView ) noteView->SaveText();
			
			fData.SetEventActivityFired( false );
			fData.SetReminderActivityFired( false );
		
				// If we have the reference to file...
			if ( in->what == kFileSave ) {
				if ( fData.GetRef() != NULL )
				{
						// ...Prepare it for usage
					ref = *( fData.GetRef() );
				} else {
						// Ask the user what to do
					fSaveFile->Show();
					break;
				}				
				
			} else {
				if ( B_OK != in->FindRef( "directory", &ref ) ||
				     B_OK != in->FindString( "name", &tempString ) ||
				     B_OK != directory.SetTo( &ref ) ||
				     B_OK != directory.CreateFile( tempString.String(), NULL, false ) ||
				     B_OK != directory.FindEntry( tempString.String(), &entry, true ) ||
				     B_OK != entry.GetRef( &ref ) )
				{
					break;
				}
			}
			if ( fData.SaveToFile( &ref ) != B_OK ) {
				utl_Deb = new DebuggerPrintout( "Couldn't save file!" );	
			}
			break;
		
		case B_ABOUT_REQUESTED:
			be_app->AboutRequested();
		
		default:
		  BWindow::MessageReceived( in );
		  break;
	}
}	// <-- end of function EventEditorMainWindow::MessageReceived
Пример #9
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;
	}
}
Пример #10
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();
}
Пример #11
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);
	}
}
Пример #12
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);
	}
}
Пример #13
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);
	}
}
Пример #14
0
int main(int argc, char *argv[])
{
	yyin = stdin;

	int i = getoptions(argc, argv);

	char buf[PATH_MAX];
	if (out[0] == '/')
		strcpy(buf, out);
	else
	{
		getcwd(buf, PATH_MAX);
		strcat(buf, "/");
		strcat(buf, out);
	}

	BEntry e;
	if (e.SetTo(out)) error("entry set to %s", out);

	BDirectory d;
	if (e.GetParent(&d)) error("get parent of %s", out);
	if ((gTruncate || gSaveAsHeader) && e.Exists() && e.Remove())
		error("removing %s", out);

	BFile f;
	BResources res;

	if (!gDump)
	{
		if (gTruncate || !e.Exists())
		{
			if (d.CreateFile(buf, &f)) error("creating %s", buf);
			gTruncate = true;
		}
		else
			if (f.SetTo(buf, B_READ_WRITE)) error("opening %s", buf);

		if (gSaveAsHeader)
		{
			gHeader = fopen(buf, "w");
			if (!gHeader) error("Error creating %s", buf);
		}
		else if (res.SetTo(&f, gTruncate) != B_NO_ERROR)
			error("opening resource file %s", buf);
	}

	resFile = &res;

	if (i == argc)
		Work(NULL);
	else
	{
		while (i < argc)
			Work(in = argv[i++]);
	}

	if (verbose)
		puts("done");

	if (gHeader)
		fclose(gHeader);
	else
		f.Sync();

	return 0;
} /* main */
Пример #15
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;
}