void PersonWindow::SaveAs() { char name[B_FILE_NAME_LENGTH]; _GetDefaultFileName(name); if (fPanel == NULL) { BMessenger target(this); fPanel = new BFilePanel(B_SAVE_PANEL, &target); BPath path; find_directory(B_USER_DIRECTORY, &path, true); BDirectory dir; dir.SetTo(path.Path()); BEntry entry; if (dir.FindEntry("people", &entry) == B_OK || (dir.CreateDirectory("people", &dir) == B_OK && dir.GetEntry(&entry) == B_OK)) { fPanel->SetPanelDirectory(&entry); } } if (fPanel->Window()->Lock()) { fPanel->SetSaveText(name); if (fPanel->Window()->IsHidden()) fPanel->Window()->Show(); else fPanel->Window()->Activate(); fPanel->Window()->Unlock(); } }
static bool is_drive_mounted(const char *dev_name, char *mount_name) { int32 i = 0; dev_t d; fs_info info; while ((d = next_dev(&i)) >= 0) { fs_stat_dev(d, &info); if (strcmp(dev_name, info.device_name) == 0) { status_t err = -1; BPath mount; BDirectory dir; BEntry entry; node_ref node; node.device = info.dev; node.node = info.root; err = dir.SetTo(&node); if (!err) err = dir.GetEntry(&entry); if (!err) err = entry.GetPath(&mount); if (!err) { strcpy(mount_name, mount.Path()); return true; } } } return false; }
uint64 PanelView::GetDirectorySize(const char *path) //////////////////////////////////////////////////////////////////////// { uint64 size = 0; BDirectory *dir; dir = new BDirectory(path); if (dir) { BEntry entry; if (dir->GetEntry(&entry)==B_OK) { while (dir->GetNextEntry(&entry)==B_OK) { BPath path; entry.GetPath(&path); if (entry.IsDirectory()) size += GetDirectorySize(path.Path()); else { struct stat statbuf; entry.GetStat(&statbuf); size += statbuf.st_size; } } } delete dir; } return size; }
static char *getMountPoint(const char *devname) { BVolumeRoster mounts; BVolume vol; mounts.Rewind(); while (mounts.GetNextVolume(&vol) == B_NO_ERROR) { fs_info fsinfo; fs_stat_dev(vol.Device(), &fsinfo); if (strcmp(devname, fsinfo.device_name) == 0) { //char buf[B_FILE_NAME_LENGTH]; BDirectory directory; BEntry entry; BPath path; status_t rc; rc = vol.GetRootDirectory(&directory); BAIL_IF_MACRO(rc < B_OK, strerror(rc), NULL); rc = directory.GetEntry(&entry); BAIL_IF_MACRO(rc < B_OK, strerror(rc), NULL); rc = entry.GetPath(&path); BAIL_IF_MACRO(rc < B_OK, strerror(rc), NULL); const char *str = path.Path(); BAIL_IF_MACRO(str == NULL, ERR_OS_ERROR, NULL); /* ?! */ char *retval = (char *) allocator.Malloc(strlen(str) + 1); BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); strcpy(retval, str); return(retval); } /* if */ } /* while */ return(NULL); } /* getMountPoint */
static char *getMountPoint(const char *devname, char *buf, size_t bufsize) { BVolumeRoster mounts; BVolume vol; mounts.Rewind(); while (mounts.GetNextVolume(&vol) == B_NO_ERROR) { fs_info fsinfo; fs_stat_dev(vol.Device(), &fsinfo); if (strcmp(devname, fsinfo.device_name) == 0) { BDirectory directory; BEntry entry; BPath path; const char *str; if ( (vol.GetRootDirectory(&directory) < B_OK) || (directory.GetEntry(&entry) < B_OK) || (entry.GetPath(&path) < B_OK) || ( (str = path.Path()) == NULL) ) return NULL; strncpy(buf, str, bufsize-1); buf[bufsize-1] = '\0'; return buf; } /* if */ } /* while */ return NULL; } /* getMountPoint */
void TFilePanel::OpenParent() { if (!CanOpenParent()) return; BEntry parentEntry; BDirectory dir; Model oldModel(*PoseView()->TargetModel()); BEntry entry(oldModel.EntryRef()); if (entry.InitCheck() == B_OK && entry.GetParent(&dir) == B_OK && dir.GetEntry(&parentEntry) == B_OK && entry != parentEntry) { entry_ref ref; parentEntry.GetRef(&ref); PoseView()->SetIsDesktop(SwitchDirToDesktopIfNeeded(ref)); PoseView()->SwitchDir(&ref); SwitchDirMenuTo(&ref); // make sure the child get's selected in the new view once it // shows up fTaskLoop->RunLater(NewMemberFunctionObjectWithResult (&TFilePanel::SelectChildInParent, this, const_cast<const entry_ref*>(&ref), oldModel.NodeRef()), 100000, 200000, 5000000); } }
bool TFilePanel::SwitchDirToDesktopIfNeeded(entry_ref &ref) { // support showing Desktop as root of everything // This call implements the worm hole that maps Desktop as // a root above the disks TrackerSettings settings; if (!settings.DesktopFilePanelRoot()) // Tracker isn't set up that way, just let Disks show return false; BEntry entry(&ref); BEntry root("/"); BDirectory desktopDir; FSGetDeskDir(&desktopDir); if (FSIsDeskDir(&entry) // navigated into non-boot desktop, switch to boot desktop || (entry == root && !settings.ShowDisksIcon())) { // hit "/" level, map to desktop desktopDir.GetEntry(&entry); entry.GetRef(&ref); return true; } return FSIsDeskDir(&entry); }
void PanelView::ReadDisks(void) //////////////////////////////////////////////////////////////////////// { char drivename[256]; char drivepath[256]; // SetMousePointer(CR_HOURGLASS); MAINWINDOW->SetMousePointer(GenesisWindow::CR_HOURGLASS); CustomListItem *item; item = new CustomListItem("..",m_Path.String(),FT_DISKBACK, 0); item->AddIcon(m_ParentIcon); m_CustomListView->AddItem(item); item->SetHeight(15.0f); // Collect available volumes... BVolumeRoster *vr = new BVolumeRoster(); if (vr) { BVolume v; while (vr->GetNextVolume(&v)==B_NO_ERROR) { if (v.GetName(drivename)==B_NO_ERROR) { if (strlen(drivename)>0) { BDirectory dir; BEntry entry; BPath path; v.GetRootDirectory(&dir); dir.GetEntry(&entry); entry.GetPath(&path); sprintf(drivepath,"%s",path.Path()); item = new CustomListItem(drivename,drivepath,FT_DISKITEM,v.FreeBytes(),v.Capacity(),v.Device()); m_CustomListView->AddItem(item); if (m_Setting_ShowIcons) { if (!item->GetIcon(&v)) item->AddIcon(m_UnknownIcon); item->SetHeight(15.0f); } } } } delete vr; } m_CustomListView->DoSortList(); m_CustomListView->Select(0,false); // SetMousePointer(CR_DEFAULT); MAINWINDOW->SetMousePointer(GenesisWindow::CR_DEFAULT); }
status_t BPrinter::SetTo(const BDirectory& directory) { StopWatching(); BEntry entry; directory.GetEntry(&entry); entry.GetRef(&fPrinterEntryRef); return InitCheck(); }
void MailProtocolThread::TriggerFileMove(const entry_ref& ref, BDirectory& dir) { BMessage message(kMsgMoveFile); message.AddRef("file", &ref); BEntry entry; dir.GetEntry(&entry); entry_ref dirRef; entry.GetRef(&dirRef); message.AddRef("directory", &dirRef); PostMessage(&message); }
status_t BDaemonClient::CreateTransaction(BPackageInstallationLocation location, BActivationTransaction& _transaction, BDirectory& _transactionDirectory) { // get an info for the location BInstallationLocationInfo info; status_t error = GetInstallationLocationInfo(location, info); if (error != B_OK) return error; // open admin directory entry_ref entryRef; entryRef.device = info.PackagesDirectoryRef().device; entryRef.directory = info.PackagesDirectoryRef().node; error = entryRef.set_name(PACKAGES_DIRECTORY_ADMIN_DIRECTORY); if (error != B_OK) return error; BDirectory adminDirectory; error = adminDirectory.SetTo(&entryRef); if (error != B_OK) return error; // create a transaction directory int uniqueId = 1; BString directoryName; for (;; uniqueId++) { directoryName.SetToFormat("transaction-%d", uniqueId); if (directoryName.IsEmpty()) return B_NO_MEMORY; error = adminDirectory.CreateDirectory(directoryName, &_transactionDirectory); if (error == B_OK) break; if (error != B_FILE_EXISTS) return error; } // init the transaction error = _transaction.SetTo(location, info.ChangeCount(), directoryName); if (error != B_OK) { BEntry entry; _transactionDirectory.GetEntry(&entry); _transactionDirectory.Unset(); if (entry.InitCheck() == B_OK) entry.Remove(); return error; } return B_OK; }
void TBarWindow::MenusBeginning() { BPath path; entry_ref ref; find_directory (B_USER_DESKBAR_DIRECTORY, &path); get_ref_for_path(path.Path(), &ref); BEntry entry(&ref, true); if (entry.InitCheck() == B_OK && entry.IsDirectory()) { // need the entry_ref to the actual item entry.GetRef(&ref); // set the nav directory to the deskbar folder sDeskbarMenu->SetNavDir(&ref); } else if (!entry.Exists()) { // the deskbar folder does not exist // create one now BDirectory dir; if (entry.GetParent(&dir) == B_OK) { BDirectory deskbarDir; dir.CreateDirectory("deskbar", &deskbarDir); if (deskbarDir.GetEntry(&entry) == B_OK && entry.GetRef(&ref) == B_OK) sDeskbarMenu->SetNavDir(&ref); } } else { // this really should never happen TRESPASS(); return; } sDeskbarMenu->NeedsToRebuild(); sDeskbarMenu->ResetTargets(); fBarView->SetEventMask(0); // This works around a BeOS bug - the menu is quit with every // B_MOUSE_DOWN the window receives. // // Is this bug still here? I commented this line out and didn't // notice anything different BWindow::MenusBeginning(); }
void SysAddDiskPrefs(void) { // Let BeOS scan for HFS drives D(bug("Looking for Mac volumes...\n")); system("mountvolume -allhfs"); // Add all HFS volumes int32 i = 0; dev_t d; fs_info info; while ((d = next_dev(&i)) >= 0) { fs_stat_dev(d, &info); status_t err = -1; BPath mount; if (!strcmp(info.fsh_name, "hfs")) { BDirectory dir; BEntry entry; node_ref node; node.device = info.dev; node.node = info.root; err = dir.SetTo(&node); if (!err) err = dir.GetEntry(&entry); if (!err) err = entry.GetPath(&mount); } #warning TODO: unmount inuse disk! #if 0 if (!err) err = unmount(mount.Path()); #endif if (!err) { char dev_name[B_FILE_NAME_LENGTH]; if (info.flags & B_FS_IS_READONLY) { dev_name[0] = '*'; dev_name[1] = 0; } else dev_name[0] = 0; strcat(dev_name, info.device_name); PrefsAddString("disk", dev_name); } } }
void PanelView::DeleteDirectory(const char *dirname) //////////////////////////////////////////////////////////////////////// { BDirectory *dir; key_info keyinfo; // Don't delete the parent directory!!!!!! if (strlen(dirname)>=3) { int len = strlen(dirname); if (dirname[len-1]=='.' && dirname[len-2]=='.' && dirname[len-3]=='/') return; } dir = new BDirectory(dirname); if (dir) { BEntry entry; if (dir->GetEntry(&entry)==B_OK) { while (dir->GetNextEntry(&entry)==B_OK) { get_key_info(&keyinfo); if (keyinfo.key_states[0] & 0x40) // ESC { beep(); delete dir; return; } BPath path; entry.GetPath(&path); if (entry.IsDirectory()) DeleteDirectory(path.Path()); entry.Remove(); } } delete dir; } }
void BSlowContextMenu::AddRootItemsIfNeeded() { BVolumeRoster roster; roster.Rewind(); BVolume volume; while (roster.GetNextVolume(&volume) == B_OK) { BDirectory root; BEntry entry; if (!volume.IsPersistent() || volume.GetRootDirectory(&root) != B_OK || root.GetEntry(&entry) != B_OK) continue; Model model(&entry); AddOneItem(&model); } }
void BSlowContextMenu::BuildVolumeMenu() { BVolumeRoster roster; BVolume volume; roster.Rewind(); while (roster.GetNextVolume(&volume) == B_OK) { if (!volume.IsPersistent()) continue; BDirectory startDir; if (volume.GetRootDirectory(&startDir) == B_OK) { BEntry entry; startDir.GetEntry(&entry); Model *model = new Model(&entry); if (model->InitCheck() != B_OK) { delete model; continue; } BNavMenu *menu = new BNavMenu(model->Name(), fMessage.what, fMessenger, fParentWindow, fTypesList); menu->SetNavDir(model->EntryRef()); menu->InitTrackingHook(fTrackingHook.fTrackingHook, &(fTrackingHook.fTarget), fTrackingHook.fDragMessage); ASSERT(menu->Name()); ModelMenuItem *item = new ModelMenuItem(model, menu); BMessage *message = new BMessage(fMessage); message->AddRef("refs", model->EntryRef()); item->SetMessage(message); fItemList->AddItem(item); ASSERT(item->Label()); } } }
int32_t PDirectoryCreateDirectory(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; BDirectory newDir; status_t status = backend->CreateDirectory(path.String(), &newDir); outArgs->MakeEmpty(); if (status == B_OK) { BEntry entry; status = newDir.GetEntry(&entry); if (status == B_OK) { BPath dirPath; status = entry.GetPath(&dirPath); outArgs->AddString("path", dirPath.Path()); } } outArgs->AddInt32("status", status); return B_OK; }
void PersonWindow::SaveAs(int32 format) { if (format == 0) format = B_PERSON_FORMAT; char name[B_FILE_NAME_LENGTH]; _GetDefaultFileName(name); if (fPanel == NULL) { BPath path; BMessenger target(this); BMessage msg(B_SAVE_REQUESTED); msg.AddInt32("format", format); fPanel = new BFilePanel(B_SAVE_PANEL, &target, NULL, 0, true, &msg); find_directory(B_USER_DIRECTORY, &path, true); BDirectory dir; dir.SetTo(path.Path()); BEntry entry; if (dir.FindEntry("people", &entry) == B_OK || (dir.CreateDirectory("people", &dir) == B_OK && dir.GetEntry(&entry) == B_OK)) { fPanel->SetPanelDirectory(&entry); } } if (fPanel->Window()->Lock()) { fPanel->SetSaveText(name); if (fPanel->Window()->IsHidden()) fPanel->Window()->Show(); else fPanel->Window()->Activate(); fPanel->Window()->Unlock(); } }
void PApp::MessageReceived(BMessage *msg) { try { switch (msg->what) { case msg_SaveAll: { const doclist& lst = CDoc::DocList(); doclist::const_iterator di; for (di = lst.begin(); di != lst.end(); di++) { BWindow *w = dynamic_cast<PDoc*>(*di); if (w) w->PostMessage(msg_Save); } break; } case msg_CloseAll: { const doclist& lst = CDoc::DocList(); doclist::const_reverse_iterator di; for (di = lst.rbegin(); di != lst.rend(); di++) { PDoc *doc = dynamic_cast<PDoc*>(*di); if (doc && ! doc->IsWorksheet() && doc->Lock()) { if (doc->QuitRequested()) doc->Quit(); else { doc->Unlock(); break; } } } break; } case B_NODE_MONITOR: { CDoc::HandleFolderNodeMonitorMsg(msg); break; } case msg_OpenSelected: DialogCreator<COpenSelection>::CreateDialog(NULL); break; case msg_OpenInclude: { const char *i; FailOSErr(msg->FindString("include", &i)); const char *src = NULL; msg->FindString("from-source", &src); FindAndOpen(i, src); break; } case msg_FindCmd: { int c = 1 << current_workspace(); if (gPrefs->GetPrefInt(prf_I_SmartWorkspaces, 1)) FindDialog()->SetWorkspaces(c); FindDialog()->SetCaller(PDoc::TopWindow()); FindDialog()->Show(); FindDialog()->Activate(true); break; } case B_REFS_RECEIVED: case 'OpFi': RefsReceived(msg); break; case msg_About: { AboutWindow *abwin = new AboutWindow(); abwin->Show(); break; } case msg_IdeBringToFront: PDoc::IDEBringToFront(); break; case msg_IdeProjectToGroup: PDoc::IDEProject2Group(); break; case msg_FindDifferences: { BRect r(100,100,500,250); new CDiffWindow(r, "Differences"); break; } case msg_Open: { if (fOpenPanel->IsShowing()) { fOpenPanel->Window()->SetWorkspaces(1 << current_workspace()); fOpenPanel->Window()->Activate(); } else { BEntry entry; gCWD.GetEntry(&entry); BAutolock lock(fOpenPanel->Window()); entry_ref ref; entry.GetRef(&ref); fOpenPanel->SetPanelDirectory(&ref); fOpenPanel->Window()->SetWorkspaces(1 << current_workspace()); if (gPrefs->GetPrefInt(prf_I_ZoomOpenPanel, 0)) { BRect r = BScreen().Frame(); fOpenPanel->Window()->MoveTo(r.left + 80, r.top + 40); fOpenPanel->Window()->ResizeTo(480, r.Height() - 50); } fOpenPanel->Show(); } break; } case msg_CommandLineOpen: { entry_ref doc; FailOSErr (msg->FindRef("refs", &doc)); CDocWindow *w; BEntry e; if (e.SetTo(&doc) == B_OK && e.Exists()) w = dynamic_cast<CDocWindow*>(OpenWindow(doc)); else { w = NewWindow(NULL); w->SetEntryRef(&doc); } long lineNr; if (w && msg->FindInt32("line", &lineNr) == B_OK) { BMessage m(msg_SelectLines); FailOSErr(m.AddInt32("from", lineNr)); FailOSErr(m.AddInt32("to", lineNr - 1)); w->PostMessage(&m, w->PreferredHandler()); } if (w) { BMessage reply; reply.AddInt32("thread", w->Thread()); msg->SendReply(&reply); } break; } case B_SILENT_RELAUNCH: case msg_New: if (be_roster->IsRunning("application/x-vnd.dw-Paladin")) { BMessage newMsg(PALADIN_SHOW_ADD_NEW_PANEL); BMessenger msgr("application/x-vnd.dw-Paladin"); msgr.SendMessage(&newMsg); } else NewWindow(); break; case msg_Select: { PDoc *doc; if ((doc = PDoc::TopWindow()) != NULL) { BMessage copy(*msg); doc->PostMessage(©); } break; } case msg_DocClosed: if (CDoc::CountDocs() == 0) Quit(); break; case msg_Tile: PDoc::Tile(); break; case msg_Stack: PDoc::Stack(); break; case msg_Zoom: if (PDoc::TopWindow()) PDoc::TopWindow()->Zoom(); break; case msg_Worksheet: OpenWorksheet(); break; case msg_NewGroup: new PGroupWindow; break; case 1: puts(rcsid); break; case msg_Quit: PostMessage(B_QUIT_REQUESTED); break; case msg_Preferences: { long l; if (fPrefOpener) wait_for_thread(fPrefOpener, &l); fPrefOpener = (thread_id)NULL; if (fPrefsDialog) { BAutolock lock(fPrefsDialog); if (!lock.IsLocked()) { THROW(("Preferences panel failed to lock")); break; } int c = 1 << current_workspace(); if (gPrefs->GetPrefInt(prf_I_SmartWorkspaces, 1)) fPrefsDialog->SetWorkspaces(c); if (fPrefsDialog->IsHidden()) { fPrefsDialog->Show(); } fPrefsDialog->Activate(true); } else THROW(("Preferences panel failed to open")); break; } default: BApplication::MessageReceived(msg); } } catch (HErr& e) { e.DoError(); } } /* PApp::MessageReceived */
void GenesisCopyWindow::CopyDirectory(const char *dirname, const char *destination, const char *destdirname) //////////////////////////////////////////////////////////////////////// { BEntry srcentry(dirname); BEntry dstentry; char name[B_FILE_NAME_LENGTH]; BString fulldestdir; if (srcentry.InitCheck()!=B_OK) return; if (!srcentry.Exists()) return; srcentry.GetName(name); fulldestdir.SetTo(destination); if (destdirname) fulldestdir << "/" << destdirname; else fulldestdir << "/" << name; dstentry.SetTo(fulldestdir.String()); if (dstentry.InitCheck()!=B_OK) return; if (!dstentry.Exists()) { if (create_directory(fulldestdir.String(), 0777)!=B_OK) // TODO: jo a 0777? return; } BDirectory dir; dir.SetTo(dirname); if (dir.InitCheck()==B_OK) { BEntry entry; if (dir.GetEntry(&entry)==B_OK) { while (dir.GetNextEntry(&entry)==B_OK) { entry.GetName(name); if (entry.IsDirectory()) { BString fullname; fullname.SetTo(dirname); fullname << "/" << name; CopyDirectory(fullname.String(), fulldestdir.String()); } else if (entry.IsSymLink()) { BString fullname; fullname.SetTo(dirname); fullname << "/" << name; CopyLink(fullname.String(), fulldestdir.String()); } else { BString fullname; fullname.SetTo(dirname); fullname << "/" << name; CopyFile(fullname.String(), fulldestdir.String()); } } } } // Copy attributes... CopyAttr(dirname, fulldestdir.String()); }
filter_result TFilePanel::FSFilter(BMessage* message, BHandler**, BMessageFilter* filter) { if (message == NULL) return B_DISPATCH_MESSAGE; ASSERT(filter != NULL); if (filter == NULL) return B_DISPATCH_MESSAGE; TFilePanel* panel = dynamic_cast<TFilePanel*>(filter->Looper()); ASSERT(panel != NULL); if (panel == NULL) return B_DISPATCH_MESSAGE; switch (message->FindInt32("opcode")) { case B_ENTRY_MOVED: { node_ref itemNode; message->FindInt64("node", (int64*)&itemNode.node); node_ref dirNode; message->FindInt32("device", &dirNode.device); itemNode.device = dirNode.device; message->FindInt64("to directory", (int64*)&dirNode.node); const char* name; if (message->FindString("name", &name) != B_OK) break; // if current directory moved, update entry ref and menu // but not wind title if (*(panel->TargetModel()->NodeRef()) == itemNode) { panel->TargetModel()->UpdateEntryRef(&dirNode, name); panel->SetTo(panel->TargetModel()->EntryRef()); return B_SKIP_MESSAGE; } break; } case B_ENTRY_REMOVED: { node_ref itemNode; message->FindInt32("device", &itemNode.device); message->FindInt64("node", (int64*)&itemNode.node); // if folder we're watching is deleted, switch to root // or Desktop if (*(panel->TargetModel()->NodeRef()) == itemNode) { BVolumeRoster volumeRoster; BVolume volume; volumeRoster.GetBootVolume(&volume); BDirectory root; volume.GetRootDirectory(&root); BEntry entry; entry_ref ref; root.GetEntry(&entry); entry.GetRef(&ref); panel->SwitchDirToDesktopIfNeeded(ref); panel->SetTo(&ref); return B_SKIP_MESSAGE; } break; } } return B_DISPATCH_MESSAGE; }
void TTracker::ReadyToRun() { gStatusWindow = new BStatusWindow(); InitMimeTypes(); InstallDefaultTemplates(); InstallIndices(); HideVarDir(); fTrashWatcher = new BTrashWatcher(); fTrashWatcher->Run(); fClipboardRefsWatcher = new BClipboardRefsWatcher(); fClipboardRefsWatcher->Run(); fAutoMounter = new AutoMounter(); fAutoMounter->Run(); fTaskLoop = new StandAloneTaskLoop(true); bool openDisksWindow = false; // open desktop window BContainerWindow *deskWindow = NULL; BVolume bootVol; BVolumeRoster().GetBootVolume(&bootVol); BDirectory deskDir; if (FSGetDeskDir(&deskDir, bootVol.Device()) == B_OK) { // create desktop BEntry entry; deskDir.GetEntry(&entry); Model *model = new Model(&entry); if (model->InitCheck() == B_OK) { AutoLock<WindowList> lock(&fWindowList); deskWindow = new BDeskWindow(&fWindowList); AutoLock<BWindow> windowLock(deskWindow); deskWindow->CreatePoseView(model); deskWindow->Init(); } else delete model; // open previously open windows attr_info attrInfo; if (!BootedInSafeMode() && deskDir.GetAttrInfo(kAttrOpenWindows, &attrInfo) == B_OK) { char *buffer = (char *)malloc((size_t)attrInfo.size); BMessage message; if (deskDir.ReadAttr(kAttrOpenWindows, B_MESSAGE_TYPE, 0, buffer, (size_t)attrInfo.size) == attrInfo.size && message.Unflatten(buffer) == B_OK) { node_ref nodeRef; deskDir.GetNodeRef(&nodeRef); int32 stateMessageCounter = 0; const char *path; for (int32 outer = 0;message.FindString("paths", outer, &path) == B_OK;outer++) { int8 flags = 0; for (int32 inner = 0;message.FindInt8(path, inner, &flags) == B_OK;inner++) { BEntry entry(path, true); if (entry.InitCheck() == B_OK) { Model *model = new Model(&entry); if (model->InitCheck() == B_OK && model->IsContainer()) { BMessage state; bool restoreStateFromMessage = false; if ((flags & kOpenWindowHasState) != 0 && message.FindMessage("window state", stateMessageCounter++, &state) == B_OK) restoreStateFromMessage = true; if (restoreStateFromMessage) OpenContainerWindow(model, 0, kOpen, kRestoreWorkspace | (flags & kOpenWindowMinimized ? kIsHidden : 0U), false, &state); else OpenContainerWindow(model, 0, kOpen, kRestoreWorkspace | (flags & kOpenWindowMinimized ? kIsHidden : 0U)); } else delete model; } } } if (message.HasBool("open_disks_window")) openDisksWindow = true; } free(buffer); } } // create model for root of everything if (deskWindow) { BEntry entry("/"); Model model(&entry); if (model.InitCheck() == B_OK) { if (TrackerSettings().ShowDisksIcon()) { // add the root icon to desktop window BMessage message; message.what = B_NODE_MONITOR; message.AddInt32("opcode", B_ENTRY_CREATED); message.AddInt32("device", model.NodeRef()->device); message.AddInt64("node", model.NodeRef()->node); message.AddInt64("directory", model.EntryRef()->directory); message.AddString("name", model.EntryRef()->name); deskWindow->PostMessage(&message, deskWindow->PoseView()); } if (openDisksWindow) OpenContainerWindow(new Model(model), 0, kOpen, kRestoreWorkspace); } } // kick off building the mime type list for find panels, etc. fMimeTypeList = new MimeTypeList(); if (!BootedInSafeMode()) // kick of transient query killer DeleteTransientQueriesTask::StartUpTransientQueryCleaner(); }
TTracker::TTracker() : BApplication(kTrackerSignature), fMimeTypeList(NULL), fClipboardRefsWatcher(NULL), fTrashWatcher(NULL), fTaskLoop(NULL), fNodeMonitorCount(-1), fWatchingInterface(new WatchingInterface), fSettingsWindow(NULL) { BPathMonitor::SetWatchingInterface(fWatchingInterface); // set the cwd to /boot/home, anything that's launched // from Tracker will automatically inherit this BPath homePath; if (find_directory(B_USER_DIRECTORY, &homePath) == B_OK) chdir(homePath.Path()); // ask for a bunch more file descriptors so that nested copying works well struct rlimit rl; rl.rlim_cur = 512; rl.rlim_max = RLIM_SAVED_MAX; setrlimit(RLIMIT_NOFILE, &rl); fNodeMonitorCount = DEFAULT_MON_NUM; gLocalizedNamePreferred = BLocaleRoster::Default()->IsFilesystemTranslationPreferred(); #ifdef CHECK_OPEN_MODEL_LEAKS InitOpenModelDumping(); #endif InitIconPreloader(); #ifdef LEAK_CHECKING SetNewLeakChecking(true); SetMallocLeakChecking(true); #endif // This is how often it should update the free space bar on the // volume icons SetPulseRate(1000000); gLaunchLooper = new LaunchLooper(); gLaunchLooper->Run(); // open desktop window BContainerWindow* deskWindow = NULL; BDirectory deskDir; if (FSGetDeskDir(&deskDir) == B_OK) { // create desktop BEntry entry; deskDir.GetEntry(&entry); Model* model = new Model(&entry, true); if (model->InitCheck() == B_OK) { AutoLock<WindowList> lock(&fWindowList); deskWindow = new BDeskWindow(&fWindowList); AutoLock<BWindow> windowLock(deskWindow); deskWindow->CreatePoseView(model); deskWindow->Init(); if (TrackerSettings().ShowDisksIcon()) { // create model for root of everything BEntry entry("/"); Model model(&entry); if (model.InitCheck() == B_OK) { // add the root icon to desktop window BMessage message; message.what = B_NODE_MONITOR; message.AddInt32("opcode", B_ENTRY_CREATED); message.AddInt32("device", model.NodeRef()->device); message.AddInt64("node", model.NodeRef()->node); message.AddInt64("directory", model.EntryRef()->directory); message.AddString("name", model.EntryRef()->name); deskWindow->PostMessage(&message, deskWindow->PoseView()); } } } else delete model; } }
TFilePanel::TFilePanel(file_panel_mode mode, BMessenger* target, const BEntry* startDir, uint32 nodeFlavors, bool multipleSelection, BMessage* message, BRefFilter* filter, uint32 containerWindowFlags, window_look look, window_feel feel, bool hideWhenDone) : BContainerWindow(0, containerWindowFlags, look, feel, 0, B_CURRENT_WORKSPACE), fDirMenu(NULL), fDirMenuField(NULL), fTextControl(NULL), fClientObject(NULL), fSelectionIterator(0), fMessage(NULL), fHideWhenDone(hideWhenDone), fIsTrackingMenu(false) { InitIconPreloader(); fIsSavePanel = (mode == B_SAVE_PANEL); BRect windRect(85, 50, 568, 296); MoveTo(windRect.LeftTop()); ResizeTo(windRect.Width(), windRect.Height()); fNodeFlavors = (nodeFlavors == 0) ? B_FILE_NODE : nodeFlavors; if (target) fTarget = *target; else fTarget = BMessenger(be_app); if (message) SetMessage(message); else if (fIsSavePanel) fMessage = new BMessage(B_SAVE_REQUESTED); else fMessage = new BMessage(B_REFS_RECEIVED); gLocalizedNamePreferred = BLocaleRoster::Default()->IsFilesystemTranslationPreferred(); // check for legal starting directory Model* model = new Model(); bool useRoot = true; if (startDir) { if (model->SetTo(startDir) == B_OK && model->IsDirectory()) useRoot = false; else { delete model; model = new Model(); } } if (useRoot) { BPath path; if (find_directory(B_USER_DIRECTORY, &path) == B_OK) { BEntry entry(path.Path(), true); if (entry.InitCheck() == B_OK && model->SetTo(&entry) == B_OK) useRoot = false; } } if (useRoot) { BVolume volume; BDirectory root; BVolumeRoster volumeRoster; volumeRoster.GetBootVolume(&volume); volume.GetRootDirectory(&root); BEntry entry; root.GetEntry(&entry); model->SetTo(&entry); } fTaskLoop = new PiggybackTaskLoop; AutoLock<BWindow> lock(this); CreatePoseView(model); fPoseView->SetRefFilter(filter); if (!fIsSavePanel) fPoseView->SetMultipleSelection(multipleSelection); fPoseView->SetFlags(fPoseView->Flags() | B_NAVIGABLE); fPoseView->SetPoseEditing(false); AddCommonFilter(new BMessageFilter(B_KEY_DOWN, key_down_filter)); AddCommonFilter(new BMessageFilter(B_SIMPLE_DATA, TFilePanel::MessageDropFilter)); AddCommonFilter(new BMessageFilter(B_NODE_MONITOR, TFilePanel::FSFilter)); // inter-application observing BMessenger tracker(kTrackerSignature); BHandler::StartWatching(tracker, kDesktopFilePanelRootChanged); Init(); }
status_t BVolume::SetTo(e_dev_t dev) { #ifdef HAVE_MNTENT_H if (dev <= 0) { Unset(); } else if (fDevice != dev) { FILE *ent = setmntent("/etc/fstab", "r"); if (ent == NULL) { ETK_DEBUG("[STORAGE]: %s --- Unable to open /etc/fstab", __PRETTY_FUNCTION__); return B_ENTRY_NOT_FOUND; } struct mntent *mnt = NULL; for (e_dev_t i = 0; i < dev; i++) { if ((mnt = getmntent(ent)) == NULL) break; } if (mnt == NULL) { endmntent(ent); return B_ENTRY_NOT_FOUND; } if (fData == NULL) { if ((fData = new_dev_data()) == NULL) { endmntent(ent); return B_NO_MEMORY; } } status_t status = set_dev_data((e_dev_data_t*)fData, mnt->mnt_fsname, mnt->mnt_dir); endmntent(ent); if (status != B_OK) return status; fDevice = dev; } return B_OK; #else // !HAVE_MNTENT_H #ifdef _WIN32 if (dev <= 0) { Unset(); } else if (fDevice != dev) { if (dev > 26) return B_ENTRY_NOT_FOUND; DWORD driveMask = GetLogicalDrives(); if (driveMask == 0) return B_ENTRY_NOT_FOUND; if (!(driveMask & (1UL << (dev - 1)))) return B_BAD_VALUE; if (fData == NULL) { if ((fData = new_dev_data()) == NULL) return B_NO_MEMORY; } char dirname[4] = "A:\\"; *dirname += (dev - 1); BString nameStr; char nameBuf[301]; bzero(nameBuf, 301); if (!(GetVolumeInformation(dirname, nameBuf, 300, NULL, NULL, NULL, NULL, 0) == 0 || nameBuf[0] == 0)) { WCHAR wStr[301]; bzero(wStr, sizeof(WCHAR) * 301); MultiByteToWideChar(CP_ACP, 0, nameBuf, -1, wStr, 300); char *utf8Name = e_unicode_convert_to_utf8((const unichar*)wStr, -1); if (utf8Name != NULL) { nameStr.SetTo(utf8Name); free(utf8Name); } } if (nameStr.Length() <= 0) nameStr.SetTo(nameBuf); dirname[2] = '/'; status_t status = set_dev_data((e_dev_data_t*)fData, nameStr.String(), dirname); if (status != B_OK) return status; fDevice = dev; } return B_OK; #else // !_WIN32 #ifdef __BEOS__ if (dev <= 0) { Unset(); } else if (fDevice != dev) { if (fData == NULL) if ((fData = new_dev_data()) == NULL) return B_NO_MEMORY; BVolume vol; BVolumeRoster volRoster; BDirectory beDir; BEntry beEntry; BPath bePath; char volName[B_FILE_NAME_LENGTH + 1]; bzero(volName, B_FILE_NAME_LENGTH + 1); e_dev_t tmp = dev; while (tmp > 0) { if (volRoster.GetNextVolume(&vol) != B_OK) return B_ENTRY_NOT_FOUND; if (--tmp > 0) continue; if (vol.GetRootDirectory(&beDir) != B_OK || beDir.GetEntry(&beEntry) != B_OK || beEntry.GetPath(&bePath) != B_OK) return B_ENTRY_NOT_FOUND; vol.GetName(volName); } status_t status = set_dev_data((e_dev_data_t*)fData, volName, bePath.Path()); if (status != B_OK) return status; fDevice = dev; } return B_OK; #else // !__BEOS__ #warning "fixme: BVolume::SetTo" if (dev <= 0) { Unset(); return B_OK; } else if (fDevice != dev && dev == 1) { if (fData == NULL) if ((fData = new_dev_data()) == NULL) return B_NO_MEMORY; status_t status = set_dev_data((e_dev_data_t*)fData, "root", "/"); if (status != B_OK) return status; fDevice = dev; return B_OK; } return B_ENTRY_NOT_FOUND; #endif // __BEOS__ #endif // _WIN32 #endif // HAVE_MNTENT_H }
int getmntent_haiku(int* cookie, struct mnttab* mp) { static BLocker mntent_locker; mntent_locker.Lock(); int ret = -1; BVolumeRoster roster; char buf[B_PATH_NAME_LENGTH]; int buflen = 0; BVolume volume; BDirectory rootDir; BEntry rootDirEntry; BPath rootDirPath; roster.Rewind(); for (int i = 0; i <= *cookie; i++) if (roster.GetNextVolume(&volume) != B_NO_ERROR) goto bail; // volume name volume.GetName(buf); buflen = strlen(buf); if (buflen == 0) { buflen = strlen(MNTENT_MP_UNKNOWN); strlcpy(buf, MNTENT_MP_UNKNOWN, buflen + 1); } mp->mnt_special = (char* )malloc(sizeof(char) * (buflen+1)); strlcpy(mp->mnt_special, buf, buflen+1); // mount point if (volume.GetRootDirectory(&rootDir) != B_OK || rootDir.GetEntry(&rootDirEntry) != B_OK || rootDirEntry.GetPath(&rootDirPath) != B_OK) goto bail; buflen = strlen(rootDirPath.Path()); mp->mnt_mountp = (char* )malloc(sizeof(char) * (buflen+1)); strlcpy(mp->mnt_mountp, rootDirPath.Path(), buflen + 1); // partition type. fs_info info; if (fs_stat_dev(volume.Device(), &info) != B_OK) goto bail; buflen = strlen(info.fsh_name); mp->mnt_fstype = (char* )malloc(sizeof(char) * (buflen+1)); strlcpy(mp->mnt_fstype, info.fsh_name, buflen+1); // fs options. set default options for all file systems for now. buflen = strlen(MNTENT_MP_DEFAULT_OPTS); mp->mnt_mntopts = (char* )malloc(sizeof(char) * (buflen+2+1)); // extra space for ro/rw strlcpy(mp->mnt_mntopts, MNTENT_MP_DEFAULT_OPTS, buflen + 2 + 1); strcat(mp->mnt_mntopts, volume.IsReadOnly() ? ",ro":",rw"); // mount time. no idea how i can get this. set it to 0 for now. buflen = 1; mp->mnt_time = (char* )malloc(sizeof(char) * (buflen+1)); strlcpy(mp->mnt_time, "0", buflen + 1); (*cookie)++; ret = 0; /* success! */ bail: mntent_locker.Unlock(); return ret; }
void PanelView::ReadDirectory(const char *itemname) //////////////////////////////////////////////////////////////////////// { BDirectory *dir; CustomListItem *item; stop_watching(this); // SetMousePointer(CR_HOURGLASS); MAINWINDOW->SetMousePointer(GenesisWindow::CR_HOURGLASS); // If we are not in the root directory, simply start the dir with a '..' entry... if (strcmp(m_Path.String(),"/")!=0) { item = new CustomListItem("..", m_Path.String(), FT_PARENT, 0); m_CustomListView->AddItem(item); if (m_Setting_ShowIcons) { item->AddIcon(m_ParentIcon); item->SetHeight(15.0f); } } dir = new BDirectory(m_Path.String()); if (dir) { BEntry entry; if (dir->GetEntry(&entry)==B_OK) { while (dir->GetNextEntry(&entry)==B_OK) { AddDirectoryEntry(&entry); } } delete dir; } m_CustomListView->DoSortList(); // Always select the first item in the list or the child where we came from... if (itemname) { CustomListItem *item; int n = m_CustomListView->CountItems(); for (int i=0;i<n;i++) { item = (CustomListItem *)m_CustomListView->ItemAt(i); if (strcasecmp(itemname,item->m_FileName.String())==0) { m_CustomListView->Select(i,false); m_CustomListView->ScrollToSelection(); break; } } // When the given file disappeared, we have to select the first entry... if (m_CustomListView->CountSelectedEntries(CT_WITHPARENT)==0) m_CustomListView->Select(0,false); } else m_CustomListView->Select(0,false); m_CurrentTotalSize = m_CustomListView->GetCurrentTotalSize(); // Probably we have to update the path of the command line... Parent()->Looper()->PostMessage(new BMessage(MSG_UPDATECOMMANDLINE_PATH)); // To update command line... EnableMonitoring(); // SetMousePointer(CR_DEFAULT); MAINWINDOW->SetMousePointer(GenesisWindow::CR_DEFAULT); }
void TTracker::ReadyToRun() { gStatusWindow = new BStatusWindow(); InitMimeTypes(); InstallDefaultTemplates(); InstallIndices(); InstallTemporaryBackgroundImages(); fTrashWatcher = new BTrashWatcher(); fTrashWatcher->Run(); fClipboardRefsWatcher = new BClipboardRefsWatcher(); fClipboardRefsWatcher->Run(); fTaskLoop = new StandAloneTaskLoop(true); // open desktop window BContainerWindow *deskWindow = NULL; BDirectory deskDir; if (FSGetDeskDir(&deskDir) == B_OK) { // create desktop BEntry entry; deskDir.GetEntry(&entry); Model *model = new Model(&entry, true); if (model->InitCheck() == B_OK) { AutoLock<WindowList> lock(&fWindowList); deskWindow = new BDeskWindow(&fWindowList); AutoLock<BWindow> windowLock(deskWindow); deskWindow->CreatePoseView(model); deskWindow->Init(); if (TrackerSettings().ShowDisksIcon()) { // create model for root of everything BEntry entry("/"); Model model(&entry); if (model.InitCheck() == B_OK) { // add the root icon to desktop window BMessage message; message.what = B_NODE_MONITOR; message.AddInt32("opcode", B_ENTRY_CREATED); message.AddInt32("device", model.NodeRef()->device); message.AddInt64("node", model.NodeRef()->node); message.AddInt64("directory", model.EntryRef()->directory); message.AddString("name", model.EntryRef()->name); deskWindow->PostMessage(&message, deskWindow->PoseView()); } } } else delete model; } // kick off building the mime type list for find panels, etc. fMimeTypeList = new MimeTypeList(); if (!BootedInSafeMode()) { // kick of transient query killer DeleteTransientQueriesTask::StartUpTransientQueryCleaner(); // the mount_server will have mounted the previous volumes already. _OpenPreviouslyOpenedWindows(); } }
void BDirMenu::Populate(const BEntry* startEntry, BWindow* originatingWindow, bool includeStartEntry, bool select, bool reverse, bool addShortcuts, bool navMenuEntries) { try { if (!startEntry) throw (status_t)B_ERROR; Model model(startEntry); ThrowOnInitCheckError(&model); ModelMenuItem* menu = new ModelMenuItem(&model, this, true, true); if (fMenuBar) fMenuBar->AddItem(menu); BEntry entry(*startEntry); bool showDesktop, showDisksIcon; { TrackerSettings settings; showDesktop = settings.DesktopFilePanelRoot(); showDisksIcon = settings.ShowDisksIcon(); } // might start one level above startEntry if (!includeStartEntry) { BDirectory parent; BDirectory dir(&entry); if (!showDesktop && dir.InitCheck() == B_OK && dir.IsRootDirectory()) { // if we're at the root directory skip "mnt" and // go straight to "/" parent.SetTo("/"); } else entry.GetParent(&parent); parent.GetEntry(&entry); } BDirectory desktopDir; FSGetDeskDir(&desktopDir); BEntry desktopEntry; desktopDir.GetEntry(&desktopEntry); for (;;) { BNode node(&entry); ThrowOnInitCheckError(&node); PoseInfo info; ReadAttrResult result = ReadAttr(&node, kAttrPoseInfo, kAttrPoseInfoForeign, B_RAW_TYPE, 0, &info, sizeof(PoseInfo), &PoseInfo::EndianSwap); BDirectory parent; entry.GetParent(&parent); bool hitRoot = false; BDirectory dir(&entry); if (!showDesktop && dir.InitCheck() == B_OK && dir.IsRootDirectory()) { // if we're at the root directory skip "mnt" and // go straight to "/" hitRoot = true; parent.SetTo("/"); } if (showDesktop) { BEntry root("/"); // warp from "/" to Desktop properly if (entry == root) { if (showDisksIcon) AddDisksIconToMenu(reverse); entry = desktopEntry; } if (entry == desktopEntry) hitRoot = true; } if (result == kReadAttrFailed || !info.fInvisible || (showDesktop && desktopEntry == entry)) { AddItemToDirMenu(&entry, originatingWindow, reverse, addShortcuts, navMenuEntries); } if (hitRoot) { if (!showDesktop && showDisksIcon && *startEntry != "/") AddDisksIconToMenu(reverse); break; } parent.GetEntry(&entry); } // select last item in menu if (!select) return; ModelMenuItem* item = dynamic_cast<ModelMenuItem*>(ItemAt(CountItems() - 1)); if (item) { item->SetMarked(true); if (menu) { entry.SetTo(item->TargetModel()->EntryRef()); ThrowOnError(menu->SetEntry(&entry)); } } } catch (status_t err) { PRINT(("BDirMenu::Populate: caught error %s\n", strerror(err))); if (!CountItems()) { BString error; error << "Error [" << strerror(err) << "] populating menu"; AddItem(new BMenuItem(error.String(), 0)); } } }