void FileTypes::MessageReceived(BMessage *message) { switch (message->what) { case kMsgSettingsChanged: fSettings.UpdateFrom(message); break; case kMsgOpenTypesWindow: if (fTypesWindow == NULL) { fTypesWindow = new FileTypesWindow(fSettings.Message()); fTypesWindow->Show(); fWindowCount++; } else fTypesWindow->Activate(true); break; case kMsgTypesWindowClosed: fTypesWindow = NULL; _WindowClosed(); break; case kMsgOpenApplicationTypesWindow: if (fApplicationTypesWindow == NULL) { fApplicationTypesWindow = new ApplicationTypesWindow( fSettings.Message()); fApplicationTypesWindow->Show(); fWindowCount++; } else fApplicationTypesWindow->Activate(true); break; case kMsgApplicationTypesWindowClosed: fApplicationTypesWindow = NULL; _WindowClosed(); break; case kMsgTypeWindowClosed: fTypeWindowCount--; // supposed to fall through case kMsgWindowClosed: _WindowClosed(); break; case kMsgOpenFilePanel: { // the open file panel sends us a message when it's done const char* subTitle; if (message->FindString("title", &subTitle) != B_OK) subTitle = B_TRANSLATE("Open file"); int32 what; if (message->FindInt32("message", &what) != B_OK) what = B_REFS_RECEIVED; BMessenger target; if (message->FindMessenger("target", &target) != B_OK) target = be_app_messenger; BString title = B_TRANSLATE("FileTypes"); if (subTitle != NULL && subTitle[0]) { title.Append(": "); title.Append(subTitle); } fFilePanel->SetMessage(new BMessage(what)); fFilePanel->Window()->SetTitle(title.String()); fFilePanel->SetTarget(target); if (!fFilePanel->IsShowing()) fFilePanel->Show(); break; } case B_SILENT_RELAUNCH: // In case we were launched via the add-on, there is no types // window yet. if (fTypesWindow == NULL) PostMessage(kMsgOpenTypesWindow); break; case B_CANCEL: if (fWindowCount == 0) PostMessage(B_QUIT_REQUESTED); break; case B_SIMPLE_DATA: RefsReceived(message); break; default: BApplication::MessageReceived(message); break; } }
status_t RunPopUpMenu(BPoint where, BString &header, BString &fileName, CLanguageInterface *languageInterface) { status_t err; BPath path; BDirectory dir; err = GetSettingsDir(dir, path); err = B_ERROR; BPopUpMenu *menu = BuildPopUp(dir); if (menu == NULL) return B_ERROR; BMenuItem *item = menu->Go(where, false, true); //if (item && item->Message()) // item->Message()->PrintToStream(); switch ((item && item->Message()) ? item->Message()->what : 0) { case 'head': { if (item->Message()->FindString("template", &header) < B_OK) break; BString tmp; time_t now = time(NULL); struct tm *tim = localtime(&now); // date char *p; p = tmp.LockBuffer(100); memset(p, 0, 100); strftime(p, 100, "%Y-%m-%d", tim); tmp.UnlockBuffer(); header.ReplaceAll("%DATE%", tmp.String()); tmp.Truncate(0); p = tmp.LockBuffer(100); memset(p, 0, 100); strftime(p, 100, "%T", tim); tmp.UnlockBuffer(); header.ReplaceAll("%TIME%", tmp.String()); tmp.Truncate(0); // year p = tmp.LockBuffer(10); memset(p, 0, 10); strftime(p, 10, "%Y", tim); tmp.UnlockBuffer(); header.ReplaceAll("%YEAR%", tmp.String()); tmp.Truncate(0); // fetch from query on META:email==** ? p = tmp.LockBuffer(B_PATH_NAME_LENGTH); memset(p, 0, B_PATH_NAME_LENGTH); err = dir.ReadAttr("pe:author_people", B_STRING_TYPE, 0LL, p, B_PATH_NAME_LENGTH); tmp.UnlockBuffer(); //printf("ppl:%s\n", tmp.String()); BNode people; if (err > 0) people.SetTo(tmp.String()); tmp.Truncate(0); BString attr; static struct { const char *tmplName; const char *attrName; } attrMap[] = { { "%AUTHOR%", "META:name" }, { "%AUTHORMAIL%", "META:email" }, { "%COMPANY%", "META:company" }, { "%AUTHORURL%", "META:url" }, { NULL, NULL } }; int i; for (i = 0; attrMap[i].tmplName; i++) { p = attr.LockBuffer(256); memset(p, 0, 256); err = people.ReadAttr(attrMap[i].attrName, B_ANY_TYPE, 0LL, p, 256); //printf("ReadAttr: %d, %s\n", err, attr.String()); attr.UnlockBuffer(); tmp << attr; header.ReplaceAll(attrMap[i].tmplName, tmp.String()); tmp.Truncate(0); attr.Truncate(0); } BString fileNameNoExt(fileName); if (fileNameNoExt.FindLast('.') > -1) fileNameNoExt.Truncate(fileNameNoExt.FindLast('.')); header.ReplaceAll("%FILENAMENOEXT%", fileNameNoExt.String()); header.ReplaceAll("%FILENAME%", fileName.String()); /* tmp << "Haiku"; header.ReplaceAll("%PROJECT%", tmp.String()); tmp.Truncate(0); */ // better values for C++ BString language("C/C++"); BString commentLineStart("/*"); BString commentLineEnd(""); BString commentBlockStart("/*"); BString commentBlockCont(" *"); BString commentBlockLazy(""); BString commentBlockLineEnd(""); BString commentBlockEnd(" */"); if (languageInterface) { // if not C++ if (language != languageInterface->Name()) { language = languageInterface->Name(); commentLineStart = languageInterface->LineCommentStart(); commentLineEnd = languageInterface->LineCommentEnd(); // I'd miss a CommentCanSpanLines() // let's assume line end means can span if (commentLineEnd.Length()) { commentBlockStart = commentLineStart; commentBlockCont = ""; commentBlockLazy = ""; commentBlockLineEnd = ""; commentBlockEnd = commentLineEnd; } else { commentBlockStart = commentLineStart; commentBlockCont = commentLineStart; commentBlockLazy = commentLineStart; commentBlockLineEnd = commentLineEnd; commentBlockEnd = commentLineStart; } /* printf("LANG:'%s' CS:'%s' CE:'%s'\n", language.String(), commentLineStart.String(), commentLineEnd.String()); */ } } // comment start header.ReplaceAll("%COMMS%", commentBlockStart.String()); // comment cont'd header.ReplaceAll("%COMMC%", commentBlockCont.String()); // comment cont'd lazy (blank if possible) header.ReplaceAll("%COMML%", commentBlockLazy.String()); // comment end header.ReplaceAll("%COMME%", commentBlockEnd.String()); // comment line end commentBlockLineEnd << "\n"; header.ReplaceAll("\n", commentBlockLineEnd.String()); err = B_OK; break; } case 'optf': { const char *args[] = {path.Path(), NULL}; err = be_roster->Launch(sTrackerSig, 1, (char **)args); //printf("err %s\n", strerror(err)); err = B_CANCELED; break; } case 'seta': { MimeRefFilter filter("application/x-person"); BPath path; entry_ref people; if (find_directory(B_USER_DIRECTORY, &path) == B_OK) { path.Append("people"); get_ref_for_path(path.Path(), &people); } BFilePanel *panel; panel = new BFilePanel(B_OPEN_PANEL, NULL, &people, B_FILE_NODE, false, NULL, &filter); // trick to synchronously use BFilePanel PanelHandler *handler = new PanelHandler; if (panel->Window()->Lock()) { panel->Window()->AddHandler(handler); panel->Window()->Unlock(); } panel->SetTarget(BMessenger(handler)); panel->Show(); if (handler->Wait() < B_OK) break; if (!handler->Message()) break; if (handler->Message()->what == B_CANCEL) break; entry_ref ref; //panel->Message()->PrintToStream(); if (panel->GetNextSelectedRef(&ref) == B_OK) { //printf("ref:%s\n", ref.name); path.SetTo(&ref); dir.WriteAttr("pe:author_people", B_STRING_TYPE, 0LL, path.Path(), strlen(path.Path())); } delete panel; delete handler; err = B_CANCELED; break; } case B_ABOUT_REQUESTED: { BString tmpPath("/tmp/Pe-HeaderHeader-About-"); tmpPath << system_time() << "-" << getpid() << ".txt"; entry_ref ref; get_ref_for_path(tmpPath.String(), &ref); { BFile f(&ref, B_CREATE_FILE | B_WRITE_ONLY); err = f.InitCheck(); if (err < 0) break; f.Write(sAboutText, strlen(sAboutText)); f.SetPermissions(0444); } BMessage msg(B_REFS_RECEIVED); msg.AddRef("refs", &ref); err = be_app_messenger.SendMessage(&msg); err = B_CANCELED; break; } case 0: err = B_CANCELED; break; default: break; } delete menu; return err; }
/* 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(); }
SDL_bool filerequester( struct machine *oric, char *title, char *path, char *fname, int type ) { BFilePanel *panel; PanelLooper *looper = new PanelLooper(); looper->Run(); SDL_bool ret; char *pat; bool dosavemode = false; switch( type ) { case FR_DISKSAVE: dosavemode = true; case FR_DISKLOAD: pat = "*.dsk"; break; // FIXME: Save TAP should be *.tap, save ORT should be *.ort, Load should be *.tap, *.ort, *.wav case FR_TAPESAVETAP: case FR_TAPESAVEORT: dosavemode = true; case FR_TAPELOAD: pat = "*.tap"; break; case FR_ROMS: pat = "*.rom"; break; case FR_SNAPSHOTSAVE: dosavemode = true; case FR_SNAPSHOTLOAD: pat = "*.sna"; break; case FR_KEYMAPPINGSAVE: dosavemode = true; case FR_KEYMAPPINGLOAD: pat = "*.kma"; break; default: pat = NULL; break; } //XXX: use RefFilter panel = new BFilePanel(dosavemode ? B_SAVE_PANEL : B_OPEN_PANEL); panel->SetTarget(BMessenger(looper)); if (path) panel->SetPanelDirectory(path); panel->Show(); looper->Wait(); ret = looper->DoIt(); entry_ref ref; looper->GetRef(ref); delete panel; looper->Lock(); looper->Quit(); if (ret) { BPath p(&ref); strncpy( fname, p.Leaf(), 512 ); path[511] = 0; p.GetParent(&p); strncpy( path, p.Path(), 4096 ); path[4095] = 0; } return ret; }
void FileTypes::MessageReceived(BMessage* message) { switch (message->what) { case kMsgSettingsChanged: fSettings.UpdateFrom(message); break; case kMsgOpenTypesWindow: if (fTypesWindow == NULL) { fTypesWindow = new FileTypesWindow(fSettings.Message()); if (fArgvType.Length() > 0) { // Set the window to the type that was requested on the // command line (-type), we do this only once, if we // ever opened more than one FileTypesWindow. fTypesWindow->SelectType(fArgvType.String()); fArgvType = ""; } fTypesWindow->Show(); fWindowCount++; } else fTypesWindow->Activate(true); break; case kMsgTypesWindowClosed: fTypesWindow = NULL; _WindowClosed(); break; case kMsgOpenApplicationTypesWindow: if (fApplicationTypesWindow == NULL) { fApplicationTypesWindow = new ApplicationTypesWindow( fSettings.Message()); fApplicationTypesWindow->Show(); fWindowCount++; } else fApplicationTypesWindow->Activate(true); break; case kMsgApplicationTypesWindowClosed: fApplicationTypesWindow = NULL; _WindowClosed(); break; case kMsgTypeWindowClosed: fTypeWindowCount--; // supposed to fall through case kMsgWindowClosed: _WindowClosed(); break; case kMsgOpenFilePanel: { // the open file panel sends us a message when it's done const char* subTitle; if (message->FindString("title", &subTitle) != B_OK) subTitle = B_TRANSLATE("Open file"); int32 what; if (message->FindInt32("message", &what) != B_OK) what = B_REFS_RECEIVED; BMessenger target; if (message->FindMessenger("target", &target) != B_OK) target = be_app_messenger; BString title = B_TRANSLATE("FileTypes"); if (subTitle != NULL && subTitle[0]) { title.Append(": "); title.Append(subTitle); } uint32 flavors = B_FILE_NODE; if (message->FindBool("allowDirs")) flavors |= B_DIRECTORY_NODE; fFilePanel->SetNodeFlavors(flavors); fFilePanel->SetMessage(new BMessage(what)); fFilePanel->Window()->SetTitle(title.String()); fFilePanel->SetTarget(target); if (!fFilePanel->IsShowing()) fFilePanel->Show(); break; } case B_SILENT_RELAUNCH: // In case we were launched via the add-on, there is no types // window yet. if (fTypesWindow == NULL) PostMessage(kMsgOpenTypesWindow); break; case B_CANCEL: if (fWindowCount == 0) PostMessage(B_QUIT_REQUESTED); break; case B_SIMPLE_DATA: RefsReceived(message); break; default: BApplication::MessageReceived(message); break; } }
bool ClientWindow::ParseCmd (const char *data) { BString firstWord (GetWord(data, 1).ToUpper()); if (firstWord == "/WALLOPS" // we need to insert a ':' before parm2 || firstWord == "/SQUIT" // for the user || firstWord == "/PRIVMSG") { BString theCmd (firstWord.RemoveAll ("/")), theRest (RestOfString (data, 2)); BMessage send (M_SERVER_SEND); AddSend (&send, theCmd); if (theRest != "-9z99") { AddSend (&send, " :"); AddSend (&send, theRest); } AddSend (&send, endl); return true; } if (firstWord == "/KILL") // we need to insert a ':' before parm3 { // for the user BString theCmd (firstWord.RemoveAll ("/")), theTarget (GetWord (data, 2)), theRest (RestOfString (data, 3)); BMessage send (M_SERVER_SEND); AddSend (&send, theCmd); AddSend (&send, " "); AddSend (&send, theTarget); if (theRest != "-9z99") { AddSend (&send, " :"); AddSend (&send, theRest); } AddSend (&send, endl); return true; } // some quick aliases for scripts, these will of course be // moved to an aliases section eventually if (firstWord == "/SOUNDPLAY" || firstWord == "/CL-AMP") { app_info ai; be_app->GetAppInfo (&ai); BEntry entry (&ai.ref); BPath path; entry.GetPath (&path); path.GetParent (&path); //path.Append ("data"); path.Append ("scripts"); if (firstWord == "/SOUNDPLAY") path.Append ("soundplay-hey"); else path.Append ("cl-amp-clr"); BMessage *msg (new BMessage); msg->AddString ("exec", path.Path()); msg->AddPointer ("client", this); thread_id execThread = spawn_thread ( ExecPipe, "exec_thread", B_LOW_PRIORITY, msg); resume_thread (execThread); return true; } if (firstWord == "/ABOUT") { be_app_messenger.SendMessage (B_ABOUT_REQUESTED); return true; } if (firstWord == "/AWAY") { BString theReason (RestOfString (data, 2)); BString tempString; if (theReason != "-9z99") { //nothing to do } else { theReason = "BRB"; // Todo: make a default away msg option } const char *expansions[1]; expansions[0] = theReason.String(); tempString = ExpandKeyed (bowser_app->GetCommand (CMD_AWAY).String(), "R", expansions); tempString.RemoveFirst("\n"); BMessage send (M_SERVER_SEND); AddSend (&send, "AWAY"); AddSend (&send, " :"); AddSend (&send, theReason.String()); AddSend (&send, endl); if (id != serverName) { ActionMessage (tempString.String(), myNick.String()); } return true; } if (firstWord == "/BACK") { BMessage send (M_SERVER_SEND); AddSend (&send, "AWAY"); AddSend (&send, endl); if (id != serverName) { ActionMessage ( bowser_app->GetCommand (CMD_BACK).String(), myNick.String()); } return true; } if (firstWord == "/CHANSERV" || firstWord == "/NICKSERV" || firstWord == "/MEMOSERV") { BString theCmd (firstWord.RemoveFirst ("/")), theRest (RestOfString (data, 2)); theCmd.ToLower(); if (theRest != "-9z99") { if (bowser_app->GetMessageOpenState()) { BMessage msg (OPEN_MWINDOW); BMessage buffer (M_SUBMIT); buffer.AddString ("input", theRest.String()); msg.AddMessage ("msg", &buffer); msg.AddString ("nick", theCmd.String()); sMsgr.SendMessage (&msg); } else { BString tempString; tempString << "[M]-> " << theCmd << " > " << theRest << "\n"; Display (tempString.String(), 0); BMessage send (M_SERVER_SEND); AddSend (&send, "PRIVMSG "); AddSend (&send, theCmd); AddSend (&send, " :"); AddSend (&send, theRest); AddSend (&send, endl); } } return true; } if (firstWord == "/CLEAR") { text->ClearView (false); return true; } if (firstWord == "/FCLEAR") { text->ClearView (true); return true; } if (firstWord == "/CTCP") { BString theTarget (GetWord (data, 2)); BString theAction (RestOfString (data, 3)); if (theAction != "-9z99") { theAction.ToUpper(); if (theAction.ICompare ("PING") == 0) { time_t now (time (0)); theAction << " " << now; } CTCPAction (theTarget, theAction); BMessage send (M_SERVER_SEND); AddSend (&send, "PRIVMSG "); AddSend (&send, theTarget << " :\1" << theAction << "\1"); AddSend (&send, endl); } return true; } if (firstWord == "/DCC") { BString secondWord (GetWord (data, 2)); BString theNick (GetWord (data, 3)); BString theFile (RestOfString(data, 4)); if (secondWord.ICompare ("SEND") == 0 && theNick != "-9z99") { BMessage *msg (new BMessage (CHOSE_FILE)); msg->AddString ("nick", theNick.String()); if (theFile != "-9z99") { char filePath[B_PATH_NAME_LENGTH] = "\0"; if (theFile.ByteAt(0) != '/') { find_directory(B_USER_DIRECTORY, 0, false, filePath, B_PATH_NAME_LENGTH); filePath[strlen(filePath)] = '/'; } strcat(filePath, theFile.LockBuffer(0)); theFile.UnlockBuffer(); // use BPath to resolve relative pathnames, above code forces it // to use /boot/home as a working dir as opposed to the app path BPath sendPath(filePath, NULL, true); // the BFile is used to verify if the file exists // based off the documentation get_ref_for_path *should* // return something other than B_OK if the file doesn't exist // but that doesn't seem to be working correctly BFile sendFile(sendPath.Path(), B_READ_ONLY); // if the file exists, send, otherwise drop to the file panel if (sendFile.InitCheck() == B_OK) { sendFile.Unset(); entry_ref ref; get_ref_for_path(sendPath.Path(), &ref); msg->AddRef("refs", &ref); sMsgr.SendMessage(msg); return true; } } BFilePanel *myPanel (new BFilePanel); BString myTitle ("Sending a file to "); myTitle.Append (theNick); myPanel->Window()->SetTitle (myTitle.String()); myPanel->SetMessage (msg); myPanel->SetButtonLabel (B_DEFAULT_BUTTON, "Send"); myPanel->SetTarget (sMsgr); myPanel->Show(); } else if (secondWord.ICompare ("CHAT") == 0 && theNick != "-9z99") { BMessage msg (CHAT_ACTION); msg.AddString ("nick", theNick.String()); sMsgr.SendMessage (&msg); } return true; } if (firstWord == "/DOP" || firstWord == "/DEOP") { BString theNick (RestOfString (data, 2)); if (theNick != "-9z99") { BMessage send (M_SERVER_SEND); AddSend (&send, "MODE "); AddSend (&send, id); AddSend (&send, " -oooo "); AddSend (&send, theNick); AddSend (&send, endl); } return true; } if (firstWord == "/DESCRIBE") { BString theTarget (GetWord (data, 2)); BString theAction (RestOfString (data, 3)); if (theAction != "-9z99") { BMessage send (M_SERVER_SEND); AddSend (&send, "PRIVMSG "); AddSend (&send, theTarget); AddSend (&send, " :\1ACTION "); AddSend (&send, theAction); AddSend (&send, "\1"); AddSend (&send, endl); BString theActionMessage ("[ACTION]-> "); theActionMessage << theTarget << " -> " << theAction << "\n"; Display (theActionMessage.String(), 0); } return true; } if (firstWord == "/DNS") { BString parms (GetWord(data, 2)); ChannelWindow *window; MessageWindow *message; if ((window = dynamic_cast<ChannelWindow *>(this))) { int32 count (window->namesList->CountItems()); for (int32 i = 0; i < count; ++i) { NameItem *item ((NameItem *)(window->namesList->ItemAt (i))); if (!item->Name().ICompare (parms.String(), strlen (parms.String()))) //nick { BMessage send (M_SERVER_SEND); AddSend (&send, "USERHOST "); AddSend (&send, item->Name().String()); AddSend (&send, endl); PostMessage(&send); return true; } } } else if ((message = dynamic_cast<MessageWindow *>(this))) { BString eid (id); eid.RemoveLast (" [DCC]"); if (!ICompare(eid, parms) || !ICompare(myNick, parms)) { BMessage send (M_SERVER_SEND); AddSend (&send, "USERHOST "); AddSend (&send, parms.String()); AddSend (&send, endl); PostMessage(&send); return true; } } if (parms != "-9z99") { BMessage *msg (new BMessage); msg->AddString ("lookup", parms.String()); msg->AddPointer ("client", this); thread_id lookupThread = spawn_thread ( DNSLookup, "dns_lookup", B_LOW_PRIORITY, msg); resume_thread (lookupThread); } return true; } if (firstWord == "/PEXEC") // piped exec { BString theCmd (RestOfString (data, 2)); if (theCmd != "-9z99") { BMessage *msg (new BMessage); msg->AddString ("exec", theCmd.String()); msg->AddPointer ("client", this); thread_id execThread = spawn_thread ( ExecPipe, "exec_thread", B_LOW_PRIORITY, msg); resume_thread (execThread); } return true; } if (firstWord == "/EXCLUDE") { BString second (GetWord (data, 2)), rest (RestOfString (data, 3)); if (rest != "-9z99" && rest != "-9z99") { BMessage msg (M_EXCLUDE_COMMAND); msg.AddString ("second", second.String()); msg.AddString ("cmd", rest.String()); msg.AddString ("server", serverName.String()); msg.AddRect ("frame", Frame()); bowser_app->PostMessage (&msg); } return true; } if (firstWord == "/IGNORE") { BString rest (RestOfString (data, 2)); if (rest != "-9z99") { BMessage msg (M_IGNORE_COMMAND); msg.AddString ("cmd", rest.String()); msg.AddString ("server", serverName.String()); msg.AddRect ("frame", Frame()); bowser_app->PostMessage (&msg); } return true; } if (firstWord == "/INVITE" || firstWord == "/I") { BString theUser (GetWord (data, 2)); if (theUser != "-9z99") { BString theChan (GetWord (data, 3)); if (theChan == "-9z99") theChan = id; BMessage send (M_SERVER_SEND); AddSend (&send, "INVITE "); AddSend (&send, theUser << " " << theChan); AddSend (&send, endl); } return true; } if (firstWord == "/JOIN" || firstWord == "/J") { BString channel (GetWord (data, 2)); if (channel != "-9z99") { if (channel[0] != '#' && channel[0] != '&') channel.Prepend("#"); BMessage send (M_SERVER_SEND); AddSend (&send, "JOIN "); AddSend (&send, channel); BString key (GetWord (data, 3)); if (key != "-9z99") { AddSend (&send, " "); AddSend (&send, key); } AddSend (&send, endl); } return true; } if (firstWord == "/KICK" || firstWord == "/K") { BString theNick (GetWord (data, 2)); if (theNick != "-9z99") { BString theReason (RestOfString (data, 3)); if (theReason == "-9z99") { // No expansions theReason = bowser_app ->GetCommand (CMD_KICK); } BMessage send (M_SERVER_SEND); AddSend (&send, "KICK "); AddSend (&send, id); AddSend (&send, " "); AddSend (&send, theNick); AddSend (&send, " :"); AddSend (&send, theReason); AddSend (&send, endl); } return true; } if (firstWord == "/LIST") { BMessage msg (M_LIST_COMMAND); msg.AddString ("cmd", data); msg.AddString ("server", serverName.String()); msg.AddRect ("frame", Frame()); bowser_app->PostMessage (&msg); return true; } if (firstWord == "/M") { BString theMode (RestOfString (data, 2)); BMessage send (M_SERVER_SEND); AddSend (&send, "MODE "); if (id == serverName) AddSend (&send, myNick); else if (id[0] == '#' || id[0] == '&') AddSend (&send, id); else AddSend (&send, myNick); if (theMode != "-9z99") { AddSend (&send, " "); AddSend (&send, theMode); } AddSend (&send, endl); return true; } if (firstWord == "/ME") { BString theAction (RestOfString (data, 2)); if (theAction != "-9z99") { ActionMessage (theAction.String(), myNick.String()); } return true; } if (firstWord == "/MODE") { BString theMode (RestOfString (data, 3)); BString theTarget (GetWord (data, 2)); if (theTarget != "-9z99") { BMessage send (M_SERVER_SEND); AddSend (&send, "MODE "); if (theMode == "-9z99") AddSend (&send, theTarget); else AddSend (&send, theTarget << " " << theMode); AddSend (&send, endl); } return true; } if (firstWord == "/MSG") { BString theRest (RestOfString (data, 3)); BString theNick (GetWord (data, 2)); if (theRest != "-9z99" && myNick.ICompare (theNick)) { if (bowser_app->GetMessageOpenState()) { BMessage msg (OPEN_MWINDOW); BMessage buffer (M_SUBMIT); buffer.AddString ("input", theRest.String()); msg.AddMessage ("msg", &buffer); msg.AddString ("nick", theNick.String()); sMsgr.SendMessage (&msg); } else { BString tempString; tempString << "[M]-> " << theNick << " > " << theRest << "\n"; Display (tempString.String(), 0); BMessage send (M_SERVER_SEND); AddSend (&send, "PRIVMSG "); AddSend (&send, theNick); AddSend (&send, " :"); AddSend (&send, theRest); AddSend (&send, endl); } } return true; } if (firstWord == "/NICK") { BString newNick (GetWord (data, 2)); if (newNick != "-9z99") { BString tempString ("*** Trying new nick "); tempString << newNick << ".\n"; Display (tempString.String(), 0); BMessage send (M_SERVER_SEND); AddSend (&send, "NICK "); AddSend (&send, newNick); AddSend (&send, endl); } return true; } if (firstWord == "/NOTICE") { BString theTarget (GetWord (data, 2)); BString theMsg (RestOfString (data, 3)); if (theMsg != "-9z99") { BMessage send (M_SERVER_SEND); AddSend (&send, "NOTICE "); AddSend (&send, theTarget); AddSend (&send, " :"); AddSend (&send, theMsg); AddSend (&send, endl); BString tempString ("[N]-> "); tempString << theTarget << " -> " << theMsg << '\n'; Display (tempString.String(), 0); } return true; } if (firstWord == "/NOTIFY") { BString rest (RestOfString (data, 2)); if (rest != "-9z99") { BMessage msg (M_NOTIFY_COMMAND); msg.AddString ("cmd", rest.String()); msg.AddBool ("add", true); msg.AddString ("server", serverName.String()); msg.AddRect ("frame", Frame()); bowser_app->PostMessage (&msg); } return true; } if (firstWord == "/OP") { BString theNick (RestOfString (data, 2)); if (theNick != "-9z99") { // TODO only applies to a channel BMessage send (M_SERVER_SEND); AddSend (&send, "MODE "); AddSend (&send, id); AddSend (&send, " +oooo "); AddSend (&send, theNick); AddSend (&send, endl); } return true; } if (firstWord == "/PART") { BMessage msg (B_QUIT_REQUESTED); msg.AddBool ("bowser:part", true); PostMessage (&msg); return true; } if (firstWord == "/PING") { BString theNick (GetWord (data, 2)); if (theNick != "-9z99") { long theTime (time (0)); BString tempString ("/CTCP "); tempString << theNick << " PING " << theTime; SlashParser (tempString.String()); } return true; } if (firstWord == "/PREFERENCES") { be_app_messenger.SendMessage (M_PREFS_BUTTON); return true; } if (firstWord == "/QUERY" || firstWord == "/Q") { BString theNick (GetWord (data, 2)); if (theNick != "-9z99") { BMessage msg (OPEN_MWINDOW); msg.AddString ("nick", theNick.String()); sMsgr.SendMessage (&msg); } return true; } if (firstWord == "/QUIT") { BString theRest (RestOfString (data, 2)); BString buffer; if (theRest == "-9z99") { const char *expansions[1]; BString version (bowser_app->BowserVersion()); expansions[0] = version.String(); theRest = ExpandKeyed (bowser_app ->GetCommand (CMD_QUIT).String(), "V", expansions); } buffer << "QUIT :" << theRest; BMessage msg (B_QUIT_REQUESTED); msg.AddString ("bowser:quit", buffer.String()); sMsgr.SendMessage (&msg); return true; } if (firstWord == "/RAW" || firstWord == "/QUOTE") { BString theRaw (RestOfString (data, 2)); if (theRaw != "-9z99") { BMessage send (M_SERVER_SEND); AddSend (&send, theRaw); AddSend (&send, endl); BString tempString ("[R]-> "); tempString << theRaw << '\n'; Display (tempString.String(), 0); } return true; } if (firstWord == "/RECONNECT") { BMessage msg (M_SLASH_RECONNECT); msg.AddString ("server", serverName.String()); bowser_app->PostMessage (&msg); return true; } if (firstWord == "/SLEEP") { BString rest (RestOfString (data, 2)); if (rest != "-9z99") { // this basically locks up the window its run from, // but I can't think of a better way with our current // commands implementation int32 time = atoi(rest.String()); snooze(time * 1000 * 100); // deciseconds? 10 = one second } return true; } if (firstWord == "/TOPIC" || firstWord == "/T") { BString theChan (id); BString theTopic (RestOfString (data, 2)); BMessage send (M_SERVER_SEND); AddSend (&send, "TOPIC "); if (theTopic == "-9z99") AddSend (&send, theChan); else AddSend (&send, theChan << " :" << theTopic); AddSend (&send, endl); return true; } if (firstWord == "/UNIGNORE") { BString rest (RestOfString (data, 2)); if (rest != "-9z99") { BMessage msg (M_UNIGNORE_COMMAND); msg.AddString ("cmd", rest.String()); msg.AddString ("server", serverName.String()); msg.AddRect ("frame", Frame()); bowser_app->PostMessage (&msg); } return true; } if (firstWord == "/UNNOTIFY") { BString rest (RestOfString (data, 2)); if (rest != "-9z99") { BMessage msg (M_NOTIFY_COMMAND); msg.AddString ("cmd", rest.String()); msg.AddBool ("add", false); msg.AddRect ("frame", Frame()); msg.AddString ("server", serverName.String()); bowser_app->PostMessage (&msg); } return true; } if (firstWord == "/UPTIME") { BString parms (GetWord(data, 2)); BString uptime (DurationString(system_time())); BString expandedString; const char *expansions[1]; expansions[0] = uptime.String(); expandedString = ExpandKeyed (bowser_app->GetCommand (CMD_UPTIME).String(), "U", expansions); expandedString.RemoveFirst("\n"); if ((id != serverName) && (parms == "-9z99")) { BMessage send (M_SERVER_SEND); AddSend (&send, "PRIVMSG "); AddSend (&send, id); AddSend (&send, " :"); AddSend (&send, expandedString.String()); AddSend (&send, endl); ChannelMessage (expandedString.String(), myNick.String()); } else if ((parms == "-l") || (id == serverName)) // echo locally { BString tempString; tempString << "Uptime: " << expandedString << "\n"; Display (tempString.String(), &whoisColor); } return true; } if (firstWord == "/VERSION" || firstWord == "/TIME") { BString theCmd (firstWord.RemoveFirst ("/")), theNick (GetWord (data, 2)); theCmd.ToUpper(); // the "." check is because the user might specify a server name if (theNick != "-9z99" && theNick.FindFirst(".") < 0) { BString tempString ("/CTCP "); tempString << theNick << " " << theCmd; SlashParser (tempString.String()); } else { BMessage send (M_SERVER_SEND); AddSend (&send, theCmd); if (theNick != "-9z99") { AddSend (&send, " "); AddSend (&send, theNick); } AddSend (&send, endl); } return true; } if (firstWord == "/VISIT") { BString buffer (data); int32 place; if ((place = buffer.FindFirst (" ")) >= 0) { buffer.Remove (0, place + 1); const char *arguments[] = {buffer.String(), 0}; be_roster->Launch ( "text/html", 1, const_cast<char **>(arguments)); } return true; } if (firstWord != "" && firstWord[0] == '/') // != "" is required to prevent a nasty crash with string[0] { BString theCmd (firstWord.RemoveAll ("/")), theRest (RestOfString (data, 2)); BMessage send (M_SERVER_SEND); if (theCmd == "W") theCmd = "WHOIS"; AddSend (&send, theCmd); if (theRest != "-9z99") { AddSend (&send, " "); AddSend (&send, theRest); } AddSend (&send, endl); return true; } return false; // we couldn't handle this message }