struct gui_download_window *gui_download_window_create(download_context *ctx, struct gui_window *parent) { struct gui_download_window *download = (struct gui_download_window*)malloc(sizeof *download); if (download == NULL) return NULL; download->storageLock = new BLocker("storage_lock"); download->storage = new BMallocIO(); download->ctx = ctx; download->window = new NSDownloadWindow(ctx); // Also ask the user where to save the file BMessage* msg = new BMessage(B_SAVE_REQUESTED); BFilePanel* panel = new BFilePanel(B_SAVE_PANEL, new BMessenger(download->window), NULL, 0, false); panel->SetSaveText(download_context_get_filename(ctx)); msg->AddPointer("source", panel); msg->AddPointer("dw", download); panel->SetMessage(msg); panel->Show(); return download; }
void ServerWindow::DCCGetDialog ( BString nick, BString file, BString size, BString ip, BString port) { BMessage msg (DCC_ACCEPT), reply; msg.AddString ("bowser:nick", nick.String()); msg.AddString ("bowser:file", file.String()); msg.AddString ("bowser:size", size.String()); msg.AddString ("bowser:ip", ip.String()); msg.AddString ("bowser:port", port.String()); //bool handled (false); // ignore this part until some minor details with DCC Prefs are worked out /* const char *directory = "/boot/home/"; entry_ref ref; BEntry entry; create_directory (directory, 0777); if (entry.SetTo (directory) == B_NO_ERROR if (entry.GetRef (&ref) == B_NO_ERROR) { BDirectory dir (&ref); BEntry file_entry; struct stat s; if (file_entry.SetTo (&dir, file.String()) == B_NO_ERROR && file_entry.GetStat (&s) == B_NO_ERROR && S_ISREG (s.st_mode)) { BString buffer; BAlert *alert; int32 which; buffer << "The file \"" << file << "\" already exists in the specified folder. " "Do you want to continue the transfer?"; alert = new BAlert ( "DCC Request", buffer.String(), "Refuse", "Get", "Resume", B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT); which = alert->Go(); if (which == 0) { return; } if (which == 2) { BFile file (&file_entry, B_READ_ONLY); off_t position; BPath path; file.GetSize (&position); file_entry.GetPath (&path); msg.AddString ("path", path.Path()); msg.AddInt64 ("pos", position); AddResumeData (&msg); return; } } msg.AddRef ("directory", &ref); msg.AddString ("name", file); sMsgr.SendMessage (&msg); handled = true; } } */ BFilePanel *panel; BString text; text << nick << ": " << file << " (" << size << " bytes)"; panel = new BFilePanel ( B_SAVE_PANEL, &sMsgr, 0, 0, false, &msg); panel->SetButtonLabel (B_DEFAULT_BUTTON, "Accept"); panel->SetButtonLabel (B_CANCEL_BUTTON, "Refuse"); panel->SetSaveText (file.String()); if (panel->Window()->Lock()) { panel->Window()->SetTitle (text.String()); panel->Window()->AddFilter (new DCCFileFilter (panel, msg)); panel->Window()->Unlock(); } panel->Show(); }
/* open a file panel and ask for a PDF file the file panel will tell by itself if openning have been cancelled or not. */ void BepdfApplication::OpenSaveFilePanel(BHandler* handler, bool fileMode, BRefFilter* filter, BMessage* msg, const char* name) { BFilePanel* panel = NULL; // lazy construct file panel if (fileMode) { // file panel for selection of file if (mSaveFilePanel == NULL) { mSaveFilePanel = new BFilePanel (B_SAVE_PANEL, NULL, NULL, B_FILE_NODE, false, NULL, NULL, true); } // hide other file panel if (mSaveToDirectoryFilePanel != NULL && mSaveToDirectoryFilePanel->IsShowing()) { mSaveToDirectoryFilePanel->Hide(); } panel = mSaveFilePanel; } else { // file panel for selection of directory if (mSaveToDirectoryFilePanel == NULL) { mSaveToDirectoryFilePanel = new BFilePanel (B_OPEN_PANEL, NULL, NULL, B_DIRECTORY_NODE, false, NULL, NULL, true); } // hide other file panel if (mSaveFilePanel != NULL && mSaveFilePanel->IsShowing()) { mSaveFilePanel->Hide(); } panel = mSaveToDirectoryFilePanel; } // (re)-set to directory of currently opened PDF file // TODO decide if directory should be independent from PDF file panel->SetPanelDirectory(mSettings->GetPanelDirectory()); if (name != NULL) { panel->SetSaveText(name); } else if (fileMode) { panel->SetSaveText(""); } // set/reset filter panel->SetRefFilter(filter); // add kind to message BMessage message(B_SAVE_REQUESTED); if (msg == NULL) { msg = &message; } panel->SetMessage(msg); // set target BMessenger msgr(handler); panel->SetTarget(msgr); panel->Refresh(); panel->Show(); }
void ServerAgent::DCCGetDialog ( BString nick, BString file, BString size, BString ip, BString port) { BMessage msg (M_DCC_ACCEPT), reply; msg.AddString ("vision:nick", nick.String()); msg.AddString ("vision:file", file.String()); msg.AddString ("vision:size", size.String()); msg.AddString ("vision:ip", ip.String()); msg.AddString ("vision:port", port.String()); BFilePanel *panel; BString text; text << nick << ": " << file << " (" << size << " bytes)"; panel = new BFilePanel ( B_SAVE_PANEL, &fSMsgr, 0, 0, false, &msg); panel->SetButtonLabel (B_DEFAULT_BUTTON, "Accept"); panel->SetButtonLabel (B_CANCEL_BUTTON, "Refuse"); panel->SetSaveText (file.String()); BWindow *panelWindow (panel->Window()); if (panelWindow->Lock()) { panelWindow->SetTitle (text.String()); panelWindow->SetFlags (panelWindow->Flags() | B_AVOID_FOCUS); panelWindow->AddFilter (new DCCFileFilter (panel, msg)); if (vision_app->GetBool ("dccAutoAccept")) { BDirectory path (vision_app->GetString ("dccDefPath")); if (path.InitCheck() == B_OK) panel->SetPanelDirectory(&path); } if (vision_app->GetBool ("dccAutoAccept")) { panelWindow->Hide(); BButton *button (dynamic_cast<BButton *>(panel->Window()->FindView ("default button"))); if (button) button->Invoke(); } panelWindow->Unlock(); panel->Show(); // hack trick to ensure that the file panel doesn't take over the keyboard focus // when it pops up panelWindow->Lock(); panelWindow->SetFlags (panelWindow->Flags() & ~B_AVOID_FOCUS); panelWindow->Unlock(); } }
BEntry *YabFilePanel::MyFilePanel(const char *name, const char *directory, const char* filename, int mode) { BEntry *myEntry = NULL; entry_ref ref; sem_id semaphore = create_sem(0, "yabfilepanel"); YabFilePanelLooper *myLooper = new YabFilePanelLooper(semaphore); myLooper->Run(); if(directory) { myEntry=new BEntry(directory); if(myEntry->GetRef(&ref)!=B_OK) { myEntry->Unset(); myEntry->SetTo("/boot/home/"); myEntry->GetRef(&ref); } myEntry->Unset(); delete myEntry; } BFilePanel *myFilePanel = NULL; switch(mode) { case 0: myFilePanel = new BFilePanel(B_OPEN_PANEL, new BMessenger(myLooper, myLooper), &ref, B_FILE_NODE, false, NULL, NULL, true, true); break; case 1: myFilePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(myLooper, myLooper), &ref, B_FILE_NODE, false, NULL, NULL, true, true); if (filename) myFilePanel->SetSaveText(filename); break; case 2: myFilePanel = new BFilePanel(B_OPEN_PANEL, new BMessenger(myLooper, myLooper), &ref, B_DIRECTORY_NODE, false, NULL, NULL, true, true); break; case 3: myFilePanel = new BFilePanel(B_OPEN_PANEL, new BMessenger(myLooper, myLooper), &ref, B_FILE_NODE|B_DIRECTORY_NODE, false, NULL, NULL, true, true); break; } if(name) myFilePanel->Window()->SetTitle(name); myFilePanel->Show(); bool inloop = true; while(inloop) { while(acquire_sem_etc(semaphore, 1, B_RELATIVE_TIMEOUT, 10000)==B_TIMED_OUT) ; myEntry = myLooper->GetChosenFile(); inloop = false; /* if(mode!=2) inloop = false; else { if(myEntry->IsDirectory()) inloop = false; else { myFilePanel->Show(); } } */ } myLooper->Lock(); myLooper->Quit(); delete_sem(semaphore); delete myFilePanel; return myEntry; }