BPath BPrinter::_DriverPath() const { BString driverName(_ReadAttribute(PSRV_PRINTER_ATTR_DRIVER_NAME)); if (driverName.Length() <= 0) return BPath(); directory_which directories[] = { B_USER_NONPACKAGED_ADDONS_DIRECTORY, B_USER_ADDONS_DIRECTORY, B_SYSTEM_NONPACKAGED_ADDONS_DIRECTORY, B_SYSTEM_ADDONS_DIRECTORY }; BPath path; driverName.Prepend("Print/"); for (int32 i = 0; i < sizeof(directories) / sizeof(directories[0]); ++i) { if (find_directory(directories[i], &path) == B_OK) { path.Append(driverName.String()); BEntry driver(path.Path()); if (driver.InitCheck() == B_OK && driver.Exists() && driver.IsFile()) return path; } } return BPath(); }
entry_ref FindFile(entry_ref folder, const char *name) { entry_ref ref,returnRef; if (!folder.name || !name) return returnRef; BDirectory dir(&folder); if (dir.InitCheck() != B_OK) return returnRef; dir.Rewind(); while (dir.GetNextRef(&ref) == B_OK) { struct stat statData; stat(BPath(&ref).Path(),&statData); // Is a directory? if (S_ISDIR(statData.st_mode)) { entry_ref innerref = FindFile(ref,name); if (innerref.device != -1 && innerref.directory != -1) return innerref; } } BEntry entry; if (dir.FindEntry(name,&entry) == B_OK) entry.GetRef(&returnRef); return returnRef; }
status_t DeleteAction(const BMessage &action, entry_ref &ref) { BEntry entry(&ref); status_t status = entry.Remove(); if (status == B_OK) printf("\tDeleted %s\n",BPath(ref.name).Path()); else { printf("\tCouldn't delete %s. Stopping here.\n\t\tError Message: %s\n", BPath(ref.name).Path(),strerror(status)); } return entry.Remove(); }
void DownloadWindow::_DownloadStarted(BWebDownload* download) { download->Start(BPath(fDownloadPath.String())); int32 finishedCount = 0; int32 missingCount = 0; int32 index = 0; for (int32 i = fDownloadViewsLayout->CountItems() - 1; BLayoutItem* item = fDownloadViewsLayout->ItemAt(i); i--) { DownloadProgressView* view = dynamic_cast<DownloadProgressView*>( item->View()); if (!view) continue; if (view->URL() == download->URL()) { index = i; view->RemoveSelf(); delete view; continue; } if (view->IsFinished()) finishedCount++; if (view->IsMissing()) missingCount++; } fRemoveFinishedButton->SetEnabled(finishedCount > 0); fRemoveMissingButton->SetEnabled(missingCount > 0); DownloadProgressView* view = new DownloadProgressView(download); if (!view->Init()) { delete view; return; } fDownloadViewsLayout->AddView(index, view); // Scroll new download into view if (BScrollBar* scrollBar = fDownloadsScrollView->ScrollBar(B_VERTICAL)) { float min; float max; scrollBar->GetRange(&min, &max); float viewHeight = view->MinSize().height + 1; float scrollOffset = min + index * viewHeight; float scrollBarHeight = scrollBar->Bounds().Height() - 1; float value = scrollBar->Value(); if (scrollOffset < value) scrollBar->SetValue(scrollOffset); else if (scrollOffset + viewHeight > value + scrollBarHeight) { float diff = scrollOffset + viewHeight - (value + scrollBarHeight); scrollBar->SetValue(value + diff); } } _SaveSettings(); SetWorkspaces(B_CURRENT_WORKSPACE); if (IsHidden()) Show(); }
BPath DjVuApp::Path(const char *dir) { app_info inf; be_app->GetAppInfo(&inf); BPath bpath = BPath(&(inf.ref)); BPath par; bpath.GetParent(&par); par.Append(dir); return(par); }
BPath* find_existing_subpath(BPath *fullpath) { if(exists(fullpath)) return new BPath(*fullpath); BPath *current; BPath previous = BPath(*fullpath); previous.GetParent(current); while(!(exists(current))) { current->GetParent(&previous); BPath *tmp = &previous; previous = *current; current = tmp; } return new BPath(previous); }
void IncludeList::RefDropped(entry_ref ref) { RefListItem* item = new RefListItem(ref, REFITEM_OTHER); BString text(BPath(&ref).Path()); text.RemoveFirst(fProjectPath); AddItem(item); item->SetText(text.String()); BMessenger messenger(Parent()); BMessage message(M_DROP_PATH); message.AddString("path", text); messenger.SendMessage(&message); }
void Fenster::Help() { app_info myAppInfo; be_app->GetAppInfo(&myAppInfo); BPath HelpFilePath; BPath(&myAppInfo.ref).GetParent(&HelpFilePath); HelpFilePath.Append(HELP_FILE); entry_ref ref; char Signatur[B_MIME_TYPE_LENGTH]; BMimeType("text/html").GetPreferredApp(Signatur); BMimeType(Signatur).GetAppHint(&ref); if ( (BPath(&ref).Path()==NULL) || (!BEntry(HelpFilePath.Path()).Exists()) ) { BAlert* myAlert = new BAlert(NULL, MESSAGE_NOHELP, STR_OK); myAlert->Go(); return; } BString Befehl(BPath(&ref).Path()); Befehl.Append(" file://").Append(HelpFilePath.Path()).Append(" &"); system(Befehl.String()); };
bool BTheme::SetDirectory(const char *path) { if(path[0]=='.' && strlen(path)>2) { app_info inf; be_app->GetAppInfo(&inf); BPath bpath = BPath(&(inf.ref)); BPath par; bpath.GetParent(&par); par.Append(path+2); ThemesFolder.SetTo(par.Path()); } else ThemesFolder.SetTo(path); return true; }
/* * Given a local file path, * update the corresponding file on Dropbox */ void update_file_in_dropbox(const char * filepath, const char *parent_rev) { char * argv[4]; argv[0] = "db_put.py"; BString db_filepath = local_to_db_filepath(filepath); const char * tmp = db_filepath.String(); char not_const[db_filepath.CountChars()]; strcpy(not_const,tmp); argv[2] = not_const; char not_const2[strlen(filepath)]; strcpy(not_const2,filepath); argv[1] = not_const2; char not_const3[strlen(parent_rev)]; strcpy(not_const3,parent_rev); argv[3] = not_const3; BString *result = run_python_script(argv,4); BString *real_path = parse_path(result); BString *new_parent_rev = parse_parent_rev(result); delete result; printf("path:|%s|\nparent_rev:|%s|\n",real_path->String(),new_parent_rev->String()); BNode node = BNode(filepath); set_parent_rev(&node,new_parent_rev); delete new_parent_rev; BEntry entry = BEntry(filepath); BPath old_path; entry.GetPath(&old_path); BPath new_path = BPath(db_to_local_filepath(real_path->String()).String()); printf("Should I move %s to %s?\n", old_path.Path(), new_path.Path()); if(strcmp(new_path.Leaf(),old_path.Leaf()) != 0) { printf("moving %s to %s\n", old_path.Leaf(), new_path.Leaf()); BEntry entry = BEntry(old_path.Path()); //entry for local path status_t err = entry.Rename(new_path.Leaf(),true); if(err != B_OK) printf("error moving: %s\n",strerror(err)); } delete real_path; }
void App::OpenPartner(entry_ref ref) { entry_ref partnerRef = GetPartnerRef(ref); DPath refpath(BPath(&ref).Path()); if (partnerRef.name) { OpenFile(partnerRef); return; } BString errmsg; errmsg << "Couldn't find a partner file for " << ref.name << " in " << refpath.GetFolder() << "/ ."; ShowAlert(errmsg.String()); }
void ProjectSettingsWindow::AddInclude(const entry_ref& ref) { BString path(BPath(&ref).Path()); // Make any subfolders of the project's parent folder into relative paths if (path[0] == '/') { BString projpath = fProject->GetPath().GetFolder(); projpath << '/'; if (path.FindFirst(projpath) == 0) path.RemoveFirst(projpath); } if (!fProject->HasLocalInclude(path.String())) { fProject->AddLocalInclude(path.String()); fIncludeList->AddItem(new BStringItem(path.String())); } }
void App::OpenPartner(entry_ref ref) { entry_ref partnerRef = GetPartnerRef(ref); DPath refpath(BPath(&ref).Path()); if (partnerRef.name) { OpenFile(partnerRef); return; } BString errmsg = B_TRANSLATE( "Couldn't find a partner file for %refname% in %reffolder%/."); errmsg.ReplaceFirst("%refname%", ref.name); errmsg.ReplaceFirst("%reffolder%", refpath.GetFolder()); ShowAlert(errmsg.String()); }
bool Project::IsProject(const entry_ref &ref) { BNode node(&ref); BString type; node.ReadAttrString("BEOS:TYPE",&type); if (type.CountChars() > 0 && type == PROJECT_MIME_TYPE) return true; BString extension = BPath(&ref).Path(); int32 pos = extension.FindLast("."); if (pos >= 0) { extension = extension.String() + pos; if (extension.ICompare(".pld") == 0) return true; } return false; }
BBitmap* NotificationView::_ReadNodeIcon(const char* fileName, icon_size size) { BEntry entry(fileName, true); entry_ref ref; entry.GetRef(&ref); BNode node(BPath(&ref).Path()); BBitmap* ret = new BBitmap(BRect(0, 0, (float)size - 1, (float)size - 1), B_RGBA32); if (BIconUtils::GetIcon(&node, kIconAttribute, kSmallIconAttribute, kLargeIconAttribute, size, ret) != B_OK) { delete ret; ret = NULL; } return ret; }
entry_ref FindProject(entry_ref folder, const char *name) { printf("Searching for %s in folder %s\n", name, folder.name); entry_ref ref,returnRef; if (!folder.name || !name) return returnRef; // Because projects can now have source control folders, skip the // internal folders for Git, Mercurial, Subversion, and CVS if (strcmp(folder.name, ".hg") == 0 || strcmp(folder.name, ".git") == 0 || strcmp(folder.name, ".svn") == 0 || strcmp(folder.name, "CVS") == 0) return returnRef; BDirectory dir(&folder); if (dir.InitCheck() != B_OK) return returnRef; dir.Rewind(); while (dir.GetNextRef(&ref) == B_OK) { struct stat statData; stat(BPath(&ref).Path(),&statData); // Is a directory? if (S_ISDIR(statData.st_mode)) { entry_ref innerref = FindFile(ref,name); if (innerref.device != -1 && innerref.directory != -1) return innerref; } } BEntry entry; if (dir.FindEntry(name,&entry) == B_OK) entry.GetRef(&returnRef); return returnRef; }
TeamListItem::TeamListItem(team_info &teamInfo) : fTeamInfo(teamInfo), fAppInfo(), fMiniIcon(BRect(0, 0, 15, 15), B_RGBA32), fLargeIcon(BRect(0, 0, 31, 31), B_RGBA32), fFound(false), fRefusingToQuit(false) { int32 cookie = 0; image_info info; if (get_next_image_info(teamInfo.team, &cookie, &info) == B_OK) { fPath = BPath(info.name); BNode node(info.name); BNodeInfo nodeInfo(&node); nodeInfo.GetTrackerIcon(&fMiniIcon, B_MINI_ICON); nodeInfo.GetTrackerIcon(&fLargeIcon, B_LARGE_ICON); } if (be_roster->GetRunningAppInfo(fTeamInfo.team, &fAppInfo) != B_OK) fAppInfo.signature[0] = '\0'; CacheLocalizedName(); }
void HWindow::MessageReceived(BMessage* message) { switch (message->what) { case M_OTHER_MESSAGE: { BMenuField* menufield = dynamic_cast<BMenuField*>(FindView("filemenu")); if (menufield == NULL) return; BMenu* menu = menufield->Menu(); HEventRow* row = (HEventRow*)fEventList->CurrentSelection(); if (row != NULL) { BPath path(row->Path()); if (path.InitCheck() != B_OK) { BMenuItem* item = menu->FindItem(B_TRANSLATE("<none>")); if (item != NULL) item->SetMarked(true); } else { BMenuItem* item = menu->FindItem(path.Leaf()); if (item != NULL) item->SetMarked(true); } } fFilePanel->Show(); break; } case B_SIMPLE_DATA: case B_REFS_RECEIVED: { entry_ref ref; HEventRow* row = (HEventRow*)fEventList->CurrentSelection(); if (message->FindRef("refs", &ref) == B_OK && row != NULL) { BMenuField* menufield = dynamic_cast<BMenuField*>(FindView("filemenu")); if (menufield == NULL) return; BMenu* menu = menufield->Menu(); // check audio file BNode node(&ref); BNodeInfo ninfo(&node); char type[B_MIME_TYPE_LENGTH + 1]; ninfo.GetType(type); BMimeType mtype(type); BMimeType superType; mtype.GetSupertype(&superType); if (superType.Type() == NULL || strcmp(superType.Type(), "audio") != 0) { beep(); BAlert* alert = new BAlert("", B_TRANSLATE("This is not an audio file."), B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->Go(); break; } // add file item BMessage* msg = new BMessage(M_ITEM_MESSAGE); BPath path(&ref); msg->AddRef("refs", &ref); BMenuItem* menuitem = menu->FindItem(path.Leaf()); if (menuitem == NULL) menu->AddItem(menuitem = new BMenuItem(path.Leaf(), msg), 0); // refresh item fEventList->SetPath(BPath(&ref).Path()); // check file menu if (menuitem != NULL) menuitem->SetMarked(true); } break; } case M_PLAY_MESSAGE: { HEventRow* row = (HEventRow*)fEventList->CurrentSelection(); if (row != NULL) { const char* path = row->Path(); if (path != NULL) { entry_ref ref; ::get_ref_for_path(path, &ref); delete fPlayer; fPlayer = new BFileGameSound(&ref, false); fPlayer->StartPlaying(); } } break; } case M_STOP_MESSAGE: { if (fPlayer == NULL) break; if (fPlayer->IsPlaying()) { fPlayer->StopPlaying(); delete fPlayer; fPlayer = NULL; } break; } case M_EVENT_CHANGED: { const char* path; BMenuField* menufield = dynamic_cast<BMenuField*>(FindView("filemenu")); if (menufield == NULL) return; BMenu* menu = menufield->Menu(); if (message->FindString("path", &path) == B_OK) { BPath path(path); if (path.InitCheck() != B_OK) { BMenuItem* item = menu->FindItem(B_TRANSLATE("<none>")); if (item != NULL) item->SetMarked(true); } else { BMenuItem* item = menu->FindItem(path.Leaf()); if (item != NULL) item->SetMarked(true); } } break; } case M_ITEM_MESSAGE: { entry_ref ref; if (message->FindRef("refs", &ref) == B_OK) fEventList->SetPath(BPath(&ref).Path()); break; } case M_NONE_MESSAGE: { fEventList->SetPath(NULL); break; } default: BWindow::MessageReceived(message); } }
bool ChatWindow::handlesRef( entry_ref & ref ) { return ( strcmp(BPath(&fEntry).Path(),BPath(&ref).Path()) == 0 ); }
void DPath::SetTo(const entry_ref &ref) { SetTo(BPath(&ref).Path()); }
entry_ref GetPartnerRef(entry_ref ref) { DPath refpath(BPath(&ref).Path()); BString ext(refpath.GetExtension()); if (ext.CountChars() < 1) return entry_ref(); BString pathbase = refpath.GetFullPath(); pathbase.Truncate(pathbase.FindLast(".") + 1); const char *cpp_ext[] = { "cpp","c","cxx","cc", NULL }; const char *hpp_ext[] = { "h","hpp","hxx","hh", NULL }; bool isSource = false; bool isHeader = false; int i = 0; while (cpp_ext[i]) { if (ext == cpp_ext[i]) { isSource = true; break; } i++; } if (!isSource) { i = 0; while (hpp_ext[i]) { if (ext == hpp_ext[i]) { isHeader = true; break; } i++; } } else { i = 0; while (hpp_ext[i]) { BString partpath = pathbase; partpath << hpp_ext[i]; BEntry entry(partpath.String()); if (entry.Exists()) { entry_ref header_ref; entry.GetRef(&header_ref); return header_ref; } i++; } } if (isHeader) { i = 0; while (cpp_ext[i]) { BString partpath = pathbase; partpath << cpp_ext[i]; BEntry entry(partpath.String()); if (entry.Exists()) { entry_ref source_ref; entry.GetRef(&source_ref); return source_ref; } i++; } } return entry_ref(); }
void App::OpenFile(entry_ref ref, int32 line) { if (!ref.name) return; BNode node(&ref); BString type; if (node.ReadAttrString("BEOS:TYPE",&type) != B_OK) { update_mime_info(BPath(&ref).Path(),0,0,1); node.ReadAttrString("BEOS:TYPE",&type); } if (type.CountChars() > 0) { if (type == PROJECT_MIME_TYPE || type.FindFirst("text/") != 0) { be_roster->Launch(&ref); return; } } else { BString extension = BPath(&ref).Path(); int32 pos = extension.FindLast("."); if (pos >= 0) { extension = extension.String() + pos; if (extension.ICompare(".cpp") != 0 && extension.ICompare(".h") != 0 && extension.ICompare(".hpp") != 0 && extension.ICompare(".c") != 0) { return; } } } // BMessage msg(B_REFS_RECEIVED); BMessage msg(PALEDIT_OPEN_FILE); msg.AddRef("refs",&ref); if (line >= 0) msg.AddInt32("line",line); if (be_roster->IsRunning(EDITOR_SIGNATURE)) { BMessenger msgr(EDITOR_SIGNATURE); msgr.SendMessage(&msg); } else { DPath path(gAppPath.GetFolder()); path.Append("PalEdit"); entry_ref launchref; BEntry(path.GetFullPath()).GetRef(&launchref); if (be_roster->Launch(&launchref,&msg) != B_OK && be_roster->Launch(EDITOR_SIGNATURE,&msg) != B_OK) be_roster->Launch(&ref); } }
void BeAccessibleWindow::MessageReceived(BMessage* msg) { switch(msg->what) { case COMPACT_DATABASE_MSG: { GlobalSQLMgr->Compact(); break; } case OPEN_DATABASE_MSG: { BString path; if (msg->FindString("path", &path) == B_OK) { OpenDatabase(BPath(path.String())); } break; } case MENU_FILE_NEW_MSG: { fNewFile->Show(); break; } case MENU_FILE_OPEN_MSG: { fOpenFile->Show(); break; } case MENU_FILE_CLOSE_MSG: { CloseDatabase(); break; } case OPEN_BUTTON: { BString name; msg->FindString("TabName", &name); if (name == "Table" || name == "TableList") OpenTable(DATA_VIEW); //else if (name == "Query") break; } case DESIGN_BUTTON: { BString name; msg->FindString("TabName", &name); if (name == "Table") OpenTable(DESIGN_VIEW); //else if (name == "Query") break; } case NEW_BUTTON: { BString name; msg->FindString("TabName", &name); if (name == "Table") NewTable(DESIGN_VIEW); //else if (name == "Query") } case ENABLE_OPEN_BUTTON: { BString listName; msg->FindString("ListName", &listName); if (listName == "TableList") { fTableTab->fOpenButton->SetEnabled(true); fTableTab->fDesignButton->SetEnabled(true); } //else if (listName == "QueryList") break; } case DISABLE_OPEN_BUTTON: { BString listName; msg->FindString("ListName", &listName); if (listName == "TableList") { fTableTab->fOpenButton->SetEnabled(false); fTableTab->fDesignButton->SetEnabled(false); } //else if (listName == "QueryList") break; } case B_QUIT_REQUESTED: { BMessenger(be_app).SendMessage(B_QUIT_REQUESTED); break; } case IMPORT_FILE_REQUESTED_MSG: { fImportFile->SetTarget(BMessenger(this)); fImportFile->Show(); break; } case IMPORT_FILE_MSG: { entry_ref ref; msg->FindRef("refs", &ref); const BEntry entry(&ref, true); BPath dbPath(&entry); BRect frame(200,200,600,700); ImportFileWindow* importWindow = new ImportFileWindow(frame, dbPath.Path()); importWindow->Show(); break; } default: { BWindow::MessageReceived(msg); break; } } }
/* * 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; }
void App::OpenFile(entry_ref ref, int32 line, int32 column) { if (!ref.name) return; BNode node(&ref); BString type; if (node.ReadAttrString("BEOS:TYPE",&type) != B_OK) { update_mime_info(BPath(&ref).Path(),0,0,1); node.ReadAttrString("BEOS:TYPE",&type); } if (type.CountChars() > 0) { if (type == PROJECT_MIME_TYPE || type.FindFirst("text/") != 0) { STRACE(2,("Launching text or project file in roster...\n")); be_roster->Launch(&ref); return; } } else { BString extension = BPath(&ref).Path(); int32 pos = extension.FindLast("."); if (pos >= 0) { extension = extension.String() + pos; if (extension.ICompare(".cpp") != 0 && extension.ICompare(".h") != 0 && extension.ICompare(".hpp") != 0 && extension.ICompare(".c") != 0) { return; } } } BMessage* msg = new BMessage(B_REFS_RECEIVED); msg->AddRef("refs",&ref); if (line >= 0) msg->AddInt32("be:line",line); if (column >= 0) msg->AddInt32("be:column",column); STRACE(2,("Paladin Launching File Ref: %s:%i:%i\n",ref.name,line,column)); /* ANTI-PATTERN - this code left here for future developers' reference Using the below method launches the app, and then be_roster sends ANOTHER B_REFS_REVEIVED of its own, causing the file to be opened twice, or once at the wrong location (i.e. without a line number). be_roster->Launch(&ref,msg); */ /* entry_ref appRef; be_roster->FindApp(&ref,&appRef); app_info appInfo; be_roster->GetAppInfo(&appRef,&appInfo); BMessenger messenger(appInfo.signature); messenger.SendMessage(msg,(BHandler*)NULL,B_INFINITE_TIMEOUT); // The above results in nothing happening unless the app is ALREADY running */ // Final effort - use the text_search tracker messenger mechanism BMessenger target("application/x-vnd.Be-TRAK"); target.SendMessage(msg); }
void afs_BackgroundDaemon(void) #endif { struct brequest *tb; int i, foundAny; AFS_STATCNT(afs_BackgroundDaemon); /* initialize subsystem */ if (brsInit == 0) /* Irix with "short stack" exits */ afs_BackgroundDaemon_once(); #ifdef AFS_NEW_BKG /* If it's a re-entering syscall, complete the request and release */ if (uspc->ts > -1) { tb = afs_brs; for (i = 0; i < NBRS; i++, tb++) { if (tb->ts == uspc->ts) { /* copy the userspace status back in */ ((struct afs_uspc_param *) tb->ptr_parm[0])->retval = uspc->retval; /* mark it valid and notify our caller */ tb->flags |= BUVALID; if (tb->flags & BUWAIT) { tb->flags &= ~BUWAIT; afs_osi_Wakeup(tb); } brequest_release(tb); break; } } } else { afs_osi_MaskUserLoop(); #endif /* Otherwise it's a new one */ afs_nbrs++; #ifdef AFS_NEW_BKG } #endif ObtainWriteLock(&afs_xbrs, 302); while (1) { int min_ts = 0; struct brequest *min_tb = NULL; if (afs_termState == AFSOP_STOP_BKG) { if (--afs_nbrs <= 0) afs_termState = AFSOP_STOP_RXCALLBACK; ReleaseWriteLock(&afs_xbrs); afs_osi_Wakeup(&afs_termState); #ifdef AFS_NEW_BKG return -2; #else return; #endif } /* find a request */ tb = afs_brs; foundAny = 0; for (i = 0; i < NBRS; i++, tb++) { /* look for request with smallest ts */ if ((tb->refCount > 0) && !(tb->flags & BSTARTED)) { /* new request, not yet picked up */ if ((min_tb && (min_ts - tb->ts > 0)) || !min_tb) { min_tb = tb; min_ts = tb->ts; } } } if ((tb = min_tb)) { /* claim and process this request */ tb->flags |= BSTARTED; ReleaseWriteLock(&afs_xbrs); foundAny = 1; afs_Trace1(afs_iclSetp, CM_TRACE_BKG1, ICL_TYPE_INT32, tb->opcode); if (tb->opcode == BOP_FETCH) BPrefetch(tb); #if defined(AFS_CACHE_BYPASS) else if (tb->opcode == BOP_FETCH_NOCACHE) BPrefetchNoCache(tb); #endif else if (tb->opcode == BOP_STORE) BStore(tb); else if (tb->opcode == BOP_PATH) BPath(tb); #ifdef AFS_DARWIN80_ENV else if (tb->opcode == BOP_MOVE) { memcpy(uspc, (struct afs_uspc_param *) tb->ptr_parm[0], sizeof(struct afs_uspc_param)); uspc->ts = tb->ts; /* string lengths capped in move vop; copy NUL tho */ memcpy(param1, (char *)tb->ptr_parm[1], strlen(tb->ptr_parm[1])+1); memcpy(param2, (char *)tb->ptr_parm[2], strlen(tb->ptr_parm[2])+1); return 0; } #endif else if (tb->opcode == BOP_PARTIAL_STORE) BPartialStore(tb); else panic("background bop"); brequest_release(tb); ObtainWriteLock(&afs_xbrs, 305); } if (!foundAny) { /* wait for new request */ afs_brsDaemons++; ReleaseWriteLock(&afs_xbrs); afs_osi_Sleep(&afs_brsDaemons); ObtainWriteLock(&afs_xbrs, 307); afs_brsDaemons--; } } #ifdef AFS_NEW_BKG return -2; #endif }
/* * Message Handling Function * If it's a node monitor message, * then figure out what to do based on it. * Otherwise, let BApplication handle it. */ void App::MessageReceived(BMessage *msg) { printf("message received:\n"); msg->PrintToStream(); switch(msg->what) { case MY_DELTA_CONST: { printf("Pulling changes from Dropbox\n"); pull_and_apply_deltas(); break; } case B_NODE_MONITOR: { printf("Received Node Monitor Alert\n"); status_t err; int32 opcode; err = msg->FindInt32("opcode",&opcode); if(err == B_OK) { switch(opcode) { case B_ENTRY_CREATED: { printf("CREATED NEW FILE\n"); entry_ref ref; BPath path; const char * name; // unpack the message msg->FindInt32("device",&ref.device); msg->FindInt64("directory",&ref.directory); msg->FindString("name",&name); ref.set_name(name); BEntry new_file = BEntry(&ref); new_file.GetPath(&path); //if we said to ignore a `NEW` msg from the path, then ignore it if(this->ignore_created(&path)) return; this->track_file(&new_file); if(new_file.IsDirectory()) { add_folder_to_dropbox(path.Path()); BDirectory new_dir = BDirectory(&new_file); this->recursive_watch(&new_dir); } else { BString *result = add_file_to_dropbox(path.Path()); BString *real_path = parse_path(result); BString *parent_rev = parse_parent_rev(result); delete result; printf("path:|%s|\nparent_rev:|%s|\n",real_path->String(),parent_rev->String()); BNode node = BNode(&new_file); set_parent_rev(&node,parent_rev); delete parent_rev; BPath new_path = BPath(db_to_local_filepath(real_path->String()).String()); if(strcmp(new_path.Leaf(),path.Leaf()) != 0) { printf("moving %s to %s\n", path.Leaf(), new_path.Leaf()); BEntry entry = BEntry(path.Path()); //entry for local path status_t err = entry.Rename(new_path.Leaf(),true); if(err != B_OK) printf("error moving: %s\n",strerror(err)); } delete real_path; watch_entry(&new_file,B_WATCH_STAT); } break; } case B_ENTRY_MOVED: { printf("MOVED FILE\n"); entry_ref eref; BDirectory from_dir, to_dir; node_ref from_ref,to_ref,nref; BPath path; const char* name; msg->FindInt32("device",&from_ref.device); msg->FindInt32("device",&to_ref.device); msg->FindInt32("device",&eref.device); msg->FindInt32("device",&nref.device); msg->FindInt64("from directory",&from_ref.node); msg->FindInt64("to directory",&to_ref.node); msg->FindInt64("to directory",&eref.directory); msg->FindInt64("node",&nref.node); msg->FindString("name",&name); eref.set_name(name); err = from_dir.SetTo(&from_ref); err = to_dir.SetTo(&to_ref); BEntry dest_entry = BEntry(&eref); BEntry test = BEntry("/boot/home/Dropbox/hi"); BDirectory dropbox_local = BDirectory(local_path_string); bool into_dropbox = dropbox_local.Contains(&dest_entry); int32 index = this->find_nref_in_tracked_files(nref); if((index >= 0) && into_dropbox) { printf("moving within dropbox\n"); BPath *old_path = (BPath*)this->tracked_filepaths.ItemAt(index); BPath new_path; dest_entry.GetPath(&new_path); char *argv[3]; argv[0] = "db_mv.py"; BString opath = local_to_db_filepath(old_path->Path()); BString npath = local_to_db_filepath(new_path.Path()); char not_const_o[opath.CountChars()]; char not_const_n[npath.CountChars()]; strcpy(not_const_o,opath.String()); strcpy(not_const_n,npath.String()); argv[1] = not_const_o; argv[2] = not_const_n; run_python_script(argv,3); old_path->SetTo(&dest_entry); } else if(index >= 0) { printf("moving the file out of dropbox\n"); BPath *old_path = (BPath*)this->tracked_filepaths.ItemAt(index); delete_file_on_dropbox(old_path->Path()); this->tracked_files.RemoveItem(index); this->tracked_filepaths.RemoveItem(index); } else if(into_dropbox) { printf("moving file into dropbox\n"); BPath new_path; dest_entry.GetPath(&new_path); this->track_file(&dest_entry); if(dest_entry.IsDirectory()) { add_folder_to_dropbox(new_path.Path()); BDirectory new_dir = BDirectory(&dest_entry); this->recursive_watch(&new_dir); } else { add_file_to_dropbox(new_path.Path()); watch_entry(&dest_entry,B_WATCH_STAT); } } else { printf("moving unrelated file...?\n"); } break; } case B_ENTRY_REMOVED: { printf("DELETED FILE\n"); node_ref nref; msg->FindInt32("device", &nref.device); msg->FindInt64("node", &nref.node); int32 index = this->find_nref_in_tracked_files(nref); if(index >= 0) { BPath *path = (BPath*)this->tracked_filepaths.ItemAt(index); printf("local file %s deleted\n",path->Path()); if(ignore_removed(path)) return; delete_file_on_dropbox(path->Path()); this->tracked_files.RemoveItem(index); this->tracked_filepaths.RemoveItem(index); } else { printf("could not find deleted file\n"); } break; } case B_STAT_CHANGED: { printf("EDITED FILE\n"); node_ref nref; msg->FindInt32("device", &nref.device); msg->FindInt64("node", &nref.node); int32 index = this->find_nref_in_tracked_files(nref); if(index >= 0) { BPath *path = (BPath*)this->tracked_filepaths.ItemAt(index); if(ignore_edited(path)) return; BNode node = BNode(path->Path()); BString * rev = get_parent_rev(&node); printf("parent_rev:|%s|\n",rev->String()); update_file_in_dropbox(path->Path(),rev->String()); } else { printf("Could not find edited file\n"); } break; } default: { printf("default case opcode...\n"); } } } break; } default: { BApplication::MessageReceived(msg); break; } } }
void PecoApp::RefsReceived ( BMessage* msg ) { entry_ref ref; BPath aPath; BEntry aEntry; off_t size; time_t timer; fWindow->Lock(); BTextControl* pfadView = (BTextControl *)fWindow->FindView("pfadView"); fWindow->Unlock(); //Pfad finden for ( int i=0; msg->FindRef("refs", i, &ref) == B_OK; i++ ) if ( ref.device > 1 ) break; if ( ref.device > 1 ) { New(); fWindow->Lock(); ((PecoApp *)be_app)->fStatusBar->SetText(STATUS_IMPORT); fWindow->Unlock(); aEntry = BEntry(&ref); BPath( &aEntry ).GetParent(&fPfad); fWindow->Lock(); pfadView->SetText( fPfad.Path() ); fWindow->Unlock(); //zählen type_code typeFound; long total = 0; msg->GetInfo("refs", &typeFound, &total); fWindow->Lock(); fStatusBar->SetMaxValue( total ); fWindow->Unlock(); BPath newPath; bool didntshow_msgmultidir = true; for ( int i=0; msg->FindRef("refs", i, &ref) == B_OK; i++ ) { fWindow->Lock(); fStatusBar->Update(1); fWindow->Unlock(); // Laufwerke ausfiltern if ( ref.device == 1 ) continue; // Dateien mit falschem Pfad ausfiltern aEntry = BEntry(&ref); aPath = BPath(&aEntry); BPath( &aEntry ).GetParent(&newPath); if ( (strcmp( fPfad.Path(), newPath.Path() ) != 0 ) ) { if ( didntshow_msgmultidir ) { BAlert* myAlert = new BAlert(NULL, MESSAGE_MULTIDIR, STR_OK); myAlert->Go(); didntshow_msgmultidir = false; } continue; } // Werte auslesen if (aEntry.IsFile()) aEntry.GetSize(&size); else if (aEntry.IsSymLink()) size = -1; else if (aEntry.IsDirectory()) size = -2; else continue; aEntry.GetModificationTime(&timer); fList->AddItem(new FileListItem(aPath.Leaf(), size, timer, &ref)); } fWindow->Lock(); fListView->AddList(fList); float Hoehe = be_plain_font->Size() + 2; if (Hoehe < 18) { BListItem* myListItem; for (int i=0; (myListItem = fListView->ItemAt(i)); i++) myListItem->SetHeight(18); // Zum Updaten: fListView->AddItem(myListItem = new BStringItem("")); fListView->RemoveItem(myListItem); } fStatusBar->Reset(STATUS_STATUS); fStatusBar->SetMaxValue(fList->CountItems()); fWindow->Unlock(); MakeList(); } fWindow->Activate(); UpdateWindowStatus(); }