/*	isImage
*	checks if selected file is a image
*	if yes, returns true
*/
bool
ProjectTypeSelector::isImage()
{
	BString *FileType = (BString*)TypeList->FirstItem();

	if(FileType->Compare("application/octet-stream") == 0 ||
		FileType->Compare("application/x-cd-image") == 0)
		return true;
	
	return false;
}
Example #2
0
status_t
RuleRunner::RunAction(const BMessage &action, entry_ref &ref)
{
	BString actionname;
	if (action.FindString("name",&actionname) != B_OK)
	{
		debugger("Couldn't find action name in RuleRunner::RunAction");
		return B_ERROR;
	}
	
	if (actionname.Compare("Move it to…") == 0)
		return MoveAction(action,ref);
	else if (actionname.Compare("Copy it to…") == 0)
		return CopyAction(action,ref);
	else if (actionname.Compare("Rename it to…") == 0)
		return RenameAction(action,ref);
	else if (actionname.Compare("Open it") == 0)
		return OpenAction(action,ref);
	else if (actionname.Compare("Add it to the archive…") == 0)
		return ArchiveAction(action,ref);
	else if (actionname.Compare("Terminal command…") == 0)
		return CommandAction(action,ref);
	else if (actionname.Compare("Move it to the Trash") == 0)
		return TrashAction(action,ref);
	else if (actionname.Compare("Delete it") == 0)
		return DeleteAction(action,ref);
	
	return B_ERROR;
}
Example #3
0
bool
StringCompare(const BString &from, const BString &to, const char *mode,
			const bool &match_case)
{
	if (!mode)
	{
		debugger("NULL mode in StringCompare");
		return false;
	}
	
	if (strcmp(mode,"is") == 0)
		if (match_case)
			return from.Compare(to) == 0;
		else
			return from.ICompare(to) == 0;
	else if (strcmp(mode,"is not") == 0)
		if (match_case)
			return from.Compare(to) != 0;
		else
			return from.ICompare(to) != 0;
	else if (strcmp(mode,"contains") == 0)
		if (match_case)
			return to.FindFirst(from) >= 0;
		else
			return to.IFindFirst(from) >= 0;
	else if (strcmp(mode,"does not contain") == 0)
		if (match_case)
			return to.FindFirst(from) < 0;
		else
			return to.IFindFirst(from) < 0;
	else if (strcmp(mode,"starts with") == 0)
		if (match_case)
			return to.FindFirst(from) == 0;
		else
			return to.IFindFirst(from) == 0;
	else if (strcmp(mode,"ends with") == 0)
	{
		int32 pos;
		if (match_case)
			pos = to.FindLast(from);
		else
			pos = to.IFindLast(from);
		
		return (to.CountChars() - from.CountChars() == pos);
	}	
	
	return false;
}
Example #4
0
status_t
OpenAction(const BMessage &action, entry_ref &ref)
{
	entry_ref app;
	BString appName("");
	if (be_roster->FindApp(&ref,&app) == B_OK)
		appName = app.name;
	
	status_t status = be_roster->Launch(&ref);
	
	if (status == B_OK)
		printf("\tOpened %s in program %s\n",ref.name,appName.String());
	else
	{
		// R5 (and probably others) don't seem to want to open folders in Tracker --
		// FindApp() returns B_OK, but sets the entry_ref of the app to open it to
		// the folder's ref, which is dumb. This works around this apparent stupidity.
		BString typestr;
		if (BNode(&ref).ReadAttrString("BEOS:TYPE",&typestr) == B_OK &&
			typestr.Compare("application/x-vnd.Be-directory") == 0)
		{
			BMessage *msg = new BMessage(B_REFS_RECEIVED);
			msg->AddRef("refs",&ref);
			be_roster->Launch("application/x-vnd.Be-TRAK",msg);
			printf("\tOpened %s in program Tracker\n",ref.name);
			return B_OK;
		}
		if (appName.CountChars() > 0)
			printf("\tCouldn't open %s in program %s\n",ref.name,appName.String());
		else
			printf("\tCouldn't open %s -- the system couldn't find a program to do it.\n",ref.name);
	}
	
	return status;
}
Example #5
0
void
Project::RemoveSystemInclude(const char *path)
{
	if (!path)
		return;
	
	BString abspath(path);
	abspath.ReplaceFirst("<project>",fPath.GetFolder());
	
	if (abspath[0] != '/')
	{
		abspath.Prepend("/");
		abspath.Prepend(fPath.GetFolder());
	}
	
	STRACE(1,("%s: Attempting to remove system include %s\n",GetName(),path));
	for (int32 i = 0; i < fSystemIncludeList.CountItems(); i++)
	{
		BString *str = fSystemIncludeList.ItemAt(i);
		if (str && str->Compare(abspath) == 0)
		{
			STRACE(1,("%s: Removed %s\n",GetName(),path));
			fSystemIncludeList.RemoveItemAt(i);
			delete str;
			return;
		}
	}
}
Example #6
0
// fetch number of unique names on the slot list
int getNumUniquePBNames(struct pbSlot *sl = NULL) {
	if (!sl)
		return 0;
	if (sl->pb->CountItems() == 0)
		return 0;
	// clone slot list
	BList *l = new BList(*(sl->pb));
	// sort slot list by name
	l->SortItems(&pbNumCompareByName);
	int j = l->CountItems();
	int n = 1;
	struct pbNum *c = (struct pbNum*)l->ItemAt(0);
	BString *last = ((union pbVal*)c->attr->ItemAt(1))->text;
	BString *cur;
	// go through the list and ++ on each change
	for (int i=1;i<j;i++) {
		c = (struct pbNum*)l->ItemAt(i);
		cur = ((union pbVal*)c->attr->ItemAt(1))->text;
		if (cur->Compare(last->String()) != 0) {
			last = cur;
			n++;
		}
	}
	delete l;
	return n;
}
void
ShortcutsSpec::_UpdateIconBitmap()
{
	BString firstWord = ParseArgvZeroFromString(fCommand);

	// Only need to change if the first word has changed...
	if (fLastBitmapName == NULL || firstWord.Length() == 0
		|| firstWord.Compare(fLastBitmapName)) {
		if (firstWord.ByteAt(0) == '*')
			fBitmapValid = IsValidActuatorName(&firstWord.String()[1]);
		else {
			fBitmapValid = false; // default till we prove otherwise!

			if (firstWord.Length() > 0) {
				delete [] fLastBitmapName;
				fLastBitmapName = new char[firstWord.Length() + 1];
				strcpy(fLastBitmapName, firstWord.String());

				BEntry progEntry(fLastBitmapName, true);
				if ((progEntry.InitCheck() == B_NO_ERROR)
					&& (progEntry.Exists())) {
					BNode progNode(&progEntry);
					if (progNode.InitCheck() == B_NO_ERROR) {
						BNodeInfo progNodeInfo(&progNode);
						if ((progNodeInfo.InitCheck() == B_NO_ERROR)
						&& (progNodeInfo.GetTrackerIcon(&fBitmap, B_MINI_ICON)
							== B_NO_ERROR)) {
							fBitmapValid = fBitmap.IsValid();
						}
					}
				}
			}
		}
	}
}
/*	isAudioDisc
*	checks if selected files are audio files, and greps the playtime of them
*	when all files audio files
*	returns true if audio disc
*/
bool
ProjectTypeSelector::isAudioDisc()
{
	BString *FileType;
	
	for(int i = 0; i < TypeList->CountItems(); i++) {
		FileType = (BString*)TypeList->ItemAt(i);
		if(FileType->Compare("audio", 5) != 0)
			return false;
	}
	
	entry_ref ref;
	BMediaFile *mediaFile;
	bigtime_t time = 0;
	
	for(int i = 0; i < FileList->CountItems(); i++){
		get_ref_for_path(((BString*)FileList->ItemAt(i))->String(), &ref);
		mediaFile = new BMediaFile(&ref);
		BMediaTrack *track = NULL;
		
		for(int j = 0; j < mediaFile->CountTracks(); j++){
			track = mediaFile->TrackAt(j);
			time = track->Duration();
			intPlayTime += ((int)time / 1000000);
		}
		
		delete mediaFile;
	}
		
	return true;
}
Example #9
0
void 
BNavigator::GoTo()
{
	BString pathname = fLocation->Text();

	if (pathname.Compare("") == 0)
		pathname = "/";

	BEntry entry;
	entry_ref ref;

	if (entry.SetTo(pathname.String()) == B_OK
		&& !FSIsDeskDir(&entry)
		&& entry.GetRef(&ref) == B_OK) {
		BMessage message(kSwitchDirectory);
		message.AddRef("refs", &ref);
		message.AddInt32("action", kActionLocation);
		Window()->PostMessage(&message);		
	} else {
		BPath path;
		
		if (Window()
			&& Window()->TargetModel()) {
			Window()->TargetModel()->GetPath(&path);
			fLocation->SetText(path.Path());
		}
	}
}
Example #10
0
void BYdpMainWindow::NewClipData(void) {
	const char *text; 
	int32 textLen; 
	BString result;
	static BString lastResult;
	BMessage *clip = (BMessage *)NULL; 
	int i;
	char c;

	if (!config->clipboardTracking)
		return;

	if (be_clipboard->Lock()) { 
		if ((clip = be_clipboard->Data()))
			clip->FindData("text/plain", B_MIME_TYPE,(const void **)&text, &textLen);
		be_clipboard->Unlock();
		result = "";
		for (i=0;i<textLen;i++) {
			c = text[i];
			if ((c!=' ')&&(c!='.')&&(c!=',')&&(c!='\t')&&(c!='\'')&&(c!='"'))
				result += c;
		}
		if (lastResult.Compare(result) != 0) {
			lastResult = result;
			wordInput->SetText(result.String());
			if (config->setFocusOnSelf)
				this->Activate();
		}
//		const char *tmp = result.String();
//		printf("got:%s:clip:%i,%i,%i\n",tmp,tmp[0],tmp[1],tmp[2]);
	}
}
Example #11
0
static bool
add_private_namespace(BString& name)
{
	if (name.Compare("_", 1) != 0)
		return false;

	name.Prepend("BPrivate::");
	return true;
}
Example #12
0
void
Tranquility::MessageReceived(BMessage *message)
{
	switch (message->what) {
		case kMsgForward:
		case kMsgUpdate:
		{
			if (fMessenger)
				fMessenger->SendMessage(message);
			break;
		}

		case kMsgBitmapData:
		{
			syslog(LOG_DEBUG, "Tranquility: received kMsgBitmapData message");
			BBitmap *bitmap = dynamic_cast<BBitmap*>(BBitmap::Instantiate(message));
			if (bitmap != NULL) {
				fBrowserWindow->SetViewBitmap(bitmap);
				delete bitmap;
			} else {
				syslog(LOG_DEBUG, "Tranquility: bitmap from message is not valid!");
			}
			// Code to create the bitmap from raw data and a bytes per row (bpr) value
			/*int32 length = 0;
			const void *data;
			if (message->FindData("data", B_RAW_TYPE, &data, &length) == B_OK) {
				int32 bpr;
				if (message->FindInt32("bpr", &bpr) == B_OK) {
					syslog(LOG_DEBUG, "Tranquility: got bpr from kMsgBitmapData message");
					BBitmap bitmap(fBrowserWindow->Bounds(), B_RGB32);
					bitmap.ImportBits(data, length, bpr, 0, B_RGB32);
					fBrowserWindow->SetViewBitmap(&bitmap);
				}
			}*/
			break;
		}

		case B_SOME_APP_QUIT:
		{
			BString sig;
			if (message->FindString("be:signature", &sig) == B_OK) {
				if (sig.Compare(kRenderAppSignature) == 0) {
					BAlert* alert = new BAlert("Error!",
						"The render process has quit!", "Damn!");
					alert->Go();
					fMessenger = NULL;
				}
			}
			break;
		}
		default:
			BApplication::MessageReceived(message);
			break;
	}
}
Example #13
0
bool
RuleRunner::IsMatch(const BMessage &test, const entry_ref &ref)
{
	BString testname;
	if (test.FindString("name",&testname) != B_OK)
	{
		debugger("Couldn't find test name in RuleRunner::IsMatch");
		return false;
	}
	
	if (testname.Compare("Name") == 0)
		return IsNameMatch(test,ref);
	else if (testname.Compare("Size") == 0)
		return IsSizeMatch(test,ref);
	else if (testname.Compare("Location") == 0)
		return IsLocationMatch(test,ref);
	else if (testname.Compare("Type") == 0)
		return IsTypeMatch(test,ref);
	else if (testname.Compare("Last Changed") == 0)
		return IsModifiedMatch(test,ref);
	else if (testname.Compare("Attribute") == 0)
		return IsAttributeMatch(test,ref);
		
	return false;
}
/*	isVideoDisc
*	checks if selected files are video files
*	if yes, returns true
*/
bool
ProjectTypeSelector::isVideoDisc()
{
	BString *FileType;

	for(int i = 0; i < TypeList->CountItems(); i++) {
		FileType = (BString*)TypeList->ItemAt(i);
		if(FileType->Compare("video", 5) != 0)
			return false;
	}

	return true;
}
Example #15
0
bool
Project::HasSystemInclude(const char *path)
{
	if (!path)
		return false;
	
	for (int32 i = 0; i < fSystemIncludeList.CountItems(); i++)
	{
		BString *str = fSystemIncludeList.ItemAt(i);
		if (str && str->Compare(path) == 0)
			return true;
	}
	return false;
}
Example #16
0
status_t NotifyFilter::ProcessMailMessage(BPositionIO**, BEntry*, BMessage*headers, BPath*path, const char*)
{
	if (callback == NULL) {
		callback = new NotifyCallback(strategy,_runner,this);
		_runner->RegisterProcessCallback(callback);
	}

	if (!headers->FindBool("ENTIRE_MESSAGE")) {
		BString status;
		headers->FindString("STATUS", &status);
		// do not notify about auto-read messages
		if (status.Compare("Read") != 0)
			callback->num_messages ++;
	}

	return B_OK;
}
Example #17
0
status_t
BDefaultChoiceList::RemoveChoice(const char *toRemove)
{
	BString *string;
	int32 choices = fList->CountItems();
	for (int32 i = 0; i < choices; i++) {
		string = fList->ItemAt(i);
		if (!string->Compare(toRemove)) {
			fList->RemoveItemAt(i);
			if (fOwner)
				fOwner->ChoiceListUpdated();

			return B_OK;
		}		
	}
	return B_ERROR;
}
void
TBarView::AddExpandedItem(const char* signature)
{
	bool shouldAdd = true;

	for (int32 i = 0; i < fExpandedItems.CountItems(); i++) {
		BString *itemSig = static_cast<BString*>(fExpandedItems.ItemAt(i));
		if (itemSig->Compare(signature) == 0) {
			// already in the list, don't add the signature
			shouldAdd = false;
			break;
		}
	}

	if (shouldAdd)
		fExpandedItems.AddItem(static_cast<void*>(new BString(signature)));
}
Example #19
0
void _OwqRow::SetRef(const entry_ref& ref)
{
	delete mRef;
	mRef = new entry_ref(ref);
	
	BString		filename("<drop query or folder here>");
	if( mRef ) {
		BPath	path(mRef);
		if( path.InitCheck() == B_OK ) {
			filename = path.Path();
			if ( mName.Length() < 1 || (mName.Compare(DEFAULT_ROW_NAME) == 0) ) {
				mName = path.Leaf();
				SetField(new BStringField( mName.String() ), 1);
			}
		}
	}
	SetField( new BStringField( filename.String() ), 2 );
}
	static int _CompareSourceFileNames(LocatableFile* a, LocatableFile* b)
	{
		if (a == b)
			return 0;

		if (a == NULL)
			return 1;
		if (b == NULL)
			return -1;

		BString pathA;
		a->GetPath(pathA);

		BString pathB;
		b->GetPath(pathB);

		return pathA.Compare(pathB);
	}
Example #21
0
bool
DecisionProvider::YesNoDecisionNeeded(const BString& description,
	const BString& question, const BString& yes, const BString& no,
	const BString& defaultChoice)
{
	if (description.Length() > 0)
		printf("%s\n", description.String());

	bool haveDefault = defaultChoice.Length() > 0;

	while (true) {
		printf("%s [%s/%s]%s: ", question.String(), yes.String(), no.String(),
			haveDefault
				? (BString(" (") << defaultChoice << ") ").String() : "");

		if (!fInteractive) {
			printf("%s\n", yes.String());
			return true;
		}

		char buffer[32];
		if (fgets(buffer, 32, stdin)) {
			if (haveDefault &&  (buffer[0] == '\n' || buffer[0] == '\0'))
				return defaultChoice == yes;
			int length = strlen(buffer);
			for (int i = 1; i <= length; ++i) {
				if (yes.ICompare(buffer, i) == 0) {
					if (no.ICompare(buffer, i) != 0)
						return true;
				} else if (no.Compare(buffer, i) == 0) {
					if (yes.ICompare(buffer, i) != 0)
						return false;
				} else
					break;
			}
			fprintf(stderr, "*** please enter '%s' or '%s'\n", yes.String(),
				no.String());
		}
	}
}
/*	isCue
*	checks if selected file is a cue file (checks by file extension)
*	if yes, returns true
*/
bool
ProjectTypeSelector::isCue()
{
	BString *SelectedFile = (BString*)FileList->FirstItem();
	BString SelectedFileTMP;
	BString FileExtension;
	BString tmp;
	
	//get file extension
	SelectedFile->CopyInto(SelectedFileTMP, 0, (int)SelectedFile->Length());
	SelectedFileTMP.RemoveAll("/");
	for(int i = 3; i > 0; i--) {
		tmp.SetTo(SelectedFileTMP.ByteAt((SelectedFileTMP.Length() - i)), 1);
		FileExtension.Insert(tmp.String(), FileExtension.Length());
	}
	
	FileExtension.ToUpper();
	if(FileExtension.Compare("CUE") == 0)
		return true;
	
	return false;
}
/*	isVolume
*	checks if selected file is a volume
*	if yes, returns true
*/	
bool
ProjectTypeSelector::isVolume()
{
	BString *SelectedFile = (BString*)FileList->FirstItem();
	BString SelectedFileTMP;
	BVolumeRoster objVolumeRoster;
	objVolumeRoster.Rewind();
	BVolume objVolume;
	char chVolumeName[B_FILE_NAME_LENGTH];
	
	SelectedFile->CopyInto(SelectedFileTMP, 0, (int)SelectedFile->Length());	
	SelectedFileTMP.RemoveAll("/");
	while(objVolumeRoster.GetNextVolume(&objVolume) != B_BAD_VALUE) {
		objVolume.GetName(chVolumeName);
		
		if(SelectedFileTMP.Compare(chVolumeName) == 0 && objVolume.IsReadOnly()) {
			fSizeOfFiles = objVolume.Capacity();
			return true;
		}
	}
	
	return false;
}
Example #24
0
void
TBarView::ExpandItems()
{
	if (fExpandoMenuBar == NULL || !fVertical || fState != kExpandoState
		|| !fBarApp->Settings()->superExpando
		|| fExpandedItems.CountItems() <= 0) {
		return;
	}

	// Start at the 'bottom' of the list working up.
	// Prevents being thrown off by expanding items.
	for (int32 i = fExpandoMenuBar->CountItems() - 1; i >= 0; i--) {
		TTeamMenuItem* teamItem
			= dynamic_cast<TTeamMenuItem*>(fExpandoMenuBar->ItemAt(i));

		if (teamItem != NULL) {
			// Start at the 'bottom' of the fExpandedItems list working up
			// matching the order of the fExpandoMenuBar list in the outer loop.
			for (int32 j = fExpandedItems.CountItems() - 1; j >= 0; j--) {
				BString* itemSig =
					static_cast<BString*>(fExpandedItems.ItemAt(j));

				if (itemSig->Compare(teamItem->Signature()) == 0) {
					// Found it, expand the item and delete signature from
					// the list so that we don't consider it for later items.
					teamItem->ToggleExpandState(false);
					fExpandedItems.RemoveItem(j);
					delete itemSig;
					break;
				}
			}
		}
	}

	// Clean up the expanded items list
	RemoveExpandedItems();
}
Example #25
0
// NewProjectWindow::MessageReceived -- receives messages
void NewProjectWindow::MessageReceived (BMessage *message)
{
	switch(message->what)
	{
		case BTN_ADD: // aka Create or Save
			{
				//printf ("txtNewProject->Text() - %s\n\n",txtNewProject->Text());
				BString tmp = "Untitled";
				if (tmp.Compare(txtNewProject->Text()) != 0)
				{
					if (PanelType == 1) {
						CreateExistingProject();
					} else {
						CreateNewProject();
					}
					Lock();
					Quit();
				} else {
					// Tip 2 - New Project Name - something other than untitled ;)
					TipNumber = 2;
					new HelpTipWindow(BRect(0.0, 0.0, 350.0, 120.0));
				}
			}
			break;
		case BTN_CANCEL:
			{
				// This Window is no longer needed.
				Lock();
		    	Quit();
		    }
			break;
		default:
			BWindow::MessageReceived(message);
			break;
	}
}
Example #26
0
/*static*/ bool
Playlist::_IsQuery(const BString& mimeString)
{
	return mimeString.Compare(BQueryFile::MimeType()) == 0;
}
Example #27
0
void
App::MessageReceived(BMessage *msg)
{
	switch (msg->what) {
		case B_SOME_APP_QUIT: {
			BString string;
			if (msg->FindString("be:signature",&string) != B_OK)
				return;
			
			// See if the signature belongs to an app that has requested
			// a restart
			for (int32 i = 0; i < fSignatureList.CountItems(); i++) {
				BString *item = (BString*) fSignatureList.ItemAt(i);
				if (string.Compare(*item) == 0) {
					fSignatureList.RemoveItem(item);
					delete item;
					
					be_roster->Launch(string.String());
					return;
				}
			}
			
			int i = 0;
			while (gSignatures[i]) {
				// Checking to see if it's one of the supported signatures
				// and if it is, add a relaunch message to the queue which is
				// to be posted here at the
				if (string.Compare(gSignatures[i]) == 0) {
					BMessage *launchmsg = new BMessage(M_RELAUNCH_DESKBAR + i);
					fRelaunchQueue.AddMessage(launchmsg);
					
					release_sem(sRelaunchSem);
					acquire_sem(sRelaunchSem);
				}
				i++;
			}
			break;
		}
		case B_SERVICES_DAEMON_RESTART: {
			BString signature;
			if (msg->FindString("signature",&signature) == B_OK)
				fSignatureList.AddItem(new BString(signature));
			break;
		}
		case M_RELAUNCH_DESKBAR: {
			be_roster->Launch(gSignatures[msg->what - M_RELAUNCH_DESKBAR]);
			break;
		}
		case M_RELAUNCH_TRACKER: {
			be_roster->Launch(gSignatures[msg->what - M_RELAUNCH_DESKBAR]);
			break;
		}
		case M_RELAUNCH_MAIL: {
			be_roster->Launch(gSignatures[msg->what - M_RELAUNCH_DESKBAR]);
			break;
		}
		case M_RELAUNCH_PRINT: {
			be_roster->Launch(gSignatures[msg->what - M_RELAUNCH_DESKBAR]);
			break;
		}
		case M_RELAUNCH_AUDIO: {
			be_roster->Launch(gSignatures[msg->what - M_RELAUNCH_DESKBAR]);
			break;
		}
		case M_RELAUNCH_MEDIA_ADDONS:
		case M_RELAUNCH_MEDIA: {
			shutdown_media_server();
			launch_media_server();
			break;
		}
		case M_RELAUNCH_MIDI: {
			be_roster->Launch(gSignatures[msg->what - M_RELAUNCH_DESKBAR]);
			break;
		}
		
		default:
			BApplication::MessageReceived(msg);
	}
}
/*
* Given a single line of the output of db_delta.py
* Figures out what to do and does it.
* (adds and removes files and directories)
*/
int
App::parse_command(BString command)
{
  command.RemoveAll("\n"); //remove trailing whitespace
  if(command.Compare("RESET") == 0)
  {
    printf("Burn Everything. 8D\n");

    status_t err = stop_watching(be_app_messenger);
    if(err != B_OK) printf("stop_watching error: %s\n",strerror(err));

    BDirectory dir = BDirectory(local_path_string);
    rm_rf(&dir);

    BString str = BString("/"); //create_local_path wants a remote path 
    create_local_directory(&str);

    this->recursive_watch(&dir);
  }
  else if(command.Compare("FILE ",5) == 0)
  {
    BString path, dirpath, partial_path;
    BPath *bpath;
    int32 last_space = command.FindLast(" ");
    command.CopyInto(path,5,last_space - 5);

    path.CopyInto(dirpath,0,path.FindLast("/"));

    create_local_directory(&dirpath);
    //TODO fix watching new dirs
    bpath = new BPath(db_to_local_filepath(path.String()).String());
    BEntry new_file = BEntry(bpath->Path());
    if(new_file.InitCheck() && new_file.Exists()) {
      this->new_paths.AddItem((void*)bpath);
    } else {
      this->edited_paths.AddItem((void*)bpath);
    }

    printf("create a file at |%s|\n",path.String());
    char *argv[3];
    argv[0] = "db_get.py";
    char not_const1[path.CountChars() + 1];
    strcpy(not_const1,path.String());
    argv[1] = not_const1;
    BString tmp = db_to_local_filepath(path.String());
    char not_const2[tmp.CountChars() + 1]; //plus one for null
    strcpy(not_const2,tmp.String());
    argv[2] = not_const2;

    //create/update file
    //potential problem: takes awhile to do this step
    // having watching for dir turned off is risky.    
    BString * b = run_python_script(argv,3);
    delete b;

    //start watching the new/updated file
    node_ref nref;
    new_file = BEntry(db_to_local_filepath(path.String()).String());
    new_file.GetNodeRef(&nref);
    status_t err = watch_node(&nref,B_WATCH_STAT,be_app_messenger);

    BString parent_rev;
    command.CopyInto(parent_rev,last_space + 1, command.CountChars() - (last_space+1));
    BNode node = BNode(db_to_local_filepath(path.String()).String());
    set_parent_rev(&node,&parent_rev);
  }
  else if(command.Compare("FOLDER ",7) == 0)
  {
    BString path;
    command.CopyInto(path,7,command.FindLast(" ") - 7);

    //ignore the creation message
    BPath bpath = BPath(db_to_local_filepath(path.String()).String());
    BPath *actually_exists = find_existing_subpath(&bpath);
    this->new_paths.AddItem((void*)actually_exists);

    //create all nescessary dirs in path
    printf("create a folder at |%s|\n", path.String());
    create_local_directory(&path);

    //start watching the new dir
    BDirectory existing_dir = BDirectory(actually_exists->Path());
    recursive_watch(&existing_dir);
  }
  else if(command.Compare("REMOVE ",7) == 0)
  {
    //TODO: deal with Dropbox file paths being case-insensitive
    //which here means all lower case
    BString path;
    command.CopyInto(path,7,command.Length() - 7);

    const char * pathstr = db_to_local_filepath(path.String()).String();
    BPath *bpath = new BPath(pathstr);
    //TODO: check if it exists...
    this->removed_paths.AddItem((void*)bpath);

    printf("Remove whatever is at |%s|\n", pathstr);

    BEntry entry = BEntry(pathstr);
    status_t err = entry.Remove();
    if(err != B_OK)
      printf("Removal error: %s\n", strerror(err));
  }
  else
  {
    printf("Did not recognize command.\n");
    return B_ERROR;
  }
  return B_OK;
}
Example #29
0
PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
    : BlockingWindow(BRect(0, 0, 100, 100), "Page setup",
                     B_TITLED_WINDOW_LOOK,
                     B_MODAL_APP_WINDOW_FEEL,
                     B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE
                     | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE),
      fSetupMsg(msg),
      fPrinterDirName(printerName)
{
    if (printerName)
        SetTitle(BString(printerName).Append(" Page setup").String());

    // load orientation
    if (fSetupMsg->FindInt32("orientation", &fCurrentOrientation) != B_OK)
        fCurrentOrientation = PrinterDriver::PORTRAIT_ORIENTATION;

    // load page rect
    BRect page;
    float width = letter_width;
    float height = letter_height;
    if (fSetupMsg->FindRect("preview:paper_rect", &page) == B_OK) {
        width = page.Width();
        height = page.Height();
    } else {
        page.Set(0, 0, width, height);
    }

    BString label;
    if (fSetupMsg->FindString("preview:paper_size", &label) != B_OK)
        label = "Letter";

    // Load units
    int32 units;
    if (fSetupMsg->FindInt32("units", &units) != B_OK)
        units = kUnitInch;

    // re-calculate the margin from the printable rect in points
    BRect margin = page;
    if (fSetupMsg->FindRect("preview:printable_rect", &margin) == B_OK) {
        margin.top -= page.top;
        margin.left -= page.left;
        margin.right = page.right - margin.right;
        margin.bottom = page.bottom - margin.bottom;
    } else {
        margin.Set(28.34, 28.34, 28.34, 28.34);		// 28.34 dots = 1cm
    }


    fMarginView = new MarginView(int32(width), int32(height), margin,
                                 MarginUnit(units));

    BPopUpMenu* pageSizePopUpMenu = new BPopUpMenu("Page size");
    pageSizePopUpMenu->SetRadioMode(true);

    fPageSizeMenu = new BMenuField("page_size", "Page size:", pageSizePopUpMenu);
    fPageSizeMenu->Menu()->SetLabelFromMarked(true);

    for (int32 i = 0; pageFormat[i].label != NULL; i++) {
        BMessage* message = new BMessage(PAGE_SIZE_CHANGED);
        message->AddFloat("width", pageFormat[i].width);
        message->AddFloat("height", pageFormat[i].height);
        BMenuItem* item = new BMenuItem(pageFormat[i].label, message);
        pageSizePopUpMenu->AddItem(item);

        if (label.Compare(pageFormat[i].label) == 0)
            item->SetMarked(true);
    }

    BPopUpMenu* orientationPopUpMenu = new BPopUpMenu("Orientation");
    orientationPopUpMenu->SetRadioMode(true);

    fOrientationMenu = new BMenuField("orientation", "Orientation:",
                                      orientationPopUpMenu);
    fOrientationMenu->Menu()->SetLabelFromMarked(true);

    for (int32 i = 0; orientation[i].label != NULL; i++) {
        BMessage* message = new BMessage(ORIENTATION_CHANGED);
        message->AddInt32("orientation", orientation[i].orientation);
        BMenuItem* item = new BMenuItem(orientation[i].label, message);
        orientationPopUpMenu->AddItem(item);

        if (fCurrentOrientation == orientation[i].orientation)
            item->SetMarked(true);
    }

    float scale0;
    BString scale;
    if (fSetupMsg->FindFloat("scale", &scale0) == B_OK)
        scale << (int)scale0;
    else
        scale = "100";

    fScaleControl = new BTextControl("scale", "Scale [%]:",
                                     scale.String(), NULL);

    for (uint32 i = 0; i < '0'; i++)
        fScaleControl->TextView()->DisallowChar(i);

    for (uint32 i = '9' + 1; i < 255; i++)
        fScaleControl->TextView()->DisallowChar(i);

    fScaleControl->TextView()->SetMaxBytes(3);

    BBox *separator = new BBox("separator");
    separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1));

    BButton *cancel = new BButton("cancel", "Cancel", new BMessage(CANCEL_MSG));

    BButton *ok = new BButton("ok", "OK", new BMessage(OK_MSG));
    ok->MakeDefault(true);

    BGridView* settings = new BGridView();
    BGridLayout* settingsLayout = settings->GridLayout();
    settingsLayout->AddItem(fPageSizeMenu->CreateLabelLayoutItem(), 0, 0);
    settingsLayout->AddItem(fPageSizeMenu->CreateMenuBarLayoutItem(), 1, 0);
    settingsLayout->AddItem(fOrientationMenu->CreateLabelLayoutItem(), 0, 1);
    settingsLayout->AddItem(fOrientationMenu->CreateMenuBarLayoutItem(), 1, 1);
    settingsLayout->AddItem(fScaleControl->CreateLabelLayoutItem(), 0, 2);
    settingsLayout->AddItem(fScaleControl->CreateTextViewLayoutItem(), 1, 2);
    settingsLayout->SetSpacing(0, 0);

    SetLayout(new BGroupLayout(B_VERTICAL));
    AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
             .AddGroup(B_HORIZONTAL, 5, 1)
             .AddGroup(B_VERTICAL, 0, 1.0f)
             .Add(fMarginView)
             .AddGlue()
             .End()
             .AddGroup(B_VERTICAL, 0, 1.0f)
             .Add(settings)
             .AddGlue()
             .End()
             .End()
             .Add(separator)
             .AddGroup(B_HORIZONTAL, 10, 1.0f)
             .AddGlue()
             .Add(cancel)
             .Add(ok)
             .End()
             .SetInsets(10, 10, 10, 10)
            );

    BRect winFrame(Frame());
    BRect screenFrame(BScreen().Frame());
    MoveTo((screenFrame.right - winFrame.right) / 2,
           (screenFrame.bottom - winFrame.bottom) / 2);
}
Example #30
0
/*static*/ bool
Playlist::_IsBinaryPlaylist(const BString& mimeString)
{
	return mimeString.Compare(kBinaryPlaylistMimeString) == 0;
}