void ChatView::renderMessage(const MessageView &mv) { QString timestr = formatTimeStamp(mv.dateTime()); QString color = colorString(mv.isLocal(), mv.isSpooled()); if (useMessageIcons_ && mv.isAwaitingReceipt()) { document()->addResource(QTextDocument::ImageResource, QUrl(QString("icon:delivery") + mv.messageId()), logIconSend); } QString icon = useMessageIcons_? (QString("<img src=\"%1\" />").arg(mv.isLocal()? (mv.isAwaitingReceipt()?QString("icon:delivery") + mv.messageId():"icon:log_icon_send"):"icon:log_icon_receive")):""; if (mv.isEmote()) { appendText(icon + QString("<span style=\"color: %1\">").arg(color) + QString("[%1]").arg(timestr) + QString(" *%1 ").arg(TextUtil::escape(mv.nick())) + mv.formattedText() + "</span>"); } else { if (PsiOptions::instance()->getOption("options.ui.chat.use-chat-says-style").toBool()) { appendText(icon + QString("<span style=\"color: %1\">").arg(color) + QString("[%1] ").arg(timestr) + tr("%1 says:").arg(TextUtil::escape(mv.nick())) + "</span><br>" + mv.formattedText()); } else { appendText(icon + QString("<span style=\"color: %1\">").arg(color) + QString("[%1] <").arg(timestr) + TextUtil::escape(mv.nick()) + QString("></span> ") + mv.formattedText()); } } if (mv.isLocal()) { deferredScroll(); } }
bool UILineEdit::onKeyPress(uchar keyCode, std::string keyText, int keyboardModifiers) { if(keyCode == Fw::KeyDelete) // erase right character removeCharacter(true); else if(keyCode == Fw::KeyBackspace) // erase left character { removeCharacter(false); else if(keyCode == Fw::KeyRight) // move cursor right moveCursor(true); else if(keyCode == Fw::KeyLeft) // move cursor left moveCursor(false); else if(keyCode == Fw::KeyHome) // move cursor to first character setCursorPos(0); else if(keyCode == Fw::KeyEnd) // move cursor to last character setCursorPos(m_text.length()); else if(keyCode == Fw::KeyV && keyboardModifiers == Fw::KeyboardCtrlModifier) appendText(g_window.getClipboardText()); else if(keyCode == Fw::KeyTab) { if(!m_alwaysActive) { if(UIWidgetPtr parent = getParent()) parent->focusNextChild(Fw::TabFocusReason); } } else if(!keyText.empty() && (keyboardModifiers == Fw::KeyboardNoModifier || keyboardModifiers == Fw::KeyboardShiftModifier)) appendText(keyText); else return false; return true; }
void ChatView::renderMucMessage(const MessageView &mv) { const QString timestr = formatTimeStamp(mv.dateTime()); QString alerttagso, alerttagsc, nickcolor; QString textcolor = palette().color(QPalette::Active, QPalette::Text).name(); QString icon = useMessageIcons_? (QString("<img src=\"%1\" />").arg(mv.isLocal()?"icon:log_icon_delivered":"icon:log_icon_receive")):""; if(mv.isAlert()) { textcolor = "#FF0000"; alerttagso = "<b>"; alerttagsc = "</b>"; } if(mv.isSpooled()) { nickcolor = ColorOpt::instance()->color(infomrationalColorOpt).name(); } else { nickcolor = getMucNickColor(mv.nick(), mv.isLocal()); } if(mv.isEmote()) { appendText(icon + QString("<font color=\"%1\">").arg(nickcolor) + QString("[%1]").arg(timestr) + QString(" *%1 ").arg(TextUtil::escape(mv.nick())) + alerttagso + mv.formattedText() + alerttagsc + "</font>"); } else { if(PsiOptions::instance()->getOption("options.ui.chat.use-chat-says-style").toBool()) { appendText(icon + QString("<font color=\"%1\">").arg(nickcolor) + QString("[%1] ").arg(timestr) + QString("%1 says:").arg(TextUtil::escape(mv.nick())) + "</font><br>" + QString("<font color=\"%1\">").arg(textcolor) + alerttagso + mv.formattedText() + alerttagsc + "</font>"); } else { appendText(icon + QString("<font color=\"%1\">").arg(nickcolor) + QString("[%1] <").arg(timestr) + TextUtil::escape(mv.nick()) + QString("></font> ") + QString("<font color=\"%1\">").arg(textcolor) + alerttagso + mv.formattedText() + alerttagsc +"</font>"); } } if(mv.isLocal()) { scrollToBottom(); } }
static bool readTagContent (tokenInfo *token, vString *text, long *line, long *lineOffset, int depth) { tokenType type; readTokenText (token, text != NULL); appendText (text, token->string); do { *line = getInputLineNumber (); *lineOffset = getInputLineOffset (); readToken (token, false); type = token->type; if (type == TOKEN_TAG_START) readTag (token, text, depth + 1); if (type == TOKEN_COMMENT || type == TOKEN_TAG_START) { readTokenText (token, text != NULL); appendText (text, token->string); } } while (type == TOKEN_COMMENT || type == TOKEN_TAG_START); return type == TOKEN_TAG_START2; }
static int runInSubprocessWithTimeLimit(AbortHandlerState &state, Callback callback, void *userData, int timeLimit) { char *end; pid_t child; int p[2], e; if (pipe(p) == -1) { e = errno; end = state.messageBuf; end = appendText(end, "Could not create subprocess: pipe() failed with errno="); end = appendULL(end, e); end = appendText(end, "\n"); write_nowarn(STDERR_FILENO, state.messageBuf, end - state.messageBuf); return -1; } child = asyncFork(); if (child == 0) { close(p[0]); callback(state, userData); _exit(0); return -1; } else if (child == -1) { e = errno; close(p[0]); close(p[1]); end = state.messageBuf; end = appendText(end, "Could not create subprocess: fork() failed with errno="); end = appendULL(end, e); end = appendText(end, "\n"); write_nowarn(STDERR_FILENO, state.messageBuf, end - state.messageBuf); return -1; } else { int status; close(p[1]); // We give the child process a time limit. If it doesn't succeed in // exiting within the time limit, we assume that it has frozen // and we kill it. struct pollfd fd; fd.fd = p[0]; fd.events = POLLIN | POLLHUP | POLLERR; if (poll(&fd, 1, timeLimit) <= 0) { kill(child, SIGKILL); safePrintErr("Could not run child process: it did not exit in time\n"); } close(p[0]); if (waitpid(child, &status, 0) == child) { return status; } else { return -1; } } }
void ChatView::renderUrls(const MessageView &mv) { QMap<QString, QString> urls = mv.urls(); foreach (const QString &key, urls.keys()) { appendText(QString("<b>") + tr("URL:") + "</b> " + QString("%1").arg(TextUtil::linkify(TextUtil::escape(key)))); if (!urls.value(key).isEmpty()) { appendText(QString("<b>") + tr("Desc:") + "</b> " + QString("%1").arg(urls.value(key))); } } }
inline bool read(T text) { if (peek(text)) { if (_ignoreCase && _ignoreCaseKeepSame) appendText(_buff.substr(0, textLen(text))); else appendText(text); return true; } return false; }
bool MonitorItem::docmd(const char* command) { if (!doconnect()) { return false; } if (command[0] != 0) { writecmd(command); } emit clearText(get_name()); bool jobRunning = false; while (1) { int stat; if ((stat = bnet_recv(d->DSock)) >= 0) { strip_trailing_newline(d->DSock->msg); QString msg = QString::fromUtf8(d->DSock->msg); emit appendText(QString::fromUtf8(get_name()), msg); if (d->type == R_CLIENT) { if (msg.contains("Job started:")) jobRunning = true; } } else if (stat == BNET_SIGNAL) { if (d->DSock->msglen == BNET_EOD) { // qDebug() << "<< EOD >>"; if (d->type == R_CLIENT) emit jobIsRunning (jobRunning); return true; } else if (d->DSock->msglen == BNET_SUB_PROMPT) { // qDebug() << "<< PROMPT >>"; return false; } else if (d->DSock->msglen == BNET_HEARTBEAT) { bnet_sig(d->DSock, BNET_HB_RESPONSE); } else { qDebug() << bnet_sig_to_ascii(d->DSock); } } else { /* BNET_HARDEOF || BNET_ERROR */ d->DSock = NULL; d->state = MonitorItem::Error; emit statusChanged(get_name(), d->state); emit showStatusbarMessage("Error : BNET_HARDEOF or BNET_ERROR"); //fprintf(stderr, "<< ERROR >>\n")); return false; } /* if ((stat = bnet_recv(d->DSock)) >= 0) */ if (is_bnet_stop(d->DSock)) { d->DSock = NULL; d->state = MonitorItem::Error; emit statusChanged(get_name(), d->state); emit showStatusbarMessage("Error : Connection closed."); //fprintf(stderr, "<< STOP >>\n"); return false; /* error or term */ } /* if (is_bnet_stop(d->DSock) */ } /* while (1) */ }
//[cf] //[c] //[of]:appendAttribute void DocbookToHTML::appendAttribute(AXAttribute* attr) { const char* start = attr->begin; const char* limit = attr->limit; size_t size = limit - start; appendText(start, size); }
void MarkupAccumulator::appendStartMarkup(StringBuilder& result, Node& node, Namespaces* namespaces) { switch (node.nodeType()) { case Node::TEXT_NODE: appendText(result, toText(node)); break; case Node::COMMENT_NODE: appendComment(result, toComment(node).data()); break; case Node::DOCUMENT_NODE: appendXMLDeclaration(result, toDocument(node)); break; case Node::DOCUMENT_FRAGMENT_NODE: break; case Node::DOCUMENT_TYPE_NODE: appendDocumentType(result, toDocumentType(node)); break; case Node::PROCESSING_INSTRUCTION_NODE: appendProcessingInstruction(result, toProcessingInstruction(node).target(), toProcessingInstruction(node).data()); break; case Node::ELEMENT_NODE: appendElement(result, toElement(node), namespaces); break; case Node::CDATA_SECTION_NODE: appendCDATASection(result, toCDATASection(node).data()); break; case Node::ATTRIBUTE_NODE: ASSERT_NOT_REACHED(); break; } }
void ChatView::dispatchMessage(const MessageView &mv) { if ((mv.type() == MessageView::Message || mv.type() == MessageView::Subject) && ChatViewCommon::updateLastMsgTime(mv.dateTime())) { QString color = ColorOpt::instance()->color(infomrationalColorOpt).name(); appendText(QString(useMessageIcons_?"<img src=\"icon:log_icon_time\" />":"") + QString("<font color=\"%1\">*** %2</font>").arg(color).arg(mv.dateTime().date().toString(Qt::ISODate))); } switch (mv.type()) { case MessageView::Message: if (isMuc_) { renderMucMessage(mv); } else { renderMessage(mv); } break; case MessageView::Subject: if (isMuc_) { renderMucSubject(mv); } else { renderSubject(mv); } break; case MessageView::Urls: renderUrls(mv); break; default: // System/Status renderSysMessage(mv); } }
EstateDetails::EstateDetails(Estate *estate, QString text, QWidget *parent, const char *name) : QWidget(parent, name) { m_pixmap = 0; m_quartzBlocks = 0; b_recreate = true; m_recreateQuartz = true; m_estate = 0; m_closeButton = 0; m_buttons.setAutoDelete(true); m_mainLayout = new QVBoxLayout(this, KDialog::marginHint(), KDialog::spacingHint()); Q_CHECK_PTR(m_mainLayout); m_mainLayout->addItem(new QSpacerItem(KDialog::spacingHint(), KDialog::spacingHint()+50, QSizePolicy::Fixed, QSizePolicy::Minimum)); m_infoListView = new KListView(this, "infoListView"); m_infoListView->addColumn(m_estate ? m_estate->name() : QString("") ); m_infoListView->setSorting(-1); m_mainLayout->addWidget(m_infoListView); appendText(text); m_buttonBox = new QHBoxLayout(m_mainLayout, KDialog::spacingHint()); m_buttonBox->setMargin(0); m_buttonBox->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum)); setEstate(estate); }
// Construct free-floating window CommandWindow::CommandWindow(FXApp* a, const FXString& name, FXString strcmd, int nblines, int nbcols) : DialogBox(a, name, DECOR_TITLE|DECOR_BORDER|DECOR_RESIZE|DECOR_MAXIMIZE|DECOR_MINIMIZE|DECOR_CLOSE, 0, 0, 0, 0, 6, 6, 6, 6, 4, 4) { // Get command to execute command = strcmd; // Bottom part FXHorizontalFrame* buttonbox = new FXHorizontalFrame(this, LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|PACK_UNIFORM_WIDTH); new FXButton(buttonbox, _("Cl&ose"), NULL, this, ID_CLOSE, BUTTON_DEFAULT|LAYOUT_RIGHT|FRAME_RAISED|FRAME_THICK, 0, 0, 0, 0, 20, 20, 5, 5); FXButton* cancelbutton = new FXButton(buttonbox, _("&Cancel"), NULL, this, ID_KILLPROCESS, BUTTON_INITIAL|BUTTON_DEFAULT|LAYOUT_RIGHT|FRAME_RAISED|FRAME_THICK, 0, 0, 0, 0, 20, 20, 5, 5); // Text part FXHorizontalFrame* textbox = new FXHorizontalFrame(this, LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN, 0, 0, 0, 0, 0, 0, 0, 0); text = new FXText(textbox, NULL, 0, TEXT_READONLY|TEXT_WORDWRAP|LAYOUT_FILL_X|LAYOUT_FILL_Y); text->setVisibleRows(nblines); text->setVisibleColumns(nbcols); appendText(_("Please wait...\n\n")); cancelbutton->setFocus(); // Initialize variables pid = -1; killed = false; closed = false; }
bool readUntil(const std::vector< T >& vec, bool contains = true) { typename std::vector< T >::const_iterator it; bool ret; std::string save; ret = false; while (readBlockIfEmpty() && !ret) { for (it = vec.begin(); it != vec.end(); ++it) if ((ret = peek(*it))) break ; if (ret) { if (contains) { save += *it; _buff = _buff.substr(textLen(*it)); } } else { save += _buff[0]; _buff = _buff.substr(1); } } if (ret) appendText(save, false); else _buff = save + _buff; return ret; }
void chat_client_pressedReturnKey(void *t, const char *msg) { TForm1 *tform1 = (TForm1 *) t; if (ircThreadInstance && ircThreadInstance->sd) { sendMessage(msg); appendText(tform1, currentTimeString( ) + " - " + playerName + ": " + msg); } }
bool UITextEdit::onKeyText(const std::string& keyText) { if(m_editable) { appendText(keyText); return true; } return false; }
static char * appendSignalName(char *buf, int signo) { switch (signo) { case SIGABRT: buf = appendText(buf, "SIGABRT"); break; case SIGSEGV: buf = appendText(buf, "SIGSEGV"); break; case SIGBUS: buf = appendText(buf, "SIGBUS"); break; case SIGFPE: buf = appendText(buf, "SIGFPE"); break; case SIGILL: buf = appendText(buf, "SIGILL"); break; default: return appendULL(buf, (unsigned long long) signo); } buf = appendText(buf, "("); buf = appendULL(buf, (unsigned long long) signo); buf = appendText(buf, ")"); return buf; }
void Channel::sendMessage(QString message) { IrcCommand *command = IrcCommand::createMessage(name, message); Channel::MessageType type = Channel::MessageTypeDefault; Server *server = getServer(); MessageParser *parser = server->getMessageParser(); QString styledString = parser->styleString(message); appendText(server->getNickname(), styledString, type); server->sendCommand(command); }
static void dumpFileDescriptorInfoWithLsof(AbortHandlerState &state, void *userData) { char *end; end = state.messageBuf; end = appendULL(end, state.pid); *end = '\0'; closeAllFileDescriptors(2, true); execlp("lsof", "lsof", "-p", state.messageBuf, "-nP", (const char * const) 0); end = state.messageBuf; end = appendText(end, "ERROR: cannot execute command 'lsof': errno="); end = appendULL(end, errno); end = appendText(end, "\n"); write_nowarn(STDERR_FILENO, state.messageBuf, end - state.messageBuf); _exit(1); }
void Textbox::addText( std::string newText, glm::vec3 color, GLboolean newLine ) { if ( newText.size() == 0 ) return; appendText( newText, color ); if ( newLine ) { addNewLine(); } }
/* * Android log function, printf-style. * Logs input string to GUI TextView. */ void androidPrint(const char* format, ...) { va_list args; char appendString[4096]; va_start(args, format); vsnprintf(appendString, sizeof(appendString), format, args); appendText(appendString); va_end(args); }
void QTerminalEdit::keyPressEvent(QKeyEvent *e) { QByteArray dataIn; dataIn.append(e->text()); if(echoBytes) { appendText(dataIn,true); } emit textEntered(e->text(),hexMode); }
/* * Android error log function, replaces com_err calls */ void androidError(const char* progname, errcode_t code, const char* format, ...) { va_list args; char errString[4096] = "Error "; va_start(args, format); vsnprintf(errString+6, sizeof(errString), format, args); strcat(errString, "\n"); appendText(errString); va_end(args); }
void ChatView::renderMucSubject(const MessageView &mv) { QString timestr = formatTimeStamp(mv.dateTime()); QString ut = mv.formattedUserText(); QString color = ColorOpt::instance()->color(infomrationalColorOpt).name(); QString userTextColor = ColorOpt::instance()->color("options.ui.look.colors.messages.usertext").name(); appendText(QString(useMessageIcons_?"<img src=\"icon:log_icon_info\" />":"") + QString("<font color=\"%1\">[%2] *** ").arg(color, timestr) + mv.formattedText() + (ut.isEmpty()?"":":<br>") + "</font>" + (ut.isEmpty()?"":QString(" <span style=\"color:%1;font-weight:bold\">%2</span>").arg(userTextColor, ut))); }
void LLChatMsgBox::addText( const LLStringExplicit& text , const LLStyle::Params& input_params ) { S32 length = getLength(); // if there is existing text, add a separator if (length > 0) { // chat separator exists right before the null terminator insertSegment(new ChatSeparator(length - 1, length - 1)); } // prepend newline only if there is some existing text appendText(text, length > 0, input_params); }
// Must be async signal safe. static char * appendPointerAsString(char *buf, void *pointer) { // Use wierd union construction to avoid compiler warnings. if (sizeof(void *) == sizeof(unsigned int)) { union { void *pointer; unsigned int value; } u; u.pointer = pointer; return appendIntegerAsHex(appendText(buf, "0x"), u.value); } else if (sizeof(void *) == sizeof(unsigned long long)) { union { void *pointer; unsigned long long value; } u; u.pointer = pointer; return appendIntegerAsHex(appendText(buf, "0x"), u.value); } else { return appendText(buf, "(pointer size unsupported)"); } }
bool UITextEdit::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks) { if(UIWidget::onKeyPress(keyCode, keyboardModifiers, autoRepeatTicks)) return true; if(keyboardModifiers == Fw::KeyboardNoModifier) { if(keyCode == Fw::KeyDelete) { // erase right character removeCharacter(true); return true; } else if(keyCode == Fw::KeyBackspace) { // erase left character { removeCharacter(false); return true; } else if(keyCode == Fw::KeyRight && !m_shiftNavigation) { // move cursor right moveCursor(true); return true; } else if(keyCode == Fw::KeyLeft && !m_shiftNavigation) { // move cursor left moveCursor(false); return true; } else if(keyCode == Fw::KeyHome) { // move cursor to first character setCursorPos(0); return true; } else if(keyCode == Fw::KeyEnd) { // move cursor to last character setCursorPos(m_text.length()); return true; } else if(keyCode == Fw::KeyTab && !m_shiftNavigation) { if(UIWidgetPtr parent = getParent()) parent->focusNextChild(Fw::KeyboardFocusReason); return true; } else if(keyCode == Fw::KeyEnter && m_multiline) { appendCharacter('\n'); return true; } else if(keyCode == Fw::KeyUp && !m_shiftNavigation && m_multiline) { } else if(keyCode == Fw::KeyDown && !m_shiftNavigation && m_multiline) { } } else if(keyboardModifiers == Fw::KeyboardCtrlModifier) { if(keyCode == Fw::KeyV) { appendText(g_window.getClipboardText()); return true; } } else if(keyboardModifiers == Fw::KeyboardShiftModifier) { if(keyCode == Fw::KeyRight && m_shiftNavigation) { // move cursor right moveCursor(true); return true; } else if(keyCode == Fw::KeyLeft && m_shiftNavigation) { // move cursor left moveCursor(false); return true; } } return false; }
static void dumpWithCrashWatch(AbortHandlerState &state) { char *messageBuf = state.messageBuf; const char *pidStr = messageBuf; char *end = messageBuf; end = appendULL(end, (unsigned long long) state.pid); *end = '\0'; pid_t child = asyncFork(); if (child == 0) { closeAllFileDescriptors(2, true); execlp("crash-watch", "crash-watch", "--dump", pidStr, (char * const) 0); if (errno == ENOENT) { safePrintErr("Crash-watch is not installed. Please install it with 'gem install crash-watch' " "or download it from https://github.com/FooBarWidget/crash-watch.\n"); } else { int e = errno; end = messageBuf; end = appendText(end, "crash-watch is installed, but it could not be executed! "); end = appendText(end, "(execlp() returned errno="); end = appendULL(end, e); end = appendText(end, ") Please check your file permissions or something.\n"); write_nowarn(STDERR_FILENO, messageBuf, end - messageBuf); } _exit(1); } else if (child == -1) { int e = errno; end = messageBuf; end = appendText(end, "Could not execute crash-watch: fork() failed with errno="); end = appendULL(end, e); end = appendText(end, "\n"); write_nowarn(STDERR_FILENO, messageBuf, end - messageBuf); } else { waitpid(child, NULL, 0); } }
void Condition::append(StringBuffer &aStringBuffer, char *aBuffer, ActiveCondition *aCond, bool &aFirst, int aMaxLen) { if (!aFirst) aStringBuffer.newline(); else aFirst = false; char *cp = aBuffer + strlen(aBuffer); aCond->toString(cp, aMaxLen); appendText(aBuffer, (char*) aCond->getText(), aMaxLen); aStringBuffer.append(aBuffer); }
static bool createCrashLogFile(char *filename, time_t t) { char *end = filename; end = appendText(end, "/var/tmp/passenger-crash-log."); end = appendULL(end, (unsigned long long) t); *end = '\0'; int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0600); if (fd == -1) { end = filename; end = appendText(end, "/tmp/passenger-crash-log."); end = appendULL(end, (unsigned long long) t); *end = '\0'; fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0600); } if (fd == -1) { *filename = '\0'; return false; } else { close(fd); return true; } }