int GUIControl::CreateDesktop( char *name, char *description, int *id ) { Message *msg = new Message( CREATE ); msg->AddString( "_type", "desktop" ); msg->AddString( "_name", name ); msg->AddString( "_description", description ); Message *reply = Messenger::SendReceiveMessage( "gui_server", 0 , msg ); if ( reply == NULL ) { delete msg; return -1; } delete msg; if ( reply->rc() != 0 ) { if ( msg->error() != NULL ) printf("%s%s\n","error: ", msg->error() ); delete reply; return -1; } if ( reply->FindInt( "_id", id ) != 0 ) { delete reply; return -1; } delete reply; return 0; }
// Idiom: SaveToArchive() saves our current state into the specified Message object status_t SaveToArchive(Message & msg) const { if (msg.AddString("name", _name) != B_NO_ERROR) return B_ERROR; if (msg.AddString("address", _address) != B_NO_ERROR) return B_ERROR; if (msg.AddString("city", _city) != B_NO_ERROR) return B_ERROR; if (msg.AddString("state", _state) != B_NO_ERROR) return B_ERROR; if (msg.AddInt32("zip_code", _zipCode) != B_NO_ERROR) return B_ERROR; return B_NO_ERROR; // success! }
status_t DbxImporter::ProcessFolder( DBX *hDbx ) { status_t nError = EOK; DBXFOLDER *psFolder = NULL; for( int i = hDbx->indexCount-1; i >= 0; i-- ) { dbx_free( hDbx, psFolder ); psFolder=(DBXFOLDER*)dbx_get( hDbx, i, 0 ); if( dbx_errno != DBX_NOERROR ) { std::cerr << "failed to read folder" << std::endl; nError = EIO; break; } if( NULL == psFolder ) continue; if( psFolder->fname != NULL ) { String cPath = m_cPath + String( psFolder->fname ); DBX *psChild = dbx_open( cPath.c_str() ); if( NULL == psChild ) { std::cerr << "failed to open child folder" << std::endl; continue; } if( psChild->type != DBX_TYPE_EMAIL ) { std::cerr << "Folder " << psFolder->fname << " doesn't contain emails like I expect" << std::endl; continue; } /* Create sub-folder */ String cChild = String( psFolder->name ); String cTarget = m_cFolder + String( "/" ) + cChild; Message *pcMessage = new Message( M_IMPORT_CREATE_FOLDER ); pcMessage->AddString( "parent", m_cFolder ); pcMessage->AddString( "name", cChild ); m_pcMessenger->SendMessage( pcMessage ); /* Add all messages to the sub-folder */ nError = ProcessMail( psChild, cTarget ); dbx_close( psChild ); if( m_bRun == false ) break; } } return nError; }
int Window::Register() { Message *msg = new Message(REGISTER); msg->AddString( "_type", "window" ); msg->AddInt( "_port", Port() ); msg->AddString( "_title", m_title ); msg->AddRect( "_rect", Frame() ); msg->AddBool( "_visible", false ); msg->AddInt( "_flags", m_flags ); Message *reply = Messenger::SendReceiveMessage( "gui_server", 0, msg ); if ( reply == NULL ) { delete msg; return -1; } delete msg; if ( reply->rc() != 0 ) { delete reply; return -1; } // Good reply.. let's get the information. int bad = 0; if ( reply->FindInt( "_id", &m_wid ) != 0 ) bad = -1; if ( reply->FindInt( "_sid", &m_sid ) != 0 ) bad = -1; if ( reply->FindInt( "_did", &m_did ) != 0 ) bad = -1; if ( reply->FindRect( "_rect", &m_frame ) != 0 ) bad = -1; delete reply; // Accept the GUI memory and everything. int tmp_pages; unsigned int tmp_flags; if ( smk_request_shmem( m_sid, (void**)&m_buffer, &tmp_pages, &tmp_flags ) != 0 ) bad = -1; // We now have our GUI buffer, size and ID. if ( bad != 0 ) return -1; // Registered with desktop port = m_did return 0; }
status_t DbxImporter::AddMessage( String &cMessage, const String &cFolder ) { if( cMessage != "" ) { /* Add an RFC2822 terminating sequence */ cMessage += "\r\n.\r\n"; /* Create a Mailmessage and send it back down to the application along with the relevent data */ Mailmessage *pcImport = new Mailmessage( cMessage.c_str(), cMessage.size() ); Message *pcImportMessage = new Message( M_IMPORT_NEW ); pcImportMessage->AddPointer( "message", pcImport ); pcImportMessage->AddString( "folder", cFolder ); m_pcMessenger->SendMessage( pcImportMessage ); /* Update the progress dialog & check if the user canceled */ //float vProgress = ( (double)m_nBytes / (double)m_nSize ); float vProgress = ( (double)m_nTotal / (double)m_nCount ); char zMessage[64] = { '\0' }; snprintf( zMessage, 64, "Importing message #%Ld", m_nTotal++ ); m_pcDialog->Lock(); m_pcDialog->SetMessage( zMessage ); m_pcDialog->SetProgress( vProgress ); m_bRun = !m_pcDialog->IsCancelled(); m_pcDialog->Unlock(); } cMessage = ""; return EOK; }
int GUIControl::GetDesktop( int *desktop_id ) { Message *msg = new Message( GET ); msg->AddString( "_type", "desktop" ); Message *reply = Messenger::SendReceiveMessage( "gui_server", 0, msg ); if ( reply == NULL ) { delete msg; return -1; } delete msg; int ans = reply->rc(); if ( ans != 0 ) { if ( msg->error() != NULL ) printf("%s%s\n","error: ", msg->error() ); } if ( reply->FindInt( "_id", desktop_id ) != 0 ) ans = -1; delete reply; return ans; }
void HexView::SetMessage(const String &cText) { Message *pcMsg = new Message(EV_SHOW_MESSAGE); pcMsg->AddString(MESSAGE_TEXT_KEY, cText); Messenger cMnger(m_pcHandler); cMnger.SendMessage(pcMsg); }
int GUIControl::SetDesktopDriver( int desktop_id, int video_id ) { Message *msg = new Message( SET ); msg->AddString( "_type", "desktop_driver" ); msg->AddInt( "_id", desktop_id ); msg->AddInt( "_vid", video_id ); Message *reply = Messenger::SendReceiveMessage( "gui_server", 0, msg ); if ( reply == NULL ) { delete msg; return -1; } delete msg; int ans = reply->rc(); if ( ans != 0 ) { if ( msg->error() != NULL ) printf("%s%s\n","error: ", msg->error() ); } delete reply; return ans; }
int GUIControl::DeleteDesktop( int desktop_id ) { Message *msg = new Message( DELETE ); msg->AddString( "_type", "desktop" ); msg->AddInt( "_id", desktop_id ); Message *reply = Messenger::SendReceiveMessage( "gui_server", 0, msg ); if ( reply == NULL ) { delete msg; return -1; } delete msg; if ( reply->rc() != 0 ) { if ( msg->error() != NULL ) printf("%s%s\n","error: ", msg->error() ); delete reply; return -1; } delete reply; return 0; }
bool EditWin::OkToQuit(void) { Message *m = new Message( ID_UNLOCK ); m->AddString( "id", m_cID ); m_pcMessenger->SendMessage( m ); return true; }
int GUIControl::SetMode( int video_id, int width, int height, int mode ) { Message *msg = new Message( SET ); msg->AddString( "_type", "video_mode" ); msg->AddInt( "_id", video_id ); msg->AddInt( "_width", width ); msg->AddInt( "_height", height ); msg->AddInt( "_mode", mode ); Message *reply = Messenger::SendReceiveMessage( "gui_server", 0, msg ); if ( reply == NULL ) { delete msg; return -1; } int ans = reply->rc(); if ( ans != 0 ) { if ( msg->error() != NULL ) printf("%s%s\n","error: ", msg->error() ); } delete reply; delete msg; return ans; }
void IFaceWin::SendCloseMessage( void ) { Messenger cMsnger( m_pcParent ); Message *pcMsg = new Message( CloseInterfaceWindow ); pcMsg->AddString( INTERFACE_NAME_KEY, m_pcIFace->GetName() ); cMsnger.SendMessage( pcMsg ); }
int GUIControl::GetDriverList( List *drivers ) { Message *msg = new Message( GET ); msg->AddString( "_type", "driver_list" ); Message *reply = Messenger::SendReceiveMessage( "gui_server", 0, msg ); if ( reply == NULL ) { delete msg; return -1; } delete msg; if ( reply->rc() != 0 ) { if ( msg->error() != NULL ) printf("%s%s\n","error: ", msg->error() ); delete reply; return -1; } // -------------------------------- int id; char *name; char *description; int count = 0; while ( (reply->FindInt( "_id", count, &id )) == 0 ) { if ( reply->FindString( "_description", count, (const char**)&description ) == 0 ) if ( reply->FindString( "_name", count, (const char**)&name ) == 0 ) { struct video_driver_info *vd = new struct video_driver_info; vd->id = id; strncpy( vd->name, name, 1024 ); strncpy( vd->description, description, 1024 ); drivers->add( vd ); free( name ); free( description ); } else free( description ); count += 1; } // -------------------------------- delete reply; return 0; }
int GUIControl::GetSupportedModes( List* modes ) { Message *msg = new Message( GET ); msg->AddString( "_type", "supported_modes" ); Message *reply = Messenger::SendReceiveMessage( "gui_server", 0, msg ); if ( reply == NULL ) { delete msg; return -1; } delete msg; if ( reply->rc() != 0 ) { if ( msg->error() != NULL ) printf("%s%s\n","error: ", msg->error() ); delete reply; return -1; } // -------------------------------- int id; int width; int height; int mode; int count = 0; while ( (reply->FindInt( "_id", count, &id )) == 0 ) { if ( reply->FindInt( "_width", count, &width ) == 0 ) if ( reply->FindInt( "_height", count, &height ) == 0 ) if ( reply->FindInt( "_mode", count, &mode ) == 0 ) { struct video_mode *vm = new struct video_mode; vm->id = id; vm->width = width; vm->height = height; vm->mode = mode; modes->add( vm ); } count += 1; } // -------------------------------- delete reply; return 0; }
/** Convenience method to sends a reply Message with a * what value of "OK", and the given "rc" and "_error" * parameters. * * \param rc The return code which will be embedded as an Int named "rc". * \param error The return string to embed as "_error". Nothing is embedded * if NULL is specified. * * \return 0 if the reply was sent successfully. */ int Message::SendRC( int rc, char *error ) { Message *msg = new Message( OK ); msg->AddInt( "rc", rc ); if ( error != NULL ) msg->AddString( "_error", error ); int ans = SendReply( msg ); delete msg; return ans; }
/************************************************* * Description: Saves the settings * Author: Rick Caudill * Date: Thu Mar 18 20:17:32 2004 **************************************************/ void WallpaperChangerSettings::SaveSettings() { ListViewStringRow* pcRow = (ListViewStringRow*)pcDirectoryList->GetRow(pcDirectoryList->GetLastSelected()); Message* pcMessage = new Message(M_PREFS_SEND_TO_PARENT); bRandom = pcRandom->GetValue().AsBool(); pcMessage->AddBool("random",bRandom); pcMessage->AddInt32("time",pcTimeDrop->GetSelection()); pcMessage->AddString("currentimage",pcRow->GetString(0)); pcParentLooper->PostMessage(pcMessage,pcParentView); }
/** \brief Create and display icons for each of the RemoteNodes. in pacNodes. * This sets the remote view contents and updates the layout when necessary. * It also gets the initial path the first time it is called. * * \todo Perform periodic layouts while downloading large dirlisting. * \todo Display file sizes in a human readable format? * \todo Move the entry path stuff somewhere else? * * \param pacNodes List of RemoteNodes that should be updated for the remote view contents. * \param bInitial Set this to true if this is the first of several messages and we should clear the iconview first. * \param bFinal Set this to true if this is the last of the directory listing. and should Layout() when done. */ void RemoteIconView::SetContents( std::vector< RemoteNode >* pacNodes, bool bInitial, bool bFinal ) { /* If we haven't yet got the entry path, get it now. */ if( m_zPath == "" ) { /* \todo Is it possible that GetEntryPath() could be "" ? */ if( m_pcServer->GetEntryPath() != "" ) { m_zPath = m_pcServer->GetEntryPath(); if( m_pcDirChangedMsg ) { Message cTmp = *m_pcDirChangedMsg; cTmp.AddString( "file/path", m_zPath ); Invoke( &cTmp ); } } else { DEBUG( "RemoteView: GetEntryPath() is empty.\n" ); } } if( bInitial ) Clear(); /* Remove all icons */ HideMessage(); int nCount = pacNodes->size(); // DEBUG( "RemoteIconView: Dirlisting fragment contains %i nodes; %s initial, %sfinal\n", nCount, bInitial?"":"not ", bFinal?"":"not " ); for( int i = 0; i < nCount; i++ ) { RemoteNode cNode = (*pacNodes)[i]; // DEBUG( " '%s', %s, size %i, permissions %i\n", cNode.GetName().c_str(), (cNode.IsDir() ? "dir" : "file"), cNode.GetSize(), cNode.GetPermissions() ); Image* pcImage = GetNodeImage( &cNode, (GetView() == VIEW_LIST || GetView() == VIEW_DETAILS) ); RemoteIconData* pcData = new RemoteIconData; pcData->m_cNode = cNode; uint nIndex = AddIcon( pcImage, pcData ); AddIconString( nIndex, cNode.GetName() ); String zTmp; if( cNode.IsDir() ) { zTmp = "<Dir>"; } else { zTmp.Format( "%li", cNode.GetSize() ); } AddIconString( nIndex, zTmp ); AddIconString( nIndex, cNode.GetTimestamp().GetDate() ); } // When this is the last of the directory listing, reset the update flag. if( bFinal ) { m_bUpdatePending = false; } Layout(); }
static status_t UnparseFileAux(const Message & readFrom, FILE * optFile, String * optString, uint32 indentLevel) { if ((optFile == NULL)&&(optString == NULL)) return B_ERROR; const String indentStr = String().Pad(indentLevel); Message scratchMsg; for (MessageFieldNameIterator fnIter(readFrom); fnIter.HasData(); fnIter++) { const String & fn = fnIter.GetFieldName(); uint32 tc; if (readFrom.GetInfo(fn, &tc) == B_NO_ERROR) { switch(tc) { case B_MESSAGE_TYPE: { MessageRef nextVal; for (uint32 i=0; readFrom.FindMessage(fn, i, nextVal) == B_NO_ERROR; i++) { AddUnparseFileLine(optFile, optString, indentStr, String("begin %1").Arg(fn)); if (UnparseFileAux(*nextVal(), optFile, optString, indentLevel+3) != B_NO_ERROR) return B_ERROR; AddUnparseFileLine(optFile, optString, indentStr, "end"); } } break; case B_STRING_TYPE: { const String * nextVal; for (uint32 i=0; readFrom.FindString(fn, i, &nextVal) == B_NO_ERROR; i++) { scratchMsg.Clear(); if (scratchMsg.AddString(fn, *nextVal) != B_NO_ERROR) return B_ERROR; AddUnparseFileLine(optFile, optString, indentStr, UnparseArgs(scratchMsg)); } } break; default: // do nothing break; } } else return B_ERROR; // should never happen } return B_NO_ERROR; }
HexEditor(const char *zFile) : Application("application/x-vnd.ADK.HexEditor") { SetCatalog("HexEditor.catalog"); HexEditWindow *pcWin = new HexEditWindow(Rect(50,50,690,530)); pcWin->Start(); pcWin->Show(true); pcWin->MakeFocus(true); if( zFile != NULL ) { Message *pcMsg = new Message(EV_OPEN_FILE_SELECTED); pcMsg->AddString("file/path", zFile); Messenger cMnger(pcWin->GetController()); cMnger.SendMessage(pcMsg); } }
/** \brief Invoked * Handles when an icon within the view is invoked. If it is a directory * it should, the current directory should move into it. If it is a file * it should be opened if possible and otherwise it should be downloaded. * * \todo Should attempt to dowload and open the remote file if it's not a directory? * \todo What should be the default action when the file type is unknown? */ void RemoteIconView::Invoked( uint nIcon, IconData* pcData ) { // DEBUG( "RemoteIconView::Invoked on icon %i (%s)\n", nIcon, GetIconString( nIcon, 0 ).c_str() ); RemoteIconData* pcRData = (RemoteIconData*)pcData; if( pcRData->m_cNode.IsDir() ) { Path cPath = m_zPath; cPath.Append( pcRData->m_cNode.m_zName ); DEBUG( "RemoteView: Changing to %s\n", cPath.GetPath().c_str() ); if( m_pcDirChangedMsg ) { Message cTmp = *m_pcDirChangedMsg; cTmp.AddString( "file/path", cPath.GetPath() ); Invoke( &cTmp ); } SetPath( cPath.GetPath() ); } }
int GUIControl::GetDesktopMode( int desktop_id, int *video_id, int *width, int *height, int *mode ) { Message *msg = new Message( GET ); msg->AddString( "_type", "desktop_mode" ); msg->AddInt( "_id", desktop_id ); Message *reply = Messenger::SendReceiveMessage( "gui_server", 0, msg ); if ( reply == NULL ) { delete msg; return -1; } delete msg; int ans = reply->rc(); if ( ans != 0 ) { if ( msg->error() != NULL ) printf("%s%s\n","error: ", msg->error() ); } if ( reply->FindInt( "_id", video_id ) != 0 ) ans = -1; if ( reply->FindInt( "_width", width ) != 0 ) ans = -1; if ( reply->FindInt( "_height", height ) != 0 ) ans = -1; if ( reply->FindInt( "_mode", mode ) != 0 ) ans = -1; delete reply; return ans; }
int Ext2FS::List( char *node, Message **list ) { struct ext2fs_inode inode; struct ext2fs_direntry dir; *list = NULL; uint32 inum = GetInodeByName( node, &inode ); if ( inum == 0 ) return -1; Message *msg = new Message(OK); int number = 0; while ( get_direntry( inode, number++, &dir ) == 0 ) { dir.name[ dir.name_len ] = 0; msg->AddString("entry", dir.name ); if ( number > 1000 ) break; } *list = msg; return 0; }
status_t MboxImporter::AddMessage( os::String &cMessage ) { if( cMessage != "" ) { if( m_bDoCrLf ) { /* Convert linefeeds to CRLF pairs */ const char *pStart, *pEnd; int nLf = 0; pStart = cMessage.c_str(); while( ( pEnd = strchr( pStart, '\n' ) ) != NULL ) { nLf++; pStart = pEnd + 1; } char *pMessage = (char*)calloc( 1, cMessage.size() + nLf + 1 ); if( NULL == pMessage ) return ENOMEM; const char *pIn; char *pOut; pIn = cMessage.c_str(); pOut = pMessage; while( '\0' != *pIn ) { if( '\n' == *pIn ) *pOut++ = '\r'; *pOut++ = *pIn++; } cMessage = pMessage; free( pMessage ); } /* Add an RFC2822 terminating sequence */ cMessage += "\r\n.\r\n"; /* Create a Mailmessage and send it back down to the application along with the relevent data */ Mailmessage *pcImport = new Mailmessage( cMessage.c_str(), cMessage.size() ); Message *pcImportMessage = new Message( M_IMPORT_NEW ); pcImportMessage->AddPointer( "message", pcImport ); pcImportMessage->AddString( "folder", m_cFolder ); m_pcMessenger->SendMessage( pcImportMessage ); /* Update the progress dialog & check if the user canceled */ float vProgress = ( (double)m_nBytes / (double)m_nSize ); char zMessage[64] = { '\0' }; snprintf( zMessage, 64, "Importing message #%Ld", m_nCount++ ); m_pcDialog->Lock(); m_pcDialog->SetMessage( zMessage ); m_pcDialog->SetProgress( vProgress ); m_bRun = !m_pcDialog->IsCancelled(); m_pcDialog->Unlock(); } cMessage = ""; return EOK; }
void EditWin::HandleMessage(Message *msg) { switch(msg->GetCode()) { case ID_EDIT_ADD: { int sel = m_pcItems->GetFirstSelected(); ListViewStringRow *lvs = new ListViewStringRow; char bfr[16]; sprintf(bfr, "%d", 0); lvs->AppendString(bfr); lvs->AppendString(""); sprintf(bfr, "%d", ++m_nIDCtr); lvs->AppendString(bfr); m_pcItems->ClearSelection(); m_pcItems->InsertRow(sel, lvs); _ReNumber(); } break; case ID_EDIT_DELETE: { int sel = m_pcItems->GetFirstSelected(); if(sel != -1) { m_pcItems->RemoveRow(sel); _ReNumber(); } } break; case ID_EDIT_ITEM: { int sel = m_pcItems->GetFirstSelected(); if(sel != -1) { _EditItem( sel ); } } break; case ID_EDIT_CANCEL: { Message *m = new Message( ID_UNLOCK ); m->AddString( "id", m_cID ); m_pcMessenger->SendMessage( m ); } Close(); break; case ID_EDIT_SAVE: _RebuildArray(); { Message *m = new Message( ID_REFRESH ); m->AddString( "id", m_cID ); m_pcMessenger->SendMessage( m ); } Close(); break; case ID_SAVE_INDEX: { String id; String s; if(msg->FindString("id", &id) == 0) { ListViewStringRow *lvr; for(int i = 0; i < (int)m_pcItems->GetRowCount(); i++) { lvr = (ListViewStringRow *)m_pcItems->GetRow(i); if( lvr->GetString(2) == id ) { lvr->SetIsSelectable(true); if(msg->FindString("data", &s) == 0) { lvr->SetString(1, s); } m_pcItems->InvalidateRow(i, 0); break; } } } // cout << "SAVE_INDEX" << endl; } break; case ID_UNLOCK: { String id; if(msg->FindString("id", &id) == 0) { ListViewStringRow *lvr; for(int i = 0; i < m_pcItems->GetRowCount(); i++) { lvr = (ListViewStringRow *)m_pcItems->GetRow(i); if( lvr->GetString(2) == id ) { lvr->SetIsSelectable(true); break; } } } } break; default: Window::HandleMessage(msg); } }